:root {
  --bg: #150b12;
  --bg-2: #22101c;
  --panel: #261520;
  --raised: #321b2a;
  --line: rgba(223, 202, 176, 0.10);
  --text: #f7ecdc;
  --muted: #c4afa2;
  --accent: #ecc9a2;
  --grad: linear-gradient(135deg, #f5e2c4, #dc9c80);
  --ink: #3a1631;
  --danger: #ff8f8f;
  --star: #f7cd83;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg) linear-gradient(180deg, var(--bg-2), var(--bg) 320px) no-repeat;
  color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

button, input, select {
  font: inherit;
  color: inherit;
  border-radius: 12px;
  border: 1px solid transparent;
  min-height: 44px;
}

button {
  background: var(--grad);
  color: var(--ink);
  font-weight: 700;
  padding: 0 18px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
button:active { filter: brightness(0.92); }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); box-shadow: none; font-weight: 600; }

input, select {
  background: var(--panel);
  padding: 0 14px;
  width: 100%;
  border-color: var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
input::placeholder { color: #8d7a74; }
input:focus-visible, select:focus-visible { outline: none; border-color: #c08a74; box-shadow: 0 0 0 3px rgba(192, 138, 116, 0.28); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Login */
#login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}
#login-form {
  width: 100%;
  max-width: 360px;
  display: grid;
  gap: 12px;
}
#login-form, #setup-card { text-align: center; }
#login h1, #setup h1 { margin: 0 0 10px; font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; }
#login .logo, #setup .logo {
  border-radius: 24px;
  width: 96px;
  height: 96px;
  margin: 0 auto 4px;
  box-shadow: 0 0 0 1px rgba(223, 202, 176, 0.25), 0 0 48px 6px rgba(192, 138, 116, 0.28);
}
#login input { text-align: left; }
.error { color: var(--danger); margin: 0; min-height: 1em; font-size: 0.9rem; }

/* App shell. Sized to the visible screen (dvh) so Safari's toolbars
   never sit on top of the bottom of the page. */
#app {
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
header {
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  border-bottom: 1px solid var(--line);
}
header nav, .subtabs { display: flex; gap: 2px; padding: 3px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
header nav button, .subtabs button {
  flex: 1;
  min-height: 38px;
  padding: 0 4px;
  background: transparent;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 13px;
  box-shadow: none;
}
header nav button.active, .subtabs button.active { background: var(--grad); color: var(--ink); font-weight: 800; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4); }

/* Search and category scroll away with the list to save room. */
#filters { display: flex; gap: 8px; margin-bottom: 12px; }
#filters > * { flex: 1; min-width: 0; }

main {
  overflow-y: auto;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 24px);
  -webkit-overflow-scrolling: touch;
}

.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }

.item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  align-items: center;
  min-height: 60px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.item .main {
  flex: 1;
  min-width: 0;
  background: none;
  color: var(--text);
  border: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  text-align: left;
  min-height: 58px;
  border-radius: 16px;
  font-weight: 600;
  box-shadow: none;
}
.item img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 10px;
  flex: none;
  background: rgba(0, 0, 0, 0.28);
}
.item .text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.item .name, .item .sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item .sub { color: var(--muted); font-size: 0.8rem; }
.item .sub:empty { display: none; }
.item .star {
  background: none;
  color: var(--muted);
  width: 48px;
  min-height: 58px;
  padding: 0;
  font-size: 1.3rem;
  border-radius: 0 16px 16px 0;
  box-shadow: none;
}
.item .star.on { color: var(--star); }

.bar {
  display: block;
  height: 3px;
  background: rgba(223, 202, 176, 0.14);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}
.bar i { display: block; height: 100%; background: var(--grad); }

