:root {
  color-scheme: light dark;
  --bg: #f6f3ea;
  --surface: #fffdf7;
  --text: #22261f;
  --muted: #555c4f;
  --line: #d9d3c2;
  --accent: #2f6b3a;
  --accent-text: #ffffff;
  --board: #ebe5d3;
  --grid: #e1dac5;
  --vine: #3d7f47;
  --vine-head: #24552d;
  --seed: #b5541b;
  --focus: #1d5fa8;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161a15;
    --surface: #1f241d;
    --text: #e8ebe2;
    --muted: #a9b0a0;
    --line: #353c31;
    --accent: #8fcf8a;
    --accent-text: #10170f;
    --board: #232a21;
    --grid: #2a3227;
    --vine: #79bf73;
    --vine-head: #b4e3a8;
    --seed: #f0a35e;
    --focus: #8cc4ff;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

.wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 16px;
}

header.site {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 0 8px;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.01em;
}

.brand span { color: var(--accent); }

nav.site a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 14px;
}

nav.site a:hover, nav.site a[aria-current="page"] { color: var(--text); text-decoration: underline; }

a { color: var(--accent); }

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

footer.site {
  padding: 24px 0 32px;
  color: var(--muted);
  font-size: 0.85rem;
}

h1 { font-size: 1.6rem; line-height: 1.25; margin: 16px 0 8px; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
p, ul { margin: 0 0 12px; }

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}

.btn:hover { border-color: var(--muted); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn[disabled] { opacity: 0.5; cursor: default; }

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

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

/* Game page (index.html) */
.intro { color: var(--muted); margin: 0 0 12px; }

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
  font-variant-numeric: tabular-nums;
}
.hud dl { display: flex; gap: 20px; margin: 0; }
.hud dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.hud dd { margin: 0; font-size: 1.35rem; font-weight: 700; }
.hud .actions { display: flex; gap: 8px; }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--board);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.board canvas { display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  text-align: center;
  background: rgba(0, 0, 0, 0.18);
  background: color-mix(in srgb, var(--board) 45%, transparent);
  transition: opacity 0.2s ease;
}
.overlay[hidden] { display: none; }
.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 320px;
  padding: 20px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}
.overlay h2 { margin: 0; font-size: 1.4rem; }
.overlay p { margin: 0; color: var(--muted); }

.pad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 56px);
  gap: 8px;
  justify-content: center;
  margin: 16px 0 4px;
}
.pad .btn { padding: 0; font-size: 1.3rem; line-height: 1; }
.pad .up { grid-column: 2; grid-row: 1; }
.pad .left { grid-column: 1; grid-row: 2; }
.pad .down { grid-column: 2; grid-row: 2; }
.pad .right { grid-column: 3; grid-row: 2; }

.padtoggle-wrap { display: none; }
@media (hover: hover) and (pointer: fine) {
  .pad { display: none; }
  .pad.show { display: grid; }
  .padtoggle-wrap { display: inline; }
}
@media (hover: none) and (pointer: coarse) {
  .help { display: none; }
}

.help { color: var(--muted); font-size: 0.9rem; margin-top: 14px; line-height: 1.8; }
.help kbd {
  font: inherit;
  font-size: 0.8rem;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}
.padtoggle {
  font: inherit;
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

/* 404 page */
.lost { text-align: center; padding: 32px 0 8px; }
.lost svg { width: 120px; height: auto; }
.lost .stem { stroke: var(--vine); }
.lost .leaf { fill: var(--vine); }
.lost .soil { fill: var(--line); }
.lost .btn { display: inline-flex; align-items: center; text-decoration: none; }
