:root {
  --bg: #0b0d12;
  --bg-elev: #161922;
  --bg-elev-2: #232634;
  --text: #e8eaf0;
  --text-muted: #8b909e;
  --accent: #f59e0b;
  --good: #4ade80;
  --bad: #f87171;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
body.trailer-open { overflow: hidden; }

.topbar {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 12px 18px;
  background: var(--bg-elev);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title {
  font-size: 18px; font-weight: 700; letter-spacing: 0.5px; flex: 0 0 auto;
  /* It's a <button> now — click to go home (Discover). Reset the
   * native button chrome so it looks like the old <h1>. */
  background: none; border: none; color: var(--text);
  cursor: pointer; padding: 0;
  font-family: inherit;
}
.topbar-title:hover { color: var(--accent); }
.topbar-nav { display: flex; gap: 4px; flex: 0 0 auto; }
.topbar-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.account-control {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-muted); font-size: 12px; font-weight: 700;
}
.account-control[hidden] { display: none; }
#account-user-button { display: flex; align-items: center; min-width: 32px; min-height: 32px; }

/* Clerk renders the account popover in a document-level portal, so its
 * neutral action color can miss the dark theme passed to the mount point. */
.cl-userButtonPopoverActionButton {
  color: #f3f4f6 !important;
}
.cl-userButtonPopoverActionButtonIcon {
  color: #cbd5e1 !important;
}
.cl-userButtonPopoverActionButton:hover,
.cl-userButtonPopoverActionButton:focus-visible {
  color: #fff !important;
  background: rgba(255, 255, 255, .08) !important;
}

.account-gate {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  overflow: auto;
  background:
    radial-gradient(circle at 50% 18%, rgba(245, 158, 11, .14), transparent 34rem),
    rgba(11, 13, 18, .98);
}
.account-gate[hidden] { display: none; }
.account-gate-panel {
  width: min(100%, 470px); padding: 28px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--bg-elev-2));
  border-radius: 18px; background: var(--bg-elev);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .42);
}
.account-gate-kicker {
  margin-bottom: 4px; color: var(--accent); font-size: 12px;
  font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
}
.account-gate-panel h1 { margin: 0 0 6px; font-size: clamp(1.65rem, 6vw, 2.15rem); }
.account-gate-panel > p:not(.account-gate-kicker) { color: var(--text-muted); }
.account-signin-mount { display: grid; justify-content: center; margin-top: 20px; min-height: 80px; }
/* The Clerk tenant is shared with Homestead. Keep its tenant-level product
 * name out of this app and use the Streaming Aggregator heading above. */
