/*
 * Styles shared by every page: design tokens (light and dark, following the system
 * setting), the app header and search, the guide grid, the programme popup, and the pieces
 * the popup and the detail pages share (tags, facts, timetable, logo tiles).
 * The detail pages add detail.css.
 */

/* ---------- Tokens ---------- */

:root {
  color-scheme: light dark;

  /* Brand: the header, time axis and channel column stay navy in both themes, and the
     channel logos are the variants drawn for dark backgrounds */
  --brand: #0b2545;
  --brand-2: #102e55;
  --brand-3: #184374; /* the bright end of the header gradients */
  --brand-line: rgba(255, 255, 255, 0.12);
  --on-brand: #ffffff;
  --on-brand-muted: rgba(255, 255, 255, 0.72);

  /* Surfaces, from the page background up */
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --surface-3: #e8ecf1;
  --line: #dfe4ea;
  --line-strong: #c9d0d9;

  /* Text */
  --text: #111827;
  --text-2: #374151;
  --muted: #586373;

  /* Accents */
  --accent: #1d4ed8;
  --accent-soft: #e6eeff;
  --focus: #2563eb;
  --live: #dc2626;
  --live-text: #b91c1c;
  --on-live: #ffffff;
  --star: #92400e;
  --star-soft: #fef3c7;

  /* Grid rows: every other row is tinted, gaps in the listings are hatched, and finished
     programmes are shaded over their row's colour */
  --row: #ffffff;
  --row-alt: #f3f5f8;
  --row-hatch: rgba(100, 112, 140, 0.1);
  --past-shade: rgba(30, 50, 80, 0.07);
  /* The "now" marker: a thin line in a faint band, and a notch under the time axis */
  --now-line: rgba(0, 0, 0, 0.25);
  --now-band: rgba(0, 0, 0, 0.05);
  --now-notch: rgba(11, 37, 69, 0.5);

  /* Elevation */
  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-2: 0 8px 24px rgba(15, 23, 42, 0.14);
  --shadow-3: 0 24px 64px rgba(15, 23, 42, 0.28);
  /* The time axis and channel column cast these onto the grid, so it scrolls beneath them */
  --shadow-axis: 0 0 10px 1px rgba(0, 0, 0, 0.5);
  --shadow-column: 2px 0 10px -2px rgba(0, 0, 0, 0.5);
  --overlay: rgba(8, 12, 20, 0.6);

  /* Type */
  --font:
    system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 1.75rem;
  /* Weights: titles of listed things (programmes, people, search results) are regular, so
     the guide reads lightly; buttons, tags and labels medium; headings semibold */
  --fw-item: 400;
  --fw-label: 500;
  --fw-heading: 600;

  /* Shape */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --header-height: 3.25rem;

  /* Grid layout (epg-grid.js reads --hour-width, --channel-width and --time-height) */
  --channel-width: 7.5rem;
  --channel-height: 3.75rem;
  --time-height: 3.125rem;
  --hour-width: 15rem;
  --program-image-width: 40px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #0a1628;
    --brand-2: #0f2038;
    --brand-3: #17304f;
    --brand-line: rgba(255, 255, 255, 0.08);

    --bg: #0b0e13;
    --surface: #161b22;
    --surface-2: #11151b;
    --surface-3: #212833;
    --line: #262d38;
    --line-strong: #364151;

    --text: #eef1f5;
    --text-2: #c9cfd8;
    --muted: #949eac;

    --accent: #8ab4f8;
    --accent-soft: rgba(138, 180, 248, 0.14);
    --focus: #8ab4f8;
    --live: #f05252;
    --live-text: #f87171;
    --star: #fbbf24;
    --star-soft: rgba(251, 191, 36, 0.12);

    --row: #161b22;
    --row-alt: #1c222b;
    --row-hatch: rgba(148, 163, 184, 0.07);
    --past-shade: rgba(0, 0, 0, 0.3);
    --now-line: rgba(255, 255, 255, 0.3);
    --now-band: rgba(255, 255, 255, 0.05);
    --now-notch: rgba(255, 255, 255, 0.3);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-3: 0 24px 64px rgba(0, 0, 0, 0.6);
    --shadow-axis: 0 0 12px 2px rgba(0, 0, 0, 0.7);
    --shadow-column: 3px 0 12px -2px rgba(0, 0, 0, 0.7);
  }
}