h2.section {
  font-size: 1.05rem;
  color: var(--text);
  margin: 24px 0 10px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
h2.section:first-child { margin-top: 4px; }
.back { margin-bottom: 12px; }
.footer { margin-top: 28px; display: flex; justify-content: center; }

.status { color: var(--muted); padding: 24px 0; text-align: center; }

/* ---------- Player ----------
   Portrait: bar, then the video at 16:9 pinned to the top, then the guide.
   Landscape: bar, then the video fills the rest (guide hidden). */
#player {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  height: 100dvh;
  background: #000;
  display: grid;
  /* minmax(0, 1fr): the column can never grow past the screen, however long a title is */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  z-index: 10;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
/* Movies and episodes have no guide: keep the controls clear of the
   home-indicator area at the bottom of the screen. */
#player.no-guide {
  grid-template-rows: auto minmax(0, 1fr);
  padding-bottom: calc(env(safe-area-inset-bottom) + 12px);
}

.player-bar {
  min-width: 0;
  display: flex;
  gap: 4px;
  align-items: center;
  min-height: 48px;
  padding: calc(env(safe-area-inset-top) + 4px) 8px 4px 12px;
  color: var(--text);
}
.player-bar .close { min-height: 36px; padding: 0 14px; font-size: 0.9rem; background: transparent; color: var(--text); border-color: rgba(223, 202, 176, 0.4); box-shadow: none; font-weight: 600; }
.player-bar span {
  flex: 1;
  min-width: 0;
  padding: 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  background: transparent;
  color: var(--text);
  box-shadow: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
}
.icon-btn.star-btn { color: var(--star); font-size: 1.5rem; }
.icon-btn .vol-off { display: none; }
.icon-btn.muted .vol-on { display: none; }
.icon-btn.muted .vol-off { display: block; }

#video {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 60vh;
  max-height: 60dvh;
  background: #000;
  align-self: start;
}
#player.no-guide #video { align-self: center; }

#guide {
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--text);
  overflow-y: auto;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  font-size: 0.9rem;
}
#guide .title { font-weight: 800; font-size: 1rem; }
#guide .meta { color: var(--muted); font-size: 0.8rem; }
#guide .desc {
  color: var(--muted);
  margin: 6px 0 0;
  font-size: 0.85rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
#guide ul { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
#guide li { display: flex; gap: 10px; }
#guide li time { color: var(--muted); flex: none; width: 5.5em; }

/* Converted (MKV etc.) playback: our own seek bar under the video */
#player.remux, #player.remux.no-guide {
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding-bottom: 0;
}
#rctl {
  color: var(--text);
  padding: 4px 12px calc(env(safe-area-inset-bottom) + 8px);
}
#rseek { width: 100%; margin: 4px 0; accent-color: #ecc9a2; }
.rrow { display: flex; align-items: center; gap: 4px; }
.rrow span { flex: 1; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.rrow span:last-child { text-align: right; }
.rrow button { background: transparent; color: var(--text); box-shadow: none; min-width: 44px; min-height: 44px; padding: 0 6px; font-size: 0.95rem; }
#rstatus {
  position: absolute;
  top: 50%;
  left: 16px;
  right: 16px;
  transform: translateY(-50%);
  text-align: center;
  color: var(--text);
  background: rgba(21, 11, 18, 0.82);
  border: 1px solid var(--line);
  padding: 12px 16px;
  border-radius: 14px;
  pointer-events: none;
}
#rstatus.error { color: var(--danger); }

@media (orientation: landscape) {
  #player, #player.no-guide {
    grid-template-rows: auto minmax(0, 1fr);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #video {
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
    align-self: stretch;
  }
  #player.remux, #player.remux.no-guide { grid-template-rows: auto minmax(0, 1fr) auto; padding-bottom: 0; }
  #guide { display: none; }
  .player-bar { min-height: 44px; padding-top: calc(env(safe-area-inset-top) + 2px); }
}

