:root {
  --bg: #f4efe4;
  --surface: #fffaf0;
  --surface-2: #ebe4d4;
  --ink: #1c1a17;
  --ink-soft: #5a554c;
  --line: #d6ccb8;
  --accent: #c8342b;
  --accent-ink: #ffffff;
  --highlight: #f2c230;
  --shadow: 4px 4px 0 var(--ink);
  --radius: 6px;
  --font-display: "Archivo Black", Impact, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141311;
    --surface: #1f1d1a;
    --surface-2: #2a2723;
    --ink: #efe8da;
    --ink-soft: #a9a193;
    --line: #3a362f;
    --accent: #ef5a4f;
    --accent-ink: #141311;
    --highlight: #f2c230;
    --shadow: 4px 4px 0 #000;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141311;
  --surface: #1f1d1a;
  --surface-2: #2a2723;
  --ink: #efe8da;
  --ink-soft: #a9a193;
  --line: #3a362f;
  --accent: #ef5a4f;
  --accent-ink: #141311;
  --highlight: #f2c230;
  --shadow: 4px 4px 0 #000;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 64px; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 400; line-height: 1.05; margin: 0; }

a { color: inherit; }

/* ---------- Masthead ---------- */

.masthead { background: #1c1a17; color: #f4efe4; }
.masthead-inner { position: relative; padding-top: 56px; padding-bottom: 40px; }
.kicker {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 13px;
  color: var(--highlight);
  margin: 0 0 12px;
}
.masthead h1 {
  font-size: clamp(34px, 9vw, 88px);
  overflow-wrap: anywhere;
  letter-spacing: -.01em;
  text-transform: uppercase;
}
.lede { max-width: 620px; font-size: 18px; margin: 18px 0 0; opacity: .85; }

.theme-toggle {
  position: absolute; top: 16px; right: 16px;
  background: transparent; color: inherit;
  border: 1px solid currentColor; border-radius: 999px;
  font: 500 13px var(--font-body); padding: 6px 12px; cursor: pointer;
  opacity: .8;
}
.theme-toggle:hover { opacity: 1; }

.tabs {
  position: sticky; top: 0; z-index: 10;
  background: var(--accent);
  border-bottom: 3px solid var(--ink);
}
.tabs-inner { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  color: var(--accent-ink);
  text-decoration: none;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 12px 12px;
  white-space: nowrap;
}
.tabs a:hover { background: rgba(0,0,0,.15); }

/* ---------- Sections ---------- */

.section { padding: 56px 0 8px; }
.section h2 { font-size: clamp(30px, 5vw, 44px); text-transform: uppercase; }
.section-note { color: var(--ink-soft); margin: 8px 0 24px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 24px; }

input[type="search"], select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-width: 0;
}
input[type="search"] { flex: 1 1 260px; }
select { flex: 0 1 260px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font: 500 13px var(--font-body);
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--bg); }
.chip .swatch { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }

.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-soft); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font: 500 12px var(--font-body);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  background: var(--surface);
  white-space: nowrap;
}
.tag .swatch { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tag.ghost { border-style: dashed; color: var(--ink-soft); }
.tag.ghost .swatch { background: transparent; border: 1.5px solid var(--c); }

/* ---------- Films ---------- */

.film-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; }
.film {
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
  border-top: 10px solid var(--c);
  display: flex; flex-direction: column; gap: 8px;
}
.film .year { font-family: var(--font-mono); font-size: 13px; color: var(--ink-soft); }
.film h3 { font-size: 22px; text-transform: uppercase; }
.film { position: relative; transition: transform .12s; }
.film:hover, .film:has(.film-open:focus-visible) { transform: translate(-2px, -2px); }
.film:has(.film-open:focus-visible) { outline: 3px solid var(--c); outline-offset: 2px; }
.film-open { font: inherit; color: inherit; text-transform: inherit; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.film-open:focus-visible { outline: none; }
/* Stretch the title button over the whole card so any click opens the film. */
.film-open::after { content: ""; position: absolute; inset: 0; }
.char-dialog > #dlgBody > .chip { margin-top: 4px; }
.film .setting { font-size: 13px; font-weight: 600; }
.film p { margin: 0; font-size: 15px; }
.film .stats { margin-top: auto; padding-top: 8px; font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); }

