/* ==========================================================================
   Tiny Arcade — shared stylesheet
   Loaded as a blocking <link>, ~4.5 KB. No fonts, no frameworks, no JS deps.
   ========================================================================== */

:root {
  --ink: #12161f;
  --ink-soft: #4a5265;
  --ink-faint: #6b7385;
  --paper: #fbfaf7;
  --card: #ffffff;
  --line: #e4e1d9;
  --line-soft: #efede7;
  --accent: #b4452c;
  --accent-deep: #8f3220;
  --ok: #2f6b4f;
  --radius: 10px;
  --measure: 68ch;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
    "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Skip link / accessibility ---------- */

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 0.7rem 1.1rem;
  z-index: 100;
  border-radius: 0 0 var(--radius) 0;
}

.skip:focus {
  left: 0;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Layout ---------- */

/* One container width for every band, so nav and hero share a left edge. */
.wrap {
  width: min(1120px, 100% - 3rem);
  margin-inline: auto;
}

@media (max-width: 640px) {
  .wrap {
    width: min(1120px, 100% - 2rem);
  }
}

.masthead {
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.92);
  backdrop-filter: saturate(1.2) blur(6px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.masthead__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  min-height: 60px;
  flex-wrap: wrap;
  padding-block: 0.5rem;
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.015em;
  font-size: 1.0625rem;
}

.brand__mark {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  align-self: center;
}

.brand__sub {
  color: var(--ink-faint);
  font-weight: 400;
  font-size: 0.8125rem;
  letter-spacing: 0.01em;
}

.nav {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.nav a {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.9375rem;
  padding-block: 0.25rem;
  border-bottom: 2px solid transparent;
}

.nav a:hover,
.nav a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

main {
  display: block;
}

/* ---------- Hero ---------- */

.hero {
  padding-block: clamp(2.5rem, 6vw, 4.5rem) clamp(1.75rem, 4vw, 3rem);
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-deep);
  margin: 0 0 0.9rem;
}

h1 {
  font-size: clamp(2rem, 5.2vw, 3.15rem);
  line-height: 1.12;
  letter-spacing: -0.032em;
  margin: 0 0 1rem;
  max-width: 22ch;
  font-weight: 760;
}

.lede {
  font-size: clamp(1.0625rem, 1.6vw, 1.25rem);
  color: var(--ink-soft);
  max-width: var(--measure);
  margin: 0 0 1.5rem;
}

.hero__facts {
  display: flex;
  gap: 0.55rem 1.6rem;
  flex-wrap: wrap;
  padding: 0;
  margin: 0;
  list-style: none;
  font-size: 0.875rem;
  color: var(--ink-faint);
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  max-width: var(--measure);
}

.hero__facts strong {
  color: var(--ink);
  font-weight: 640;
}

/* ---------- Answer block (GEO: the citable summary) ---------- */

.answer {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.35rem 1.6rem;
  max-width: var(--measure);
  margin-block: 2rem;
}

.answer h2 {
  font-size: 0.75rem;
  font-family: var(--mono);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.6rem;
  font-weight: 600;
}

.answer p {
  margin: 0 0 0.75rem;
}

.answer p:last-child {
  margin-bottom: 0;
}

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

.section {
  padding-block: clamp(2rem, 4vw, 3.25rem);
  border-top: 1px solid var(--line);
}

.section > h2,
.section__head h2 {
  font-size: clamp(1.4rem, 2.6vw, 1.85rem);
  letter-spacing: -0.022em;
  margin: 0 0 0.6rem;
  line-height: 1.2;
  font-weight: 700;
}

.section__head p {
  color: var(--ink-soft);
  max-width: var(--measure);
  margin: 0 0 2rem;
}

.prose {
  max-width: var(--measure);
}

.prose p,
.prose li {
  color: var(--ink-soft);
}

.prose strong {
  color: var(--ink);
}

.prose h3 {
  font-size: 1.0625rem;
  margin: 1.75rem 0 0.5rem;
  color: var(--ink);
  letter-spacing: -0.01em;
}

/* Full-bleed helper removed: calc(max(1.25rem, (100% - 1120px) / -2)) evaluates
   to a *positive* 381px margin below 1120px, collapsing the section to zero
   width. Nothing needs the bleed now that card rows stack on phones. */

/* ---------- Game cards ---------- */

.games {
  display: grid;
  gap: 1rem;
  list-style: none;
  padding: 0;
  margin: 0;
  grid-template-columns: 1fr;
}

/* Five cards only tile cleanly as 5 or 3+2, never 4+1 — auto-fill at a fixed
   minimum produces an orphaned last card, so the tracks are explicit. */
@media (min-width: 700px) {
  .games {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1060px) {
  .games {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* Rows holding exactly three cards (the "play something else" lists) stay three
   across on desktop but must still stack on phones. Two classes so it outranks
   the single-class .games rules above at every breakpoint. */
.games.games--three {
  grid-template-columns: 1fr;
}

@media (min-width: 700px) {
  .games.games--three {
    grid-template-columns: repeat(3, 1fr);
  }
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 140ms ease, transform 140ms ease;
}

.game-card:hover {
  border-color: var(--ink-faint);
  transform: translateY(-2px);
}

.game-card__glyph {
  width: 100%;
  height: 84px;
  border-radius: 7px;
  background: var(--line-soft);
  display: block;
  margin-bottom: 0.9rem;
  overflow: hidden;
}

.game-card__glyph svg {
  display: block;
  width: 100%;
  height: 100%;
}

.game-card h3 {
  margin: 0 0 0.3rem;
  font-size: 1.0625rem;
  letter-spacing: -0.015em;
}

.game-card p {
  margin: 0 0 0.9rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

.game-card__meta {
  margin-top: auto;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  background: var(--paper);
}

/* ---------- Play page ---------- */

.play-head {
  padding-block: 2rem 1.25rem;
  border-bottom: 1px solid var(--line);
}

.play-head h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  max-width: none;
  margin-bottom: 0.5rem;
}

.crumbs {
  font-size: 0.8125rem;
  color: var(--ink-faint);
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.crumbs li + li::before {
  content: "/";
  margin-right: 0.5rem;
  color: var(--line);
}

.crumbs a {
  color: var(--ink-soft);
}

.stage {
  margin-block: 1.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
}

/* The canvas is the sizing authority: it defines its own aspect ratio via
   width/height attributes and is capped by viewport height, so it never
   overflows the fold and never letterboxes. */
.stage__inner {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  background: var(--ink);
  border-radius: 6px;
  overflow: hidden;
}

.stage__inner--square {
  max-width: 480px;
  margin-inline: auto;
}

.stage__inner--tall {
  max-width: 360px;
  margin-inline: auto;
}

.stage__inner--tall canvas {
  max-height: 76vh;
}

/* The canvas carries its design resolution as width/height attributes, so the
   browser can derive an intrinsic aspect ratio. Cap by width and by viewport
   height together so it neither overflows the fold nor stretches. */
/* A canvas has an intrinsic ratio from its width/height attributes, but
   width:100% + max-height clamps only one axis and stretches the other, which
   would letterbox the drawing. Instead each stage narrows the allowed width so
   the ratio is honoured by construction: 4/3 boards cap their width at
   (68vh * 4/3), square boards at 62vh, tall boards at half of 74vh. */
.stage canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  image-rendering: pixelated;
  background: var(--ink);
}

.stage--landscape canvas {
  max-width: min(100%, calc(68vh * 1.3333));
  margin-inline: auto;
}

.stage--square canvas {
  max-width: min(100%, 62vh);
  margin-inline: auto;
}

.stage--square .stage__inner {
  max-width: min(100%, 62vh);
  margin-inline: auto;
}

.stage--tall canvas {
  max-width: min(100%, calc(74vh * 0.5));
  margin-inline: auto;
}

.stage--tall .stage__inner {
  max-width: min(100%, calc(74vh * 0.5));
  margin-inline: auto;
}

.stage__inner {
  width: 100%;
  max-width: 100%;
  margin-inline: auto;
}

.stage__skip {
  font-size: 0.8125rem;
  color: var(--ink-faint);
  margin: 0.6rem 0.25rem 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0.75rem 0.25rem 0.25rem;
  font-family: var(--mono);
  font-size: 0.8125rem;
}

.stage--square .hud,
.stage--tall .hud {
  max-width: min(100%, 62vh);
  margin-inline: auto;
}

.stage--tall .hud {
  max-width: min(100%, calc(74vh * 0.5));
}

.hud__stat {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.hud__stat b {
  color: var(--accent-deep);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.btn {
  font: inherit;
  font-size: 0.875rem;
  font-family: var(--sans);
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 7px;
  padding: 0.45rem 0.95rem;
  cursor: pointer;
  line-height: 1.3;
}

.btn:hover {
  background: #000;
}

.btn--ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.btn--ghost:hover {
  background: var(--line-soft);
  color: var(--ink);
}

.btn:active {
  transform: translateY(1px);
}

/* ---------- Controls table & prose ---------- */

.controls {
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-block: 0.75rem 1.5rem;
}

.controls th,
.controls td {
  text-align: left;
  padding: 0.4rem 1.25rem 0.4rem 0;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

.controls th {
  font-weight: 600;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.controls td {
  color: var(--ink-soft);
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
}

@media (max-width: 780px) {
  .two-col {
    /* minmax(0, 1fr), not 1fr: a bare 1fr track takes its minimum from
       min-content, and the 640px table inside the aside would stretch the
       whole page wider than the viewport. */
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
  }
}

.two-col > * {
  min-width: 0;
}

/* ---------- FAQ (GEO: Q&A pairs are the most reliably quoted format) ---------- */

.faq {
  max-width: var(--measure);
}

.faq details {
  border-bottom: 1px solid var(--line);
  padding: 0.9rem 0;
}

.faq details:first-of-type {
  border-top: 1px solid var(--line);
}

.faq summary {
  cursor: pointer;
  font-weight: 640;
  color: var(--ink);
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
}

.faq summary::-webkit-details-marker {
  display: none;
}

.faq summary::after {
  content: "+";
  font-family: var(--mono);
  color: var(--accent);
  font-weight: 700;
  flex: none;
}

.faq details[open] summary::after {
  content: "\2212";
}

.faq details p {
  margin: 0.7rem 0 0;
  color: var(--ink-soft);
}

/* ---------- Table (sources) ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  min-width: 640px;
}

/* Narrow, two-column tables (e.g. the weight budget) should fit their
   column instead of forcing a horizontal scrollbar in a 460px aside. */
.table-wrap--fit table.data {
  min-width: 0;
}

.table-wrap--fit table.data td:first-child {
  white-space: normal;
}

table.data th,
table.data td {
  text-align: left;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

table.data th {
  background: var(--paper);
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  font-weight: 600;
  white-space: nowrap;
}

table.data tr:last-child td {
  border-bottom: 0;
}

table.data td:first-child {
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  border: 1px solid;
  white-space: nowrap;
}

.pill--used {
  color: var(--ok);
  border-color: #b9d5c6;
  background: #f1f8f4;
}

.pill--unused {
  color: var(--ink-faint);
  border-color: var(--line);
  background: var(--paper);
}

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

.site-foot {
  border-top: 1px solid var(--line);
  padding-block: 2rem 2.5rem;
  color: var(--ink-faint);
  font-size: 0.875rem;
}

.site-foot__grid {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.site-foot a {
  color: var(--ink-soft);
}

.site-foot nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Hints are input-aware: show only the instruction that applies. */
.touch-only {
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  .kb-only {
    display: none;
  }
  .touch-only {
    display: inline;
  }
}

/* ---------- Touch controls ---------- */

.touchpad {
  display: none;
  margin-top: 0.75rem;
  gap: 0.5rem;
  justify-content: center;
}

@media (hover: none) and (pointer: coarse) {
  .touchpad {
    display: flex;
  }
}

.touchpad__grid {
  display: grid;
  grid-template-columns: repeat(3, 3.25rem);
  grid-template-rows: repeat(2, 3.25rem);
  gap: 0.4rem;
}

.touchpad button {
  font-family: var(--mono);
  font-size: 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.touchpad button:active {
  background: var(--line-soft);
}

/* D-pad with a column of action buttons beside it (Minesweeper). The two grids
   sit in one flex row and are centred, so they read as a single control cluster
   instead of two blocks at different heights. */
.pad-split {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.pad-split__actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.pad-split__actions button {
  font-family: var(--mono);
  font-size: 0.8125rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 0.6rem 0.9rem;
  min-width: 4.5rem;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.pad-split__actions button:active {
  background: var(--line-soft);
}

/* Six nav items no longer fit one line on a phone at the desktop gap; tighten
   the rhythm so they stay on a single row rather than orphaning the last item. */
@media (max-width: 700px) {
  .nav {
    gap: 0.85rem;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .nav::-webkit-scrollbar {
    display: none;
  }
  .nav a {
    font-size: 0.8125rem;
    white-space: nowrap;
  }
}