.account-signin-mount .cl-header {
  display: none !important;
}
.account-retry {
  align-self: start; justify-self: center; padding: 10px 20px;
  border: 0; border-radius: 999px; background: var(--accent); color: #17120a;
  font: inherit; font-weight: 800; cursor: pointer;
}
body.account-locked { overflow: hidden; }
body.account-locked > .topbar, body.account-locked > .search-row, body.account-locked > .app-layout { visibility: hidden; }
.settings-dialog.lp-ui {
  --lp-bg:var(--bg); --lp-card:var(--bg-elev); --lp-fg:var(--text);
  --lp-muted:#b6bbc7; --lp-line:#6b7280; --lp-accent:var(--accent);
  --lp-on-accent:#1b1305; --lp-focus:#fbbf24; --lp-success:var(--good); --lp-danger:var(--bad);
  box-sizing:border-box; margin:auto; width:min(560px,calc(100% - 24px));
  max-height:calc(100dvh - 24px); overflow:auto;
  border:1px solid var(--lp-line); border-radius:var(--lp-radius);
  padding:var(--lp-space); color-scheme:dark;
}
.settings-dialog::backdrop { background:rgb(0 0 0 / .7); }
.settings-dialog header { display:flex; flex-wrap:wrap; align-items:flex-start; justify-content:space-between; gap:12px; }
.settings-dialog h2 { margin:0; min-width:0; flex:1 1 160px; }
.settings-dialog #settings-close { flex:0 0 auto; overflow-wrap:normal; }
.settings-dialog section { margin-top:var(--lp-space); }
.settings-dialog section h3 { margin-bottom:12px; }
.settings-dialog p { line-height:1.5; overflow-wrap:anywhere; }
.settings-dialog p + p { margin-top:10px; }
.settings-dialog details { margin-top:12px; }
.settings-dialog summary { cursor:pointer; padding:10px 0; color:var(--lp-accent); }
.settings-dialog [role=status]:not(:empty) { margin-top:12px; }
.settings-dialog #settings-preview-file { max-width:100%; margin:12px 0; }
.settings-dialog #settings-preview-rows { white-space:pre-wrap; overflow-wrap:anywhere; max-height:320px; overflow:auto; font-size:.85rem; padding:12px; border:1px solid var(--lp-line); border-radius:8px; }
#signin-help { min-height:44px; padding:10px 14px; border-radius:8px; border:1px solid #343847; color:var(--text); background:var(--bg-elev); cursor:pointer; }
.nav-btn {
  background: transparent; color: var(--text-muted);
  border: 1px solid transparent; border-radius: 999px;
  padding: 6px 14px; font-size: 14px; cursor: pointer;
}
.nav-btn:hover { color: var(--text); }
.nav-btn.active {
  background: var(--bg-elev-2); color: var(--text);
}
.topbar-btn {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid transparent; border-radius: 999px;
  padding: 6px 14px; font-size: 14px; cursor: pointer;
}
.topbar-btn:hover { border-color: var(--accent); }
.family-profile-btn.active {
  color: #17120a;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.modal.family-profile-modal {
  width: min(560px, calc(100vw - 28px));
  max-width: 560px;
  max-height: min(760px, calc(100dvh - 28px));
  padding: 0;
  border: 1px solid var(--bg-elev-2);
  border-radius: 18px;
  color: var(--text);
  background: var(--bg-elev);
  position: fixed;
  inset: 0;
  margin: auto;
  overflow: auto;
}
.family-profile-modal::backdrop { background: rgba(3, 5, 10, .78); backdrop-filter: blur(4px); }
.modal.family-unlock-modal { width: min(440px, calc(100vw - 28px)); }
.family-unlock-modal .family-form { margin-top: 0; }
.family-unlock-modal h2 { margin-right: 0; }
.family-unlock-modal p { line-height: 1.5; }
.family-profile-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--bg-elev-2); color: var(--text); background: var(--bg-elev-2); cursor: pointer;
}
.family-profile-body { padding: 28px; overflow: auto; }
.family-profile-body h2 { margin: 0 44px 8px 0; font-size: 1.5rem; }
.family-profile-body > p { color: var(--text-muted); line-height: 1.55; }
.family-kid-list { display: grid; gap: 10px; margin: 20px 0; }
.family-kid-row {
  display: grid; grid-template-columns: auto 46px 1fr auto; align-items: center; gap: 12px;
  padding: 12px; border: 1px solid var(--bg-elev-2); border-radius: 12px;
  background: color-mix(in srgb, var(--bg-elev-2) 90%, var(--accent));
}
.family-kid-pick { display: contents; cursor: pointer; }
.family-kid-row:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.family-kid-row.disabled .family-kid-pick > * { opacity: .55; }
.family-kid-row.disabled .family-kid-pick { cursor: not-allowed; }
.family-kid-settings { min-height: 36px; padding: 0 12px; font-size: .85rem; white-space: nowrap; }
.family-kid-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.family-kid-avatar {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent); color: #17120a; font-size: 1.15rem; font-weight: 800;
}
.family-kid-row strong, .family-kid-row small { display: block; }
.family-kid-row small { margin-top: 3px; color: var(--text-muted); }
.family-modal-actions { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 18px; }
.family-primary, .family-secondary {
  display: inline-flex; align-items: center; justify-content: center; min-height: 42px;
  padding: 0 14px; border-radius: 9px; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.family-primary { border: 1px solid var(--accent); color: #17120a; background: var(--accent); }
.family-secondary { border: 1px solid var(--bg-elev-2); color: var(--text); background: transparent; }
.family-beta-note { font-size: .82rem; }
.family-form { display: grid; gap: 12px; margin-top: 16px; }
.family-editor-heading { margin: 8px 0 0; font-size: 1.05rem; }
.family-editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.family-field {
  display: grid; gap: 6px; padding: 12px; border: 1px solid var(--bg-elev-2); border-radius: 10px;
  background: color-mix(in srgb, var(--bg-elev-2) 90%, var(--accent));
}
.family-field > span { font-weight: 700; font-size: .9rem; }
.family-field small { color: var(--text-muted); font-size: .76rem; line-height: 1.4; }
.family-field select, .family-field input[type="text"], .family-field input[type="number"], .family-field input[type="password"] {
  min-height: 40px; padding: 0 10px; border: 1px solid var(--bg-elev-2); border-radius: 8px;
  background: var(--bg-elev); color: var(--text); font: inherit;
}
.family-field.family-check { grid-template-columns: auto 1fr; align-items: start; }
.family-field.family-check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); }
.family-field.family-check strong { display: block; font-size: .9rem; }
.family-field.family-check small { display: block; margin-top: 3px; }
.family-lean-fieldset {
  border: 1px solid var(--bg-elev-2); border-radius: 10px; padding: 12px; margin: 0;
  display: flex; flex-wrap: wrap; gap: 12px 16px;
}
.family-lean-fieldset legend { font-weight: 700; font-size: .9rem; padding: 0 4px; }
.family-lean-fieldset label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.family-lean-fieldset input { accent-color: var(--accent); }
.family-wizard-kid { display: grid; grid-template-columns: 1fr 130px; gap: 10px; }
.family-wizard-kid input {
  min-height: 40px; padding: 0 10px; border: 1px solid var(--bg-elev-2); border-radius: 8px;
  background: var(--bg-elev); color: var(--text); font: inherit;
}
.family-error { color: #ff8896; font-size: .85rem; min-height: 1em; margin: 0; }
.family-signin-copy { min-height: 380px; }
#family-signin-mount { margin-top: 20px; }
.family-notes-link { color: var(--accent); font-weight: 700; }

.content-notes {
  margin: 22px 0;
  padding: 18px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--bg-elev-2));
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg-elev) 88%, var(--accent));
}
.content-notes h3 { margin: 0 0 5px; font-size: 1.08rem; }
.content-notes-head p, .content-notes-warning { color: var(--text-muted); font-size: .88rem; line-height: 1.5; }
.beta-pill {
  display: inline-block; margin-left: 5px; padding: 2px 7px; border-radius: 999px;
  vertical-align: 2px; color: #17120a; background: var(--accent); font-size: .65rem; letter-spacing: .05em; text-transform: uppercase;
}
.content-note-surprise { margin: 14px 0; padding: 10px 12px; border: 1px solid var(--bg-elev-2); border-radius: 9px; }
.content-note-surprise summary, .content-note-row summary { cursor: pointer; font-weight: 700; }
.content-note-surprise p, .content-note-row p { margin: 8px 0 0; color: var(--text-muted); line-height: 1.55; }
.content-note-list { display: grid; gap: 6px; }
.content-note-row { border-top: 1px solid var(--bg-elev-2); padding-top: 8px; }
.content-note-row summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; list-style: none; }
.content-note-row summary::-webkit-details-marker { display: none; }
.content-note-score { flex: 0 0 auto; min-width: 42px; padding: 2px 7px; border-radius: 999px; text-align: center; font-size: .75rem; background: var(--bg-elev-2); }
.content-note-score.score-0, .content-note-score.score-1 { color: var(--good); }
.content-note-score.score-2 { color: var(--accent); }
.content-note-score.score-3, .content-note-score.score-4 { color: var(--bad); }
.content-notes .content-notes-warning { margin: 14px 0 0; }
.content-policy-verdict, .notes-test-verdict {
  margin: 14px 0; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--bg-elev-2); font-size: .88rem;
}
.content-policy-verdict.passes, .notes-test-verdict.passes { border-color: rgba(74, 222, 128, .45); background: rgba(74, 222, 128, .08); }
.content-policy-verdict.blocked, .notes-test-verdict.blocked { border-color: rgba(248, 113, 113, .5); background: rgba(248, 113, 113, .08); }
.content-policy-verdict ul, .notes-test-verdict ul { margin: 7px 0 0 18px; color: var(--text-muted); }
.notes-score-grid { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.notes-score-pill { padding: 4px 7px; border: 1px solid var(--bg-elev-2); border-radius: 7px; color: var(--text-muted); background: rgba(11, 13, 18, .38); font-size: .7rem; }
.notes-score-pill b { color: var(--text); font-weight: 700; }
.notes-score-pill.score-0, .notes-score-pill.score-1 { border-color: rgba(74, 222, 128, .25); }
.notes-score-pill.score-2 { border-color: rgba(245, 158, 11, .35); }
.notes-score-pill.score-3, .notes-score-pill.score-4 { border-color: rgba(248, 113, 113, .35); }

.family-catalog-summary { margin: 16px 0; padding: 14px; border: 1px solid var(--bg-elev-2); border-radius: 11px; }
.family-catalog-summary h3 { margin: 0 0 8px; font-size: 1rem; }
.family-catalog-counts { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 5px 8px; align-items: baseline; }
.family-catalog-counts strong { color: var(--accent); font-size: 1.35rem; }
.family-catalog-counts span { color: var(--text-muted); }
.family-catalog-summary details { margin-top: 10px; }
.family-catalog-summary summary { cursor: pointer; font-weight: 700; }
.family-catalog-summary ul { display: grid; gap: 8px; margin: 10px 0 0; padding: 0; list-style: none; }
.family-catalog-summary li { display: grid; gap: 2px; }
.family-catalog-summary li span, .family-catalog-summary p { color: var(--text-muted); font-size: .78rem; }

.notes-test-page { min-height: 100dvh; }
.notes-test-topbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; gap: 20px;
  padding: 13px max(18px, calc((100vw - 1120px) / 2)); border-bottom: 1px solid var(--bg-elev-2); background: rgba(22, 25, 34, .96);
}
.notes-test-topbar a { color: var(--accent); text-decoration: none; font-weight: 700; }
.notes-test-topbar span { color: var(--text-muted); }
.notes-test-main { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 42px 0 70px; }
.notes-test-intro { max-width: 780px; }
.notes-test-eyebrow { color: var(--accent); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.notes-test-intro h1 { margin: 5px 0 12px; font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.05; }
.notes-test-intro > p:not(.notes-test-eyebrow) { margin-top: 9px; color: var(--text-muted); font-size: 1.04rem; }
.notes-test-search { display: grid; gap: 6px; max-width: 520px; margin: 28px 0; color: var(--text-muted); font-size: .85rem; font-weight: 700; }
.notes-test-search input { min-height: 48px; padding: 0 14px; border: 1px solid var(--bg-elev-2); border-radius: 10px; color: var(--text); background: var(--bg-elev); font: inherit; }
.notes-simulator { margin: 0 0 28px; padding: 20px; border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--bg-elev-2)); border-radius: 14px; background: var(--bg-elev); }
.notes-simulator h2 { margin: 3px 0 5px; }
.notes-simulator > div > p:not(.notes-test-eyebrow) { color: var(--text-muted); }
.notes-simulator-controls { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.notes-simulator-controls label { display: grid; gap: 5px; color: var(--text-muted); font-size: .76rem; font-weight: 700; }
.notes-simulator-controls select { min-height: 42px; padding: 0 9px; border: 1px solid var(--bg-elev-2); border-radius: 8px; color: var(--text); background: var(--bg); }
.notes-simulator-summary { margin-top: 13px; color: var(--accent); font-weight: 800; }
.notes-test-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.notes-test-card { padding: 20px; border: 1px solid var(--bg-elev-2); border-radius: 14px; background: var(--bg-elev); }
.notes-test-card > header { display: flex; justify-content: space-between; gap: 14px; align-items: start; }
.notes-test-card h2 { margin: 0; font-size: 1.2rem; }
.notes-test-card header p, .notes-test-card > p { color: var(--text-muted); }
.notes-test-card > p { margin-top: 10px; }
.notes-test-more { grid-column: 1 / -1; justify-self: center; min-width: 180px; padding: 12px 20px; border: 1px solid var(--accent); border-radius: 999px; background: transparent; color: var(--accent); font: inherit; font-weight: 800; cursor: pointer; }
.notes-test-more:hover { background: rgba(245, 158, 11, .12); }
.notes-test-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.notes-test-tag { padding: 3px 8px; border-radius: 999px; color: var(--accent); background: rgba(245, 158, 11, .12); font-size: .72rem; }
.notes-test-tag.muted { color: var(--text-muted); background: var(--bg-elev-2); }
.notes-test-age { font-size: .9rem; line-height: 1.5; }
.notes-test-sources { margin-top: 14px; color: var(--text-muted); font-size: .82rem; }
.notes-test-sources summary { cursor: pointer; font-weight: 700; }
.notes-test-sources p { margin-top: 7px; }
@media (max-width: 760px) {
  .notes-test-grid { grid-template-columns: 1fr; }
  .notes-simulator-controls { grid-template-columns: 1fr 1fr; }
  .notes-test-topbar span { display: none; }
  .family-modal-actions { align-items: stretch; flex-direction: column; }
  .family-modal-actions > span { display: grid; gap: 10px; }
  .family-editor-grid { grid-template-columns: 1fr; }
  .family-wizard-kid { grid-template-columns: 1fr 110px; }
}
@media (max-width: 460px) { .notes-simulator-controls { grid-template-columns: 1fr; } }

/* List views (watchlist / watched) hide quick-action buttons on cards.
 * All state mutations happen via the detail modal there — keeps the
 * read-only browse uncluttered. */
.card.read-only .card-quick-acts { display: none; }

/* On narrow phones the topbar gets too crowded with title + 3 tabs +
 * 2 action buttons. Drop the title; the tabs make the app obvious. */
@media (max-width: 540px) {
  .topbar-title { display: none; }
  .nav-btn { padding: 6px 10px; font-size: 13px; }
}

.search-row {
  display: flex; justify-content: center;
  padding: 10px 18px; background: var(--bg-elev);
  border-bottom: 1px solid var(--bg-elev-2);
  position: sticky; top: 50px; z-index: 9;
}
.search-input {
  width: 100%; max-width: 640px;
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid transparent; border-radius: 8px;
  padding: 10px 14px; font-size: 15px;
  outline: none;
}
.search-input:focus { border-color: var(--accent); }

/* App layout: vertical sidebar (filters) on the left, grid on the
 * right. On phones the sidebar stacks above the grid via media query. */
.app-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  align-items: start;
}
/* On views where the sidebar is hidden (watchlist, watched, passed,
 * services-page), collapse the grid to a single column so the
 * content fills the full width instead of leaving a 260px gap. */
