/*
 * COMPATIBILITY FLOOR: CHROME 53. Every declaration it cannot parse needs a
 * plain fallback right before it - clamp()/min()/max(), env(), dvh, #rrggbbaa:
 *   width: 420px; width: min(420px, 92vw);
 * A custom property cannot be guarded that way, and neither can a value that
 * also uses var() (53 accepts it at parse time and it resets to initial):
 * set the plain value and put the modern one inside @supports. Grid, aspect-ratio and flex gap need the
 * fallbacks at the foot of css/app.css (@supports not ..., html.no-flexgap).
 * Rules: CLAUDE.md.
 */
/*
 * Touch mode — phones and tablets.
 *
 * Everything here is behind html.touch, which the page head sets for a coarse
 * pointer that is not a television (see index.html). The television layout in
 * app.css is not touched: this sheet only takes things away from it or re-lays
 * them out for a finger and a portrait screen, the way the native TiViCon Play
 * phone and tablet apps do — a slim top bar, the sections in a tab bar at the
 * foot, rows that swipe, and a guide that scrolls both ways under a finger.
 *
 * Two sizes: a phone (narrower than 600px) and a tablet. The tablet mostly
 * keeps the television's proportions with the chrome of the phone; the phone
 * gets its own card sizes and single-column screens.
 */

html.touch { -webkit-text-size-adjust: 100%; }
html.touch body { -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }

/*
 * The screen, and nothing past it.
 *
 * iOS lets the document itself scroll even with overflow hidden on it, and
 * takes 100% to mean the screen with its toolbars put away - so the app was
 * taller than what shows, and a flick moved the whole thing: the top bar (the
 * avatar and the gear) slid off the top and the tab bar off the bottom. The
 * body is pinned to the viewport instead, and the app is exactly as tall as
 * what is visible (dvh; 100% where that is unknown). Only the content region
 * inside it scrolls.
 *
 * Edge to edge (viewport-fit=cover in the page head), so the notch, the
 * rounded corners and the home indicator are given room by padding rather
 * than by the browser boxing the page in.
 */
html.touch, html.touch body { height: 100%; }
html.touch body { position: fixed; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden; }
html.touch #app { height: 100%; height: 100dvh; }
html.touch .topbar { padding-top: calc(10px + 0px); padding-top: calc(10px + env(safe-area-inset-top, 0px));
                     padding-left: calc(12px + 0px); padding-left: calc(12px + env(safe-area-inset-left, 0px));
                     padding-right: calc(12px + 0px); padding-right: calc(12px + env(safe-area-inset-right, 0px)); }
html.touch .main { padding-top: calc(var(--top) + 0px);
                   padding-left: calc(12px + 0px); padding-left: calc(12px + env(safe-area-inset-left, 0px));
                   padding-right: calc(12px + 0px); padding-right: calc(12px + env(safe-area-inset-right, 0px)); }
@supports (top: env(safe-area-inset-top, 0px)) { html.touch .main { padding-top: calc(var(--top) + env(safe-area-inset-top, 0px)); } }
html.touch .bottombar { padding-left: 0px; padding-left: env(safe-area-inset-left, 0px);
                        padding-right: 0px; padding-right: env(safe-area-inset-right, 0px); }
html.touch .player .closex { top: calc(12px + 0px); top: calc(12px + env(safe-area-inset-top, 0px));
                             left: calc(12px + 0px); left: calc(12px + env(safe-area-inset-left, 0px)); }
html.touch .login { padding-top: 0px; padding-top: env(safe-area-inset-top, 0px); }
/* No focus ring or zoom for a finger. The app still moves the focus about for
   the remote's sake - onto the first card of a screen, onto Play in a detail -
   and on a phone that painted a ring on something nobody had touched. A press
   answers with a small push-in instead. */
html.touch .focusable:focus, html.touch .focusable:hover {
  border-color: transparent; transform: none; }
html.touch .focusable:active { transform: scale(.97); }

/* ---------- the top bar: logo, search, avatar, gear ---------- */
html.touch .topbar .tabs,
html.touch .topbar .clock { display: none; }
html.touch .topbar { gap: 6px; }
html.touch .topbar .logo { height: 40px; width: 40px; margin-right: auto; }
html.touch .who b { display: none; }
html.touch .who { padding: 4px; }
html.touch .who .avatar { width: 32px; height: 32px; }
.topsearch { display: none; }
html.touch .topsearch { display: flex; align-items: center; justify-content: center;
                        width: 40px; height: 40px; border-radius: 50%; color: var(--text);
                        cursor: pointer; }
