:root {
  /* Defaults; overridden at boot by theme.json via app.js setThemeVars(). */
  --brand: #e50914;
  --brand-text: #ffffff;
  --bg: #0b0d12;
  --bg-elevated: #14171f;
  --surface: #1b1f2a;
  --text: #f5f6f8;
  --text-muted: #9aa3b2;
  --focus-ring: #ffffff;
  --top10-numeral: #2a2f3c;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-display: var(--font-body);

  --poster-w: 11.5rem;
  --poster-h: 17.25rem;
  --row-gap: 0.9rem;
  --radius: 0.6rem;
  --header-h: 4.25rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body { overscroll-behavior: none; }

img { display: block; max-width: 100%; }

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ----------------------------------------------------------------- focus */
/* Spatial-nav engine adds .is-focused to the active element. */
.focusable { outline: none; }
.focusable.is-focused {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius);
  position: relative;
  z-index: 2;
}
.focusable.is-focused.poster {
  transform: scale(1.06);
}

/* ----------------------------------------------------------------- boot */
.boot-splash {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1.5rem;
  background: var(--bg);
  z-index: 100;
}
.boot-logo { width: 7rem; height: auto; opacity: 0.95; }
.boot-spinner {
  width: 2.5rem; height: 2.5rem;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------- header */
.app-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0 2.5rem;
  z-index: 40;
  background: linear-gradient(180deg, rgba(11,13,18,0.95) 0%, rgba(11,13,18,0) 100%);
  transition: background 0.2s;
}
.app-header .brand {
  display: flex; align-items: center; gap: 0.65rem;
  font-family: var(--font-display);
  font-weight: 800; font-size: 1.15rem; letter-spacing: 0.02em;
}
.app-header .brand img { height: 2rem; width: auto; }
.app-header nav { display: flex; gap: 0.5rem; margin-left: auto; align-items: center; }
.app-header nav .navbtn {
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.95rem; font-weight: 600;
}
.app-header nav .navbtn.is-focused,
.app-header nav .navbtn:hover { color: var(--text); background: rgba(255,255,255,0.08); }
.app-header .avatar {
  width: 2.25rem; height: 2.25rem; border-radius: 50%;
  object-fit: cover; background: var(--surface);
}

.view { min-height: 100vh; padding-top: var(--header-h); }