.app-layout.no-sidebar {
  grid-template-columns: 1fr;
}
.sidebar {
  position: sticky; top: 102px;     /* below topbar (~50px) + search row (~52px) */
  align-self: start;
  max-height: calc(100vh - 102px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 14px 16px 24px;
  background: var(--bg-elev);
  border-right: 1px solid var(--bg-elev-2);
  display: flex; flex-direction: column; gap: 14px;
  scrollbar-width: thin;
}
/* Preset bar — sits above the Browse section. Layout:
 *   [label]
 *   [select (full width)]
 *   [New] [Update]      ← buttons side-by-side, evenly sized
 * Update is disabled (greyed) until a preset is picked. */
.preset-bar {
  display: flex; flex-direction: column; gap: 6px;
  padding: 4px 0 12px;
  border-bottom: 1px solid var(--bg-elev-2);
  margin-bottom: 4px;
}
.preset-bar-label {
  font-size: 12px; color: var(--text-muted);
}
.preset-bar > select {
  width: 100%;
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--bg-elev-2); border-radius: 6px;
  padding: 6px 8px; font: inherit; cursor: pointer;
  font-family: inherit;
}
.preset-bar-row {
  display: flex; gap: 6px;
}
.preset-bar-btn {
  flex: 1;
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--bg-elev-2); border-radius: 6px;
  padding: 6px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.preset-bar-btn:hover:not(:disabled) { border-color: var(--accent); }
.preset-bar-btn:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.55;
}
.preset-bar-btn-update:not(:disabled) { color: var(--accent); }
/* Reset button — shows only when a customized built-in is selected.
 * Subdued styling so it doesn't compete with New/Update; a soft red
 * accent on hover hints at the "undo your changes" action. */
.preset-bar-reset {
  align-self: flex-start;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--bg-elev-2); border-radius: 6px;
  padding: 4px 10px; font-size: 11px; cursor: pointer;
  font-family: inherit;
}
.preset-bar-reset:hover {
  border-color: #d94e4e;
  color: #d94e4e;
}

.sidebar-section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: -4px;
}
.sidebar-group-title {
  font-size: 11px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--text-muted);
}
.sidebar-clear-btn {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--bg-elev-2); border-radius: 999px;
  padding: 3px 10px; font-size: 11px; cursor: pointer;
  font-family: inherit;
}
.sidebar-clear-btn:hover { border-color: var(--accent); color: var(--text); }

/* Movies/Shows are catalog filters, so present them as one cool-blue
 * segmented control rather than making them resemble the neighboring
 * randomizer/action pills. Clicking the only-active one swaps to the
 * other instead of going to zero (see app.js). */
.media-type-toggles {
  display: flex; gap: 3px;
  flex: 0 0 auto;
  padding: 3px;
  background: rgba(96, 165, 250, 0.08);
  border: 1px solid rgba(96, 165, 250, 0.32);
  border-radius: 9px;
}
.media-type-btn {
  background: transparent; color: #9cc5fa;
  border: 0; border-radius: 6px;
  padding: 5px 12px; font-size: 13px; font-weight: 650;
  cursor: pointer; font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.media-type-btn:hover { background: rgba(96, 165, 250, 0.14); color: #c7ddfb; }
.media-type-btn.active {
  background: #60a5fa; color: #061429;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.32);
}
.media-type-btn:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }

/* TV badge on grid cards — small chip in the upper-left corner of
 * the poster. Mirrors .card-saved-badge styling but in a cool blue
 * so the two badges are clearly different. */
.card-tv-badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(96, 165, 250, 0.92);
  color: #061429;
  padding: 3px 8px; border-radius: 6px;
  font-size: 11px; font-weight: 700;
  z-index: 2;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.filter-group {
  display: flex; flex-direction: column; gap: 14px;
  padding: 12px; border-radius: 8px;
  background: var(--bg);
}
/* The score filters get a slightly tinted card so the
 * eye groups them apart from the structural filters above. */
.filter-group-tinted {
  background: rgba(245, 158, 11, 0.06);
  border: 1px solid rgba(245, 158, 11, 0.18);
}

/* Reuse the .filter row style inside the sidebar too. */
.sidebar .filter {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.sidebar .filter select {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--bg-elev-2); border-radius: 6px;
  padding: 5px 8px; font: inherit;
  min-width: 120px; cursor: pointer;
}
.sidebar .filter-toggle {
  gap: 8px; cursor: pointer;
}
.sidebar .filter-apply {
  background: var(--accent); color: #1b1305;
  border: none; border-radius: 8px;
  padding: 8px 16px; font-size: 14px; font-weight: 700;
  cursor: pointer;
}
.sidebar .filter-apply:hover { filter: brightness(1.08); }

/* Bottom actions use two toggle rows with Apply centered beside them.
 * The ad qualifier wraps intentionally so the button can sit higher
 * without recreating horizontal overflow at narrow widths/high zoom. */
.filter-bottom-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "rentals apply"
    "free    apply";
  column-gap: 10px;
  row-gap: 10px;
  min-width: 0;
  margin-top: 4px;
  padding-right: 8px;
}
.filter-bottom-row .filter-toggle {
  justify-content: flex-start;
  min-width: 0;
  width: 100%;
}
.filter-bottom-row .filter-toggle-rentals { grid-area: rentals; }
.filter-bottom-row .filter-toggle-free { grid-area: free; }
.filter-bottom-row .filter-label {
  line-height: 1.25;
  white-space: nowrap;
}
.filter-bottom-row .filter-label-break { display: block; }
.filter-bottom-row .filter-apply {
  grid-area: apply;
  align-self: center;
  justify-self: end;
  margin: 0 8px 0 0;
}

/* Range slider — dual handle. Two overlapping <input type="range">
 * inputs both sitting on the same track. Pointer-events disabled on
 * the track-area but re-enabled on the thumbs so each handle is
 * grabbable. The filled segment between the two thumbs is positioned
 * via inline left/right percentages set in JS. */
.range-control { display: flex; flex-direction: column; gap: 6px; }
.range-header {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px; min-width: 0; font-size: 13px;
}
.range-label { flex: 0 0 auto; color: var(--text-muted); }
.range-value {
  min-width: 0; color: var(--text); font-weight: 600; font-size: 12px;
  text-align: right; white-space: nowrap;
}
.range-slider {
  position: relative; height: 28px;
  margin: 0 9px;     /* shoulders so the round thumb doesn't get clipped */
}
.range-track {
  position: absolute; left: 0; right: 0; top: 50%;
  height: 4px; background: var(--bg-elev-2);
  transform: translateY(-50%);
  border-radius: 2px;
}
.range-track-fill {
  position: absolute; top: 50%; height: 4px;
  background: var(--accent);
  transform: translateY(-50%);
  border-radius: 2px;
  pointer-events: none;
}
.range-slider input[type="range"] {
  position: absolute; left: -9px; right: -9px; top: 0;
  width: calc(100% + 18px); height: 28px;
  -webkit-appearance: none; appearance: none;
  background: transparent;
  pointer-events: none;     /* the track-area is dead; only thumbs receive clicks */
  margin: 0; padding: 0;
}
/* Thumbs: round, accent-colored, re-enable pointer events.
 * margin-top centers the thumb vertically on the 4px track:
 *   margin-top = (track_height - thumb_height) / 2 = (4 - 18) / 2 = -7px
 * Without this, Chrome aligns the thumb's TOP to the track's top
 * and the circle sits visually below the line. */
.range-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer; pointer-events: auto;
  position: relative; z-index: 3;
  margin-top: -7px;
}
.range-slider input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer; pointer-events: auto;
}
.range-slider input[type="range"]::-webkit-slider-runnable-track {
  background: transparent; border: none; height: 4px;
}
.range-slider input[type="range"]::-moz-range-track {
  background: transparent; border: none; height: 4px;
}
.range-ticks {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--text-muted);
  margin: 0 9px;
}

