:root {
  --bg: #ece6da;
  --surface: #fbf8f2;
  --ink: #221e18;
  --muted: #7c7468;
  --line: #ddd4c4;
  --accent: #b5402a;
  --accent-ink: #fff;
  --you: #2f6fd6;
  --truth: #b5402a;
  --good: #2e8b57;
  --ok: #c48a12;
  --bad: #9a9184;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 28px rgba(40, 30, 10, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15130f;
    --surface: #211e19;
    --ink: #f2ece2;
    --muted: #9d9588;
    --line: #36322b;
    --accent: #e0674d;
    --you: #6ea2ff;
    --truth: #ff7a5c;
    --good: #57c287;
    --ok: #e5ac3d;
    --bad: #6f685d;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 Inter, system-ui, -apple-system, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 1000;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: "Abril Fatface", serif; font-size: 26px; line-height: 1;
  color: var(--ink); text-decoration: none; letter-spacing: .01em;
}
.bar-mid { display: flex; gap: 6px; justify-content: center; }
.pip { width: 26px; height: 6px; border-radius: 3px; background: var(--line); }
.pip.done { background: var(--muted); }
.pip.now { background: var(--accent); }
.bar-right { justify-self: end; display: flex; align-items: center; gap: 8px; }
.bar-score { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.bar-score small { color: var(--muted); font-weight: 500; }

#app { max-width: 2200px; margin: 0 auto; padding: 20px 16px 56px; }
.screen { animation: rise .3s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px;
  padding: 15px 22px; font-weight: 600; font-size: 16px;
  background: var(--ink); color: var(--bg);
  transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.block { width: 100%; }
.muted { color: var(--muted); }

/* ---------- Start ---------- */
.start { display: grid; gap: 40px; grid-template-columns: 1.1fr 1fr; align-items: center; min-height: calc(100dvh - 200px); max-width: 1180px; margin: 0 auto; }
.start-copy .kicker { color: var(--accent); font-weight: 600; font-size: 14px; letter-spacing: .08em; text-transform: uppercase; }
.start-copy h1 {
  font-family: "Abril Fatface", serif; font-weight: 400;
  font-size: clamp(56px, 9vw, 112px); line-height: .92; margin: 10px 0 14px; letter-spacing: -.01em;
}
.start-copy .lede { font-size: 20px; max-width: 30ch; margin: 0 0 26px; }
.steps { list-style: none; padding: 0; margin: 0 0 28px; display: grid; gap: 12px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.steps .n {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--surface); border: 1px solid var(--line);
}
.start-cta { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.start-art { position: relative; height: 460px; overflow: hidden; }
.art-card { position: absolute; width: 230px; box-shadow: var(--shadow); border-radius: 4px; overflow: hidden; background: #ddd; }
.art-card .scan { width: 100% !important; height: 100% !important; }
.art-card:nth-child(1) { left: 2%; top: 40px; transform: rotate(-7deg); }
.art-card:nth-child(2) { left: 30%; top: 0; transform: rotate(3deg); z-index: 2; }
.art-card:nth-child(3) { left: 55%; top: 70px; transform: rotate(8deg); }
.start-art::after {
  content: ""; position: absolute; inset: 0; z-index: 3;
  background: linear-gradient(to bottom, transparent 55%, var(--bg));
}

/* ---------- Game layout ---------- */
.stage { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 24px; align-items: start; }
.menu-col { min-width: 0; }
.guess-col { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 14px; }

/* Desktop: a fixed-size frame for the menu (same size every round, filling the space left
   of the controls), and a guess column of the same height whose map takes the spare room.
   JS sets --stage-h (viewport height minus the top bar and padding). */
@media (min-width: 901px) {
  .stage { --stage-h: 640px; grid-template-columns: minmax(0, 1fr) clamp(400px, 26vw, 520px); }
  .menu-col { position: sticky; top: calc(var(--bar-h, 47px) + 20px); }
  .scan-frame {
    height: var(--stage-h); display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius); overflow: hidden;
    background-color: color-mix(in srgb, var(--ink) 7%, var(--bg));
    background-image:
      radial-gradient(ellipse at center, transparent 55%, color-mix(in srgb, var(--ink) 10%, transparent)),
      repeating-linear-gradient(0deg, color-mix(in srgb, var(--ink) 4%, transparent) 0 1px, transparent 1px 4px),
      repeating-linear-gradient(90deg, color-mix(in srgb, var(--ink) 3%, transparent) 0 1px, transparent 1px 5px);
    box-shadow: inset 0 0 0 1px var(--line);
  }
  .stage:not(.revealing) .guess-col { height: var(--stage-h); top: calc(var(--bar-h, 47px) + 20px); overflow-y: auto; overscroll-behavior: contain; }
  .stage:not(.revealing) .map-card { flex: 1 1 auto; min-height: 170px; display: flex; flex-direction: column; }
  .stage:not(.revealing) .map { flex: 1 1 auto; height: auto; min-height: 130px; }
  #app:has(> .stage:not(.revealing)) { padding-bottom: 20px; }   /* the stage fits the screen exactly: no scroll */
  .stage.revealing .guess-col { position: static; min-height: var(--stage-h); }
  .stage.revealing .map { height: 300px; }
}
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card h3 {
  margin: 0 0 10px; font-size: 12px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
}

/* Year picker */
.year-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.year-big {
  font-family: "Abril Fatface", serif; font-size: 54px; line-height: 1;
  font-variant-numeric: tabular-nums; text-align: center; flex: 1;
}
.era { text-align: center; color: var(--muted); font-size: 14px; margin-top: 2px; min-height: 20px; }
.nudge {
  width: 42px; height: 42px; border-radius: 50%; border: 1.5px solid var(--line);
  background: transparent; font-size: 20px; font-weight: 600; line-height: 1;
}
.nudge:active { background: var(--line); }
input[type=range].year-slider {
  -webkit-appearance: none; appearance: none; width: 100%; margin: 16px 0 4px;
  height: 8px; border-radius: 4px; background: var(--line); outline: none;
}
.year-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); border: 4px solid var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: grab;
}
.year-slider::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 4px solid var(--surface); cursor: grab;
}
.ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Map */
.map-card { padding: 0; overflow: hidden; }
.map-card h3 { padding: 14px 16px 0; }
.map { height: 280px; margin-top: 10px; background: var(--line); }
.map-hint { font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--accent); font-size: 13px; }
.leaflet-container { font: inherit; }
.map .leaflet-tile-pane { filter: saturate(.55) sepia(.12); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.4); }
}
.pin { position: relative; }
.pin span {
  position: absolute; left: 50%; bottom: 0; transform: translate(-50%, 0);
  width: 22px; height: 22px; border-radius: 50% 50% 50% 0; rotate: -45deg;
  border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.pin.you span { background: var(--you); }
.pin.truth span { background: var(--truth); }
.pin-label {
  background: var(--ink); color: var(--bg); border: 0; border-radius: 8px;
  font-weight: 600; font-size: 12px; padding: 3px 8px; box-shadow: none;
}
.pin-label::before { display: none; }

.actions { display: flex; gap: 10px; }
.actions .btn.accent { flex: 1; }
.hint-btn { font-size: 14px; padding: 12px 16px; }

/* Reveal */
.reveal .answer { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.reveal .answer-year { font-family: "Abril Fatface", serif; font-size: 44px; line-height: 1; }
.reveal .answer-place { font-weight: 600; font-size: 17px; text-align: right; }
.reveal .answer-place small { display: block; color: var(--muted); font-weight: 500; font-size: 13px; }
.timeline { position: relative; height: 34px; margin: 18px 6px 6px; }
.timeline .track { position: absolute; left: 0; right: 0; top: 15px; height: 4px; border-radius: 2px; background: var(--line); }
.timeline .span { position: absolute; top: 15px; height: 4px; background: var(--muted); opacity: .5; }
.timeline .mk {
  position: absolute; top: 9px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%;
  border: 3px solid var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.timeline .mk.you { background: var(--you); }
.timeline .mk.truth { background: var(--truth); }
.timeline .tl-ends { display: flex; justify-content: space-between; position: absolute; top: 24px; left: 0; right: 0; font-size: 11px; color: var(--muted); }
.score-rows { display: grid; gap: 8px; margin: 14px 0; }
.srow { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; font-size: 15px; }
.srow .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.srow .dot { width: 10px; height: 10px; border-radius: 50%; justify-self: center; }
.round-total {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--line); padding-top: 12px; margin-bottom: 14px;
}
.round-total .big { font-family: "Abril Fatface", serif; font-size: 36px; line-height: 1; }
.round-total .big.good { color: var(--good); }
.round-total .big.ok { color: var(--ok); }
.fact {
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  border-radius: 12px; padding: 12px 14px; font-size: 14.5px; margin-bottom: 14px;
}
.fact b { display: block; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }

/* ---------- Scan viewer ---------- */
.scan-wrap { display: flex; justify-content: center; }
.scan {
  position: relative; overflow: hidden; border-radius: 6px;
  background: #1c1a16; box-shadow: var(--shadow);
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.scan.zoomed { cursor: grab; }
.scan.zoomed:active { cursor: grabbing; }
.scan-stage { position: absolute; inset: 0; transform-origin: 0 0; will-change: transform; }
.scan-inner { position: absolute; }
.scan-inner img { display: block; width: 100%; height: 100%; pointer-events: none; }
.scan.loading::after {
  content: "Fetching from the archive…"; position: absolute; inset: 0; display: grid; place-items: center;
  color: #bdb4a5; font-size: 14px; background: #1c1a16;
}
.scan.failed::after {
  content: "Couldn't load this menu. Check your connection."; position: absolute; inset: 0; display: grid; place-items: center;
  color: #bdb4a5; font-size: 14px; background: #1c1a16; padding: 20px; text-align: center;
}
.redact {
  position: absolute; background: #111; border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.35), inset 0 0 0 1px rgba(255,255,255,.04);
  background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.035) 0 6px, transparent 6px 12px);
  transition: opacity .5s ease .15s, clip-path .6s cubic-bezier(.7,0,.3,1);
  clip-path: inset(0 0 0 0);
}
.scan.revealed .redact { clip-path: inset(0 0 0 100%); opacity: 0; }
.zoom-ctl {
  position: absolute; right: 10px; bottom: 10px; z-index: 5;
  display: flex; flex-direction: column; gap: 6px;
}
.zoom-ctl button {
  width: 36px; height: 36px; border-radius: 10px; border: 0;
  background: rgba(20,18,14,.78); color: #fff; font-size: 20px; line-height: 1;
  backdrop-filter: blur(6px);
}
.zoom-ctl .reset { font-size: 16px; }
.zoom-tip {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 5;
  background: rgba(20,18,14,.72); color: #fff; font-size: 12.5px; padding: 5px 10px; border-radius: 999px;
  pointer-events: none; animation: tipfade 4s ease 1.2s forwards; white-space: nowrap;
}
@keyframes tipfade { to { opacity: 0; } }
.scan.zoomed .zoom-tip { display: none; }
.hint-box {
  background: color-mix(in srgb, #ffd23f 22%, var(--surface)); border: 1px solid color-mix(in srgb, #ffd23f 50%, var(--line));
  border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: 14.5px;
}
.hint-box b { display: block; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ok); margin-bottom: 2px; }
.answer-title { color: var(--muted); font-size: 14px; margin-top: 4px; }
.giveaways { margin: 0 0 12px; font-size: 14.5px; }
.giveaways b { display: block; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.giveaways ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.credit { font-size: 12px; color: var(--muted); margin: -4px 0 12px; }
.credit a { color: inherit; }
.rthumb { width: 44px; height: 56px; object-fit: cover; border-radius: 4px; background: var(--line); filter: grayscale(.2); }

/* ---------- Results ---------- */
.results { max-width: 620px; margin: 0 auto; text-align: center; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.results .kicker { color: var(--muted); font-size: 14px; }
.results .total { font-family: "Abril Fatface", serif; font-size: clamp(72px, 16vw, 120px); line-height: .9; }
.results .title-rank { font-size: 20px; font-weight: 600; }
.results .tiles { font-size: 24px; line-height: 1.3; letter-spacing: 3px; }
.rlist { width: 100%; text-align: left; padding: 6px 16px; }
.rrow { display: grid; grid-template-columns: 44px 1fr auto; gap: 4px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rtext { min-width: 0; }
.rrow:last-child { border-bottom: 0; }
.rrow .rname { font-weight: 600; }
.rrow .rmeta { color: var(--muted); font-size: 13px; }
.rrow .rpts { align-self: center; font-family: "Abril Fatface", serif; font-size: 26px; }
.stats { display: flex; gap: 10px; width: 100%; }
.stat { flex: 1; padding: 12px 6px; text-align: center; }
.stat .sv { font-family: "Abril Fatface", serif; font-size: 28px; line-height: 1.1; }
.stat .sk { font-size: 12px; color: var(--muted); }
.share-preview { width: 100%; text-align: left; white-space: pre-wrap; font-size: 14px; margin: 0; user-select: all; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 2000;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px);
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .start { grid-template-columns: 1fr; gap: 10px; min-height: 0; }
  .start-art { height: 300px; order: -1; }
  .art-card { width: 180px; }
  .stage { grid-template-columns: 1fr; }
  .guess-col { position: static; }
}
@media (max-width: 520px) {
  #app { padding: 14px 12px 48px; }
  .bar { padding: 10px 12px; }
  .pip { width: 16px; }
  .art-card { width: 150px; }
  .art-card:nth-child(2) { left: 28%; }
  .art-card:nth-child(3) { left: 54%; }
}

/* QA helper: ?debug */
.debug-redact .redact { background: rgba(255, 0, 60, .28) !important; outline: 2px solid #ff003c; }

/* ---------- Header buttons, dialogs, footer ---------- */
.icon-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1.5px solid var(--line);
  background: transparent; color: var(--ink); font-weight: 700; font-size: 15px; line-height: 1;
  display: inline-grid; place-items: center; padding: 0;
}
.icon-btn:hover { border-color: var(--muted); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.icon-btn:focus-visible, .linkish:focus-visible, .dlg-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.dlg {
  width: min(560px, calc(100vw - 24px)); max-height: min(86dvh, 820px); padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
.dlg::backdrop { background: rgba(10, 8, 5, .55); backdrop-filter: blur(2px); }
.dlg[open] { display: flex; flex-direction: column; animation: rise .2s ease-out; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.dlg-head h2 { margin: 0; font-family: "Abril Fatface", serif; font-weight: 400; font-size: 28px; }
.dlg-x { width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; font-size: 26px; line-height: 1; color: var(--muted); }
.dlg-x:hover { background: var(--line); color: var(--ink); }
.dlg-body { padding: 4px 18px 20px; overflow-y: auto; }
.dlg-body h3 { margin: 18px 0 6px; font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.dlg-body p { margin: 6px 0; }
.dlg-body .steps { margin: 6px 0 0; }
.dlg .stats { flex-wrap: wrap; }
.dlg .stat { min-width: 90px; box-shadow: none; }
.small { font-size: 13px; }
.sbar { display: grid; grid-template-columns: 120px 1fr 44px; gap: 10px; align-items: center; font-size: 14px; margin: 5px 0; }
.sbar-k { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sbar-track { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.sbar-fill { display: block; height: 100%; border-radius: 5px; background: var(--accent); }
.sbar-v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.report { display: grid; gap: 8px; margin-top: 8px; }
.ropt { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.ropt:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.ropt input { accent-color: var(--accent); margin: 0; }
.report textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; resize: vertical; min-height: 70px;
}
.linkish { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-decoration: underline; cursor: pointer; }

.site-foot {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px;
  margin: 28px auto 0; font-size: 13.5px;
}
.site-foot a { color: var(--muted); text-decoration: none; }
.site-foot a:hover { color: var(--ink); text-decoration: underline; }

/* ---------- Info pages (about, credits, privacy) ---------- */
.page { max-width: 720px; margin: 0 auto; padding: 8px 0 24px; }
.page h1 { font-family: "Abril Fatface", serif; font-weight: 400; font-size: clamp(40px, 7vw, 64px); line-height: 1; margin: 18px 0 12px; }
.page h2 { font-family: "Abril Fatface", serif; font-weight: 400; font-size: 28px; margin: 34px 0 8px; }
.page h3 { font-size: 17px; margin: 22px 0 4px; }
.page p, .page li { font-size: 16.5px; }
.page a { color: var(--accent); }
.page .lede { font-size: 19px; color: var(--muted); margin-top: 0; }
.page .card { margin: 14px 0; }
.credits-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.credits-table th { text-align: left; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--line); }
.credits-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.credits-table td:last-child { white-space: nowrap; }
@media (max-width: 520px) {
  .sbar { grid-template-columns: 96px 1fr 38px; font-size: 13px; }
  .bar-right { gap: 6px; }
  .icon-btn { width: 30px; height: 30px; }
  .credits-table { font-size: 13.5px; }
}
