/* Site frame shared by every page: design tokens, base styles, header and footer.
   Page-specific styles live in landing-catalog.css, game.css, legal.css and help.css.
   Token reference: docs/design-system/README.md. */

/* ---------- Font ---------- */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/assets/fonts/inter-latin-var.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/assets/fonts/inter-latin-ext-var.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* Arial scaled to Inter's metrics, so text does not reflow when the web font arrives. */
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial"), local("Helvetica"), local("Liberation Sans");
  size-adjust: 107%;
  ascent-override: 90%;
  descent-override: 22%;
  line-gap-override: 0%;
}

/* ---------- Tokens ---------- */

:root {
  color-scheme: light;

  /* Primitives. Components use the semantic tokens below, not these. */
  --green-100: #e4f1ec;
  --green-300: #6cc6a4;
  --green-400: #4fb38f;
  --green-600: #176a51;
  --green-700: #11563f;
  --green-800: #12392d;
  --green-900: #0b2a20;
  --neutral-0: #ffffff;
  --neutral-50: #f7f7f4;
  --neutral-100: #f0f2ee;
  --neutral-200: #e0e4de;
  --neutral-400: #7d8a83;
  --neutral-500: #5b645f;
  --neutral-900: #171a1d;
  --red-500: #e2553f;
  --red-600: #b3402e;
  --gold-300: #ffd76a;
  --gold-400: #f2c94c;
  --gold-700: #805a12;
  --blue-500: #3b7ddd;
  --blue-700: #2563b8;

  /* Semantic colour */
  --bg: var(--neutral-50);
  --surface: var(--neutral-0);
  --surface-2: var(--neutral-100);
  --border: var(--neutral-200);
  --border-strong: var(--neutral-400);
  --text: var(--neutral-900);
  --text-muted: var(--neutral-500);
  --accent: var(--green-600);
  --accent-hover: var(--green-700);
  --accent-subtle: var(--green-100);
  --on-accent: #ffffff;
  --danger: var(--red-600);
  --on-danger: #ffffff;
  --warning: var(--gold-700);
  --success: var(--green-600);

  /* Game surfaces */
  --board: var(--green-800);
  --board-edge: var(--green-900);
  --board-alt: #164434;
  --grid-rule: var(--board);
  --board-cell-light: #eef0e0;
  --board-cell-dark: #7fa890;
  --board-cell-last-light: #e4dc8f;
  --board-cell-last-dark: #b4bc66;
  --board-cell-selected: #e8c356;
  --board-marker: rgb(23 26 29 / 0.28);
  --board-check: rgb(226 85 63 / 0.9);
  --on-board-cell: var(--neutral-900);
  --felt: #1f5a47;
  --piece-light: #fdfaf0;
  --piece-light-edge: #1f2b26;
  --piece-dark: #2a3530;
  --piece-dark-edge: #0b120f;
  --piece-dark-mark: #c9d3cc;
  --tile-correct: var(--green-600);
  --tile-present: var(--gold-700);
  --tile-absent: var(--neutral-500);
  --on-tile: #ffffff;
  --highlight: var(--gold-400);
  --highlight-ring: var(--gold-300);
  --player-1: var(--red-500);
  --player-2: var(--gold-400);
  --player-3: var(--blue-500);
  --player-4: #2f9a6a;
  /* Text-safe player colours for labels (>=4.5:1 on page and surface). */
  --player-1-ink: var(--red-600);
  --player-3-ink: var(--blue-700);
  --card-face: #ffffff;
  --card-ink: var(--neutral-900);
  --card-red: #cf3a2c;
  --card-edge: rgb(23 26 29 / 0.28);
  --card-back: var(--felt);
  --scrim: rgb(10 28 22 / 0.72);
  /* Bright piece colours shared by the arcade games (blocks, bubbles, bricks). */
  --arcade-red: #eb5d57;
  --arcade-orange: #f2994a;
  --arcade-yellow: #f2c94c;
  --arcade-green: #6fcf7c;
  --arcade-cyan: #4fc3d9;
  --arcade-blue: #5b8def;
  --arcade-purple: #a97fd6;
  --arcade-pink: #e0679a;
  --arcade-steel: #8a9a93;
  --paddle: #f3efe2;
  --on-board: #ffffff;

  /* Type */
  --font-sans: "Inter", "Inter Fallback", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: clamp(1.75rem, 1.2rem + 2vw, 2.25rem);
  --text-display: clamp(2rem, 1.3rem + 3vw, 3rem);
  --leading-tight: 1.15;
  --leading-snug: 1.3;
  --leading: 1.5;
  --weight-regular: 400;
  --weight-medium: 600;
  --weight-bold: 700;
  --tracking-tight: -0.015em;

  /* Space, 4px base */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --gutter: 16px;

  /* Shape */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;
  --elev-1: 0 1px 2px rgb(23 26 29 / 0.05), 0 4px 12px rgb(23 26 29 / 0.06);
  --elev-2: 0 4px 8px rgb(23 26 29 / 0.06), 0 16px 40px rgb(23 26 29 / 0.14);

  /* Focus, motion, layering, targets */
  --focus-width: 3px;
  --focus-offset: 3px;
  --focus-color: var(--accent);
  --focus-inverse: #ffffff;
  --motion-fast: 120ms;
  --motion: 160ms;
  --motion-max: 240ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --z-header: 20;
  --z-menu: 30;
  --z-overlay: 5;
  --z-toast: 40;
  --z-skip: 100;
  --target-min: 44px;
  --icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%235b645f' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

  /* Earlier names, kept until every page uses the names above. */
  --page: var(--bg);
  --ink: var(--text);
  --muted: var(--text-muted);
  --soft: var(--surface-2);
  --line: var(--border);
  --accent-soft: var(--accent-subtle);
  --amber: var(--warning);
  --shadow: var(--elev-1);
  --shadow-hover: var(--elev-2);
  --elevation-popover: var(--elev-2);
  --radius-control: var(--radius-md);
  --radius-panel: var(--radius-lg);
  --radius-tag: var(--radius-full);
  --text-small: var(--text-sm);

  font-family: var(--font-sans);
}