/* Main content column: the action row and genre categories share one
 * desktop sticky wrapper so neither disappears while browsing results. */
.content { min-width: 0; }
.content-sticky-controls {
  position: sticky;
  top: 102px;     /* below topbar (~50px) + search row (~52px) */
  z-index: 8;
  background: var(--bg-elev);
}
.content-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--bg-elev-2);
}
.mobile-filter-row { display: contents; }
.content-actions-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.active-filter-chips { display: none; }
.mobile-genre-filter { display: none !important; }
.content-btn {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid transparent; border-radius: 999px;
  padding: 7px 16px; font-size: 14px; cursor: pointer;
  white-space: nowrap;   /* never let "🎲 Surprise me" wrap into a 3-line pill */
}
.content-btn:hover { border-color: var(--accent); }
.action-label-short { display: none; }
.content-sort {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-muted); font-size: 13px;
}
.content-sort select {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--bg-elev-2); border-radius: 6px;
  padding: 5px 8px; font: inherit; cursor: pointer;
  /* Widen so longer aggregate-source labels fit: "🍿 User reviews
   * (IMDb + Letterboxd + RT Audience)" is the longest one. */
  min-width: 340px;
}

/* Genre quick-filter chips — horizontal scrolling row below the
 * content header. Click sets the Genre dropdown + reapplies. Active
 * chip mirrors the dropdown value so the two stay in sync. */
.genre-chips {
  display: flex; gap: 8px;
  padding: 10px 18px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--bg-elev-2);
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-elev-2) transparent;
}
.genre-chips::-webkit-scrollbar { height: 6px; }
.genre-chips::-webkit-scrollbar-thumb { background: var(--bg-elev-2); border-radius: 3px; }
.genre-chip {
  flex: 0 0 auto;
  background: var(--bg-elev-2); color: var(--text-muted);
  border: 1px solid transparent; border-radius: 999px;
  padding: 5px 14px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.genre-chip:hover { border-color: var(--accent); color: var(--text); }
.genre-chip.active {
  background: var(--accent); color: #1b1305;
  border-color: var(--accent);
}

/* Stats modal — opened from the 📊 Stats button on Watched view.
 * Lightweight overlay rendering aggregates from /api/stats/me. */
.stats-modal {
  max-width: 720px; width: calc(100vw - 32px);
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--bg-elev-2); border-radius: 12px;
  padding: 0;
  max-height: 86vh; overflow: auto;
}
.stats-modal::backdrop { background: rgba(0, 0, 0, 0.65); }
.stats-modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--bg-elev-2);
  position: sticky; top: 0; background: var(--bg-elev); z-index: 2;
}
.stats-modal-header h2 { margin: 0; font-size: 20px; }
.stats-modal-close {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--bg-elev-2); border-radius: 6px;
  width: 30px; height: 30px; font-size: 16px; cursor: pointer;
  font-family: inherit;
}
.stats-modal-close:hover { color: var(--text); border-color: var(--accent); }
.stats-modal-body { padding: 22px; display: flex; flex-direction: column; gap: 20px; }
.stats-tiles {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.stats-tile {
  background: var(--bg);
  border: 1px solid var(--bg-elev-2); border-radius: 10px;
  padding: 14px;
  text-align: center;
}
.stats-tile-num { font-size: 28px; font-weight: 700; color: var(--accent); }
.stats-tile-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-muted); margin-top: 6px;
}
.stats-section { display: flex; flex-direction: column; gap: 10px; }
.stats-section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted); margin: 0;
}
.stats-bar-list { display: flex; flex-direction: column; gap: 6px; }
.stats-bar-row {
  display: grid; grid-template-columns: 1fr 60px;
  align-items: center; gap: 10px;
  font-size: 13px;
}
.stats-bar-label-wrap {
  position: relative;
  background: var(--bg-elev-2);
  border-radius: 6px;
  padding: 6px 10px;
  overflow: hidden;
}
.stats-bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: rgba(245, 158, 11, 0.35);
}
.stats-bar-label-text { position: relative; }
.stats-bar-count { color: var(--text-muted); text-align: right; }

/* Banner above the Watched grid hosting the 📊 Stats button. Lets the
 * user open the stats modal without having to surface a top-level
 * tab. Discreet — sits just above the cards, centered. */
.watched-stats-banner {
  display: flex; justify-content: center;
  padding: 14px 18px 0;
}
.watched-stats-banner .content-btn {
  font-size: 13px; padding: 8px 18px;
}

@media (max-width: 860px) {
  .account-control > span { display: none; }
  .content-sticky-controls { position: static; }
  /* Phones + narrow tablets: the sidebar used to stack ABOVE the
   * grid, which buried the first poster ~1500px down the page —
   * every app-open started with two screens of sliders. Now it's a
   * full-screen drawer, hidden until the 🎛 Filters button in the
   * content header opens it (body.filters-open, wired in app.js). */
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  body.filters-open .sidebar {
    display: flex;
    position: fixed; inset: 0; z-index: 40;
    /* `.sidebar` is normally a start-aligned grid item. Without an
     * explicit mobile height that alignment makes this fixed drawer grow
     * to its content height, leaving no internal overflow area to scroll.
     * Keep it locked to the visible phone viewport instead. */
    align-self: stretch;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    border-right: none;
    padding-bottom: max(48px, calc(24px + env(safe-area-inset-bottom)));
  }
  /* Lock the page behind the open drawer. */
  body.filters-open { overflow: hidden; }
  .mobile-genre-filter { display: flex !important; }
  /* Drawer header (hidden on desktop, below) gets a sticky Done
   * button so it's always reachable mid-scroll. Extra .sidebar in
   * the selector out-specifies the desktop display:none below. */
  .sidebar .sidebar-drawer-head {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: -14px;      /* cancel the sidebar's 14px top padding */
    margin: -14px -16px 0;             /* bleed to the drawer edges */
    padding: 14px 16px;
    background: var(--bg-elev);
    z-index: 2;
    border-bottom: 1px solid var(--bg-elev-2);
  }
  /* The content header is no longer sticky here: its 102px desktop
   * offset is wrong under the mobile topbar heights (it slid under
   * the search row), and un-sticking it gives posters back ~90px of
   * screen while scrolling. */
  .content-header { position: static; }
}
/* Hidden on desktop — the sidebar is always visible there. */
.sidebar-drawer-head { display: none; }
.sidebar-drawer-title { font-size: 16px; font-weight: 700; }
.sidebar-drawer-done {
  background: var(--accent); color: var(--bg);
  border: none; border-radius: 999px;
  padding: 8px 18px; font: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer;
}
/* Filters toggle button — only exists as a control on narrow
 * layouts; desktop always shows the sidebar. Views without a
 * sidebar (services, lists) hide it too. */
.filters-toggle { display: none; }
@media (max-width: 860px) {
  .filters-toggle { display: inline-block; }
  .app-layout.no-sidebar .filters-toggle { display: none; }
}
.filter { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.filter select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--bg-elev-2); border-radius: 6px;
  padding: 5px 8px; font: inherit;
  min-width: 110px;
  cursor: pointer;
}
.filter select:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

.filter-apply {
  background: var(--accent); color: var(--bg);
  border: none; border-radius: 6px;
  padding: 6px 16px; font: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer;
  margin-left: auto;     /* push the button to the right edge */
}
.filter-apply:hover { filter: brightness(1.1); }
.filter-apply:active { transform: translateY(1px); }
.filter-toggle { cursor: pointer; user-select: none; }
.filter-toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.filter-toggle .filter-label { color: var(--text); }

.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  padding: 18px;
}

.card {
  background: var(--bg-elev); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: transform 0.12s ease, border-color 0.12s ease;
  border: 1px solid transparent; position: relative;
}
/* Long result sets can contain hundreds of cards. Skip paint/layout work for
 * cards well outside the viewport while reserving a stable approximate height
 * so scrolling does not jump. Browsers without content-visibility ignore it. */
