/* ==========================================================================
   Popcorn — page composition
   Layout that is specific to a screen lives here. Reusable pieces live in
   components.css.
   ========================================================================== */

/* ── App shell ─────────────────────────────────────────────────────────── */

.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--s5);
  padding-inline: var(--gutter);
  padding-top: env(safe-area-inset-top);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
  border-bottom: 1px solid transparent;
}
/* Over a hero the header floats; once you scroll it becomes a real surface. */
.app-header.is-solid {
  background: rgba(8, 8, 10, .82);
  backdrop-filter: blur(18px) saturate(140%);
  border-bottom-color: var(--line);
}
/* Theatre marquee: a row of warm bulbs along the bottom edge. */
.app-header.is-solid::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 3px;
  background: radial-gradient(circle at 50% 50%, var(--accent) 0 1px, transparent 1.6px) 0 0 / 14px 3px repeat-x;
  opacity: .55;
  pointer-events: none;
}
.app-header.is-over-hero:not(.is-solid) {
  background: linear-gradient(to bottom, rgba(0,0,0,.6), transparent);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  flex: 0 0 auto;
  font-weight: 800;
  font-size: 1.0625rem;
  letter-spacing: -.045em;
  color: var(--text);
}
.brand-mark {
  width: 34px; height: 34px;
  display: block;
  transition: transform var(--dur) var(--ease-out);
}
.brand:hover .brand-mark { transform: rotate(-8deg) translateY(-1px); }

.nav {
  display: flex;
  align-items: center;
  gap: var(--s1);
  flex: 1;
  min-width: 0;
}
.nav a {
  position: relative;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-sm);
  color: var(--text-dim);
  font-size: var(--t-sm);
  font-weight: 600;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.nav a:hover { color: var(--text); background: rgba(255, 255, 255, .05); }
.nav a[aria-current="page"] { color: var(--text); }
.nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: var(--s3); right: var(--s3);
  bottom: -2px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.header-actions { display: flex; align-items: center; gap: var(--s2); margin-left: auto; }

/* Round icon button used in the header and on the player. */
.icon-btn {
  width: 38px; height: 38px;
  display: grid;
  place-content: center;
  border-radius: var(--r-pill);
  color: var(--text-dim);
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, .08); }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .avatar { width: 30px; height: 30px; font-size: 11px; }

/* Pages without a hero need to clear the fixed header. */
.page { padding-top: calc(var(--header-h) + var(--s6) + env(safe-area-inset-top)); padding-bottom: var(--s9); }
.page-head { margin-bottom: var(--s6); }
.page-head h1 { font-size: var(--t-h1); font-weight: 800; letter-spacing: -.03em; }
.page-head p { margin-top: var(--s2); color: var(--text-dim); max-width: 60ch; }

/* ── Mobile tab bar ────────────────────────────────────────────────────── */

.tabbar { display: none; }

@media (max-width: 860px) {
  :root { --header-h: 58px; }
  .nav { display: none; }
  .page { padding-bottom: calc(var(--tabbar-h) + var(--s8) + env(safe-area-inset-bottom)); }

  .tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 100;
    display: flex;
    align-items: stretch;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(10, 10, 12, .94);
    backdrop-filter: blur(20px) saturate(140%);
    border-top: 1px solid var(--line);
  }
  .tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-mute);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .01em;
    transition: color var(--dur-fast) var(--ease);
  }
  .tabbar a svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar a[aria-current="page"] { color: var(--accent); }
  .tabbar a:active { transform: scale(.94); }
  /* Badge for running downloads on the Downloads tab. */
  .tabbar a .tab-badge {
    position: absolute;
    transform: translate(14px, -14px);
    min-width: 16px;
    height: 16px;
    padding-inline: 4px;
    display: grid;
    place-content: center;
    border-radius: var(--r-pill);
    background: var(--accent);
    color: var(--accent-ink);
    font-size: 9px;
    font-weight: 800;
  }
  .tabbar a { position: relative; }
}

