/* One dark theme for every page (listener, host, host login), whatever the OS
   setting: easier on the eyes during a long webinar. Panels such as the chat sit
   a step lighter than the page so they stand out. */
:root {
  color-scheme: dark;
  --bg: #0d1320;
  --fg: #e8ecf3;
  --muted: #94a0b4;
  --card: #182132;
  --line: rgba(255, 255, 255, .11);
  --accent: #4c8dff;
  --accent-fg: #ffffff;
  --live: #ff5c5c;
  --ok: #3fb950;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 17px; margin: 0; font-weight: 600; flex: 1; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}
.badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.badge.live { color: var(--live); }
.badge.live::before { background: var(--live); animation: pulse 1.6s infinite, ripple-out 1.6s ease-out infinite; }
/* Connected: the grey dot pulses and sends out rings. */
.badge.on::before { animation: pulse 1.6s infinite, ripple-out 1.6s ease-out infinite; }
.badge.live, .badge.on { --ring: currentColor; }
@keyframes ripple-out {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ring) 60%, transparent), 0 0 0 0 color-mix(in srgb, var(--ring) 40%, transparent); }
  100% { box-shadow: 0 0 0 7px transparent, 0 0 0 14px transparent; }
}
.badge.ok::before { background: var(--ok); }
@keyframes pulse { 50% { opacity: .35; } }

.listeners {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
}
.listeners svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.listeners rect { fill: currentColor; }
.listeners b { font-variant-numeric: tabular-nums; font-weight: 700; }
.listeners.bump b { animation: bump .35s ease-out; }
@keyframes bump { 40% { transform: scale(1.25); } }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.card h2 { margin: 0 0 8px; font-size: 22px; }
.card p { margin: 0 0 20px; color: var(--muted); }

input {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  margin-bottom: 12px;
}
button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  padding: 14px 18px;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-fg);
}
button.wide { width: 100%; font-size: 18px; }
button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); }
button:disabled { opacity: .55; cursor: default; }

.error { color: var(--live); min-height: 1.4em; margin: 12px 0 0; font-size: 14px; }

