/* App layout and player. Colour, type and corner rules come from tokens.css: only var(--…) here. */
*, *::before, *::after { box-sizing: border-box; }
* { min-width: 0; }
html, body { margin: 0; color: var(--ink); background-color: var(--ground); }
body { min-height: 100dvh; -webkit-font-smoothing: antialiased; overflow-x: clip; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
code, .mono { font-family: var(--font-mono); }
h3 { margin: 0; font: 600 20px/28px var(--font-display); letter-spacing: -0.02em; }
.grow, .hgrow { flex: 1; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- buttons, fields, badges ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--control-md); padding: 0 var(--space-4); border: 0; background: none; color: var(--ink); font: 600 15px/1 var(--font-sans); white-space: nowrap; }
.btn.cut-primary { color: var(--on-accent); }
.btn.cut-ghost { color: var(--klein); }
.btn.sm { height: var(--control-sm); padding: 0 var(--space-3); font-size: 13px; }
.btn.icon { width: var(--control-md); padding: 0; }
.btn.icon.sm { width: var(--control-sm); }
.btn.wide { width: 100%; height: var(--control-lg); }
.btn:active { transform: translateY(1px); }
.btn:disabled { --fill: var(--sunken); --line: var(--sunken); color: var(--ink-muted); cursor: not-allowed; }
.field { display: flex; align-items: center; height: var(--control-md); padding: 0 var(--space-3); }
.field input, .field select { width: 100%; height: 100%; border: 0; outline: 0; background: transparent; font: 400 16px/24px var(--font-sans); }
.field.select select { cursor: pointer; }
select option { background: var(--surface); color: var(--ink); }
.label { display: inline-block; }
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; font: 600 11px/16px var(--font-mono); letter-spacing: 1px; text-transform: uppercase; color: var(--ink-muted); white-space: nowrap; }
.dia { width: 7px; height: 7px; transform: rotate(45deg); background: var(--ink-muted); flex: none; }
.badge.ok { color: var(--success); } .badge.ok .dia { background: var(--success); }
.badge.bad { color: var(--danger); } .badge.bad .dia { background: var(--danger); }
.badge.run { --fill: var(--klein-tint); color: var(--ink); } .badge.run .dia { background: var(--klein); }
.badge.data { color: var(--cyan); } .badge.data .dia { background: var(--cyan); }
.badge.em { color: var(--magenta); } .badge.em .dia { background: var(--magenta); }
.num { font: 600 32px/36px var(--font-mono); font-variant-numeric: tabular-nums; color: var(--cyan); }
.num.sm { font-size: 16px; line-height: 24px; min-width: 72px; text-align: right; }
.c-magenta { color: var(--magenta); }
.hint { margin: 0; font: 400 13px/20px var(--font-sans); color: var(--ink-muted); max-width: 65ch; }
.note { margin: 12px 0 0; font: 400 13px/20px var(--font-sans); color: var(--ink-muted); min-height: 20px; }

