/* Ear Drama — smart-TV stylesheet (Tizen · webOS · VIDAA · aggregators).
 *
 * Ported from Archive Watch; section numbers cite
 * docs/templates/TV-DESIGN-template.md §4 (layout/type/colour) and §3.2 (focus).
 *
 * ADDITIVE ONLY. Every rule is scoped under `html.tv`, which tv.js adds solely
 * on a TV runtime, so the mobile-first stylesheet is untouched and the phone /
 * desktop viewer cannot regress (§7.5). The existing `min-width` media-query
 * discipline is preserved — this is a TV *breakpoint*, not a TV fork.
 */

html.tv {
  /* §4.1 — 1920x1080 is the design baseline.
     §4.2 — 5% overscan-safe inset: nothing meaningful crosses this line. */
  --tv-overscan-x: 96px;
  --tv-overscan-y: 54px;

  /* §4.3 — six levels, three weights x two sizes. 24px is the ten-foot body
     floor; a seventh level is refused (refactor instead). */
  --tv-body: 24px;
  --tv-body-lg: 28px;
  --tv-title: 32px;
  --tv-title-lg: 40px;
  --tv-hero: 64px;
}

/* §4.4 colors come from design-tokens.json (the dark palette). */
/* BEGIN design-tokens. Generated from design-tokens.json by tools/design_tokens.mjs. Do not edit by hand. */
html.tv {
  --tv-bg: #0F0F11;
  --tv-text: #F2F2F4;
  --tv-text-muted: #C4C4CC;
  --tv-accent: #F2F2F4;
  --tv-focus-ring: #F2F2F4;
}
/* END design-tokens */

/* §4.4 — dark-first. Living rooms are dark; a bright UI is fatiguing at ten
   feet. Light mode is not offered on TV. */
html.tv,
html.tv body {
  background: var(--tv-bg);
  color: var(--tv-text);
  /* TVs do not scroll-bounce and a visible scrollbar reads as a bug. */
  overflow: hidden;
}

/* ⚠️ DO NOT set `font-size` on `html.tv`.
   watch.css uses 62 rem values, and rem resolves against the ROOT font size —
   so a root override silently rescales EVERY rem dimension in the app (1.5x at
   24px), which overflowed the top nav and blew out the hero. Caught in Chrome;
   the Node DOM shim cannot see it because it does not do layout.
   Ten-foot type is set explicitly per element below (§4.3), which is also what
   the six-level rule requires. `body` alone is safe — it does not move the rem
   basis — and gives unstyled text a floor. */
html.tv body {
  font-size: var(--tv-body);
}

/* A TV browser has no pointer by default; hide the cursor unless the LG Magic
   Remote wakes it (that pointer generates real mousemove events). */
html.tv:not(.tv-webos) body { cursor: none; }

/* ------------------------------------------------------------------ *
 * §3.2 — Focus is visible from ten feet.
 *
 * At LEAST two of scale / ring / lift, never colour alone: colour alone fails
 * colour-blind viewers and washes out on a bright living-room panel. Here we
 * use all three.
 * ------------------------------------------------------------------ */

html.tv :focus {
  outline: none;   /* replaced by the ring below, not removed */
}

html.tv a:focus,
html.tv button:focus,
html.tv select:focus,
html.tv input:focus,
html.tv [tabindex]:not([tabindex="-1"]):focus {
  outline: 3px solid var(--tv-focus-ring);
  outline-offset: 3px;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.75);
}

/* A series card lifts as well as rings: the focused card is the one bright
   thing in its row (§3.2). */
html.tv .g-tile {
  transition: transform 120ms ease-out;
  transform-origin: center center;
  /* scrollIntoView clears the unscaled box; the margin also clears the lift
     and the ring, which otherwise sat a few pixels under the panel's edge. */
  scroll-margin: 32px;
}

html.tv .ep-link,
html.tv .btn,
html.tv .nav-item { scroll-margin: 32px; }

html.tv .g-tile:focus {
  transform: scale(1.05);
  z-index: 5;   /* the lifted card must sit above its neighbors */
}

/* ------------------------------------------------------------------ *
 * Layout — overscan-safe insets (§4.2). The sidebar holds the left inset;
 * the views use the full width a phone-first max-width would waste.
 * ------------------------------------------------------------------ */

html.tv .sidebar {
  width: 360px;
  padding: var(--tv-overscan-y) 24px var(--tv-overscan-y) var(--tv-overscan-x);
  gap: 8px;
}