/* ── Hero ──────────────────────────────────────────────────────────────── */

.hero {
  position: relative;
  min-height: min(78vh, 680px);
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  margin-bottom: var(--s6);
}
.hero-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.hero-backdrop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 22%;
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease);
}
.hero-backdrop img.is-loaded { opacity: 1; }
/* Three gradients: legibility for the copy, a vignette, and a base fade so the
   hero dissolves into the rows below instead of ending on a hard line. */
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(to right, rgba(8,8,10,.94) 0%, rgba(8,8,10,.72) 38%, rgba(8,8,10,.15) 68%, transparent 100%),
    linear-gradient(to top, var(--bg) 2%, rgba(8,8,10,.55) 26%, transparent 62%),
    radial-gradient(120% 90% at 20% 80%, transparent 40%, rgba(0,0,0,.5) 100%);
}
.hero-inner {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: var(--max-w);
  margin-inline: auto;
  padding: 0 var(--gutter) var(--s8);
}
/* Title logos are wildly different shapes — a wordmark can be 10:1 — so cap
   width and height together and let the image scale to fit both. */
.hero-logo {
  width: auto;
  height: auto;
  max-height: clamp(48px, 6vw, 96px);
  max-width: min(78%, 520px);
  margin-bottom: var(--s4);
}
.hero-title { font-size: var(--t-display); font-weight: 800; letter-spacing: -.04em; line-height: 1; max-width: 18ch; }
.hero-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-top: var(--s4);
  color: var(--text-dim);
  font-size: var(--t-sm);
}
.hero-overview {
  margin-top: var(--s4);
  max-width: 56ch;
  color: #cfcfd4;
  font-size: var(--t-body);
  line-height: 1.65;
}
.hero-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-top: var(--s5);
}
.hero-progress {
  margin-top: var(--s4);
  max-width: 280px;
}
.hero-progress .progress { height: 4px; }
.hero-progress-label { margin-top: var(--s2); color: var(--text-mute); font-size: var(--t-xs); }

.hero-dots {
  position: absolute;
  right: var(--gutter);
  bottom: var(--s8);
  z-index: 3;
  display: flex;
  gap: var(--s2);
}
.hero-dots button {
  width: 24px; height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .25);
  transition: background var(--dur) var(--ease), width var(--dur) var(--ease);
}
.hero-dots button[aria-current="true"] { background: var(--accent); width: 34px; }

@media (max-width: 860px) {
  .hero { min-height: 0; padding-top: calc(var(--header-h) + var(--s6)); align-items: flex-end; }
  .hero-backdrop img { object-position: center 18%; }
  .hero::after {
    background:
      linear-gradient(to top, var(--bg) 3%, rgba(8,8,10,.82) 30%, rgba(8,8,10,.35) 70%, rgba(8,8,10,.5) 100%);
  }
  .hero-inner { padding-bottom: var(--s6); }
  .hero-overview { font-size: var(--t-sm); -webkit-line-clamp: 3; }
  .hero-actions .btn { flex: 1 1 auto; }
  .hero-actions .btn-icon { flex: 0 0 auto; }
  .hero-dots { display: none; }
}

/* ── Browse (Movies / Shows) ───────────────────────────────────────────── */

.browse-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-bottom: var(--s5);
}
.browse-toolbar .spacer { flex: 1; }
.browse-count { color: var(--text-mute); font-size: var(--t-sm); }

.genre-strip {
  display: flex;
  gap: var(--s2);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: var(--s2);
  margin-bottom: var(--s5);
}
.genre-strip::-webkit-scrollbar { display: none; }
.genre-chip {
  flex: 0 0 auto;
  padding: 7px var(--s4);
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface-1);
  color: var(--text-dim);
  font-size: var(--t-sm);
  font-weight: 600;
  transition: all var(--dur-fast) var(--ease);
}
.genre-chip:hover { color: var(--text); border-color: var(--line-strong); }
.genre-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ── Detail pages (movie / show) ───────────────────────────────────────── */

