:root, [data-theme="dark"] {
  --bg: #0d0e12; --panel: #15171d; --panel-2: #1c1f27; --hover: #242833;
  --border: #2a2e39; --text: #eceef3; --muted: #8f96a5;
  --accent: #f5b341; --accent-ink: #1d1404; --accent-soft: rgba(245,179,65,.14);
  --danger: #ff6b6b; --ok: #4ade80; --shadow: 0 10px 30px rgba(0,0,0,.45);
  --track: rgba(255,255,255,.18);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f4f4f7; --panel: #ffffff; --panel-2: #f0f1f5; --hover: #e7e9ef;
  --border: #e0e2e9; --text: #15171c; --muted: #5d6474;
  --accent: #e09a1b; --accent-ink: #1d1404; --accent-soft: rgba(224,154,27,.14);
  --danger: #d93b3b; --ok: #16a34a; --shadow: 0 10px 30px rgba(20,20,40,.12);
  --track: rgba(0,0,0,.14);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 Inter, system-ui, sans-serif; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: var(--text); }
svg { width: 20px; height: 20px; flex: none; }
.hidden { display: none !important; }
.logo { font-family: "Bricolage Grotesque", Inter, sans-serif; font-weight: 700; font-size: 20px; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; }
.logo-mark { width: 30px; height: 30px; color: var(--accent); display: grid; place-items: center; }
.logo-mark svg { width: 30px; height: 30px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2); font-weight: 500; transition: background .15s, transform .05s; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn[aria-busy="true"] { opacity: .6; pointer-events: none; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.field { height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2); outline: none; width: 100%; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.invalid { border-color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Landing */
#landing { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.landing-card { width: 100%; max-width: 440px; }
.landing-card .logo { font-size: 28px; margin-bottom: 8px; }
.landing-card .logo-mark, .landing-card .logo-mark svg { width: 44px; height: 44px; }
.tagline { color: var(--muted); font-size: 16px; margin: 0 0 28px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 22px; }
.label { font-size: 12px; font-weight: 500; color: var(--muted); margin: 0 0 6px; display: block; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.join-row { display: flex; gap: 8px; }
.join-row .field { text-transform: uppercase; letter-spacing: .2em; font-family: ui-monospace, monospace; }
.join-row .field::placeholder { text-transform: none; }
.err { color: var(--danger); font-size: 12px; margin-top: 6px; min-height: 18px; }
.landing-top { position: fixed; top: 14px; right: 14px; }

/* Room */
#room { height: 100%; display: grid; grid-template-rows: auto minmax(0,1fr); }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.code-chip { font-family: ui-monospace, monospace; letter-spacing: .15em; background: var(--panel-2); border: 1px solid var(--border); padding: 4px 10px; border-radius: 8px; font-size: 13px; }
.spacer { flex: 1; }
.people { display: flex; align-items: center; }
.avatar { position: relative; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; color: #111; border: 2px solid var(--panel); margin-left: -6px; cursor: pointer; transition: transform .1s; }
.avatar:first-child { margin-left: 0; }
.avatar:hover { transform: translateY(-2px); z-index: 2; }
.avatar.offline { opacity: .4; }
.avatar .crown { position: absolute; top: -9px; left: 50%; transform: translateX(-50%); color: var(--accent); }
.avatar .crown svg { width: 14px; height: 14px; }
.avatar .dot { position: absolute; bottom: -1px; right: -1px; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); border: 2px solid var(--panel); }
.avatar .dot.buffering { background: var(--accent); }
.avatar.offline .dot { background: var(--muted); }
.sync-pill { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.sync-pill.waiting { color: var(--accent); background: var(--accent-soft); }
.sync-pill.offline { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.sync-pill .pulse { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.menu { position: absolute; z-index: 50; min-width: 210px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; }
.menu-head { padding: 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-head b { display: block; font-weight: 600; }
.menu-head span { color: var(--muted); font-size: 12px; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu button svg { width: 16px; height: 16px; }
.menu .note { padding: 8px 10px; color: var(--muted); font-size: 12px; }

.main { display: grid; grid-template-columns: minmax(0,1fr) 360px; min-height: 0; }
.stage-col { padding: 18px; overflow-y: auto; }
.player-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; margin: 0 auto; max-width: min(100%, calc((100vh - 270px) * 16 / 9)); }
.player { position: relative; aspect-ratio: 16 / 9; background: #000; }
.player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.empty-stage { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #9aa0ad; padding: 20px; background: #000; }
.empty-stage svg { width: 36px; height: 36px; opacity: .5; }
.empty-stage p { margin: 8px 0 0; }
.player-wrap:fullscreen { max-width: none; width: 100vw; height: 100vh; border-radius: 0; border: 0; display: flex; flex-direction: column; }
.player-wrap:fullscreen .player { flex: 1; aspect-ratio: auto; }
.notice { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px 12px; font-size: 13px; background: var(--accent-soft); color: var(--text); }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--track); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { padding: 4px 10px 6px; }
.ctrl-row { display: flex; align-items: center; gap: 4px; }
.time { font-size: 13px; font-variant-numeric: tabular-nums; margin: 0 8px; white-space: nowrap; color: var(--muted); }
.range { -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; height: 16px; margin: 0; }
.range::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--accent) var(--p,0%), var(--track) var(--p,0%)); }
.range::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--accent) var(--p,0%), var(--track) var(--p,0%)); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); margin-top: -5px; border: 0; }
.range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 0; }
.seek { width: 100%; display: block; }
.vol-wrap { display: flex; align-items: center; }
.vol { width: 0; opacity: 0; transition: width .2s, opacity .2s; }
.vol-wrap:hover .vol, .vol:focus { width: 80px; opacity: 1; margin-right: 6px; }
.now { margin-top: 14px; }
.now h2 { margin: 0; font-size: 18px; font-weight: 600; }
.now p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.kbd-hint { color: var(--muted); font-size: 12px; margin-top: 18px; display: flex; flex-wrap: wrap; gap: 6px 14px; }
kbd { font-family: ui-monospace, monospace; font-size: 11px; background: var(--panel-2); border: 1px solid var(--border); border-bottom-width: 2px; padding: 1px 6px; border-radius: 5px; }