/* Subtitles on converted playback: Safari's own rendering is hidden, we draw them centered. */
#player.remux video::-webkit-media-text-track-container { display: none !important; }
#subs {
  position: fixed;
  z-index: 5;
  text-align: center;
  pointer-events: none;
  color: #fff6e8;
  font-weight: 500;
  line-height: 1.25;
  text-shadow: 0 0 3px #000, 0 1px 2px #000, 0 0 6px #000;
  white-space: pre-line;
  box-sizing: border-box;
  padding: 0 6px;
}
#subs span { background: rgba(0, 0, 0, 0.55); padding: 1px 8px; border-radius: 4px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.cc-btn { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.02em; }
.cc-btn.off { opacity: 0.4; text-decoration: line-through; }

/* Our own fullscreen for converted playback: the picture fills the screen, controls overlay it. */
#player.remux.fs, #player.remux.fs.no-guide {
  display: block;
  padding: 0;
}
#player.fs #video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
  object-fit: contain;
}
#player.fs .player-bar, #player.fs #rctl {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 6;
  transition: opacity 0.2s;
  padding-left: calc(env(safe-area-inset-left) + 12px);
  padding-right: calc(env(safe-area-inset-right) + 12px);
}
#player.fs .player-bar { top: 0; background: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0)); }
#player.fs #rctl { bottom: 0; background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.8)); padding-top: 24px; }
#player.fs:not(.ui) .player-bar, #player.fs:not(.ui) #rctl { opacity: 0; pointer-events: none; }
#player.fs #guide { display: none; }

/* Library: TV / Movies / Series switcher (tray styling shared with the main nav above) */
.subtabs { margin: 8px 12px 4px; }