/* ----------------------------------------------------------------- hero */
.hero {
  position: relative;
  height: 78vh;
  min-height: 28rem;
  margin-bottom: 1rem;
  overflow: hidden;
}
.hero .hero-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 1s ease-in-out;
}
.hero .hero-img.active { opacity: 1; }
.hero::after {
  content: "";
  position: absolute; inset: 0;
  background:
    linear-gradient(90deg, rgba(11,13,18,0.92) 0%, rgba(11,13,18,0.55) 38%, rgba(11,13,18,0) 70%),
    linear-gradient(0deg, var(--bg) 2%, rgba(11,13,18,0) 40%);
  pointer-events: none;
}
.hero .hero-content {
  position: absolute;
  left: 2.5rem; bottom: 3.5rem;
  max-width: 36rem;
  z-index: 3;
}
.hero .hero-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.75rem);
  font-weight: 900; line-height: 1.02; margin: 0 0 0.75rem;
  text-shadow: 0 2px 18px rgba(0,0,0,0.6);
}
.hero .hero-meta { color: var(--text-muted); font-weight: 600; margin-bottom: 0.6rem; }
.hero .hero-overview {
  color: var(--text); opacity: 0.92; line-height: 1.45;
  margin-bottom: 1.25rem;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.hero .hero-cta { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.7rem 1.4rem;
  border-radius: 0.5rem;
  font-weight: 700; font-size: 1rem;
  background: rgba(255,255,255,0.16);
  color: var(--text);
  transition: transform 0.1s, background 0.15s;
}
.btn .ic { font-size: 1.1em; line-height: 1; }
.btn-primary { background: var(--brand); color: var(--brand-text); }
.btn-primary.is-focused, .btn-primary:hover { filter: brightness(1.12); }
.btn.is-focused, .btn:hover { background: rgba(255,255,255,0.28); }
.btn-primary.is-focused, .btn-primary:hover { background: var(--brand); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn-block { width: 100%; justify-content: center; }

/* ----------------------------------------------------------------- rows */
.rows { padding: 0 0 4rem; }
.poster-row { margin: 2rem 0; }
.poster-row .row-title {
  font-family: var(--font-display);
  font-size: 1.35rem; font-weight: 800;
  margin: 0 0 0.85rem 2.5rem;
}
.row-track {
  display: flex; gap: var(--row-gap);
  padding: 0.5rem 2.5rem;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  /* Keep horizontal scroll inside the row; don't chain to the page. */
  overscroll-behavior: contain;
}
.row-track::-webkit-scrollbar { display: none; }

.poster {
  position: relative;
  flex: 0 0 var(--poster-w);
  width: var(--poster-w);
  scroll-snap-align: start;
  transition: transform 0.15s ease;
}
.poster .poster-art {
  width: var(--poster-w); height: var(--poster-h);
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--surface);
  display: block;
}
.poster .poster-fallback {
  width: var(--poster-w); height: var(--poster-h);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 0.75rem; color: var(--text-muted); font-weight: 700; font-size: 0.95rem;
}
.poster .poster-label {
  margin-top: 0.5rem;
  font-size: 0.9rem; font-weight: 600;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.poster .poster-year { color: var(--text-muted); font-weight: 500; }

/* availability badge */
.avail {
  position: absolute; top: 0.5rem; right: 0.5rem;
  font-size: 0.7rem; font-weight: 800; letter-spacing: 0.04em;
  padding: 0.2rem 0.5rem; border-radius: 999px;
  text-transform: uppercase;
  background: rgba(0,0,0,0.7); color: #fff;
}
.avail.requestable { background: rgba(0,0,0,0.7); color: var(--text-muted); }
.avail.requested, .avail.processing { background: #b5870b; color: #fff; }
.avail.on-plex { background: var(--brand); color: var(--brand-text); }

/* ----------------------------------------------------------------- top10 */
.poster-row.top10 .row-track { align-items: flex-end; gap: 1.6rem; padding-left: 3.5rem; }
.poster.top10 {
  display: flex; align-items: flex-end;
  flex: 0 0 auto; width: auto;
}
.poster.top10 .numeral {
  font-family: var(--font-display);
  font-size: 11rem; line-height: 0.7;
  font-weight: 900;
  color: var(--top10-numeral);
  -webkit-text-stroke: 3px var(--text-muted);
  margin-right: -2.4rem;
  z-index: 1;
  user-select: none;
  font-variant-numeric: tabular-nums;
}
.poster.top10 .poster-art, .poster.top10 .poster-fallback {
  z-index: 2; position: relative;
}

/* ----------------------------------------------------------------- login */
.center-pane {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 2rem;
}
.center-pane .logo-lg { width: 9rem; margin-bottom: 1.75rem; }
.center-pane h1 { font-family: var(--font-display); font-size: 2.25rem; margin: 0 0 0.5rem; }
.center-pane p { color: var(--text-muted); max-width: 30rem; margin: 0 0 2rem; line-height: 1.5; }
.login-status { margin-top: 1.25rem; color: var(--text-muted); min-height: 1.4rem; }
.login-error { color: #ff6b6b; }

/* ----------------------------------------------------------------- setup */
.setup-wrap { max-width: 64rem; margin: 0 auto; padding: 3rem 2rem 4rem; }
.setup-wrap h1 { font-family: var(--font-display); font-size: 2.5rem; text-align: center; margin: 0 0 0.5rem; }
.setup-wrap .sub { text-align: center; color: var(--text-muted); margin: 0 0 2.5rem; }
.mode-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 1.5rem; }
.mode-card {
  text-align: left;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: 1rem;
  padding: 1.75rem;
  transition: transform 0.12s, border-color 0.15s;
  display: flex; flex-direction: column;
}
.mode-card.is-focused, .mode-card:hover { transform: translateY(-4px); border-color: var(--focus-ring); }
.mode-card.selected { border-color: var(--brand); }
.mode-card h2 { font-family: var(--font-display); font-size: 1.5rem; margin: 0 0 0.75rem; }
.mode-card .desc { color: var(--text-muted); line-height: 1.5; flex: 1; margin: 0 0 1.5rem; }
.mode-card .pick { align-self: flex-start; }
.mode-card[aria-disabled="true"] { opacity: 0.6; }
.mode-card .locked-note { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.75rem; }

/* ----------------------------------------------------------------- detail */
.detail {
  position: relative;
  min-height: 100vh;
}
.detail-backdrop {
  position: absolute; inset: 0; height: 70vh;
  background-size: cover; background-position: center;
}
.detail-backdrop::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(11,13,18,0.92), rgba(11,13,18,0.4) 60%, rgba(11,13,18,0.7)),
              linear-gradient(0deg, var(--bg), rgba(11,13,18,0) 55%);
}
.detail-body {
  position: relative; z-index: 2;
  padding: calc(var(--header-h) + 4rem) 2.5rem 4rem;
  display: grid; grid-template-columns: minmax(0, 42rem) 1fr; gap: 3rem;
  max-width: 80rem;
}
.detail-poster { width: 16rem; border-radius: var(--radius); }
.detail-main h1 { font-family: var(--font-display); font-size: clamp(2rem,4vw,3.25rem); margin: 0 0 0.5rem; }
.detail-meta { color: var(--text-muted); font-weight: 600; margin-bottom: 1rem; display: flex; gap: 0.9rem; flex-wrap: wrap; }
.detail-overview { line-height: 1.55; max-width: 42rem; margin-bottom: 1.5rem; }
.detail-cta { display: flex; gap: 0.75rem; margin-bottom: 2rem; flex-wrap: wrap; }
.detail-section-title { font-family: var(--font-display); font-size: 1.2rem; font-weight: 800; margin: 1.5rem 0 0.75rem; }
.cast-row { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 0.5rem; scrollbar-width: none; }
.cast-row::-webkit-scrollbar { display: none; }
.cast-card { flex: 0 0 7rem; text-align: center; }
.cast-card img, .cast-card .cast-fallback {
  width: 7rem; height: 7rem; border-radius: 50%; object-fit: cover;
  background: var(--surface); margin: 0 auto 0.5rem;
  display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-weight: 800; font-size: 1.5rem;
}
.cast-name { font-weight: 700; font-size: 0.9rem; }
.cast-role { color: var(--text-muted); font-size: 0.82rem; }
.toast {
  position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated); color: var(--text);
  padding: 0.9rem 1.5rem; border-radius: 0.6rem;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  z-index: 80; font-weight: 600;
  border-left: 4px solid var(--brand);
  max-width: 90vw;
}
.toast.err { border-left-color: #ff6b6b; }

/* ----------------------------------------------------------------- search */
.search-view { padding: calc(var(--header-h) + 1.5rem) 2.5rem 4rem; }
.search-bar {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--surface); border-radius: 0.6rem;
  padding: 0.85rem 1.25rem; max-width: 48rem; margin: 0 auto 1.5rem;
}
.search-bar input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 1.25rem; font-family: inherit;
}
.search-bar input::placeholder { color: var(--text-muted); }
.search-results-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--poster-w), 1fr));
  gap: 1.5rem 1rem; max-width: 80rem; margin: 0 auto;
}
.search-empty { text-align: center; color: var(--text-muted); margin-top: 3rem; }