@media (max-width: 768px) {
  :root {
    --header-height: 3rem;
    --hour-width: 12rem;
    --channel-width: 70px;
    --channel-height: 50px;
    --time-height: 40px;
  }
}

/* ---------- Base ---------- */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  /* macOS otherwise thickens text, most visibly white on the navy header and in dark mode */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent);
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

/* ---------- App header (every page) ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) calc(0.75rem + env(safe-area-inset-right, 0px)) 0
    calc(0.75rem + env(safe-area-inset-left, 0px));
  background: var(--brand);
  color: var(--on-brand);
  border-bottom: 1px solid var(--brand-line);
}

.app-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0 0.375rem;
  margin-right: auto;
  border-radius: var(--r-md);
  color: var(--on-brand);
  text-decoration: none;
}

.app-brand:hover {
  background: rgba(255, 255, 255, 0.08);
}

.app-brand img {
  width: 1.5rem;
  height: 1.5rem;
}

.app-brand .back-arrow {
  margin-right: -0.125rem;
  opacity: 0.8;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--on-brand);
  cursor: pointer;
}

.icon-button:hover,
.icon-button[aria-expanded='true'] {
  background: rgba(255, 255, 255, 0.12);
}

.icon-button:disabled {
  opacity: 0.35;
  cursor: default;
  background: transparent;
}

.icon-button svg {
  width: 1.375rem;
  height: 1.375rem;
}

/* The guide's day strip: a tab per day with listings, between the icon and search. Too narrow
   for every day, it scrolls sideways. */
.day-nav {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.125rem;
  min-width: 0;
  margin-right: auto;
  padding: 2px; /* room for the focus ring, which the scrolling would otherwise clip */
  overflow-x: auto;
  scrollbar-width: none;
}

.day-nav::-webkit-scrollbar {
  display: none;
}

.day-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 3rem;
  height: 2.5rem;
  padding: 0 0.375rem;
  border-radius: var(--r-md);
  color: var(--on-brand-muted);
  line-height: 1.15;
  text-decoration: none;
}

.day-tab:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--on-brand);
}

.day-tab[aria-current='page'] {
  background: var(--on-brand);
  color: var(--brand);
}

.day-tab:focus-visible {
  outline-offset: 0;
}

.day-tab-name {
  font-size: var(--fs-xs);
  font-weight: var(--fw-label);
}

.day-tab-date {
  font-size: var(--fs-md);
  font-weight: var(--fw-heading);
  font-variant-numeric: tabular-nums;
}

/* ---------- Search (in the header) ---------- */

#search-container {
  position: relative;
}

.search-panel {
  display: none;
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: min(26rem, calc(100vw - 1.5rem));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
}

#search-container.expanded .search-panel {
  display: block;
}

#search-input {
  display: block;
  width: 100%;
  padding: 0.875rem 1rem;
  border: none;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* stops iOS zooming in */
  -webkit-appearance: none;
  appearance: none;
}

#search-input::placeholder {
  color: var(--muted);
}

#search-input:focus {
  outline: none;
}

.search-results {
  display: none;
  max-height: min(26rem, 60vh);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item.selected {
  background: var(--surface-2);
}

.search-result-item.selected {
  box-shadow: inset 3px 0 0 var(--accent);
}

.search-result-title {
  font-weight: var(--fw-item);
  font-size: var(--fs-sm);
}

.search-result-meta {
  margin-top: 0.125rem;
  color: var(--muted);
  font-size: var(--fs-xs);
}

.search-no-results,
.search-loading {
  padding: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* ---------- Guide page layout ---------- */

/* The page itself scrolls the grid, both ways, so Safari on a phone lets the listings run
   under its toolbar and shrinks the toolbar as you scroll. The header is fixed; the time axis,
   the corner and the channel column are sticky. */
html:has(> body.guide-page) {
  /* Scrolling back past the start of the day shouldn't swipe back a page */
  overscroll-behavior-x: none;
  /* Keyboard focus scrolls programmes clear of the header, time axis and channel column */
  scroll-padding: calc(var(--header-height) + env(safe-area-inset-top, 0px) + var(--time-height)) 0
    0 calc(var(--channel-width) + env(safe-area-inset-left, 0px));
}

/* Opening the popup holds the page still behind it */
html.modal-open {
  overflow: hidden;
}

body.guide-page {
  --grid-top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  /* In landscape the channel column also covers the notch side, its contents clear of it */
  --column-width: calc(var(--channel-width) + env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: var(--grid-top);
  /* Opened from the Home Screen, this lets the last row scroll clear of the home indicator */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

body.guide-page .app-header {
  position: fixed;
  right: 0;
  left: 0;
}

#epg-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: fit-content;
  min-width: 100%;
  background: var(--surface);
  cursor: grab;
}

#epg-container.dragging {
  cursor: grabbing;
  user-select: none;
}

#epg-container.dragging * {
  cursor: grabbing;
}

#sticky-container {
  position: relative;
  display: flex;
  width: fit-content;
  min-width: 100%;
}

