/*
 * Aerial - design system.
 * Implements docs/UX_SPECIFICATION.md sections 6 and 7. Tokens only here;
 * no component invents its own colour or spacing.
 *
 * The single most important rule in this file: SELECTED is not FOCUSED.
 * Selected (dim blue) is where you are. Focused (white fill) is where the
 * keyboard is. Both are visible at once, in different columns. That
 * distinction is the navigation model.
 */

:root {
  --bg:         #0e1116;
  --panel:      #161b22;
  --panel-2:    #1c232c;
  --panel-3:    #222a34;
  --line:       #2a323d;
  --text:       #e7ecf3;
  --muted:      #8b97a8;
  --accent:     #4da3ff;
  --accent-dim: #1e3a5c;
  --focus-fill: #f2f6fb;
  --focus-text: #0e1116;
  --ok:         #5ad19b;
  --danger:     #ff6b6b;

  --u: 8px;
  --row-h: 44px;
  --row-h-2: 56px;
  --rail-w: 64px;
  --rail-w-open: 210px;
  --cat-w: 260px;
  --ch-w: 340px;
  --radius: 10px;

  --t-focus: 120ms;
  --t-panel: 180ms;
  --t-fade: 250ms;
}

@media (prefers-reduced-motion: reduce) {
  :root { --t-focus: 0ms; --t-panel: 0ms; --t-fade: 0ms; }
  * { animation: none !important; transition: none !important; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* Long-press on a channel row should not select its text or raise iOS's
     callout menu - the row is a control, not prose. Inputs opt back in. */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;         /* no rubber-band bounce behind the app */
}
input, textarea { -webkit-user-select: text; user-select: text; }
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
:focus { outline: none; }            /* focus is drawn, never browser-default */

/* Keyboard users still need to see where they are. This restores a visible
   ring for keyboard navigation only, without putting one on every mouse click. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.scroll, #panelBody { -webkit-overflow-scrolling: touch; }

/* ============================================================ primitives */

/*
 * ListRow - categories, channels, search results.
 * Focused wins over selected: if the keyboard is here, that is what you see.
 */
.row {
  display: flex; align-items: center; gap: 10px;
  height: var(--row-h); padding: 0 14px; width: 100%;
  text-align: left; color: var(--text);
  border-bottom: 1px solid rgba(255,255,255,.035);
  transition: background var(--t-focus), color var(--t-focus);
}
.row:hover { background: rgba(255,255,255,.055); }
.row.selected { background: var(--accent-dim); }
.row.focused { background: var(--focus-fill); color: var(--focus-text); border-radius: var(--radius); }
.row.focused .sub, .row.focused .num, .row.focused .badge { color: rgba(14,17,22,.62); }

.row .num { min-width: 36px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .logo { width: 30px; height: 30px; flex: 0 0 30px; object-fit: contain; background: #000; border-radius: 5px; }
.row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 12px; color: var(--muted); }
.row .badge { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .tag {
  font-size: 10px; letter-spacing: .08em; padding: 2px 6px; border-radius: 4px;
  background: var(--accent-dim); color: var(--accent);
}
.row.focused .tag { background: rgba(14,17,22,.12); color: var(--focus-text); }
.row .playing { color: var(--accent); font-size: 12px; }
.row.focused .playing { color: var(--focus-text); }

/* Name over category, for search results where the group disambiguates. */
.row .nmstack { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.row .nmstack .nm { flex: none; line-height: 1.25; }
.row .nmstack .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Rename. Same weight as the star: revealed on hover or focus, always
   present for touch, where there is no hover to reveal anything. */
.row .pen {
  flex: 0 0 auto; width: 26px; height: 26px; line-height: 26px; text-align: center;
  border-radius: 5px; color: var(--muted); font-size: 13px;
  opacity: 0; transition: opacity var(--t-focus), background var(--t-focus);
}
.row:hover .pen, .row.focused .pen { opacity: 1; }
.row .pen:hover { background: rgba(255,255,255,.12); color: var(--text); }
.row.focused .pen { color: rgba(14,17,22,.45); }
@media (hover: none) { .row .pen, .row .star { opacity: 1; } }

/* Inline channel search, inside the channel column. */
#chanSearchWrap { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.searchbox {
  width: 100%; height: 38px; padding: 0 12px; border-radius: var(--radius);
  background: var(--panel-3); border: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 15px;
}
.searchbox:focus { outline: none; border-color: var(--accent); }
.searchbox::placeholder { color: var(--muted); }

/* SettingsRow - label over value, optional right control */
.srow {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: var(--row-h-2); padding: 10px 18px; text-align: left;
  transition: background var(--t-focus), color var(--t-focus);
}
.srow:hover { background: rgba(255,255,255,.05); }
.srow.focused { background: var(--focus-fill); color: var(--focus-text); border-radius: var(--radius); }
.srow .txt { flex: 1; min-width: 0; }
.srow .lab { display: block; }
/* pre-line so a multi-line value (the speed test reports three) keeps its
   shape instead of running together into one paragraph. */
.srow .val { display: block; font-size: 13px; color: var(--muted); margin-top: 1px;
             white-space: pre-line; }
.srow.focused .val { color: rgba(14,17,22,.62); }
.srow .chev { color: var(--muted); }
.srow.focused .chev { color: rgba(14,17,22,.5); }

.srow.primary { background: var(--accent-dim); color: var(--accent); }
.srow.primary.focused { background: var(--focus-fill); color: var(--focus-text); }

/* A read-only explanatory block. Deliberately not shaped like a row: it is
   not clickable, and looking clickable would be a lie. */
.snote { padding: 10px 18px 14px; }
.snote .lab { display: block; font-size: 12px; letter-spacing: .06em;
              text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.snote .val { display: block; color: var(--text); font-size: 14px; line-height: 1.5;
              overflow-wrap: anywhere; }

/* A text field inside a settings panel. */
.sinput { display: block; padding: 12px 18px 4px; }
.sinput .lab { display: block; font-size: 12px; letter-spacing: .06em;
               text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.sinput input {
  width: 100%; height: 42px; padding: 0 12px; border-radius: var(--radius);
  background: var(--panel-3); border: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 16px;   /* 16px stops iOS Safari zooming on focus */
}
.sinput input:focus { outline: none; border-color: var(--accent); }

/* SectionHeading - coloured, not bold */
.shead {
  padding: 18px 18px 6px; font-size: 12px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--accent);
}

/* Toggle */
.tg { width: 46px; height: 26px; border-radius: 13px; background: var(--line); position: relative; flex: 0 0 46px; }
.tg i { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
        background: var(--muted); transition: left var(--t-focus), background var(--t-focus); }
.tg.on { background: var(--accent-dim); }
.tg.on i { left: 23px; background: var(--accent); }

/* Buttons */
.btn {
  padding: 9px 16px; border-radius: 8px; background: var(--panel-3);
  border: 1px solid var(--line); transition: background var(--t-focus);
}
.btn:hover { background: #2b3540; }
.btn.primary { background: var(--accent-dim); border-color: var(--accent); }
.btn.primary:hover { background: #24486f; }
.btn.focused, .btn:focus-visible { background: var(--focus-fill); color: var(--focus-text); border-color: var(--focus-fill); }
.btn[disabled] { opacity: .45; cursor: default; }

/* ================================================================= shell */

/* 100vh is wrong on mobile Safari - it measures the viewport as if the URL bar
   were hidden, so the bottom of the app sits under it. dvh follows the bar as
   it comes and goes; vh stays as the fallback for browsers without dvh. */
#app { display: flex; height: 100vh; height: 100dvh; }

#rail {
  width: var(--rail-w); flex: 0 0 var(--rail-w);
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 12px 8px; gap: 4px;
  transition: width var(--t-panel), flex-basis var(--t-panel);
}
#rail.open { width: var(--rail-w-open); flex-basis: var(--rail-w-open); }
.brand {
  display: flex; align-items: center; gap: 10px; height: 40px;
  padding: 0 8px; margin-bottom: 10px; color: var(--accent);
  font-weight: 600; letter-spacing: .02em; overflow: hidden; white-space: nowrap;
}
.brand .txt { opacity: 0; transition: opacity var(--t-panel); }
#rail.open .brand .txt { opacity: 1; }

.rb {
  display: flex; align-items: center; gap: 14px; height: 46px;
  padding: 0 12px; border-radius: var(--radius); color: var(--muted);
  transition: background var(--t-focus), color var(--t-focus);
}
.rb svg { width: 22px; height: 22px; flex: 0 0 22px; }
.rb .txt { opacity: 0; white-space: nowrap; transition: opacity var(--t-panel); }
#rail.open .rb .txt { opacity: 1; }
.rb:hover { background: var(--panel-2); color: var(--text); }
.rb.selected { background: var(--accent-dim); color: var(--text); }
.rb.focused { background: var(--focus-fill); color: var(--focus-text); }
.rail-gap { flex: 1; }

#views { flex: 1; display: flex; min-width: 0; }
.view { display: none; flex: 1; min-width: 0; }
.view.on { display: flex; }

/* columns */
.col { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
#cats { width: var(--cat-w); flex: 0 0 var(--cat-w); background: var(--panel); }
#chans { width: var(--ch-w); flex: 0 0 var(--ch-w); background: var(--panel-2); }
#stage { flex: 1; min-width: 0; background: #000; position: relative; display: flex; flex-direction: column; }

.chead {
  display: flex; align-items: center; gap: 8px; padding: 0 14px;
  height: 46px; flex: 0 0 46px; border-bottom: 1px solid var(--line);
  font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
}
.chead .count { margin-left: auto; font-variant-numeric: tabular-nums; }
.scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 6px; }
.scroll::-webkit-scrollbar { width: 10px; }
.scroll::-webkit-scrollbar-thumb { background: #2f3946; border-radius: 5px; }

/* =============================================================== player */

#stage video { width: 100%; height: 100%; background: #000; object-fit: contain; }
#vwrap { flex: 1; position: relative; min-height: 0; }

/* The channel banner. Covers the whole frame so the top strip (category,
   clock) and the bottom bar fade together as one object, the way a set-top
   box does it - two separately-fading overlays read as two bugs. */
#nameOv {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  opacity: 0; transition: opacity var(--t-fade); pointer-events: none;
}
#nameOv.show { opacity: 1; }

#ovTop {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 16px 22px; font-size: 15px; letter-spacing: .01em;
  background: linear-gradient(to bottom, rgba(0,0,0,.75), transparent);
  text-shadow: 0 1px 3px rgba(0,0,0,.9);
}
#ovCat { text-transform: uppercase; font-size: 14px; opacity: .95; }
#ovClock { font-variant-numeric: tabular-nums; opacity: .95; }

#ovBar {
  display: flex; align-items: center; gap: 18px; padding: 22px 24px 24px;
  background: linear-gradient(to top, rgba(0,0,0,.9), transparent);
}
#ovLogo {
  width: 68px; height: 68px; flex: 0 0 68px; object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.6));
}
#ovText { min-width: 0; flex: 1; }
#ovProg { font-size: 22px; font-weight: 600; margin-bottom: 6px; }
#ovLine { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 15px; }
#ovNum { font-variant-numeric: tabular-nums; opacity: .8; }
#ovName { font-weight: 600; }
#ovChips { display: flex; gap: 8px; flex-wrap: wrap; }
#ovChips .chip {
  font-size: 12px; letter-spacing: .04em; padding: 3px 8px; border-radius: 4px;
  background: rgba(255,255,255,.16); white-space: nowrap;
}