/* ---------- top bar ---------- */
.topbar { --fill: var(--surface); position: sticky; top: 0; z-index: var(--z-sticky); display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin: var(--space-4) var(--space-4) 0; padding: var(--space-3) var(--space-4); }
.wordmark { font: 700 28px/32px var(--font-logo); color: var(--ink); margin-right: var(--space-3); white-space: nowrap; }
.room { font: 500 13px/20px var(--font-mono); color: var(--cyan); }
.stat { display: inline-flex; align-items: baseline; gap: 8px; }
.stat .num { font-size: 24px; line-height: 28px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--space-6); padding: var(--space-6) var(--space-4) var(--space-12); max-width: 1536px; margin: 0 auto; }
.screen { grid-column: 1; }
.side { grid-column: 2; grid-row: 1 / span 2; display: flex; flex-direction: column; gap: var(--space-6); }
.library { grid-column: 1; }
.panel > header { min-height: 36px; }
.panel > header.d-cyan::before { background: var(--cyan-bright); }
.panel > header.d-magenta::before { background: var(--magenta-bright); }
.panel > .body { background: var(--surface); }
.panel > .body.flush { padding: var(--space-4); }
.panel > .body.tight { padding: var(--space-4); }
.panel > header .now { font: 500 11px/16px var(--font-mono); letter-spacing: 1px; color: var(--on-bar); opacity: 0.85; text-transform: none; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel > header .hnote { text-transform: none; letter-spacing: 0; font-weight: 400; }
.panel > header .onbar { color: var(--on-bar); }
@media (max-width: 1024px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .screen, .side, .library { grid-column: 1; grid-row: auto; }
}
@media (max-width: 640px) {
  .topbar { margin: 0; position: static; }
  .layout { padding: var(--space-3) 0 var(--space-12); gap: var(--space-4); }
  .panel > .body.flush { padding: 0; }
  #copyLink span { display: none; }
  #copyLink { width: var(--control-md); padding: 0; }
  .note { padding: 0 var(--space-4) var(--space-3); }
}

/* ---------- stage: a dark island in both themes ---------- */
.stage {
  color-scheme: dark;
  --ink: #DDE1EC; --ink-muted: #AEB7CA; --surface: #0D121C; --sunken: #232C42; --hairline: #232C42; --border-control: #AEB7CA;
  --klein: #7F8EFF; --klein-tint: #161C55; --cyan: #1FE0F5; --magenta: #FF4FB8; --success: #2EF08A; --danger: #FF6B7A; --on-accent: #06080C; --ground: #06080C;
  position: relative; aspect-ratio: 16 / 9; width: 100%; background: #000; color: var(--ink); overflow: hidden; outline: none;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.stage.idle { cursor: none; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 4px; padding: 0 10%; }
.empty p { margin: 0; color: var(--ink-muted); }

/* fullscreen and CSS fallback for phones without element fullscreen (iPhone) */
.stage:fullscreen, .stage.immersive { aspect-ratio: auto; width: 100vw; height: 100dvh; clip-path: none; }
.stage.immersive { position: fixed; inset: 0; z-index: var(--z-modal); height: var(--vh, 100dvh); }
body.lock { overflow: hidden; }
body.lock .topbar, body.lock .side, body.lock .library { visibility: hidden; } /* nothing peeks around the immersive player */
.panel.host-imm { clip-path: none; overflow: visible; isolation: auto; }
.panel.host-imm::before, .panel.host-imm::after { display: none; }

/* subtitles: drawn by our renderer so offsets and per-user tracks work everywhere */
.subs { position: absolute; left: 6%; right: 6%; bottom: 8%; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; transition: bottom var(--duration-fast) var(--ease-out); }
.stage:not(.idle):not(.noctl) .subs { bottom: calc(96px + 2%); }
.subs span { max-width: 100%; padding: 2px 10px; background: rgba(6, 8, 12, 0.82); color: #fff; font: 600 var(--sub-size, 22px)/1.3 var(--font-sans); text-align: center; white-space: pre-line; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.stage[data-sub="s"] { --sub-size: clamp(14px, 2.2vw, 22px); }
.stage[data-sub="m"] { --sub-size: clamp(16px, 2.8vw, 30px); }
.stage[data-sub="l"] { --sub-size: clamp(19px, 3.6vw, 40px); }

/* controls */
.controls { position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; padding: 8px 12px 10px; background: rgba(6, 8, 12, 0.86); transition: opacity var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.stage.idle .controls { opacity: 0; transform: translateY(8px); pointer-events: none; }
.controls .row { display: flex; align-items: center; gap: 2px; }
.cbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; min-width: 44px; padding: 0 10px; border: 0; background: transparent; color: var(--ink);
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px); transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out); }
.cbtn:hover, .cbtn[aria-expanded="true"] { background: var(--klein-tint); }
.cbtn.accent { color: var(--klein); }
.cbtn.on { color: var(--cyan); }
.cbtn .cl { font: 600 11px/16px var(--font-mono); letter-spacing: 1px; text-transform: uppercase; }
.cbtn .ic { width: 22px; height: 22px; }
.time { font: 500 13px/20px var(--font-mono); font-variant-numeric: tabular-nums; color: var(--ink-muted); padding: 0 8px; white-space: nowrap; }
.time b { color: var(--ink); font-weight: 500; }
.volwrap { display: flex; align-items: center; }
.vol { width: 0; opacity: 0; transition: width var(--duration-fast) var(--ease-out), opacity var(--duration-fast) var(--ease-out); accent-color: #7F8EFF; height: 44px; }
.volwrap:hover .vol, .volwrap:focus-within .vol { width: 90px; opacity: 1; }

/* seek bar: only transforms move, so it never forces layout while playing */
.seek { position: relative; height: 24px; display: flex; align-items: center; cursor: pointer; touch-action: none; margin: 0 4px; }
.seek .track { position: relative; width: 100%; height: 4px; background: var(--sunken); overflow: hidden; transition: height var(--duration-fast) var(--ease-out); }
.seek:hover .track, .seek.drag .track { height: 6px; }
.seek .track i { position: absolute; inset: 0; transform-origin: 0 50%; transform: scaleX(0); will-change: transform; }
.seek .buf { background: #4A5572; }
.seek .played { background: var(--klein); }
.seek .thumb { position: absolute; left: 0; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; background: var(--klein); transform: translateX(0) rotate(45deg); will-change: transform; pointer-events: none; }
.seek .tip { position: absolute; bottom: 26px; left: 0; padding: 2px 8px; --fill: var(--surface); --line: var(--hairline); font: 500 12px/18px var(--font-mono); color: var(--ink); opacity: 0; pointer-events: none; transform: translateX(-50%); transition: opacity var(--duration-fast) var(--ease-out); white-space: nowrap; }
.seek:hover .tip, .seek.drag .tip { opacity: 1; }

/* popovers above the control bar */
.popwrap { position: relative; }
.pop { --fill: var(--surface); --line: var(--hairline); position: absolute; right: 0; bottom: 52px; z-index: 6; padding: 8px; filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.7)); }
.reactpop { display: grid; grid-template-columns: repeat(6, 44px); gap: 4px; }
.reactpop button { height: 44px; border: 0; background: transparent; color: var(--ink); clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px); }
.reactpop button:hover { background: var(--klein-tint); color: var(--magenta); }
.reactpop .ic { width: 26px; height: 26px; }
.ccpop { min-width: 220px; display: grid; gap: 2px; }
.ccpop button { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 10px; border: 0; background: transparent; color: var(--ink); text-align: left; font: 400 15px/20px var(--font-sans); }
.ccpop button:hover { background: var(--klein-tint); }
.ccpop button .dia { visibility: hidden; background: var(--klein); }
.ccpop button.on .dia { visibility: visible; }
.ccpop .label { padding: 6px 10px 2px; }

