:root {
  --bg: #0e0f13;
  --surface: #16171d;
  --surface-2: #1e2028;
  --line: #2a2c36;
  --text: #ecedf1;
  --muted: #8b8e9c;
  --accent: #f5b544;
  --accent-ink: #1a1408;
  --good: #4ccb8d;
  --warn: #f5b544;
  --bad: #f06a6a;
  --peer: #6aa8ff;
  --cached: #4a4d5a;
  --radius: 12px;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---- buttons & inputs ---- */
.btn {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #262833; border-color: #3a3d4a; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: #ffc35a; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.tiny { padding: 2px 10px; }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type='range'] { padding: 0; accent-color: var(--accent); background: none; border: 0; }

kbd {
  font: 11px var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  margin: 0 1px;
}

.logo { font-weight: 800; font-size: 18px; letter-spacing: -0.02em; color: var(--text); text-decoration: none; }
.logo span { color: var(--accent); margin-left: 1px; }
.logo.big { font-size: 44px; margin: 0 0 8px; }

/* ---- landing ---- */
.landing { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.landing-card { max-width: 440px; text-align: center; }
.lede { color: var(--muted); font-size: 16px; margin: 0 0 28px; }
.landing .btn.primary { padding: 12px 28px; font-size: 16px; }
.join { display: flex; gap: 8px; margin-top: 20px; }
.join input { flex: 1; }

/* ---- room layout ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}
.conn { display: flex; align-items: center; gap: 8px; color: var(--muted); flex: 1; min-width: 0; }
.conn span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.good { background: var(--good); box-shadow: 0 0 0 3px rgb(76 203 141 / 0.18); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .keys { display: none; }
}

/* ---- stage ---- */
.stage {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
}
.screen {
  position: relative;
  aspect-ratio: 16 / 9;
  container-type: size;
  background: #000;
}
video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }

.subs {
  --sub-scale: 1;
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 6%;
  text-align: center;
  pointer-events: none;
  font-size: calc(4.6cqh * var(--sub-scale));
  font-weight: 600;
  line-height: 1.25;
  color: #fff;
  text-shadow: 0 0 4px #000, 0 0 2px #000, 0 2px 3px rgb(0 0 0 / 0.9);
}
.subs:empty { display: none; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, #1a1b22 0%, #0b0c0f 70%);
}
.empty > div { max-width: 380px; }
.empty-title { font-size: 20px; font-weight: 600; margin: 0 0 6px; }
.empty .muted { margin: 0 0 18px; }
.stage.drag .empty {
  outline: 2px dashed var(--accent);
  outline-offset: -12px;
}

.notice {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgb(14 15 19 / 0.82);
  backdrop-filter: blur(6px);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 500;
  display: flex;
  gap: 10px;
  align-items: center;
  white-space: nowrap;
}
.notice::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.unlock {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.55);
  color: var(--text);
  border: 0;
  font: 600 18px system-ui;
  cursor: pointer;
}

.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translate(-50%, -8px);
  background: rgb(14 15 19 / 0.85);
  backdrop-filter: blur(6px);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- controls ---- */
.controls { background: var(--surface); padding: 6px 12px 8px; border-top: 1px solid var(--line); }
.seek { position: relative; height: 18px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.seek-track { position: relative; height: 4px; width: 100%; border-radius: 2px; background: #2e3039; transition: height 0.1s; }
.seek:hover .seek-track { height: 6px; }
.seek-buf, .seek-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 2px; }
.seek-buf { background: #4a4d5a; }
.seek-fill { background: var(--accent); }
.seek-fill::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.1s;
}
.seek:hover .seek-fill::after { opacity: 1; }
.seek-peer { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--peer); border-radius: 1px; }
.seek-tip {
  position: absolute;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 6px;
  font: 12px var(--mono);
  pointer-events: none;
  white-space: nowrap;
}

.ctrl-row { display: flex; align-items: center; gap: 4px; }
.spacer { flex: 1; }
.icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  flex: none;
}
.icon:hover { background: var(--surface-2); }
.icon svg { width: 20px; height: 20px; fill: currentColor; }
#b-mute svg, #b-fs svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#b-mute svg path:first-child { fill: currentColor; stroke: none; }
.play svg { width: 24px; height: 24px; }
.play .i-pause, .playing .play .i-play { display: none; }
.playing .play .i-pause { display: block; }
#b-mute .i-mute, .muted-on #b-mute .i-vol { display: none; }
.muted-on #b-mute .i-mute { display: block; }
.cc { font: 700 11px system-ui; letter-spacing: 0.02em; color: var(--muted); }
.cc.on { color: var(--text); }

