:root {
  --bg: #000;
  --tx: #f2f5f9;
  --dim: #9aa7b8;
  --line: rgba(255, 255, 255, .16);
  --panel: rgba(14, 18, 24, .94);
  --acc: #5ee0a8;
  --bad: #ff7a7a;
  --warn: #ffc46b;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); overflow: hidden; }
body {
  color: var(--tx);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* The player IS the page — there is no chrome around it to lose in fullscreen. */
.player { position: fixed; inset: 0; background: #000; overflow: hidden; cursor: default; }
.player canvas, .player video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000; display: none;
}
.player canvas.show, .player video.show { display: block; }

/* ------------------------------------------------------------- the curtain */
.curtain {
  position: absolute; inset: 0; z-index: 20; display: flex;
  align-items: center; justify-content: center; text-align: center; cursor: pointer;
  background: radial-gradient(ellipse at center, #10161f 0%, #05070a 100%);
  transition: opacity .35s;
}
.curtain[hidden] { display: none; }
.curtain.fading { opacity: 0; pointer-events: none; }
/* The gallery is the arrival screen, so the panel is as wide as the picture and
   the header above it is deliberately small — the worlds are the headline. */
.curtain-inner {
  /* Wide enough to read as a gallery rather than a centred column: at 1920 the
     1180px cap left a third of the screen empty on each side. */
  max-width: min(1680px, 92vw); width: 100%; padding: 24px 22px 16px;
  /* Block, not flex: a flex column shrinks its children to fit, and a squeezed
     row clipped the title off every tile on a phone. Plain block layout lets the
     grid keep its natural height and the panel scroll instead. */
  max-height: 100%; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: none;
}
.curtain-inner::-webkit-scrollbar { width: 0; height: 0; }
.curtain-icon {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 50%;
  border: 2px solid var(--line); display: grid; place-items: center;
  background: rgba(255, 255, 255, .04); flex: none;
  transition: border-color .25s, transform .25s;
}
.curtain-icon::after {
  content: ""; width: 17px; height: 26px; border-radius: 9px;
  background: var(--dim); transition: background .25s;
}
.curtain:hover .curtain-icon { border-color: var(--acc); transform: scale(1.04); }
.curtain:hover .curtain-icon::after { background: var(--acc); }
.curtain h1 { font-size: 23px; font-weight: 600; margin: 0 0 7px; letter-spacing: -.2px; }
.curtain p { color: var(--dim); font-size: 14px; margin: 0 0 18px; line-height: 1.55; }
.skip {
  background: none; border: 0; color: var(--dim); font: inherit; font-size: 13.5px;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 6px;
}
.skip:hover { color: var(--tx); }

/* ------------------------------------------------------- what it heard */
/* Subtitles, not a log. On a big screen the point is to read, from across the
   room, exactly what the microphone understood — so this is centred, large and
   short-lived rather than a stack of small bubbles in a corner. */
.said {
  position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%);
  z-index: 12; width: min(1100px, 88vw); list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  pointer-events: none; text-align: center; transition: bottom .25s;
}
.said li {
  font-size: clamp(22px, 3.1vw, 44px);
  font-weight: 650; line-height: 1.28; letter-spacing: -.3px;
  color: #fff;
  /* A hard shadow instead of a panel: readable over any frame, hides nothing. */
  text-shadow: 0 2px 5px rgba(0,0,0,.92), 0 0 22px rgba(0,0,0,.72);
  animation: rise .22s ease-out; max-width: 100%;
  text-wrap: balance;
}
/* Still forming — you can watch the sentence being heard. */
.said li.live { color: #cfe0f2; opacity: .82; font-weight: 550; }
.said li.live::after {
  content: "▍"; margin-left: 3px; opacity: .7;
  animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
.said li.reject { color: var(--bad); font-size: clamp(17px, 2vw, 26px); font-weight: 550; }
/* Older lines step back so the newest is always the one you read. */
.said li:not(:last-child) { font-size: clamp(16px, 1.9vw, 26px); opacity: .45; font-weight: 500; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.player.idle .said { bottom: 40px; }

/* ------------------------------------------------------------------- toast */
.toast {
  position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%);
  z-index: 14; background: rgba(6, 9, 13, .9); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 16px; font-size: 13.5px; color: #dde5ef;
  opacity: 0; pointer-events: none; transition: opacity .25s, bottom .25s;
  backdrop-filter: blur(6px); max-width: 78vw; text-align: center;
}
.toast.show { opacity: 1; }

/* --------------------------------------------------------------- the bar */
.bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 18px 14px 20px;
  background: linear-gradient(to top, rgba(0, 0, 0, .88) 10%, rgba(0, 0, 0, 0));
  transition: opacity .3s;
}
.bar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bar-right { display: flex; align-items: center; gap: 8px; }
.status {
  font: 12.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: #55606f; flex: none; transition: background .3s; }
.dot.live { background: var(--acc); box-shadow: 0 0 0 4px rgba(94, 224, 168, .16); }
.dot.busy { background: var(--warn); }
.dot.err { background: var(--bad); }

button.icon {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: rgba(255, 255, 255, .07); border: 1px solid transparent;
  color: var(--tx); display: grid; place-items: center; cursor: pointer;
  transition: background .18s, color .18s, border-color .18s;
}
button.icon:hover { background: rgba(255, 255, 255, .16); }
button.icon.on { color: var(--acc); border-color: var(--acc); background: rgba(94, 224, 168, .12); }
button.icon.rec { color: var(--bad); border-color: var(--bad); background: rgba(255, 122, 122, .14); }
button.icon:disabled { opacity: .35; cursor: not-allowed; }

.level { width: 46px; height: 4px; border-radius: 3px; background: rgba(255, 255, 255, .14); overflow: hidden; opacity: 0; transition: opacity .25s; }
.level.on { opacity: 1; }
#level-bar { height: 100%; width: 0; background: var(--acc); transition: width .07s linear; }

/* ------------------------------------------------------- settings, upward */
.menu {
  position: absolute; right: 18px; bottom: 64px; z-index: 18; width: 292px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; backdrop-filter: blur(14px); box-shadow: 0 12px 40px rgba(0, 0, 0, .55);
  animation: pop .16s ease-out; transition: bottom .25s;
}
.menu[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.menu .row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 11px; border-radius: 8px; font-size: 13.5px; color: #dde5ef;
}
.menu .row:hover { background: rgba(255, 255, 255, .05); }
.menu .row[hidden] { display: none; }
.menu .row.sep { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }
.menu .row:hover.sep { background: none; }
.menu select {
  background: rgba(255, 255, 255, .08); color: var(--tx); border: 1px solid var(--line);
  border-radius: 7px; padding: 5px 8px; font: inherit; font-size: 13px; cursor: pointer; max-width: 160px;
}
.menu input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--acc); cursor: pointer; }
.file {
  cursor: pointer; font-size: 12.5px; color: var(--dim); border: 1px dashed var(--line);
  border-radius: 7px; padding: 5px 9px; max-width: 150px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.file:hover { color: var(--tx); border-color: var(--acc); }
.file.set { color: var(--acc); border-style: solid; border-color: var(--acc); }
.muted { color: var(--dim); font-size: 12px; line-height: 1.5; }

/* Idle hides the furniture but never the picture. */
.player.idle .bar { opacity: 0; pointer-events: none; }
.player.idle { cursor: none; }
.player.idle .said { bottom: 18px; }
.player.idle .toast { bottom: 26px; }

/* --- richer menu, presets, typed input --------------------------------- */
.menu { max-height: min(76vh, 620px); overflow-y: auto; width: 320px; }
.menu-head {
  font-size: 10.5px; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--dim); padding: 12px 11px 5px; font-weight: 600;
}
.menu-head:first-child { padding-top: 6px; }
.menu input[type=range] { width: 118px; accent-color: var(--acc); }
.menu .row b { color: var(--acc); font-weight: 600; }

/* --- the gallery of worlds --------------------------------------------- */
/* A pill says a word; a tile shows the medium. Since the medium is the thing
   the viewer is actually choosing between, the picture has to be the control.
   The scrollbar is hidden on purpose: a click anywhere on the curtain arms the
   microphone, and dragging a scrollbar would land as one. */
.presets {
  display: grid; align-content: start; gap: 14px; margin: 0 0 12px;
  /* auto-fit, not auto-fill: with 14 tiles auto-fill reserved empty columns and
     left a lopsided last row. */
  grid-template-columns: repeat(auto-fit, minmax(214px, 1fr));
  padding: 3px;
}

.presets button {
  position: relative; display: block; text-align: left; padding: 0;
  border: 1px solid var(--line); border-radius: 13px; overflow: hidden;
  color: var(--tx); font: inherit; cursor: pointer;
  background: linear-gradient(160deg, hsl(var(--h, 205), 26%, 15%), hsl(var(--h, 205), 30%, 8%));
  transition: transform .18s, border-color .18s, box-shadow .18s;
}
.tile-shot { display: block; position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; }
.tile-shot img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block;
  filter: saturate(.95) brightness(.92); transition: transform .35s, filter .22s;
}
/* No cover reached us: the tinted plate stands in, and the tile still works. */
.presets button.nocover .tile-shot::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(120% 92% at 28% 18%, hsla(var(--h, 205), 72%, 46%, .55), transparent 70%);
}
.tile-meta { display: block; padding: 9px 11px 11px; }
.tile-name { display: block; font-size: 13.5px; font-weight: 600; letter-spacing: -.1px; }
.tile-hint {
  margin-top: 3px; font-size: 11.5px; line-height: 1.35; color: var(--dim);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 31px;
}
.presets button:hover, .presets button:focus-visible {
  border-color: var(--acc); transform: translateY(-3px); outline: none;
  box-shadow: 0 12px 30px rgba(0,0,0,.55), 0 0 0 1px rgba(94,224,168,.4);
}
.presets button:hover .tile-shot img, .presets button:focus-visible .tile-shot img {
  transform: scale(1.06); filter: saturate(1.06) brightness(1.06);
}
.presets button:hover .tile-hint, .presets button:focus-visible .tile-hint { color: var(--tx); }
.presets button.on { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc); }
.presets button.on .tile-name { color: var(--acc); }