.detail-hero {
  position: relative;
  min-height: min(72vh, 620px);
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.detail-hero-backdrop { position: absolute; inset: 0; z-index: 0; }
.detail-hero-backdrop img {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center 20%;
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease);
}
.detail-hero-backdrop img.is-loaded { opacity: 1; }
/* No backdrop art: the poster carries the page instead. */
.detail-hero-backdrop.is-empty {
  background:
    radial-gradient(circle at 25% 20%, rgba(255, 200, 61, .06), transparent 50%),
    linear-gradient(160deg, var(--surface-2), var(--bg) 70%);
}
.detail-hero-content {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: var(--max-w);
  margin-inline: auto;
  padding: var(--s9) var(--gutter) var(--s7);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--s7);
  align-items: end;
}
.detail-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(to top, var(--bg) 1%, rgba(8,8,10,.72) 28%, rgba(8,8,10,.2) 62%, rgba(8,8,10,.45) 100%),
    linear-gradient(to right, rgba(8,8,10,.8) 0%, transparent 55%);
}

.detail-poster {
  width: clamp(150px, 17vw, 230px);
  aspect-ratio: 2 / 3;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-3);
}
.detail-poster img { width: 100%; height: 100%; object-fit: cover; }

.detail-info { min-width: 0; padding-bottom: var(--s2); }
.detail-title { font-size: var(--t-display); font-weight: 800; letter-spacing: -.04em; line-height: 1.02; }
.detail-tagline { margin-top: var(--s3); color: var(--text-dim); font-style: italic; font-size: var(--t-body); }
.detail-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-top: var(--s4);
  color: var(--text-dim);
  font-size: var(--t-sm);
}
.detail-overview {
  margin-top: var(--s4);
  max-width: 68ch;
  color: #cbcbd1;
  line-height: 1.7;
}
.detail-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-top: var(--s5);
}

.detail-body {
  width: 100%;
  max-width: var(--max-w);
  margin-inline: auto;
  padding-inline: var(--gutter);
  padding-bottom: var(--s9);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: var(--s8);
  align-items: start;
}
.detail-main { min-width: 0; }
.detail-side { display: flex; flex-direction: column; gap: var(--s6); }

.detail-block { margin-bottom: var(--s7); }
.detail-block:last-child { margin-bottom: 0; }
.detail-block h2 {
  font-size: var(--t-xs);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--text-mute);
  margin-bottom: var(--s4);
}

/* Definition list for technical/media facts. */
.facts { display: flex; flex-direction: column; gap: var(--s3); }
.fact { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: var(--s3); align-items: baseline; }
.fact dt { color: var(--text-mute); font-size: var(--t-xs); }
.fact dd { margin: 0; font-size: var(--t-sm); color: var(--text-dim); }
.fact dd strong { color: var(--text); font-weight: 600; }

/* Cast */
.cast-strip {
  display: flex;
  gap: var(--s4);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: var(--s2);
}
.cast-strip::-webkit-scrollbar { display: none; }
.cast-member { flex: 0 0 auto; width: 92px; text-align: center; }
.cast-member img, .cast-member .cast-fallback {
  width: 84px; height: 84px;
  margin-inline: auto;
  border-radius: var(--r-pill);
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.cast-member .cast-fallback { display: grid; place-content: center; color: var(--text-mute); font-weight: 700; font-size: var(--t-body); }
.cast-member strong { display: block; margin-top: var(--s3); font-size: var(--t-xs); font-weight: 600; line-height: 1.35; }
.cast-member small { display: block; margin-top: 2px; color: var(--text-mute); font-size: 10px; line-height: 1.3; }

@media (max-width: 1024px) {
  .detail-body { grid-template-columns: 1fr; gap: var(--s7); }
  .detail-side { order: 2; }
}
@media (max-width: 860px) {
  /* Clear the mobile tab bar below the last shelf. */
  .home-rows { padding-bottom: calc(var(--tabbar-h) + var(--s6)); }
  .detail-body { padding-bottom: var(--s7); }
  #detail-similar { padding-bottom: calc(var(--tabbar-h) + var(--s6)); }
}
@media (max-width: 720px) {
  .detail-hero { min-height: 0; }
  .detail-hero-content {
    grid-template-columns: 1fr;
    gap: var(--s5);
    padding: calc(var(--header-h) + var(--s8)) var(--gutter) var(--s5);
  }
  .detail-poster { width: 118px; box-shadow: var(--shadow-2); }
  .detail-overview { -webkit-line-clamp: 5; font-size: var(--t-sm); }
  .detail-actions .btn { flex: 1 1 auto; }
  .fact { grid-template-columns: 1fr; gap: 2px; }
}

/* ── Search ────────────────────────────────────────────────────────────── */

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 0 var(--s4);
  height: 60px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.search-bar:focus-within { border-color: var(--accent); background: var(--surface-2); }
.search-bar svg { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: var(--text-mute); stroke-width: 1.9; stroke-linecap: round; }
.search-bar input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 1.0625rem;
  font-weight: 500;
}
.search-bar input::placeholder { color: var(--text-mute); }
/* The bar itself shows focus; the input's own ring and the browser's native
   clear button both duplicate the ones we draw. */
