:root {
  --bg: #16121f;
  --panel: #221c2f;
  --panel-2: #2c2540;
  --text: #f4eefc;
  --muted: #a99fbd;
  --accent: #ff8a3d;
  --accent-2: #ff4f8b;
  --good: #46d39a;
  --bad: #ff6b6b;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
#app {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px calc(96px + env(safe-area-inset-bottom));
}
h1 { font-size: 28px; margin: 4px 0 6px; letter-spacing: -0.02em; }
h2 { font-size: 20px; margin: 24px 0 10px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--accent);
}
.brand {
  font-weight: 800; font-size: 34px; letter-spacing: -0.03em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* Buttons */
.btn {
  display: block; width: 100%;
  border: 0; border-radius: 14px;
  padding: 15px 18px; font: inherit; font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #1a1020; text-align: center; text-decoration: none;
  cursor: pointer;
}
.btn.secondary { background: var(--panel-2); color: var(--text); }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 600; }
.btn:active { transform: scale(0.98); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 10px; }

/* Cards */
.card { background: var(--panel); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }

/* Generated "poster" */
.poster {
  position: relative; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 3 / 2; padding: 18px;
  display: flex; flex-direction: column; justify-content: flex-end;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.poster::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.04) 0 2px, transparent 2px 4px);
  pointer-events: none;
}
.poster .ptitle { font-size: 28px; font-weight: 800; line-height: 1.05; letter-spacing: -0.02em; text-shadow: 0 2px 12px rgba(0,0,0,0.35); }
.poster .pyear { font-weight: 700; opacity: 0.85; margin-top: 4px; }
.poster.small { aspect-ratio: auto; padding: 12px; min-height: 64px; box-shadow: none; }
.poster.small .ptitle { font-size: 16px; }

.meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip {
  background: var(--panel-2); color: var(--text);
  border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 600;
}
.chip.hot { background: rgba(255,138,61,0.18); color: var(--accent); }

.dots { letter-spacing: 2px; color: var(--accent); }

/* Lines */
.line { background: var(--panel); border-radius: 14px; padding: 14px 16px; border-left: 4px solid var(--accent); }
.line + .line { margin-top: 10px; }
.line .q { font-weight: 700; font-size: 17px; }
.line .w { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* Year range */
.years { display: flex; gap: 12px; align-items: center; margin: 18px 0; }
.years label { flex: 1; font-size: 13px; color: var(--muted); }
select {
  width: 100%; margin-top: 6px; font: inherit; font-size: 20px; font-weight: 700;
  padding: 12px; border-radius: 12px; border: 0;
  background: var(--panel-2); color: var(--text);
}

/* Progress bars */
.bar { height: 12px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; }
.era { margin-top: 14px; }
.era .lbl { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.big-num { font-size: 56px; font-weight: 800; letter-spacing: -0.04em; line-height: 1; }

/* Library list */
.lib-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border-radius: 14px; padding: 10px 12px;
  text-decoration: none; color: inherit;
}
.lib-item + .lib-item { margin-top: 8px; }
.swatch { width: 44px; height: 44px; border-radius: 10px; flex: none; }
.lib-item .info { flex: 1; min-width: 0; }
.lib-item .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.status.watched { background: rgba(70,211,154,0.18); color: var(--good); }
.status.seen { background: rgba(70,211,154,0.12); color: var(--good); }
.status.kinda { background: rgba(255,138,61,0.15); color: var(--accent); }

.filters { display: flex; gap: 8px; overflow-x: auto; margin: 10px 0 14px; padding-bottom: 4px; }
.filters button {
  border: 0; font: inherit; font-size: 14px; font-weight: 600;
  padding: 7px 13px; border-radius: 999px; background: var(--panel-2); color: var(--muted);
  white-space: nowrap; cursor: pointer;
}
.filters button.on { background: var(--text); color: var(--bg); }

/* Quiz */
.quiz-line { font-size: 22px; font-weight: 800; line-height: 1.25; margin: 14px 0 20px; }
.opt {
  display: block; width: 100%; text-align: left;
  border: 2px solid transparent; border-radius: 14px;
  padding: 14px 16px; font: inherit; font-weight: 600;
  background: var(--panel); color: var(--text); cursor: pointer;
}
.opt + .opt { margin-top: 10px; }
.opt.right { border-color: var(--good); background: rgba(70,211,154,0.12); }
.opt.wrong { border-color: var(--bad); background: rgba(255,107,107,0.10); }

.sort-count { text-align: center; color: var(--muted); font-size: 14px; margin: 12px 0; }
.back { color: var(--muted); text-decoration: none; font-weight: 600; display: inline-block; margin-bottom: 12px; }
.note { background: rgba(255,138,61,0.10); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 12px 0; }

/* Bottom tabs */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  background: rgba(22,18,31,0.94); backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
#tabs[hidden] { display: none; }
#tabs a {
  flex: 1; max-width: 170px; text-align: center; text-decoration: none;
  color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 0;
}
#tabs a span { display: block; font-size: 20px; line-height: 1.2; }
#tabs a.on { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); font-weight: 700;
  padding: 10px 16px; border-radius: 999px; font-size: 14px;
}

