:root {
  --color-bg: #0b1026;
  --color-bg-glow: #1b2a6b;
  --color-surface: #f6f4ef;
  --color-surface-hover: #ffffff;
  --color-text: #eef0f8;
  --color-text-muted: #a9b0cc;
  --color-text-on-surface: #121735;
  --color-accent: #ff4d3d;
  --color-focus: #ffd34d;

  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;

  --text-sm: 0.875rem;
  --text-base: clamp(1rem, 0.94rem + 0.3vw, 1.125rem);
  --text-h2: clamp(1.05rem, 0.95rem + 0.5vw, 1.3rem);
  --text-hero: clamp(2.25rem, 1.2rem + 5vw, 4.5rem);

  --gutter: clamp(1rem, 0.5rem + 3vw, 3rem);
  --radius-card: 18px;
  --radius-pill: 999px;

  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

/* ---------- Maintenance page ---------- */

.page-maintenance {
  background:
    radial-gradient(60rem 40rem at 85% -10%, var(--color-bg-glow) 0%, transparent 60%),
    radial-gradient(40rem 30rem at -10% 110%, #3a1430 0%, transparent 60%),
    var(--color-bg);
}

/* faint scanlines for a broadcast "standby" feel */
.page-maintenance::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgb(255 255 255 / 0.025) 0 1px, transparent 1px 4px);
}

.site-header {
  position: absolute;
  top: var(--gutter);
  left: var(--gutter);
  z-index: 1;
}

.site-header__logo {
  display: block;
  width: auto;
  height: 40px;
}

.maintenance {
  position: relative;
  width: min(100%, 46rem);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  /* top padding always clears the absolutely positioned logo */
  padding: max(clamp(3rem, 8vh, 6rem), calc(var(--gutter) + 40px + 1.5rem)) var(--gutter) 3rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(2.5rem, 6vh, 4rem);
}

.on-air {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 1.25rem;
  padding: 0.35rem 0.9rem 0.35rem 0.75rem;
  border: 1px solid rgb(255 255 255 / 0.18);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.on-air__dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--color-focus);
  box-shadow: 0 0 0 0 rgb(255 211 77 / 0.6);
  animation: pulse 1.8s var(--ease-out-expo) infinite;
}

.on-air__dot--live {
  background: var(--color-accent);
  box-shadow: 0 0 0 0 rgb(255 77 61 / 0.6);
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  60% { transform: scale(1.6); opacity: 0.35; }
  100% { transform: scale(1); opacity: 1; }
}

.maintenance h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-hero);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.maintenance__lede {
  max-width: 34rem;
  margin: 1.25rem 0 0;
  color: var(--color-text-muted);
}

.channels h2 {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: var(--text-h2);
  font-weight: 600;
}

.channels__grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(0.75rem, 2vw, 1.25rem);
}

.channel-card {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  gap: 0.75rem;
  height: 100%;
  min-height: clamp(8rem, 18vw, 10rem);
  padding: 1.25rem 1rem 1rem;
  border-radius: var(--radius-card);
  background: var(--color-surface);
  color: var(--color-text-on-surface);
  text-decoration: none;
  box-shadow:
    0 1px 0 rgb(255 255 255 / 0.6) inset,
    0 12px 30px -12px rgb(0 0 0 / 0.6);
  transition:
    transform var(--duration-normal) var(--ease-out-expo),
    box-shadow var(--duration-normal) var(--ease-out-expo),
    background-color var(--duration-fast) ease;
}

.channel-card img {
  width: auto;
  max-width: 75%;
  height: auto;
  max-height: 3.25rem;
  object-fit: contain;
}

.channel-card__name {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.channel-card__cta {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--text-sm);
  font-weight: 700;
  color: #5a6080;
  transition: color var(--duration-fast) ease;
}

.channel-card__cta::before {
  content: '';
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0.32rem 0 0.32rem 0.5rem;
  border-color: transparent transparent transparent currentColor;
}

.channel-card:hover,
.channel-card:focus-visible {
  background: var(--color-surface-hover);
  transform: translateY(-4px);
  box-shadow:
    0 1px 0 rgb(255 255 255 / 0.6) inset,
    0 22px 40px -14px rgb(0 0 0 / 0.75),
    0 0 0 2px var(--color-accent);
}

.channel-card:hover .channel-card__cta,
.channel-card:focus-visible .channel-card__cta {
  color: var(--color-accent);
}

.channel-card:active {
  transform: translateY(-1px) scale(0.99);
}