/* Player controls, top-right of the picture. Always visible on a touch screen:
   there is no hover to reveal them with, and no keyboard to press F on. */
#pctl {
  position: absolute; top: 10px; right: 12px; z-index: 5;
  display: flex; gap: 8px; opacity: 0; transition: opacity var(--t-fade);
}
#vwrap:hover #pctl, #nameOv.show ~ #pctl, #pctl:focus-within, #pctl.paused { opacity: 1; }
@media (hover: none) { #pctl { opacity: 1; } }
#pctl button {
  width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; color: #fff; background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
}
#pctl button:hover { background: rgba(0,0,0,.8); }
body.fullscreen #pctl { top: max(10px, env(safe-area-inset-top)); }

#pstate {
  position: absolute; inset: 0; display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; text-align: center;
  padding: 30px; background: rgba(8,10,14,.82);
}
#pstate.show { display: flex; }
#pTitle { font-size: 19px; }
#pText { color: var(--muted); max-width: 460px; white-space: pre-line; }
.spinner {
  width: 30px; height: 30px; border: 3px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================== overlay */

#panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 46%; min-width: 420px; max-width: 620px;
  background: var(--panel); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform var(--t-panel);
  display: flex; flex-direction: column; z-index: 30;
  box-shadow: -20px 0 60px rgba(0,0,0,.5);
}
#panel.open { transform: translateX(0); }
#panelHead {
  padding: 20px 22px; background: var(--panel-3); border-bottom: 1px solid var(--line);
  font-size: 20px; font-weight: 600;
}
#panelBody { flex: 1; overflow-y: auto; padding: 6px 4px 24px; }
#panelBody .filter { padding: 10px 14px; }
#panelBody .filter input {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--line);
}

