/* =====================================================================
   live.css: TV en vivo (categories, stage + now playing, channel list,
   number entry over the stage). Mobile-first: one column; ≤860 portrait
   pins the stage under the header; ≥1024 stage and list side by side,
   both sticky; short landscape puts them side by side without sticking.
   ===================================================================== */

.live {
  display: flex; flex-direction: column; gap: 16px;
  padding: calc(var(--header-h) + 16px) var(--gutter) 24px;
}

/* ---------------------------------------------------------- categories */
.live__cats { display: flex; align-items: center; gap: 12px; min-width: 0; }
/* The fade sits in the gutter and in the track's own padding, so the first and last
   chip are fully opaque at the ends; 6px of block padding keeps the 3px ring unclipped. */
.live__cat-track {
  --fade: min(24px, var(--gutter));
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 8px;
  overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  padding: 6px var(--fade); margin: -6px 0 -6px calc(-1 * var(--fade));
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--fade), #000 calc(100% - var(--fade)), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 var(--fade), #000 calc(100% - var(--fade)), transparent 100%);
}
.live__cat-track::-webkit-scrollbar { display: none; }
/* TV: the focused chip scales 1.06, so its ring reaches about 9px out. */
html.is-tv .live__cat-track { padding-top: 10px; padding-bottom: 10px; margin-top: -10px; margin-bottom: -10px; }
.live__cat-track .chip { flex: none; }
.live__cat-track .chip .icon { width: 16px; height: 16px; }
.live__cat-count { color: var(--text-3); font-weight: 500; }
.live__cat-track .chip[aria-pressed="true"] .live__cat-count { color: inherit; opacity: .6; }
/* The jump list repeats the selected chip, so it stays a neutral chip instead of a second white one. */
.live__picker { flex: none; }
.live__picker .picker[data-set] { background: var(--fill-1); color: var(--text); font-weight: 500; }
.live__picker .picker[data-set] .icon { color: var(--text-2); }
@media (hover: hover) and (pointer: fine) { .live__picker .picker[data-set]:hover { background: var(--fill-3); } }
@media (max-width: 599px) { .live__picker .picker__text { max-width: 11ch; } }