/* reactions float up: transform and opacity only */
.reactlayer { position: absolute; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; }
.fly { position: absolute; bottom: 18%; display: flex; flex-direction: column; align-items: center; gap: 2px; animation: fly 2.4s var(--ease-out) forwards; will-change: transform, opacity; }
.fly .ic { width: 40px; height: 40px; stroke-width: 1.75; }
.fly.laugh { color: var(--cyan); } .fly.heart { color: var(--magenta); } .fly.fire { color: var(--danger); } .fly.wow { color: var(--klein); } .fly.sad { color: var(--cyan); } .fly.clap { color: var(--success); }
.fly b { font: 600 11px/16px var(--font-mono); letter-spacing: 1px; text-transform: uppercase; color: var(--ink); background: rgba(6, 8, 12, 0.8); padding: 0 6px; }
@keyframes fly { 0% { transform: translateY(0) scale(0.6); opacity: 0; } 12% { transform: translateY(-20px) scale(1.1); opacity: 1; } 100% { transform: translateY(-260px) scale(1); opacity: 0; } }

.waitbar { --fill: var(--surface); --line: var(--magenta); position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5; padding: 4px 12px; font: 600 11px/16px var(--font-mono); letter-spacing: 1px; text-transform: uppercase; color: var(--magenta); white-space: nowrap; max-width: 90%; overflow: hidden; text-overflow: ellipsis; }
.spinner { position: absolute; inset: 0; display: grid; place-items: center; z-index: 2; pointer-events: none; }
.spinner span { width: 18px; height: 18px; background: var(--klein); animation: spin 0.9s linear infinite; }
@keyframes spin { from { transform: rotate(45deg) scale(1); } 50% { transform: rotate(225deg) scale(0.6); } to { transform: rotate(405deg) scale(1); } }
.flash { position: absolute; top: 50%; left: 50%; z-index: 3; width: 72px; height: 72px; margin: -36px 0 0 -36px; display: grid; place-items: center; background: rgba(6, 8, 12, 0.7); color: var(--ink); opacity: 0; pointer-events: none;
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px); font: 600 13px/16px var(--font-mono); }
.flash.go { animation: flash 0.5s var(--ease-out); }
.flash .ic { width: 32px; height: 32px; }
@keyframes flash { 0% { opacity: 1; transform: scale(0.9); } 100% { opacity: 0; transform: scale(1.15); } }