/* ================================================================ gates */

.gate {
  position: fixed; inset: 0; z-index: 60; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.gate .card { width: 440px; max-width: 100%; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px 28px;
}
.card h1 { margin: 0 0 4px; font-size: 23px; }
.card h2 { margin: 0 0 4px; font-size: 19px; }
.card p.sub { margin: 0 0 20px; color: var(--muted); }
label { display: block; margin-bottom: 14px; }
label span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=url] {
  width: 100%; padding: 11px 13px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--line);
}
input:focus { border-color: var(--accent); }
.msg { margin-top: 14px; padding: 11px 13px; border-radius: 8px; display: none; font-size: 14px; }
.msg.show { display: block; }
.msg.err { background: rgba(255,107,107,.12); border: 1px solid var(--danger); }
.msg.ok { background: rgba(90,209,155,.12); border: 1px solid var(--ok); }

/* A text button that reads as a link - "I already have an account". */
.linkish {
  display: block; width: 100%; margin-top: 14px; padding: 10px;
  color: var(--accent); font-size: 14px; text-align: center;
}
.linkish:hover { text-decoration: underline; }

.empty { padding: 40px 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); margin-bottom: 6px; font-weight: 500; }

#toast {
  position: fixed; left: 20px; bottom: 20px; z-index: 70;
  background: var(--panel-3); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; opacity: 0; transform: translateY(8px);
  transition: opacity var(--t-fade), transform var(--t-fade); pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }

