:root {
  --bg: #0E1116;
  --bg2: #12161D;
  --surface: #181C24;
  --surface2: #222833;
  --line: #2C3340;
  --text: #ECEEF1;
  --text2: #C9CFD6;
  --muted: #A3ACB9;
  --accent: #F2A541;
  --accent-ink: #1A1300;
  --info: #7DB3FF;
  --radius: 12px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
img { display: block; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tv :focus { outline: 4px solid var(--accent); outline-offset: 3px; }

/* ---- layout */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(14,17,22,.94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--surface2);
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: -.02em; color: var(--text); text-decoration: none; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; }
.mainnav a {
  min-height: 44px; display: flex; align-items: center; padding: 0 14px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-weight: 600;
}
.mainnav a.on { background: var(--surface2); color: var(--text); }
main { padding: 16px; max-width: 1400px; margin: 0 auto; outline: none; }

@media (max-width: 700px) {
  .top { justify-content: space-between; }
  .mainnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0; background: var(--bg2); border-top: 1px solid var(--surface2); padding-bottom: env(safe-area-inset-bottom);
  }
  .mainnav a { justify-content: center; min-height: 56px; border-radius: 0; font-size: 13px; padding: 0; }
  .mainnav a.on { background: transparent; color: var(--accent); }
  main { padding-bottom: 96px; }
}

h1 { font-size: 26px; margin: 8px 0 16px; letter-spacing: -.01em; }
h2.sec { font-size: 18px; margin: 26px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }

/* ---- controls */
.btn {
  min-height: 44px; padding: 0 18px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.quiet { background: var(--surface2); color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.chip {
  flex: 0 0 auto; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--text); border-color: var(--text); color: var(--bg); }
input[type=search], input[type=text], input[type=password] {
  width: 100%; min-height: 48px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text2); }