/* ---------- Time axis ---------- */

#time-axis {
  position: sticky;
  top: var(--grid-top);
  z-index: 12;
  display: flex;
  width: fit-content;
  min-width: calc(var(--day-hours, 24) * var(--hour-width));
  height: var(--time-height);
  margin-left: calc(-1 * var(--column-width));
  padding-left: var(--column-width);
  background: var(--brand-2);
  box-shadow:
    0 1px 0 var(--brand-line),
    var(--shadow-axis);
}

/* Each hour shades from dark to bright navy, with a faint tick at the half hour */
.time-slot {
  display: flex;
  align-items: center;
  width: var(--hour-width);
  height: 100%;
  padding-left: 0.5rem;
  border-left: 1px solid var(--brand-line);
  background:
    linear-gradient(var(--brand-line), var(--brand-line)) 50% 100% / 1px 35% no-repeat,
    linear-gradient(90deg, var(--brand-2), var(--brand-3));
  color: var(--on-brand);
  font-size: var(--fs-sm);
  font-weight: var(--fw-item);
  font-variant-numeric: tabular-nums;
}

/* The top-left corner, above the channel column: stays put while the hours scroll under it */
.time-axis-corner {
  position: sticky;
  left: 0;
  z-index: 2;
  flex-shrink: 0;
  width: var(--column-width);
  margin-left: calc(-1 * var(--column-width));
  background: var(--brand-2);
  box-shadow: 1px 0 0 var(--brand-line);
}

/* ---------- Channel column ---------- */

/* A layer as wide as the grid, so the channel column in it can stick to the left edge. It needs
   a compositing layer of its own (will-change): without one, Safari on a phone draws the sticky
   column only down to about the top of its toolbar, though the listings show through it */
#channel-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  width: 100%;
  padding-top: var(--time-height);
  pointer-events: none;
  will-change: transform;
}

#channel-list {
  position: sticky;
  left: 0;
  display: block;
  width: var(--column-width);
  padding-left: env(safe-area-inset-left, 0px);
  background: var(--brand-2);
  box-shadow:
    1px 0 0 var(--brand-line),
    var(--shadow-column);
  pointer-events: auto;
}

.channel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  height: var(--channel-height);
  padding: 0.25rem;
  border-bottom: 1px solid var(--brand-line);
  background: linear-gradient(var(--brand-2), var(--brand-3));
  color: var(--on-brand);
}

.channel-logo {
  flex-shrink: 0;
  width: 40px;
  height: 30px;
  object-fit: contain;
}

/* Grid images wait in data-src until they're near the screen (utils/lazy-images.js); hide
   them until then so the alt text doesn't show */
img[data-src] {
  visibility: hidden;
}