/* =========================================================== responsive
 *
 * Three layouts, because three devices genuinely want different things:
 *
 *   >= 1100px   desktop and laptop. Three columns beside the picture, the
 *               full navigation model, keyboard first.
 *
 *   700-1099px  tablet, and desktop windows that have been made narrow.
 *               The picture goes ON TOP at 16:9 and the lists sit under it -
 *               squeezing 664px of fixed columns beside a video leaves the
 *               video 100px wide, which is not a layout, it is a bug.
 *
 *   < 700px     phone. One pane at a time, because two 44px rows side by side
 *               on a 390px screen means neither is readable. Categories ->
 *               Channels -> Player, with Back walking the same path in
 *               reverse. This is how every phone TV app works, and it is the
 *               only arrangement where a thumb can reach anything.
 *
 * The panes are driven by body[data-mpane] rather than by JavaScript moving
 * elements around, so rotating the device re-lays-out with no code involved.
 */

@media (max-width: 1499px) and (min-width: 1100px) {
  :root { --cat-w: 210px; --ch-w: 280px; }
}

/* -------------------------------------------------- tablet: picture on top
 *
 * Height matters as much as width here. A phone held sideways is ~850px wide
 * and ~390px tall: wide enough to look like a tablet and far too short to be
 * treated as one. Without the height condition it took this layout, and the
 * picture ended up a letterboxed strip under two lists. So the tablet layout
 * requires real vertical room, and a short landscape screen falls through to
 * the phone rules below.
 */