.stage {
  width: 100%;
  max-width: 1200px;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 160px);
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stage img { width: 100%; height: 100%; object-fit: contain; }
.stage .placeholder { color: #9a9aa2; padding: 16px; text-align: center; }

.status { color: var(--muted); font-size: 14px; text-align: center; min-height: 1.4em; }

#live { width: 100%; max-width: 1500px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.live-main { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.live-main .status { margin: 0; }
#live > .chat { height: min(60vh, 520px); }
@media (min-width: 960px) {
  #live { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  #live > .chat { height: calc(100vh - 110px); position: sticky; top: 16px; }
}
.floor { border-color: var(--live); }
#speak.on { background: var(--live); color: #fff; }

/* ---- chat ---- */
.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.chat-toggle { font-weight: 400; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }
.chat-toggle input { width: auto; margin: 0; }
.chat-list { list-style: none; margin: 0; padding: 8px 10px; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.chat-list li { padding: 6px 10px; border-radius: 10px; background: var(--bg); max-width: 100%; }
.chat-list li.mine { background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }
.chat-list li.host { background: color-mix(in srgb, #c9a227 18%, var(--bg)); }
.chat-meta { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.chat-meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list li.host .chat-meta b { color: #a8841a; }
.chat-meta time { color: var(--muted); font-size: 12px; margin-right: auto; }
.chat-meta button { background: none; color: var(--muted); padding: 0 4px; font-size: 13px; font-weight: 400; opacity: .6; }
.chat-meta button:hover { opacity: 1; }
.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.chat-banned { padding: 6px 12px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chat-banned button { padding: 2px 8px; font-size: 12px; font-weight: 400; background: transparent; color: var(--fg); border: 1px solid var(--line); }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { margin: 0; padding: 10px 12px; }
.chat-form button { padding: 0 14px; }
.chat-note { color: var(--live); font-size: 13px; padding: 0 12px; }
.chat-note:not(:empty) { padding-bottom: 8px; }

/* Chat bubbles and input a step lighter than the chat panel. */
.chat { --bg: #232e44; }
.chat-list li.host .chat-meta b { color: #e2bb4d; }

.leave {
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line);
}
.leave:hover { border-color: var(--muted); }

/* ---- travel scene behind the join / ended screens ---- */
:root {
  --sky-top: #4fb3ef; --sky-bottom: #c6ecff;
  --sun: #ffd447; --sun-glow: rgba(255, 210, 70, .55);
  --cloud: #ffffff;
  --sea-1: #7fd3f2; --sea-2: #34a4d8; --sea-3: #1a7fbd;
  --sand: #f2d79b; --trunk: #9a6b3f; --trunk-ring: #7a5230;
  --leaf: #2f9e4f; --leaf-rib: #1f7a3a; --nut: #6b4423;
  --hull: #d9473b; --sail: #ffffff; --jib: #f3f0e6;
  --plane: #ffffff; --plane-accent: #1f6feb; --deck: #ffffff; --win: #3d6aa8; --puff: #86b6e8; --puff-core: #ffffff;
  --bird: #2b3a4a;
  --sea: 24vh;
}

header, main { position: relative; z-index: 1; }
header {
  background: color-mix(in srgb, var(--card) 72%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.card {
  background: color-mix(in srgb, var(--card) 84%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0, 40, 80, .18);
}

.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(var(--sky-top), var(--sky-bottom) calc(100% - var(--sea)));
}
/* During the broadcast the scene would only distract and cost CPU. */
body:has(#live:not([hidden])) .scene { display: none; }
body:has(.scene) { background: var(--sky-bottom); }
body:has(#live:not([hidden])) { background: var(--bg); }
.scene svg { position: absolute; display: block; overflow: visible; }

.stars {
  position: absolute;
  inset: 0 0 40% 0;
  opacity: var(--stars, 0);
  transition: opacity 60s linear;
}
.stars::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
      radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent),
      radial-gradient(1px 1px at 27% 8%, #fff 50%, transparent),
      radial-gradient(1.5px 1.5px at 41% 30%, #fff 50%, transparent),
      radial-gradient(1px 1px at 58% 12%, #fff 50%, transparent),
      radial-gradient(1.5px 1.5px at 69% 36%, #fff 50%, transparent),
      radial-gradient(1px 1px at 83% 22%, #fff 50%, transparent),
      radial-gradient(1px 1px at 92% 6%, #fff 50%, transparent),
      radial-gradient(1px 1px at 6% 40%, #fff 50%, transparent),
      radial-gradient(1.5px 1.5px at 35% 52%, #fff 50%, transparent),
      radial-gradient(1px 1px at 76% 55%, #fff 50%, transparent);
    animation: twinkle 4s ease-in-out infinite alternate;
}
@keyframes twinkle { to { opacity: .45; } }

/* Sun and moon ride up and down with the clock (sky.js sets --sun-e / --moon-e).
   At 0 the disc is centred on the horizon; below that it sinks behind the sea. */
.sun, .moon {
  position: absolute;
  aspect-ratio: 1;
  border-radius: 50%;
  bottom: calc(var(--sea) - var(--size) / 2 + (100% - 7vh - var(--size) / 2 - var(--sea)) * var(--e));
  transition: bottom 60s linear, transform 60s linear;
}
.sun {
  --size: clamp(64px, 10vw, 120px);
  --e: var(--sun-e, 1);
  right: 9vw;
  width: var(--size);
  transform: scale(var(--sun-scale, 1));
  background: radial-gradient(circle at 40% 40%, color-mix(in srgb, var(--sun) 35%, #fff), var(--sun) 60%);
  box-shadow: 0 0 40px 10px var(--sun-glow), 0 0 120px 40px var(--sun-glow);
}
.moon {
  --size: clamp(46px, 7vw, 84px);
  --e: var(--moon-e, -0.6);
  right: 26vw;
  width: var(--size);
  background:
    radial-gradient(circle at 62% 38%, rgba(160, 150, 120, .35) 0 8%, transparent 9%),
    radial-gradient(circle at 38% 62%, rgba(160, 150, 120, .3) 0 11%, transparent 12%),
    radial-gradient(circle at 58% 70%, rgba(160, 150, 120, .25) 0 6%, transparent 7%),
    radial-gradient(circle at 40% 40%, #fffef2, #ece8c8 70%);
  box-shadow: 0 0 30px 8px rgba(240, 240, 210, .3), 0 0 90px 30px rgba(240, 240, 210, .12);
}

.cloud { fill: var(--cloud); opacity: .9; left: 0; animation: drift-right linear infinite; }
.c1 { top: 6vh;  width: clamp(110px, 16vw, 220px); animation-duration: 90s;  animation-delay: -20s; }
.c2 { top: 18vh; width: clamp(80px, 11vw, 150px);  animation-duration: 70s;  animation-delay: -55s; opacity: .75; }
.c3 { top: 30vh; width: clamp(130px, 19vw, 260px); animation-duration: 120s; animation-delay: -90s; opacity: .6; }
.c4 { top: 11vh; width: clamp(70px, 9vw, 120px);   animation-duration: 80s;  animation-delay: -5s;  opacity: .8; }
@keyframes drift-right { from { transform: translateX(-30vw); } to { transform: translateX(110vw); } }

.plane {
  position: absolute;
  top: 13vh;
  left: 0;
  display: flex;
  align-items: center;
  animation: fly 26s linear infinite, climb 6s ease-in-out infinite alternate;
  animation-delay: -4s, 0s;
}
.plane svg { position: static; width: clamp(56px, 7vw, 90px); }
.plane .body { fill: var(--plane); }
.plane .fin, .plane .wing { fill: var(--plane-accent); }
.plane .win { fill: var(--plane-accent); opacity: .7; }
.trail {
  width: 28vw;
  height: 3px;
  margin-right: -6px;
  margin-top: -4px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .85));
}
@keyframes fly { from { transform: translateX(-45vw); } to { transform: translateX(115vw); } }
@keyframes climb { from { translate: 0 8px; } to { translate: 0 -10px; } }

.birds {
  position: absolute;
  top: 24vh;
  left: 0;
  width: 120px;
  height: 50px;
  animation: drift-left 38s linear infinite, climb 4s ease-in-out infinite alternate;
  animation-delay: -12s, 0s;
}
.bird {
  width: 22px;
  fill: none;
  stroke: var(--bird);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: flap .45s ease-in-out infinite alternate;
  animation-delay: var(--d);
}
@keyframes flap { to { transform: scaleY(.35); } }
@keyframes drift-left { from { transform: translateX(110vw); } to { transform: translateX(-30vw); } }

.wave {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 200%;
  height: var(--h);
  animation: roll var(--t) linear infinite, swell 4s ease-in-out infinite alternate;
  background: linear-gradient(var(--c), var(--c)) 0 27px / 100% 100% no-repeat;
}
.wave svg { position: static; width: 100%; height: 28px; fill: var(--c); }
.w1 { --h: var(--sea);                --c: var(--sea-1); --t: 22s; }
.w2 { --h: calc(var(--sea) * .78);   --c: var(--sea-2); --t: 15s; animation-direction: reverse, alternate; animation-delay: 0s, -1.5s; }
.w3 { --h: calc(var(--sea) * .52);   --c: var(--sea-3); --t: 10s; animation-delay: 0s, -3s; }
@keyframes roll { to { transform: translateX(-50%); } }
@keyframes swell { from { translate: 0 0; } to { translate: 0 6px; } }

.island {
  left: -2vw;
  bottom: calc(var(--sea) * .62);
  height: clamp(170px, 36vh, 360px);
  aspect-ratio: 320 / 340;
}
.sand { fill: var(--sand); }
.trunk, .rings { fill: none; stroke-width: 14; stroke-linecap: round; }
.trunk { stroke: var(--trunk); }
.rings { stroke: var(--trunk-ring); stroke-dasharray: 3 9; }
.leaf { fill: var(--leaf); }
.rib { fill: none; stroke: var(--leaf-rib); stroke-width: 2; }
.nut { fill: var(--nut); }
.crown { transform-origin: 0 0; animation: sway 5s ease-in-out infinite alternate; animation-delay: var(--d); }
.frond { transform-origin: 0 0; animation: rustle 2.6s ease-in-out infinite alternate; animation-delay: var(--d); }
@keyframes sway { from { transform: rotate(-4deg); } to { transform: rotate(5deg); } }
@keyframes rustle { from { transform: rotate(-5deg); } to { transform: rotate(7deg); } }

.boat {
  left: 58%;
  bottom: calc(var(--sea) * .4);
  height: clamp(70px, 14vh, 130px);
  aspect-ratio: 160 / 140;
  transform-origin: 50% 85%;
  animation: bob 3.2s ease-in-out infinite alternate, voyage-boat 120s ease-in-out infinite;
}
.hull { fill: var(--hull); }
.stripe { fill: #fff; opacity: .85; }
.sail { fill: var(--sail); }
.jib { fill: var(--jib); }
.mast { stroke: var(--trunk-ring); stroke-width: 3; }
.flag { fill: var(--hull); transform-origin: 80px 9px; animation: flutter .5s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(0) rotate(-5deg); } to { transform: translateY(-9px) rotate(5deg); } }
/* Sailboat and cruise liner take turns. The cycle starts with the sailboat
   leaving to the right, so the liner shows up within seconds of opening. */
@keyframes voyage-boat {
  0%     { translate: 0 0; }
  8%     { translate: 60vw 0; }
  8.01%  { translate: -100vw 0; }
  62%    { translate: -100vw 0; }
  74%    { translate: 0 0; }
  87%    { translate: 6vw 0; }
  100%   { translate: 0 0; }
}
@keyframes flutter { to { transform: scaleX(.75) skewY(4deg); } }

@media (prefers-reduced-motion: reduce) {
  .scene, .scene * { animation: none !important; }
  .plane, .birds, .liner, .liner-wake { display: none; }
  .c1 { transform: translateX(8vw); } .c2 { transform: translateX(45vw); }
  .c3 { transform: translateX(70vw); } .c4 { transform: translateX(28vw); }
}
/* On phones lift the card so the island and boat stay visible below it. */
@media (max-width: 600px) {
  #join, #ended { margin: 3vh 0 auto; }
}

/* Join / ended cards are always dark, in both themes, to stand out against the sky. */
#join, #ended {
  --fg: #ececf0;
  --muted: #b4b4bd;
  --line: rgba(255, 255, 255, .14);
  --accent: #4c8dff;
  --accent-fg: #ffffff;
  background: rgba(16, 24, 40, .78);
  border-color: rgba(255, 255, 255, .12);
  color: var(--fg);
  box-shadow: 0 16px 48px rgba(0, 20, 50, .35);
}
#join input { background: rgba(255, 255, 255, .08); color: var(--fg); }
#join input::placeholder { color: #9a9aa6; }

/* ---- cruise liner ---- */
.liner, .liner-wake {
  --lh: clamp(70px, min(19vh, 24vw), 170px);
  right: 6vw;
  /* Put the waterline (20% up the box) at the front wave's crest peak, so crests
     never climb above it; troughs show a little of the red bottom. */
  bottom: calc(var(--sea) * .52 - 8px - var(--lh) * .2);
  height: var(--lh);
  aspect-ratio: 300 / 130;
  translate: -95vw 0;
  transform-origin: 50% 85%;
  animation: bob-big 4.5s ease-in-out infinite alternate, voyage-liner 120s ease-in-out infinite;
}
.liner-wake { animation: voyage-liner 120s ease-in-out infinite; }
.ripple {
  fill: none;
  stroke: #fff;
  stroke-width: 2.2;
  stroke-linecap: round;
  opacity: 0;
  animation: ripple 5.1s ease-out infinite;
  animation-delay: var(--d);
}
@keyframes ripple {
  0%   { transform: translateX(0); opacity: 0; }
  15%  { opacity: .8; }
  100% { transform: translateX(-110px); opacity: 0; }
}
.lhull, .deck { fill: var(--deck); stroke: #c3cfdc; stroke-width: 1; }
.lstripe { fill: #1d3f7a; }
.lbottom { fill: #d8143a; }
.lifeboat { fill: #f28c28; }
.lname { fill: #1d3f7a; }
.windows { stroke: var(--win); stroke-width: 4; stroke-dasharray: 6 4; }
.puff-core { stop-color: var(--puff-core); }
.puff-edge { stop-color: var(--puff); }
.funnel { fill: #f2c230; }
.funnel-band { fill: #1d3f7a; }
.puff {
  fill: url(#puff-grad);
  transform-box: fill-box;
  transform-origin: center;
  opacity: 0;
  animation: puff 4.4s ease-out infinite;
  animation-delay: var(--d);
}
@keyframes bob-big { from { transform: translateY(0) rotate(-1.2deg); } to { transform: translateY(-5px) rotate(1.2deg); } }
@keyframes puff {
  0%   { transform: translate(0, 0) scale(.4); opacity: 1; }
  100% { transform: translate(-110px, -40px) scale(3); opacity: 0; }
}
@keyframes voyage-liner {
  0%, 3% { translate: -95vw 0; }
  15%     { translate: 0 0; }
  32%     { translate: -5vw 0; }
  48%     { translate: 0 0; }
  56%     { translate: 0 0; }
  68%     { translate: 80vw 0; }
  100%    { translate: 80vw 0; }
}

/* Compact join card so more of the scene shows on phones. */
#join, #ended { max-width: 280px; padding: 18px 18px 16px; }
#join h2 { margin-bottom: 14px; font-size: 20px; }
#join input { padding: 10px 12px; margin-bottom: 10px; }
#join button.wide { padding: 12px 16px; font-size: 17px; }
#join #enter:disabled { opacity: 1; background: rgba(255, 255, 255, .08); color: #9fb0c8; font-weight: 500; }
#joinError:empty { min-height: 0; margin: 0; }
#ended p { margin-bottom: 0; }

/* ---- sea sounds toggle, top-right corner of the join card ---- */
#join { position: relative; }
.ambient {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #4fb3ff;
  background: rgba(2, 6, 14, .85);
  border: 1px solid rgba(79, 179, 255, .3);
}
.ambient:hover { color: #7cc6ff; background: rgba(2, 6, 14, .95); }
.ambient[aria-pressed="true"] { color: #7cc6ff; }
.ambient svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ambient .spk { fill: currentColor; }
.ambient .on, .ambient[aria-pressed="true"] .off { display: none; }
.ambient[aria-pressed="true"] .on { display: inline; }
