:root {
  --ink: #1b1033;
  --ink-deep: #0d0718;
  --cream: #fff3dc;
  --line: #3b2a55;
  --text: #f3e9ff;
  --muted: #a993c9;
  --gold: #ffd36e;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --body: 'VT323', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: none;
  touch-action: none;
  outline: none;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ── Pixel buttons ─────────────────────────────── */
.pixel-btn {
  font-family: var(--pixel);
  font-size: 10px;
  line-height: 1;
  color: var(--cream);
  background: var(--ink);
  border: 0;
  padding: 9px 11px;
  cursor: pointer;
  box-shadow:
    0 0 0 2px var(--cream),
    4px 4px 0 2px var(--ink-deep);
  transition: transform 60ms steps(1);
}
.pixel-btn:hover { background: var(--line); }
.pixel-btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 2px var(--cream), 2px 2px 0 2px var(--ink-deep); }
.pixel-btn:focus-visible { outline: 2px dashed var(--gold); outline-offset: 5px; }

.hud-buttons {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  gap: 12px;
  z-index: 5;
}

/* ── Overlay window ────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  grid-template-columns: minmax(0, 1fr); /* lets the window shrink to the screen; the tab row scrolls instead */
  padding: 20px;
  background: rgba(13, 7, 24, 0.62);
  user-select: text;
  -webkit-user-select: text;
}
.overlay[hidden] { display: none; }

.window {
  --accent: var(--gold);
  width: min(660px, 100%);
  max-height: min(86vh, 780px);
  display: flex;
  flex-direction: column;
  background: var(--ink);
  box-shadow:
    0 0 0 4px var(--cream),
    0 0 0 8px var(--ink-deep),
    14px 14px 0 8px rgba(0, 0, 0, 0.35);
  animation: pop 220ms steps(4) both;
}