/* ---- cards */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; }
.now-card { border: 1px solid var(--accent); background: #1E2430; display: flex; flex-direction: column; gap: 10px; }
.kicker { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 4px; background: var(--accent); flex: 0 0 auto; }
.bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--info); }
.now-card .bar > i { background: var(--accent); }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.hscroll { display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: none; }
.tile {
  flex: 0 0 168px; display: flex; flex-direction: column; gap: 6px; color: var(--text); text-decoration: none;
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer; border-radius: 10px;
}
.tile .thumb { aspect-ratio: 16/9; border-radius: 10px; background: var(--surface2) center/cover no-repeat; }
.tile .t1 { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .t2 { font-size: 12px; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.poster {
  display: flex; flex-direction: column; gap: 6px; background: none; border: 0; padding: 0; text-align: left;
  color: var(--text); cursor: pointer; border-radius: 10px; text-decoration: none;
}
.poster .img { aspect-ratio: 2/3; border-radius: 10px; background: var(--surface2) center/cover no-repeat; position: relative; }
.poster .img .bar { position: absolute; left: 6px; right: 6px; bottom: 6px; }
.poster .t1 { font-size: 13px; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.poster .t2 { font-size: 12px; color: var(--muted); }

.list { display: flex; flex-direction: column; }
.ch {
  display: flex; align-items: center; gap: 12px; padding: 10px 6px; border: 0; border-bottom: 1px solid var(--surface2);
  background: none; color: var(--text); text-align: left; cursor: pointer; width: 100%; border-radius: 8px;
}
.ch .logo { width: 48px; height: 36px; border-radius: 6px; background: var(--surface2) center/contain no-repeat; flex: 0 0 auto; }
.ch .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ch .name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch .prog { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch .state { font-size: 12px; font-weight: 600; color: var(--muted); flex: 0 0 auto; }
.ch .state.join { color: var(--accent); }
.ch .bar { margin-top: 2px; }
.ch .bar > i { background: var(--muted); }

.live-layout { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.live-cats { flex: 1 1 220px; max-width: 300px; display: flex; flex-direction: column; gap: 2px; max-height: calc(100vh - 140px); overflow-y: auto; }
.live-cats button {
  min-height: 42px; text-align: left; padding: 0 12px; border-radius: 8px; border: 0; background: none; color: var(--muted);
  font-weight: 600; cursor: pointer;
}
.live-cats button.on { background: var(--surface2); color: var(--text); }
.live-main { flex: 999 1 480px; min-width: 0; }
@media (max-width: 700px) {
  .live-cats { max-width: none; flex-direction: row; overflow-x: auto; max-height: none; flex-basis: 100%; }
  .live-cats button { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 20px; min-height: 40px; white-space: nowrap; }
}

.show-head { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-end; }
.show-head .cover { width: 160px; aspect-ratio: 2/3; border-radius: 12px; background: var(--surface2) center/cover no-repeat; flex: 0 0 auto; }
.show-head .info { flex: 1 1 260px; display: flex; flex-direction: column; gap: 8px; }
.ep { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--surface2); }
.ep .no { width: 30px; color: var(--muted); font-weight: 600; font-size: 14px; flex: 0 0 auto; }
.ep .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; background: none; border: 0; padding: 0; text-align: left; color: var(--text); cursor: pointer; }
.ep .body .t1 { font-size: 15px; font-weight: 600; }
.ep.seen .body .t1 { color: var(--muted); }
.ep .body .t2 { font-size: 12px; color: var(--muted); }
.check {
  width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line); background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.check svg { stroke: #4A5260; }
.ep.seen .check { background: var(--line); }
.ep.seen .check svg { stroke: var(--info); }

.settings { display: grid; gap: 14px; max-width: 640px; }
.settings .card { display: flex; flex-direction: column; gap: 10px; }
.settings h2 { margin: 0; font-size: 16px; }
.range-row { display: flex; flex-direction: column; gap: 4px; }
.range-row label { display: flex; justify-content: space-between; color: var(--text2); font-size: 14px; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 30px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stats div { background: var(--surface2); border-radius: 8px; padding: 10px; }
.stats b { display: block; font-family: var(--mono); font-size: 17px; font-weight: 500; }

.login { max-width: 360px; margin: 10vh auto; display: flex; flex-direction: column; gap: 14px; }
.empty { padding: 40px 0; color: var(--muted); text-align: center; }

/* ---- player */
#player { position: fixed; inset: 0; z-index: 20; background: #000; }
#player video { width: 100%; height: 100%; background: #000; }
.p-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  transition: opacity .25s; pointer-events: none;
}
.p-overlay > * { pointer-events: auto; }
.p-overlay.hide { opacity: 0; }
.p-overlay.hide > * { pointer-events: none; }
.p-top { display: flex; align-items: center; gap: 12px; padding: 16px; padding-top: max(16px, env(safe-area-inset-top)); background: linear-gradient(rgba(0,0,0,.7), transparent); flex-wrap: wrap; }
.p-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.p-chips span { padding: 6px 12px; border-radius: 16px; background: rgba(24,28,36,.9); font-size: 13px; color: var(--text2); }
.p-bottom { padding: 20px 20px 28px; padding-bottom: max(28px, env(safe-area-inset-bottom)); background: rgba(8,10,14,.88); display: flex; flex-direction: column; gap: 6px; }
.p-title { font-size: 22px; font-weight: 700; }
.p-sub { font-size: 14px; color: var(--muted); }
.p-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.p-msg {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); max-width: 88%;
  background: var(--surface); border-radius: 12px; padding: 18px 20px; text-align: center; line-height: 1.45;
}

/* ---- dialog + toast */
#dialog { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dlg { width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 10px; }
.dlg-kicker { font-size: 13px; font-weight: 600; color: var(--accent); }
.dlg h2 { margin: 0; font-size: 21px; }
.dlg p { margin: 0; color: var(--text2); line-height: 1.45; }
.dlg-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.dlg-actions .btn { min-height: 50px; font-size: 16px; }
#toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 40; background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 10px; font-weight: 600; max-width: 90%;
}

/* ---- tv (Fire TV / ?tv=1): larger type for 10-foot viewing */
.tv { font-size: 18px; }
.tv main { padding: 28px 48px; }
.tv .tile { flex-basis: 240px; }
.tv .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 20px; }
.tv .ch .name { font-size: 18px; }
.tv .ch .prog { font-size: 15px; }

/* ---- player controls */
#player video.ar-contain { object-fit: contain; }
#player video.ar-cover { object-fit: cover; }
#player video.ar-fill { object-fit: fill; }
#player video.ar-169, #player video.ar-43 {
  object-fit: fill; position: absolute; inset: 0; margin: auto; width: 100%; height: auto; max-height: 100%;
}
#player video.ar-169 { aspect-ratio: 16 / 9; }
#player video.ar-43 { aspect-ratio: 4 / 3; width: auto; height: 100%; max-width: 100%; }
.p-seek { display: flex; align-items: center; gap: 12px; }
.p-seek input { flex: 1; }
.p-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 4px; }
.p-buffer {
  margin-left: auto; min-width: 220px; flex: 0 1 300px; display: flex; flex-direction: column; gap: 6px;
  background: rgba(24,28,36,.9); border-radius: 10px; padding: 10px 12px;
}
.p-buffer-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--text2); }
.p-buffer-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.p-buffer-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.p-buffer-bar i.low { background: #E5484D; }
.p-buffer-set { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text2); }
.p-buffer-set input { flex: 1; height: 24px; }
@media (max-width: 700px) { .p-buffer { margin-left: 0; flex-basis: 100%; } }