/* on-screen keyboard (remote fallback) */
.osk { max-width: 48rem; margin: 0 auto 2rem; display: none; }
.osk.show { display: block; }
.osk-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 0.4rem; }
.osk-key {
  background: var(--surface); border-radius: 0.4rem;
  padding: 0.75rem 0; text-align: center; font-weight: 700; font-size: 1.05rem;
}
.osk-key.wide { grid-column: span 2; }
.osk-key.is-focused { background: var(--brand); color: var(--brand-text); }

/* ----------------------------------------------------------------- settings */
.settings-wrap { max-width: 40rem; margin: 0 auto; padding: calc(var(--header-h) + 2rem) 2rem 4rem; }
.settings-wrap h1 { font-family: var(--font-display); margin-bottom: 1.5rem; }
.settings-section { background: var(--surface); border-radius: 0.8rem; padding: 1.5rem; margin-bottom: 1.5rem; }
.settings-section h2 { margin: 0 0 1rem; font-size: 1.15rem; }
.settings-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.mode-toggle { display: flex; gap: 0.75rem; }
.mode-toggle .btn { flex: 1; }
.mode-toggle .btn.selected { background: var(--brand); color: var(--brand-text); }
.muted { color: var(--text-muted); }

/* ----------------------------------------------------------------- misc */
.skeleton-row { display: flex; gap: var(--row-gap); padding: 0.5rem 2.5rem; }
.skeleton-poster {
  flex: 0 0 var(--poster-w); width: var(--poster-w); height: var(--poster-h);
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface) 25%, var(--bg-elevated) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  .hero .hero-img { transition: none; }
  .focusable.is-focused.poster, .mode-card.is-focused { transform: none; }
  .boot-spinner { animation-duration: 2s; }
}