.channel-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.channel-number {
  color: var(--on-brand-muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

/* ---------- Programme grid ---------- */

#programs-container {
  position: relative;
  flex: 1;
  margin-left: var(--column-width);
  width: calc(var(--day-hours, 24) * var(--hour-width));
}

#programs-grid,
#programs-grid > [role='rowgroup'] {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Rows alternate in colour; gaps in a channel's listings show the row's diagonal stripes */
.channel-row {
  --row-bg: var(--row);
  position: relative;
  display: flex;
  width: calc(var(--day-hours, 24) * var(--hour-width));
  height: var(--channel-height);
  /* A programme starting just before midnight is widened to the 48px minimum; clip it at the
     day's end so it doesn't widen the grid */
  overflow: clip;
  border-bottom: 1px solid var(--line);
  background-color: var(--row-bg);
  background-image: linear-gradient(
    to left top,
    transparent 25%,
    var(--row-hatch) 0 50%,
    transparent 0 75%,
    var(--row-hatch) 0
  );
  background-size: 1rem 1rem;
}

.channel-row:nth-child(even) {
  --row-bg: var(--row-alt);
}

.program {
  position: absolute;
  display: flex;
  align-items: stretch;
  height: 100%;
  min-width: 48px;
  overflow: hidden;
  border-left: 1px solid var(--line);
  background-color: var(--row-bg);
  cursor: pointer;
  /* Each cell lays out and paints on its own (no per-cell GPU layers: there are thousands) */
  contain: layout style paint;
}

.program:hover {
  background-color: var(--surface-3);
}

.program:focus {
  z-index: 2;
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

/* Highlight for a programme opened from a shared link */
@keyframes highlightPulse {
  0% {
    box-shadow: inset 0 0 0 3px var(--focus);
  }
  100% {
    box-shadow: inset 0 0 0 3px transparent;
  }
}

.program.highlight-pulse {
  z-index: 10;
  animation: highlightPulse 1s ease-out 3;
}

.program-image {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: var(--program-image-width);
  height: 100%;
  padding: 0.25rem;
  overflow: hidden;
}

.program-image img {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  object-fit: cover;
}

.program-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 0.125rem;
  min-width: 0;
  padding: 0 0.5rem;
}

.program-title {
  overflow: hidden;
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: var(--fw-item);
  white-space: nowrap;
  text-overflow: ellipsis;
  text-decoration: none;
}

/* The title link covers the whole cell, so a tap anywhere on it opens the programme */
.program-title-link::after {
  content: '';
  position: absolute;
  inset: 0;
}

.program-time {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.program-new {
  margin-right: 0.3rem;
  color: var(--live-text);
  font-weight: var(--fw-heading);
}

/* Finished programmes recede (keeping the row stripes); the "now" line marks the boundary */
.program.is-past {
  background-image: linear-gradient(var(--past-shade), var(--past-shade));
}

.program.is-past .program-title {
  color: var(--muted);
}

.program.is-past img {
  opacity: 0.45;
}

.program.is-live .program-time::before {
  content: '';
  display: inline-block;
  width: 0.4375rem;
  height: 0.4375rem;
  margin-right: 0.3rem;
  border-radius: 50%;
  background: var(--live);
  vertical-align: 1px;
}

.program.continues-from-yesterday,
.program.continues-to-tomorrow {
  mask-size:
    0.5rem 0.5rem,
    100% 100%;
  mask-repeat: repeat-y;
}

.program.continues-from-yesterday {
  mask-image:
    linear-gradient(to top left, #fff, #fff 50%, transparent 0, transparent),
    linear-gradient(270deg, transparent 0.5rem, #000 0, #fff);
  mask-position: top left;
}

.program.continues-to-tomorrow {
  mask-image:
    linear-gradient(to top right, #fff, #fff 50%, transparent 0, transparent),
    linear-gradient(270deg, transparent 0.5rem, #000 0, #fff);
  mask-position: top right;
}

/* The "now" line: 1px wide, centred in a faint band, with a notch that stays under the time
   axis. The band is the borders; the background only fills the padding box, i.e. the line. */
.current-time-indicator {
  --now-band-width: 0.5rem;
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  box-sizing: border-box;
  width: calc(2 * var(--now-band-width) + 1px);
  margin-left: calc(-1 * var(--now-band-width));
  border-right: var(--now-band-width) solid var(--now-band);
  border-left: var(--now-band-width) solid var(--now-band);
  background: var(--now-line);
  background-clip: padding-box;
  pointer-events: none;
  transition: left 0.5s ease-out;
}

.current-time-indicator::before {
  content: '';
  position: sticky;
  top: calc(var(--grid-top) + var(--time-height));
  display: block;
  width: 0;
  height: 0;
  margin-left: calc(-1 * var(--now-band-width));
  border: var(--now-band-width) solid transparent;
  border-top-color: var(--now-notch);
}

/* ---------- Guide states ---------- */

.epg-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--muted);
  font-size: var(--fs-md);
}

.epg-error {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  text-align: center;
}

.epg-error h2 {
  font-size: var(--fs-xl);
}

.epg-error .error-icon {
  font-size: 2rem;
}

.epg-error .error-message,
.epg-error .error-help {
  color: var(--muted);
}

.epg-error .error-actions {
  margin-top: 0.75rem;
}

.button,
.retry-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0 1.25rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-weight: var(--fw-label);
  text-decoration: none;
  cursor: pointer;
}

.button:hover,
.retry-button:hover {
  background: var(--surface-2);
}

/* Day with no listings: a card over the (empty) grid */
.epg-empty {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 50;
  max-width: calc(100% - 2rem);
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.epg-empty-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-heading);
}

.epg-empty-help {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* ---------- Shared pieces (popup and detail pages) ---------- */

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.0625rem 0.4375rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-label);
  line-height: 1.5;
}

.tag-new {
  border-color: var(--live);
  background: var(--live);
  color: var(--on-live);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag-stars {
  border-color: transparent;
  background: var(--star-soft);
  color: var(--star);
}

.tag-genre {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
}

/* Label/value rows: cast, crew, genre and so on */
.facts {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.5rem 1rem;
  font-size: 0.9375rem;
  line-height: 1.45;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  color: var(--text-2);
}

.facts a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 2px;
}

.facts a:hover {
  color: var(--text);
  text-decoration-color: currentColor;
}

.section-title {
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-heading);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Channel logo on a navy tile (the logos are drawn for dark backgrounds) */
.logo-tile {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 2.625rem;
  padding: 0.25rem;
  border-radius: 6px;
  background: var(--brand-2);
}

.logo-tile img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.logo-tile-small {
  width: 2.5rem;
  height: 1.875rem;
  padding: 0.1875rem;
  border-radius: var(--r-sm);
}

/* Airings as a timetable: day (once per day), time, logo, channel */
.timetable {
  list-style: none;
}

.timetable li.new-day:not(:first-child) {
  margin-top: 0.25rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--line);
}