.typebar {
  position: absolute; left: 50%; bottom: 74px; transform: translateX(-50%);
  z-index: 16; display: flex; gap: 8px; width: min(620px, 88vw);
  background: rgba(6,9,13,.9); border: 1px solid var(--line); border-radius: 12px;
  padding: 7px 7px 7px 15px; backdrop-filter: blur(10px);
}
.typebar[hidden] { display: none; }
.typebar input {
  flex: 1; background: none; border: 0; color: var(--tx); font: inherit; font-size: 14.5px; outline: none;
}
.typebar input::placeholder { color: var(--dim); }
.player.idle .typebar { bottom: 22px; }

.samples { color: var(--dim); font-size: 12.5px; margin: -4px 0 12px; min-height: 18px; }
.samples[hidden] { display: none; }

/* --- the beat: when the next scene is composed ------------------------- */
.beat {
  position: absolute; left: 20px; bottom: 74px; z-index: 13;
  display: flex; align-items: center; gap: 11px;
  background: rgba(6,9,13,.78); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 16px 6px 7px; backdrop-filter: blur(8px);
  transition: bottom .25s, border-color .25s, background .25s;
}
.beat[hidden] { display: none; }
.player.idle .beat { bottom: 18px; }
.beat svg { transform: rotate(-90deg); display: block; }
.beat-track { fill: none; stroke: rgba(255,255,255,.13); stroke-width: 3; }
.beat-arc {
  fill: none; stroke: var(--acc); stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 119.4; stroke-dashoffset: 0;
  transition: stroke-dashoffset .2s linear, stroke .25s;
}
.beat-num {
  position: absolute; left: 7px; width: 44px; text-align: center;
  font: 600 14px/44px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--tx);
  pointer-events: none;
}
.beat-label { font-size: 12.5px; color: var(--dim); white-space: nowrap; }

