:root {
  --bg: #14101e;
  --surface: #1c1828;
  --surface-2: #251f33;
  --text: #f0ebf5;
  --muted: #a89db8;
  --accent: #c7a4ff;
  --accent-2: #ffb46b;
  --danger: #ff6b81;
  --radius: 10px;
  --poster-w: 110px;
  --poster-h: 165px;
  --gap: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ── Top bar ──────────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); padding: 10px 14px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid #2a2438;
}
.brand { font-weight: 700; letter-spacing: 0.5px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 24px; height: 24px; border-radius: 6px; display: block; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a {
  padding: 7px 12px; border-radius: 999px; color: var(--muted);
  white-space: nowrap; font-size: 14px;
}
.tabs a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn { font-size: 18px; padding: 4px 6px; }
.me { color: var(--muted); font-size: 13px; }

/* ── Main view ────────────────────────────────────────────── */
main { padding: 14px; max-width: 1400px; margin: 0 auto; }
section.rail { margin-bottom: 22px; }
section.rail h2 { font-size: 16px; margin: 4px 0 8px; color: var(--text); }
.rail-reason { color: var(--muted); font-size: 12px; margin-bottom: 8px; }

/* Horizontal rail */
.rail-scroll {
  display: flex; gap: var(--gap); overflow-x: auto; scroll-snap-type: x mandatory;
  padding-bottom: 6px;
}
.rail-scroll::-webkit-scrollbar { height: 6px; }
.rail-scroll::-webkit-scrollbar-thumb { background: #3a3252; border-radius: 3px; }

.card {
  width: var(--poster-w); flex: 0 0 var(--poster-w);
  scroll-snap-align: start; cursor: pointer; display: block;
}
/* Desktop-only hover affordance — posters lift slightly so it's obvious
   cards are clickable. No-op on touch and TV. */
@media (hover: hover) and (pointer: fine) {
  .card .poster { transition: transform 0.15s ease, box-shadow 0.15s ease; }
  .card:hover .poster {
    transform: translateY(-3px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  }
  .btn { transition: filter 0.12s ease; }
  .btn:hover { filter: brightness(1.15); }
}
.card .poster {
  width: var(--poster-w); height: var(--poster-h); border-radius: var(--radius);
  background: var(--surface-2) center/cover no-repeat;
  display: flex; align-items: flex-end; justify-content: flex-start;
  position: relative; overflow: hidden;
}
.card .poster .badges {
  position: absolute; top: 4px; left: 4px; display: flex; gap: 4px;
}
.card .poster .badge {
  background: rgba(0,0,0,0.6); color: #fff; font-size: 10px;
  padding: 2px 5px; border-radius: 4px; line-height: 1;
}
.card .meta { padding: 6px 2px 2px; }
.card .meta .t { font-size: 13px; line-height: 1.25; min-height: 32px; }
.card .meta .y { color: var(--muted); font-size: 11px; }
.card.no-poster .poster {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 11px; text-align: center; padding: 6px;
}

/* Grid for library / collection */
.grid {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(var(--poster-w), 1fr));
}

/* Title detail */
.detail { display: grid; gap: 20px; grid-template-columns: minmax(180px, 240px) 1fr; }
@media (max-width: 540px) { .detail { grid-template-columns: 120px 1fr; } }
.detail .poster {
  width: 100%; aspect-ratio: 2/3; background: var(--surface-2) center/cover no-repeat;
  border-radius: var(--radius);
}
.detail h1 { margin: 0 0 6px; font-size: 22px; line-height: 1.2; }
.detail .sub { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.detail .overview { color: #d9d2e5; font-size: 14px; margin: 12px 0; }
.detail .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.btn {
  background: var(--surface-2); color: var(--text); border: 1px solid #3a3252;
  border-radius: 999px; padding: 8px 14px; font-size: 14px;
}
.btn.on { background: var(--accent); color: #1a1626; border-color: var(--accent); }
.btn.on-pos { background: var(--accent-2); color: #1a1626; border-color: var(--accent-2); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn[disabled], .btn:disabled {
  opacity: 0.4; cursor: not-allowed; filter: grayscale(0.5);
}
.why {
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
  font-size: 13px; color: var(--muted);
}
.why h3 { margin: 0 0 6px; font-size: 13px; color: var(--text); }

/* Search */
.search-bar {
  display: flex; gap: 8px; align-items: center; margin-bottom: 14px;
}
.search-bar input {
  flex: 1; background: var(--surface-2); border: 1px solid #3a3252;
  color: var(--text); border-radius: var(--radius); padding: 10px 12px;
  font-size: 16px;
}
.filters { display: flex; gap: 6px; margin-bottom: 14px; }
.filters .chip {
  padding: 6px 12px; border-radius: 999px; background: var(--surface);
  font-size: 13px; color: var(--muted); cursor: pointer;
}
.filters .chip.on { background: var(--accent); color: #1a1626; }
.result-row {
  display: grid; grid-template-columns: 70px 1fr; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid #2a2438; cursor: pointer;
}
.result-row .poster { width: 70px; height: 105px; background: var(--surface-2) center/cover no-repeat; border-radius: 6px; }
.result-row .info .t { font-size: 15px; }
.result-row .info .y { color: var(--muted); font-size: 12px; margin-top: 2px; }
.result-row .state { font-size: 11px; color: var(--accent); margin-top: 4px; }

/* Collections list */
.col-row {
  display: block; padding: 12px 0; border-bottom: 1px solid #2a2438;
}
.col-row .name { font-size: 16px; }
.col-row .count { color: var(--muted); font-size: 12px; }
.col-row .preview { color: var(--muted); font-size: 12px; margin-top: 4px; }
.col-row .ai-badge { color: var(--accent); margin-right: 6px; }

/* Empty / loading */
.empty {
  text-align: center; color: var(--muted); padding: 40px 16px;
}
.spinner {
  width: 28px; height: 28px; border: 3px solid #3a3252; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid #3a3252;
  padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 100;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  max-width: calc(100vw - 32px);
}

/* Sheet (modal) */
.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.sheet[hidden] { display: none; }
.sheet-inner {
  background: var(--surface); border-top-left-radius: 16px; border-top-right-radius: 16px;
  width: 100%; max-width: 600px; padding: 16px; max-height: 80vh; overflow-y: auto;
  animation: sheet-up 0.18s ease-out;
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet-inner { animation: none; }
  .card .poster { transition: none; }
}
.sheet-inner h2 { margin: 0 0 12px; font-size: 18px; }
.sheet-list { list-style: none; padding: 0; margin: 0; }
.sheet-list li {
  padding: 12px; border-radius: var(--radius); cursor: pointer; background: var(--surface-2);
  margin-bottom: 6px;
}
.sheet-list li:hover, .sheet-list li:focus-visible { outline: 2px solid var(--accent); }

/* Attribution footer */
.attribution {
  text-align: center; color: var(--muted); font-size: 11px;
  padding: 24px 16px;
}

/* ── 10-foot / TV mode ─────────────────────────────────────────────────────
   Activated when the viewport is wide and pointer is coarse/none — i.e.
   Android TV's Chrome with a D-pad remote. */
@media (min-width: 1280px) and (pointer: coarse), (min-width: 1280px) and (pointer: none) {
  :root {
    --poster-w: 200px;
    --poster-h: 300px;
    --gap: 24px;
  }
  body { font-size: 22px; }
  .top { padding: 18px 36px; }
  .brand { font-size: 28px; }
  .tabs a { font-size: 22px; padding: 12px 22px; }
  main { padding: 28px 36px; }
  .card .meta .t { font-size: 18px; min-height: 46px; }
  .card .meta .y { font-size: 14px; }
  .btn { font-size: 20px; padding: 14px 24px; }
  .card:focus-visible .poster {
    outline: 4px double var(--accent); outline-offset: 4px;
  }
  /* hide cursor-only affordances */
  .icon-btn { font-size: 28px; }
  .hint-bar {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: rgba(0,0,0,0.7); color: var(--muted);
    padding: 12px 24px; font-size: 16px; text-align: center;
    transition: opacity 0.5s ease;
  }
  .hint-bar.faded { opacity: 0; pointer-events: none; }
}

/* Global focus-visible — works on TV too */
a:focus-visible, .card:focus-visible, .chip:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px;
}

/* Desktop / wide screens — slightly bigger than phone, but not chunky like a TV. */
@media (min-width: 900px) and (pointer: fine) {
  :root { --poster-w: 128px; --poster-h: 192px; --gap: 14px; }
}
@media (min-width: 1400px) and (pointer: fine) {
  :root { --poster-w: 150px; --poster-h: 225px; --gap: 16px; }
}

/* Detail page is currently a tight 2-column grid that wastes width on a
    desktop monitor. Cap the column on wide screens so reading width stays
    sensible while letting cards / rails below use full width. */
@media (min-width: 1000px) {
  .detail { grid-template-columns: 280px 1fr; max-width: 1100px; }
}

/* Edit items sheet */
.edit-row {
  display: grid;
  grid-template-columns: 50px 1fr 40px;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #2a2438;
  cursor: pointer;
}
.edit-row .poster {
  width: 50px; height: 75px;
  background: var(--surface-2) center/cover no-repeat;
  border-radius: 6px;
}
.edit-row .info { font-size: 14px; }
.edit-row .info .t { font-size: 15px; }
.edit-row .info .y { color: var(--muted); font-size: 12px; margin-top: 2px; }
.edit-row .check { font-size: 18px; text-align: center; }

/* Move review sheet */
.review-section {
  border-top: 1px solid #2a2438;
  margin-top: 16px;
  padding-top: 16px;
}
.review-section:first-child { border-top: none; margin-top: 0; padding-top: 0; }
.review-count { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.review-posters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.review-posters .poster {
  width: 60px; height: 90px;
  background: var(--surface-2) center/cover no-repeat;
  border-radius: 6px;
}
.review-name { font-size: 16px; margin-bottom: 10px; }
.review-name .ai-name { color: var(--accent); }
.review-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.review-prior { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.naming-spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid #3a3252;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-left: 6px;
}

/* Trailer sheet */
.trailer-wrap {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.trailer-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