.side { border-left: 1px solid var(--border); background: var(--panel); display: grid; grid-template-rows: auto minmax(0,1fr) auto auto minmax(0,1.2fr) auto; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; font-weight: 600; }
.side-head .count { color: var(--muted); font-weight: 400; margin-left: 6px; }
.chat-head { border-top: 1px solid var(--border); }
.add-row { padding: 0 16px 12px; display: flex; gap: 6px; }
.add-row .field { height: 38px; font-size: 13px; }
.queue { overflow-y: auto; padding: 0 10px 10px; }
.q-item { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; cursor: pointer; }
.q-item:hover { background: var(--hover); }
.q-item.dragging { opacity: .4; }
.q-item.over { box-shadow: inset 0 2px 0 var(--accent); }
.grip { color: var(--muted); cursor: grab; opacity: .6; }
.grip svg { width: 16px; height: 16px; }
.thumb { width: 72px; height: 40px; border-radius: 6px; flex: none; background: var(--panel-2) center / cover; }
.q-text { min-width: 0; flex: 1; }
.q-text b { display: block; font-weight: 500; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-text small { color: var(--muted); font-size: 12px; }
.q-item .icon-btn { width: 28px; height: 28px; opacity: 0; }
.q-item:hover .icon-btn, .q-item .icon-btn:focus-visible { opacity: 1; }
.q-item .icon-btn svg { width: 16px; height: 16px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 10px; }
.chat { overflow-y: auto; padding: 0 16px 8px; display: flex; flex-direction: column; gap: 8px; }
.msg { font-size: 13px; overflow-wrap: anywhere; }
.msg b { font-weight: 600; margin-right: 6px; }
.msg.sys { color: var(--muted); font-size: 12px; text-align: center; }
.chat-form { display: flex; gap: 6px; padding: 10px 16px 14px; }
.chat-form .field { height: 38px; font-size: 13px; }
.send { width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.send svg { width: 18px; height: 18px; }

.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 90; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--panel); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 8px 14px; border-radius: 99px; font-size: 13px; animation: tin .2s ease-out; text-align: center; }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }

.dialog-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 80; padding: 16px; }
.dialog { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); }
.dialog h3 { margin: 0 0 4px; font-size: 17px; }
.dialog p { margin: 0 0 16px; color: var(--muted); }
.dialog .row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 900px) {
  #room { height: auto; min-height: 100%; }
  .main { grid-template-columns: 1fr; }
  .side { border-left: 0; border-top: 1px solid var(--border); grid-template-rows: none; }
  .queue { max-height: 300px; }
  .chat { height: 260px; }
  .stage-col { padding: 0; }
  .player-wrap { border-radius: 0; border-left: 0; border-right: 0; max-width: none; }
  .now { padding: 0 16px; }
  .kbd-hint { display: none; }
  .hide-sm { display: none; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .sync-pill { display: none; }
}