.search-bar input:focus-visible { outline: none; }
.search-bar input::-webkit-search-cancel-button,
.search-bar input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.search-bar kbd {
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  padding: 3px 7px;
  color: var(--text-mute);
  font-family: var(--font-mono);
  font-size: var(--t-micro);
}

.recent-searches { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
.recent-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 6px var(--s3);
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface-1);
  color: var(--text-dim);
  font-size: var(--t-sm);
  transition: all var(--dur-fast) var(--ease);
}
.recent-chip:hover { color: var(--text); border-color: var(--line-strong); }
.recent-chip svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; }

.result-group { margin-top: var(--s7); }
.result-group-head {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--s5);
}
.result-group-head h2 { font-size: var(--t-h2); font-weight: 700; letter-spacing: -.022em; }
.result-group-head .count { color: var(--text-mute); font-size: var(--t-sm); }
.result-group-head .spacer { flex: 1; }

/* Titles that can be added: decide first, details on demand. */
.add-list { display: flex; flex-direction: column; gap: var(--s3); }
.add-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: var(--s4);
  align-items: center;
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-1);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.add-row:hover { border-color: var(--line-strong); background: var(--surface-2); }
.add-row-art {
  position: relative;   /* contains any artwork fallback */
  width: 72px;
  aspect-ratio: 2 / 3;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.add-row-art img { width: 100%; height: 100%; object-fit: cover; }
.add-row-body { min-width: 0; }
.add-row-title { font-size: var(--t-body); font-weight: 700; letter-spacing: -.015em; }
.add-row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-top: var(--s2); }
.add-row-facts { margin-top: var(--s2); color: var(--text-mute); font-size: var(--t-xs); }
.add-row-actions { display: flex; align-items: center; gap: var(--s2); }

@media (max-width: 640px) {
  .add-row { grid-template-columns: 56px minmax(0, 1fr); gap: var(--s3); }
  .add-row-art { width: 56px; }
  .add-row-actions { grid-column: 1 / -1; justify-content: stretch; }
  .add-row-actions .btn { flex: 1; }
  .search-bar { height: 54px; }
}

/* ── Release / quality picker ──────────────────────────────────────────── */

.release-list { display: flex; flex-direction: column; gap: var(--s2); }
.release-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--s3);
  align-items: center;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-1);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.release-option:hover { border-color: var(--line-strong); }