@supports (content-visibility: auto) {
  .grid > .card {
    content-visibility: auto;
    contain-intrinsic-size: auto 420px;
  }
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-open-detail {
  position: absolute; inset: 0; z-index: 1;
  width: 100%; height: 100%;
  border: 0; border-radius: var(--radius);
  background: transparent; cursor: pointer;
}
.card:has(.card-open-detail:focus-visible) {
  border-color: var(--accent);
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.card-poster {
  width: 100%; height: auto; aspect-ratio: 2 / 3; object-fit: cover; background: var(--bg-elev-2);
  display: block;
  border-radius: var(--radius) var(--radius) 0 0;   /* keep top corners rounded when card overflow goes visible */
}
.card-body { padding: 8px 10px 12px; }
.card-title {
  font-size: 14px; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; font-size: 11px; color: var(--text-muted); }
.card-rating { padding: 1px 5px; border-radius: 4px; background: var(--bg-elev-2); }
/* "For You" carousels — rendered above the discover grid on a
 * clean Discover load. Includes new releases + recommendations
 * (when the user has rated highly enough to seed recs). */
.for-you-explanation { overflow-wrap: anywhere; }
.for-you-explanation summary { cursor: pointer; padding: 8px 0; min-height: 44px; }
.for-you-explanation details p, .for-you-explanation ul { margin: 8px 0; }
.for-you-explanation ul { padding-left: 20px; }
.for-you-explanation li + li { margin-top: 8px; }
.for-you-wrap {
  padding: 16px 18px 4px;
  display: flex; flex-direction: column; gap: 18px;
}
.for-you-section {
  display: flex; flex-direction: column; gap: 8px;
}
.for-you-header {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px;
}
.for-you-header h3 {
  font-size: 16px; font-weight: 700; color: var(--text);
}
.for-you-subtitle {
  font-size: 12px; color: var(--text-muted); min-width: 0; overflow-wrap: anywhere;
}
.for-you-strip-wrap { position: relative; }
.for-you-strip {
  display: flex; gap: 10px; overflow-x: auto;
  scroll-snap-type: x proximity; scroll-behavior: smooth;
  padding-bottom: 6px;
  scrollbar-width: thin; scrollbar-color: var(--bg-elev-2) transparent;
}
.for-you-strip::-webkit-scrollbar { height: 8px; }
.for-you-strip::-webkit-scrollbar-thumb { background: var(--bg-elev-2); border-radius: 4px; }
.for-you-card {
  flex: 0 0 160px;
  min-width: 0; overflow-wrap: anywhere;
  background: var(--bg-elev); border-radius: 8px;
  border: 1px solid var(--bg-elev-2);
  cursor: pointer;
  padding: 0;
  text-align: left;
  scroll-snap-align: start;
  font-family: inherit; color: inherit;
  transition: border-color 0.15s, transform 0.15s;
}
.for-you-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.for-you-card:focus-visible {
  border-color: var(--accent);
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.for-you-card-poster {
  width: 100%; height: auto; aspect-ratio: 2/3; object-fit: cover;
  border-radius: 8px 8px 0 0;
  background: var(--bg-elev-2);
  display: block;
}
.for-you-card-body { padding: 8px 10px 10px; }
.for-you-card-title {
  font-size: 12px; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.for-you-card-reason {
  font-size: 10px; color: var(--text-muted);
  margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.for-you-card-ratings {
  display: flex; gap: 4px; flex-wrap: wrap;
  margin-top: 6px;
  font-size: 10px;
}

/* Personal star rating badge on cards in the Watched view. */
.card-my-rating {
  margin-top: 5px;
  font-size: 13px; color: var(--accent);
  letter-spacing: 1px;
}
.card-my-rating-num { font-size: 10px; color: var(--text-muted); letter-spacing: 0; margin-left: 4px; }

.card-rating.good  { background: rgba(74, 222, 128, 0.18); color: var(--good); }
.card-rating.meh   { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.card-rating.bad   { background: rgba(248, 113, 113, 0.18); color: var(--bad); }
/* Three labeled quick-actions overlaid on the poster's top-right.
 * Hover-reveal so they're invisible until the user mouses over the
 * card — frees the card body for ratings + title without clutter.
 * Stacked vertically: Watched (top) -> Save -> Pass (bottom). */
.card-quick-acts {
  position: absolute;
  top: 6px; right: 6px;
  display: flex; flex-direction: column; gap: 5px;
  z-index: 3;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
/* Dark scrim fades in behind the buttons on hover so they're always
 * readable, even on near-black posters where a translucent black
 * button used to disappear into the artwork. */
.card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 110px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), rgba(0,0,0,0));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 2;
  border-radius: var(--radius) var(--radius) 0 0;
}
.card:hover::before,
.card:focus-within::before {
  opacity: 1;
}
.card:hover .card-quick-acts,
.card:focus-within .card-quick-acts {
  opacity: 1;
  pointer-events: auto;
}
.card-act {
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(0, 0, 0, 0.78); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  padding: 5px 9px;
  font: inherit; font-size: 11px; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  justify-content: flex-start;
  /* Drop-shadow for separation from the poster regardless of color. */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
}
.card-act:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.card-act.active {
  background: rgba(245, 158, 11, 0.95);
  color: var(--bg);
  border-color: var(--accent);
}
.card-act-icon { font-size: 12px; }
.card-act-label { line-height: 1; }

/* Touch devices have no hover — keep quick-actions reachable by
 * always showing them. Hover-capable devices (most desktops + many
 * tablets w/ a mouse) get the cleaner reveal-on-hover behavior. */
@media (hover: none) {
  .card-quick-acts {
    opacity: 1;
    pointer-events: auto;
  }
}

/* "Saved" overlay badge on the poster when the title is on the
 * watch list. Top-left so it doesn't fight the (no-longer-rendered)
 * top-right action area. */
.card-saved-badge {
  position: absolute; top: 6px; left: 6px; z-index: 2;
  background: rgba(245, 158, 11, 0.92); color: var(--bg);
  font-size: 11px; font-weight: 700;
  padding: 3px 7px; border-radius: 4px;
  pointer-events: none;
}
/* A saved TV show renders BOTH top-left badges — drop Saved below
 * the TV badge instead of stacking them on the same pixel. */
.card-tv-badge ~ .card-saved-badge { top: 36px; left: 8px; }

/* "Free with ads" badge — top-RIGHT so it never collides with the
 * TV/Saved badges in the top-left corner. Green = costs nothing. */
.card-free-badge {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  background: rgba(52, 211, 153, 0.92); color: #04281c;
  font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 6px;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.empty { padding: 60px 24px; text-align: center; color: var(--text-muted); grid-column: 1 / -1; }
.search-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.search-retry-btn { min-height: 40px; }

.discover-load-warning {
  margin: 14px 18px 0;
  padding: 10px 14px;
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.10);
  color: var(--text);
  font-size: 13px;
}

.load-more-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 24px;
}
.load-more-stats { color: var(--text-muted); font-size: 13px; }
.load-more-sentinel { color: var(--text-muted); font-size: 13px; font-style: italic; }

.filter input[placeholder] { color: var(--text); }
.filter input[type="number"][placeholder]::placeholder { color: var(--text-dim, #666); }
.filter-suffix { color: var(--text-muted); font-size: 11px; margin-left: 4px; }

.modal {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--bg-elev-2); border-radius: var(--radius);
  padding: 0; max-width: 480px; width: calc(100% - 32px);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.65); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--bg-elev-2); }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; }
.modal-foot { display: flex; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--bg-elev-2); }

.btn {
  background: var(--bg-elev-2); color: var(--text);
  border: none; border-radius: 6px;
  padding: 8px 16px; cursor: pointer; font-weight: 600;
}
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-secondary { background: var(--bg-elev-2); color: var(--text); }