/* Dark theme. A choice made with the header toggle (data-theme on <html>, set by
   shared/theme.js) wins; without one, the device setting decides. Keep the two
   lists identical: tests/v2/design_lint.mjs compares them. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1412;
  --surface: #161c19;
  --surface-2: #1d2420;
  --border: #29322d;
  --border-strong: #66736c;
  --text: #e8ece9;
  --text-muted: #9aa59f;
  --accent: var(--green-400);
  --accent-hover: var(--green-300);
  --accent-subtle: #173328;
  --on-accent: #0f1412;
  --danger: #f08a76;
  --player-1-ink: #f08a76;
  --player-3-ink: #8db4f2;
  --on-danger: #0f1412;
  --warning: #e0b04a;
  --success: var(--green-400);
  --board: #0f2e24;
  --board-edge: #08201a;
  --board-alt: #133a2e;
  --grid-rule: var(--border-strong);
  --scrim: rgb(4 12 9 / 0.78);
  --elev-1: 0 1px 2px rgb(0 0 0 / 0.3);
  --elev-2: 0 8px 32px rgb(0 0 0 / 0.5);
  --icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%239aa59f' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1412;
    --surface: #161c19;
    --surface-2: #1d2420;
    --border: #29322d;
    --border-strong: #66736c;
    --text: #e8ece9;
    --text-muted: #9aa59f;
    --accent: var(--green-400);
    --accent-hover: var(--green-300);
    --accent-subtle: #173328;
    --on-accent: #0f1412;
    --danger: #f08a76;
    --player-1-ink: #f08a76;
    --player-3-ink: #8db4f2;
    --on-danger: #0f1412;
    --warning: #e0b04a;
    --success: var(--green-400);
    --board: #0f2e24;
    --board-edge: #08201a;
    --board-alt: #133a2e;
    --grid-rule: var(--border-strong);
    --scrim: rgb(4 12 9 / 0.78);
    --elev-1: 0 1px 2px rgb(0 0 0 / 0.3);
    --elev-2: 0 8px 32px rgb(0 0 0 / 0.5);
    --icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%239aa59f' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}

/* Breakpoints (custom properties cannot be used in media queries):
   480px roomier phone, 768px tablet, 1024px desktop; short landscape is
   (orientation: landscape) and (max-height: 500px). */

/* ---------- Base ---------- */

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-size: var(--text-md);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 {
  line-height: var(--leading-tight);
  font-weight: var(--weight-bold);
}

h1 {
  letter-spacing: var(--tracking-tight);
}

b, strong {
  font-weight: var(--weight-bold);
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

img[hidden] {
  display: none;
}

button, input, select, textarea {
  font: inherit;
}

/* One focus ring for everything. Components only change the colour or offset. */
:focus-visible {
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: var(--focus-offset);
}

[tabindex="-1"]:focus:not(:focus-visible),
main[tabindex="-1"]:focus {
  outline: none;
}

.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.shell {
  width: min(1040px, 100% - 2 * var(--gutter));
  margin: 0 auto;
}

main.shell {
  flex: 1;
}

main {
  scroll-margin-top: 120px;
}

main h1 {
  overflow-wrap: anywhere;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-3);
  z-index: var(--z-skip);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--accent);
  font-weight: var(--weight-bold);
  transform: translateY(-200%);
}

.skip-link:focus {
  box-shadow: var(--elev-2);
  transform: none;
}

.preview-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 70px;
  aspect-ratio: 16 / 10;
  padding: var(--space-3);
  background: var(--board);
  color: var(--on-board);
  font-size: var(--text-sm);
  text-align: center;
}

