:root {
  --bg: #0c0a0f;
  --surface: #16131b;
  --surface-2: #1f1b26;
  --line: #2c2735;
  --text: #f4f0f8;
  --muted: #9d95ab;
  --accent: #e8476a;
  --accent-2: #ff7a93;
  --gold: #f3c562;
  --ok: #4fd18b;
  --warn: #f5b942;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100dvh; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; border-radius: 12px; padding: 11px 16px; background: var(--surface-2); transition: transform .08s, background .15s, opacity .15s; }
button:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: default; transform: none; }
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-2); }
button.quiet { background: transparent; border: 1px solid var(--line); }
button.icon { padding: 8px; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: transparent; }
input, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
input[type=range] { padding: 0; border: 0; background: transparent; accent-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }

/* ---------- home ---------- */
.home { min-height: 100dvh; display: grid; place-items: center; padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b));
  background: radial-gradient(ellipse 80% 50% at 50% 0%, #3a1020 0%, transparent 70%), var(--bg); }
.home-inner { width: min(420px, 100%); }
.brand { text-align: center; margin-bottom: 28px; }
.brand .logo { width: 64px; height: 64px; }
.brand h1 { font-size: 30px; margin: 10px 0 4px; letter-spacing: -.5px; }
.brand p { margin: 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 20px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--bg); padding: 4px; border-radius: 12px; margin-bottom: 8px; }
.tabs button { padding: 9px; background: transparent; color: var(--muted); border-radius: 9px; }
.tabs button.on { background: var(--surface-2); color: var(--text); }
.card .primary { width: 100%; margin-top: 18px; padding: 14px; }
.error { color: var(--accent-2); min-height: 18px; font-size: 13px; margin-top: 10px; }
.install-hint { margin-top: 16px; text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- room ---------- */
.room { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-t)) 12px 8px; border-bottom: 1px solid var(--line); }
.topbar .title { min-width: 0; flex: 1; }
.topbar .title strong { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title span { font-size: 12px; color: var(--muted); }
.faces { display: flex; }
.face { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #111; border: 2px solid var(--bg); margin-left: -6px; position: relative; flex: none; }
.face .badge { position: absolute; right: -6px; bottom: -6px; font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.ok { background: var(--ok); }

.main { flex: 1; display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.main > * { min-width: 0; }
.stage-wrap { display: flex; flex-direction: column; min-height: 0; padding: 12px; gap: 10px; }
.stage { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; width: 100%; max-height: calc(100dvh - 150px); margin: 0 auto; }
.stage video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.stage.theater { position: fixed; inset: 0; z-index: 50; border-radius: 0; max-height: none; aspect-ratio: auto; }
.stage:fullscreen { border-radius: 0; max-height: none; aspect-ratio: auto; }

.subs { position: absolute; left: 4%; right: 4%; bottom: 12%; text-align: center; pointer-events: none; white-space: pre-line; line-height: 1.3; z-index: 2; transition: bottom .2s; }
.stage.show-ui .subs { bottom: calc(76px + var(--safe-b)); }
.subs span { background: rgba(0,0,0,.72); padding: 2px 10px; border-radius: 6px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }

.controls { position: absolute; inset: auto 0 0 0; z-index: 4; padding: 28px 12px calc(10px + var(--safe-b)); background: linear-gradient(transparent, rgba(0,0,0,.85)); display: flex; flex-direction: column; gap: 6px; opacity: 0; transition: opacity .25s; pointer-events: none; }
.stage.show-ui .controls { opacity: 1; pointer-events: auto; }
.controls .seekrow { display: flex; align-items: center; gap: 10px; font-size: 12px; font-variant-numeric: tabular-nums; }
.controls .seekrow input { flex: 1; }
.controls .btnrow { display: flex; align-items: center; gap: 4px; }
.controls button.icon { color: #fff; font-size: 18px; }
.controls button.icon.on { background: rgba(255,255,255,.15); }
.controls .vol { width: 90px; }
.controls.locked .drive { opacity: .35; }
.center-play { position: absolute; inset: 0; margin: auto; width: 72px; height: 72px; border-radius: 50%; background: rgba(0,0,0,.55); font-size: 28px; z-index: 3; color: #fff; }
.banner { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6; background: rgba(12,10,15,.9); border: 1px solid var(--line); padding: 7px 14px; border-radius: 99px; font-size: 13px; max-width: 92%; text-align: center; }
.react-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.float-emoji { position: absolute; bottom: 70px; font-size: 38px; text-align: center; animation: floatUp 3s ease-out forwards; }
.float-emoji small { display: block; font-size: 11px; font-weight: 600; text-shadow: 0 1px 3px #000; }
@keyframes floatUp { from { transform: translateY(0) scale(.8); opacity: 1; } to { transform: translateY(-240px) scale(1.15); opacity: 0; } }

.reactbar { display: flex; gap: 6px; align-items: center; overflow-x: auto; scrollbar-width: none; }
.reactbar button { font-size: 20px; padding: 6px 10px; background: var(--surface); border-radius: 99px; flex: none; }
.reactbar .last { font-size: 12px; color: var(--muted); margin-left: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vote-bar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 12px 14px; border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 60%, transparent); font-size: 14px; }
.vote-bar .grow { min-width: 180px; }
.vote-bar button { padding: 7px 14px; }

/* side panel */
.panel { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.panel-tabs { display: flex; border-bottom: 1px solid var(--line); }
.panel-tabs button { flex: 1; background: transparent; border-radius: 0; padding: 12px 6px; color: var(--muted); font-size: 13px; border-bottom: 2px solid transparent; position: relative; }
.panel-tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.panel-tabs .unread::after { content: ''; position: absolute; top: 9px; right: calc(50% - 26px); width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.pane { flex: 1; overflow-y: auto; padding: 14px 16px calc(16px + var(--safe-b)); min-height: 0; }
.pane h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.pane h3:first-child { margin-top: 2px; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.people li:last-child { border-bottom: 0; }
.people .face { margin: 0; width: 34px; height: 34px; font-size: 14px; border: 0; }
.people .who { flex: 1; min-width: 0; }
.people .who b { display: block; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.people .who span { font-size: 12px; color: var(--muted); }
.people .who span.ready { color: var(--ok); }
.people button.mini { font-size: 12px; padding: 5px 10px; border-radius: 8px; background: var(--surface-2); flex: none; }
.chat-log { display: flex; flex-direction: column; gap: 6px; }
.chat-line { font-size: 14px; word-break: break-word; }
.chat-line b { font-weight: 600; }
.chat-line.system { color: var(--muted); font-size: 12px; text-align: center; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); }
.chat-form button { padding: 10px 14px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0; font-size: 14px; }
.setting input[type=range] { width: 140px; }
.setting input[type=number] { width: 90px; padding: 8px 10px; }
.filebtn { display: block; text-align: center; padding: 11px 16px; border-radius: 12px; background: var(--surface-2); cursor: pointer; font-size: 14px; color: var(--text); margin: 0; }
.filebtn input { display: none; }

/* pre-show lobby */
.preshow { position: absolute; inset: 0; z-index: 7; display: flex; flex-direction: column; background: radial-gradient(ellipse at 50% 35%, #4a1426 0%, #12070c 60%, #050306 100%); }
.preshow video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.curtain-l, .curtain-r { position: absolute; top: 0; bottom: 0; width: 9%; background: repeating-linear-gradient(90deg, #5a0f22 0 14px, #460b1a 14px 28px); box-shadow: inset -10px 0 30px rgba(0,0,0,.6); pointer-events: none; }
.curtain-l { left: 0; } .curtain-r { right: 0; transform: scaleX(-1); }
.slide { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; min-width: 0; overflow-wrap: anywhere; padding: 16px 12%; position: relative; font-size: clamp(20px, 4.2vw, 46px); font-weight: 700; letter-spacing: -.3px; animation: fadeIn .8s; }
.slide small { display: block; font-size: .42em; font-weight: 400; color: #d9c7cf; margin-top: 8px; letter-spacing: 0; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.lobby-bar { position: relative; z-index: 2; margin-top: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 12px; background: rgba(0,0,0,.65); backdrop-filter: blur(6px); }
.lobby-status { flex-basis: 100%; font-size: 13px; color: #e5d9df; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.chip { font-size: 12px; background: rgba(255,255,255,.1); border-radius: 99px; padding: 4px 10px 4px 4px; display: flex; align-items: center; gap: 6px; }
.chip i { width: 18px; height: 18px; border-radius: 50%; display: inline-block; flex: none; }
.chip.go { background: color-mix(in srgb, var(--ok) 30%, transparent); }
.lobby-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.lobby-actions button { padding: 9px 14px; }
#readyBtn.on { background: var(--ok); color: #06210f; }
.countdown { position: absolute; inset: 0; z-index: 3; display: grid; place-content: center; text-align: center; line-height: 1; font-size: clamp(56px, 10vw, 128px); font-weight: 800; background: rgba(0,0,0,.6); }
.countdown small { display: block; font-size: clamp(15px, 2.2vw, 26px); font-weight: 600; color: #e5d9df; margin-bottom: 10px; }
.sound-btn { position: absolute; top: 12px; right: 12px; z-index: 3; background: rgba(0,0,0,.6); padding: 7px 12px; font-size: 13px; }
.progress { height: 6px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; flex-basis: 100%; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .4s; }

/* name sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.6); display: grid; place-items: end center; }
.sheet { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 22px 20px calc(22px + var(--safe-b)); }
@media (min-width: 700px) { .sheet-wrap { place-items: center; } .sheet { border-radius: 20px; } }
.sheet h2 { margin: 0 0 4px; font-size: 20px; }
.sheet .primary { width: 100%; margin-top: 16px; padding: 13px; }

/* ---------- phones ---------- */
@media (max-width: 860px) {
  .slide { padding: 12px 14%; }
  .lobby-bar { padding: 8px 10px; gap: 6px 8px; }
  .chip { font-size: 11px; }
  .main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .stage-wrap { padding: 0; gap: 0; }
  .stage { border-radius: 0; max-height: 46dvh; }
  .reactbar { padding: 8px 12px; border-bottom: 1px solid var(--line); }
  .vote-bar { margin: 8px 12px; }
  .panel { border-left: 0; }
  .controls .vol { display: none; }
  .hide-phone { display: none; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .stage:not(.theater) { max-height: 70dvh; }
}

.agree-list { margin: 12px 0; padding-left: 20px; display: grid; gap: 8px; line-height: 1.45; }
.agree-list + p a { color: inherit; }
.agree-cancel { width: 100%; margin-top: 8px; }