html.touch .topsearch.on { color: var(--focus); }
html.touch .gear { width: 40px; height: 40px; display: flex; align-items: center;
                   justify-content: center; }

/* ---------- the tab bar ---------- */
.bottombar { display: none; }
html.touch .bottombar {
  display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(62px + 0px); height: calc(62px + env(safe-area-inset-bottom, 0px));
  padding-bottom: 0px; padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-2, #0b1323); border-top: 1px solid var(--stroke);
}
html.touch .bottombar a {
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; color: var(--muted); text-decoration: none; cursor: pointer;
  font-size: 10px; letter-spacing: .2px; text-transform: uppercase; font-weight: 600;
  border-top: 2px solid transparent;
}
html.touch .bottombar a svg { width: 24px; height: 24px; margin-bottom: 3px; }
html.touch .bottombar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis;
                               white-space: nowrap; padding: 0 2px; }
html.touch .bottombar a.on { color: var(--text); border-top-color: var(--focus); }
html.touch .bottombar a.on svg { color: var(--focus); }

/* The content region ends above the tab bar, not behind it. */
html.touch .main { padding-bottom: calc(80px + 0px); padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
                   -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* ---------- rows and cards: they swipe ---------- */
html.touch .cards { scroll-snap-type: x proximity; scroll-behavior: auto;
                    -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
html.touch .cards > * { scroll-snap-align: start; }
/* Row arrows and anything else that exists for a mouse over a television. */
html.touch .row .scroll-btn { display: none; }

/* ---------- phone ---------- */
@media (max-width: 599px) {
  html.touch body { font-size: 14px; }
  html.touch { --top: 64px; }

  html.touch .card { width: 31vw; }
  html.touch .card .art.logo { aspect-ratio: 16/10; }
  html.touch .card .t { font-size: .85em; padding: 6px 8px 2px; }
  html.touch .card .s { font-size: .75em; padding: 0 8px 7px; }
  html.touch .grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }


}

/* ---------- the showcase on any portrait screen ---------- */
@media (max-width: 599px), (orientation: portrait) {
  /* The showcase: the picture across the width, the words under it. */
  /* Below the bar rather than behind it: whole banners carry lettering at the
     top as often as at the foot. */
  html.touch .promo { height: auto !important; min-height: 0; margin: -8px calc(-1 * var(--gutter-touch, 12px)) 14px; }
  /* Whole, at its own shape: these banners carry their own lettering, and a
     crop to a phone's width cuts it in half. */
  html.touch .promo-art { position: relative; left: 0; height: auto; min-height: 30vw; }
  html.touch .promo-art img { height: auto; object-fit: contain; }
  html.touch .promo-art::after { background: linear-gradient(to top, var(--bg), rgba(0,0,0,0) 30%); }
  html.touch .promo::after { display: none; }
  html.touch .promo-text { position: relative; left: 0; right: 0; bottom: auto; top: auto;
                           margin-top: 4px; padding: 0 14px; }
  html.touch .promo-dots { position: relative; right: auto; bottom: auto; justify-content: center;
                           display: flex; margin-top: 8px; }
}
@media (min-width: 600px) { html.touch { --gutter-touch: 2vw; } @supports (width: clamp(1px, 1px, 1px)) { html.touch { --gutter-touch: clamp(12px, 2vw, 28px); } } }

/* ---------- detail, phone: title first, then the buttons ---------- */
@media (max-width: 599px) {
  /* The phone app reads top to bottom: picture, what it is, what to do with
     it, then the rest. The television puts the buttons first because that is
     where the remote lands; a thumb has no such need. .facts is dissolved into
     the column so its title and meta line can go ahead of the buttons while
     the description and the rows stay after them. */
  html.touch .detail { display: flex; flex-direction: column; }
  html.touch .detail .facts { display: contents; }
  html.touch .detail .facts > * { order: 3; padding-left: 14px; padding-right: 14px; }
  html.touch .detail .facts > h2,
  html.touch .detail .facts > .line,
  html.touch .detail .facts > .avail { order: 1; }
  html.touch .detail .facts > h2 { margin-top: 4px; font-size: 1.35em; }
  html.touch .detail .actionbar { order: 2; margin-left: 0; padding: 4px 14px 14px; gap: 8px; }
  html.touch .detail .actionbar .btn { padding: 9px 14px; font-size: .92em; }
  html.touch .detail .facts > .row.similar { padding-left: 0; padding-right: 0; margin-left: 14px; }
  html.touch .backdrop { height: 34vh; }
  html.touch .detail .poster { display: none; }
}

@media (max-width: 400px) {
  html.touch .bottombar a { font-size: 9px; letter-spacing: 0; }
}

/* ---------- tablet ---------- */
@media (min-width: 600px) {
  html.touch .card { width: 20vw; width: clamp(150px, 20vw, 220px); }
  /* Poster grids (Movies, Series, Search) are a width per column, not per
     card: the row size above was laid over them and a 160px card sat in a
     121px column, each one over the next. */
  html.touch .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
}
/* Whatever the device: a card in a grid is its column's width. */
html.touch .grid .card { width: auto; }

/* ---------- the player ---------- */
.closex { display: none; }
html.touch .closex { display: flex; position: absolute; top: 12px; left: 12px; z-index: 8;
                     width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
                     align-items: center; justify-content: center; color: #fff;
                     background: rgba(0,0,0,.55); }
html.touch .actionbar .btn:focus { border-color: transparent; }

@media (max-width: 599px), (max-height: 499px) {
  /* A phone: the bar stacks - title, then the scrub bar across the full width,
     then the buttons - because side by side the scrub bar was a thumb wide. */
  html.touch .player .infobar { flex-direction: column; align-items: stretch; gap: 10px;
                                padding: 12px 14px calc(12px + 0px); padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px)); }
  html.touch .player .infobar .txt { width: 100%; max-width: none; }
  html.touch .player .infobar .transport { justify-content: center; }
  html.touch .player .infobar .osd-tracks { justify-content: center; }
}