/* chat over the picture, shown in full screen */
.ovchat { display: none; position: absolute; left: 12px; bottom: 112px; z-index: 5; width: min(420px, 70%); flex-direction: column; gap: 6px; }
.stage:fullscreen .ovchat, .stage.immersive .ovchat { display: flex; }
.stage.idle .ovchat { bottom: 16px; }
.ovlog { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
.ovlog li { align-self: flex-start; max-width: 100%; padding: 4px 10px; background: rgba(6, 8, 12, 0.82); font: 400 14px/20px var(--font-sans); color: var(--ink); overflow-wrap: anywhere; transition: opacity 0.6s var(--ease-out);
  clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px); unicode-bidi: plaintext; }
.ovlog li b { font: 600 12px/20px var(--font-mono); color: var(--klein); margin-right: 8px; }
.ovlog li.out { opacity: 0; }
.ovform { --fill: var(--surface); --line: var(--border-control); display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 12px; }
.ovform input { flex: 1; height: 36px; border: 0; outline: 0; background: transparent; font-size: 16px; color: var(--ink); }

@media (max-width: 640px) {
  .stage { clip-path: none; }
  .controls { padding: 4px 4px 6px; }
  .cbtn { min-width: 40px; padding: 0 6px; }
  .cbtn .cl, #backBtn, #fwdBtn, .vol { display: none; }
  .time { padding: 0 4px; font-size: 12px; }
  .stage:not(.idle):not(.noctl) .subs { bottom: calc(80px + 2%); }
  .ovchat { bottom: 92px; width: 80%; }
  .reactpop { grid-template-columns: repeat(3, 44px); }
}

/* ---------- side panels ---------- */
.people { list-style: none; margin: 0; padding: 0; display: grid; }
.people li { display: flex; align-items: center; gap: 10px; min-height: 40px; border-top: 1px solid var(--divider); padding: 4px 0; }
.people li:first-child { border-top: 0; }
.people .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .mk { font: 600 11px/16px var(--font-mono); letter-spacing: 1px; text-transform: uppercase; color: var(--klein); border: 0; background: none; padding: 4px; }
.people .mk:hover { text-decoration: underline; }
.chat { flex: 1; }
.chatbody { display: flex; flex-direction: column; gap: 12px; }
.log { list-style: none; margin: 0; padding: 12px; display: flex; flex-direction: column; gap: 10px; height: 360px; overflow: auto; background: var(--sunken); clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px); }
.log li { display: grid; gap: 0; unicode-bidi: plaintext; }
.log .who { font: 600 12px/16px var(--font-mono); color: var(--klein); }
.log .who.me { color: var(--magenta); }
.log .who time { color: var(--ink-muted); font-weight: 400; margin-left: 8px; }
.log .txt { font: 400 15px/22px var(--font-sans); overflow-wrap: anywhere; }
.log .sys { font: 400 12px/16px var(--font-mono); color: var(--ink-muted); }
.compose { display: flex; gap: 8px; }
.compose .field { flex: 1; }
@media (max-width: 1024px) { .log { height: 260px; } }

