:root {
  --bg: #07080f; --panel: #0e1020; --card: rgba(255,255,255,.06); --card-2: rgba(255,255,255,.1);
  --line: rgba(255,255,255,.1); --text: #f4f5f8; --muted: #a3a8b8; --accent: #ffb03c; --ink: #1a1203;
  --danger: #ff6b6b; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 12px 20px; background: rgba(7,8,15,.85); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.search { flex: 1; max-width: 560px; display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; }
.search span { color: var(--muted); font-size: 18px; }
.search input { flex: 1; background: none; border: 0; outline: 0; color: var(--text); padding: 10px 0; font: inherit; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 9px 16px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--card-2); }
.btn.primary { background: var(--accent); color: var(--ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

.layout { display: grid; grid-template-columns: 250px 1fr; min-height: calc(100vh - 61px); }
.sidebar { border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 61px; height: calc(100vh - 61px); overflow-y: auto; }
.nav-title { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin: 18px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-radius: 10px; padding: 9px 10px; cursor: pointer; color: var(--text); }
.nav-item:hover { background: var(--card); }
.nav-item.active { background: rgba(255,176,60,.14); color: var(--accent); }
.nav-item .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.nav-item .err { margin-left: auto; color: var(--danger); }
.main { min-width: 0; }

.player { position: sticky; top: 61px; z-index: 10; background: #000; border-bottom: 1px solid var(--line); }
.stage { position: relative; background: #000; aspect-ratio: 16 / 9; max-height: 56vh; margin: 0 auto; }
.stage video, .car-stage video { width: 100%; height: 100%; display: block; background: #000; }
#viz { position: absolute; inset: 0; width: 100%; height: calc(100% - 48px); pointer-events: none; }
.status { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; background: rgba(0,0,0,.78); }
.status p { max-width: 520px; margin: 0 0 14px; }
.player-bar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel); flex-wrap: wrap; }
.now { flex: 1; min-width: 180px; }
.now-title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-sub { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.live { background: #e5484d; color: #fff; font-weight: 700; font-size: 11px; border-radius: 999px; padding: 1px 7px; }
.controls { display: flex; gap: 6px; align-items: center; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--card); cursor: pointer; font-size: 17px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--card-2); }
.icon-btn.big { width: 48px; height: 48px; background: var(--accent); color: var(--ink); font-size: 20px; }
.icon-btn.on { color: var(--accent); }
.icon-btn:disabled { opacity: .35; cursor: default; }

.view { padding: 24px 28px 80px; }
.view h1 { font-size: 28px; margin: 0 0 4px; }
.view .sub { color: var(--muted); margin: 0 0 18px; }
.view-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.view-head .grow { flex: 1; min-width: 200px; }
.view-head .tools { display: flex; gap: 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 14px; }
.chip { flex: none; border: 0; background: var(--card); border-radius: 999px; padding: 7px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.chip.active { background: var(--accent); color: var(--ink); }

.list { list-style: none; margin: 0; padding: 0; }
.ch { display: flex; align-items: center; gap: 12px; padding: 8px 6px; border-bottom: 1px solid var(--line); border-radius: 10px; }
.ch:hover { background: var(--card); }
.ch.playing { background: rgba(255,176,60,.1); }
.ch-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; text-align: left; cursor: pointer; padding: 0; }
.logo { flex: none; width: 46px; height: 46px; border-radius: 11px; background: var(--card); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-weight: 700; font-size: 14px; }
.logo img { width: 100%; height: 100%; object-fit: contain; padding: 5px; }
.ch-text { min-width: 0; }
.ch-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-group { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 3px; width: 120px; background: var(--card-2); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.star { border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; padding: 6px 8px; }
.star.on { color: var(--accent); }
.more { margin: 18px auto 0; display: block; }

.rail-title { display: flex; justify-content: space-between; align-items: baseline; margin: 26px 0 10px; }
.rail-title h2 { font-size: 19px; margin: 0; }
.rail { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 6px; }
.tile { flex: none; width: 120px; background: none; border: 0; text-align: left; cursor: pointer; padding: 0; }
.tile .logo { width: 120px; height: 120px; border-radius: 18px; font-size: 26px; }
.tile .ch-name { font-size: 13px; margin-top: 6px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .bar { width: 120px; }

.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty .big-icon { font-size: 44px; }
.empty h2 { color: var(--text); margin: 10px 0 6px; }
.empty .btns { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 20px; padding: 24px; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 14px; }
.tabs { display: flex; background: var(--card); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 16px; }
.tab { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--card-2); color: var(--text); }
dialog label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
dialog input:not([type=file]) { display: block; width: 100%; margin-top: 6px; background: #05060c; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--text); font: inherit; }
dialog input[type=file] { display: block; margin-top: 8px; color: var(--text); }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.error { color: var(--danger); font-size: 14px; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1b1e30; border: 1px solid var(--line); padding: 10px 18px; border-radius: 999px; z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,.5); }

/* Car mode */
.car { position: fixed; inset: 0; z-index: 40; background: #000; display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; padding: 20px; }
.car-stage { position: relative; border-radius: 18px; overflow: hidden; background: #000; align-self: center; aspect-ratio: 16/9; width: 100%; }
.car-panel { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.car-head { display: flex; gap: 12px; align-items: flex-start; }
.car-head > div { flex: 1; min-width: 0; }
.car-title { font-size: clamp(22px, 3vw, 34px); font-weight: 800; line-height: 1.15; }
.car-group { color: var(--muted); font-size: 18px; }
.car-controls { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }
.round { width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--card); cursor: pointer; font-size: 18px; font-weight: 700; display: grid; place-items: center; flex: none; }
.round:hover { background: var(--card-2); }
.round.lg { width: 76px; height: 76px; font-size: 26px; }
.round.xl { width: 96px; height: 96px; font-size: 34px; }
.round.accent { background: var(--accent); color: var(--ink); }
.round:disabled { opacity: .3; }
.car-time { text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 18px; }
.car-strip { display: flex; gap: 12px; overflow-x: auto; margin-top: auto; padding-bottom: 6px; }
.car-tile { flex: none; width: 128px; height: 108px; border-radius: 16px; border: 2px solid transparent; background: var(--card); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 8px; font-weight: 600; font-size: 14px; text-align: center; }
.car-tile.current { border-color: var(--accent); background: rgba(255,176,60,.2); }
.car-tile span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.car-tile .logo { width: 40px; height: 40px; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; overflow-x: auto; }
  #nav { display: flex; gap: 6px; }
  .nav-title { display: none; }
  .nav-item { width: auto; white-space: nowrap; }
  .nav-item .count { display: none; }
  .topbar { flex-wrap: wrap; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .topbar .btn { margin-left: auto; }
  .player { position: static; }
  .view { padding: 18px 16px 80px; }
  .car { grid-template-columns: 1fr; overflow-y: auto; }
}

/* App-style tabs and views */
.tabbar { display: none; }
.card-box { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; margin-bottom: 14px; }
.card-box h2 { font-size: 17px; margin: 0 0 10px; }
.card-box details { border-top: 1px solid var(--line); padding: 10px 0; }
.card-box summary { cursor: pointer; font-weight: 600; }
.cast-status { font-size: 15px; }
.cast-now { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.cast-now .btns, .card-box .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.steps-list { margin: 0; padding-left: 20px; color: var(--muted); }
.steps-list li { margin: 6px 0; }
.notice { border: 1px solid rgba(255,210,80,.35); background: rgba(255,210,80,.08); color: #ffd98a; border-radius: 12px; padding: 12px 16px; font-size: 14px; }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
a.btn { text-decoration: none; color: var(--text); display: inline-block; }

@media (max-width: 820px) {
  .sidebar { display: none; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: rgba(14,16,32,.95); backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar button { flex: 1; border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; cursor: pointer; }
  .tabbar button span { font-size: 20px; line-height: 1.2; filter: grayscale(1); opacity: .8; }
  .tabbar button.active { color: var(--accent); }
  .tabbar button.active span { filter: none; opacity: 1; }
  .view { padding-bottom: 110px; }
}