/* ---- Detail modal ------------------------------------------------------ */
.detail-modal {
  max-width: 880px; width: calc(100% - 24px);
  max-height: calc(100vh - 32px);
  /* dvh tracks the REAL visible height on mobile (URL bar expands/
   * collapses); without it the bottom action row can hide behind the
   * browser toolbar. Falls back to the vh line above where dvh is
   * unsupported. */
  max-height: calc(100dvh - 32px);
  padding: 0; overflow: hidden;
  background: var(--bg-elev);
  /* Explicit centering — some browsers don't perfectly center <dialog>
   * by default when min-content height < viewport. inset:0 + margin:auto
   * does it reliably. */
  inset: 0;
  margin: auto;
  position: fixed;             /* explicit so absolute children anchor to the dialog */
}
.detail-modal-inner {
  /* Inner is the SCROLLABLE area. Close + side chevrons live OUTSIDE
   * this element so they're always visible even when the user has
   * scrolled to the bottom of the modal content. */
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);   /* see .detail-modal note */
  overflow-y: auto;
  position: relative;
}
.detail-backdrop {
  height: 220px;
  background-size: cover; background-position: center top;
  position: relative;
}
.detail-backdrop::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(11,13,18,0.35) 0%, var(--bg-elev) 100%);
}
.detail-close {
  /* Sibling of .detail-modal-inner inside <dialog>, so position:absolute
   * anchors to the dialog and stays put as inner scrolls. */
  position: absolute; top: 12px; right: 12px; z-index: 6;
  background: rgba(0,0,0,0.85); color: var(--text);
  border: none; border-radius: 999px;
  width: 36px; height: 36px; font-size: 16px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.detail-close:hover { background: var(--accent); color: var(--bg); }

/* Pinned action buttons on the detail modal — vertical stack below
 * the close button. Stays visible while the inner content scrolls
 * so the user never has to scroll to find Watched/Save/Pass. */

/* Per-card error toast — fades into the bottom of a grid card
 * when a quick-action fails. */
.card-action-error {
  position: absolute;
  bottom: 4px; left: 4px; right: 4px;
  background: rgba(248, 113, 113, 0.92); color: #1b1305;
  padding: 4px 8px; border-radius: 6px;
  font-size: 11px; font-weight: 600;
  text-align: center;
  z-index: 4;
}

/* Transient error banner shown on the detail modal when an action
 * call (watched/save/pass/rating) fails. Floats over the top. */
.detail-action-toast {
  position: absolute;
  top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(248, 113, 113, 0.95); color: #1b1305;
  padding: 8px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.detail-actions-static {
  position: absolute;
  top: 64px; right: 14px;
  z-index: 4;
  display: flex; flex-direction: column; gap: 6px;
}
.detail-action-btn {
  background: rgba(11, 13, 18, 0.85);
  color: var(--text);
  border: 1px solid var(--bg-elev-2);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
  font-size: 13px; font-weight: 500;
  min-width: 116px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.detail-action-btn:hover {
  background: var(--bg-elev-2);
  border-color: var(--accent);
}
.detail-action-btn.active {
  background: var(--accent);
  color: #1b1305;
  border-color: var(--accent);
}
.dab-icon { font-size: 14px; line-height: 1; }
.dab-label { flex: 1; text-align: left; }
@media (max-width: 540px) {
  /* Give the pinned phone actions their own row outside the scroller.
   * An absolute bottom overlay can turn a footer Next tap into Save/Pass. */
  .detail-modal[open] { display: flex; flex-direction: column; }
  .detail-modal-inner { min-height: 0; }
  .detail-actions-static {
    position: static; order: 1; flex-shrink: 0;
    flex-direction: row; justify-content: flex-end; gap: 8px;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .detail-action-btn { min-width: 0; padding: 8px 10px; }
  .dab-label { display: none; }
}
.detail-head {
  display: flex; gap: 18px; padding: 0 22px 16px;
  margin-top: -80px; position: relative; z-index: 2;
  /* Belt-and-suspenders: keep the poster at its natural height even
   * if the text column grows. Otherwise flex's default stretch would
   * make the poster a tall skinny rectangle. */
  align-items: flex-start;
}
.detail-poster {
  width: 160px; height: auto; flex-shrink: 0; border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.55);
  background: var(--bg-elev-2);
}
.detail-head-text { flex: 1; min-width: 0; padding-top: 90px; }

/* Where-to-watch strip — sits between the detail-head and the body.
 * Visible without scrolling so the user always lands on play buttons.
 * Padded to match the head + body horizontal padding (22px). */
/* Personal-rating star picker — appears in the detail body. Click
 * a star to rate (also marks the title watched); click the same
 * star to clear. Filled stars use the accent color; empty stars
 * are translucent. */
.my-rating-section {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 22px 12px;
  border-bottom: 1px solid var(--bg-elev-2);
}
.my-rating-label {
  font-size: 12px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text-muted);
}
.my-rating-stars { display: flex; gap: 2px; }
.my-rating-star {
  background: none; border: none;
  color: rgba(255, 255, 255, 0.18);
  font-size: 22px; line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 0.1s, transform 0.1s;
}
.my-rating-star:hover { color: var(--accent); transform: scale(1.1); }
.my-rating-star.filled { color: var(--accent); }

.detail-offers-strip {
  padding: 8px 22px 14px;
  display: flex; flex-direction: column; gap: 8px;
  border-bottom: 1px solid var(--bg-elev-2);
}
.detail-offers-strip-label {
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text-muted);
}
.detail-offers-strip-list {
  display: flex; flex-direction: column; gap: 8px;
}
/* Rent/buy collapses into a <details> toggle, closed by default.
 * Less visual weight than the subscription row above it. */
.offer-paid-details {
  margin-top: 4px;
}
.offer-availability-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
}
.offer-report { font-size: 13px; }
.offer-report summary { cursor: pointer; padding: 8px 0; }
.offer-report label { display: block; margin-top: 10px; }
.offer-report textarea {
  display: block; width: 100%; box-sizing: border-box; resize: vertical;
  margin: 6px 0; padding: 8px; color: var(--text); background: var(--bg-elev-2);
  border: 1px solid var(--text-muted); border-radius: 6px;
}
.offer-report-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.offer-paid-summary {
  font-size: 12px; color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 0;
  user-select: none;
}
.offer-paid-summary::-webkit-details-marker { display: none; }
.offer-paid-summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s;
  font-size: 10px;
}
.offer-paid-details[open] .offer-paid-summary::before {
  transform: rotate(90deg);
}
.offer-paid-summary:hover { color: var(--text); }
.offer-paid-count { color: var(--text-muted); }
.offer-paid-body {
  margin-top: 6px;
  display: flex; flex-direction: column; gap: 8px;
}
.detail-title { font-size: 24px; font-weight: 700; line-height: 1.2; }
.detail-year  { color: var(--text-muted); font-weight: 500; }
.detail-tagline { color: var(--text-muted); font-style: italic; margin-top: 4px; font-size: 14px; }
.detail-meta { color: var(--text-muted); font-size: 13px; margin-top: 6px; }
.detail-cast { margin-top: 10px; line-height: 1.45; }
.detail-overview { margin-top: 8px; line-height: 1.55; font-size: 15px; }

.rating-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.rating-chip {
  font-size: 12px; padding: 3px 8px; border-radius: 4px;
  background: var(--bg-elev-2); color: var(--text);
}
.rating-chip.good  { background: rgba(74, 222, 128, 0.18); color: var(--good); }
.rating-chip.meh   { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.rating-chip.bad   { background: rgba(248, 113, 113, 0.18); color: var(--bad); }
.rating-chip.muted { color: var(--text-muted); }
.rating-chip-max   { color: var(--text-muted); }

/* Detail modal rating row group — separates audience scores from
 * critic scores with a small label above each row. */
.rating-row-group { margin-top: 10px; }
.rating-row-group:first-of-type { margin-top: 12px; }
.rating-row-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.8px;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 4px;
}
/* Detail modal: where the critic score and average rating come from. */
.rating-note { margin-top: 6px; font-size: 12px; line-height: 1.45; color: var(--text-muted); max-width: 60ch; }
.rating-note a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.rating-note a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

.detail-body { padding: 0 22px 22px; }

.offers { margin: 18px 0 22px; }
.offer-group { margin-bottom: 14px; }
.offer-group-label {
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 8px;
}
.offer-row { display: flex; flex-wrap: wrap; gap: 8px; }
.offer-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--bg-elev-2);
  color: var(--text); text-decoration: none;
  font-size: 13px; font-weight: 600;
}
.offer-btn img { width: 24px; height: 24px; border-radius: 4px; }
/* Rent/buy price and a "Leaving <date>" note sit after the service name. */
.offer-extra { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.offer-btn.mine .offer-extra { color: inherit; }
.offer-leaving { color: var(--accent); }
.offer-btn:hover { border-color: var(--accent); }
.offer-btn.mine {
  background: rgba(245, 158, 11, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-act {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--bg-elev-2);
}
.btn-act:hover { border-color: var(--accent); color: var(--accent); }
.btn-act.active {
  background: rgba(245, 158, 11, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}
.ba-icon { font-size: 14px; }

/* Side arrows — floating left/right edge of modal, big tap targets,
 * fade when at the start or end of the list. */
.detail-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px;
  background: rgba(0,0,0,0.65); color: var(--text);
  border: none; border-radius: 999px;
  font-size: 28px; font-weight: 700; line-height: 1;
  cursor: pointer; z-index: 4;
  display: flex; align-items: center; justify-content: center;
  padding-bottom: 4px;            /* nudge ‹/› chevrons up to look centered */
}
.detail-nav:hover:not([disabled]) { background: var(--accent); color: var(--bg); }
.detail-nav[disabled] { opacity: 0.25; cursor: default; }
.detail-nav-prev { left: 10px; }
.detail-nav-next { right: 10px; }

/* Footer nav inside the scrolling area — same prev/next, plus position. */
.detail-nav-footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid var(--bg-elev-2);
}
.detail-position { color: var(--text-muted); font-size: 13px; }
.detail-nav-footer .btn[disabled] { opacity: 0.4; cursor: default; }

@media (max-width: 540px) {
  /* Side arrows get out of the way on phones — footer buttons are the
   * mobile pattern. Keyboard arrows still work if a Bluetooth keyboard
   * is attached. */
  .detail-nav { display: none; }
}

/* On phones, posters stack above text and we drop the negative margin */
@media (max-width: 540px) {
  .detail-head { flex-direction: column; margin-top: -60px; }
  .detail-poster { width: 130px; }
  .detail-head-text { padding-top: 0; }
  .detail-title { font-size: 20px; }
  .detail-backdrop { height: 160px; }
}

/* Services page — full-page picker that replaces the old modal.
 * Featured order or A–Z. Each tile is a click-to-toggle card with the
 * service's logo (or its initial when the catalog has no logo), name,
 * and a corner checkmark when selected. */
.services-page {
  grid-column: 1 / -1;
  padding: 20px 8px;
}
.services-page-head { margin-bottom: 18px; }
.services-page-head h2 {
  font-size: 22px; font-weight: 700; color: var(--text);
}
.services-page-sub {
  font-size: 13px; color: var(--text-muted); margin-top: 4px;
}
.services-controls {
  display: flex; gap: 12px; align-items: center;
  margin-top: 14px; flex-wrap: wrap;
}
.services-search-input {
  flex: 1 1 280px; min-width: 200px;
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--bg-elev-2); border-radius: 8px;
  padding: 9px 12px; font-size: 14px;
  font-family: inherit;
  outline: none;
}
.services-search-input:focus { border-color: var(--accent); }
.services-sort {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-muted); font-size: 13px;
}
.services-sort select {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--bg-elev-2); border-radius: 6px;
  padding: 6px 10px; font: inherit; cursor: pointer;
}
.services-section { margin-top: 24px; }
.services-section-head {
  font-size: 13px; font-weight: 600; letter-spacing: 0.4px;
  color: var(--text-muted); text-transform: uppercase;
  margin-bottom: 12px;
}
.services-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
.services-grid-featured {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.service-tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  gap: 8px;
  background: var(--bg-elev); color: var(--text);
  border: 2px solid var(--bg-elev-2);
  border-radius: 10px;
  padding: 16px 10px 12px;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
  min-height: 130px;
}
.service-tile:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.service-tile.selected {
  border-color: var(--accent);
  background: rgba(245, 158, 11, 0.10);
}
.service-tile-logo {
  width: 64px; height: 64px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg);
}
.service-tile-logo-blank {
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; color: var(--text-muted);
  border: 1px solid var(--bg-elev-2);
}
.service-tile-name {
  font-size: 12px; font-weight: 500; text-align: center;
  line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.service-tile-check {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent); color: #1b1305;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  opacity: 0; transform: scale(0.6);
  transition: opacity 0.15s, transform 0.15s;
}
.service-tile.selected .service-tile-check {
  opacity: 1; transform: scale(1);
}