/* ---------- the guide: one grid that scrolls both ways ---------- */
/* Every channel is drawn (guideRows), and the grid is its own scroller in both
   directions, so the hour strip can stay at the top and the channel column at
   the left while a finger moves the programmes under them - the native apps'
   guide. The page around it does not scroll. The up/down paging chips were
   the remote's way through a window of rows and have nothing left to do. */
html.touch .guide-head .chip.page { display: none; }
html.touch .guide-scroll {
  overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  height: calc(100vh - var(--top) - 140px - 0px);
  height: calc(100vh - var(--top) - 140px - 0px);
}
@supports (top: env(safe-area-inset-top, 0px)) { html.touch .guide-scroll { height: calc(100vh - var(--top) - 140px - env(safe-area-inset-bottom, 0px)); } }
@supports (top: env(safe-area-inset-top, 0px)) and (height: 1dvh) { html.touch .guide-scroll { height: calc(100dvh - var(--top) - 140px - env(safe-area-inset-bottom, 0px)); } }
html.touch .guide-hours { position: sticky; top: 0; z-index: 6; background: var(--bg); }
html.touch .nowline { z-index: 3; }
html.touch .guide-ch { z-index: 5; }
@media (max-width: 599px) {
  html.touch .guide-ch { flex-basis: 78px; gap: 4px; }
  html.touch .guide-ch img { width: 40px; height: 28px; }
  html.touch .guide-hours, html.touch .nowline { margin-left: 78px; }
  html.touch .guide-head { gap: 6px; flex-wrap: wrap; }
  html.touch .guide-head .day { min-width: 0; flex: 1 1 auto; }
}
html.touch .guide-scroll::-webkit-scrollbar { width: 0; height: 0; }

/* ---------- search ---------- */
html.touch .promo { touch-action: pan-y pinch-zoom; }
html.touch .searchbar.native { margin-bottom: 14px; }
html.touch .searchbar.native .input { width: 100%; font-size: 16px; /* 16px: iOS zooms smaller fields */
                                      -webkit-appearance: none; appearance: none; }

/* ---------- settings: the section tabs swipe, without a scrollbar ---------- */
@media (max-width: 899px) {
  html.touch .settings-split { flex-direction: column; }
  html.touch .settings-menu { flex: 0 0 auto; flex-direction: row; overflow-x: auto; width: 100%; gap: 6px;
                              align-items: center; scrollbar-width: none; padding-bottom: 4px; }
  html.touch .settings-menu::-webkit-scrollbar { display: none; height: 0; }
  html.touch .settings-item.danger { margin-top: 0; }
  html.touch .settings-item { flex: 0 0 auto; white-space: nowrap; padding: 8px 14px;
                              border-radius: 999px; }
  html.touch .settings-body { width: 100%; }
  html.touch .settings .box { max-width: none; }
}

/* A phone on its side has little height to give: the tab bar keeps its icons
   and drops the names. */
