/* Fonts are served from this site (SIL Open Font License, see fonts/LICENSE.txt),
   so no third party sees visitors' requests. */
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Press Start 2P"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/press-start-2p-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Pixelify Sans"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/pixelify-sans-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); }

/* The 8-bit look. Our own pixel world sits behind everything; cards always show at full
   resolution on top of it. Pixel rules: square corners on everything but cards, 3px outlines,
   hard offset shadows, Press Start 2P for short labels, Pixelify Sans for headings,
   Atkinson Hyperlegible for anything people read. */
:root {
  --bg: #edf0f6;
  --surface: #ffffff;
  --surface-2: #e1e6f0;
  --ink: #141a2b;
  --muted: #5a6479;
  --line: #d3d9e5;
  --accent: #2748c8;       /* cobalt: links and text */
  --accent-soft: #dfe5fb;
  --fill: #2748c8;         /* cobalt: filled buttons, selected tabs, progress */
  --fill-ink: #ffffff;
  --gold: #f0c05a;         /* fills: your pick, ranked, the chrome trim */
  --gold-text: #8a5d06;    /* gold that has to be read on a light surface */
  --navy: #141a2b;         /* header, tab bar, badges */
  --navy-2: #3a4566;
  --chrome-ink: #c9d1e6;
  --px: #141a2b;           /* outlines */
  --px-shadow: #141a2b;    /* hard shadows */
  --cell-off: #d3d9e5;
  --scrim: rgba(13, 19, 34, 0.92);
  --scene-dim: none;

  --font-pixel: "Press Start 2P", ui-monospace, monospace;
  --font-display: "Pixelify Sans", "Atkinson Hyperlegible", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  --card-radius: 4.8% / 3.4%; /* 3 mm corners on a 63 x 88 mm card */
  --info-h: 66px;             /* the name panel under each card */
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1322;
    --surface: #161e33;
    --surface-2: #222c46;
    --ink: #e8ecf6;
    --muted: #9ba5bd;
    --line: #2a3553;
    --accent: #9fb1ff;
    --accent-soft: #24305a;
    --gold-text: #f0c05a;
    --px: #04060c;
    --px-shadow: #04060c;
    --cell-off: #2a3553;
    --scrim: rgba(5, 8, 16, 0.94);
    --scene-dim: brightness(0.62) saturate(0.9);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1322;
  --surface: #161e33;
  --surface-2: #222c46;
  --ink: #e8ecf6;
  --muted: #9ba5bd;
  --line: #2a3553;
  --accent: #9fb1ff;
  --accent-soft: #24305a;
  --gold-text: #f0c05a;
  --px: #04060c;
  --px-shadow: #04060c;
  --cell-off: #2a3553;
  --scrim: rgba(5, 8, 16, 0.94);
  --scene-dim: brightness(0.62) saturate(0.9);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font-body);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
img { max-width: 100%; }
button { font: inherit; color: inherit; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- frame ---------- */
.app {
  min-height: 100%;
  min-height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.top {
  position: relative;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  padding-bottom: 9px;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
  background: var(--navy);
  border-bottom: 3px solid var(--gold);
  color: #ffffff;
}
.brand {
  font-family: var(--font-pixel);
  font-size: 15px;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}
.brand span { color: var(--gold); }
.mode-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 0;
  max-width: 62%;
  padding: 6px 9px;
  border: 2px solid var(--gold);
  border-radius: 0;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  text-align: right;
}
.mode-chip:hover { background: rgba(240, 192, 90, 0.12); }
.mode-kind {
  white-space: nowrap;
  font-family: var(--font-pixel);
  font-size: 7px;
  line-height: 1;
  text-transform: uppercase;
  color: var(--gold);
}
.mode-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.15;
}
.views { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-block: 12px 20px;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
}

/* a white pixel panel: the building block for anything that sits on the world */
.panel, .formats, .progress, .done-panel, .recap, .load-error {
  background: var(--surface);
  border: 3px solid var(--px);
  box-shadow: 4px 4px 0 var(--px-shadow);
}