.timetable-row {
  display: grid;
  grid-template-columns: 6rem 3rem auto minmax(0, 1fr);
  align-items: center;
  gap: 0.75rem;
  margin: 0 -0.5rem;
  padding: 0.375rem 0.5rem;
  border-radius: 6px;
  color: inherit;
  font-size: 0.9375rem;
  text-decoration: none;
}

.timetable-row:hover {
  background: var(--surface-2);
}

.timetable-row.is-past {
  opacity: 0.55;
}

.timetable-day {
  font-weight: var(--fw-label);
}

.timetable-time {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.timetable-channel {
  overflow: hidden;
  color: var(--text-2);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.timetable-more {
  color: var(--muted);
  font-size: 0.8125rem;
}

/* Rows that name the programme (the person page) put the channel underneath */
.timetable-title,
.timetable-on {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timetable-title {
  color: var(--text);
  font-weight: var(--fw-item);
}

.timetable-on {
  color: var(--muted);
  font-size: var(--fs-xs);
}

.live-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.375rem;
  border-radius: 50%;
  background: var(--live);
  vertical-align: 1px;
  animation: pulse 2s ease-in-out infinite;
}

/* Loading placeholder lines */
.skeleton {
  display: grid;
  gap: 0.625rem;
  margin-bottom: 1.5rem;
}

.skeleton span {
  height: 0.875rem;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.skeleton span:last-child {
  width: 60%;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ---------- Programme popup ---------- */

.program-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(2rem, env(safe-area-inset-top, 0px)) max(2rem, env(safe-area-inset-right, 0px))
    max(2rem, env(safe-area-inset-bottom, 0px)) max(2rem, env(safe-area-inset-left, 0px));
  background: transparent;
  transition:
    background 0.25s ease,
    backdrop-filter 0.25s ease;
}

.program-modal-overlay.active {
  background: var(--overlay);
  backdrop-filter: blur(4px);
}

.program-modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 680px;
  max-height: min(90vh, 900px);
  overflow: hidden;
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
}

.program-modal-overlay.active .program-modal {
  opacity: 1;
  transform: none;
}

.program-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  color: #fff;
  cursor: pointer;
}

.program-modal-close:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* No scrollbar: where the system shows one permanently (a Mac with a mouse, Windows) it takes a
   column down the panel's edge, beside the banner. The panel still scrolls, and the content cut
   off at the bottom shows there's more. */
.program-modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.program-modal-body::-webkit-scrollbar {
  display: none;
}

/* Wide artwork across the top, fading into the panel */
.modal-banner {
  position: relative;
  width: 100%;
  max-height: 340px;
  aspect-ratio: 16 / 9;
  background: var(--surface-2);
}

.modal-banner img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-banner::after {
  content: '';
  position: absolute;
  inset: 45% 0 0;
  background: linear-gradient(to bottom, transparent, var(--surface));
}

.modal-content {
  position: relative;
  padding: 1.75rem 2rem 2rem;
}

/* The title sits on the banner's fade */
.modal-content.has-banner {
  margin-top: -3.5rem;
  padding-top: 0;
}

.modal-heading {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

/* Clear of the close button when there's no banner */
.modal-content:not(.has-banner) .modal-heading {
  padding-right: 2.5rem;
}

.modal-heading-text {
  min-width: 0;
}

.modal-heading .tags {
  margin-top: 0.625rem;
}

.modal-poster {
  flex: none;
  width: 80px;
  height: auto;
  border-radius: 6px;
  box-shadow: var(--shadow-2);
}

.modal-title {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-heading);
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.modal-subtitle {
  margin-top: 0.375rem;
  color: var(--text-2);
  font-size: var(--fs-md);
}

/* This airing: channel, day and time, and how much is left when it's on now */
.modal-airing {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  margin-bottom: 1.5rem;
  padding: 0.75rem 1rem 0.75rem 0.75rem;
  overflow: hidden;
  border-radius: 10px;
  background: var(--surface-2);
  color: inherit;
  text-decoration: none;
}

.modal-airing:hover {
  background: var(--surface-3);
}

.modal-airing-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.modal-airing-when {
  font-weight: var(--fw-label);
}

.modal-airing-channel {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.modal-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--live);
}

.modal-description {
  margin-bottom: 1.5rem;
  color: var(--text-2);
  font-size: var(--fs-md);
  line-height: 1.6;
}

.modal-notice {
  margin-bottom: 1.25rem;
  color: var(--live-text);
  font-size: var(--fs-sm);
}

.modal-content .facts {
  margin-bottom: 1.5rem;
}

.modal-section {
  margin-bottom: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.modal-more-link {
  display: block;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: var(--fw-label);
  text-align: center;
  text-decoration: none;
}

.modal-more-link::after {
  content: ' →';
}

.modal-more-link:hover {
  background: var(--surface-2);
}

.modal-more-link + .modal-more-link {
  margin-top: 0.5rem;
}

/* ---------- Phones ---------- */

@media (max-width: 768px) {
  .search-panel {
    position: fixed;
    top: calc(var(--header-height) + env(safe-area-inset-top, 0px));
    right: 0;
    left: 0;
    width: auto;
    border-width: 0 0 1px;
    border-radius: 0 0 var(--r-lg) var(--r-lg);
  }

  .search-result-item {
    min-height: 44px;
    padding: 0.875rem 1rem;
  }

  .channel-logo {
    width: 40px;
    height: 24px;
  }

  .program-content {
    padding: 0 0.375rem;
  }

  .program-title {
    font-size: 0.8125rem;
  }

  /* On the guide the icon would only do what Today does, so the days have the width up to
     search to themselves */
  body.guide-page .app-brand {
    display: none;
  }

  .day-nav {
    flex: 1;
  }

  .day-tab {
    flex: 1 1 0;
    min-width: auto;
    max-width: 3.5rem;
    padding: 0 0.125rem;
  }

  /* Centred when they reach their full width; the margins come to nothing if they overflow */
  .day-tab:first-child {
    margin-left: auto;
  }

  .day-tab:last-child {
    margin-right: auto;
  }

  .time-slot {
    padding-left: 0.375rem;
    font-size: var(--fs-xs);
  }

  #sticky-container {
    touch-action: pan-x pan-y;
  }

  .program {
    touch-action: pan-x pan-y;
  }

  /* Full-screen sheet */
  .program-modal-overlay {
    padding: 0;
  }

  .program-modal {
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    transform: translateY(24px);
  }

  .program-modal-close {
    top: calc(0.75rem + env(safe-area-inset-top, 0px));
    right: calc(0.75rem + env(safe-area-inset-right, 0px));
    width: 2.75rem;
    height: 2.75rem;
  }

  .modal-banner {
    max-height: none;
  }

  .modal-content {
    padding: calc(1.25rem + env(safe-area-inset-top, 0px)) 1rem
      calc(1.5rem + env(safe-area-inset-bottom, 0px));
  }

  .modal-content.has-banner {
    margin-top: -2.5rem;
    padding-top: 0;
  }

  .modal-content:not(.has-banner) .modal-heading {
    padding-right: 3rem;
  }

  .modal-title {
    font-size: var(--fs-xl);
  }

  .modal-poster {
    width: 72px;
  }

  .facts {
    grid-template-columns: 6.25rem 1fr;
    font-size: var(--fs-sm);
  }

  .timetable-row {
    grid-template-columns: 4.5rem 2.75rem auto minmax(0, 1fr);
    gap: 0.5rem;
    font-size: var(--fs-sm);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