.release-option[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.release-radio {
  width: 18px; height: 18px;
  flex: 0 0 auto;
  border-radius: var(--r-pill);
  border: 1.5px solid var(--line-strong);
  display: grid;
  place-content: center;
}
.release-option[aria-checked="true"] .release-radio { border-color: var(--accent); }
.release-option[aria-checked="true"] .release-radio::after {
  content: "";
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
}
.release-main { min-width: 0; }
.release-title { font-size: var(--t-sm); font-weight: 600; }
.release-sub { margin-top: 2px; color: var(--text-mute); font-size: var(--t-xs); display: flex; flex-wrap: wrap; gap: var(--s2); }
.release-side { text-align: right; color: var(--text-dim); font-size: var(--t-xs); white-space: nowrap; }
.release-side strong { display: block; color: var(--text); font-size: var(--t-sm); font-weight: 600; }

.quality-group + .quality-group { margin-top: var(--s5); }
.quality-group h3 {
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  text-transform: uppercase;
  letter-spacing: .13em;
  color: var(--text-mute);
  margin-bottom: var(--s3);
}

/* ── Downloads ─────────────────────────────────────────────────────────── */

.downloads-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s4);
  flex-wrap: wrap;
  margin-bottom: var(--s5);
}
.downloads-toolbar .spacer { flex: 1; }

.download-list { display: flex; flex-direction: column; gap: var(--s3); }
.download {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: var(--s4);
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-1);
}
.download-art {
  position: relative;   /* contains the artwork fallback */
  width: 64px;
  aspect-ratio: 2 / 3;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.download-art img { width: 100%; height: 100%; object-fit: cover; }
.download-body { min-width: 0; display: flex; flex-direction: column; gap: var(--s3); }
.download-head { display: flex; align-items: flex-start; gap: var(--s3); }
.download-head .download-titles { flex: 1; min-width: 0; }
.download-head h3 { font-size: var(--t-body); font-weight: 700; letter-spacing: -.015em; }
.download-head p { margin-top: 3px; color: var(--text-dim); font-size: var(--t-xs); }
.download-actions { display: flex; align-items: center; gap: var(--s2); flex: 0 0 auto; }

.download-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s4);
  color: var(--text-mute);
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.download-stats strong { color: var(--text); font-size: var(--t-xs); }
.download-note { color: var(--text-mute); font-size: var(--t-xs); }

/* A row of stages reads clearer than one opaque status word. */
.stage-track { display: flex; align-items: center; gap: 3px; }
.stage-track i {
  height: 3px;
  flex: 1;
  border-radius: 2px;
  background: rgba(255, 255, 255, .12);
}
.stage-track i.is-done { background: var(--accent); }
.stage-track i.is-current { background: var(--accent); animation: pulse-stage 1.6s var(--ease) infinite; }
@keyframes pulse-stage { 50% { opacity: .4; } }
.stage-track.is-failed i.is-current { background: var(--danger); animation: none; }

@media (max-width: 640px) {
  .download { grid-template-columns: 52px minmax(0, 1fr); gap: var(--s3); padding: var(--s3); }
  .download-art { width: 52px; }
  .download-head { flex-direction: column; }
  .download-actions { width: 100%; }
  .download-actions .btn { flex: 1; }
}

/* ── Jellyfin fallback (/watch) ────────────────────────────────────────── */