/* fullscreen: no overflow (inline video left a few px), black everywhere */
#player { overflow: hidden; }
#player video { display: block; }
#player:fullscreen, #player:-webkit-full-screen { background: #000; width: 100%; height: 100%; }
#player::backdrop { background: #000; }
#player button:focus:not(:focus-visible) { outline: none; }

/* ---- login: profiles and PIN pad */
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 14px; }
.profile {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px 6px; border-radius: 14px;
  border: 0; background: transparent; color: var(--text); font-weight: 600; cursor: pointer;
}
.profile:hover { background: var(--surface); }
.avatar {
  width: 72px; height: 72px; border-radius: 36px; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 700;
}
.avatar.ghost { background: var(--surface2); color: var(--text); }
.avatar.big { width: 84px; height: 84px; border-radius: 42px; font-size: 36px; }
.pinbox { align-items: center; text-align: center; }
.dots { display: flex; gap: 16px; margin: 8px 0 2px; }
.dots i { width: 16px; height: 16px; border-radius: 8px; border: 2px solid var(--muted); }
.dots i.on { background: var(--accent); border-color: var(--accent); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; justify-content: center; margin-top: 6px; }
.key {
  width: 76px; height: 76px; border-radius: 38px; border: 0; background: var(--surface2); color: var(--text);
  font-size: 28px; font-weight: 500; cursor: pointer;
}
.key:active { background: var(--line); }
.key.quiet { background: transparent; font-size: 15px; color: var(--muted); }

/* ---- loading feedback */
#busyBar { position: fixed; left: 0; right: 0; top: 0; height: 3px; z-index: 50; overflow: hidden; background: rgba(242,165,65,.2); }
#busyBar i { position: absolute; top: 0; bottom: 0; width: 30%; background: var(--accent); animation: busy 1.1s ease-in-out infinite; }
@keyframes busy { 0% { left: -30%; } 100% { left: 100%; } }
.p-load {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); min-width: 240px; max-width: 88%;
  display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px 24px; border-radius: 14px;
  background: rgba(24,28,36,.92); text-align: center; font-weight: 600;
}
.p-load .p-buffer-bar { width: 100%; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- search groups and on-air status */
.sgroup { margin-bottom: 18px; }
.sg-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding: 4px 6px 6px; border-bottom: 1px solid var(--line); }
.sg-head b { font-size: 16px; }
.onair { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); flex: 0 0 auto; }
.dot2 { width: 9px; height: 9px; border-radius: 5px; background: var(--line); }
.onair.on { color: #5BD18B; } .onair.on .dot2 { background: #5BD18B; }
.onair.off .dot2 { background: #E5484D; }
.onair.wait .dot2 { background: var(--accent); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
