:root {
  --bg: #0e1014;
  --surface: #161920;
  --surface-2: #1e222c;
  --surface-3: #272c38;
  --border: #2a2f3b;
  --text: #e9ecf2;
  --muted: #8e95a4;
  --accent: #7c9cff;
  --accent-ink: #0b0d12;
  --danger: #ff7a7a;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-size: 26px; margin: 4px 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 28px 0 12px; display: flex; align-items: baseline; gap: 12px; }
h2 a { font-size: 13px; color: var(--accent); font-weight: 500; }
button { font: inherit; color: inherit; cursor: pointer; }
select, input { font: inherit; color: inherit; }

/* Layout */
.app { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 2px;
  padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 12px 20px; font-weight: 700; font-size: 18px; color: var(--accent); }
.brand span { color: var(--text); }
.nav { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav svg { width: 20px; height: 20px; }
.nav:hover { background: var(--surface-2); color: var(--text); }
.nav.active { background: var(--surface-3); color: var(--text); }
.nav.active svg { color: var(--accent); }
.nav-badge { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 12px; line-height: 20px; text-align: center; }

/* Downloads page: the queue of files this browser saves, one at a time. */
.downloads { display: grid; gap: 2px; max-width: 900px; }
.download { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center; padding: 12px 10px; border-bottom: 1px solid var(--border); }
.download .name { font-weight: 600; overflow-wrap: anywhere; }
.download .state { color: var(--muted); font-size: 13.5px; }
.download .state.error { color: var(--danger); }
.download .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.download .bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.download .bar span { display: block; height: 100%; background: var(--accent); }
.downloads-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 6px; }
.downloads-note { color: var(--muted); font-size: 13.5px; max-width: 900px; margin: 0 0 16px; }
.sidebar-foot { margin-top: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--muted); }
.sync-status strong { color: var(--text); font-weight: 600; }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-align: left; font-size: 12.5px; }
.link:disabled { color: var(--muted); cursor: default; }
.toggle { display: flex; gap: 8px; align-items: center; cursor: pointer; }