/* ---------- library ---------- */
.libtop { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4); }
.upload { position: relative; overflow: hidden; }
.upload input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.upload:focus-within { outline: 2px solid var(--klein); outline-offset: 2px; }
.uploadstate { font: 500 13px/20px var(--font-mono); color: var(--cyan); }
.uploadstate.err { color: var(--danger); font-family: var(--font-sans); }
.tablewrap { --line: var(--hairline); --fill: var(--surface); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font: 400 15px/22px var(--font-sans); }
.table th { background: var(--sunken); text-align: left; padding: 8px 12px; font: 600 11px/16px var(--font-mono); letter-spacing: 1px; text-transform: uppercase; color: var(--ink-muted); white-space: nowrap; }
.table td { padding: 8px 12px; border-top: 1px solid var(--divider); vertical-align: middle; }
.table tbody tr { transition: background-color var(--duration-fast) var(--ease-out); }
.table tbody tr:hover, .table tbody tr.on { background: var(--klein-tint); }
.table .r { text-align: right; }
.table .mono { font: 400 13px/20px var(--font-mono); font-variant-numeric: tabular-nums; color: var(--ink-muted); white-space: nowrap; }
.table .tname { font-weight: 600; overflow-wrap: anywhere; }
.table .tsub { font: 400 12px/16px var(--font-mono); color: var(--ink-muted); }
.table .acts { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.table .emptyrow td { color: var(--ink-muted); text-align: center; padding: 24px; }
@media (max-width: 640px) {
  .table thead { display: none; }
  .table tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 10px 12px; border-top: 1px solid var(--divider); }
  .table td { padding: 0; border: 0; }
  .table td.c-name { grid-column: 1 / -1; }
  .table td.c-len, .table td.c-size { display: inline; }
  .table td.c-act { grid-column: 1 / -1; }
  .table .acts { justify-content: flex-start; }
}

/* ---------- modal ---------- */
.scrim { position: fixed; inset: 0; z-index: var(--z-modal); display: grid; place-items: center; padding: var(--space-4); background: rgba(6, 8, 12, 0.72); overflow: auto; }
:root[data-theme="light"] .scrim { background: rgba(11, 16, 32, 0.4); }
.modal { width: min(640px, 100%); max-height: calc(100dvh - 32px); overflow: auto; filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.5)); }
.modal.small { width: min(420px, 100%); }
.form { display: grid; gap: var(--space-6); }
.form .group { display: grid; gap: var(--space-2); }
.form .group + .group { border-top: 1px solid var(--divider); padding-top: var(--space-6); }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0; }
.seg { --line: var(--border-control); --fill: var(--surface); display: inline-flex; padding: 3px; gap: 3px; justify-self: start; }
.seg button { height: 32px; padding: 0 14px; border: 0; background: transparent; color: var(--ink-muted); font: 600 13px/1 var(--font-sans); clip-path: polygon(5px 0, 100% 0, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0 100%, 0 5px); transition: background-color var(--duration-fast) var(--ease-out); }
.seg button[aria-checked="true"] { background: var(--klein); color: var(--on-accent); }
.offset { display: grid; gap: 6px; }
.ofrow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ofrow input[type=range] { flex: 1 1 140px; accent-color: var(--klein); height: 32px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 32px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--klein); }
.check input:disabled + span { color: var(--ink-muted); }
.kpis { display: flex; gap: var(--space-8); }
.kpis > div { display: grid; }
.gatewm { margin: 0; font-size: 40px; line-height: 44px; }
.gate .hint code { color: var(--cyan); }

/* ---------- toast ---------- */
.toast { --fill: var(--surface); --line: var(--border-control); position: fixed; left: 50%; bottom: 24px; z-index: var(--z-toast); transform: translateX(-50%); padding: 10px 16px; font: 400 15px/22px var(--font-sans); color: var(--ink); max-width: calc(100vw - 32px); filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.5)); }
.toast.bad { --fill: var(--danger); --line: var(--danger); color: var(--on-accent); }
@media (max-width: 480px) { #muteBtn { display: none; } .controls .cbtn { min-width: 38px; padding: 0 4px; } }
.formerr { margin: 0; font: 400 13px/20px var(--font-sans); color: var(--danger); }