@keyframes pop {
  from { transform: scale(0.86); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  background: var(--accent);
  color: var(--ink);
}
.titlebar h2 {
  flex: 1;
  margin: 0;
  font-family: var(--pixel);
  font-size: 14px;
  line-height: 1.4;
  letter-spacing: 0.5px;
}
.titlebar .close {
  color: var(--ink);
  background: var(--cream);
  box-shadow: 0 0 0 2px var(--ink);
  padding: 7px 8px;
}
.titlebar .close:hover { background: #fff; }
.titlebar .close:focus-visible { outline-color: var(--ink); }

.badge {
  font-family: var(--pixel);
  font-size: 9px;
  padding: 5px 6px;
  color: var(--cream);
  background: var(--ink);
  animation: blink 0.8s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0.35; } }

.body {
  overflow: auto;
  padding: 18px 22px 22px;
  font-family: var(--body);
  font-size: 23px;
  line-height: 1.2;
  scrollbar-color: var(--line) transparent;
}
.body > :first-child { margin-top: 0; }
.body p { margin: 0 0 14px; }
.body ul { margin: 0 0 14px; padding-left: 22px; }
.body li { margin-bottom: 4px; }
.body li::marker { content: '> '; color: var(--accent); }
.body strong { color: var(--cream); }
.body em { color: var(--accent); font-style: normal; }
.body a { color: var(--accent); text-underline-offset: 3px; }
.body a:hover { color: var(--cream); }
.body a:focus-visible { outline: 2px dashed var(--accent); outline-offset: 3px; }
.body h3 {
  font-family: var(--pixel);
  font-size: 11px;
  color: var(--cream);
  margin: 22px 0 12px;
  line-height: 1.5;
}
.body img { max-width: 100%; image-rendering: auto; }

.cards { list-style: none; padding: 0 !important; display: grid; gap: 14px; }
.cards li::marker { content: none; }
.card {
  padding: 14px 16px;
  background: #22163a;
  box-shadow: inset 0 0 0 2px var(--line);
}
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 8px; }
.card h3 { margin: 0; color: var(--cream); }
.card p { margin: 0 0 8px; }
.meta { color: var(--muted); font-size: 19px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags span { padding: 0 7px; font-size: 17px; color: #cbb8ea; box-shadow: inset 0 0 0 1px #5a4680; }
.card a { display: inline-block; margin-top: 2px; }

.links { list-style: none; padding: 0 !important; display: flex; flex-wrap: wrap; gap: 14px; }
.links li::marker { content: none; }
.links a {
  display: inline-block;
  padding: 8px 14px;
  font-family: var(--pixel);
  font-size: 10px;
  text-decoration: none;
  color: var(--ink);
  background: var(--accent);
  box-shadow: 4px 4px 0 var(--ink-deep);
}
.links a:hover { background: var(--cream); color: var(--ink); }

/* Menu */
.menu { list-style: none; padding: 0 !important; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 8px !important; }
.menu li::marker { content: none; }
.menu-item {
  --c: var(--gold);
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 12px;
}
.menu-item .dot { width: 10px; height: 10px; background: var(--c); flex: none; }
.menu-item .state { margin-left: auto; color: var(--muted); font-family: var(--body); font-size: 20px; line-height: 10px; }
.menu-item.found .state { color: var(--c); }
.menu-item:disabled { opacity: 0.5; cursor: default; }
.menu-item:disabled .dot { background: transparent; box-shadow: inset 0 0 0 2px #5a4680; }
.lede { color: var(--muted); }
.small { font-size: 19px; color: var(--muted); }
.plain-section + .plain-section { margin-top: 28px; padding-top: 18px; border-top: 2px dashed var(--line); }
.plain-section > h3:first-child { margin-top: 0; }

/* While paging between sections the window keeps one height, so the tabs don't jump. */
.window.paged { height: min(86vh, 680px); }
.window.paged .body { flex: 1; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 14px 0;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 2px solid var(--line);
  flex: none;
}
.tabs[hidden] { display: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  --c: var(--gold);
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: -2px;
  padding: 9px 11px 8px;
  font-family: var(--pixel);
  font-size: 9px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 0;
  box-shadow: inset 0 0 0 2px var(--line);
  cursor: pointer;
}
.tab .dot { width: 8px; height: 8px; background: var(--c); }
.tab:hover { color: var(--cream); }
.tab[aria-current] { color: var(--ink); background: var(--c); box-shadow: none; }
.tab[aria-current] .dot { background: var(--ink); }
.tab:focus-visible { outline: 2px dashed var(--cream); outline-offset: -5px; }
.tab.locked { color: #5a4680; cursor: default; box-shadow: inset 0 0 0 2px var(--line); }
.tab.locked .dot { background: transparent; box-shadow: inset 0 0 0 2px #5a4680; }

.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 16px;
  border-top: 2px dashed var(--line);
  flex: none;
}
.footer .continue, .footer .next { margin-left: auto; }

.noscript {
  position: fixed; inset: 0; display: grid; place-items: center;
  font-family: var(--pixel); font-size: 12px; text-align: center; padding: 24px;
}

@media (max-width: 520px) {
  .pixel-btn { font-size: 9px; padding: 8px 9px; }
  .body { font-size: 21px; padding: 16px; }
  .titlebar h2 { font-size: 11px; }
  .overlay { padding: 12px; }
  .footer .wide { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .window, .badge { animation: none; }
}

/* ── The secret zoo ───────────────────────────────── */
.window.wide { width: min(940px, 100%); }
.window.wide { height: min(88vh, 820px); }
.window.wide .body { flex: 1; }

.zoo-loading, .zoo-empty { color: var(--muted); }
.zoo-intro { color: var(--text); max-width: 62ch; }
.zoo-example {
  font-family: var(--pixel);
  font-size: 9px;
  line-height: 1.7;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--gold);
}
.zoo-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}
.zoo-stats div { padding: 10px 12px; box-shadow: inset 0 0 0 2px var(--line); }
.zoo-stats dt { font-size: 17px; color: var(--muted); }
.zoo-stats dd { margin: 2px 0 0; font-family: var(--pixel); font-size: 16px; color: var(--cream); font-variant-numeric: tabular-nums; }

.zoo-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.zoo-filter {
  font-family: var(--pixel);
  font-size: 8px;
  line-height: 1;
  padding: 8px 9px;
  color: var(--muted);
  background: transparent;
  border: 0;
  box-shadow: inset 0 0 0 2px var(--line);
  cursor: pointer;
}
.zoo-filter span { color: var(--cream); margin-left: 4px; }
.zoo-filter:hover { color: var(--cream); }
.zoo-filter[aria-pressed="true"] { color: var(--ink); background: var(--gold); box-shadow: none; }
.zoo-filter[aria-pressed="true"] span { color: var(--ink); }
.zoo-filter:focus-visible, .specimen:focus-visible { outline: 2px dashed var(--gold); outline-offset: 2px; }

.zoo-enclosure h3, .zoo-h { margin: 22px 0 10px; }
.zoo-enclosure h3 small { display: block; margin-top: 6px; font-family: var(--body); font-size: 18px; color: var(--muted); font-weight: normal; }
.zoo-grid {
  list-style: none;
  padding: 0 !important;
  margin: 0 !important;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.zoo-grid li::marker { content: none; }
.specimen {
  width: 100%;
  height: 100%;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 2px;
  padding: 10px 8px 12px;
  text-align: center;
  font: inherit;
  color: var(--text);
  background: #22163a;
  border: 0;
  box-shadow: inset 0 0 0 2px var(--line);
  cursor: pointer;
}
.specimen:hover { box-shadow: inset 0 0 0 2px var(--gold); }
.specimen canvas { width: 72px; height: 72px; image-rendering: pixelated; margin-bottom: 4px; }
.sp-name { font-family: var(--pixel); font-size: 8px; line-height: 1.5; color: var(--cream); }
.sp-latin { font-style: italic; color: var(--gold); font-size: 18px; }
.sp-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 17px; font-variant-numeric: tabular-nums; }

.zoo-chip {
  --c: var(--muted);
  display: inline-block;
  font-family: var(--pixel);
  font-size: 7px;
  line-height: 1;
  padding: 3px 4px;
  color: var(--ink);
  background: var(--c);
}

.zoo-ledger { list-style: none; padding: 0 !important; margin: 0 0 14px !important; }
.zoo-ledger li { display: grid; grid-template-columns: 7.5em 1fr auto; gap: 10px; align-items: baseline; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.zoo-ledger li::marker { content: none; }
.zoo-ledger time { color: var(--muted); font-variant-numeric: tabular-nums; }
.zoo-ledger b { color: var(--cream); font-weight: normal; min-width: 0; overflow-wrap: anywhere; }
.zoo-ledger code, .zoo-ua { font-family: var(--body); color: var(--gold); overflow-wrap: anywhere; }
.zoo-key { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 18px; color: var(--muted); }
.zoo-key > span { display: inline-flex; align-items: center; gap: 6px; }

.zoo-back { margin-bottom: 16px; }
.zoo-plate { box-shadow: inset 0 0 0 2px var(--line); padding: 16px 18px; background: #22163a; }
.zoo-plate header {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-family: var(--pixel);
  font-size: 8px;
  color: var(--muted);
  padding-bottom: 10px;
  margin-bottom: 14px;
  border-bottom: 2px dashed var(--line);
}
.plate-body { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: start; }
.plate-body > div { min-width: 0; }
.plate-art { width: 144px; height: 144px; image-rendering: pixelated; background: #1b1033; box-shadow: inset 0 0 0 2px var(--line); }
.zoo-plate h3 { margin: 0 0 4px; font-size: 13px; }
.plate-facts { display: grid; grid-template-columns: max-content 1fr; gap: 2px 16px; margin: 12px 0 0; }
.plate-facts dt { color: var(--muted); }
.plate-facts dd { margin: 0; color: var(--cream); font-variant-numeric: tabular-nums; }
.plate-status { margin: 16px 0 10px !important; padding: 10px 12px; box-shadow: inset 4px 0 0 var(--c); }
.plate-status .zoo-chip { background: var(--c); }
.zoo-ua { display: block; padding: 8px 10px; background: var(--ink); font-size: 18px; }

@media (max-width: 520px) {
  .plate-body { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .plate-facts { text-align: left; }
  .zoo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .zoo-ledger li { grid-template-columns: 5.5em 1fr; }
  .zoo-ledger code { grid-column: 2; }
}