/* ----------------------------------------------------------------- mobile */
/* Phones (iPhone etc.): shrink the TV-sized layout, single-column detail,
   bigger tap targets, momentum scrolling, safe-area insets. */
@media (max-width: 640px) {
  :root {
    --poster-w: 7.5rem;
    --poster-h: 11.25rem;
    --row-gap: 0.7rem;
    --header-h: 3.4rem;
  }
  .row-track, .cast-row { -webkit-overflow-scrolling: touch; }

  /* header — tighter, fits a phone width, respects the notch */
  .app-header {
    gap: 0.5rem;
    padding: 0 0.9rem;
    padding-left: max(0.9rem, env(safe-area-inset-left));
    padding-right: max(0.9rem, env(safe-area-inset-right));
  }
  .app-header .brand { font-size: 1rem; gap: 0.4rem; }
  .app-header .brand img { height: 1.5rem; }
  .app-header nav { gap: 0.15rem; }
  .app-header nav .navbtn { padding: 0.45rem 0.55rem; font-size: 0.82rem; }
  .app-header .avatar { height: 1.7rem; width: 1.7rem; }
  /* keep the mode toggle compact (icon only would be too terse; allow wrap off) */
  .app-header nav .mode-toggle { white-space: nowrap; }

  /* hero — shorter, full-width readable content */
  .hero { height: 58vh; min-height: 19rem; }
  .hero .hero-content { left: 1rem; right: 1rem; bottom: 1.4rem; max-width: none; }
  .hero .hero-title { font-size: clamp(1.6rem, 8vw, 2.4rem); }
  .hero .hero-overview { -webkit-line-clamp: 2; font-size: 0.9rem; }
  .hero .hero-cta { gap: 0.5rem; }
  .hero .hero-cta .btn { padding: 0.65rem 1rem; font-size: 0.9rem; }

  /* rows — tighter side padding, smaller titles */
  .rows { padding: 0 0 3rem; }
  .poster-row { margin: 1.4rem 0; }
  .poster-row .row-title { font-size: 1.1rem; margin: 0 0 0.6rem 1rem; }
  .row-track { padding: 0.4rem 1rem; }
  .skeleton-row { padding: 0.4rem 1rem; }
  .poster .poster-label { font-size: 0.78rem; }

  /* top10 numerals — scale down so a poster + numeral fit the screen */
  .poster-row.top10 .row-track { gap: 0.9rem; padding-left: 1.8rem; }
  .poster.top10 .numeral {
    font-size: 6rem; -webkit-text-stroke: 2px var(--text-muted); margin-right: -1.3rem;
  }

  /* detail — single column */
  .detail-backdrop { height: 50vh; }
  .detail-body {
    grid-template-columns: 1fr; gap: 1.25rem;
    padding: calc(var(--header-h) + 1.25rem) 1rem 3rem;
  }
  .detail-poster { width: 8.5rem; }
  .detail-cta { gap: 0.6rem; }
  .detail-cta .btn { flex: 1 1 auto; justify-content: center; min-height: 44px; }
  .cast-card { flex: 0 0 5rem; }
  .cast-card img, .cast-card .cast-fallback { width: 5rem; height: 5rem; }

  /* search */
  .search-view { padding: calc(var(--header-h) + 1rem) 1rem 3rem; }
  .search-bar { padding: 0.7rem 1rem; }
  .search-bar input { font-size: 1.05rem; }
  .search-results-grid { gap: 1rem 0.6rem; }
  .osk { display: none !important; } /* no on-screen remote keyboard on touch */

  /* setup / settings / login */
  .setup-wrap { padding: 2rem 1rem 3rem; }
  .setup-wrap h1 { font-size: 1.9rem; }
  .mode-cards { grid-template-columns: 1fr; gap: 1rem; }
  .settings-wrap { padding: calc(var(--header-h) + 1.5rem) 1rem 3rem; }
  .center-pane { padding: 1.5rem; }
  .center-pane .logo-lg { width: 7rem; }
  .center-pane h1 { font-size: 1.8rem; }

  /* comfortable default tap target for primary actions */
  .btn { min-height: 44px; }
}