html.tv .sidebar-title {
  font-size: var(--tv-title-lg);
  padding: 0 16px 24px;
}

html.tv .nav-item {
  min-height: 64px;
  padding: 0 16px;
  gap: 16px;
  font-size: var(--tv-title);
}

html.tv .nav-item svg { width: 32px; height: 32px; }

html.tv .view {
  max-width: none;
  margin: 0;
  padding: var(--tv-overscan-y) var(--tv-overscan-x) var(--tv-overscan-y) 48px;
}

/* §1.7 no dead ends: the skip link, the phone tab bar and the site footer's
   web pages (not in a packaged app) have no meaning on a remote. Share needs
   a share sheet the TV does not have. */
html.tv .skip-link,
html.tv .tabbar,
html.tv .site-footer,
html.tv button[aria-label^="Share "] {
  display: none !important;
}

/* ------------------------------------------------------------------ *
 * Type — six levels (§4.3), set per element because rem must not move.
 * ------------------------------------------------------------------ */

html.tv .view-heading { font-size: var(--tv-hero); }
html.tv .section-header { font-size: var(--tv-title-lg); }
html.tv .body-strong { font-size: var(--tv-body-lg); }
html.tv .body,
html.tv .caption,
html.tv .tabular,
html.tv .btn { font-size: var(--tv-body); }

html.tv .block,
html.tv .shelf { margin-bottom: 48px; }
html.tv .shelf > .section-header,
html.tv .block-head { margin-bottom: 16px; }

/* §4.6 — rows at the root. Shelves get room to breathe, and the row is padded
   by the focus lift so a focused card's ring is never clipped (skill bug 5). */
html.tv .rail {
  grid-auto-columns: 340px;
  gap: 24px;
  padding: 16px 16px 24px;
  margin-left: -16px;
  margin-right: -16px;
  scroll-padding-inline: var(--tv-overscan-x);
  scrollbar-width: none;
}

html.tv .g-link {
  padding: 16px 12px;
}

html.tv .btn,
html.tv .icon-btn { min-height: 56px; }
html.tv .icon-btn { min-width: 56px; }
html.tv .icon-btn svg { width: 32px; height: 32px; }

/* ------------------------------------------------------------------ *
 * Player — the bar spans the panel inside the safe area; Now Playing is a
 * centered panel sized for the room.
 * ------------------------------------------------------------------ */

html.tv .player-row {
  padding: 12px var(--tv-overscan-x) 12px calc(360px + 48px);
  gap: 12px;
}

html.tv .now-playing {
  width: 960px;
  max-height: 90vh;
  padding: 0;
}

html.tv .np-inner {
  max-width: none;
  padding: 48px 64px;
  gap: 16px;
}

/* The web's backdrop is the text color at 40%, which in the dark palette
   lightens the room behind the panel; a TV dims it. */
html.tv .now-playing::backdrop { background: rgba(0, 0, 0, 0.7); opacity: 1; }

html.tv .np-controls { gap: 48px; }
html.tv .icon-btn-lg svg { width: 48px; height: 48px; }

/* The exit question Samsung's Return policy requires at the root (tv.js
   askToExit). Buttons take the shared focus ring above. */
html.tv dialog.tv-exit {
  background: var(--tv-bg);
  color: var(--tv-text);
  border: 0;
  padding: 48px 64px;
  text-align: center;
}
html.tv dialog.tv-exit::backdrop { background: rgba(0, 0, 0, 0.7); }
html.tv dialog.tv-exit p {
  font-size: var(--tv-title);
  margin: 0 0 32px 0;
}
html.tv dialog.tv-exit button {
  font-size: var(--tv-body-lg);
  min-width: 200px;
  margin: 0 12px;
  padding: 16px 32px;
}

html.tv .ear-drama-only { display: none !important; }

/* The read-along panel (PLAYS-DESIGN §2.11 rule 10): the line heard with one before and one after, the speaker in the part's hue,
   at the 28 px body (the ten-foot size Android TV's bodyLarge shares). No word mark, no controls; focus stays on the transport. */
html.tv .listen-now .script-line { max-width: none; margin-top: 12px; }
html.tv .listen-now .line-text, html.tv .listen-now .line-role { font-size: var(--tv-body-lg); }
html.tv .listen-now .line-role { color: var(--hue, var(--tv-text-muted)); font-weight: var(--type-body-strong-weight); }
html.tv .listen-now .panel-near .line-text { color: var(--tv-text-muted); }