/* Trailer button — lives in the detail-head-text column under the
 * rating chips. Clicking opens the dedicated #trailer-modal popup
 * so closing reliably stops the YouTube audio. */
.trailer-section { margin-top: 14px; }
.trailer-play-btn[aria-busy="true"] { opacity: 0.7; cursor: progress; }
.trailer-status { margin-top: 8px; font-size: 13px; color: var(--text-muted); }
.trailer-status:empty { display: none; }
.trailer-status a { color: var(--accent); }
.trailer-play-btn {
  background: var(--accent); color: #1b1305;
  border: none; border-radius: 8px;
  padding: 9px 16px; font-size: 14px; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.trailer-play-btn:hover { filter: brightness(1.08); }
.trailer-icon { font-size: 12px; }

/* Dedicated trailer popup — its own <dialog>. Sized large enough
 * that YouTube serves 1080p (its auto-quality picker uses iframe
 * pixel size). Centered explicitly so the global .modal rule
 * (which targets the smaller dialogs) doesn't fight us. */
.trailer-modal {
  width: 90vw; max-width: 2560px;
  /* Cap height too so the 16:9 box never overflows a short screen. */
  max-height: calc(100vh - 60px);
  padding: 0;
  background: #000;
  border: 1px solid var(--bg-elev-2);
  border-radius: 12px;
  overflow: hidden;
  /* Belt-and-suspenders centering. Native <dialog> already centers
   * itself, but explicit `margin: auto` + `inset: 0` overrides any
   * stray positioning inherited from .modal. */
  position: fixed;
  inset: 0;
  margin: auto;
}
.trailer-modal::backdrop {
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.trailer-modal-shell { width: 100%; background: #000; }
.trailer-modal-shell:fullscreen {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #000;
}
.trailer-modal-shell:fullscreen::backdrop { background: #000; }
.trailer-modal-shell:fullscreen .trailer-modal-header { flex: 0 0 40px; }
.trailer-modal-shell:fullscreen .trailer-modal-iframe-wrap {
  flex: 1 1 auto;
  width: 100%;
  height: auto;
  min-height: 0;
  padding-bottom: 0;
}
/* Thin header bar above the iframe. Holds the close button so it
 * never overlaps YouTube's own controls (gear icon, fullscreen,
 * etc.) inside the player area. */
.trailer-modal-header {
  display: flex; justify-content: flex-end; align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 10px;
  background: #000;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.trailer-modal-iframe-wrap {
  position: relative; padding-bottom: 56.25%; height: 0;
}
.trailer-modal-iframe-wrap iframe {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%; border: 0;
}
.trailer-modal-close,
.trailer-modal-minimize {
  background: var(--bg-elev-2); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.20);
  border-radius: 999px;
  font-size: 13px; font-weight: 600; line-height: 1;
  padding: 6px 14px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  font-family: inherit;
}
.trailer-modal-minimize { display: none; }
.trailer-modal-shell:fullscreen .trailer-modal-minimize { display: inline-flex; }
.trailer-modal-close:hover,
.trailer-modal-minimize:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }

/* A phone rotated sideways should feel like a video player, not a
 * portrait dialog squeezed into a short viewport. Use the entire visible
 * landscape viewport and let the iframe consume the space below Close.
 * The max-height check keeps this treatment scoped to phones rather than
 * ordinary desktop windows that happen to be wider than they are tall. */
@media (orientation: landscape) and (max-height: 600px) {
  .trailer-modal[open] {
    display: flex;
    flex-direction: column;
    width: 100vw;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
  }
  .trailer-modal-shell {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
  }
  .trailer-modal-header {
    flex: 0 0 40px;
    padding-right: max(10px, env(safe-area-inset-right));
    padding-left: max(10px, env(safe-area-inset-left));
  }
  .trailer-modal-iframe-wrap {
    flex: 1 1 auto;
    width: 100%;
    height: auto;
    min-height: 0;
    padding-bottom: 0;
  }
}

/* Similar-titles horizontal strip — Netflix-style scroll with side arrows. */
.similar-section { margin-top: 22px; }
.similar-heading {
  font-size: 15px; font-weight: 600;
  margin-bottom: 10px; color: var(--text);
}
.similar-strip-wrap { position: relative; }
.similar-row {
  display: flex; gap: 10px; overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-behavior: smooth;
  padding-bottom: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-elev-2) transparent;
}
.similar-row::-webkit-scrollbar { height: 8px; }
.similar-row::-webkit-scrollbar-thumb { background: var(--bg-elev-2); border-radius: 4px; }

/* Side arrows: absolutely positioned over the strip, centered
 * vertically. Hidden via [hidden] when at the respective edge. */
/* Arrows overlay INSIDE the poster strip — anchored a few px from each
 * edge, big circular button with a gradient mask trailing into the row
 * so they read as "scroll controls" instead of looking detached. */
.similar-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px;
  background: rgba(11, 13, 18, 0.92);
  color: var(--text);
  border: 2px solid var(--accent); border-radius: 50%;
  font-size: 28px; line-height: 1; font-weight: 600;
  cursor: pointer; z-index: 3;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
  /* nudge the glyph up slightly so it visually centers in a round btn */
  padding-bottom: 4px;
}
.similar-arrow:hover {
  background: var(--accent);
  color: #1b1305;
  transform: translateY(-50%) scale(1.06);
}
.similar-arrow[hidden] { display: none; }
/* Position inside the strip — 8px from the visible edge of the row. */
.similar-arrow-prev { left: 8px; }
.similar-arrow-next { right: 8px; }
@media (max-width: 540px) {
  /* On phones, finger-scrolling is the norm — drop the arrows to
   * keep the strip uncluttered. */
  .similar-arrow { display: none; }
}
.similar-card {
  flex: 0 0 110px; scroll-snap-align: start;
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid transparent; border-radius: 6px;
  cursor: pointer; padding: 0;
  text-align: left;
  transition: border-color 0.15s;
}
.similar-card:hover { border-color: var(--accent); }
.similar-card img,
.similar-blank {
  width: 100%; aspect-ratio: 2 / 3;
  object-fit: cover; border-radius: 5px 5px 0 0;
  display: block;
}
.similar-card img { height: auto; }
.similar-blank { background: var(--bg); }
.similar-title {
  font-size: 12px; line-height: 1.3;
  padding: 6px 6px 0; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.similar-year {
  font-size: 11px; color: var(--text-muted);
  padding: 2px 6px 6px;
}

/* ================================================================
 * Mobile & touch polish — the couch-phone pass. Everything below is
 * scoped to (hover: none) [touch devices] or narrow widths, so
 * desktop is untouched.
 * ================================================================ */

/* Kill the 300ms double-tap-zoom delay + accidental zoom when
 * rapid-tapping Pass on consecutive cards. */
button, select, input[type="range"], .card, .for-you-card {
  touch-action: manipulation;
}
body { -webkit-tap-highlight-color: transparent; }

@media (hover: none) {
  /* Card quick-actions (Watched/Save/Pass) are the app's most-used
   * controls and were ~24px tall — below every touch-target
   * guideline. Bump to comfortable thumb size. */
  .card-act { padding: 9px 12px; font-size: 12px; gap: 6px; }
  .card-act-icon { font-size: 14px; }
  /* On touch the quick-acts are always visible, which collided with
   * the 🆓 Free badge (both top-right). When a Free badge exists,
   * start the button stack below it. (:has is supported by every
   * mobile browser this app targets; older ones just keep the old
   * overlap.) */
  .card:has(.card-free-badge) .card-quick-acts { top: 42px; }
  /* Range-slider thumbs: 18px is a fiddly drag target. */
  .range-slider input[type="range"]::-webkit-slider-thumb {
    width: 24px; height: 24px; margin-top: -10px;
  }
  .range-slider input[type="range"]::-moz-range-thumb {
    width: 24px; height: 24px;
  }
  /* Star rating in the detail modal. */
  .my-rating-star { font-size: 26px; padding: 4px 6px; }
}

@media (max-width: 540px) {
  /* Reclaim vertical space: on phones only the topbar stays sticky.
   * (Search scrolls away — couch browsing is poster-first.) */
  .search-row { position: static; }

  /* Content header: active filters scroll beside the drawer button;
   * discovery actions and media toggles share the next line; sort
   * remains a full-width final row. */
  .content-header {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 10px 14px;
  }
  .mobile-filter-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
  }
  .mobile-filter-row .filters-toggle {
    flex: 0 0 auto;
    padding: 8px 12px;
    font-size: 13px;
  }
  .active-filter-chips {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    padding: 1px 2px;
  }
  .active-filter-chips:empty { display: none; }
  .active-filter-chips::-webkit-scrollbar { display: none; }
  .active-filter-chip {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: stretch;
    min-height: 36px;
    overflow: hidden;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.42);
    border-radius: 999px;
  }
  .active-filter-chip button {
    border: 0;
    color: var(--text);
    font: inherit;
    cursor: pointer;
  }
  .active-filter-chip-edit {
    max-width: 190px;
    overflow: hidden;
    padding: 7px 6px 7px 11px;
    background: transparent;
    font-size: 11px !important;
    font-weight: 600 !important;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .active-filter-chip-remove {
    display: grid;
    place-items: center;
    width: 32px;
    padding: 0 7px 1px 5px;
    background: rgba(245, 158, 11, 0.10);
    color: var(--text-muted) !important;
    font-size: 18px !important;
    line-height: 1;
  }
  .active-filter-chip-remove:active { background: rgba(245, 158, 11, 0.28); }
  .content-actions-row {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    min-width: 0;
  }
  .content-actions-row > .content-btn {
    flex: 1 1 auto;
    min-height: 38px;
    padding: 8px 7px;
    font-size: 11px;
  }
  .media-type-btn {
    min-height: 38px;
    padding: 8px 6px;
    font-size: 11px;
  }
  .media-type-toggles { margin-left: 0; gap: 2px; padding: 2px; }
  .content-sort { flex: 1 1 100%; }
  .content-sort select { flex: 1; width: 100%; min-width: 0; }

  /* Genre chips: real tap targets, and give the row a little more
   * breathing room since it horizontal-scrolls anyway. */
  .genre-chip { padding: 9px 16px; font-size: 13px; }

  /* Top nav: taller buttons; let the row scroll sideways instead of
   * squeezing five tabs into 375px. flex/min-width let the nav (a
   * flex item) shrink below its content width — without that it
   * refuses to shrink and the whole PAGE scrolls horizontally. */
  .topbar { padding: 10px 10px; }
  .topbar-nav { overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 0; }
  .topbar-nav::-webkit-scrollbar { display: none; }
  /* A soft edge indicates that more tabs are available off-screen.
   * JS removes each fade as that end of the row is reached. */
  .topbar-nav.nav-overflow-right:not(.nav-overflow-left) {
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 30px), transparent 100%);
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 30px), transparent 100%);
  }
  .topbar-nav.nav-overflow-left:not(.nav-overflow-right) {
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 30px, #000 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 30px, #000 100%);
  }
  .topbar-nav.nav-overflow-left.nav-overflow-right {
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 30px, #000 calc(100% - 30px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 30px, #000 calc(100% - 30px), transparent 100%);
  }
  .nav-btn { padding: 9px 12px; flex: 0 0 auto; }

  /* Detail-modal action buttons are icon-only here — make the icons
   * comfortably tappable. */
  .detail-action-btn { padding: 11px 13px; }
  .dab-icon { font-size: 16px; }
}

