:root {
  color-scheme: dark;
  --bg: #131315;
  --surface: #1d1d21;
  --raised: #29292e;
  --line: #3a3a41;
  --text: #f8f7f5;
  --muted: #b8b6bf;
  --amber: #f0b34a;
  --danger: #ffc1b2;
  --gutter: clamp(1rem, 4vw, 3rem);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, select, input { font: inherit; }
button, select { cursor: pointer; }
button, a, select { touch-action: manipulation; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.topbar, main, footer { max-width: 1480px; margin-inline: auto; padding-inline: var(--gutter); }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  min-height: 78px;
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: .65rem; text-decoration: none; font-size: 1.15rem; font-weight: 800; }
.brand-mark { width: .9rem; height: .9rem; border-radius: .25rem; background: var(--amber); transform: rotate(-12deg); }
.topbar nav { display: flex; gap: .35rem; flex-wrap: wrap; }
.library-tab { min-height: 44px; border: 0; border-radius: .6rem; padding: .5rem .8rem; background: transparent; color: var(--muted); }
.library-tab[aria-pressed="true"] { background: var(--raised); color: var(--amber); }

.browse { padding-block: clamp(1.75rem, 5vw, 3.75rem); }
.browse-heading { display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.browse-heading h1 { font-size: clamp(2rem, 5vw, 3.5rem); letter-spacing: -.04em; line-height: 1.1; }
#channel-count { color: var(--muted); margin-top: .45rem; }
.search-box { width: min(100%, 25rem); min-width: 0; display: flex; align-items: center; gap: .65rem; padding-inline: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: .65rem; }
.search-box:focus-within { outline: 2px solid var(--amber); outline-offset: 2px; }
.search-box svg { flex: 0 0 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; }
.search-box input { width: 100%; height: 48px; min-width: 0; outline: 0; border: 0; color: var(--text); background: transparent; }
.search-box input::placeholder { color: var(--muted); }
.select-label { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .55rem; color: var(--muted); }
.select-label select { min-height: 44px; max-width: 100%; border: 1px solid var(--line); border-radius: .55rem; background: var(--raised); color: var(--text); padding: .25rem .5rem; }
.select-label select:disabled { opacity: .75; }
.browse-filter { margin-block: 1.25rem; }

.channel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 1rem; }
.channel-tile { position: relative; min-width: 0; }
.channel-card { display: block; width: 100%; height: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: .65rem; padding: 0; background: var(--surface); color: var(--text); text-align: left; }
.channel-card:hover { border-color: var(--amber); }
.logo-wrap { position: relative; aspect-ratio: 16 / 9; display: grid; place-items: center; background: #e8e7eb; color: #292632; font-size: 1.35rem; font-weight: 800; }
.logo-wrap img { position: absolute; inset: 13%; width: 74%; height: 74%; object-fit: contain; }
.channel-copy { display: block; padding: .65rem 2.9rem .65rem .65rem; }
.channel-name, .channel-meta { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-name { font-weight: 700; }
.channel-meta { font-size: .875rem; color: var(--muted); }
.favourite { position: absolute; bottom: .35rem; right: .25rem; display: grid; place-items: center; width: 44px; height: 44px; background: transparent; color: var(--muted); border: 0; border-radius: .5rem; }
.favourite:hover { background: var(--raised); }
.favourite svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; }
.favourite[aria-pressed="true"] { color: var(--amber); }
.favourite[aria-pressed="true"] svg { fill: currentColor; }

.player-section { padding-block: 1.25rem; border-bottom: 1px solid var(--line); }
.video-shell { position: relative; background: #000; overflow: hidden; border-radius: .75rem; aspect-ratio: 16 / 9; max-height: 65vh; width: 100%; }
.video-shell:fullscreen { max-height: none; border-radius: 0; width: 100%; height: 100%; }
video { display: block; width: 100%; height: 100%; background: #000; object-fit: contain; }
.video-controls { position: absolute; inset: auto 0 0; padding: .6rem max(.55rem, env(safe-area-inset-right)) max(.4rem, env(safe-area-inset-bottom)) max(.55rem, env(safe-area-inset-left)); background: linear-gradient(transparent, rgba(15, 14, 18, .94) 65%); opacity: 1; transition: opacity .2s ease; }
.video-controls.is-idle { opacity: 0; pointer-events: none; }
.video-controls:has(:focus-visible) { opacity: 1; pointer-events: auto; }
.video-controls-row { display: flex; align-items: center; gap: .2rem; }
.video-controls-spacer { flex: 1; }
.video-control, .video-quality select { min-height: 44px; border: 0; border-radius: .5rem; color: #fff; background: transparent; padding-inline: .4rem; font: inherit; }
.video-control { display: grid; place-items: center; flex: 0 0 44px; }
.video-control:hover, .video-quality select:hover { color: var(--amber); background: #2c2a31; }
.video-quality select { max-width: 9rem; background: #242329; }
.video-control:disabled, .video-quality select:disabled { opacity: .65; }
.control-icon { display: block; position: relative; width: 20px; height: 20px; }
.playback-icon { background: currentColor; clip-path: polygon(25% 10%, 90% 50%, 25% 90%); }
.is-playing .playback-icon { clip-path: polygon(20% 12%, 43% 12%, 43% 88%, 20% 88%, 20% 12%, 58% 12%, 81% 12%, 81% 88%, 58% 88%, 58% 12%); }
.speaker-icon::before { content: ""; position: absolute; inset: 1px 9px 1px 0; background: currentColor; clip-path: polygon(0 32%, 39% 32%, 100% 4%, 100% 96%, 39% 68%, 0 68%); }
.speaker-icon::after { content: ""; position: absolute; inset: 3px 0 3px 8px; border: 2px solid transparent; border-right-color: currentColor; border-radius: 50%; }
.is-muted .speaker-icon::after { content: "×"; border: 0; inset: 1px 0 auto auto; font: 700 16px/18px system-ui; }
.fullscreen-icon { border: 2px solid currentColor; clip-path: polygon(0 0, 34% 0, 34% 18%, 66% 18%, 66% 0, 100% 0, 100% 34%, 82% 34%, 82% 66%, 100% 66%, 100% 100%, 66% 100%, 66% 82%, 34% 82%, 34% 100%, 0 100%, 0 66%, 18% 66%, 18% 34%, 0 34%); }
.video-volume { width: clamp(48px, 10vw, 92px); height: 44px; margin: 0; accent-color: var(--amber); cursor: pointer; }
.video-seek { display: block; width: 100%; height: 26px; margin: 0; accent-color: var(--amber); cursor: pointer; }
.stream-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: .65rem; }
.stream-tools a { display: inline-flex; align-items: center; text-decoration: none; }
.stream-tools input { width: 100%; min-height: 44px; background: var(--raised); color: var(--text); border: 1px solid var(--line); padding-inline: .55rem; border-radius: .45rem; }
.player-placeholder { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: .75rem; background: #09090a; color: var(--muted); pointer-events: none; }
.loader { width: 24px; height: 24px; border: 3px solid var(--line); border-top-color: var(--amber); border-radius: 50%; animation: spin .85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.now-playing { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; padding-top: 1rem; }
.now-playing img { width: 54px; height: 54px; object-fit: contain; border-radius: .5rem; padding: .3rem; background: #e8e7eb; }
.now-copy { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.now-copy h2 { font-size: 1.25rem; }
.now-copy p, .quality-note { color: var(--muted); }
.live-label { display: flex; align-items: center; gap: .35rem; color: var(--amber); font-size: .8rem; font-weight: 800; }
.live-label span { width: .45rem; height: .45rem; background: var(--amber); border-radius: 50%; }
.player-message { color: var(--danger); overflow-wrap: anywhere; }
.player-message:not(:empty), .quality-note:not(:empty) { margin-top: .5rem; }
.button { min-height: 44px; padding: .5rem .85rem; border: 0; border-radius: .55rem; background: var(--amber); color: #221706; font-weight: 700; }
.button-subtle, .button-more { background: var(--raised); color: var(--text); }
.install-banner { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem .7rem; margin-top: 1rem; padding: .8rem; border: 1px solid var(--line); border-radius: .65rem; background: var(--surface); }
.install-banner img { flex: 0 0 44px; }
.install-banner div { flex: 1 1 9rem; }
#install-title { font-weight: 700; }
.install-description, .install-help { color: var(--muted); font-size: .9rem; }
.install-help { flex: 1 0 100%; }
.button-more { display: block; margin: 1.25rem auto 0; }
.loading-state, .error-state, .empty-state { min-height: 200px; display: grid; place-content: center; justify-items: center; gap: .5rem; text-align: center; color: var(--muted); }
.error-state h3, .empty-state h3 { color: var(--text); }
footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .65rem; padding-block: 1rem 2rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .875rem; }
.guide-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; margin-bottom: .85rem; }
.guide-toolbar button:disabled { opacity: .5; cursor: default; }
#guide-date, #guide-status { color: var(--muted); }
#guide-status:not(:empty), #guide-retry { margin-bottom: .75rem; }
.guide-scroll { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: .65rem; }
.guide-row { --channel-width: clamp(105px, 23vw, 170px); min-width: max(760px, calc(var(--channel-width) + var(--timeline-width, 1020px))); display: grid; grid-template-columns: var(--channel-width) repeat(var(--ticks, 12), minmax(0, 1fr)); min-height: 56px; border-bottom: 1px solid var(--line); }
.guide-hours { min-height: 44px; align-items: center; color: var(--muted); background: var(--raised); font-size: .875rem; }
.guide-hours span { padding-inline: .6rem; }
.guide-hours span:first-child, .guide-channel { position: sticky; left: 0; z-index: 1; }
.guide-hours span:first-child { background: var(--raised); }
.guide-channel { border: 0; border-right: 1px solid var(--line); padding: .45rem .65rem; background: var(--surface); color: var(--text); text-align: left; line-height: 1.2; overflow-wrap: anywhere; }
.guide-channel:hover { color: var(--amber); }
.guide-track { position: relative; grid-column: 2 / -1; display: flex; align-items: center; padding-inline: .5rem; color: var(--muted); font-size: .875rem; background: repeating-linear-gradient(to right, transparent 0, transparent calc(var(--tick-width, 8.333%) - 1px), var(--line) calc(var(--tick-width, 8.333%) - 1px), var(--line) var(--tick-width, 8.333%)); }
.programme { position: absolute; inset-block: 4px; display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: .8rem .4rem; border-right: 3px solid var(--bg); border-radius: .35rem; background: var(--raised); color: var(--text); }
.programme.on-now { background: #4a351c; color: #ffe3b2; }
.guide-empty { padding: .75rem; }
#load-sentinel { height: 1px; }
@media (max-width: 560px) {
  .topbar { justify-content: flex-start; padding-block: .75rem .45rem; }
  .topbar nav, .search-box { width: 100%; }
  .library-tab { padding-inline: .55rem; font-size: .875rem; }
  .channel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
  .video-shell { max-height: none; }
  .video-quality select { max-width: 5.3rem; padding-inline: .28rem; }
  .video-seek { height: 20px; }
}
@media (max-width: 380px) {
  .now-copy { flex-basis: calc(100% - 68px); }
  .now-playing .button-subtle { margin-left: 67px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; }
}