main { padding: 0 32px 64px; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; padding: 16px 0 14px; background: linear-gradient(var(--bg) 75%, transparent); }
.search { display: flex; align-items: center; gap: 10px; max-width: 640px; padding: 0 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; }
.search:focus-within { border-color: var(--accent); }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; padding: 11px 0; background: none; border: 0; outline: 0; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.btn.fav-on svg { fill: #ffc857; stroke: #ffc857; }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn svg { width: 22px; height: 22px; }
select {
  padding: 8px 30px 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  appearance: none; max-width: 100%;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: transparent; font-size: 13px; color: var(--muted); }
.chip:hover { color: var(--text); }
.card .studio-line { font-size: 12.5px; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta a.studio { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
/* The streamer rail: TMDB logos at one height, the name when there is none or it fails to load. */
.rail .chip img { display: block; height: 20px; max-width: 96px; width: auto; }
/* TMDB's logos are drawn for a light background (HBO's and Apple's are black): a logo chip is white, and the active one is ringed. */
.rail .chip:has(img) { padding: 4px 12px; background: #fff; border-color: #fff; }
.rail .chip.active { background: var(--text); color: var(--bg); border-color: var(--text); box-shadow: 0 0 0 2px var(--accent); }
/* A streamer's page: its logo beside its name; the sort beside the grid's title. */
.studio-head { display: flex; align-items: center; gap: 14px; }
.studio-head img { height: 36px; width: auto; max-width: 160px; }
h2 select { margin-left: auto; font-size: 13px; }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 16px; }
.grid.live { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.shelf { display: grid; grid-auto-flow: column; grid-auto-columns: 150px; gap: 16px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: thin; }
.card { display: block; min-width: 0; cursor: pointer; }
.poster {
  position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border); transition: transform .15s, border-color .15s;
}
.card:hover .poster { transform: translateY(-2px); border-color: var(--accent); }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card.live .poster { aspect-ratio: 16 / 10; background: #fff1; }
.card.live .poster img { object-fit: contain; padding: 14%; }
.placeholder { width: 100%; height: 100%; display: grid; place-items: center; padding: 10px; text-align: center; font-weight: 700; color: var(--muted); font-size: 15px; line-height: 1.2; }
.badge { position: absolute; top: 6px; font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 4px; background: rgba(0, 0, 0, .72); letter-spacing: .02em; }
.badge.q { right: 6px; }
.badge.v { left: 6px; color: var(--muted); }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0, 0, 0, .6); }
.progress i { display: block; height: 100%; background: var(--accent); }
/* Round buttons over the poster, shown on hover: the favorite star, and × in Continue watching. */
.card-fav, .card-remove {
  position: absolute; right: 6px; bottom: 8px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0, 0, 0, .7); color: #fff; cursor: pointer;
  opacity: 0; transition: opacity .15s, transform .15s;
}
.card-fav svg, .card-remove svg { width: 16px; height: 16px; }
.card-remove { left: 6px; right: auto; }
.card:hover .card-fav, .card-fav:focus-visible, .card-fav.on, .card:hover .card-remove, .card-remove:focus-visible { opacity: 1; }
.card-fav:hover, .card-remove:hover { transform: scale(1.1); }
.card-fav.on svg { fill: #ffc857; stroke: #ffc857; }
@media (hover: none) { .card-fav, .card-remove { opacity: 1; } }
/* 👍 / 👎 over the poster on hover, left of the star; the 👍 badge on liked titles. */
.card-rate {
  position: absolute; bottom: 8px; width: 30px; height: 30px; border-radius: 50%; right: 42px;
  display: grid; place-items: center; background: rgba(0, 0, 0, .7); cursor: pointer; font-size: 14px;
  opacity: 0; transition: opacity .15s, transform .15s;
}
.card-rate.down { right: 78px; }
.card:hover .card-rate, .card-rate:focus-visible { opacity: 1; }
.card-rate:hover { transform: scale(1.1); }
/* Touch screens have no hover: 👍 / 👎 always show (a long press on the card offers them too, cards.js). */
@media (hover: none) { .card-rate { opacity: 1; } }
/* A 👎 already given stays visible outside Home (pressing it again clears it). */
.card[data-feedback="-1"] .card-rate.down { opacity: 1; outline: 2px solid var(--accent); }
.badge.liked { right: 6px; top: 30px; }
/* A followed series got a new season (server/new-seasons.ts). */
.badge.new { left: 6px; top: auto; bottom: 8px; background: var(--accent); color: var(--accent-ink); }
/* The starter picker: poster buttons, 👍 on the picked ones. */
.starter-pick { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-align: left; }
.starter-pick .badge.picked { right: 6px; display: none; }
.starter-pick.on .badge.picked { display: block; }
.starter-pick.on .poster { border-color: var(--accent); outline: 3px solid var(--accent); }
.starter-actions { position: sticky; bottom: 0; padding: 12px 0; background: var(--bg); }
.match { color: #46d369; font-weight: 600; }
/* Match % on its own line under the title, above the year and scores. */
.card .match-line { font-size: 12.5px; color: #46d369; font-weight: 600; white-space: nowrap; }
.rate { display: inline-flex; gap: 8px; align-items: center; }
.rate.prompt { padding: 4px 8px; border-radius: 8px; outline: 1px solid var(--accent); }
.rate-hint { color: var(--accent); font-size: 13px; }
.btn.rated { outline: 2px solid var(--accent); }
.card .title { margin-top: 8px; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Channels: the name keeps its room and the country · category after it is cut first. */
.card.live .title { display: flex; align-items: baseline; min-width: 0; }
.card.live .title .name { flex: none; max-width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.card.live .title .meta { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: pre; font-weight: 400; font-size: 12.5px; color: var(--muted); }
.card .on-now { font-size: 12.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* The year and both scores stay on one line, shrinking on cards narrower than they need (IMDb 10.0 and 100%). */
.card { container-type: inline-size; }
.card .sub.rated { display: flex; align-items: center; gap: .48em; font-size: min(12.5px, 8cqi); }
.card .sub.rated .score { gap: .24em; }
.card .sub.rated .imdb { font-size: .72em; line-height: 1.33; }
.card .sub.rated .tomato { width: .96em; height: .96em; }

/* Ratings */
.score { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; vertical-align: -1px; }
.score .imdb { background: #f5c518; color: #000; font-size: 9px; font-weight: 800; line-height: 12px; padding: 0 3px; border-radius: 2px; letter-spacing: .02em; }
.tomato { width: 12px; height: 12px; stroke: none; flex: none; }
.meta .score .imdb { font-size: 10.5px; line-height: 15px; padding: 0 4px; }
.meta .tomato { width: 15px; height: 15px; }
a.score:hover { color: var(--text); }
.ratings-status { margin-top: 4px; font-size: 11.5px; }
.awards { display: flex; align-items: center; gap: 6px; margin: -6px 0 12px; font-size: 13.5px; color: #d9c27a; }
.awards:empty { display: none; }
/* A followed series' next episode (server/upcoming.ts). */
.upcoming { margin: -6px 0 12px; font-size: 13.5px; color: var(--accent); }
.trophy { width: 16px; height: 16px; flex: none; }

/* Home selection */
.selection { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 28px 0 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.selection.on { border-color: #7c9cff66; }
.selection select:disabled { opacity: .45; }
.switch { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; margin-right: 6px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 36px; height: 20px; border-radius: 999px; background: var(--surface-3); position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--accent-ink); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.notice.slim { padding: 8px 0 0; font-size: 13.5px; }
/* A link in a notice (Home's "Pick a few you like"). */
.notice a { color: var(--accent); }

/* Versions filter on the title page */
.versions-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 24px; }
.version-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; font-size: 13.5px; color: var(--muted); }
.version-filter select { padding-top: 5px; padding-bottom: 5px; font-size: 13.5px; }
.version-filter select:disabled, .version-filter input:disabled + * { opacity: .45; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.switch.small { font-weight: 500; gap: 8px; margin: 0; }
.switch.small span { width: 30px; height: 17px; }
.switch.small span::after { width: 11px; height: 11px; }
.switch.small input:checked + span::after { transform: translateX(13px); }
.variants tr.dimmed td { opacity: .5; }
.variants tr.mine td { background: #7c9cff14; }
.mine-badge { margin-left: 8px; padding: 1px 7px; border-radius: 4px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; vertical-align: 1px; }

.more { display: grid; place-items: center; padding: 28px; color: var(--muted); }
.empty, .notice { padding: 40px 0; color: var(--muted); }
.notice.error { color: var(--danger); }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Entry page */
.hero { position: relative; margin: 0 -32px; padding: 28px 32px 32px; overflow: hidden; }
.hero-bg { position: absolute; inset: 0; background-size: cover; background-position: center 20%; opacity: .22; filter: blur(2px); }
.hero-bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 30%, var(--bg)), linear-gradient(90deg, var(--bg), transparent 70%); }
.hero-inner { position: relative; display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 32px; align-items: start; }
.hero-inner.live { grid-template-columns: 210px minmax(0, 1fr); }
.hero .poster { width: 210px; }
.hero.live .poster { aspect-ratio: 16 / 10; background: #fff1; }
.hero.live .poster img { object-fit: contain; padding: 14%; }
.hero h1 { font-size: 32px; margin: 0 0 8px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.meta .pill { padding: 1px 7px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; font-weight: 700; color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 8px; }
.plot { max-width: 760px; color: #cfd3dc; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13.5px; margin-top: 14px; max-width: 760px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.variants { width: 100%; border-collapse: collapse; font-size: 14px; }
.variants td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.variants tr:hover td { background: var(--surface); }
.variants .raw { color: var(--muted); font-size: 12.5px; }
.variants .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--surface-3); color: #cfd3dc; }
.tag.q { background: #7c9cff26; color: var(--accent); }
.variants .go { text-align: right; white-space: nowrap; }

.season-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; align-items: center; }
.episodes { display: flex; flex-direction: column; gap: 2px; }
.episode { display: grid; grid-template-columns: 44px 120px minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 10px; border-radius: 8px; }
.episode:hover { background: var(--surface); }
.episode .num { color: var(--muted); font-size: 18px; font-weight: 700; text-align: center; }
.episode .thumb { width: 120px; aspect-ratio: 16 / 9; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.episode .thumb img { width: 100%; height: 100%; object-fit: cover; }
.episode .ep-title { font-weight: 600; }
.episode .ep-plot { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.episode .ep-actions { display: flex; gap: 6px; }
.episode.current .num { color: var(--accent); }

/* Player */
.player { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; flex-direction: column; }
.player[hidden] { display: none; }
.player-bar { display: flex; align-items: center; gap: 12px; padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); background: #0b0c10; border-bottom: 1px solid #1c1f27; }
/* The bar wraps at any width: its controls (version, data saver, audio, subtitles, guide…) outgrow a tablet or the
   iPhone Duo open wide (951 px), where they used to run off the edge and squeeze the title to nothing. */
.player-bar { flex-wrap: wrap; }
.player-title { flex: 1 1 240px; min-width: 240px; display: flex; flex-direction: column; }
.player-title strong, .player-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-title span { font-size: 12.5px; color: var(--muted); }
.player-bar select { max-width: 280px; }
#player-audio, #player-subs { max-width: 220px; }
.versions-head .hint { flex-basis: 100%; margin: 0; color: #9aa3b2; font-size: 13px; }
.player-stage { position: relative; flex: 1; min-height: 0; margin-bottom: env(safe-area-inset-bottom); }
/* Pinned to the stage: a 4K video must not grow the page past the window (its controls would be off screen). */
.player video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.player-msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(520px, 90vw);
  padding: 22px 24px; border-radius: var(--radius); background: rgba(22, 25, 32, .96); border: 1px solid var(--border); text-align: center;
}
.player-msg p { margin: 0 0 14px; color: #cfd3dc; }
.player-msg .actions { justify-content: center; margin: 0; }
.player-msg .spinner { margin: 0 auto 12px; }
/* Above the guide band and its dismiss layer: a failure's Retry stays clickable with the band open. */
.player-msg { z-index: 3; }

/* The guide band (js/overlay.js): the programme grid over the lower half of the picture, see-through, the picture
   still moving under it; the clear upper half is a dismiss layer while the band is open. */
.player-guide {
  position: absolute; left: 0; right: 0; bottom: 0; height: 50%; z-index: 2; display: flex; flex-direction: column;
  background: rgba(8, 12, 18, .86); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-top: 1px solid rgba(255, 255, 255, .12); outline: none;
}
.player-guide[hidden], .player-guide-dismiss[hidden] { display: none; }
.player-guide-dismiss { position: absolute; left: 0; right: 0; top: 0; height: 50%; z-index: 2; }
.player-guide-now { display: flex; gap: 10px; align-items: center; padding: 4px 6px 4px 14px; font-size: 14px; color: #cfd3dc; }
.player-guide-now span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-guide-now strong { color: #fff; }
.player-guide-now .icon-btn { width: 32px; height: 32px; font-size: 20px; line-height: 1; }
#player-guide-grid { flex: 1; min-height: 0; overflow-y: auto; }
.player-guide .guide { --guide-channel: 130px; border: 0; border-radius: 0; background: transparent; }
.player-guide .guide-row { min-height: 44px; min-width: 0; border-top-color: rgba(255, 255, 255, .08); }
.player-guide .guide-head { min-height: 28px; background: rgba(255, 255, 255, .06); }
.player-guide .guide-row.guide-group { padding: 6px 12px 2px; }
.player-guide .guide-channel, .player-guide .guide-program, .player-guide .guide-group { background: rgba(255, 255, 255, .06); }
.player-guide .guide-channel { padding: 4px 8px; }
.player-guide .guide-logo { width: 34px; height: 24px; }
.player-guide .guide-time { display: none; }
/* Beats .guide-program.live (same specificity, declared later): the highlighted cell is always yellow. */
.player-guide .guide-program.guide-focus { background: #f5c518; border-color: #fff; z-index: 1; }
.player-guide .guide-program.guide-focus .guide-title { color: #111; }
.player-guide .guide-program.guide-focus .guide-progress { background: #111; }
.player-guide .guide-focus-row .guide-name { color: #f5c518; }
.player-guide .guide-playing .guide-name::before {
  content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%;
  background: #e53935; box-shadow: 0 0 6px #e53935;
}

/* A version's audio and subtitle languages, once a player has seen them */
.variants .tracks { margin-top: 2px; font-size: 12px; color: var(--muted); }

/* What's on: the card next to a channel card (showNowCard in app.js) */
.now-card {
  position: fixed; z-index: 60; width: 340px; display: grid; gap: 4px; padding: 12px 14px; pointer-events: none;
  border: 1px solid var(--accent); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
}
/* display: grid above would otherwise override the hidden attribute and keep the card on screen. */
.now-card[hidden] { display: none; }
.now-channel { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.now-channel span { font-weight: 400; font-size: 12.5px; color: var(--muted); }
.now-label { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.now-title { font-size: 15px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.now-muted { font-size: 12.5px; color: var(--muted); }
.now-bar { height: 4px; margin-top: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.now-bar i { display: block; height: 100%; background: var(--accent); }
.now-next { margin-top: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Sports (js/sports.js): a day's games as rows, each unfolding into the streams that carry it. */
a.chip { text-decoration: none; }
.chip-count { margin-left: 6px; color: var(--muted); font-weight: 400; }
.games { display: grid; gap: 6px; margin-bottom: 18px; }
.game { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.game-row { display: grid; grid-template-columns: 84px auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 14px; border: 0; background: none; text-align: left; min-width: 0; }
.game-row:hover { background: var(--surface-2); }
.game-time { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.game.live .game-time { color: #ff6b6b; }
.live-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: #ff6b6b; box-shadow: 0 0 0 3px #ff6b6b33; }
.game-badge { padding: 1px 7px; border: 1px solid var(--border); border-radius: 4px; font-size: 11.5px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.game-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-count { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.game-actions { display: flex; align-items: center; gap: 4px; padding: 0 10px; }
.game-follow { font-size: 18px; color: var(--muted); }
.game-follow.fav-on, .game.followed .game-follow { color: #ffc857; }
.game-sources { grid-column: 1 / -1; border-top: 1px solid var(--border); background: var(--surface-2); }
.game-sources[hidden] { display: none; }
.game-source { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 8px 14px 8px 26px; border-top: 1px solid var(--border); }
.game-source:first-child { border-top: 0; }
.game-quality { font-size: 12px; font-weight: 700; color: var(--accent); }
.game-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-feed { color: var(--muted); font-size: 12.5px; }
.day-chips { margin-bottom: 10px; }

/* TV guide */
.guide-row.guide-group { display: block; min-height: 0; padding: 10px 12px 4px; font-size: 12.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); }
.guide-row.missing { opacity: .5; }
.guide-row.missing .guide-channel { cursor: default; }
.guide { --guide-channel: 190px; position: relative; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.guide-row { display: grid; grid-template-columns: var(--guide-channel) minmax(0, 1fr); border-top: 1px solid var(--border); min-height: 64px; }
.guide-row:first-child { border-top: 0; }
.guide-head { min-height: 34px; background: var(--surface-2); }
.guide-channel {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 0; border-right: 1px solid var(--border);
  background: var(--surface-2); text-align: left; min-width: 0;
}
button.guide-channel:hover { background: var(--surface-3); }
.guide-now { font-size: 14px; font-weight: 700; color: var(--accent); }
.guide-logo { flex: none; width: 44px; height: 30px; display: grid; place-items: center; border-radius: 4px; background: #fff1; overflow: hidden; }
.guide-logo img { max-width: 90%; max-height: 90%; object-fit: contain; }
.guide-logo .placeholder { font-size: 10px; padding: 2px; }
.guide-label { display: flex; flex-direction: column; min-width: 0; }
.guide-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guide-track { position: relative; min-width: 0; overflow: hidden; }
.guide-mark { position: absolute; top: 9px; transform: translateX(4px); font-size: 14px; color: var(--muted); white-space: nowrap; }
.guide-mark.hour { color: var(--text); font-weight: 600; }
.guide-mark::before { content: ""; position: absolute; left: -4px; top: -9px; height: 34px; border-left: 1px solid var(--border); }
.guide-program {
  position: absolute; top: 6px; bottom: 6px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); text-align: left; overflow: hidden; display: flex; flex-direction: column; justify-content: center; min-width: 0;
}
.guide-program:hover { border-color: var(--accent); z-index: 1; }
.guide-program.live { background: #7c9cff1f; border-color: #7c9cff66; }
.guide-program.past { opacity: .5; }
.guide-progress { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); }
.guide-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guide-time { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.guide-empty { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 13px; color: var(--muted); }
.guide-nowline { position: absolute; top: 0; bottom: 0; width: 2px; background: #ff6b6b; pointer-events: none; z-index: 2; }
.guide-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.guide-foot label { display: inline-flex; align-items: center; gap: 8px; }
.guide-foot select { padding-top: 4px; padding-bottom: 4px; font-size: 12.5px; }
@media (max-width: 820px) {
  .guide { overflow-x: auto; }
  .guide-row { min-width: 760px; }
  .guide { --guide-channel: 130px; }
  /* The band's grid fits the picture: three or four rows on a phone held sideways, no sideways scroll. */
  .player-guide .guide { overflow-x: hidden; --guide-channel: 96px; }
  .player-guide .guide-row { min-width: 0; min-height: 38px; }
}

/* Touch screens: targets a finger can hit, no grey flash on tap, no link preview on a card's long press. */
@media (pointer: coarse) {
  * { -webkit-tap-highlight-color: transparent; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 40px; padding: 6px 12px; }
  .icon-btn { width: 44px; height: 44px; }
  .chip { padding: 9px 14px; }
  /* Three round buttons fit side by side on a phone's narrow cards (about 110 px). */
  .card-rate { right: 40px; }
  .card-rate.down { right: 74px; }
  select { min-height: 40px; }
  .card { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
}

/* Sign-in page */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
.login { width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 28px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.login .brand { padding: 0 0 12px; }
.login label { font-size: 13px; color: var(--muted); }
.login input { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); outline: 0; }
.login input:focus { border-color: var(--accent); }
.login .btn { justify-content: center; margin-top: 6px; }
.login-error { margin: 4px 0 0; color: var(--danger); font-size: 13.5px; }

/* Profiles: the sidebar's chip, "Who's watching?", the name and color form */
.avatar {
  display: inline-grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 8px;
  background: var(--surface-3); color: #fff; font-weight: 700; font-size: 15px;
}
.avatar.big { width: 96px; height: 96px; border-radius: 16px; font-size: 40px; }
.profile-chip {
  display: flex; align-items: center; gap: 10px; margin: auto 0 0; padding: 8px 12px; border: 0; border-radius: 8px;
  background: none; text-align: left; font-size: 12.5px; color: var(--muted);
}
.profile-chip strong { color: var(--text); font-size: 14px; }
.profile-chip:hover { background: var(--surface-2); }
/* The chip takes the push to the bottom, the foot follows it (the gear of the menu at the top sits between). */
.profile-chip:not([hidden]) ~ .sidebar-foot { margin-top: 0; }
/* Their display would otherwise win over the hidden attribute. */
.profiles[hidden], .profile-chip[hidden], .download-bar[hidden] { display: none; }
.nav[hidden], .icon-btn[hidden] { display: none !important; }
.profiles {
  position: fixed; inset: 0; z-index: 150; overflow-y: auto; display: grid; place-items: center;
  padding: max(32px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
  background: var(--bg);
}
.profiles-box { display: flex; flex-direction: column; align-items: center; gap: 24px; width: 100%; max-width: 760px; text-align: center; }
.profiles-box h1 { font-size: 32px; margin: 0; }
.profile-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 24px; }
.profile-tile {
  display: flex; flex-direction: column; align-items: center; gap: 10px; width: 120px; padding: 8px; border: 0; border-radius: 16px;
  background: none; color: var(--muted); font-size: 16px; overflow-wrap: anywhere;
}
.profile-tile:hover, .profile-tile:focus-visible { color: var(--text); outline: none; }
.profile-tile:hover .avatar, .profile-tile:focus-visible .avatar { box-shadow: 0 0 0 3px var(--text); }
.profile-tile.add .avatar { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--border); }
.profile-tile small { font-size: 12.5px; color: var(--accent); }
.profile-form { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; max-width: 360px; }
.profile-form p { margin: 0; color: var(--muted); }
.profile-form input[name="name"] {
  width: 100%; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); outline: 0; font-size: 17px;
}
.profile-form input[name="name"]:focus { border-color: var(--accent); }
.profile-form .actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.swatches { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.swatches input { position: absolute; opacity: 0; }
.swatches span { display: block; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; }
.swatches input:checked + span { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--text); }
.swatches input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; }
.form-error { color: var(--danger) !important; font-size: 13.5px; }
.btn.danger { color: var(--danger); }

/* A yes/no question (html.js ask): "Alice is watching on Samsung TV. Stop it and watch?" */
dialog.ask {
  max-width: min(420px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
dialog.ask::backdrop { background: #000a; }
dialog.ask p { margin: 0 0 18px; }
dialog.ask .actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; }
/* A card's long press (html.js pick): the actions stacked, full width. */
dialog.ask.sheet .actions { flex-direction: column; align-items: stretch; }
dialog.ask.sheet .btn { justify-content: center; }

/* A direct download of this profile holds the connection: "Download finished" frees it for the others */
.download-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 16px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); font-size: 14px;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200;
  padding: 10px 18px; border-radius: 8px; background: var(--surface-3); border: 1px solid var(--border); box-shadow: 0 8px 30px #0008;
}

.bar-search, .menu-btn { display: none; }

/* The menu at the top (html[data-layout="top"]): the sidebar becomes a bar over the page, the search box in it,
   its foot (sync status, settings, sign out) behind the gear. Phones keep their tabs: this is the desktop only. */
@media (min-width: 821px) {
  html[data-layout="top"] .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  html[data-layout="top"] .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto; min-height: 56px;
    flex-direction: row; align-items: center; gap: 2px; padding: 0 32px;
    border-right: 0; border-bottom: 1px solid var(--border);
    background: rgba(14, 16, 20, .85); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  }
  html[data-layout="top"] .sidebar > .brand { padding: 0 16px 0 0; }
  html[data-layout="top"] .nav { position: relative; height: 56px; padding: 0 12px; gap: 7px; border-radius: 0; font-size: 14.5px; font-weight: 600; }
  html[data-layout="top"] .nav svg { width: 18px; height: 18px; }
  html[data-layout="top"] .nav:hover, html[data-layout="top"] .nav.active { background: none; }
  html[data-layout="top"] .nav.active::after {
    content: ''; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px;
    background: var(--accent); border-radius: 2px 2px 0 0;
  }
  html[data-layout="top"] .nav-badge { margin-left: 8px; }
  /* The search box next to the logo, before Home; it gives way to the menu on narrower screens. */
  html[data-layout="top"] .bar-search { flex: 0 1 320px; display: flex; min-width: 140px; margin: 0 14px 0 0; }
  html[data-layout="top"] .bar-search .search { width: 100%; }
  html[data-layout="top"] .bar-search .search input { padding: 8px 0; font-size: 14px; }
  /* The avatar and the gear keep the right edge (the gear alone when no profile is picked). */
  html[data-layout="top"] .profile-chip { margin: 0 0 0 auto; padding: 4px; border-radius: 10px; }
  html[data-layout="top"] .profile-chip[hidden] + .menu-btn { margin-left: auto; }
  html[data-layout="top"] .profile-chip span:not(.avatar) { display: none; }
  html[data-layout="top"] .menu-btn { display: grid; color: var(--muted); }
  html[data-layout="top"] .menu-btn:hover, html[data-layout="top"] .sidebar.menu-open .menu-btn { color: var(--text); }
  html[data-layout="top"] .sidebar-foot {
    display: none; position: absolute; top: calc(100% + 8px); right: 32px; width: 300px; margin: 0; padding: 14px 16px;
    border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: 0 14px 40px #000a;
  }
  html[data-layout="top"] .sidebar.menu-open .sidebar-foot { display: flex; }
  html[data-layout="top"] .topbar { display: none; }
  html[data-layout="top"] main { padding-top: 24px; }
  /* Smaller posters, as the TV app's: 112 px instead of 150 in the Movies and Series grids and the shelves, so a row
     holds a third more. Channels keep their wider logo tiles. The three round buttons sit closer, as on a phone's
     cards, and the rated line keeps a readable floor as it shrinks to the narrower card. */
  html[data-layout="top"] .grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 16px 12px; }
  html[data-layout="top"] .grid.live { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  html[data-layout="top"] .shelf { grid-auto-columns: 112px; gap: 12px; }
  html[data-layout="top"] .card-rate { right: 40px; }
  html[data-layout="top"] .card-rate.down { right: 74px; }
  html[data-layout="top"] .card .sub.rated { font-size: clamp(10px, 8cqi, 12.5px); }
  html[data-nyan][data-layout="top"] .sidebar {
    border-bottom-width: 2px; border-image: linear-gradient(to right, #ff2a2a, #ff9a1f, #ffe81f, #33d64a, #2f8dff, #7a3cff) 1;
    background: rgba(10, 17, 48, .8);
  }
}
/* Narrow desktops and tablets: the menu's icons alone (their names as tooltips, js/layout.js) leave room for the search. */
@media (min-width: 821px) and (max-width: 1080px) {
  html[data-layout="top"] .nav { padding: 0 10px; }
  html[data-layout="top"] .nav span { display: none; }
  html[data-layout="top"] .nav svg { width: 21px; height: 21px; }
  html[data-layout="top"] .nav.active::after { left: 10px; right: 10px; }
}
/* A phone held sideways, or the iPhone Duo open wide (951 × 620): the menu at the top (js/layout.js), clear of the
   notch on either side. Capped at 1000 px so an iPad in landscape, 1024 px and wider, keeps its layout. */
@media (min-width: 821px) and (max-width: 1000px) and (max-height: 700px) and (pointer: coarse) {
  .layout-setting { display: none; }
  html[data-layout="top"] .sidebar { padding: 0 max(32px, env(safe-area-inset-right)) 0 max(32px, env(safe-area-inset-left)); }
  html[data-layout="top"] .sidebar-foot { right: max(32px, env(safe-area-inset-right)); }
  main { padding-left: max(32px, env(safe-area-inset-left)); padding-right: max(32px, env(safe-area-inset-right)); }
}

/* Nyan Cat mode (html[data-nyan], js/nyan.js): space behind the page, the cat flying through it with its rainbow,
   rainbow edges on the menu and the posters, the bar at the bottom right that turns it off. */
html[data-nyan] { --bg: #0a1130; --surface: #111a44; --surface-2: #192459; --surface-3: #232f6e; --border: #2f3c80; }
html[data-nyan] .app { position: relative; z-index: 1; }
html[data-nyan] .sidebar { border-right-width: 2px; border-image: linear-gradient(to bottom, #ff2a2a, #ff9a1f, #ffe81f, #33d64a, #2f8dff, #7a3cff) 1; }
html[data-nyan] .poster { animation: nyan-border 4s linear infinite; }
@keyframes nyan-border {
  0%, 100% { border-color: #ff2a2a; } 17% { border-color: #ff9a1f; } 33% { border-color: #ffe81f; }
  50% { border-color: #33d64a; } 67% { border-color: #2f8dff; } 83% { border-color: #7a3cff; }
}
.nyan { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; background: var(--bg); }
.nyan[hidden], .nyan-bar[hidden], .nyan-peek[hidden] { display: none; }
.nyan svg, .nyan-peek svg, .nyan-mini svg { stroke: none; display: block; }
.nyan-stars { position: absolute; inset: 0; background-repeat: repeat; animation: nyan-stars linear infinite; }
.nyan-stars.far {
  --nyan-shift: -240px; opacity: .55; animation-duration: 40s; background-size: 240px 240px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cg fill='%23fff'%3E%3Crect x='12' y='30' width='2' height='2'/%3E%3Crect x='70' y='12' width='2' height='2'/%3E%3Crect x='130' y='52' width='2' height='2'/%3E%3Crect x='200' y='20' width='2' height='2'/%3E%3Crect x='40' y='100' width='2' height='2'/%3E%3Crect x='160' y='120' width='2' height='2'/%3E%3Crect x='222' y='90' width='2' height='2'/%3E%3Crect x='90' y='160' width='2' height='2'/%3E%3Crect x='20' y='200' width='2' height='2'/%3E%3Crect x='180' y='210' width='2' height='2'/%3E%3Crect x='120' y='230' width='2' height='2'/%3E%3C/g%3E%3C/svg%3E");
}
.nyan-stars.near {
  --nyan-shift: -320px; animation-duration: 14s; background-size: 320px 320px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cg fill='%23fff'%3E%3Crect x='30' y='60' width='3' height='3'/%3E%3Crect x='150' y='20' width='3' height='3'/%3E%3Crect x='260' y='110' width='3' height='3'/%3E%3Crect x='90' y='180' width='3' height='3'/%3E%3Crect x='210' y='250' width='3' height='3'/%3E%3Crect x='300' y='300' width='3' height='3'/%3E%3Crect x='20' y='290' width='3' height='3'/%3E%3C/g%3E%3C/svg%3E");
}
@keyframes nyan-stars { to { background-position-x: var(--nyan-shift); } }
/* The big cat flies over the page (clicks go through), under the player, the profiles and the bars. */
.nyan-front { z-index: 45; background: none; }
/* The cats face right: they cross left to right, the rainbow trailing on their left and fading out.
   --s is a cat's pixel size (29 × 17 pixels), the same as its data-size; a pass takes its data-seconds. */
.nyan-fly { --s: 4; position: absolute; left: 0; top: 40%; width: calc(29px * var(--s)); height: calc(17px * var(--s)); animation: nyan-fly 17s linear infinite; }
.nyan-fly.small { --s: 3; animation-duration: 26s; }
.nyan-fly.medium { --s: 4; animation-duration: 17s; }
.nyan-fly.big { --s: 6; animation-duration: 12s; }
@keyframes nyan-fly { from { transform: translateX(calc(-60vw - 29px * var(--s))); } to { transform: translateX(100vw); } }
.nyan-cat { position: relative; animation: nyan-bob .5s steps(1, end) infinite; }
@keyframes nyan-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(calc(-1.5px * var(--s, 4))); } }
.nyan-trail {
  position: absolute; right: calc(100% - 3px * var(--s)); top: calc(2px * var(--s)); width: 60vw; height: calc(10px * var(--s));
  background: linear-gradient(#ff2a2a 0 16.67%, #ff9a1f 0 33.33%, #ffe81f 0 50%, #33d64a 0 66.67%, #2f8dff 0 83.33%, #7a3cff 0) 0 0 / 100% calc(10px * var(--s)) repeat-y;
  -webkit-mask-image: linear-gradient(to left, #000 55%, transparent); mask-image: linear-gradient(to left, #000 55%, transparent);
  animation: nyan-wave .5s steps(1, end) infinite;
}
@keyframes nyan-wave { 0%, 100% { background-position-y: 0; } 50% { background-position-y: calc(1.5px * var(--s, 4)); } }
.nyan-bar {
  position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 10px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); box-shadow: 0 8px 30px #0008;
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
}
.nyan-mini { --s: 1.5; line-height: 0; animation: nyan-bob .5s steps(1, end) infinite; }
.nyan-peek { position: fixed; z-index: 55; padding: 0; border: 0; background: none; cursor: pointer; filter: drop-shadow(0 4px 10px #0009); animation: nyan-peek .5s steps(4) both; }
.nyan-peek:hover svg, .nyan-peek:focus-visible svg { transform: translateY(-4px); }
/* The top corners sit under the menu at the top, clear of its gear. */
.nyan-peek.top-left { top: 66px; left: 10px; } .nyan-peek.top-right { top: 66px; right: 10px; }
/* The bottom corners sit above the layout button and the mode's bar. */
.nyan-peek.bottom-left { bottom: 64px; left: 10px; } .nyan-peek.bottom-right { bottom: 64px; right: 10px; }
@keyframes nyan-peek { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .nyan-stars, .nyan-fly, .nyan-cat, .nyan-trail, .nyan-peek, .nyan-mini, html[data-nyan] .poster { animation: none; }
  .nyan-fly.small { transform: translateX(8vw); } .nyan-fly.medium { transform: translateX(58vw); } .nyan-fly.big { transform: translateX(30vw); }
  html[data-nyan] .poster { border-color: #7a3cff; }
}

/* Phones (and the home screen app on iPhone): the top bar under the notch, tabs at the bottom. */
.phone-bar, .phone-only, .pull { display: none; }
.phone-bar .icon-btn { position: relative; color: var(--muted); }
.phone-bar .icon-btn.active { color: var(--accent); }
.phone-bar .nav-badge { position: absolute; top: 2px; right: 0; min-width: 17px; padding: 0 4px; font-size: 10.5px; line-height: 17px; }
.phone-bar .avatar { width: 28px; height: 28px; font-size: 13px; }
/* Pull to refresh in the home screen app (phone.js), which has no browser bar to reload from. */
.pull { justify-content: center; height: 0; overflow: hidden; transition: height .2s; }
.pull .spinner { margin-top: 8px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 40; height: auto; flex-direction: row; gap: 0;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    border-right: 0; border-top: 1px solid var(--border); background: rgba(22, 25, 32, .96);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  }
  .sidebar > .brand, .sidebar [data-nav="favorites"], .sidebar [data-nav="downloads"], .profile-chip, .sidebar-foot { display: none; }
  /* Sports is a sixth tab when the server has it (hidden otherwise, js/sports.js): six fit at 382 px with the 10.5 px labels. */
  .nav, .nav.phone-only {
    flex: 1 1 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 0; min-height: 52px;
    padding: 6px 0 4px; border-radius: 0; font-size: 10.5px; font-weight: 600;
  }
  .nav svg { width: 24px; height: 24px; }
  .nav.active, .nav:hover { background: none; }
  .nav.active { color: var(--accent); }
  .phone-bar {
    display: flex; align-items: center; gap: 2px; position: sticky; top: 0; z-index: 20;
    margin: 0 -16px; padding: env(safe-area-inset-top) 8px 0; min-height: calc(52px + env(safe-area-inset-top)); background: var(--bg);
  }
  .phone-bar .brand { flex: 1; padding: 0 6px; font-size: 17px; }
  .phone-bar #back:not([hidden]) + .brand span { display: none; }
  .pull { display: flex; }
  .pull[hidden] { display: none; }
  .avatar.big { width: 80px; height: 80px; font-size: 34px; }
  .profile-tile { width: 100px; }
  main { padding: 0 max(16px, env(safe-area-inset-right)) calc(76px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .topbar { top: calc(52px + env(safe-area-inset-top)); padding: 4px 0 12px; }
  body:not([data-section="search"]) .topbar { display: none; }
  .toast { bottom: calc(72px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); }
  /* Nyan Cat mode: the rainbow along the tabs, the bar and the peeking cat above them. */
  html[data-nyan] .sidebar { border-top-width: 2px; border-image: linear-gradient(to right, #ff2a2a, #ff9a1f, #ffe81f, #33d64a, #2f8dff, #7a3cff) 1; }
  .nyan-bar { bottom: calc(68px + env(safe-area-inset-bottom)); }
  .nyan-peek.bottom-left, .nyan-peek.bottom-right { bottom: calc(116px + env(safe-area-inset-bottom)); }
  /* The player: its controls wrap under the title (the safe-area padding is in the base rule, for every width). */
  .player-bar { flex-wrap: wrap; gap: 8px; padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); }
  .player-title { flex: 1 1 calc(100% - 60px); }
  .player-bar select, #player-audio, #player-subs { max-width: 46vw; }
  .hero { margin: 0 -16px; padding: 20px 16px; }
  /* Only the title and meta sit beside the poster; the buttons and details take the full width below it. */
  .hero-inner, .hero-inner.live { grid-template-columns: 96px minmax(0, 1fr); grid-template-rows: auto auto 1fr; gap: 0 14px; }
  .hero-text { display: contents; }
  .hero .poster { width: 96px; grid-row: 1 / 4; align-self: start; }
  .hero h1 { font-size: 21px; overflow-wrap: anywhere; }
  .hero .meta { margin-bottom: 8px; font-size: 13px; }
  .hero .awards { margin: 0 0 8px; }
  .hero .actions, .hero #details { grid-column: 1 / -1; }
  .hero .actions { gap: 8px; margin: 14px 0 4px; }
  .hero .actions .btn { flex: 1 1 auto; justify-content: center; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 16px 10px; }
  .episode { grid-template-columns: 32px minmax(0, 1fr) auto; }
  /* Games on a phone: the title gets its own line under the time and the badge; the source count goes. */
  .game-row { grid-template-columns: 72px auto minmax(0, 1fr); gap: 8px 10px; padding: 10px 12px; }
  .game-title { grid-column: 1 / -1; white-space: normal; }
  .game-count { display: none; }
  .game-actions { padding: 0 8px 0 0; }
  .episode .thumb { display: none; }
  .variants .raw { display: none; }
  /* A version's buttons go under its language and tags instead of past the screen's edge. */
  .variants tr { display: flex; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--border); }
  .variants td { border-bottom: 0; }
  .variants td.go { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; padding-top: 0; text-align: left; white-space: normal; }
}

/* Settings */
.settings-page { max-width: 640px; }
/* Settings › New features: a switch per feature, what it does under its name. */
.features { display: grid; gap: 14px; margin: 0 0 28px; }
.features h3 { margin: 10px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.feature { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 12px; align-items: center; }
.feature .switch { margin: 0; }
.feature-name { font-weight: 600; }
.feature-note { grid-column: 2; color: var(--muted); font-size: 13.5px; }
.feature.unavailable .feature-name { color: var(--muted); }
.features-intro { color: var(--muted); margin: 0 0 14px; }
.about { display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; margin: 0; }
.about dt { color: var(--muted); }
.about dd { margin: 0; }
.about code { font-size: 13.5px; }
@media (max-width: 820px) { .layout-setting { display: none; } } /* phones keep their tabs whatever the layout */

/* Tablets in portrait (the iPhone Duo open, 669 × 902; an iPad, 768 × 1024): the phone's tabs with more room.
   A phone held sideways in this width range is under 600 px tall; a desktop window has a fine pointer.
   Only for a profile that turned the tablet layout on (Settings › New features sets html[data-tablet]): without
   it a tablet keeps the phone layout as it was. */
@media (min-width: 600px) and (max-width: 820px) and (min-height: 600px) and (pointer: coarse) {
  html[data-tablet] .sidebar [data-nav="favorites"] { display: flex; }
  /* Five posters per row at 669 px: 5 × 116 + 4 × 10 in the 637 px between the gutters. */
  html[data-tablet] .grid { grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); }
  html[data-tablet] .shelf { grid-auto-columns: 116px; }
  /* The title page as on a computer: the poster with the title, meta and buttons beside it. */
  html[data-tablet] .hero-inner, html[data-tablet] .hero-inner.live { grid-template-columns: 140px minmax(0, 1fr); grid-template-rows: auto; gap: 0 20px; }
  html[data-tablet] .hero-text { display: block; }
  html[data-tablet] .hero .poster { width: 140px; grid-row: auto; }
  html[data-tablet] .hero h1 { font-size: 26px; }
  html[data-tablet] .hero .actions, html[data-tablet] .hero #details { grid-column: auto; }
  html[data-tablet] .hero .actions .btn { flex: 0 1 auto; }
  /* The favorites guide fits the width instead of scrolling sideways. */
  html[data-tablet] .guide-row { min-width: 0; }
  html[data-tablet] .guide { --guide-channel: 150px; }
}

/* The home screen app has no browser bar: its back button and pull to refresh (phone.js) exist at every width.
   With the menu at the top the back button sits before the logo (layout.js moves it there); Safari tabs keep
   the browser's own back and reload. */
.sidebar > #back { display: none; }
@media (display-mode: standalone) {
  .pull { display: flex; }
  .pull[hidden] { display: none; }
  html[data-layout="top"] .sidebar > #back:not([hidden]) { display: grid; margin-right: 4px; }
}

/* A foldable open wide and folded to 90° (Safari's Viewport Segments API, js/posture.js): the picture fills the
   top half, the controls and the TV guide the bottom half, and the hinge band between them stays black. */
.player-panel[hidden] { display: none; }
@media (vertical-viewport-segments: 2) {
  .player:not([hidden]) {
    display: grid;
    grid-template-rows: env(viewport-segment-height 0 0) calc(env(viewport-segment-top 0 1) - env(viewport-segment-bottom 0 0)) auto minmax(0, 1fr);
  }
  .player-stage { grid-row: 1; margin-bottom: 0; }
  .player-bar { grid-row: 3; flex-wrap: wrap; gap: 8px; border-top: 1px solid #1c1f27; }
  .player-title { flex: 1 1 calc(100% - 60px); }
  .player-panel { grid-row: 4; min-height: 0; overflow-y: auto; padding: 10px max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left)); }
  .player-panel .guide-foot { display: none; }
}