/* ---------- Header ---------- */

.site-header {
  z-index: var(--z-header);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

/* Pinned on reading pages only: on a game page it would cover the board while scrolling. */
.site-header.sticky {
  position: sticky;
  top: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 64px;
  padding: var(--space-2) 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  min-height: var(--target-min);
  color: var(--text);
  border-radius: var(--radius-md);
}

.brand img {
  width: 48px;
  height: 34px;
  flex-shrink: 0;
}

.brand b {
  color: var(--accent);
  font-weight: inherit;
}

.brand .brand-wordmark {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  line-height: 1;
  white-space: nowrap;
}

.brand-wordmark strong {
  color: var(--text);
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  letter-spacing: 0.02em;
}

.brand-wordmark small {
  color: var(--text-muted);
  font-size: 0.625rem;
  font-weight: var(--weight-regular);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--target-min);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  transition: color var(--motion) var(--ease), background-color var(--motion) var(--ease);
}

.site-nav a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.site-nav a[aria-current="page"] {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 8px;
}

/* Light/dark toggle (shared/theme.js). The icon shows the theme you would switch to. */
.theme-toggle {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: var(--target-min);
  height: var(--target-min);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--motion) var(--ease), background-color var(--motion) var(--ease);
}

/* Headers without a nav (404) still keep the toggle at the right. */
.brand + .theme-toggle {
  margin-left: auto;
}

.theme-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.theme-toggle .sun,
:root[data-theme="dark"] .theme-toggle .moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .sun {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .sun { display: block; }
}

/* "All games" stands in for the category links on game pages, where they are hidden on phones. */
.site-nav a.all {
  display: none;
}

.site-header.sticky .site-nav a.all {
  display: inline-flex;
}

/* Reading pages switch to a native disclosure menu below tablet width. */
.browse-menu {
  display: none;
  position: relative;
  flex-shrink: 0;
  margin-left: auto;
}

.browse-menu summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--target-min);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  list-style: none;
  cursor: pointer;
}

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

.browse-menu summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

.browse-menu[open] summary::after {
  transform: translateY(2px) rotate(225deg);
}

.browse-menu-panel {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: var(--z-menu);
  width: 224px;
  max-width: calc(100vw - 2 * var(--gutter));
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--elev-2);
}

.browse-menu-panel a {
  display: flex;
  align-items: center;
  min-height: var(--target-min);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  font-weight: var(--weight-medium);
}

.browse-menu-panel a:hover,
.browse-menu-panel a[aria-current="page"] {
  background: var(--accent-subtle);
  color: var(--accent);
}

.browse-menu-panel a:focus-visible {
  outline-offset: -3px;
}

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

.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.footer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.35fr) minmax(0, 0.8fr) minmax(0, 0.6fr);
  gap: var(--space-5);
  padding: var(--space-6) 0 var(--space-5);
}

.footer-brand p {
  max-width: 300px;
  margin: var(--space-3) 0 0;
  line-height: var(--leading);
}

.footer-col h2 {
  margin: 0 0 var(--space-3);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  letter-spacing: 0;
}

.footer-col ul {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Pages without the games list (game pages) use three columns. */
.footer-grid:not(:has(.games)) {
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr);
}

.footer-col.games ul {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: var(--space-4);
}

.footer-col a {
  overflow-wrap: anywhere;
  border-bottom: 1px solid transparent;
}

.footer-col a:hover {
  color: var(--accent);
  border-color: currentColor;
}

.footer-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-4) 0 var(--space-5);
  border-top: 1px solid var(--border);
  font-size: var(--text-sm);
}

.footer-bottom a {
  color: var(--text);
  font-weight: var(--weight-medium);
}

.footer-bottom a:hover {
  color: var(--accent);
}

/* ---------- Responsive ---------- */

@media (max-width: 767px) {
  .site-header.sticky {
    position: static;
  }

  .site-header.sticky .site-nav {
    display: none;
  }

  .browse-menu {
    display: block;
  }

  .site-header:not(.sticky) .site-nav a {
    display: none;
  }

  .site-header:not(.sticky) .site-nav a.all {
    display: inline-flex;
  }

  .topbar {
    min-height: 60px;
  }

  .footer-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    padding: var(--space-5) 0;
  }

  .footer-brand,
  .footer-col.games {
    grid-column: 1 / -1;
  }
}

/* Narrow phones: "Browse" alone leaves room for the theme toggle. */
@media (max-width: 399px) {
  .browse-extra {
    display: none;
  }
}

@media (max-width: 360px) {
  .brand {
    gap: var(--space-2);
  }

  .brand img {
    width: 40px;
    height: 28px;
  }

  .brand-wordmark strong {
    font-size: var(--text-lg);
  }
}

@media (min-width: 768px) {
  :root {
    --gutter: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .site-nav a,
  .theme-toggle {
    transition: none;
  }
}