/* Movie, series and episode rows carry a portrait poster instead of a square icon. */
.item.poster .main { padding: 8px 12px 8px 8px; }
.item.poster img {
  width: 48px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.item.poster .name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* Setup screen, profile page and the "who" card in the library */
#setup { min-height: 100%; display: grid; place-items: center; padding: 16px; }
#setup-card { width: 100%; max-width: 380px; display: grid; gap: 12px; }
#setup .hint { margin: 0 0 4px; color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.form { display: grid; gap: 10px; text-align: left; }
.form .error { min-height: 0; }
#setup .error:empty, .form .error:empty { display: none; }
.who {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 12px 16px;
  min-height: 48px;
  text-align: left;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: none;
  font-weight: 600;
}
.who .who-name { font-weight: 800; }
.who .who-list { flex: 1; min-width: 0; color: var(--muted); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .who-go { color: var(--accent); font-size: 0.85rem; }
.profile .back { display: inline-flex; align-items: center; }
.profile .addbox { margin-top: 10px; display: grid; }
.item.pl.current { border-color: rgba(236, 201, 162, 0.55); }
.item .star.rm { width: auto; padding: 0 16px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.item .star.rm.armed { color: var(--danger); }
.profile .form { margin-top: 4px; }

#submenu {
  position: fixed; z-index: 30; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
  max-height: 60vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: #261521; border: 1px solid #4a2d43; border-radius: 14px; padding: 6px 0;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}
@media (min-width: 640px) { #submenu { left: auto; width: 340px; right: 12px; } }
#submenu button {
  display: block; width: 100%; text-align: left; background: none; border: 0; color: #f3e6d0;
  font: inherit; padding: 12px 18px; min-height: 44px;
}
#submenu button.on::after { content: ' ✓'; color: #e8c88a; }
#submenu button.dim { opacity: 0.45; }
#submenu button.head { font-size: 0.85rem; color: #c9a77a; padding-top: 10px; padding-bottom: 4px; min-height: 0; }

/* No double-tap zoom or sideways drag on the player, so fast repeated taps are always taps. */
html, body { overscroll-behavior: none; }
/* Not on the video itself: Safari's own controls (AirPlay etc.) must be left alone. */
#player .player-bar, #player .player-bar *, #player #rctl, #player #rctl *, #player #guide, #player #guide *, #player #submenu, #player #submenu * { touch-action: manipulation; }
#player { overscroll-behavior: none; }

/* Live TV in our own player: bar, a play button under the video, our own fullscreen. No seek bar. */
#player.live-own { grid-template-rows: auto auto auto minmax(0, 1fr); }
#player.live-own #rseek, #player.live-own [data-skip], #player.live-own #rcur, #player.live-own #rdur { display: none; }
#player.live-own .rrow { justify-content: center; }
#player.live-own #rctl { padding-top: 0; padding-bottom: 4px; }
#player.live-own #rplay { min-width: 64px; }
#player.live-own.fs, #player.live-own.fs.no-guide { display: block; padding: 0; }
@media (orientation: landscape) {
  #player.live-own { grid-template-rows: auto minmax(0, 1fr) auto; padding-bottom: 0; }
  #player.live-own.fs { display: block; }
}

/* ---------- TV mode (html.tv): remote control, bigger layout ---------- */
.versioninfo { color: var(--muted); font-size: 0.72rem; text-align: center; word-break: break-word; margin: 18px 0 0; line-height: 1.4; }

html.tv { font-size: 21px; }
/* The page itself scrolls (the remote scrolls the page, not an inner box). */
html.tv, html.tv body { height: auto; min-height: 100%; overscroll-behavior: auto; }
html.tv #app { height: auto; min-height: 100vh; display: block; }
html.tv header { position: sticky; top: 0; z-index: 5; padding: 0.667rem 1.524rem 0.571rem; }
html.tv main { overflow: visible; padding: 0.952rem 1.524rem 4.571rem; }
html.tv #login, html.tv #setup { padding: 1.524rem; }

html.tv button, html.tv input, html.tv select { min-height: 2.667rem; }
html.tv header nav button, html.tv .subtabs button { min-height: 2.667rem; font-size: 1rem; }
html.tv .subtabs { margin: 0.381rem 0 0.19rem; }
html.tv .list:not(.tiles) { grid-template-columns: repeat(auto-fill, minmax(20.952rem, 1fr)); gap: 0.667rem; }
html.tv .item { min-height: 4rem; }
html.tv .item .main { min-height: 3.905rem; padding: 0.571rem 0.762rem; gap: 0.762rem; font-size: 1rem; }
html.tv .item img { width: 3.048rem; height: 3.048rem; }
html.tv .item.poster .main { padding: 0.476rem 0.762rem 0.476rem 0.476rem; }
html.tv .item.poster img { width: 2.857rem; height: 4.286rem; }
html.tv .item .sub { font-size: 0.8rem; }
html.tv .item .star { width: 3.429rem; min-height: 3.905rem; font-size: 1.6rem; }
html.tv .item .star.rm { width: auto; padding: 0 1.048rem; font-size: 0.85rem; }
html.tv .who { min-height: 3.048rem; }

/* Focus: a bright ring, so you always see where you are. */
html.tv button:focus, html.tv input:focus, html.tv select:focus { outline: max(0.143rem, 0.19rem) solid var(--accent); outline-offset: 0.143rem; }
html.tv .item .main:focus, html.tv .item .star:focus { outline-offset: -0.238rem; background: rgba(236, 201, 162, 0.16); }
html.tv .item:focus-within { border-color: var(--accent); box-shadow: 0 0 0 0.095rem rgba(236, 201, 162, 0.35), 0 0.476rem 1.238rem rgba(0, 0, 0, 0.5); }
html.tv header nav button:focus, html.tv .subtabs button:focus { background: rgba(236, 201, 162, 0.24); color: var(--text); outline-offset: -0.143rem; }
html.tv header nav button.active:focus, html.tv .subtabs button.active:focus { background: var(--grad); color: var(--ink); }
html.tv #rseek:focus { outline-offset: 0.286rem; }
html.tv #player:focus { outline: none; }

/* When scrolling to a focused item, keep it clear of the sticky header. */
html.tv .item .main, html.tv .item .star, html.tv .back, html.tv .who, html.tv .subtabs button,
html.tv #filters > *, html.tv .form > *, html.tv .addbox > *, html.tv .footer > * { scroll-margin-top: 6.667rem; scroll-margin-bottom: 3.333rem; }

/* Player */
html.tv .player-bar { min-height: 3.619rem; gap: 0.381rem; }
html.tv .player-bar .close { min-height: 2.667rem; font-size: 1rem; }
html.tv .icon-btn { min-width: 2.667rem; min-height: 2.667rem; }
html.tv .icon-btn svg { width: 1.429rem; height: 1.429rem; }
html.tv .cc-btn { font-size: 1rem; }
html.tv .rrow button { min-height: 2.667rem; min-width: 3.238rem; font-size: 1.15rem; }
html.tv .rrow span { font-size: 1rem; }
html.tv #rctl { padding-left: 1.143rem; padding-right: 1.143rem; }
/* Hidden controls must not be reachable with the remote either. */
html.tv #player.fs:not(.ui) .player-bar, html.tv #player.fs:not(.ui) #rctl { visibility: hidden; }
html.tv #submenu { left: auto; right: 1.524rem; bottom: 1.524rem; width: 22.857rem; max-height: 70vh; }
html.tv #submenu button { padding: 0.667rem 1.048rem; min-height: 2.667rem; font-size: 1rem; }
html.tv #submenu button.head { min-height: 0; font-size: 0.85rem; }
html.tv #submenu button:focus { background: rgba(236, 201, 162, 0.28); outline: none; }
html.tv #rstatus { font-size: 1.1rem; }
html.tv .who { align-items: center; }

/* ---------- Tiles (v27): poster / channel-logo grids, same look on phone and TV; columns follow the width ---------- */
:root { --pw: 104px; --lw: 150px; }
@media (min-width: 700px) { :root { --pw: 140px; --lw: 200px; } }
@media (min-width: 1100px) { :root { --pw: 170px; --lw: 240px; } }
html.tv { --pw: 7.143rem; --lw: 9.05rem; }   /* ~150px poster / 190px channel at the 1600 design width; app.js can override (?tvtile=) */

.list.tiles { grid-template-columns: repeat(auto-fill, minmax(var(--pw), 1fr)); gap: 14px 10px; }
.list.tiles.live-tiles { grid-template-columns: repeat(auto-fill, minmax(var(--lw), 1fr)); }
.list.tiles .item { display: block; position: relative; min-height: 0; background: none; border: 0; box-shadow: none; border-radius: 0; }
.list.tiles .item .main { display: flex; flex-direction: column; align-items: stretch; gap: 7px; width: 100%; min-height: 0; padding: 0; border-radius: 12px; }
.list.tiles .item .art {
  position: relative; display: block; width: 100%; aspect-ratio: 2 / 3; overflow: hidden; border-radius: 12px;
  background: linear-gradient(160deg, var(--raised), var(--panel)); border: 1px solid var(--line);
}
.list.tiles .item:not(.poster) .art { aspect-ratio: 16 / 10; }
.list.tiles .item .art::before {
  content: attr(data-letter); position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 2.2rem; font-weight: 800; color: rgba(236, 201, 162, 0.35);
}
.list.tiles .item .art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border: 0; border-radius: 0; background: transparent; }
.list.tiles .item:not(.poster) .art img { object-fit: contain; padding: 16px; background: rgba(0, 0, 0, 0.28); }
.list.tiles .item .text { display: grid; gap: 2px; padding: 0 2px; }
.list.tiles .item .name, .list.tiles .item .sub {
  white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; line-height: 1.25;
}
.list.tiles .item .name { font-size: 0.82rem; font-weight: 700; }
.list.tiles .item .sub { font-size: 0.72rem; }
.list.tiles .item .sub:empty { display: none; }
.list.tiles .item .bar { position: absolute; left: 8px; right: 8px; bottom: 7px; margin: 0; height: 4px; background: rgba(0, 0, 0, 0.55); z-index: 1; }
.list.tiles .item .star {
  position: absolute; top: 6px; right: 6px; width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 50%;
  background: rgba(21, 11, 18, 0.72); color: #fff; font-size: 1.1rem; box-shadow: none;
}
.list.tiles .item .star.on { color: var(--star); }

html.tv .list.tiles { gap: 1.048rem 0.857rem; }
html.tv .list.tiles .item .name { font-size: 0.85rem; }
html.tv .list.tiles .item .sub { font-size: 0.75rem; }
html.tv .list.tiles .item .star { width: 2.476rem; height: 2.476rem; min-height: 2.476rem; font-size: 1.4rem; }
html.tv .list.tiles .item .main:focus { outline: max(0.143rem, 0.19rem) solid var(--accent); outline-offset: 0.143rem; background: none; }
html.tv .list.tiles .item:focus-within { border: 0; box-shadow: none; transform: scale(1.05); z-index: 2; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); z-index: 50; max-width: 80vw;
  background: var(--raised); color: var(--text); border: 1px solid var(--accent); border-radius: 14px; padding: 12px 22px;
  font-weight: 700; transition: opacity 0.2s; pointer-events: none;
}
.toast:not(.show) { opacity: 0; }
html.tv .list.tiles .item .main { scroll-margin-top: 7.143rem; scroll-margin-bottom: 5.714rem; }

/* Playback problem screen: choices under the message */
#rstatus.actions { pointer-events: auto; z-index: 7; }
#rstatus .errbtns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px; }
#rstatus .errbtn { min-height: 44px; padding: 0 18px; }
html.tv #rstatus .errbtn { min-height: 2.667rem; font-size: 1rem; }

/* ---------- v37: TV category picker, slimmer search row ---------- */
#catmenu {
  position: fixed; z-index: 40; width: 22rem; max-width: 92vw; overflow-y: auto;
  background: #261521; border: 1px solid #4a2d43; border-radius: 0.8rem; padding: 0.3rem 0;
  box-shadow: 0 0.5rem 1.8rem rgba(0, 0, 0, 0.6);
}
#catmenu button {
  display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 0; color: #f3e6d0;
  font: inherit; font-size: 1rem; padding: 0.55rem 1rem; min-height: 2.4rem; box-shadow: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#catmenu button.on::after { content: ' ✓'; color: #e8c88a; }