/* --------------------------------------------------------- stage + now */
.live__main { min-width: 0; max-width: 960px; }
.live__now {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  margin-top: 12px;
}
.live__now-logo {
  display: flex; align-items: center; justify-content: center; width: 56px; height: 36px; overflow: hidden;
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-3); font-size: 13px; font-weight: 700;
}
/* Contained and never upscaled: small logos keep their own size. */
.live__now-logo img { max-width: 48px; max-height: 30px; object-fit: contain; }
.live__now-text { min-width: 0; }
.live__now-over { display: none; margin-bottom: 6px; color: var(--text-3); }
.live__now-name { font-size: 17px; font-weight: 600; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live__now-sub { margin-top: 2px; color: var(--text-2); font-size: 13px; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live__now-over:empty, .live__now-num:empty, .live__now-cat:empty { display: none; }
/* "Canal 5 · Deportes": a CSS dot, so screen readers skip it. Compact bar only: ≥861 hides the number. */
@media (max-width: 860px) {
  .live__now-num:not(:empty) + .live__now-cat:not(:empty)::before {
    content: ""; display: inline-block; width: 3px; height: 3px; margin: 0 8px; border-radius: 50%;
    background: currentColor; opacity: .55; vertical-align: middle;
  }
}
.live__now-actions { display: flex; align-items: center; gap: 4px; }
.live__now-label { display: none; }
.live__now-fav[aria-pressed="true"] .icon { color: var(--star); }

/* Keyboard hint: only where there is a keyboard and room for it. */
.live__hint { display: none; margin-top: 20px; color: var(--text-3); font-size: 13px; line-height: 1.4; }

/* Number typed with the keyboard or remote, over the stage ("12_"). */
.live-digits {
  position: absolute; top: 16px; right: 16px; z-index: var(--z-stage-osd);
  padding: 8px 16px; border-radius: var(--radius); background: var(--overlay);
  color: #fff; font: 700 40px/1 var(--font); font-variant-numeric: tabular-nums; pointer-events: none;
  animation: fade-in var(--dur-2) var(--ease-calm);
}
@media (max-width: 599px) { .live-digits { top: 12px; right: 12px; padding: 6px 12px; font-size: 32px; } }
/* Separate rules: an engine that does not know one of the selectors would drop a combined list. */
.stage:fullscreen .live-digits { top: 32px; right: 32px; transform: scale(1.5); transform-origin: top right; }
.stage:-webkit-full-screen .live-digits { top: 32px; right: 32px; transform: scale(1.5); transform-origin: top right; }
html.is-tv .live-digits { top: 32px; right: 32px; transform: scale(1.5); transform-origin: top right; }

/* --------------------------------------------------------------- list */
.live__list { display: flex; flex-direction: column; min-width: 0; max-width: 720px; }
.live__list-head { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.live__list-head h2 { font-size: var(--fs-title-3); line-height: var(--lh-title-3); font-weight: 600; }
.live__count { margin-left: 4px; color: var(--text-3); font-size: 15px; font-weight: 500; }
.live__search { flex: none; }
.live__status:empty { display: none; }
.live__status .empty { padding: 48px 16px; }
.live__loading { display: flex; justify-content: center; padding: 48px 0; }

.live__channels { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.channel {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 44px; align-items: center;
  border-radius: var(--radius-tile); content-visibility: auto; contain-intrinsic-size: auto 60px;
  transition: background-color var(--dur-2);
}
.channel__tune {
  display: grid; grid-template-columns: 36px 64px minmax(0, 1fr); gap: 12px; align-items: center; min-width: 0;
  min-height: 60px; padding: 8px 4px 8px 8px; border-radius: var(--radius-tile); text-align: left;
}
/* No channel in the category has a number: the column goes away. */
.live__channels--nonum .channel__tune { grid-template-columns: 64px minmax(0, 1fr); }
.live__channels--nonum .channel__num { display: none; }
.channel__num { color: var(--text-3); font-size: 13px; font-weight: 500; text-align: right; }
.channel__logo {
  display: flex; align-items: center; justify-content: center; width: 64px; height: 40px; overflow: hidden;
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-3); font-size: 13px; font-weight: 700;
}
.channel__logo img { max-width: 56px; max-height: 36px; object-fit: contain; }
.channel__name { min-width: 0; font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Always visible: touch screens have no hover to reveal it. */
.channel__fav {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: var(--text-3);
  transition: color var(--dur-2);
}
.channel__fav .icon { width: 18px; height: 18px; }
.channel__fav[aria-pressed="true"] { color: var(--star); }
/* Rows sit in a scroller and paint-contain themselves: the ring goes inside. */
.channel__tune:focus-visible, .channel__fav:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; box-shadow: none; }
body.is-dpad .channel:focus-within { background: var(--surface-2); }
@media (hover: hover) and (pointer: fine) {
  .channel:hover { background: var(--surface-1); }
  .channel__fav:hover { color: var(--text); }
  .channel__fav[aria-pressed="true"]:hover { color: var(--star); }
}
/* Tuned: raised row, white capsule on the left, live dot before the name. */
.channel.is-tuned, body.is-dpad .channel.is-tuned:focus-within { background: var(--surface-3); }
@media (hover: hover) and (pointer: fine) { .channel.is-tuned:hover { background: var(--surface-3); } }
.channel.is-tuned::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--text);
}
.channel.is-tuned .channel__name { color: var(--text); font-weight: 600; }
.channel.is-tuned .channel__name::before {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 8px; border-radius: 50%;
  background: var(--live); vertical-align: 2px;
}

/* ------------------------------------------------------------- tiers */
/* 600–1023, one column: heading and search share a line. */
@media (min-width: 600px) and (max-width: 1023px) {
  .live__list-head { flex-direction: row; align-items: center; justify-content: space-between; }
  .live__search { flex: 0 1 320px; }
}

/* P/TP portrait: the stage is pinned full-bleed under the header; chips and list scroll below it. */
@media (max-width: 860px) and (orientation: portrait) {
  .live { padding-top: var(--header-h); }
  .live__main {
    order: -1; position: sticky; top: var(--header-h); z-index: var(--z-sticky); max-width: none;
    margin: 0 calc(-1 * var(--gutter)); padding-bottom: 12px; background: var(--bg); box-shadow: 0 1px 0 var(--line);
  }
  .live__main .stage { border-radius: 0; box-shadow: none; }
  .live__now { padding: 0 var(--gutter); }
  /* Whatever is brought into view must clear the pinned stage (16:9 of the width plus the now bar):
     a row, and every focus target, since focus scrolling reads the focused element's own margin. */
  .channel, .channel > button, .live__cat-track .chip, .live__picker select, .live__search input, .live__search .field__clear {
    scroll-margin-top: calc(var(--header-h) + 56.25vw + 72px);
    scroll-margin-bottom: calc(var(--tabbar-total) + 8px);
  }
}

/* ≥861: full now-playing bar. */
@media (min-width: 861px) {
  .live { gap: 24px; padding-top: calc(var(--header-h) + 24px); }
  .live__now { grid-template-columns: 96px minmax(0, 1fr) auto; gap: 16px; margin-top: 16px; }
  .live__now-logo { width: 96px; height: 64px; border-radius: var(--radius); font-size: 15px; }
  .live__now-logo img { max-width: 72px; max-height: 48px; }
  .live__now-over { display: block; }
  .live__now-over:empty { display: none; }
  .live__now-name { font-size: 24px; line-height: 1.25; letter-spacing: -.01em; }
  .live__now-num { display: none; }
  .live__now-sub { font-size: 15px; line-height: 1.5; }
  .channel, .channel > button { scroll-margin: calc(var(--header-h) + 8px) 0 8px; }
  .live__cat-track .chip, .live__picker select, .live__search input, .live__search .field__clear { scroll-margin-top: calc(var(--header-h) + 8px); }
}

/* ≥1024: stage and list side by side in one screen; the list scrolls inside. The page is one viewport
   tall, so the list ends on screen whatever the chips measure (40, 44 on touch, TV); a list filling its
   grid area could never stick, so only the stage is sticky (on the way to the footer). */
@media (min-width: 1024px) {
  .live {
    display: grid; grid-template-areas: "cats cats" "main list";
    grid-template-columns: minmax(0, 1fr) clamp(320px, 28vw, 400px); grid-template-rows: auto minmax(0, 1fr);
    gap: 24px 32px; align-items: start;
    height: calc(100vh - var(--tabbar-total));
    height: calc(100svh - var(--tabbar-total));
    padding: calc(var(--header-h) + 24px) var(--gutter) 24px;
  }
  .live__cats { grid-area: cats; }
  /* Wide but short windows: the stage shrinks so it and the now bar stay on screen. */
  .live__main {
    grid-area: main; position: sticky; top: calc(var(--header-h) + 16px);
    max-width: max(480px, calc((100vh - var(--header-h) - 200px) * 16 / 9));
    max-width: max(480px, calc((100svh - var(--header-h) - 200px) * 16 / 9));
  }
  .live__list { grid-area: list; align-self: stretch; min-height: 0; max-width: none; }
  .live__status, .live__list-head { flex: none; }
  .live__channels {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    padding-bottom: 24px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .2) transparent;
    -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 24px), transparent);
    mask-image: linear-gradient(180deg, #000 calc(100% - 24px), transparent);
  }
  .channel, .channel > button { scroll-margin: 8px 0 32px; }
}