@media (max-width: 1099px) and (min-width: 700px) and (min-height: 501px) {
  #app { flex-direction: column; }
  #rail {
    width: 100%; flex: 0 0 auto; flex-direction: row; align-items: center;
    border-right: 0; border-bottom: 1px solid var(--line);
    padding: 6px 10px; gap: 6px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  #rail .brand { margin-bottom: 0; margin-right: 6px; }
  #rail .brand .txt, #rail .rb .txt { opacity: 1; }
  .rb { height: 40px; }
  .rail-gap { flex: 1; }

  #views { flex: 1; min-height: 0; }
  .view.on { flex-direction: column; }

  /* The picture first, at a real aspect ratio, then the lists beneath it. */
  #stage { flex: 0 0 auto; width: 100%; aspect-ratio: 16 / 9; max-height: 46vh; }
  .col { border-right: 0; }
  #cats, #chans {
    width: auto; flex: 1 1 50%; min-width: 0;
    border-top: 1px solid var(--line);
  }
  #cats { border-right: 1px solid var(--line); }

  /* Picture across the top, the two lists side by side underneath.
     grid-row must be stated: the DOM order is cats, chans, stage, so auto
     placement puts the lists in row 1 and the picture underneath them - which
     is exactly the wrong way up, and is what the landscape screenshot showed. */
  #views .view.on { display: grid; grid-template-rows: auto 1fr;
                    grid-template-columns: 1fr 1fr; }
  #stage { grid-row: 1; grid-column: 1 / -1; }
  #cats  { grid-row: 2; grid-column: 1; }
  #chans { grid-row: 2; grid-column: 2; }
}

/* ------------------------------------------------------- phone: one at a time
 *
 * The comma is an OR: narrow, or short. A short screen is a phone held
 * sideways, and it wants the same one-pane-at-a-time treatment as a phone held
 * upright - not a tablet layout that happens to fit its width.
 */
@media (max-width: 699px), (max-height: 500px) {
  :root { --row-h: 52px; --row-h-2: 60px; }   /* thumbs, not mouse pointers */

  #app { flex-direction: column; }
  #rail {
    order: 2; width: 100%; flex: 0 0 auto; flex-direction: row;
    justify-content: space-around; align-items: center;
    border-right: 0; border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  #rail .brand { display: none; }             /* the name is not navigation */
  #rail .rail-gap { display: none; }
  .rb { flex-direction: column; gap: 2px; height: 48px; flex: 1; justify-content: center; }
  .rb .txt { opacity: 1; font-size: 11px; }

  #views { order: 1; flex: 1; min-height: 0; }
  .view.on { flex-direction: column; }

  /* Exactly one pane is on screen. Which one is body[data-mpane]. */
  #cats, #chans, #stage { width: 100%; flex: 1 1 auto; min-width: 0; border-right: 0; }
  body[data-mpane="cat"]    #chans,
  body[data-mpane="cat"]    #stage,
  body[data-mpane="chan"]   #cats,
  body[data-mpane="chan"]   #stage,
  body[data-mpane="player"] #cats,
  body[data-mpane="player"] #chans { display: none; }

  /* The picture keeps its shape at the top; nothing else competes with it. */
  body[data-mpane="player"] #stage { flex: 1; }

  .chead { height: 52px; flex: 0 0 52px; padding-left: 6px; }
  .searchbox { font-size: 16px; }   /* below 16px, iOS zooms the whole page */

  #panel { width: 100%; max-width: none; }
  #toast { left: 12px; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); }

  /* The banner has to shrink or it covers the match. */
  #ovBar { padding: 14px 16px 16px; gap: 12px; }
  #ovLogo { width: 44px; height: 44px; flex-basis: 44px; }
  #ovProg { font-size: 17px; }
  #ovLine { font-size: 13px; gap: 8px; }
  #ovTop { padding: 10px 14px; font-size: 12px; }
  #pstats { font-size: 11px; }
}

/* The mobile back control only exists where panes are stacked. */
#paneBack { display: none; }
@media (max-width: 699px), (max-height: 500px) {
  #paneBack {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; margin-left: -4px; margin-right: 2px;
    border-radius: var(--radius); color: var(--muted); font-size: 22px;
  }
  body[data-mpane="cat"] #paneBack { display: none; }
}