/* Real poster header: poster on the left, over a blurred copy of itself */
.hero {
  position: relative; overflow: hidden; border-radius: var(--radius);
  display: flex; align-items: flex-end; gap: 14px; padding: 16px;
  min-height: 200px; background: var(--panel);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.hero-bg {
  position: absolute; inset: -30px;
  background-size: cover; background-position: center;
  filter: blur(22px) brightness(0.45) saturate(1.2);
}
.hero img {
  position: relative; width: 112px; aspect-ratio: 2 / 3; object-fit: cover;
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); flex: none;
  background: var(--panel-2);
}
.hero-txt { position: relative; min-width: 0; padding-bottom: 4px; }
.hero .ptitle { font-size: 24px; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; text-shadow: 0 2px 12px rgba(0,0,0,0.5); }
.hero .pyear { font-weight: 700; opacity: 0.85; margin-top: 4px; }

/* Sort screen: the poster is what you recognize, so make it the star */
.hero.big { flex-direction: column; align-items: center; text-align: center; }
.hero.big img { width: 170px; }

img.swatch { width: 40px; height: 60px; object-fit: cover; background: var(--panel-2); }
.credit { color: var(--muted); font-size: 12px; text-align: center; margin-top: 24px; }

/* Favorites + search */
.chip.fav { border: 0; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip.fav.on { background: rgba(255,200,61,0.18); color: #ffc83d; }
.search {
  width: 100%; margin: 6px 0 4px; font: inherit; font-size: 16px;
  padding: 12px 14px; border-radius: 12px; border: 0;
  background: var(--panel-2); color: var(--text);
}
.search::placeholder { color: var(--muted); }

/* ── v2 layout: onboarding, grid, help ───────────────────────── */
.hidden { display: none !important; }
.filters { flex-wrap: wrap; overflow: visible; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin: -4px 0 14px; }
.brand.small { font-size: 22px; }
.help-btn {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-2); color: var(--text); text-decoration: none; font-weight: 800;
}

/* Welcome */
.welcome .brand { font-size: 28px; margin-top: 8px; }
.headline { font-size: 32px; line-height: 1.12; margin: 14px 0 12px; }
.lede { font-size: 17px; color: var(--text); opacity: 0.9; }
.example { background: var(--panel); border-radius: var(--radius); padding: 16px; margin: 20px 0; border-left: 4px solid var(--accent); }
.example-row { display: flex; gap: 14px; margin-top: 8px; align-items: flex-start; }
.example .q { font-weight: 800; font-size: 20px; margin-bottom: 4px; }
.example .w { color: var(--muted); font-size: 15px; }
img.swatch.tall, .swatch.tall { width: 64px; height: 96px; }
.steps { padding-left: 22px; margin: 0 0 22px; }
.steps li { margin-bottom: 10px; }
.fine { color: var(--muted); font-size: 13px; text-align: center; margin-top: 14px; }

/* Step 1 choices */
.choice {
  display: block; width: 100%; text-align: left; font: inherit; color: var(--text); cursor: pointer;
  background: var(--panel); border: 2px solid transparent; border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.choice.on { border-color: var(--accent); background: rgba(255,138,61,0.08); }
.choice-title { display: block; font-weight: 800; font-size: 18px; margin-bottom: 4px; }
.choice-body { display: block; color: var(--muted); font-size: 15px; }
.tag { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; background: var(--accent); color: #1a1020; border-radius: 999px; padding: 2px 8px; margin-left: 6px; vertical-align: middle; }

/* Sticky bottom action */
.sticky-cta {
  position: sticky; bottom: 0; margin: 18px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, rgba(22,18,31,0));
  display: flex; gap: 12px; align-items: center;
}
.sticky-cta .btn { flex: 1; }
.cta-count { font-weight: 700; color: var(--muted); white-space: nowrap; }
body:not(.has-tabs) #app { padding-bottom: 24px; }

/* Step 2 poster grid */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 8px; }
.tile {
  position: relative; border: 0; padding: 0; background: none; color: var(--text); font: inherit;
  cursor: pointer; text-align: left;
}
.tile img, .tile-ph {
  width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 10px; display: block;
  background: var(--panel-2); transition: opacity .15s, outline-color .15s;
  outline: 3px solid transparent; outline-offset: -3px;
}
.tile-ph { display: flex; align-items: flex-end; padding: 8px; font-size: 13px; font-weight: 700; }
.tile .tick {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 900; font-size: 15px;
  background: rgba(0,0,0,0.55); color: transparent; border: 2px solid rgba(255,255,255,0.7);
}
.tile.on img, .tile.on .tile-ph { outline-color: var(--good); opacity: 0.55; }
.tile.on .tick { background: var(--good); color: #0b2a1d; border-color: var(--good); }
.tile-name { display: block; font-size: 12px; line-height: 1.25; margin-top: 4px; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Up Next */
.summary { display: block; text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.summary .bar { display: block; margin-top: 6px; height: 6px; }
.tip { background: rgba(255,138,61,0.10); border: 1px solid rgba(255,138,61,0.35); border-radius: 14px; padding: 12px 14px; font-size: 15px; margin-bottom: 14px; }
button.link { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; padding: 0; margin-left: 4px; }
.more { display: inline-block; margin-top: 10px; color: var(--accent); font-weight: 700; text-decoration: none; }
.ext-link { display: block; text-align: center; color: var(--text); font-weight: 700; text-decoration: none; padding: 10px 0; }
.ext-link .muted { display: block; font-weight: 500; font-size: 12px; }

/* Segmented control */
.seg { display: flex; background: var(--panel-2); border-radius: 12px; padding: 4px; margin: 4px 0 8px; }
.seg button { flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 700; padding: 10px; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--text); color: var(--bg); }

/* Quiz feedback */
.feedback { border-radius: 14px; padding: 12px 14px; margin: 14px 0; font-size: 15px; }
.feedback.good { background: rgba(70,211,154,0.12); }
.feedback.bad { background: rgba(255,107,107,0.10); }

/* Progress */
.big-num .of { font-size: 24px; color: var(--muted); font-weight: 700; letter-spacing: 0; }
.big-num.code { font-size: 34px; letter-spacing: 0.08em; }
.lib-item.block { display: block; }
.lbl-row { display: flex; justify-content: space-between; margin-bottom: 8px; }
.btn.danger { color: var(--bad); }
textarea.search { resize: vertical; font-size: 13px; }
.code-input { font-size: 24px; letter-spacing: 0.12em; text-transform: uppercase; text-align: center; font-weight: 800; }
.error { color: var(--bad); min-height: 20px; font-size: 14px; }
.help p { margin-bottom: 14px; }

/* Toast with an action, and confirm sheet */
.toast { display: flex; gap: 14px; align-items: center; max-width: calc(100vw - 32px); }
.toast button { background: none; border: 0; color: var(--accent-2); font: inherit; font-weight: 800; cursor: pointer; }
.sheet-wrap { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet { background: var(--panel); border-radius: 18px 18px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); width: 100%; max-width: 520px; }

/* Desktop: a proper web page, tabs move to the top */
@media (min-width: 820px) {
  #app { max-width: 640px; padding-top: 84px; }
  body.has-tabs #tabs { top: 0; bottom: auto; border-top: 0; border-bottom: 1px solid rgba(255,255,255,0.06); padding: 8px; }
  #tabs a { display: flex; gap: 8px; align-items: center; justify-content: center; font-size: 15px; }
  #tabs a span { display: inline; font-size: 16px; }
  .grid { grid-template-columns: repeat(5, 1fr); }
  .headline { font-size: 44px; }
  .welcome { max-width: 600px; margin: 0 auto; }
}

/* ── v3: line lookup, poster placeholders, seen banner ─────────── */
.lookup { margin: 0 0 16px; }
.lookup-label { display: block; font-weight: 800; font-size: 17px; margin-bottom: 8px; }
.lookup-input { margin: 0; }
.lookup-results { margin-top: 10px; }
.hit { display: block; text-decoration: none; color: inherit; background: var(--panel); border-radius: 14px; padding: 14px 16px; border-left: 4px solid var(--accent); }
.hit + .hit { margin-top: 10px; }
.hit .q { font-weight: 800; font-size: 17px; }
.hit .w { color: var(--muted); font-size: 14px; margin-top: 4px; }
.hit .from { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 14px; color: var(--accent); }
.empty { background: var(--panel); border-radius: 14px; padding: 14px 16px; }
.empty p { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.example .lookup-label { font-size: 15px; }

/* Posters: title placeholder underneath, image fades in on top */
.pimg { position: relative; display: block; overflow: hidden; background: var(--panel-2); flex: none; }
.pimg .ph { position: absolute; inset: 0; display: flex; align-items: flex-end; padding: 6px; font-size: 11px; font-weight: 700; line-height: 1.15; color: #fff; overflow: hidden; }
.pimg img { position: relative; display: block; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s; }
.pimg img.in { opacity: 1; }
.pimg.swatch { width: 40px; height: 60px; border-radius: 8px; }
.pimg.swatch .ph { font-size: 0; }
.pimg.mini { width: 28px; height: 42px; border-radius: 5px; }
.pimg.mini .ph { font-size: 0; }
.pimg.tall { width: 64px; height: 96px; border-radius: 8px; }
.pimg.tile-img { width: 100%; aspect-ratio: 2 / 3; border-radius: 10px; outline: 3px solid transparent; outline-offset: -3px; transition: outline-color .15s; }
.pimg.tile-img .ph { font-size: 12px; padding: 8px; }
.tile.on .pimg.tile-img { outline-color: var(--good); }
.tile.on .pimg.tile-img img, .tile.on .pimg.tile-img .ph { opacity: 0.5; }
.tile .tick { box-shadow: 0 1px 6px rgba(0,0,0,0.6); }
.pimg.hero-img { position: relative; width: 112px; aspect-ratio: 2 / 3; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); }
.pimg.hero-img .ph { font-size: 13px; padding: 8px; }

/* Up Next */
.action-row { margin: 12px 0 4px; }
.action-row .btn { padding: 14px 10px; }
.done-banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: rgba(70,211,154,0.14); border: 1px solid rgba(70,211,154,0.4); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; font-size: 15px; }
.done-banner .link { color: var(--good); }
.tip p { margin: 0 0 10px; }
.btn.small-btn { width: auto; display: inline-block; padding: 10px 22px; }
.years-wrap .years { margin-top: 6px; }
.decades { margin-top: -4px; }

/* ── v4 polish ─────────────────────────────────────────────────── */
.share-btn { background: var(--panel-2); color: var(--text); text-decoration: none; font-weight: 700; font-size: 14px; padding: 7px 14px; border-radius: 999px; }
.reassure { margin: -6px 0 14px; }
.presets { margin: 4px 0 6px; }
.presets button.on { background: var(--text); color: var(--bg); }
.cta-count { font-weight: 600; font-size: 14px; }
details.settings { margin-top: 22px; }
details.settings > summary { cursor: pointer; font-weight: 800; font-size: 18px; padding: 10px 0; list-style: none; }
details.settings > summary::before { content: "▸ "; color: var(--muted); }
details.settings[open] > summary::before { content: "▾ "; }

/* ── Ranks and quiz leagues ───────────────────────────────────── */
.summary-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.summary-next { display: block; margin-top: 6px; font-size: 13px; font-weight: 500; }
.rank-badge { background: rgba(255,138,61,0.16); color: var(--accent); border-radius: 999px; padding: 3px 10px; font-weight: 800; font-size: 13px; white-space: nowrap; }
.rank-card, .league-card { background: linear-gradient(135deg, rgba(255,138,61,0.14), rgba(255,79,139,0.10)), var(--panel); }
.rank-top { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.rank-icon { font-size: 40px; line-height: 1; }
.rank-name { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.league-card .xp { margin-left: auto; font-size: 26px; font-weight: 800; }
.league-card .xp span { font-size: 13px; color: var(--muted); font-weight: 600; }
.league-card.compact { margin: 14px 0; }
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 14px; text-align: center; }
.stats-row b { display: block; font-size: 20px; }
.stats-row span { font-size: 11px; color: var(--muted); }
.ladder { margin-top: 12px; }
.ladder > summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 700; }
.ladder-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; color: var(--muted); border-bottom: 1px solid rgba(255,255,255,0.05); }
.ladder-row.done { color: var(--text); }
.ladder-row.on { color: var(--accent); font-weight: 800; }
.rank-up {
  display: flex; align-items: center; gap: 14px; margin-bottom: 14px; padding: 14px 16px; border-radius: 16px;
  background: linear-gradient(135deg, rgba(255,138,61,0.25), rgba(255,79,139,0.22));
  border: 1px solid rgba(255,138,61,0.5); animation: pop .5s ease-out;
}
.rank-up .big { font-size: 40px; line-height: 1; }
@keyframes pop { 0% { transform: scale(.9); opacity: 0; } 60% { transform: scale(1.03); opacity: 1; } 100% { transform: scale(1); } }
.score-row { display: flex; gap: 28px; margin: 6px 0 10px; }
.big-num.accent { color: var(--accent); }
.quiz-bar { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; font-weight: 700; color: var(--muted); background: var(--panel); border-radius: 12px; padding: 8px 12px; margin-bottom: 14px; }

/* Head to head */
.rivals { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.08); }
.rival-row { display: grid; grid-template-columns: 1fr auto 52px; gap: 10px; align-items: center; padding: 8px 0; font-size: 15px; }
.rival-row b { text-align: right; }
.rival-row span:nth-child(2) { color: var(--muted); font-size: 13px; }
.rival-row.me { color: var(--accent); font-weight: 700; }
.nick { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.nick input { flex: 1; font: inherit; font-size: 15px; padding: 8px 10px; border-radius: 10px; border: 0; background: var(--panel-2); color: var(--text); }