/* Speaking with time to spare. */
.beat.room { border-color: rgba(94,224,168,.5); }
.beat.room .beat-label { color: var(--acc); }
/* Too late for this one — the sentence lands in the scene after. */
.beat.late .beat-arc { stroke: var(--warn); }
.beat.late .beat-label { color: var(--warn); }
/* Queued, waiting for the boundary. */
.beat.queued .beat-arc { stroke: var(--acc2); }
.beat.queued .beat-label { color: var(--acc2); }
/* It just went in. */
.beat.landed { border-color: var(--acc); background: rgba(94,224,168,.16); }
.beat.landed .beat-label { color: var(--acc); }

.still {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000; z-index: 2;
}
.still[hidden] { display: none; }

/* The gap filler sits above both the live picture and the held frame, because
   when a frame has not arrived the last seconds moving is a better answer than
   a frozen one. It is faded rather than switched: a hard cut announces the seam
   that the whole thing exists to hide. */
.player video.fill {
  display: block; z-index: 3; opacity: 0; pointer-events: none;
  transition: opacity .2s linear;
}
.player video.fill.on { opacity: 1; }

/* --- invite card ------------------------------------------------------- */
.invite {
  position: absolute; right: 18px; bottom: 64px; z-index: 18; width: 268px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; text-align: center; backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px rgba(0,0,0,.55); animation: pop .16s ease-out;
}
.invite[hidden] { display: none; }
.invite-code {
  font: 700 40px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 8px; color: var(--acc); margin-bottom: 8px;
}
.invite-url { font: 12.5px/1.4 ui-monospace, Menlo, monospace; color: #c6d2e0; word-break: break-all; }
.invite-qr { width: 168px; height: 168px; margin: 12px auto 4px; display: block; border-radius: 8px; background: #fff; }
.invite-note { color: var(--dim); font-size: 12px; line-height: 1.5; margin-top: 10px; }


/* --- the arrival gallery at other sizes -------------------------------- */
/* 720p-tall desktop: the header gives up its air so three rows of worlds fit
   without a scroll. */
@media (max-height: 820px) {
  .curtain-inner { padding: 16px 20px 12px; }
  .curtain-icon { width: 44px; height: 44px; margin: 0 auto 10px; }
  .curtain-icon::after { width: 14px; height: 21px; }
  .curtain h1 { font-size: 20px; margin: 0 0 5px; }
  .curtain p { font-size: 13px; margin: 0 0 14px; }
  .presets { grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); gap: 12px; }
  .tile-meta { padding: 7px 10px 9px; }
  .tile-name { font-size: 12.5px; }
  .tile-hint { -webkit-line-clamp: 1; min-height: 16px; font-size: 11px; }
}

/* Phone: two columns, thumb-sized, and the list is meant to be scrolled — so
   the bottom edge fades to say so. */
@media (max-width: 640px) {
  .curtain-inner { padding: 14px 14px 10px; }
  .curtain h1 { font-size: 18px; }
  .curtain p { font-size: 12.5px; margin: 0 0 12px; }
  .presets { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile-hint { -webkit-line-clamp: 2; min-height: 30px; }
  .skip { padding: 10px 6px; }
}

/* Very short viewport (landscape phone): drop the icon rather than the worlds. */
@media (max-height: 460px) {
  .curtain-icon { display: none; }
  .curtain p { display: none; }
  .curtain h1 { font-size: 16px; margin: 0 0 10px; }
}

/* The film is the thing people take away, so the two buttons that let them keep
   it read as part of the transport, not as a debug affordance. */
#btn-rec.on { color: #ff5a5a; }
#btn-rec.on svg { animation: recpulse 1.4s ease-in-out infinite; }
@keyframes recpulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
body.recording .bar { box-shadow: inset 0 2px 0 0 #ff5a5a; }