/* A phone held sideways has ~390px of height and is almost certainly being
   held that way to watch something. Give the picture the whole screen and put
   navigation back only when the banner is up. */
@media (max-height: 500px) and (orientation: landscape) {
  body[data-mpane="player"] #rail { display: none; }
  body[data-mpane="player"] #stage { flex: 1; }
  #ovBar { padding: 10px 14px 12px; }
  #ovProg { font-size: 15px; margin-bottom: 2px; }
  #ovLogo { width: 36px; height: 36px; flex-basis: 36px; }
  #ovTop { padding: 8px 12px; }
}

/* Notches and rounded corners, on every layout. */
#rail { padding-left: max(8px, env(safe-area-inset-left)); }
#nameOv { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }

body.fullscreen #rail, body.fullscreen #cats, body.fullscreen #chans { display: none; }
body.fullscreen #stage { flex: 1; aspect-ratio: auto; max-height: none; }

/*
 * CSS full screen, for iPhone.
 *
 * iPhone Safari has no Element.requestFullscreen, and its only alternative is
 * the video element's own native player - which brings a playback speed menu
 * that means nothing on live television, and pauses the video when you leave
 * it, with none of our controls on screen to start it again.
 *
 * So the picture is simply expanded to fill the viewport. Safari's own chrome
 * stays visible, which is the price, but the player remains ours.
 */
body.css-fullscreen #vwrap {
  position: fixed; inset: 0; z-index: 100; background: #000;
}
body.css-fullscreen #vwrap video { object-fit: contain; }
body.css-fullscreen #rail,
body.css-fullscreen #cats,
body.css-fullscreen #chans { display: none; }
/* Clear of the notch and the home indicator when expanded. */
body.css-fullscreen #pctl { top: max(12px, env(safe-area-inset-top)); }
body.css-fullscreen #ovBar { padding-bottom: max(24px, env(safe-area-inset-bottom)); }

/*
 * Live playback readout. Evidence that the BROWSER is decoding, not merely
 * that the server sent bytes: decoded frames climbing and dropped frames flat
 * is the difference between "a stream arrived" and "television is playing".
 */
#pstats {
  position: absolute; right: 14px; top: 12px; z-index: 3;
  font: 12px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--muted); background: rgba(8,10,14,.62);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; display: none; white-space: pre; pointer-events: none;
}
#pstats.show { display: block; }
#pstats b { color: var(--ok); font-weight: 500; }
#pstats i { color: var(--danger); font-style: normal; }
/* ------------------------------------------- settings: never feel trapped */

#scrim {
  position: fixed; inset: 0; z-index: 29; background: rgba(4,6,9,.5);
  opacity: 0; pointer-events: none; transition: opacity var(--t-panel);
}
#scrim.show { opacity: 1; pointer-events: auto; }

#panelHead { display: flex; align-items: center; gap: 12px; }
#panelTitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#panelBack, #panelClose {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 8px;
  color: var(--muted); font-size: 20px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-focus), color var(--t-focus);
}
#panelBack:hover, #panelClose:hover { background: rgba(255,255,255,.09); color: var(--text); }
#panelBack[hidden] { visibility: hidden; }

/* ------------------------------------------------- favourites and ordering */