@media (max-height: 499px) {
  html.touch .bottombar { height: calc(46px + 0px); height: calc(46px + env(safe-area-inset-bottom, 0px)); }
  html.touch .bottombar a span { display: none; }
  html.touch .bottombar a svg { margin-bottom: 0; }
  html.touch .main { padding-bottom: calc(60px + 0px); padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- live TV: buttons for what the remote's keys did ---------- */
html.touch .player .tkey { display: none; }
html.touch .player .osd-foot .hint { font-size: .8em; color: var(--muted); }
@media (max-width: 599px) {
  /* The bar stacks: the channel's mark and number above what is on. */
  html.touch .osd .osd-main { flex-direction: column; align-items: flex-start; gap: 8px; }
  html.touch .osd .ch { flex-direction: row; gap: 10px; }
  /* Stacked, there is no column above for the transport to line up with. */
  html.touch .osd .osd-transport .osd-lead { min-width: 0; }
  html.touch .osd .osd-foot { flex-direction: column; align-items: stretch; gap: 10px; }
}

/* The channel list and the guide over the picture. On a phone the list takes
   most of the width - at 44vw its names were one letter - and the guide fills
   what is under its banner, scrolling like the Guide tab. */
@media (max-width: 599px) {
  html.touch .player .chlist { width: 86vw; }
}
html.touch .player .epg-over .guide-scroll { height: auto; flex: 1; min-height: 0; }
html.touch .player .epg-over .guide { display: flex; flex-direction: column; }
/* The ✕ sits where the banner's channel mark is; nudged under it. */
html.touch .player .epg-over ~ .closex,
html.touch .player .chlist ~ .closex { display: none; }

/* The ⌨ beside each field calls up the client's own keyboard; a phone brings
   up its own the moment a field is tapped. */
html.touch .kb-open { display: none; }

/* Swipes over the player are the app's (see onPlayerTouchEnd), not the
   browser's: without this a finger from left to right is the browser's own
   Back and leaves the page. The list and the guide over the picture still
   scroll under the finger. iOS keeps its edge-of-screen Back whatever a page
   says, so a swipe there should start a little in from the edge. */
html.touch, html.touch body { overscroll-behavior: none; }
html.touch .player { touch-action: none; }
html.touch .player .timeline-touch {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 100%; height: 44px; margin: 0; padding: 0; opacity: 0;
  pointer-events: auto; touch-action: none; cursor: pointer;
}
html.touch .player .chlist, html.touch .player .chlist .items { touch-action: pan-y; }
html.touch .player .epg-over, html.touch .player .epg-over .guide-scroll { touch-action: pan-x pan-y; }

/* ---------- subtitles on a phone ----------
   They are the browser's own, drawn inside the <video> box and sized from its
   height. On an upright phone that box was the whole screen, so a line came out
   several times the size of the picture and ran off both sides. The box is
   made the picture's own size, centred, and the text is given a size a phone
   can hold whatever the box is. */
@media (orientation: portrait) {
  html.touch .player .video { position: absolute; top: 50%; left: 0; width: 100%;
                              height: auto; max-height: 100%; transform: translateY(-50%); }
}
/* Sized from the screen's shorter side, so turning the phone does not make the
   text twice the size: upright that is its width, on its side its height.
   ::cue is the standard hook; WebKit also sets the size inline on its own
   caption box, which only !important on that box gets past. */
html.touch .player .video::cue { font-size: 22px !important; font-size: clamp(12px, min(3.6vw, 4.2vh), 22px) !important;
                                 line-height: 1.3; background: rgba(0,0,0,.6); }
html.touch .player .video::-webkit-media-text-track-display {
  font-size: 22px !important; font-size: clamp(12px, min(3.6vw, 4.2vh), 22px) !important; }
html.touch .player .video::-webkit-media-text-track-container {
  font-size: 22px !important; font-size: clamp(12px, min(3.6vw, 4.2vh), 22px) !important; }

/* Flex gap on an engine without it (see the probe in index.html): the touch
   layouts that change a row's direction or gap need their own margins. */
html.touch.no-flexgap .detail .actionbar > * { margin-right: 8px; margin-bottom: 8px; }
html.touch.no-flexgap .player .infobar > * { margin-right: 0; margin-bottom: 10px; }
html.touch.no-flexgap .osd .osd-main > * { margin-right: 0; margin-bottom: 8px; }
html.touch.no-flexgap .osd .ch > * { margin-right: 10px; }
html.touch.no-flexgap .osd .osd-foot > * { margin-right: 0; margin-bottom: 10px; }
