:root {
  --bg: #0b0d12;
  --surface: #141821;
  --surface-2: #1b2130;
  --line: #262d3d;
  --text: #e9edf5;
  --muted: #8f99ad;
  --accent: #4f8cff;
  --accent-ink: #0b1224;
  --live: #ff4d5e;
  --star: #ffc24b;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
img { display: block; }

.muted { color: var(--muted); }

/* Boot + spinner */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .15); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Brand */
.brand-mark {
  width: 56px; height: 40px; border-radius: 10px; background: var(--accent);
  position: relative; display: grid; place-items: center; margin: 0 auto 18px;
  box-shadow: 0 10px 40px rgba(79, 140, 255, .35);
}
.brand-mark span { width: 14px; height: 14px; border-radius: 50%; background: var(--bg); }
.brand-mark.small { width: 30px; height: 22px; border-radius: 6px; margin: 0; box-shadow: none; }
.brand-mark.small span { width: 8px; height: 8px; }

/* Sign-in */
.signin {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(800px 400px at 50% 0%, rgba(79, 140, 255, .16), transparent 70%);
}
.signin-card {
  width: 100%; max-width: 400px; text-align: center; padding: 40px 28px 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
}
.signin h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: -.02em; }
.lede { margin: 0 0 24px; color: var(--muted); }
.discord-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 13px 18px; border-radius: 12px; text-decoration: none;
  background: #5865f2; color: #fff; font-weight: 600;
  transition: background .15s, transform .15s;
}
.discord-btn:hover { background: #4752c4; }
.discord-btn:active { transform: translateY(1px); }
.discord-btn svg { width: 22px; height: 22px; }
.fine { margin: 18px 0 0; font-size: 12.5px; color: var(--muted); }
.signin-error {
  margin: 0 0 18px; padding: 10px 12px; border-radius: 10px; font-size: 14px;
  background: rgba(255, 77, 94, .12); color: #ffb3bb; border: 1px solid rgba(255, 77, 94, .3);
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px max(16px, env(safe-area-inset-left));
  background: rgba(11, 13, 18, .85); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me img { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); }
.me span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; color: var(--muted); }
.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 9px; padding: 6px 12px;
  transition: background .15s, border-color .15s;
}
.ghost:hover { background: var(--surface-2); border-color: #34405a; }
.icon { background: transparent; border: 0; font-size: 18px; color: var(--muted); padding: 4px 8px; border-radius: 8px; }
.icon:hover { color: var(--text); background: var(--surface-2); }

/* Player */
.player {
  display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 0;
  max-width: 1440px; margin: 16px auto 0; padding: 0 16px;
}
.stage { align-self: start; position: relative; background: #000; border-radius: var(--radius) 0 0 var(--radius); overflow: hidden; aspect-ratio: 16 / 9; }
.stage video { width: 100%; height: 100%; display: block; background: #000; object-fit: contain; }
.stage-overlay {
  position: absolute; inset: 0; z-index: 1; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: rgba(0, 0, 0, .6); text-align: center; padding: 16px;
}
.stage:fullscreen { border-radius: 0; aspect-ratio: auto; width: 100vw; height: 100vh; }
.stage:-webkit-full-screen { border-radius: 0; aspect-ratio: auto; width: 100vw; height: 100vh; }
.stage.idle { cursor: none; }

/* Player controls: no seek bar, since live and in step is the point. */
.controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  display: flex; align-items: center; gap: 4px; padding: 32px 12px 10px;
  background: linear-gradient(to top, rgba(0, 0, 0, .78), rgba(0, 0, 0, 0));
  transition: opacity .2s;
}
.stage.idle .controls { opacity: 0; pointer-events: none; }
.ctl {
  display: grid; place-items: center; padding: 6px; border: 0; border-radius: 8px;
  background: transparent; color: #fff;
}
.ctl:hover { background: rgba(255, 255, 255, .14); }
.ctl:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ctl svg { display: block; width: 22px; height: 22px; }
.ctl .when-on, .ctl.on .when-off { display: none; }
.ctl.on .when-on { display: block; }
.ctl[aria-pressed="true"] { color: var(--accent); }
.volume { width: 84px; margin-right: 6px; accent-color: #fff; }
.live-pill {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: #fff; background: var(--live); border-radius: 6px; padding: 2px 8px;
}
.live-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: pulse 1.6s ease-in-out infinite; }
.stage.paused .live-pill { background: #4a5163; }
.stage.paused .live-pill .dot { animation: none; }
.sync-badge {
  min-width: 0; margin-left: 4px; padding: 2px 8px; border-radius: 6px;
  font-size: 12.5px; color: #dfe5f0; background: rgba(255, 255, 255, .12);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sync-badge[data-state="good"] { color: #b6f2c6; background: rgba(46, 204, 113, .2); }
.sync-badge[data-state="bad"] { color: #ffd3ad; background: rgba(255, 159, 67, .22); }
.grow { flex: 1; }
.quality { margin-right: 4px; font-size: 12px; color: #cfd6e4; font-variant-numeric: tabular-nums; }
.unmute {
  position: absolute; left: 50%; top: 50%; z-index: 3; transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border: 0; border-radius: 12px;
  background: rgba(0, 0, 0, .78); color: #fff; font-weight: 600;
}
.unmute svg { width: 22px; height: 22px; }
.stage-overlay p { margin: 0; color: #cfd6e4; }
.now {
  background: var(--surface); border: 1px solid var(--line); border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0; padding: 18px; overflow: auto;
}
.now-head { display: flex; align-items: center; gap: 12px; }
.now-head > div { flex: 1; min-width: 0; }
.now-head > .logo { flex: none; } /* a fallback logo is a div too; keep it logo-sized */
.logo {
  width: 52px; height: 36px; object-fit: contain; border-radius: 6px;
  background: var(--surface-2); padding: 3px;
}
.now-channel { font-weight: 700; }
.now-watching { font-size: 13px; color: var(--muted); }
.now h2 { margin: 16px 0 2px; font-size: 20px; line-height: 1.25; letter-spacing: -.01em; }
.episode { margin: 0 0 12px; color: var(--muted); }
.synopsis { color: #c3cad8; font-size: 14px; }
.upnext { list-style: none; margin: 16px 0 0; padding: 0; border-top: 1px solid var(--line); }
.upnext li { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.upnext time { color: var(--muted); min-width: 64px; font-variant-numeric: tabular-nums; }
.surf { display: flex; gap: 8px; margin-top: 16px; }
.surf button { flex: 1; }

.bar { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; }

/* Toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  max-width: 1440px; margin: 20px auto 0; padding: 0 16px;
}
.toolbar input {
  flex: 1 1 260px; max-width: 420px; padding: 10px 14px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; outline: none;
}
.toolbar input:focus { border-color: var(--accent); }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.tabs button { border: 0; background: transparent; padding: 7px 13px; border-radius: 8px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); }
.count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--live); color: #fff; font-size: 12px; text-align: center; }
.count:empty { display: none; }

/* Grid */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px;
  max-width: 1440px; margin: 16px auto 0; padding: 0 16px 24px;
}
.card {
  position: relative; text-align: left; display: flex; flex-direction: column; gap: 10px;
  padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  transition: border-color .15s, transform .15s, background .15s;
}
.card:hover { border-color: #3a4764; background: #161b26; transform: translateY(-1px); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.playing { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card-head { display: flex; align-items: center; gap: 12px; }
.card-head .logo { width: 48px; height: 34px; }
.logo.fallback {
  display: grid; place-items: center; background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 700; padding: 0;
}
.chan { flex: 1; min-width: 0; }
.chan-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.chan-name { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.star { background: transparent; border: 0; padding: 4px; color: #4a5470; font-size: 18px; line-height: 1; border-radius: 6px; }
.star:hover { color: var(--star); }
.star.on { color: var(--star); }
.title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.9em; }
.title.none { color: var(--muted); font-weight: 400; }
.meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  position: absolute; top: 12px; right: 44px; display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  color: #fff; background: var(--live); border-radius: 6px; padding: 2px 7px;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.hd { font-size: 10.5px; font-weight: 700; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 6px; vertical-align: 1px; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.foot { text-align: center; color: #5d6780; font-size: 12.5px; padding: 8px 16px 32px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  max-width: min(520px, calc(100vw - 32px)); padding: 12px 16px; border-radius: 12px;
  background: #222a3b; border: 1px solid #34405a; box-shadow: 0 12px 40px rgba(0, 0, 0, .45);
}
.toast p { margin: 0; }
.toast .live-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.toast .live-list button { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; font-size: 13px; }

/* Theater mode: the video spans the full browser width and the guide moves
   below it. Narrow screens already play edge to edge, so it's desktop-only. */
@media (min-width: 901px) {
  .player.theater {
    grid-template-columns: minmax(0, 1fr); max-width: none; margin-top: 0; padding: 0;
    container-type: inline-size;
  }
  .player.theater .stage {
    border-radius: 0; aspect-ratio: auto;
    /* Full-width 16:9, capped so the whole picture and its controls fit under
       the top bar; a short window letterboxes the sides instead of cropping. */
    height: min(56.25vw, calc(100vh - var(--topbar-h, 61px)));
    height: min(56.25cqw, calc(100dvh - var(--topbar-h, 61px)));
  }
  .player.theater .now {
    justify-self: center; width: calc(100% - 32px); max-width: 1408px; margin-top: 16px;
    border-left: 1px solid var(--line); border-radius: var(--radius);
  }
  .player.theater .now-body { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 0 32px; }
}

@media (max-width: 600px) {
  .volume, .quality { display: none; }
}

@media (max-width: 900px) {
  #theater { display: none; }
  .player { grid-template-columns: 1fr; padding: 0; margin-top: 0; }
  .stage { border-radius: 0; }
  .now { border-radius: 0; border-left: 1px solid var(--line); border-top: 0; max-height: none !important; border-width: 0 0 1px; }
  .me span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