.tc { font: 600 15px var(--mono); font-variant-numeric: tabular-nums; margin-left: 8px; white-space: nowrap; }
.tc-sep { color: var(--muted); margin: 0 6px; font-weight: 400; }
#rate { padding: 4px 6px; background: transparent; border-color: transparent; color: var(--muted); }
#rate:hover { border-color: var(--line); }
.vol { width: 80px; }

@media (max-width: 600px) {
  .vol, #rate, #tc-dur, .tc-sep { display: none; }
  .tc { font-size: 13px; margin-left: 4px; }
}

/* fullscreen: controls float over the picture and hide when idle */
.stage:fullscreen { border: 0; border-radius: 0; }
.stage:fullscreen .screen { aspect-ratio: auto; flex: 1; }
.stage:fullscreen .controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(transparent, rgb(0 0 0 / 0.85));
  border: 0;
  padding: 24px 24px 14px;
  transition: opacity 0.25s;
}
.stage:fullscreen.idle .controls { opacity: 0; }
.stage:fullscreen.idle { cursor: none; }
.stage:fullscreen .subs { transition: bottom 0.25s; }
.stage:fullscreen:not(.idle) .subs { bottom: 14%; }

/* ---- sidebar ---- */
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.info { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 6px 10px; margin: 12px 0 0; align-items: center; }
.info dt { color: var(--muted); }
.info dd { margin: 0; overflow-wrap: anywhere; }
.info select { padding: 3px 6px; }
.row { display: flex; align-items: center; gap: 8px; }
#s-off { min-width: 64px; text-align: center; }
.goto { display: flex; gap: 8px; margin-top: 12px; }
.goto input { flex: 1; }
.keys p { margin: 0; color: var(--muted); line-height: 2; font-size: 12px; }
.good-t { color: var(--good); }
.warn-t { color: var(--warn); }
.bad-t { color: var(--bad); }

/* Bucket picker */
#pick-bucket { margin-top: 8px; }
.bucket { width: min(560px, calc(100vw - 32px)); max-height: min(70vh, 640px); padding: 14px; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); }
.bucket[open] { display: flex; flex-direction: column; gap: 10px; }
.bucket::backdrop { background: rgb(0 0 0 / 0.6); }
.bucket-head { display: flex; align-items: center; justify-content: space-between; }
.bucket-head h2 { font-size: 14px; margin: 0; }
.bucket-list { list-style: none; margin: 0; padding: 0; overflow: auto; }
.bucket-list button { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%; text-align: left; font: inherit; color: inherit; background: none; border: 0; border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.bucket-list button:hover, .bucket-list button:focus-visible { background: var(--surface-2); }
.bucket-list .name { overflow-wrap: anywhere; }
.bucket-list .meta, .bucket-list .muted { color: var(--muted); font-size: 12px; }
.bucket-list .muted { padding: 8px 10px; }

/* Sign-in */
.login { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login .logo, .login > p { text-align: center; margin-top: 0; }
.login label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login input { padding: 10px 12px; font-size: 15px; }
.login .btn.primary { margin-top: 6px; }
.login-error { margin: 0; padding: 10px 12px; border-radius: 8px; background: rgb(240 106 106 / 0.12); color: var(--bad); font-size: 13px; }
.login-error code { font-family: var(--mono); }
.user { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }
.user form { margin: 0; }
.landing-user { justify-content: center; margin-top: 28px; font-size: 13px; }
@media (max-width: 640px) { .topbar .me-name { display: none; } }