/* ---------- Timeline ---------- */

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 118px; top: 6px; bottom: 6px;
  width: 3px; background: var(--ink);
}
.event { display: grid; grid-template-columns: 104px 1fr; gap: 32px; padding: 0 0 22px; position: relative; }
.event .when {
  font-family: var(--font-mono); font-size: 13px; font-weight: 600;
  text-align: right; padding-top: 12px; color: var(--ink-soft);
}
.event .card {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 12px 16px 14px;
}
.event .card::before {
  content: ""; position: absolute; left: -24px; top: 14px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--c, var(--ink)); border: 3px solid var(--bg);
  box-shadow: 0 0 0 2px var(--ink);
}
.event.crossover .card { box-shadow: var(--shadow); }
.event h3 { font-family: var(--font-body); font-weight: 600; font-size: 17px; line-height: 1.3; }
.event p { margin: 6px 0 10px; font-size: 15px; }
.event .tags { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-block; margin-left: 8px; vertical-align: 2px;
  font: 600 10px var(--font-mono); text-transform: uppercase; letter-spacing: .08em;
  background: var(--highlight); color: #1c1a17; padding: 2px 6px; border-radius: 3px;
}

/* ---------- Characters ---------- */

.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.char {
  text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 6px;
  transition: transform .12s, box-shadow .12s;
}
.char:hover, .char:focus-visible { transform: translate(-2px, -2px); box-shadow: var(--shadow); outline: none; }
.char .name { font-weight: 600; font-size: 16px; line-height: 1.25; }
.char .actor { font-size: 13px; color: var(--ink-soft); }
.char .group { font: 600 11px var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.char .film-dots { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.char .film-dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.char .film-dots i.ref { background: transparent; border: 2px solid var(--c); }
.empty { color: var(--ink-soft); font-style: italic; }

/* ---------- Dialog ---------- */

.char-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
  padding: 24px;
}
.char-dialog::backdrop { background: rgba(20, 19, 17, .55); }
.dlg-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: 0; color: var(--ink); font-size: 28px; line-height: 1; cursor: pointer;
}
.char-dialog h3 { font-size: 28px; text-transform: uppercase; padding-right: 32px; }
.char-dialog .actor { color: var(--ink-soft); margin: 4px 0 14px; }
.char-dialog h4 { font: 600 12px var(--font-mono); text-transform: uppercase; letter-spacing: .08em; margin: 18px 0 8px; color: var(--ink-soft); }
.char-dialog .tags { display: flex; flex-wrap: wrap; gap: 6px; }
.rel-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.rel-list button {
  font: inherit; color: var(--ink); background: var(--surface-2); border: 0; border-radius: 4px;
  padding: 6px 10px; width: 100%; text-align: left; cursor: pointer; display: flex; justify-content: space-between; gap: 12px;
}
.rel-list button:hover { background: var(--line); }
.rel-list .rel { color: var(--ink-soft); font-size: 14px; text-align: right; }

/* ---------- Matrix ---------- */

.matrix-scroll {
  overflow-x: auto;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
}
.matrix { border-collapse: collapse; width: 100%; font-size: 14px; }
.matrix th, .matrix td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.matrix thead th {
  font: 600 11px var(--font-mono); text-transform: uppercase; letter-spacing: .04em;
  vertical-align: bottom; background: var(--surface-2); position: sticky; top: 0;
  border-bottom: 2px solid var(--ink); border-top: 4px solid var(--c, transparent);
}
.matrix thead th:not(:first-child) { text-align: center; min-width: 74px; }
.matrix tbody th {
  text-align: left; font-weight: 500; white-space: nowrap;
  position: sticky; left: 0; background: var(--surface); z-index: 1;
}
.matrix tbody th button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.matrix td { text-align: center; }
.matrix tbody tr:hover th, .matrix tbody tr:hover td { background: var(--surface-2); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--c, var(--ink)); vertical-align: -1px; }
.dot.ref { background: transparent; border: 2px solid var(--c, var(--ink)); }
.section-note .dot.ref { margin-left: 12px; }
.matrix .count { font-family: var(--font-mono); color: var(--ink-soft); }

