:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #ece7dc;
  --text: #1f1d1a;
  --muted: #6b665d;
  --border: #d9d2c3;
  --accent: #d4300b; /* white button text on it is 5:1 */
  --accent-ink: #ffffff;
  --accent-text: #c42a05; /* the accent as link text: 5:1 on --bg */
  --correct: #217f48;
  --partial: #d9a514;
  --wrong: #c8412f;
  --cell-ink: #ffffff;
  --ad-bg: repeating-linear-gradient(45deg, #ebe5d8 0 10px, #e4ddcf 10px 20px);
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 12px;
  --cell: 74px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --surface: #1e2128;
    --surface-2: #272b34;
    --text: #eceae4;
    --muted: #9a9ea8;
    --border: #333844;
    --accent-text: #ff6a45;
    --correct: #237a46;
    --partial: #b98c0f;
    --wrong: #a93a2b;
    --ad-bg: repeating-linear-gradient(45deg, #1c1f26 0 10px, #20242c 10px 20px);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Ad slots ----------
   Ads are off until <body data-ads> is set (see README). Until then every slot, the
   side rails and the mobile anchor's padding are hidden, so no empty boxes show.
   Each slot reserves its space up front so the page doesn't jump when ads load
   (layout shift hurts both UX and ad-network quality scores). */
body:not([data-ads]) .ad-slot,
body:not([data-ads]) .rail { display: none; }
.ad-slot {
  position: relative;
  margin: 0 auto;
  background: var(--ad-bg);
  border: 1px dashed var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.ad-slot:empty::after {
  content: "Advertisement";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted);
}
.ad-leaderboard { width: min(728px, calc(100% - 32px)); height: 90px; margin-top: 12px; }
.ad-rectangle { width: 300px; height: 250px; margin: 24px auto; max-width: 100%; }
.ad-skyscraper { width: 160px; height: 600px; position: sticky; top: 16px; }
.ad-anchor { display: none; }

@media (max-width: 767px) {
  .ad-leaderboard { width: 320px; height: 50px; max-width: calc(100% - 32px); }
  .ad-anchor {
    display: block;
    position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
    width: 320px; height: 50px; max-width: 100%;
    border-radius: 6px 6px 0 0; z-index: 20;
  }
  body[data-ads] { padding-bottom: 58px; }
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  justify-content: center;
  gap: 24px;
  padding: 0 16px;
}
.rail { display: none; }
@media (min-width: 1200px) {
  body[data-ads] .layout { grid-template-columns: 160px minmax(0, 760px) 160px; }
  .rail { display: block; padding-top: 24px; }
}
.main { width: 100%; max-width: 760px; margin: 0 auto; min-width: 0; }

/* ---------- Header ---------- */
.header {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 18px 0 10px;
  border-bottom: 1px solid var(--border);
}
.header-side { display: flex; gap: 8px; }
.header-side.end { justify-content: flex-end; }
.logo {
  margin: 0; font-size: 30px; font-weight: 600; letter-spacing: -.02em;
  display: flex; align-items: center; gap: 10px;
}
.logo b { font-weight: 800; color: var(--accent); }
.ball {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--text);
  background: linear-gradient(var(--accent) 0 44%, var(--text) 44% 56%, #fff 56%);
  position: relative;
}
.ball::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 8px; height: 8px; transform: translate(-50%, -50%);
  border-radius: 50%; background: #fff; border: 2px solid var(--text);
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  display: grid; place-items: center; font-weight: 800; font-size: 17px;
}
a.icon-btn { color: var(--text); text-decoration: none; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

.modebar {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px 14px;
  padding: 10px 2px; font-size: 14px; color: var(--muted);
}
.banner {
  margin: 4px 0 0; padding: 9px 14px; border-radius: var(--radius); text-align: center;
  background: var(--surface); border: 1px dashed var(--border);
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.banner a { color: var(--accent-text); }
a.btn { display: inline-block; text-decoration: none; }
.puzzle-label b { color: var(--text); }
.modelinks { display: flex; gap: 14px; white-space: nowrap; }
.modeleft { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.pool {
  max-width: 100%; padding: 4px 8px; border-radius: 999px; font: inherit; font-size: 13px; font-weight: 600;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.link-btn {
  background: none; border: 0; padding: 4px 0;
  color: var(--accent-text); font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}

/* ---------- Guess input ---------- */
.guess-area { margin: 6px 0 14px; }
.combo { position: relative; max-width: 460px; margin: 0 auto; }
#guessInput {
  width: 100%; padding: 14px 18px; font: inherit; font-size: 17px;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-radius: 999px; outline: none;
  box-shadow: var(--shadow);
}
#guessInput:focus { border-color: var(--accent); }
#guessInput:disabled { opacity: .6; }
.suggestions {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px);
  margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 320px; overflow-y: auto;
}
.suggestions li {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px; border-radius: 8px; cursor: pointer;
}
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--surface-2); }
.suggestions img { width: 40px; height: 40px; image-rendering: pixelated; }
/* A sprite that failed to load (see app.js): its dex number in a box the sprite's size. */
.noimg {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; border-radius: 8px; background: var(--surface-2); color: var(--muted);
  font: 600 10px/1 system-ui, sans-serif; text-shadow: none;
}
.cell.poke .noimg { width: 44px; height: 44px; margin-bottom: 2px; }
.noimg.wide { width: auto; height: 64px; padding: 0 10px; font-size: 12px; }
.suggestions .dex { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.suggestions li[aria-disabled="true"] { cursor: default; background: none; color: var(--muted); }
.guess-count { text-align: center; margin: 10px 0 0; font-size: 14px; color: var(--muted); min-height: 1.4em; }
.still { text-align: center; margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.still .link-btn { font-size: 13px; }
.still-list { margin: 6px auto 0; max-width: 520px; font-size: 13px; line-height: 1.5; color: var(--text, inherit); }
.give-up { display: block; margin: 2px auto 0; font-size: 13px; color: var(--muted); }
.give-up[hidden] { display: none; }
.give-up.armed { color: var(--accent-text); }

/* ---------- Hints ---------- */
.hints { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.hint {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; text-align: center; min-height: 84px;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px;
}
.hint .label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.hint .value { font-weight: 800; font-size: 18px; text-transform: capitalize; }
.hint.locked .value { font-weight: 400; font-size: 13px; color: var(--muted); text-transform: none; }
.hint img.silhouette { width: 64px; height: 64px; filter: brightness(0); image-rendering: pixelated; }
@media (prefers-color-scheme: dark) { .hint img.silhouette { filter: brightness(0) invert(.85); } }
/* Categories run to two words and a "Pokémon"; a long word wraps rather than widening its column. */
.hint .value.genus { font-size: 16px; line-height: 1.2; overflow-wrap: anywhere; hyphens: auto; text-transform: none; }
.hint .sub { font-size: 12px; color: var(--muted); }
/* The Pokédex entry is a sentence or three, so it takes a row of its own under the other three. */
.hint.wide { grid-column: 1 / -1; min-height: 0; }
.hint.wide.locked { flex-direction: row; flex-wrap: wrap; gap: 4px 10px; }
.hint .value.dex { font-weight: 400; font-size: 15px; line-height: 1.45; text-transform: none; max-width: 62ch; text-wrap: pretty; }

/* ---------- Board ---------- */
.board-wrap { overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
.board { width: max-content; margin: 0 auto; }
.row { display: grid; grid-template-columns: repeat(9, var(--cell)); gap: 6px; margin-bottom: 6px; }
.row.head div {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); text-align: center; align-self: end;
  padding-bottom: 4px; border-bottom: 2px solid var(--border); line-height: 1.2;
}
.cell {
  width: var(--cell); height: var(--cell); border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; font-weight: 600; font-size: 13px; line-height: 1.15;
  color: var(--cell-ink); padding: 4px; text-transform: capitalize;
  animation: flip .45s ease both;
  text-shadow: 0 1px 1px rgba(0,0,0,.25);
}
.cell .arrow { font-size: 20px; line-height: 1; margin-top: 2px; }
.cell { position: relative; }
.cell .sr-only { text-transform: none; }
.cell .mark { position: absolute; top: 3px; right: 5px; font-style: normal; font-size: 12px; line-height: 1; opacity: .9; }
.sw { color: var(--cell-ink); font-size: 10px; font-style: normal; font-weight: 700; line-height: 14px; text-align: center; }
.cell .unit { text-transform: none; } /* keep "m" and "kg" lowercase */
.cell.poke {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); text-shadow: none; font-size: 11px;
}
.cell.poke img { width: 52px; height: 52px; image-rendering: pixelated; margin-bottom: -4px; }
.cell.poke.twin { border: 2px solid var(--wrong); }
.correct { background: var(--correct); }
.partial { background: var(--partial); }
/* White on the yellow was 2.25:1 (light) and 3.08:1 (dark); dark ink gets 7.5:1 and 5.5:1. */
.cell.partial, .tag.partial, .sw.partial { color: #1f1d1a; text-shadow: none; }
.wrong { background: var(--wrong); }
@keyframes flip {
  from { transform: rotateX(90deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .cell { animation: none; } }
/* the same for the site-wide Reduce motion setting (hub/prefs.js) */
html.reduce-motion .cell { animation: none; }
/* Keep the Pokemon column visible while the board scrolls sideways on phones. */
.cell.poke, .row.head div:first-child { position: sticky; left: 0; z-index: 1; }
.row.head div:first-child { background: var(--bg); box-shadow: 6px 0 0 var(--bg); }
/* A page-coloured backing the width of the grid gap, so scrolled cells don't show through the corners or the gap. */
.cell.poke { box-shadow: 0 0 0 6px var(--bg); }
.empty { text-align: center; color: var(--muted); font-size: 15px; margin: 18px 0; }

.legend {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px;
  font-size: 13px; color: var(--muted); margin: 14px 0 4px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* Type chip colors */
.type { display: inline-block; padding: 2px 6px; border-radius: 999px; font-size: 12px; line-height: 1.2; background: var(--tb, rgba(0,0,0,.18)); color: var(--ti, inherit); text-shadow: none; box-shadow: 0 0 0 1.5px rgba(255,255,255,.55); }
/* The games' usual type colours, so a row can be scanned by type. The cell's fill still says match or not. */
.t-normal { --tb: #a8a77a; --ti: #1f1d1a; }
.t-fire { --tb: #ee8130; --ti: #1f1d1a; }
.t-water { --tb: #6390f0; --ti: #fff; }
.t-electric { --tb: #f7d02c; --ti: #1f1d1a; }
.t-grass { --tb: #7ac74c; --ti: #1f1d1a; }
.t-ice { --tb: #96d9d6; --ti: #1f1d1a; }
.t-fighting { --tb: #c22e28; --ti: #fff; }
.t-poison { --tb: #a33ea1; --ti: #fff; }
.t-ground { --tb: #e2bf65; --ti: #1f1d1a; }
.t-flying { --tb: #a98ff3; --ti: #1f1d1a; }
.t-psychic { --tb: #f95587; --ti: #1f1d1a; }
.t-bug { --tb: #a6b91a; --ti: #1f1d1a; }
.t-rock { --tb: #b6a136; --ti: #1f1d1a; }
.t-ghost { --tb: #735797; --ti: #fff; }
.t-dragon { --tb: #6f35fc; --ti: #fff; }
.t-dark { --tb: #705746; --ti: #fff; }
.t-steel { --tb: #b7b7ce; --ti: #1f1d1a; }
.t-fairy { --tb: #d685ad; --ti: #1f1d1a; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); margin-top: 24px; padding: 16px 0 28px; font-size: 12px; color: var(--muted); text-align: center; }
.footer p { margin: 4px 0; }

/* ---------- Dialogs ---------- */
.dialog {
  width: min(440px, calc(100% - 32px)); max-height: calc(100% - 32px);
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text);
  padding: 24px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
  overflow-x: hidden;
}
.dialog::backdrop { background: rgba(10,10,14,.55); }
.dialog h2 { margin: 0 0 10px; font-size: 22px; }
.dialog h2:focus { outline: none; } /* focused on open so it is read first, but it isn't a control */
.dialog ul { padding-left: 18px; }
.dialog li { margin-bottom: 6px; }
.close {
  position: absolute; top: 10px; right: 12px; background: none; border: 0;
  font-size: 26px; line-height: 1; color: var(--muted);
}
.tag { color: #fff; padding: 0 6px; border-radius: 4px; }
.help-ex { margin: 12px 0; }
.help-ex figcaption { font-size: 14px; margin-bottom: 8px; }
.help-ex-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 6px; }
.help-ex-row > div { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px; }
.help-ex-row small { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: center; line-height: 1.1; }
.help-ex-row .cell { width: 100%; height: 52px; font-size: 12px; animation: none; }
.help-ex-row .cell .arrow { font-size: 16px; }
.reveal { text-align: center; }
.reveal img { width: 180px; height: 180px; object-fit: contain; }
.reveal .name { font-size: 26px; font-weight: 800; margin: 0; }
.reveal .sub { color: var(--muted); margin: 2px 0 14px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 16px 0; }
.stats b { display: block; font-size: 26px; font-weight: 800; line-height: 1.1; }
.stats span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stats-line { margin: -6px 0 8px; text-align: center; color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 999px; padding: 11px 20px; font-weight: 600;
  background: var(--accent); color: var(--accent-ink);
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.countdown { text-align: center; color: var(--muted); font-size: 14px; margin-top: 14px; }
.countdown b { color: var(--text); font-variant-numeric: tabular-nums; font-size: 18px; }

/* ---------- Pokédex ---------- */
.dialog.dex { width: min(720px, calc(100% - 32px)); padding-bottom: 0; }
.dex-count { margin: -4px 0 10px; color: var(--muted); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 4px 10px; font-size: 13px; font-weight: 600; line-height: 1.3;
}
.chip small { font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip[aria-pressed="true"] small { color: inherit; opacity: .85; }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; margin: 12px 0 0; }
/* A cell is the sprite (or "?") over its number; a big sprite shrinks to fit rather than cover it. */
.dex-cell {
  aspect-ratio: 1; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2px 2px 4px; min-width: 0; overflow: hidden;
}
.dex-cell img { flex: 1; min-height: 0; width: 100%; object-fit: contain; image-rendering: pixelated; }
.dex-cell.caught { background: var(--surface); }
.dex-cell.seen img, .dex-detail img.sil { filter: brightness(0); opacity: .55; }
@media (prefers-color-scheme: dark) { .dex-cell.seen img, .dex-detail img.sil { filter: brightness(0) invert(.85); } }
.dex-cell .q, .dex-detail .q { font-size: 22px; font-weight: 800; color: var(--muted); opacity: .6; }
.dex-cell .q { flex: 1; display: grid; place-items: center; }
.dex-cell .no { font-size: 10px; line-height: 1; color: var(--muted); font-variant-numeric: tabular-nums; }
.dex-cell .noimg { flex: 1; width: 80%; height: auto; margin-bottom: 2px; }
.dex-cell[tabindex="0"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.dex-cell:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.dex-empty { grid-column: 1 / -1; text-align: center; color: var(--muted); margin: 18px 0; }
.dex-detail {
  position: sticky; bottom: 0; margin: 12px -22px 0; padding: 10px 22px 16px; min-height: 76px;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; font-size: 14px; line-height: 1.4;
}
.dex-detail img { width: 56px; height: 56px; flex: none; image-rendering: pixelated; }
.dex-detail .q { width: 56px; flex: none; text-align: center; }
.dex-line { text-align: center; margin: 4px 0 12px; font-size: 14px; }
.dex-new { font-weight: 800; color: var(--accent-text); }
@media (max-width: 520px) {
  /* The generation chips stay one row that scrolls sideways, so the grid starts higher up. */
  #dexGens { flex-wrap: nowrap; overflow-x: auto; margin-right: -14px; padding-right: 14px; scrollbar-width: none; }
  #dexGens .chip { flex: none; }
  .dex-grid { grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 4px; }
  .dialog.dex { padding-left: 14px; padding-right: 14px; }
  .dex-detail { margin: 12px -14px 0; padding: 10px 14px 14px; }
}

.toast {
  position: fixed; left: 50%; top: 20px; transform: translate(-50%, -140%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-weight: 600; font-size: 14px; transition: transform .25s ease; z-index: 100;
  pointer-events: none; visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 520px) {
  :root { --cell: 62px; }
  .logo { font-size: 24px; }
  .cell { font-size: 11px; }
  /* Each guess is a card: the Pokémon on the left, its eight clues in a 4×2 grid with their names
     in the corner, so nothing scrolls sideways. */
  .board { width: auto; }
  .row.head { display: none; }
  .row { grid-template-columns: 66px repeat(4, minmax(0, 1fr)); gap: 4px; margin-bottom: 8px; }
  .cell { width: auto; height: 52px; padding: 13px 2px 2px; border-radius: 8px; }
  .cell.poke { grid-row: span 2; width: auto; height: auto; padding: 4px 2px; position: relative; box-shadow: none; overflow-wrap: anywhere; hyphens: auto; font-size: 10px; }
  .cell[data-k]::before {
    content: attr(data-k); position: absolute; top: 3px; left: 5px;
    font-size: 8.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; text-shadow: none; opacity: .85;
  }
  .cell .arrow { font-size: 15px; margin-top: 0; }
  .cell .mark { top: auto; bottom: 3px; right: 4px; font-size: 10px; }
  .type { padding: 1px 4px; font-size: 10px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .hints { gap: 6px; }
  /* Locked hints shrink to a line or two, so a guess's row isn't pushed under the keyboard. */
  .hint.locked { min-height: 0; padding: 6px 8px; gap: 0; }
  .hint.locked .label { font-size: 10px; }
  .hint.locked .value { font-size: 11px; }
  .hint .value { font-size: 15px; }
  .hint .value.genus { font-size: 13px; }
  .hint .value.dex { font-size: 14px; }
}

/* Twelve-letter names (Crabominable, Squawkabilly) fit the 66px column on the narrowest phones. */
@media (max-width: 360px) { .cell.poke { font-size: 9px; } }

/* Touch screens: small controls keep their look but take taps in a 44px box around their centre
   (the same rule as hub/links.css). */
@media (pointer: coarse) {
  :where(.icon-btn, .close, .link-btn) { position: relative; }
  :where(.icon-btn, .close, .link-btn)::after { content: ''; position: absolute; inset: min(0px, calc((100% - 44px) / 2)); }
}