/* ---------- Player page ---------- */

.page-player {
  display: flex;
  flex-direction: column;
  background: #000;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem var(--gutter);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.95rem 0.45rem 0.7rem;
  border: 1px solid rgb(255 255 255 / 0.2);
  border-radius: var(--radius-pill);
  color: var(--color-text);
  font-weight: 500;
  text-decoration: none;
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease;
}

.back-link svg {
  transition: transform var(--duration-normal) var(--ease-out-expo);
}

.back-link:hover {
  background: rgb(255 255 255 / 0.1);
  border-color: rgb(255 255 255 / 0.4);
}

.back-link:hover svg {
  transform: translateX(-3px);
}

.player-bar__title {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
}

.player-bar__replay {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.player-bar__replay[hidden] {
  display: none;
}

.player-bar__tag {
  flex: none;
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-pill);
  background: var(--color-focus);
  color: var(--color-text-on-surface);
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.player-bar__replay-title {
  overflow: hidden;
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--color-text-muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.go-live {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  padding: 0.45rem 0.95rem 0.45rem 0.8rem;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-pill);
  background: rgb(255 77 61 / 0.14);
  color: var(--color-text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) ease,
    transform var(--duration-fast) ease;
}

.go-live[hidden] {
  display: none;
}

.go-live:hover {
  background: var(--color-accent);
}

.go-live:active {
  transform: scale(0.97);
}

.go-live:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

.go-live:not([hidden]) + .epg-toggle {
  margin-left: 0;
}

.go-live__short {
  display: none;
}

/* Narrow phones: the REPLAY tag + "Live" button carry the state; wrap as a last resort */
@media (max-width: 479px) {
  .player-bar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .player-bar__replay-title,
  .go-live__full {
    display: none;
  }

  .go-live__short {
    display: inline;
  }
}

.player-stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 0 var(--gutter) var(--gutter);
}

/* keep 16:9 fully visible on any viewport, landscape or portrait */
.player-frame {
  position: relative;
  width: min(100%, (100dvh - 5rem) * 16 / 9);
}

.player-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.75rem;
  text-align: center;
  background: rgb(0 0 0 / 0.85);
}

.player-error[hidden] {
  display: none;
}

.player-error p {
  margin: 0;
}

.player-error a {
  color: var(--color-focus);
  font-weight: 700;
}

/* ---------- Programme guide (EPG) ---------- */

.epg-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
  padding: 0.45rem 0.95rem 0.45rem 0.75rem;
  border: 1px solid rgb(255 255 255 / 0.2);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.epg-toggle[hidden] {
  display: none;
}

.epg-toggle:hover {
  background: rgb(255 255 255 / 0.1);
  border-color: rgb(255 255 255 / 0.4);
}

.epg-toggle[aria-expanded='true'] {
  background: var(--color-surface);
  border-color: var(--color-surface);
  color: var(--color-text-on-surface);
}

.epg-toggle:focus-visible,
.epg-day:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

.epg {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: var(--radius-card);
  background: linear-gradient(to bottom, rgb(27 42 107 / 0.35), rgb(11 16 38 / 0.6));
  overflow: hidden;
  animation: epg-in var(--duration-normal) var(--ease-out-expo);
}

.epg[hidden] {
  display: none;
}

@keyframes epg-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.epg__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem 0.5rem;
}

.epg__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-h2);
  font-weight: 600;
}