@media (max-width: 360px) {
  .content-actions-row { gap: 3px; }
  .content-actions-row > .content-btn {
    padding-right: 4px;
    padding-left: 4px;
    font-size: 10.5px;
  }
  .media-type-btn {
    padding-right: 4px;
    padding-left: 4px;
    font-size: 10.5px;
  }
  .action-label-full { display: none; }
  .action-label-short { display: inline; }
}

/* ================================================================
 * Swipe triage on cards (touch devices, Discover view).
 * ← Pass · ↑ Watched · → Save. JS drives the transforms; these
 * classes provide the transitions and the direction badge.
 * ================================================================ */
@media (hover: none) {
  /* Horizontal gestures belong to the swipe engine; vertical stays
   * with the browser for page scrolling. Overrides the generic
   * touch-action: manipulation set above. */
  #grid .card { touch-action: pan-y; }
}
.card.swiping {
  transition: none;
  z-index: 20;           /* dragged card floats over its neighbors */
}
.card.swipe-reset  { transition: transform 0.18s ease, opacity 0.18s ease; }
.card.swipe-commit {
  transition: transform 0.22s ease-in, opacity 0.22s ease-in;
  pointer-events: none;
  z-index: 20;
}
.swipe-badge {
  position: absolute;
  top: 38%; left: 50%;
  transform: translate(-50%, -50%) rotate(-6deg);
  padding: 8px 14px; border-radius: 8px;
  font-size: 16px; font-weight: 800; letter-spacing: 0.5px;
  pointer-events: none;
  opacity: 0;
  z-index: 6;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}
.swipe-badge-pass    { background: rgba(248, 113, 113, 0.95); color: #2b0606; }
.swipe-badge-save    { background: rgba(245, 158, 11, 0.95); color: #1b1305; }
.swipe-badge-watched { background: rgba(74, 222, 128, 0.95); color: #06240f; }
/* Double-tap feedback: same badge, but self-animating (drag badges
 * have their opacity driven frame-by-frame from JS instead). */
.swipe-badge-pulse   { transition: opacity 0.25s ease; }

/* One-time gesture hint toast. */
.swipe-hint-toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13px;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  max-width: calc(100vw - 32px);
  white-space: nowrap;
}
.swipe-hint-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.swipe-hint-toast b { color: var(--accent); }

/* ================================================================
 * "Play on Roku" row — lives under the Where-to-watch strip in the
 * detail modal. ECP control over the local network; see app.js.
 * ================================================================ */
.roku-row {
  margin-top: 10px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.roku-row:empty { display: none; }
.roku-play-btn {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid #6f2da8;          /* Roku purple */
  border-radius: 999px;
  padding: 8px 16px; font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.roku-play-btn:hover { background: #6f2da8; color: #fff; }
.roku-gear-btn {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--bg-elev-2); border-radius: 999px;
  width: 34px; height: 34px; font-size: 14px; cursor: pointer;
}
.roku-gear-btn:hover { border-color: var(--accent); color: var(--text); }
.roku-setup-link {
  background: none; border: none;
  color: var(--text-muted); font: inherit; font-size: 12px;
  cursor: pointer; padding: 4px 0;
  text-decoration: underline dotted;
}
.roku-setup-link:hover { color: var(--text); }
.roku-status { font-size: 12px; color: var(--text-muted); }
.roku-setup { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.roku-setup-hint { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.roku-setup-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.roku-setup-controls input {
  flex: 1 1 140px; min-width: 0;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--bg-elev-2); border-radius: 6px;
  padding: 8px 10px; font: inherit; font-size: 14px;
  outline: none;
}
.roku-setup-controls input:focus { border-color: var(--accent); }

/* Keep primary navigation usable beside the shared account controls. */
@media (max-width: 540px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .topbar-nav { order: 2; flex: 1 0 100%; width: 100%; }
  .topbar-actions { margin-left: auto; }
}

/* Catalog attribution (required by the Streaming Availability API terms):
 * a persistent page footer, the detail panel and Settings › Help. */
.app-footer {
  padding: 18px 16px 28px;
  border-top: 1px solid var(--bg-elev-2);
  text-align: center;
}
.catalog-attribution {
  font-size: 12px; line-height: 1.5; color: var(--text-muted);
}
.catalog-attribution a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.catalog-attribution a:hover { color: var(--accent); }
.catalog-attribution a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.detail-offers-strip .catalog-attribution { margin-top: 12px; }