@media (min-width: 1120px) and (hover: hover) and (pointer: fine) { .live__hint { display: block; } }

@media (min-width: 1280px) {
  .live__now .live__now-btn { width: auto; padding: 0 16px 0 12px; }
  .live__now-label { display: inline; }
}

/* ---------------------------------------------------------------- TV */
html.is-tv .live { padding-top: calc(var(--header-h) + 24px * var(--tvu)); }
html.is-tv .live__hint { display: none; }
html.is-tv .live__search { height: var(--control); }
html.is-tv .live__list-head h2 { font-size: var(--fs-title-2); }
html.is-tv .live__count { font-size: var(--fs-callout); }
html.is-tv .live__now { grid-template-columns: calc(120px * var(--tvu)) minmax(0, 1fr) auto; gap: calc(20px * var(--tvu)); margin-top: calc(20px * var(--tvu)); }
html.is-tv .live__now-logo { width: calc(120px * var(--tvu)); height: calc(80px * var(--tvu)); }
html.is-tv .live__now-logo img { max-width: calc(96px * var(--tvu)); max-height: calc(60px * var(--tvu)); }
html.is-tv .live__now-name { font-size: var(--fs-title-2); }
html.is-tv .live__now-sub { font-size: var(--fs-callout); }
html.is-tv .channel { grid-template-columns: minmax(0, 1fr) var(--control); contain-intrinsic-size: auto calc(76px * var(--tvu)); }
html.is-tv .channel__tune {
  grid-template-columns: calc(52px * var(--tvu)) calc(96px * var(--tvu)) minmax(0, 1fr); gap: calc(16px * var(--tvu));
  min-height: calc(76px * var(--tvu)); padding: calc(8px * var(--tvu)) calc(4px * var(--tvu)) calc(8px * var(--tvu)) calc(12px * var(--tvu));
}
html.is-tv .live__channels--nonum .channel__tune { grid-template-columns: calc(96px * var(--tvu)) minmax(0, 1fr); }
html.is-tv .channel__num { font-size: var(--fs-caption); }
html.is-tv .channel__logo { width: calc(96px * var(--tvu)); height: calc(60px * var(--tvu)); font-size: var(--fs-caption); }
html.is-tv .channel__logo img { max-width: calc(84px * var(--tvu)); max-height: calc(52px * var(--tvu)); }
html.is-tv .channel__name { font-size: var(--fs-callout); }
html.is-tv .channel__fav { width: var(--control); height: var(--control); }
html.is-tv .channel__fav .icon { width: calc(24px * var(--tvu)); height: calc(24px * var(--tvu)); }
@media (min-width: 1024px) {
  html.is-tv .live { grid-template-columns: minmax(0, 1fr) calc(440px * var(--tvu)); gap: calc(24px * var(--tvu)) calc(32px * var(--tvu)); }
}