.legacy-page { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.legacy-bar {
  display: flex;
  align-items: center;
  gap: var(--s4);
  height: var(--header-h);
  flex: 0 0 auto;
  padding-inline: var(--s4);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.legacy-bar > div { flex: 1; min-width: 0; }
.legacy-bar strong { display: block; font-size: var(--t-sm); font-weight: 700; }
.legacy-bar small { display: block; color: var(--text-mute); font-size: var(--t-xs); }
.legacy-shell { flex: 1; min-height: 0; display: flex; }
.legacy-shell iframe { width: 100%; height: 100%; border: 0; background: #101010; }
.legacy-shell > .state { margin: auto; }

/* ── Sign-in ───────────────────────────────────────────────────────────── */

.auth-page { min-height: 100vh; }
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(380px, .9fr);
}
.auth-pitch {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(28px, 5vw, 64px);
  overflow: hidden;
  background:
    radial-gradient(110% 80% at 12% 88%, rgba(255, 200, 61, .07), transparent 55%),
    linear-gradient(160deg, #101014, var(--bg) 65%);
  border-right: 1px solid var(--line);
}
.auth-pitch::after {
  content: "";
  position: absolute;
  right: -18%; bottom: -32%;
  width: min(560px, 70vw);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(255, 200, 61, .12);
  box-shadow: 0 0 0 60px rgba(255, 200, 61, .014), 0 0 0 130px rgba(255, 200, 61, .009);
  pointer-events: none;
}
.auth-copy { max-width: 16ch; }
.auth-copy h1 { margin-bottom: var(--s5); }
.auth-copy p { color: var(--text-dim); font-size: var(--t-body); max-width: 34ch; line-height: 1.7; }
.auth-form { display: grid; place-items: center; padding: clamp(28px, 6vw, 72px); }
.auth-form form { width: min(100%, 400px); }
.auth-form p { margin-top: var(--s2); }
.auth-error {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  margin-top: var(--s5);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-sm);
  border: 1px solid rgba(255, 90, 77, .3);
  border-left-width: 3px;
  background: var(--danger-soft);
  color: #ffb3aa;
  font-size: var(--t-sm);
}
.auth-error svg { color: var(--danger); flex: 0 0 auto; margin-top: 1px; }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-pitch {
    min-height: 40vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    gap: var(--s6);
  }
  .auth-copy { max-width: none; }
  .auth-copy h1 { font-size: clamp(2rem, 9vw, 2.75rem); }
  .auth-form { padding-block: var(--s8); }
}

/* ── Settings ──────────────────────────────────────────────────────────── */

.settings-layout {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  gap: var(--s8);
  align-items: start;
}
.settings-nav {
  position: sticky;
  top: calc(var(--header-h) + var(--s5));
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings-nav a {
  padding: var(--s3);
  border-radius: var(--r-sm);
  color: var(--text-dim);
  font-size: var(--t-sm);
  font-weight: 600;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.settings-nav a:hover { background: rgba(255, 255, 255, .05); color: var(--text); }
.settings-nav a[aria-current="true"] { background: rgba(255, 255, 255, .08); color: var(--text); }
.settings-nav .settings-nav-group {
  margin-top: var(--s5);
  padding: 0 var(--s3) var(--s2);
  color: var(--text-mute);
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  text-transform: uppercase;
  letter-spacing: .13em;
}

.settings-content { min-width: 0; display: flex; flex-direction: column; gap: var(--s8); }
.settings-section { scroll-margin-top: calc(var(--header-h) + var(--s5)); }
.settings-section > header { margin-bottom: var(--s4); }
.settings-section > header h2 { font-size: var(--t-h2); font-weight: 700; letter-spacing: -.022em; }
.settings-section > header p { margin-top: var(--s2); color: var(--text-dim); font-size: var(--t-sm); max-width: 60ch; }

.settings-rows {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-1);
  overflow: hidden;
}
.settings-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 300px);
  gap: var(--s5);
  align-items: center;
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
}
.settings-row:last-child { border-bottom: 0; }
.settings-row > .settings-label strong { display: block; font-size: var(--t-sm); font-weight: 600; }
.settings-row > .settings-label small { display: block; margin-top: 3px; color: var(--text-mute); font-size: var(--t-xs); line-height: 1.5; }
.settings-row .settings-control { display: flex; flex-direction: column; gap: var(--s2); }
.settings-row .settings-control.is-inline { flex-direction: row; align-items: center; gap: var(--s3); }
.settings-row.is-stacked { grid-template-columns: 1fr; }

@media (max-width: 900px) {
  .settings-layout { grid-template-columns: 1fr; gap: var(--s6); }
  .settings-nav {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: var(--s2);
    border-bottom: 1px solid var(--line);
  }
  .settings-nav::-webkit-scrollbar { display: none; }
  .settings-nav a { white-space: nowrap; }
  .settings-nav .settings-nav-group { display: none; }
  .settings-row { grid-template-columns: 1fr; gap: var(--s3); }
}