/* ---------- the world behind the play screen ---------- */
.scene {
  position: fixed;
  inset: 0;
  left: 50%;
  width: min(100vw, 820px);
  transform: translateX(-50%);
  z-index: -2;
  background: #86c9f4 no-repeat 50% 72% / cover;
  image-rendering: pixelated;
  opacity: 0;
  filter: var(--scene-dim);
  transition: opacity 0.45s ease;
  pointer-events: none;
}
.scene.on { opacity: 1; }
.scene[data-scene="meadow"] { background-image: url("px/scene-meadow.png"); background-color: #5aa846; }
.scene[data-scene="coast"] { background-image: url("px/scene-coast.png"); background-color: #efd59a; }
.scene[data-scene="volcano"] { background-image: url("px/scene-volcano.png"); background-color: #2e2224; }
.scene[data-scene="night"] { background-image: url("px/scene-night.png"); background-color: #121834; }
.scene[data-scene="peaks"] { background-image: url("px/scene-peaks.png"); background-color: #8a7f6f; }
.scene[data-scene="storm"] { background-image: url("px/scene-storm.png"); background-color: #b8a356; }
.scene[data-scene="blossom"] { background-image: url("px/scene-blossom.png"); background-color: #8fd07a; }

/* ---------- format switcher ---------- */
.formats {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
}
.format-btn {
  min-height: 34px;
  padding: 0 4px;
  border: 0;
  border-radius: 0;
  background: none;
  font-family: var(--font-pixel);
  font-size: 9px;
  line-height: 1.3;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}
.format-btn:hover { color: var(--ink); background: var(--surface-2); }
.format-btn[aria-selected="true"] { background: var(--fill); color: var(--fill-ink); }

/* ---------- progress ---------- */
.progress { display: grid; gap: 7px; padding: 8px 10px 9px; }
.progress-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; min-width: 0; }
.progress-text {
  margin: 0;
  min-width: 0;
  font-weight: 700;
  font-size: 13.5px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.place {
  flex: none;
  font-family: var(--font-pixel);
  font-size: 7px;
  line-height: 1;
  text-transform: uppercase;
  color: var(--accent);
}
/* 20 cells, like a health bar; the fill moves smoothly underneath the cell mask */
.progress-bar {
  height: 10px;
  background: var(--cell-off);
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 calc(5% - 2px), transparent calc(5% - 2px) 5%);
  mask: repeating-linear-gradient(90deg, #000 0 calc(5% - 2px), transparent calc(5% - 2px) 5%);
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--fill);
  transition: width 0.3s steps(6, end);
}

/* ---------- arena ---------- */
/* The arena takes whatever height the screen has left, and the cards size themselves
   from it, so both cards and their names always fit without scrolling. */
.arena-shell {
  flex: 1 1 0;
  min-height: 250px;
  container-type: size;
  display: flex;
  align-items: center;
}
.arena {
  width: 100%;
  /* card height is 88/63 of its width; 40px covers the gap, the lift on a pick and the YOUR PICK tag */
  --card-w: min(calc((100cqw - 18px) / 2), calc((100cqh - var(--info-h) - 40px) * 0.716), 300px);
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}
.slot {
  position: relative;
  width: var(--card-w);
  max-width: 100%;
  justify-self: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.slot:first-child { justify-self: end; }
.slot:last-child { justify-self: start; }
.pick {
  display: grid;
  gap: 10px;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.sleeve {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 63 / 88;
  border-radius: var(--card-radius);
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--px), 6px 6px 0 3px rgba(20, 26, 43, 0.45);
  transition: transform 0.12s steps(2, end), box-shadow 0.12s steps(2, end);
}
.sleeve img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.sleeve img.loaded { opacity: 1; }
.sleeve::after { /* penny-sleeve glare */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(118deg, transparent 32%, rgba(255, 255, 255, 0.2) 44%, transparent 58%);
  mix-blend-mode: screen;
}
.sleeve .img-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.pick:hover .sleeve { transform: translate(-2px, -2px); }
.pick:focus-visible { outline: none; }
.pick:focus-visible .sleeve { box-shadow: 0 0 0 3px var(--px), 0 0 0 6px var(--accent), 6px 6px 0 6px rgba(20, 26, 43, 0.45); }
.slot.won .sleeve { transform: translate(-2px, -3px); box-shadow: 0 0 0 3px var(--px), 0 0 0 6px var(--gold), 8px 8px 0 6px var(--px-shadow); }
.slot.won::before {
  content: "Your pick";
  position: absolute;
  z-index: 3;
  left: 50%;
  top: -12px;
  transform: translateX(-50%);
  padding: 5px 6px 4px;
  border: 2px solid var(--px);
  background: var(--gold);
  color: #141a2b;
  font-family: var(--font-pixel);
  font-size: 8px;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}
.slot.lost { opacity: 0.55; transform: scale(0.97); }

/* the crowd's split, shown right after a pick (never before) */
.crowd {
  position: absolute;
  left: 50%;
  bottom: 9px;
  z-index: 2;
  transform: translateX(-50%);
  padding: 7px 8px 6px;
  border: 2px solid var(--px);
  background: var(--navy);
  color: #ffffff;
  font-family: var(--font-pixel);
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
  animation: crowd-in 0.2s steps(3, end);
}
.crowd[hidden] { display: none; }
.crowd.mine { background: var(--gold); color: #141a2b; }
@keyframes crowd-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.crowd-line {
  align-self: center;
  max-width: 100%;
  margin: -2px 0 0;
  min-height: 30px;
  padding: 5px 12px 4px;
  border: 2px solid var(--px);
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--px-shadow);
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  line-height: 17px;
  color: var(--ink);
}
.crowd-line.empty { visibility: hidden; }
.crowd-line[hidden] { display: none; }
.crowd-line.past { color: var(--muted); font-weight: 400; }

.info {
  display: grid;
  align-content: center;
  gap: 1px;
  min-width: 0;
  height: var(--info-h);
  padding: 5px 8px;
  background: var(--surface);
  border: 2px solid var(--px);
  box-shadow: 3px 3px 0 var(--px-shadow);
}
.card-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.25;
}
.card-meta { display: flex; gap: 6px; min-width: 0; font-size: 12px; line-height: 1.3; color: var(--muted); }
.card-set, .card-artist {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-num { flex: none; font-family: var(--font-mono); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.card-artist { font-size: 12px; line-height: 1.3; color: var(--muted); }

.zoom {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 0;
  background: rgba(13, 19, 34, 0.62);
  color: #ffffff;
  cursor: pointer;
}
.zoom svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: square; }

.vs {
  position: absolute;
  left: 50%;
  top: calc(var(--card-w) * 0.698);
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border: 3px solid var(--gold);
  background: var(--navy);
  box-shadow: 3px 3px 0 rgba(20, 26, 43, 0.5);
  pointer-events: none;
  z-index: 2;
}
.vs span { font-family: var(--font-pixel); font-size: 11px; line-height: 1; color: #ffffff; padding-left: 1px; }

/* shiny matchup: 1 in 4,096 */
.arena.shiny .sleeve { box-shadow: 0 0 0 3px var(--px), 0 0 0 6px var(--gold), 0 0 0 9px var(--px), 0 0 28px 10px var(--gold); }
.arena.shiny .sleeve::before {
  content: "";
  position: absolute;
  inset: -40%;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 245, 200, 0.75) 50%, transparent 60%);
  animation: shine 1.6s steps(12, end) infinite;
}
@keyframes shine {
  from { transform: translateX(-60%); }
  to { transform: translateX(60%); }
}

/* ---------- buttons ---------- */
.controls { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 0 0 4px; }
.controls .btn { flex: 1 1 0; max-width: 220px; }
.btn {
  min-height: 46px;
  padding: 10px 14px;
  border: 3px solid var(--px);
  border-radius: 0;
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--px-shadow);
  font-family: var(--font-pixel);
  font-size: 10px;
  line-height: 1.4;
  text-transform: uppercase;
  color: var(--ink);
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--px-shadow); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--fill); color: var(--fill-ink); }
.btn-primary:hover:not(:disabled) { background: #1f3aa6; }

/* ---------- done ---------- */
.done-panel { display: grid; gap: 12px; justify-items: center; text-align: center; padding: 18px 14px; }
.done-kicker {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 9px;
  line-height: 1.4;
  text-transform: uppercase;
  color: var(--gold-text);
}
.done-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  line-height: 1.1;
  text-wrap: balance;
}
.done-top { display: flex; gap: 12px; justify-content: center; align-items: flex-end; }
.done-top figure { margin: 0; display: grid; gap: 6px; justify-items: center; }
.done-top img { width: 92px; aspect-ratio: 63 / 88; object-fit: cover; border-radius: var(--card-radius); box-shadow: 0 0 0 3px var(--px); }
.done-top figure:first-child img { width: 118px; box-shadow: 0 0 0 3px var(--px), 0 0 0 6px var(--gold); }
.done-top figcaption { font-family: var(--font-pixel); font-size: 10px; }
.done-first { margin: 0; color: var(--muted); max-width: 40ch; }
.done-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

/* ---------- quick game recap ---------- */
.recap { display: grid; gap: 12px; justify-items: center; text-align: center; padding: 16px 12px; }
.recap-list { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 8px; }
.recap-row {
  display: grid;
  grid-template-columns: 1.8em 60px 60px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 2px solid var(--line);
  background: var(--surface);
  text-align: left;
}
.recap-num { font-family: var(--font-pixel); font-size: 10px; text-align: right; color: var(--muted); }
.recap-card { position: relative; display: block; }
.recap-card img {
  display: block;
  width: 60px;
  aspect-ratio: 63 / 88;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface-2);
  opacity: 0.45;
}
.recap-card.mine img, .recap-card.tie img { opacity: 1; }
.recap-card.mine img { box-shadow: 0 0 0 3px var(--gold); }
.recap-tag {
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  max-width: 64px;
  padding: 2px 4px;
  border: 2px solid var(--px);
  background: var(--fill);
  color: var(--fill-ink);
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recap-verdict { font-size: 13.5px; font-weight: 700; color: var(--muted); }
.name-field { display: grid; gap: 4px; width: 100%; max-width: 360px; text-align: left; font-size: 13px; color: var(--muted); }
.name-field input, .share-fallback input, .search input, .sort-field select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 3px solid var(--px);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* stops iOS zoom on focus */
}
.share-fallback { display: grid; gap: 6px; width: 100%; max-width: 480px; text-align: left; font-size: 13px; color: var(--muted); }

/* ---------- coming next ---------- */
.coming-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.coming-list li {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 2px dashed var(--muted);
  background: var(--surface);
}
.coming-list strong { font-size: 15px; }
.coming-list span { font-size: 13px; color: var(--muted); }

/* ---------- headings for list views ---------- */
.view-head { display: grid; gap: 6px; }
.view-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 30px;
  line-height: 1.1;
  text-wrap: balance;
}
.view-sub { margin: 0; color: var(--muted); }
.empty { display: grid; gap: 12px; justify-items: start; color: var(--muted); }
.empty p { margin: 0; max-width: 46ch; }

/* ---------- ranking ---------- */
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rank-item {
  display: grid;
  grid-template-columns: 2.6em 52px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 2px solid var(--px);
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--px-shadow);
}
.rank-num {
  font-family: var(--font-pixel);
  font-size: 12px;
  text-align: right;
}
.rank-item:nth-child(1) { background: linear-gradient(90deg, rgba(240, 192, 90, 0.28), transparent 60%), var(--surface); }
.rank-item:nth-child(1) .rank-num { color: var(--gold-text); }
.rank-item img { width: 52px; aspect-ratio: 63 / 88; object-fit: cover; border-radius: 4px; background: var(--surface-2); }
.rank-text { min-width: 0; display: grid; gap: 1px; }
.rank-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-text span { font-family: var(--font-mono); font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- map: kinds of things to rank ---------- */
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 3px solid var(--px);
  box-shadow: 4px 4px 0 var(--px-shadow);
}
.tab {
  min-height: 40px;
  padding: 0 4px;
  border: 0;
  border-radius: 0;
  background: none;
  font-weight: 700;
  font-size: 13.5px;
  line-height: 1.15;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab[aria-selected="true"] { background: var(--fill); color: var(--fill-ink); }

/* ---------- card browser ---------- */
.back-link {
  justify-self: start;
  min-height: 36px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-family: var(--font-pixel);
  font-size: 9px;
  text-transform: uppercase;
  cursor: pointer;
}
.cards-kind {
  margin: 4px 0 0;
  font-family: var(--font-pixel);
  font-size: 8px;
  text-transform: uppercase;
  color: var(--accent);
}
.type-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.type-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 10px;
  border: 2px solid var(--px);
  border-radius: 0;
  background: var(--surface);
  box-shadow: 2px 2px 0 var(--px-shadow);
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
}
.type-chip .n { font-family: var(--font-mono); font-size: 11.5px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.type-chip[aria-pressed="true"] { background: var(--fill); color: var(--fill-ink); }
.type-chip[aria-pressed="true"] .n { color: var(--fill-ink); opacity: 0.85; }
.cards-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.sort-field { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sort-field select { width: auto; min-height: 40px; padding: 6px 10px; font-size: 15px; }
.card-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 16px 12px;
}
.grid-card { display: grid; gap: 3px; width: 100%; padding: 0; border: 0; background: none; text-align: left; cursor: zoom-in; }
.grid-card img {
  display: block;
  width: 100%;
  aspect-ratio: 63 / 88;
  object-fit: cover;
  border-radius: var(--card-radius);
  background: var(--surface-2);
  box-shadow: 0 0 0 2px var(--px), 4px 4px 0 2px rgba(20, 26, 43, 0.3);
}
.grid-name { min-width: 0; margin-top: 6px; font-weight: 700; font-size: 12.5px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-meta { min-width: 0; font-family: var(--font-mono); font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.more-btn { align-self: center; }
@media (min-width: 700px) {
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
}
.search input { min-height: 48px; padding: 10px 14px; box-shadow: 4px 4px 0 var(--px-shadow); }
.search input:focus { outline: 3px solid var(--accent); outline-offset: 2px; }
.mode-section { display: grid; gap: 8px; }
.section-label, .mode-group {
  margin: 6px 0 0;
  font-family: var(--font-pixel);
  font-size: 9px;
  line-height: 1.4;
  text-transform: uppercase;
  color: var(--accent);
}
.mode-group { margin-top: 12px; }
.mode-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mode-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 12px;
  border: 2px solid var(--px);
  border-radius: 0;
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--px-shadow);
  text-align: left;
  cursor: pointer;
}
.mode-item:hover { background: var(--surface-2); }
.mode-item.active { box-shadow: inset 5px 0 0 var(--fill), 3px 3px 0 var(--px-shadow); }
.mode-item-main { min-width: 0; display: grid; gap: 1px; }
.mode-item-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mode-item-main span { font-size: 12.5px; color: var(--muted); }
.pill {
  padding: 5px 6px 4px;
  border: 2px solid var(--px);
  background: var(--navy);
  color: #ffffff;
  font-family: var(--font-pixel);
  font-size: 8px;
  line-height: 1;
  white-space: nowrap;
}
.pill.done { background: var(--gold); color: #141a2b; }
.results-note { margin: 0; font-size: 13px; color: var(--muted); }
.fine-print { margin-top: 12px; display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.fine-print p { margin: 0; max-width: 60ch; }
.fine-print a { color: var(--accent); text-underline-offset: 2px; }

/* ---------- journey map: every set as a stop on a trail, eras as lands ---------- */
.journey {
  margin-left: calc(-1 * var(--gutter-l));
  margin-right: calc(-1 * var(--gutter-r));
  border-top: 3px solid var(--px);
  border-bottom: 3px solid var(--px);
}
.region {
  --path-edge: #b08a45;
  --path: #ecd598;
  position: relative;
  padding-top: 14px;
  background-color: #68b84f;
  background-image: var(--tile);
  background-size: 48px 48px;
  image-rendering: pixelated;
}
.region.fog {
  /* unexplored: mist over the ground until you start one of its sets */
  background-image: linear-gradient(rgba(240, 243, 249, 0.5), rgba(240, 243, 249, 0.5)), var(--tile);
  background-size: auto, 48px 48px;
}
.biome-meadow { --tile: url("px/tile-meadow.png"); background-color: #68b84f; }
.biome-forest { --tile: url("px/tile-forest.png"); background-color: #4f9a3e; }
.biome-coast { --tile: url("px/tile-coast.png"); background-color: #ecd598; --path-edge: #5d6b82; --path: #b7bfcd; }
.biome-desert { --tile: url("px/tile-desert.png"); background-color: #e3c27a; --path-edge: #5d6b82; --path: #b7bfcd; }
.biome-snow { --tile: url("px/tile-snow.png"); background-color: #eef3fa; --path-edge: #7d8ea6; --path: #a8b6c9; }
.biome-autumn { --tile: url("px/tile-autumn.png"); background-color: #c98a3c; --path-edge: #5d6b82; --path: #d8dde6; }
.biome-canyon { --tile: url("px/tile-canyon.png"); background-color: #c97b4f; --path-edge: #5d6b82; --path: #d8dde6; }
.biome-tropical { --tile: url("px/tile-tropical.png"); background-color: #4fbf7a; }
.biome-city { --tile: url("px/tile-city.png"); background-color: #9aa3b5; --path-edge: #3a4566; --path: #5d6b82; }
.biome-highlands { --tile: url("px/tile-highlands.png"); background-color: #79b36a; }
.biome-plains { --tile: url("px/tile-plains.png"); background-color: #a8c45a; }
.biome-crystal { --tile: url("px/tile-crystal.png"); background-color: #b9a8e8; }
.biome-lakes { --tile: url("px/tile-lakes.png"); background-color: #6cc08f; }

.region-banner {
  position: sticky;
  top: 8px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: max-content;
  max-width: calc(100% - 32px);
  height: 50px;
  margin: 0 auto;
  padding: 0 12px;
  border: 2px solid var(--gold);
  background: var(--navy);
  box-shadow: 3px 3px 0 rgba(20, 26, 43, 0.4);
  color: #ffffff;
  white-space: nowrap;
}
.region-name { font-family: var(--font-pixel); font-size: 9px; line-height: 1.1; color: var(--gold); text-transform: uppercase; }
.region-sub { font-size: 12.5px; line-height: 1.15; color: #e8ecf6; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.trail {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 26px 0 26px;
}
.trail-path {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  z-index: 0;
  pointer-events: none;
}
.trail-path polyline { fill: none; vector-effect: non-scaling-stroke; stroke-linecap: square; stroke-linejoin: miter; }
.trail-path .edge { stroke: var(--path-edge); stroke-width: 20px; }
.trail-path .road { stroke: var(--path); stroke-width: 12px; }
.stop { position: relative; z-index: 1; height: 96px; --x: 22%; }
.stop.right { --x: 78%; }
.stop-btn {
  position: absolute;
  inset: 0;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.stop-btn:focus-visible { outline: 3px solid #ffffff; outline-offset: -4px; }
.medal {
  position: absolute;
  left: var(--x);
  top: 50%;
  width: 54px;
  height: 54px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border: 3px solid var(--navy);
  background: linear-gradient(to top, var(--gold) calc(var(--done, 0) * 100%), #ffffff 0);
  box-shadow: 3px 3px 0 rgba(20, 26, 43, 0.4);
}
.medal img { width: 34px; height: 34px; object-fit: contain; image-rendering: auto; }
.stop.here .medal { border-color: var(--fill); box-shadow: 0 0 0 3px #ffffff, 3px 3px 0 3px rgba(20, 26, 43, 0.4); animation: bob 1.2s steps(2, jump-none) infinite; }
@keyframes bob { from { transform: translate(-50%, -50%); } to { transform: translate(-50%, -56%); } }
.stop-label {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  gap: 4px;
  max-width: calc(78% - 48px);
  padding: 6px 8px 7px;
  background: var(--navy);
  box-shadow: 3px 3px 0 rgba(20, 26, 43, 0.4);
  color: #ffffff;
}
.stop.left .stop-label { left: calc(var(--x) + 40px); }
.stop.right .stop-label { right: calc(100% - var(--x) + 40px); }
.stop-btn:hover .stop-label { box-shadow: 0 0 0 2px var(--gold), 3px 3px 0 2px rgba(20, 26, 43, 0.4); }
.stop-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.15;
}
.stop-meta { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12px; line-height: 1.2; color: #c9d1e6; }
.cells {
  flex: none;
  width: 98px;
  height: 7px;
  background: linear-gradient(90deg, var(--gold) calc(var(--done, 0) * 100%), #3a4566 0);
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 8px, transparent 8px 10px);
  mask: repeating-linear-gradient(90deg, #000 0 8px, transparent 8px 10px);
}
.stop-tag { font-family: var(--font-pixel); font-size: 7px; line-height: 1; white-space: nowrap; color: #9fb1ff; }
.stop.ranked .stop-tag, .stop.new .stop-tag { color: var(--gold); }
.here-tag {
  position: absolute;
  left: var(--x);
  top: -2px;
  z-index: 2;
  transform: translateX(-50%);
  padding: 4px 5px 3px;
  background: var(--fill);
  box-shadow: 2px 2px 0 var(--navy);
  color: #ffffff;
  font-family: var(--font-pixel);
  font-size: 7px;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}
.deco {
  position: absolute;
  bottom: 14px;
  background: no-repeat center / 100% 100%;
  image-rendering: pixelated;
  pointer-events: none;
}
.stop.left .deco { left: max(6px, calc(var(--x) - 92px)); }
.stop.right .deco { right: max(6px, calc(100% - var(--x) - 92px)); }
.deco-tree { width: 30px; height: 36px; background-image: url("px/sprite-tree.png"); }
.deco-autumntree { width: 30px; height: 36px; background-image: url("px/sprite-autumntree.png"); }
.deco-pine { width: 30px; height: 42px; background-image: url("px/sprite-pine.png"); }
.deco-snowpine { width: 30px; height: 42px; background-image: url("px/sprite-snowpine.png"); }
.deco-palm { width: 36px; height: 42px; background-image: url("px/sprite-palm.png"); }
.deco-cactus { width: 27px; height: 36px; background-image: url("px/sprite-cactus.png"); }
.deco-rock { width: 30px; height: 21px; background-image: url("px/sprite-rock.png"); }
.deco-flowers { width: 30px; height: 18px; background-image: url("px/sprite-flowers.png"); }
.deco-crystal { width: 24px; height: 36px; background-image: url("px/sprite-crystal.png"); }
.deco-lamp { width: 18px; height: 42px; background-image: url("px/sprite-lamp.png"); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .region::after { content: ""; position: absolute; inset: 0; background: rgba(6, 10, 28, 0.38); pointer-events: none; z-index: 0; }
}
:root[data-theme="dark"] .region::after { content: ""; position: absolute; inset: 0; background: rgba(6, 10, 28, 0.38); pointer-events: none; z-index: 0; }

/* ---------- tab bar ---------- */
.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 7px;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
  background: var(--navy);
  border-top: 3px solid var(--gold);
}
.tabbar-btn {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 2px 0;
  border: 0;
  border-radius: 0;
  background: none;
  font-family: var(--font-pixel);
  font-size: 8px;
  line-height: 1;
  text-transform: uppercase;
  color: var(--chrome-ink);
  cursor: pointer;
}
.tabbar-btn svg { width: 24px; height: 20px; fill: currentColor; shape-rendering: crispEdges; }
.tabbar-btn:hover { color: #ffffff; }
.tabbar-btn[aria-current="page"] { color: var(--gold); }
.tabbar-btn:focus-visible { outline-color: var(--gold); outline-offset: -2px; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding-top: max(56px, env(safe-area-inset-top, 0px));
  padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
  background: var(--scrim);
}
.lightbox img {
  width: min(100%, calc((100dvh - 150px) * 0.716));
  aspect-ratio: 63 / 88;
  object-fit: contain;
  border-radius: var(--card-radius);
}
.lightbox-caption { margin: 0; color: #e8ecf6; text-align: center; font-size: 14px; max-width: 46ch; }
.lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 0px));
  right: var(--gutter-r);
  min-height: 40px;
  padding: 8px 12px;
  border: 2px solid var(--gold);
  border-radius: 0;
  background: var(--navy);
  color: #ffffff;
  font-family: var(--font-pixel);
  font-size: 9px;
  text-transform: uppercase;
  cursor: pointer;
}

/* ---------- toast + errors ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border: 2px solid var(--gold);
  background: var(--navy);
  color: #ffffff;
  box-shadow: 3px 3px 0 rgba(20, 26, 43, 0.45);
  font-weight: 700;
  font-size: 14.5px;
}
.toast.gold { background: var(--gold); color: #141a2b; border-color: var(--px); }
.load-error { margin: 24px var(--gutter-r) 24px var(--gutter-l); padding: 16px; }
.load-error p { margin: 0; }

@media (min-width: 700px) {
  .brand { font-size: 18px; }
  .view-title, .done-title { font-size: 36px; }
  .card-name { font-size: 15.5px; }
}

/* short screens (small phones with the browser bars showing): give the cards the room */
@media (max-height: 700px) {
  :root { --info-h: 48px; }
  .card-artist { display: none; }
  .view-play { gap: 10px; padding-top: 8px; padding-bottom: 10px; }
  .top { padding-top: max(7px, env(safe-area-inset-top, 0px)); padding-bottom: 6px; }
  .format-btn { min-height: 28px; }
  .progress { padding: 6px 9px 7px; gap: 5px; }
  .progress-bar { height: 8px; }
  .crowd-line { min-height: 26px; padding-top: 3px; padding-bottom: 2px; }
  .btn { min-height: 42px; padding-block: 8px; }
  .tabbar { padding-top: 5px; padding-bottom: max(5px, env(safe-area-inset-bottom, 0px)); }
  .tabbar-btn { min-height: 38px; gap: 4px; }
  .tabbar-btn svg { width: 20px; height: 16px; }
}

@media (max-height: 600px) {
  :root { --info-h: 44px; }
  .info { padding-block: 3px; }
  .arena-shell { min-height: 190px; }
  .format-btn { min-height: 26px; }
  .crowd-line { min-height: 24px; font-size: 13px; line-height: 15px; padding-top: 2px; padding-bottom: 1px; }
  .btn { min-height: 38px; padding-block: 6px; }
  .tabbar-btn { min-height: 30px; font-size: 0; gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
