:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #555c6b;
  --line: #d7dbe3;
  --accent: #1f7a3d;
  --accent-ink: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1014;
    --card: #161a21;
    --ink: #e9edf3;
    --muted: #a3adbd;
    --line: #2a313d;
    --accent: #3fb950;
    --accent-ink: #08130b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
  max-width: 34rem;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

h1 { font-size: 1.6rem; margin: 0.4rem 0 0.35rem; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 0.4rem; }

.lead { margin: 0 0 1rem; color: var(--muted); }

.howto {
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 0.6rem 0.8rem 0.7rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}

.howto[hidden] { display: none; }

.howto-title {
  margin: 0 0 0.35rem;
  font-weight: 600;
  color: var(--ink);
}

.howto ol {
  margin: 0 0 0.6rem;
  padding-left: 1.2rem;
  color: var(--muted);
}

.howto li { margin-bottom: 0.15rem; }

.howto button { font-size: 0.9rem; padding: 0.4rem 0.65rem; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 1rem;
}

.panel-note {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.row .label { color: var(--muted); font-size: 0.9rem; }

button {
  font: inherit;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

button:hover { border-color: var(--accent); }

button:focus-visible,
input:focus-visible,
canvas:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.chip { font-size: 0.92rem; }
.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.check {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin-top: 0.7rem;
  font-size: 0.92rem;
  color: var(--muted);
}

.check input { margin-top: 0.25rem; }

.actions { margin-bottom: 0.75rem; }

.board-wrap {
  margin: 0 auto;
  max-width: 30rem;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid var(--line);
  touch-action: none;
}

.status {
  min-height: 1.5em;
  margin: 0.75rem 0;
  color: var(--muted);
}

/* The numbers a player watches while playing, kept in their own row just under
   the status line so they are on screen with the board on a phone: score, level,
   run clock and — since version 2.21 — the best standing on the picked board.
   Four cells need a wider screen, so a phone lays the row out two by two and a
   screen from 28rem up lays the four out in one row. The rest of the read-out
   (dl.stats) stays further down the page. */
.live-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  margin: 0 0 0.75rem;
}

@media (min-width: 28rem) {
  .live-stats { grid-template-columns: repeat(4, 1fr); }
}

.live-stats > div {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem 0.55rem;
}

.live-stats dt { font-size: 0.78rem; color: var(--muted); }
.live-stats dd { margin: 0.1rem 0 0; font-size: 1.1rem; font-weight: 600; }

.pad {
  display: grid;
  grid-template-columns: repeat(3, 4rem);
  grid-auto-rows: 3rem;
  gap: 0.4rem;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.pad button { padding: 0.4rem; }
#up { grid-area: 1 / 2; }
#left { grid-area: 2 / 1; }
#right { grid-area: 2 / 3; }
#down { grid-area: 3 / 2; }

.help {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.help summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 600;
  padding: 0.2rem 0;
}

.help ul { margin: 0.5rem 0 0.3rem; padding-left: 1.1rem; }
.help li { margin-bottom: 0.25rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin: 1rem 0 0;
}

.stats > div {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
}

.stats dt { font-size: 0.8rem; color: var(--muted); }
.stats dd { margin: 0.15rem 0 0; font-size: 1.15rem; font-weight: 600; }

.result { margin-top: 1rem; }
.result[hidden] { display: none; }

.result-title {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.result-line {
  margin: 0 0 0.6rem;
  padding: 0.5rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  overflow-wrap: anywhere;
  user-select: text;
}

.result-hint {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.about { color: var(--muted); font-size: 0.94rem; }
.about ul { padding-left: 1.1rem; margin: 0.4rem 0; }
.about li { margin-bottom: 0.25rem; }
.built { color: var(--ink); }

footer {
  max-width: 34rem;
  margin: 0 auto;
  padding: 0 1rem 2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

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

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