/* ---------- Crossovers ---------- */

#crossoverChips { margin-bottom: 20px; }
.cross-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.cross {
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.cross .route { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.cross .arrow { font-family: var(--font-mono); color: var(--ink-soft); }
.cross h3 { font-family: var(--font-body); font-weight: 600; font-size: 17px; line-height: 1.3; }
.cross p { margin: 6px 0 0; font-size: 15px; }
.cross .type { font: 600 11px var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }

/* ---------- Footer ---------- */

.footer { margin-top: 64px; border-top: 3px solid var(--ink); color: var(--ink-soft); }
.footer-inner {
  display: flex; align-items: center; gap: 20px;
  padding-top: 18px; padding-bottom: 26px;
  font: 11px var(--font-mono); text-transform: uppercase; letter-spacing: .09em;
}
.footer__mark {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px;
  background: var(--accent); color: var(--accent-ink);
  font: 17px var(--font-display); letter-spacing: 0;
  transform: rotate(-5deg);
}
.footer p { display: flex; align-items: center; gap: 8px; margin: 0; }
.footer p img { width: 28px; height: 28px; flex: none; object-fit: contain; }
.footer a { color: var(--accent); }
.footer__meta { display: block !important; margin-left: auto !important; text-align: right; line-height: 1.5; font-size: 9px; }

/* ---------- Scroll to top ---------- */

.scroll-top {
  position: fixed; right: 24px; bottom: 24px; z-index: 20;
  width: 52px; height: 52px;
  border: 2px solid var(--ink); border-radius: 50%;
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 26px; line-height: 1; cursor: pointer;
  opacity: 0; visibility: hidden; transform: translateY(12px);
  transition: opacity .2s, transform .2s, visibility .2s, background .15s;
}
.scroll-top.is-visible { opacity: 1; visibility: visible; transform: translateY(0); }
.scroll-top:hover { background: var(--highlight); color: #1c1a17; }

/* ---------- Easter eggs ---------- */

/* A manual popover, so it sits in the top layer above an open dialog. */
.toast {
  position: fixed; inset: auto auto 24px 50%; margin: 0;
  max-width: calc(100% - 160px); transform: translate(-50%, 12px);
  background: var(--ink); color: var(--bg);
  border: 2px solid var(--ink); border-radius: var(--radius);
  box-shadow: 4px 4px 0 var(--accent);
  padding: 10px 16px; font: 600 14px var(--font-mono); text-align: center;
  opacity: 0; transition: opacity .2s, transform .2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@keyframes berserk {
  10%, 90% { transform: translate(-2px, 1px) rotate(-.4deg); }
  20%, 80% { transform: translate(3px, -2px) rotate(.5deg); }
  30%, 50%, 70% { transform: translate(-5px, 2px) rotate(-.8deg); }
  40%, 60% { transform: translate(5px, -1px) rotate(.8deg); }
}
.berserk main { animation: berserk .6s 2; }
@media (prefers-reduced-motion: reduce) {
  .berserk main { animation: none; }
  .toast { transition: none; }
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  .masthead-inner { padding-top: 64px; }
  .tabs-inner { flex-wrap: wrap; justify-content: center; gap: 0 2px; overflow-x: visible; }
  .tabs a { font-size: 13px; padding: 9px 8px; }
  .timeline::before { left: 7px; }
  .event { grid-template-columns: 1fr; gap: 4px; padding-left: 28px; }
  .event .when { text-align: left; padding-top: 0; }
  .event .card::before { left: -29px; top: -18px; }
  .cross-grid { grid-template-columns: 1fr; }
  .footer-inner { display: grid; grid-template-columns: auto 1fr; gap: 12px; }
  .footer__meta { grid-column: 2; margin: 0 !important; text-align: left; }
  .scroll-top { right: 16px; bottom: 16px; width: 46px; height: 46px; }
}