/* ---------------------------------------------------- short landscape */
/* Phones on their side: stage left, the Categoría picker and the list right, all inside the
   viewport. Nothing sticks; chips, now bar and hint give way. Last, so it beats every tier above. */
@media (orientation: landscape) and (max-height: 500px) {
  .live {
    display: grid; grid-template-areas: "main cats" "main list";
    grid-template-columns: minmax(0, 60%) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
    gap: 8px 16px; align-items: start;
    height: calc(100vh - var(--tabbar-total));
    height: calc(100svh - var(--tabbar-total));
    padding: calc(var(--header-h) + 8px) var(--gutter) 8px;
  }
  .live__cats { grid-area: cats; }
  .live__cat-track, .live__now, .live__hint { display: none; }
  .live__picker .picker__text { max-width: 22ch; }
  .live__main {
    grid-area: main; order: 0; position: static; margin: 0; padding: 0; background: none; box-shadow: none;
    width: min(100%, calc((100vh - var(--header-h) - var(--tabbar-total) - 16px) * 16 / 9));
    width: min(100%, calc((100svh - var(--header-h) - var(--tabbar-total) - 16px) * 16 / 9));
    max-width: none;
  }
  .live__main .stage { border-radius: var(--radius); }
  .live__list { grid-area: list; align-self: stretch; position: static; height: auto; min-height: 0; max-width: none; }
  .live__list-head { flex: none; flex-direction: row; align-items: center; gap: 8px; margin-bottom: 8px; }
  .live__list-head h2 { flex: none; font-size: 15px; }
  .live__count { font-size: 13px; }
  /* Keeps the 44px field: its 44px clear button would stick out of a shorter one, and touch needs 44. */
  .live__search { flex: 1 1 auto; min-width: 0; }
  .live__status { flex: none; }
  .live__status .empty { padding: 16px 8px; }
  .live__channels {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    padding-bottom: 16px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .2) transparent;
    -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 16px), transparent);
    mask-image: linear-gradient(180deg, #000 calc(100% - 16px), transparent);
  }
  .channel, .channel > button { scroll-margin: 4px 0 20px; }
}

/* Engines without aspect-ratio (Chromium < 88: older Tizen and webOS TVs) would give the stage no
   height, since everything in it is absolute: an in-flow spacer 56.25% of its width holds it open.
   ::after is free (::before is the "preparing" shade); in full screen the UA size wins and it is clipped. */
@supports not (aspect-ratio: 16 / 9) {
  .stage--inline::after { content: ""; display: block; padding-top: 56.25%; }
}