#catmenu button:focus { background: rgba(236, 201, 162, 0.28); outline: none; }
html.tv #filters { gap: 0.6rem; margin-bottom: 0.7rem; }
html.tv #filters input, html.tv #filters select { min-height: 2.1rem; font-size: 0.9rem; padding-top: 0; padding-bottom: 0; }
html.tv #filters > #search { flex: 0.75; }
html.tv #filters > #category { flex: 1.25; }

/* ---------- v41: sign in with your phone (TV) / Approve a TV (phone) ---------- */
#pair { display: grid; place-items: center; min-height: 100vh; padding: 24px; text-align: center; }
#pair-card { width: 100%; max-width: 520px; display: grid; gap: 14px; justify-items: center; }
#pair-card .logo { border-radius: 16px; }
#pair-code { font-size: 3.4rem; font-weight: 800; letter-spacing: 0.18em; padding: 0.15em 0.4em; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); color: var(--accent); font-variant-numeric: tabular-nums; }
#pair-start { width: 100%; }
.pairask { display: grid; gap: 10px; }
.pairwho { margin: 0; }
p.ok { color: #9fd8a8; margin: 0; }
html.tv #pair-card { max-width: 38rem; gap: 1rem; }
html.tv #pair-code { font-size: 4.2rem; }
html.tv #pair-start { margin-bottom: 0.4rem; }

/* v44: skip drawing tiles that are off screen (the grid holds up to 300) */
html.tv .list.tiles .item { content-visibility: auto; contain-intrinsic-size: auto 15rem; }
html.tv .list.tiles .item:focus-within { content-visibility: visible; }
