:root {
  --bg: #0b0c0f;
  --panel: #14161b;
  --panel-2: #1b1e25;
  --line: #262a33;
  --text: #e8eaef;
  --muted: #8b92a1;
  --red: #e10600;
  --amber: #ffb000;
  --green: #22c55e;
  --blue: #3b82f6;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* header */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: rgba(11,12,15,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand b { letter-spacing: .14em; font-size: 16px; }
.brand small { color: var(--muted); }
.flag { width: 22px; height: 16px; border-radius: 2px; background: conic-gradient(#fff 25%, #111 0 50%, #fff 0 75%, #111 0) 0 0 / 8px 8px; box-shadow: 0 0 0 1px #333; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: none; border: 0; padding: 8px 14px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tabs button.active, .tabs button:hover { background: var(--panel-2); color: var(--text); }
.right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.ghost { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; }
.ghost:hover { border-color: #3a404c; }
.pill { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; font-size: 12px; text-align: center; background: var(--panel-2); }
.pill.red { background: var(--red); color: #fff; }

/* filters */
.filters { display: flex; gap: 12px; align-items: center; padding: 12px 20px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 4px 12px; font-size: 13px; color: var(--muted); }
.chip.on { background: var(--text); color: #000; border-color: var(--text); }
.chip .n { margin-left: 6px; font-size: 11px; opacity: .8; }
#search { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; width: 260px; }

main { padding: 0 20px 60px; }
.tab { display: none; }
.tab.active { display: block; }
h2.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 22px 0 10px; font-weight: 700; }
h2.sec small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.empty { color: var(--muted); padding: 20px; background: var(--panel); border-radius: var(--radius); border: 1px dashed var(--line); }

/* theater */
.theater { scroll-margin-top: 70px; background: #000; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-top: 4px; }
.theater-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); gap: 10px; }
#theaterTitle { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layout-btns { display: flex; gap: 4px; flex-shrink: 0; }
.layout-btns button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; width: 32px; height: 28px; }
.layout-btns button.on { border-color: var(--red); }
.players { display: grid; gap: 2px; background: #000; }
.players.l1 { grid-template-columns: 1fr; }
.players.l2 { grid-template-columns: 1fr 1fr; }
.players.l4 { grid-template-columns: 1fr 1fr; }
.player { position: relative; aspect-ratio: 16 / 9; background: #000; }
.players.l1 .player { max-height: calc(100vh - 220px); margin: 0 auto; width: 100%; }
.player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player .x { position: absolute; top: 6px; right: 6px; z-index: 2; background: rgba(0,0,0,.7); border: 0; border-radius: 6px; padding: 2px 8px; opacity: 0; transition: opacity .15s; }
.player:hover .x { opacity: 1; }
.player.focus { outline: 2px solid var(--red); outline-offset: -2px; }

/* live cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card:hover { border-color: #3a404c; }
.thumb { position: relative; aspect-ratio: 16/9; background: #000 center/cover no-repeat; cursor: pointer; }
.thumb .badge { position: absolute; top: 8px; left: 8px; background: var(--red); color: #fff; font-weight: 800; font-size: 11px; letter-spacing: .08em; padding: 2px 7px; border-radius: 4px; }
.thumb .viewers { position: absolute; bottom: 8px; right: 8px; background: rgba(0,0,0,.75); font-size: 12px; padding: 1px 7px; border-radius: 4px; }
.thumb .noembed { position: absolute; bottom: 8px; left: 8px; background: rgba(0,0,0,.75); color: var(--amber); font-size: 11px; padding: 1px 7px; border-radius: 4px; }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.meta img { width: 20px; height: 20px; border-radius: 50%; }
.cat-tag { font-size: 11px; padding: 1px 7px; border-radius: 4px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.actions { display: flex; gap: 6px; margin-top: auto; padding-top: 4px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 6px; padding: 4px 10px; font-size: 12px; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.btn:hover { border-color: #4a5160; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn.sub { border-color: var(--green); color: var(--green); }
.btn.sub::before { content: "✓"; }

/* soon */
.soon { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 8px; }
.soon-row { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.soon-row img.t { width: 96px; aspect-ratio: 16/9; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.soon-row .info { min-width: 0; flex: 1; }
.soon-row .info div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count { font-variant-numeric: tabular-nums; color: var(--amber); font-weight: 700; font-size: 12px; white-space: nowrap; }

/* schedule */
.sched-controls { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin: 6px 0 14px; color: var(--muted); }
.sched-controls select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.day h3 { position: sticky; top: 56px; z-index: 5; margin: 18px 0 6px; padding: 6px 0; background: var(--bg); font-size: 14px; border-bottom: 1px solid var(--line); }
.day h3 .today { color: var(--red); margin-left: 8px; font-size: 12px; }
.ev { display: grid; grid-template-columns: 70px 6px minmax(160px, 260px) 1fr auto; gap: 12px; align-items: center; padding: 7px 8px; border-radius: 6px; }
.ev:nth-child(even) { background: var(--panel); }
.ev .time { font-variant-numeric: tabular-nums; font-weight: 600; }
.ev .bar { width: 4px; height: 26px; border-radius: 2px; background: var(--line); }
.ev .series { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev .what { min-width: 0; }
.ev .what div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev .what small { color: var(--muted); }
.ev.main .what div:first-child { font-weight: 600; }
.ev.past { opacity: .5; }
.ev.now .time { color: var(--red); }
.ev .actions { margin: 0; padding: 0; justify-content: flex-end; }
.src { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; padding: 1px 5px; border-radius: 3px; background: var(--panel-2); color: var(--muted); margin-left: 6px; }

/* category colors */
[data-cat="sportscar"] { --c: #3b82f6; } [data-cat="openwheel"] { --c: #e10600; } [data-cat="touring"] { --c: #f59e0b; }
[data-cat="rally"] { --c: #84cc16; } [data-cat="bikes"] { --c: #a855f7; } [data-cat="club"] { --c: #14b8a6; }
[data-cat="karting"] { --c: #ec4899; } [data-cat="drift"] { --c: #f97316; } [data-cat="historic"] { --c: #a3a3a3; } [data-cat="sim"] { --c: #06b6d4; }
.ev .bar, .card .cat-line { background: var(--c, var(--line)); }
.card .cat-line { height: 3px; }

/* directory */
.add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin: 4px 0 18px; }
.add input, .add select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
.add input { width: 300px; }
.add button { background: var(--red); border: 0; color: #fff; border-radius: 6px; padding: 6px 14px; font-weight: 600; }
.dir-cat h2 { display: flex; align-items: center; gap: 8px; }
.dir-cat h2::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--c); }
.series-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 12px; }
.series-card { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--c); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.series-card h4 { margin: 0; font-size: 15px; }
.series-card .note { font-size: 12px; color: var(--muted); }
.chlist { display: flex; flex-wrap: wrap; gap: 6px; }
.ch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 8px 2px 2px; border-radius: 99px; background: var(--panel-2); text-decoration: none; }
.ch img { width: 18px; height: 18px; border-radius: 50%; background: #333; }
.ch .dot { width: 7px; height: 7px; border-radius: 50%; background: #3a404c; }
.ch .dot.live { background: var(--red); box-shadow: 0 0 6px var(--red); }
.ch .dot.up { background: var(--amber); }
.ch .dot.err { background: #6b21a8; }
.ch .rm { border: 0; background: none; color: var(--muted); padding: 0 0 0 2px; }

/* 24/7 */
.tv { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; margin-top: 14px; }
.tv-screen { position: relative; aspect-ratio: 16 / 9; max-height: calc(100vh - 230px); width: 100%; background: #000; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.tv-screen iframe, #tvPlayer { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.tv-idle { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 15px; pointer-events: none; }
.tv-hit { position: absolute; inset: 0; z-index: 1; cursor: pointer; } /* catches clicks/mouse moves the iframe would swallow */
.tv-bar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 30px 14px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,.85)); transition: opacity .25s; color: #fff; }
.tv-bar button { background: none; border: 0; color: #fff; font-size: 17px; line-height: 1; padding: 4px 6px; border-radius: 4px; }
.tv-bar button:hover { background: rgba(255,255,255,.15); }
.tv-bar input[type=range] { accent-color: var(--red); cursor: pointer; }
#tvVol { width: 90px; }
.tv-seek { flex: 1; min-width: 60px; }
.tv-spacer { flex: 1; }
.tv-seek:not(.hidden) + .tv-spacer { display: none; }
.tv-time { font-size: 12px; font-variant-numeric: tabular-nums; opacity: .85; white-space: nowrap; }
.tv-golive { font-size: 12px !important; font-weight: 800; letter-spacing: .06em; color: var(--red) !important; }
.tv-golive.behind { color: #bbb !important; }
.tv-screen.ui-hidden .tv-bar { opacity: 0; }
.tv-screen.ui-hidden, .tv-screen.ui-hidden .tv-hit { cursor: none; }
.tv-screen:fullscreen { max-height: none; border: 0; border-radius: 0; aspect-ratio: auto; }
.tv-info { display: flex; align-items: center; gap: 12px; padding: 12px 2px; }
.tv-badge { font-weight: 800; font-size: 11px; letter-spacing: .1em; padding: 3px 8px; border-radius: 4px; background: var(--panel-2); flex-shrink: 0; }
.tv-badge.live { background: var(--red); color: #fff; }
.tv-badge.replay { background: var(--blue); color: #fff; }
.tv-text { min-width: 0; flex: 1; }
.tv-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tv-ctrl { display: flex; gap: 6px; flex-shrink: 0; }
.tv-ctrl .btn.on { border-color: var(--amber); color: var(--amber); }
.tv-queue { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.q-item { display: flex; gap: 6px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--c, var(--line)); border-radius: 8px; padding: 6px; min-width: 0; }
.q-item:hover { border-color: #4a5160; border-left-color: var(--c); }
.q-main { display: flex; gap: 10px; align-items: center; flex: 1; min-width: 0; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.q-ctrl { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
.q-ctrl button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; font-size: 11px; padding: 1px 6px; color: var(--muted); white-space: nowrap; }
.q-ctrl button:hover { color: var(--text); border-color: #4a5160; }
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.q-add { display: flex; gap: 6px; margin-bottom: 8px; }
.q-add input { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
.q-item img { width: 88px; aspect-ratio: 16/9; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.q-item .info { min-width: 0; font-size: 12px; }
.q-item .info div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-item .tag { font-size: 10px; font-weight: 800; letter-spacing: .08em; color: var(--muted); }
.q-item .tag.live { color: var(--red); }
.tv-prefs { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; align-self: start; position: sticky; top: 70px; display: flex; flex-direction: column; gap: 8px; }
.tv-prefs h3 { margin: 0; font-size: 15px; }
.tv-prefs h4 { margin: 10px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.tv-prefs select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; width: 100%; }
.tv-prefs label { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.small { font-size: 12px; margin: 0; }
.fav-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; counter-reset: fav; }
.fav-list li { display: flex; align-items: center; gap: 6px; background: var(--panel-2); border-radius: 6px; padding: 4px 6px; font-size: 13px; counter-increment: fav; }
.fav-list li::before { content: counter(fav); font-weight: 800; color: var(--amber); width: 16px; text-align: center; }
.fav-list li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-list li button { background: none; border: 0; color: var(--muted); padding: 0 3px; }
.fav-list li button:hover { color: var(--text); }
.fav-list:empty::after { content: "No priorities yet. Showing whatever is biggest and live."; color: var(--muted); font-size: 12px; }

.foot { text-align: center; padding: 10px 0 24px; font-size: 11px; }
.foot a { color: #3a404c; text-decoration: none; }
.foot a:hover { color: var(--muted); }

/* dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; max-width: 520px; width: 92vw; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.subs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin: 12px 0; }
.subs label { display: flex; gap: 8px; align-items: center; }
.dlg-actions { text-align: right; }
.dlg-actions button { background: var(--red); border: 0; color: #fff; border-radius: 6px; padding: 6px 16px; font-weight: 600; }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  .brand small, #scan { display: none; }
  .filters, main { padding-left: 16px; padding-right: 16px; }
  #search { width: 100%; }
  .players.l2, .players.l4 { grid-template-columns: 1fr; }
  .ev { grid-template-columns: 52px 4px 1fr; }
  .ev .what { grid-column: 3; }
  .ev .series { grid-column: 3; }
  .ev .actions { grid-column: 1 / -1; justify-content: flex-start; }
  .series-grid, .soon { grid-template-columns: 1fr; }
  .tv { grid-template-columns: 1fr; }
  .tv-info { flex-wrap: wrap; }
  .tv-prefs { position: static; }
  .add input { width: 100%; }
}