.row .star {
  width: 26px; height: 26px; flex: 0 0 26px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #55606f; font-size: 15px; opacity: 0; transition: opacity var(--t-focus), color var(--t-focus);
}
.row:hover .star, .row.focused .star, .row .star.on { opacity: 1; }
.row .star.on { color: #f5c451; }
.row .star:hover { background: rgba(255,255,255,.12); color: #f5c451; }
.row.focused .star { color: rgba(14,17,22,.45); }
.row.focused .star.on { color: #c98f0a; }

.srow .grip {
  width: 24px; flex: 0 0 24px; color: var(--muted); cursor: grab;
  text-align: center; font-size: 15px; user-select: none;
}
.srow.dragging { opacity: .45; }
.srow.drop-above { box-shadow: inset 0 3px 0 var(--accent); }
.srow.drop-below { box-shadow: inset 0 -3px 0 var(--accent); }

/* Move up / move down. The only way to reorder on a touch screen, where
   drag-and-drop never fires, so these are always visible - not hover-revealed. */
.srow .moves { display: flex; gap: 4px; flex: 0 0 auto; }
.srow .mv {
  width: 34px; height: 34px; line-height: 34px; text-align: center;
  border-radius: 7px; font-size: 12px; color: var(--muted);
  background: rgba(255,255,255,.06);
}
.srow .mv:hover { background: rgba(255,255,255,.16); color: var(--text); }
.srow .mv.off { opacity: .22; pointer-events: none; }
.srow.focused .mv { background: rgba(14,17,22,.1); color: rgba(14,17,22,.6); }
/* The grip is a desktop convenience; on touch it does nothing, so hide it and
   leave the buttons to do the work. */
@media (hover: none) { .srow .grip { display: none; } }

.saved-flash { animation: savedFlash 700ms ease-out; }
@keyframes savedFlash {
  0% { background: rgba(90,209,155,.28); }
  100% { background: transparent; }
}
/* ==================================================== home-screen app mode
 *
 * Installed to the home screen there is no browser chrome at all: no URL bar
 * to push content down from the notch, and no toolbar keeping it clear of the
 * home indicator. The page owns the entire screen, including the parts of it
 * that are physically obstructed - which is why the interface looked cramped
 * and cut off. Everything that touches an edge has to inset itself.
 */
body.standalone #rail {
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
}
body.standalone .chead,
body.standalone #panelHead {
  padding-top: env(safe-area-inset-top);
  height: calc(52px + env(safe-area-inset-top));
  flex-basis: calc(52px + env(safe-area-inset-top));
}
body.standalone #ovTop { padding-top: calc(10px + env(safe-area-inset-top)); }
body.standalone #pDown { top: calc(10px + env(safe-area-inset-top)); }
body.standalone #panel { padding-bottom: env(safe-area-inset-bottom); }

/* ------------------------------------------------------- leaving the player */
#pDown {
  position: absolute; top: 10px; left: 12px; z-index: 6;
  width: 42px; height: 42px; display: none;
  align-items: center; justify-content: center;
  border-radius: 50%; color: #fff; background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
}
body[data-mpane="player"] #pDown { display: flex; }
#pDown:hover { background: rgba(0,0,0,.8); }

/* -------------------------------------------------------------- now playing
 *
 * The bar that stops the picture becoming a dead end. It is deliberately a
 * large single target: the whole thing returns you to what is playing, with
 * only the play control carved out of it.
 */
#mini {
  display: none; align-items: center; gap: 12px;
  width: 100%; padding: 8px 12px; text-align: left;
  background: var(--panel-2); border-top: 1px solid var(--line);
}
#mini[hidden] { display: none; }
#miniLogo {
  width: 40px; height: 40px; flex: 0 0 40px;
  object-fit: contain; background: #000; border-radius: 6px;
}
#miniText { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#miniName {
  font-size: 15px; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#miniSub { font-size: 12px; color: var(--accent); }
#miniPlay {
  flex: 0 0 auto; width: 40px; height: 40px; line-height: 40px;
  text-align: center; color: var(--text); font-size: 13px;
  border-radius: 8px; background: rgba(255,255,255,.07);
}

/* Only where panes are stacked. On a desktop the picture is always on screen,
   so a bar telling you what is playing would be describing the obvious. */
@media (max-width: 699px), (max-height: 500px) {
  body.has-audio:not([data-mpane="player"]) #mini { display: flex; }
  #rail { order: 3; }
  #mini { order: 2; }
  #views { order: 1; }

  /* Controls sit along the bottom of the picture, clear of the notch. */
  #pctl {
    top: auto; bottom: calc(12px + env(safe-area-inset-bottom));
    right: 12px; left: 12px;
    justify-content: flex-end;
  }
  #pctl button { width: 48px; height: 48px; }

  /* Bigger tap targets in the tab bar, and room for the label. */
  .rb { height: 52px; }
  .rb .txt { font-size: 11px; }
}