/* Library maintenance list */
.maintenance-list { max-height: 460px; overflow-y: auto; }
.maintenance-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: var(--s3);
  align-items: center;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
}
.maintenance-item:last-child { border-bottom: 0; }
.maintenance-item img, .maintenance-item .maintenance-art {
  width: 44px; height: 44px;
  border-radius: var(--r-xs);
  object-fit: cover;
  background: var(--surface-2);
  display: grid;
  place-content: center;
  color: var(--text-mute);
  font-size: var(--t-micro);
}
.maintenance-item strong { display: block; font-size: var(--t-sm); font-weight: 600; }
.maintenance-item small { display: block; margin-top: 2px; color: var(--text-mute); font-size: var(--t-xs); }

.proposal {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: var(--s4);
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-1);
}
.proposal + .proposal { margin-top: var(--s3); }
.proposal-art { width: 56px; aspect-ratio: 2/3; border-radius: var(--r-xs); object-fit: cover; background: var(--surface-2); }
.proposal-change { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-top: var(--s2); font-size: var(--t-xs); }
.proposal-change .from { color: var(--text-mute); text-decoration: line-through; }
.proposal-change .to { color: var(--accent); font-weight: 600; }
.proposal-overview { margin-top: var(--s2); color: var(--text-dim); font-size: var(--t-xs); line-height: 1.55; }

/* ── Episode list ──────────────────────────────────────────────────────── */

.season-tabs { margin-bottom: var(--s5); }
.episode-list { display: flex; flex-direction: column; gap: var(--s2); }
.episode {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr) auto;
  gap: var(--s4);
  align-items: center;
  padding: var(--s3);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  text-align: left;
  width: 100%;
}
.episode:hover { background: var(--surface-1); border-color: var(--line); }
.episode-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.episode-thumb img { width: 100%; height: 100%; object-fit: cover; }
.episode-thumb .episode-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  background: rgba(0, 0, 0, .4);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.episode:hover .episode-play { opacity: 1; }
.episode-play span {
  width: 40px; height: 40px;
  display: grid;
  place-content: center;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-ink);
}
.episode-play svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.episode-body { min-width: 0; }
.episode-head { display: flex; align-items: baseline; gap: var(--s3); }
.episode-num { color: var(--text-mute); font-family: var(--font-mono); font-size: var(--t-xs); flex: 0 0 auto; }
.episode-title { font-size: var(--t-sm); font-weight: 600; }
.episode-desc { margin-top: var(--s2); color: var(--text-dim); font-size: var(--t-xs); line-height: 1.6; }
.episode-meta { margin-top: var(--s2); display: flex; align-items: center; gap: var(--s3); color: var(--text-mute); font-size: var(--t-xs); }
.episode-progress { margin-top: var(--s3); max-width: 220px; }
.episode-progress .progress { height: 3px; }
.episode-side { display: flex; align-items: center; gap: var(--s2); }
.episode.is-current { background: var(--surface-1); border-color: rgba(255, 200, 61, .22); }

@media (max-width: 720px) {
  .episode { grid-template-columns: 116px minmax(0, 1fr); gap: var(--s3); padding: var(--s2); }
  .episode-side { grid-column: 1 / -1; justify-content: flex-end; }
  .episode-desc { -webkit-line-clamp: 2; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
}

/* ── AI clips ──────────────────────────────────────────────────────────── */

.clips-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); }
.clips-head h2 { margin-bottom: var(--s2); }
.clips-blurb { color: var(--text-mute); font-size: var(--t-xs); }

.clips-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4);
  margin-bottom: var(--s5);
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.clips-status-main { display: flex; align-items: center; gap: var(--s3); min-width: 0; flex: 1 1 320px; }
.clips-status-text { color: var(--text-dim); font-size: var(--t-sm); min-width: 0; }
.clips-actions { display: flex; align-items: center; gap: var(--s2); }
.clips-actions .btn svg { width: 16px; height: 16px; }
.clips-progress { flex: 1 1 100%; height: 4px; }
.clips-reason { flex: 1 1 100%; margin: 0; color: var(--text-mute); font-size: var(--t-xs); line-height: 1.6; }
.clips-notes { flex: 1 1 100%; font-size: var(--t-xs); color: var(--text-mute); }
.clips-notes summary { cursor: pointer; color: var(--text-dim); }
.clips-notes ul { margin: var(--s2) 0 0; padding-left: var(--s4); display: grid; gap: 4px; }