.epg__tz {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.epg__days {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1.1rem 0.85rem;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid rgb(255 255 255 / 0.08);
}

.epg-day {
  flex: none;
  display: grid;
  justify-items: start;
  padding: 0.4rem 0.8rem;
  border: 1px solid rgb(255 255 255 / 0.15);
  border-radius: 12px;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  line-height: 1.2;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease;
}

.epg-day:hover {
  background: rgb(255 255 255 / 0.08);
}

.epg-day[aria-pressed='true'] {
  background: var(--color-surface);
  border-color: var(--color-surface);
  color: var(--color-text-on-surface);
}

.epg-day__name {
  font-size: var(--text-sm);
  font-weight: 700;
}

.epg-day__date {
  font-size: 0.75rem;
  opacity: 0.7;
}

.epg__status {
  margin: 0;
  padding: 1.5rem 1.1rem;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.epg__status[hidden] {
  display: none;
}

.epg__list {
  position: relative; /* offsetTop reference for scroll-to-live */
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0.5rem 0.6rem 0.75rem;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.epg-item {
  position: relative;
  display: grid;
  grid-template-columns: 4.6rem minmax(0, 1fr);
  gap: 0.75rem;
  padding: 0.6rem 0.6rem 0.6rem 0.75rem;
  border-radius: 10px;
  font-size: var(--text-sm);
  overflow: hidden;
}

.epg-item + .epg-item {
  margin-top: 2px;
}

.epg-item__time {
  display: grid;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1.3;
}

.epg-item__end {
  font-weight: 400;
  color: var(--color-text-muted);
}

.epg-item__body {
  display: grid;
  gap: 0.3rem;
  align-content: start;
}

.epg-item__title {
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.epg-item.is-past {
  color: var(--color-text-muted);
  transition: background-color var(--duration-fast) ease, color var(--duration-fast) ease;
}

.epg-item.is-past:hover,
.epg-item.is-past:focus-within {
  background: rgb(255 255 255 / 0.06);
  color: var(--color-text);
}

.epg-item.is-replaying {
  background: rgb(255 211 77 / 0.12);
  box-shadow: inset 3px 0 0 var(--color-focus);
  color: var(--color-text);
}

.epg-item.is-replaying .epg-item__title {
  font-weight: 700;
}

.epg-item__badge.epg-item__badge--replay {
  color: var(--color-focus);
}

.epg-item__badge--replay .on-air__dot {
  background: var(--color-focus);
  box-shadow: none;
}

/* Stretched button: the ::after covers the whole row, the pill is the visible label. */
.epg-item__action {
  justify-self: start;
  padding: 0.15rem 0.6rem;
  border: 1px solid rgb(255 255 255 / 0.25);
  border-radius: var(--radius-pill);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.epg-item__action::after {
  content: '';
  position: absolute;
  inset: 0;
}

.epg-item:hover .epg-item__action,
.epg-item__action:focus-visible {
  background: var(--color-surface);
  border-color: var(--color-surface);
  color: var(--color-text-on-surface);
}

.epg-item__action:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.epg-item.is-live .epg-item__action {
  border-color: var(--color-accent);
}

.epg-item.is-live {
  background: rgb(255 77 61 / 0.14);
  box-shadow: inset 3px 0 0 var(--color-accent);
}

.epg-item.is-live .epg-item__title {
  font-weight: 700;
}

.epg-item__badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-accent);
}

.epg-item__badge .on-air__dot {
  width: 0.45rem;
  height: 0.45rem;
}

.epg-item__progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--color-accent);
  transform-origin: left;
  transform: scaleX(var(--progress, 0));
  transition: transform var(--duration-normal) var(--ease-out-expo);
}

/* Mobile portrait: player on top, schedule fills the rest of the screen */
@media (max-width: 959px) and (orientation: portrait) {
  .page-player.is-epg-open {
    height: 100vh;
    height: 100dvh;
  }

  .is-epg-open .player-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    min-height: 0;
  }

  .is-epg-open .epg {
    flex: 1;
  }
}

@media (max-width: 959px) and (orientation: landscape) {
  .is-epg-open .player-stage {
    gap: 1rem;
  }
}

/* ---------- Desktop ---------- */

@media (min-width: 960px) {
  :root {
    --text-base: clamp(1.2rem, 0.8rem + 0.6vw, 1.45rem);
    --text-h2: clamp(1.5rem, 0.9rem + 0.9vw, 2rem);
    --text-hero: clamp(4.5rem, 1rem + 6vw, 7.5rem);
  }

  .maintenance {
    width: min(100%, 78rem);
  }

  .on-air {
    font-size: 1rem;
    padding: 0.5rem 1.1rem 0.5rem 0.95rem;
  }

  .maintenance__lede {
    max-width: 44rem;
    margin-top: 1.75rem;
  }

  .channels h2 {
    margin-bottom: 1.5rem;
  }

  .channels__grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.5rem;
  }

  .channel-card {
    min-height: 13rem;
    padding: 2rem 1.5rem 1.5rem;
  }

  .channel-card img {
    max-height: 4.5rem;
  }

  .channel-card__cta {
    font-size: 1.05rem;
  }

  .back-link,
  .player-bar__title,
  .epg-toggle {
    font-size: 1.15rem;
  }

  /* player and schedule side by side */
  .is-epg-open .player-stage {
    grid-template-columns: minmax(0, 1fr) clamp(20rem, 24vw, 26rem);
    gap: var(--gutter);
  }

  .is-epg-open .epg {
    align-self: stretch;
    height: calc(100dvh - 5rem - var(--gutter));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
