:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --sunken: #eef2f5;
  --ink: #142233;
  --ink-2: #3d4b5c;
  --ink-3: #6a7786;
  --line: #dde3e9;
  --dc: #174e95;
  --mcu: #b3163f;
  --marvel: #d0566f;
  --other: #1d6d4d;
  --accent: #b3163f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --top-h: 0px;
  --tabs-h: calc(58px + env(safe-area-inset-bottom));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1620; --surface: #17212d; --sunken: #1d2937;
    --ink: #e9eef3; --ink-2: #b9c4cf; --ink-3: #8794a2; --line: #2a3644;
    --dc: #6a9fe6; --mcu: #f0587c; --marvel: #f08aa0; --other: #4cbb8b; --accent: #f0587c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1620; --surface: #17212d; --sunken: #1d2937;
  --ink: #e9eef3; --ink-2: #b9c4cf; --ink-3: #8794a2; --line: #2a3644;
  --dc: #6a9fe6; --mcu: #f0587c; --marvel: #f08aa0; --other: #4cbb8b; --accent: #f0587c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--top-h) + 8px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--sans);
  padding-bottom: calc(var(--tabs-h) + 24px);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
a { color: var(--dc); }
[hidden] { display: none !important; }

/* Top bar */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px 6px; max-width: 760px; margin: 0 auto; }
.brand { display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
.kicker { font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.wordmark { font: 400 25px/1.1 var(--serif); letter-spacing: -.01em; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; color: var(--ink-2); }
.icon-btn:active, .icon-btn[aria-pressed="true"] { background: var(--sunken); color: var(--ink); }

.search-row { display: flex; gap: 10px; align-items: center; padding: 0 16px 8px; max-width: 760px; margin: 0 auto; }
.search-row input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px;
}
.search-row input:focus { outline: 2px solid var(--dc); outline-offset: -1px; }
.text-btn { font-weight: 600; color: var(--dc); padding: 8px 2px; }

.icon-btn { position: relative; }
.badge { position: absolute; top: 5px; right: 4px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; line-height: 17px; text-align: center; }
.icon-btn[aria-expanded="true"] { background: var(--ink); color: var(--bg); }

.panel { max-width: 760px; margin: 0 auto; padding: 2px 16px 10px; display: grid; gap: 10px; animation: drop .18s ease-out; }
@keyframes drop { from { opacity: 0; transform: translateY(-6px); } }
.prow { display: flex; align-items: center; gap: 6px; }
.prow.chips { overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.prow.chips::-webkit-scrollbar { display: none; }
.logos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.logo {
  position: relative; height: 52px; border-radius: 12px; background: #fff;
  border: 1px solid var(--line); display: grid; place-items: center; padding: 8px;
  transition: opacity .15s, box-shadow .15s;
}
.logo img { max-width: 100%; max-height: 26px; display: block; }
.logo img.round { max-height: 36px; }
.logo svg.other { width: 34px; height: 34px; fill: var(--other); stroke: none; }
.logo svg.other path { fill: #fff; }
.logo[aria-pressed="true"] { box-shadow: 0 0 0 2.5px var(--ink); border-color: transparent; }
.logo[aria-pressed="true"]::after { content: "✓"; position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); color: var(--bg); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.logo.dim { opacity: .4; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; font-weight: 600; color: var(--ink-2); white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.prow .sep { flex: none; width: 1px; height: 20px; background: var(--line); margin: 0 2px; }
.watchrow { justify-content: space-between; }
.seg { display: inline-grid; grid-auto-flow: column; background: var(--sunken); border-radius: 11px; padding: 3px; }
.seg button { height: 30px; padding: 0 14px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--ink-3); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.jumps { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.jumps[hidden] { display: none; }
.pick { position: relative; display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 5px 12px 6px; }
.pick span { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.pick select { appearance: none; -webkit-appearance: none; width: 100%; border: 0; background: none; color: var(--ink); font: 600 15px var(--sans); padding: 0 18px 0 0; }
.pick::after { content: ""; position: absolute; right: 12px; bottom: 13px; width: 7px; height: 7px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg); pointer-events: none; }
.status .clr { color: var(--accent); font-weight: 600; font-size: 12px; margin-left: 6px; }

.status { font-size: 12px; color: var(--ink-3); padding: 0 16px 7px; max-width: 760px; margin: 0 auto; display: flex; justify-content: space-between; gap: 12px; }
.status b { color: var(--ink-2); font-weight: 600; }
.progress { flex: none; }

/* Timeline */
main { max-width: 760px; margin: 0 auto; }
.era { padding: 28px 16px 6px; }
.era-kicker { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.era h2 { font: 400 32px/1.1 var(--serif); margin: 4px 0 6px; letter-spacing: -.01em; }
.era-counts { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-3); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.era-counts span b { color: var(--ink); margin-left: 4px; }

.year {
  position: sticky; top: var(--top-h); z-index: 5;
  display: flex; align-items: center; gap: 10px;
  margin: 14px 0 0; padding: 6px 16px; background: var(--sunken);
  font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums;
}
.year .squares { display: flex; gap: 3px; flex-wrap: wrap; }
.year .n { margin-left: auto; font-size: 11px; color: var(--ink-3); letter-spacing: .06em; text-transform: uppercase; }

.sq { width: 11px; height: 11px; border-radius: 2.5px; background: var(--c); position: relative; }
.sq.series { background: transparent; box-shadow: inset 0 0 0 1.6px var(--c); }
.sq.special { background: color-mix(in srgb, var(--c) 35%, transparent); box-shadow: inset 0 0 0 1.2px var(--c); }
.sq.anim::after { content: ""; position: absolute; right: -2px; top: -2px; width: 5px; height: 5px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 1px var(--sunken); }
.f-DC { --c: var(--dc); } .f-MCU { --c: var(--mcu); } .f-MARVEL { --c: var(--marvel); } .f-OTHER { --c: var(--other); }

.card {
  display: grid; grid-template-columns: 96px 1fr; gap: 14px;
  padding: 16px; border-bottom: 1px solid var(--line);
  scroll-margin-top: calc(var(--top-h) + 36px);
}
.card.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 14%, transparent); } to { background: transparent; } }
.poster { position: relative; display: block; width: 96px; aspect-ratio: 2/3; border-radius: 6px; overflow: hidden; background: var(--sunken); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.meta { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 0 6px; align-items: center; }
.meta .fr { color: var(--c); }
.meta i { font-style: normal; opacity: .5; }
.card h3 { font: 600 21px/1.2 var(--serif); margin: 3px 0 6px; letter-spacing: -.005em; text-wrap: balance; }
.card p { margin: 0; font-size: 15px; line-height: 1.55; color: var(--ink-2); }
.cast { margin-top: 8px !important; font-size: 13px !important; color: var(--ink-3) !important; }
.cast b { font-size: 10.5px; letter-spacing: .08em; font-weight: 700; margin-right: 4px; }
.card-actions { display: flex; align-items: center; gap: 4px; margin-top: 10px; margin-left: -8px; }
.act { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--ink-3); text-decoration: none; }
.act svg { width: 18px; height: 18px; }
.act:active { background: var(--sunken); }
.act.watched { color: var(--other); }
.act.watched svg { fill: color-mix(in srgb, var(--other) 18%, transparent); }
.card.is-watched .poster img { opacity: .55; filter: grayscale(.5); }
.card.is-watched .poster::after { content: "✓"; position: absolute; inset: auto 6px 6px auto; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--other); color: #fff; font-weight: 700; font-size: 14px; }

.empty { padding: 64px 24px; text-align: center; color: var(--ink-3); }
.empty strong { display: block; font: 400 24px var(--serif); color: var(--ink); margin-bottom: 6px; }

/* Maps */
.page-head { padding: 24px 16px 4px; }
.page-head .era-kicker { color: var(--ink-3); }
.page-head h2 { font: 400 34px/1.1 var(--serif); margin: 4px 0 4px; }
.page-head p { margin: 0; color: var(--ink-2); }
.mapnav { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 14px 16px 4px; }
.mapnav::-webkit-scrollbar { display: none; }
.franchise { padding: 20px 16px 8px; border-bottom: 1px solid var(--line); scroll-margin-top: calc(var(--top-h) + 8px); }
.franchise h3 { font: 400 28px/1.15 var(--serif); margin: 0; }
.franchise > p { margin: 2px 0 10px; color: var(--ink-3); font-size: 14px; }
.grp { display: grid; gap: 10px; padding: 14px 0; border-top: 1px dashed var(--line); }
.grp-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.mapnav .chip { text-decoration: none; }
.grp-span { font-weight: 700; font-variant-numeric: tabular-nums; }
.grp-note { font-size: 13.5px; color: var(--ink-3); line-height: 1.4; }
.actors { display: flex; flex-wrap: wrap; gap: 12px; }
.actor { width: 76px; text-decoration: none; color: inherit; }
.actor img { width: 76px; height: 100px; object-fit: cover; border-radius: 8px; background: var(--sunken); display: block; }
.actor b { display: block; font-size: 12.5px; line-height: 1.25; margin-top: 6px; }
.actor span { display: block; font-size: 11.5px; color: var(--ink-3); line-height: 1.3; }
.grp-blurb { color: var(--ink-2); font-size: 14px; margin: 0; }

/* Index */
.az-rail { position: fixed; right: 2px; top: 50%; transform: translateY(-50%); z-index: 8; display: flex; flex-direction: column; font-size: 10.5px; font-weight: 700; color: var(--dc); touch-action: none; padding: 4px 2px; }
.az-rail span { padding: 1px 6px; text-align: center; }
.letter { position: sticky; top: var(--top-h); background: var(--sunken); padding: 4px 16px; font-weight: 700; font-size: 13px; z-index: 4; }
.irow { display: flex; align-items: baseline; gap: 10px; width: 100%; text-align: left; padding: 11px 36px 11px 16px; border-bottom: 1px solid var(--line); }
.irow .t { flex: 1; min-width: 0; font-weight: 500; }
.irow .y { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.irow .sq { flex: none; transform: translateY(1px); }
.irow.is-watched .t { color: var(--ink-3); }
.irow.is-watched .t::after { content: " ✓"; color: var(--other); }

/* Comics */
.comic { padding: 18px 16px; border-bottom: 1px solid var(--line); }
.comic .yrs { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--accent); }
.comic h3 { font: 400 24px/1.2 var(--serif); margin: 2px 0 6px; }
.comic p { margin: 0; color: var(--ink-2); }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: var(--tabs-h); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--ink-3); }
.tabs button[aria-current="page"] { color: var(--ink); }
.tabs button[aria-current="page"] svg { stroke-width: 2.2; color: var(--accent); }

/* Sheet */
.sheet-scrim { position: fixed; inset: 0; background: rgb(8 14 22 / .45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 82vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto;
  box-shadow: 0 -10px 40px rgb(0 0 0 / .2);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 12px; }
.sheet h4 { margin: 18px 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.sheet h4:first-of-type { margin-top: 4px; }
.era-btn { display: flex; justify-content: space-between; align-items: baseline; width: 100%; text-align: left; padding: 10px 0; border-bottom: 1px solid var(--line); }
.era-btn span { font: 400 19px var(--serif); }
.era-btn small { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.years { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.years button { padding: 9px 0; border-radius: 10px; background: var(--sunken); font-weight: 600; font-variant-numeric: tabular-nums; font-size: 14px; }
.years button.cur { background: var(--ink); color: var(--bg); }
.row-btn { display: block; width: 100%; text-align: left; padding: 12px 0; border-bottom: 1px solid var(--line); font-weight: 600; }
.row-btn small { display: block; font-weight: 400; color: var(--ink-3); }

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .88); display: grid; place-items: center; padding: 24px; }
.lightbox img { max-width: 100%; max-height: 80vh; border-radius: 8px; }
.lightbox a { color: #fff; margin-top: 14px; display: inline-block; font-weight: 600; }
.lightbox div { text-align: center; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + 14px); z-index: 35;
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: var(--bg);
  padding: 10px 10px 10px 16px; border-radius: 14px; font-size: 14px;
  width: max-content; max-width: calc(100% - 32px);
  box-shadow: 0 8px 30px rgb(0 0 0 / .25);
}
.toast button { font-weight: 700; color: var(--bg); padding: 6px 8px; border-radius: 8px; background: color-mix(in srgb, var(--bg) 16%, transparent); }

@media (min-width: 560px) {
  .card { grid-template-columns: 128px 1fr; gap: 20px; padding: 20px 16px; }
  .poster { width: 128px; }
}
@media (prefers-reduced-motion: reduce) { .card.flash { animation: none; } html { scroll-behavior: auto; } }