.clip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--s5);
}
.clip-card {
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.clip-card:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.clip-art { position: relative; aspect-ratio: 16 / 9; background: var(--surface-2); }
.clip-art img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity var(--dur-slow) var(--ease);
}
.clip-art img.is-loaded { opacity: 1; }
.clip-art .card-art-fallback { display: grid; place-items: center; height: 100%; color: var(--text-mute); }
.clip-length {
  position: absolute; right: var(--s2); bottom: var(--s2);
  padding: 2px 7px;
  border-radius: var(--r-xs);
  background: rgba(8, 8, 10, .78);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--t-micro);
}
.clip-play {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  border: 0; cursor: pointer;
  background: linear-gradient(180deg, rgba(8, 8, 10, .1), rgba(8, 8, 10, .45));
  color: #fff; opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.clip-play span, .clip-play svg { display: grid; place-items: center; }
.clip-play svg {
  width: 44px; height: 44px; padding: 11px;
  border-radius: var(--r-pill);
  background: var(--accent); color: var(--accent-ink);
  fill: currentColor; stroke: none;
}
.clip-card:hover .clip-play, .clip-card:focus-within .clip-play { opacity: 1; }

.clip-body { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s4); }
.clip-time { font-family: var(--font-mono); font-size: var(--t-micro); color: var(--text-mute); }
.clip-title { font-size: var(--t-h3); font-weight: 700; line-height: 1.3; }
.clip-hook { color: var(--text-dim); font-size: var(--t-sm); font-style: italic; line-height: 1.5; }
.clip-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.clip-score {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--text-mute); font-size: var(--t-micro); font-family: var(--font-mono);
}
.clip-score svg { fill: var(--accent); stroke: none; }
.clip-why { font-size: var(--t-xs); color: var(--text-mute); }
.clip-why summary { cursor: pointer; color: var(--text-dim); }
.clip-why p { margin-top: var(--s2); line-height: 1.6; }
.clip-actions { display: flex; gap: var(--s2); margin-top: var(--s2); }
.clips-source { grid-column: 1 / -1; color: var(--text-mute); font-size: var(--t-micro); }

.clip-modal video { width: 100%; border-radius: var(--r-sm); background: #000; display: block; }
.clip-modal-meta { margin-top: var(--s3); font-family: var(--font-mono); font-size: var(--t-xs); color: var(--text-mute); }
.clip-modal-hook { font-family: var(--font); font-style: italic; color: var(--text-dim); }

@media (max-width: 720px) {
  .clip-grid { grid-template-columns: 1fr; gap: var(--s4); }
  .clips-status { padding: var(--s3); }
  .clips-actions { flex: 1 1 100%; }
  .clips-actions .btn { flex: 1 1 auto; }
}
.clips-detail {
  flex: 1 1 100%;
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  color: var(--text-mute);
  word-break: break-word;
}

/* ── Re-matching a title ───────────────────────────────────────────────── */

.match-panel { display: grid; gap: var(--s4); }
.match-search { display: flex; gap: var(--s2); }
.match-search .input { flex: 1 1 auto; }
.match-list { display: grid; gap: var(--s3); max-height: 52vh; overflow-y: auto; }
.match-option {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: var(--s3);
  align-items: center;
  padding: var(--s3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.match-option img, .match-fallback {
  width: 52px; height: 78px; object-fit: cover; border-radius: var(--r-xs); background: var(--surface-3);
}
.match-fallback { display: grid; place-items: center; color: var(--text-mute); }
.match-body { min-width: 0; }
.match-body p { margin-top: var(--s1); color: var(--text-dim); font-size: var(--t-xs); line-height: 1.55; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
