:root {
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efe9e0;
  --text: #22201c;
  --muted: #6e685f;
  --line: #e6e0d6;
  --line-strong: #cbc2b4;
  --a: #e8833a;
  --b: #4263eb;
  --error: #d6336c;
  --error-bg: rgba(214, 51, 108, 0.16);
  --hint: rgba(66, 99, 235, 0.22);
  --ok: #2b8a3e;
  --ok-bg: rgba(43, 138, 62, 0.12);
  --focus: #4263eb;
  --radius: 16px;
  --hit-bg: var(--a);
  --hit-fg: #1f1d1a;
  --near-bg: var(--b);
  --near-fg: #ffffff;
  --miss-bg: #8b8478;
  --miss-fg: #ffffff;
  color-scheme: light;
}

/* The base colours above are the Light theme. Fun is the default (each page's
   <html data-theme="fun">); Light and Dark apply when picked (js/theme.js). */
:root[data-theme="dark"] {
  --bg: #151413;
  --surface: #1f1d1b;
  --surface-2: #2a2724;
  --text: #f2eee8;
  --muted: #a59f95;
  --line: #34302b;
  --line-strong: #4b453e;
  --a: #f2994a;
  --b: #6f8cff;
  --error: #ff6b9a;
  --error-bg: rgba(255, 107, 154, 0.18);
  --hint: rgba(111, 140, 255, 0.28);
  --ok: #69db7c;
  --ok-bg: rgba(105, 219, 124, 0.14);
  --focus: #8ea4ff;
  --near-fg: #151413;
  --miss-bg: #3a3632;
  --miss-fg: #d6d0c6;
  color-scheme: dark;
}

/* Fun theme, the default: an arcade look. Deep purple, neon yellow and cyan,
   and a bouncy font for headings (the "Fun theme" section further down). */
:root[data-theme="fun"] {
  --bg: #2a1a5e;
  --surface: #3a2580;
  --surface-2: #4b3399;
  --text: #ffffff;
  --muted: #cbbff7;
  --line: #5a44ad;
  --line-strong: #8a72e8;
  --a: #ffd23f;
  --b: #22d3ee;
  --pink: #ff4fa3;
  --lime: #a3e635;
  --ink: #23124f;
  --error: #ff5c8a;
  --error-bg: rgba(255, 92, 138, 0.24);
  --hint: rgba(34, 211, 238, 0.32);
  --ok: #5cf08f;
  --ok-bg: rgba(92, 240, 143, 0.18);
  --focus: #ffd23f;
  --hit-fg: var(--ink);
  --near-fg: var(--ink);
  --miss-bg: #5f4ea8;
  --miss-fg: #ece6ff;
  --display: "Fredoka", var(--font);
  color-scheme: dark;
}

/* Only downloaded when the Fun theme uses it. */
@font-face {
  font-family: "Fredoka";
  src: url("fonts/fredoka-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

button { font: inherit; color: inherit; }

[hidden] { display: none !important; }

/* Read out by screen readers, not shown on screen. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Buttons */

.btn {
  appearance: none;
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.btn.primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.primary:hover:not(:disabled) { background: var(--text); opacity: 0.88; }
.btn.small { padding: 6px 12px; font-size: 0.9rem; }
a.btn { display: inline-block; color: inherit; text-decoration: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

/* Tiles, shared by the board, the rules and the home page */

.tile { display: block; aspect-ratio: 1; }
.tile.a { background: var(--a); border-radius: 50%; }
.tile.b { background: var(--b); border-radius: 18%; rotate: 45deg; }
.tile.inline { display: inline-block; width: 1em; height: 1em; vertical-align: -0.15em; }
.tile.b.inline { width: 0.78em; height: 0.78em; margin: 0 0.12em; vertical-align: -0.05em; }

/* Game pages */

/* Back on the left, the title centred, the buttons on the right. */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 0;
}
.topbar > :last-child { justify-self: end; }
.topbar h1 { margin: 0; font-size: 1.3rem; letter-spacing: -0.01em; }
.topbar-spacer { width: 40px; }
.topbar-actions { display: flex; gap: 8px; }

/* Music and Sound: a line through the icon when off (js/audio.js). */
.audio-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.audio-btn[aria-pressed="true"] .off,
.audio-btn[aria-pressed="false"] .on { display: none; }
.audio-btn[aria-pressed="false"] { color: var(--muted); }

/* Plain text pages (privacy) */

.page { max-width: 480px; margin: 0 auto; padding: 8px 16px 48px; }
.page h2 { margin: 28px 0 4px; font-size: 1.05rem; }
.page p { margin: 8px 0; }

/* The frame shared by every game (js/shell.js) */

.game { max-width: 480px; margin: 0 auto; padding: 8px 16px 32px; }

.status { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0; }
.status + .status { margin-top: -4px; }
.day { margin: 0; font-weight: 700; }
.refresh { color: var(--muted); font-size: 0.88rem; font-weight: 600; }
.timer { color: var(--muted); font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.levels { display: inline-flex; padding: 3px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); }
.seg {
  appearance: none;
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.seg:hover { color: var(--text); }
.seg[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.seg.done::after { content: " ✓"; color: var(--ok); }
.seg.done[aria-pressed="true"]::after { color: inherit; }
.seg:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.message { min-height: 1.5em; margin: 14px 0 0; color: var(--muted); text-align: center; }

.rules { margin: 0; padding-left: 1.2em; }
.rules li + li { margin-top: 6px; }
.fine { margin: 14px 0 0; color: var(--muted); font-size: 0.92rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 0; }
.stats div { padding: 12px 8px; border-radius: 12px; background: var(--surface-2); text-align: center; }
.stats dt { color: var(--muted); font-size: 0.8rem; }
.stats dd { margin: 2px 0 0; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Action games (js/arcade.js): score bar, and messages over the play area */

.scoreboard { display: flex; align-items: center; gap: 12px; color: var(--muted); font-weight: 600; }
.scoreboard strong { color: var(--text); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.lives { color: var(--a); letter-spacing: 2px; }
.icon-btn.small { width: 34px; height: 34px; font-size: 0.75rem; }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

.stage { position: relative; }
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  align-items: start;
  justify-items: center;
  padding-top: 36%;
  pointer-events: none;
}
.overlay span {
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-weight: 700;
  text-align: center;
}

@keyframes pop { 50% { scale: 1.2; } }
@keyframes flash { from { background-color: var(--hint); } }

/* Dialogs */

dialog {
  width: min(400px, calc(100vw - 32px));
  padding: 24px;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(20, 18, 16, 0.5); }
dialog h2 { margin: 0 0 12px; font-size: 1.35rem; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

/* Home page */

.hub { max-width: 560px; margin: 0 auto; padding: 48px 16px; }
.hub h1 { margin: 0; font-size: 2.1rem; letter-spacing: -0.02em; }
.tagline { margin: 4px 0 28px; color: var(--muted); }

.game-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.game-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08); }
.game-card:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.game-card h2 { margin: 0; font-size: 1.15rem; }
.game-card p { margin: 2px 0 10px; color: var(--muted); font-size: 0.95rem; }

.card-art {
  display: grid;
  flex: none;
  grid-template-columns: repeat(3, 1fr);
  place-items: center;
  gap: 4px;
  width: 84px;
  height: 84px;
  padding: 10px;
  border-radius: 14px;
  background: var(--surface-2);
}
.card-art .tile { width: 72%; }
.card-art .tile.b { width: 54%; }
.ops-art { grid-template-columns: repeat(2, 1fr); gap: 6px; }
.ops-art span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: var(--surface);
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1;
}
.ops-art span:nth-child(odd) { color: var(--a); }
.ops-art span:nth-child(even) { color: var(--b); }
.game-card + .game-card { margin-top: 12px; }
.refresh-note { margin: -16px 0 24px; color: var(--muted); font-size: 0.92rem; }
.site-footer { max-width: 560px; margin: 0 auto; padding: 0 16px 32px; color: var(--muted); font-size: 0.85rem; }
.site-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.site-footer a { color: inherit; }

.rally-art { position: relative; display: block; }
.rally-art .ball { position: absolute; top: 18px; left: 44px; width: 14px; height: 14px; border-radius: 50%; background: var(--a); }
.rally-art .paddle { position: absolute; bottom: 16px; left: 20px; width: 44px; height: 8px; border-radius: 4px; background: var(--b); }

.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 0.85rem; }
.badge { padding: 3px 10px; border-radius: 999px; background: var(--surface-2); font-weight: 600; }
.badge.done { background: var(--ok-bg); color: var(--ok); }
.streak { font-weight: 600; }

.snake-art { gap: 4px; }
.snake-art span { width: 100%; height: 100%; border-radius: 5px; }
.snake-art .s { background: var(--b); opacity: 0.8; }
.snake-art .s.head { opacity: 1; }
.snake-art .apple { background: var(--a); border-radius: 50%; scale: 0.8; }

.scramble-art { grid-template-columns: repeat(2, 1fr); gap: 6px; }
.scramble-art span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: var(--surface);
  font-size: 1.05rem;
  font-weight: 800;
}
.scramble-art .hit { background: var(--hit-bg); color: var(--hit-fg); }

.pipes-art { display: block; padding: 12px; }
.pipes-art svg { display: block; width: 100%; height: 100%; }
.pipes-art path { stroke: var(--b); }
.pipes-art circle { fill: var(--a); }

/* Fun theme (see the tokens at the top). Glowing background, gradient titles,
   one bright colour per game card, and chunky buttons that press down. */

[data-theme="fun"] body {
  background:
    radial-gradient(900px 520px at 0% -10%, rgba(255, 79, 163, 0.32), transparent 65%),
    radial-gradient(800px 480px at 100% 0%, rgba(34, 211, 238, 0.26), transparent 65%),
    radial-gradient(circle, rgba(255, 255, 255, 0.07) 1.5px, transparent 1.7px) 0 0 / 24px 24px,
    var(--bg);
  background-attachment: fixed;
}
[data-theme="fun"] :is(h1, h2, .btn, .seg, .badge, .day, .stats dd, .scoreboard strong, .overlay span) {
  font-family: var(--display);
  letter-spacing: 0.01em;
}
[data-theme="fun"] :is(.hub h1, .topbar h1) {
  background: linear-gradient(90deg, var(--a), var(--pink) 55%, var(--b));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
[data-theme="fun"] .hub h1 { width: fit-content; font-size: 2.6rem; font-weight: 700; }

[data-theme="fun"] .game-card {
  --card: var(--pink);
  border: 2px solid color-mix(in srgb, var(--card) 70%, transparent);
  box-shadow: 0 6px 0 var(--card);
}
[data-theme="fun"] .game-card:nth-child(5n + 2) { --card: var(--a); }
[data-theme="fun"] .game-card:nth-child(5n + 3) { --card: var(--b); }
[data-theme="fun"] .game-card:nth-child(5n + 4) { --card: var(--lime); }
[data-theme="fun"] .game-card:nth-child(5n + 5) { --card: #ff9f43; }
[data-theme="fun"] .game-card:hover { transform: translateY(-3px); box-shadow: 0 9px 0 var(--card); }
[data-theme="fun"] .game-card:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--card); }
[data-theme="fun"] .game-card h2 { color: var(--card); font-size: 1.3rem; }
[data-theme="fun"] .game-card .card-art { background: rgba(0, 0, 0, 0.24); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--card) 55%, transparent); }
[data-theme="fun"] .badge { background: var(--a); color: var(--ink); }
[data-theme="fun"] .badge.done { background: var(--ok); color: var(--ink); }

[data-theme="fun"] :is(.btn, .icon-btn) {
  border: 0;
  background: var(--surface-2);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
[data-theme="fun"] :is(.btn, .icon-btn):active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
[data-theme="fun"] .btn:hover:not(:disabled) { background: var(--line); }
[data-theme="fun"] .btn.primary { background: var(--a); color: var(--ink); box-shadow: 0 4px 0 #c79a00; }
[data-theme="fun"] .btn.primary:hover:not(:disabled) { background: var(--a); opacity: 1; filter: brightness(1.06); }
[data-theme="fun"] .btn.primary:active:not(:disabled) { box-shadow: 0 1px 0 #c79a00; }
[data-theme="fun"] .levels { border: 0; background: rgba(0, 0, 0, 0.22); }
[data-theme="fun"] .seg[aria-pressed="true"] { background: var(--a); color: var(--ink); }

[data-theme="fun"] dialog { border: 2px solid var(--line-strong); box-shadow: 0 8px 0 var(--pink), 0 24px 60px rgba(0, 0, 0, 0.45); }
[data-theme="fun"] dialog::backdrop { background: rgba(12, 6, 36, 0.65); }

@keyframes card-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } }
[data-theme="fun"] .game-card { animation: card-in 0.35s ease backwards; }
[data-theme="fun"] .game-card:nth-child(2) { animation-delay: 60ms; }
[data-theme="fun"] .game-card:nth-child(3) { animation-delay: 120ms; }
[data-theme="fun"] .game-card:nth-child(4) { animation-delay: 180ms; }
[data-theme="fun"] .game-card:nth-child(5) { animation-delay: 240ms; }
@media (prefers-reduced-motion: reduce) {
  [data-theme="fun"] .game-card { animation: none; }
}

/* The theme picker, in the home page footer */
.theme-picker { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.theme-picker .levels { padding: 2px; }
.theme-picker .seg { padding: 3px 10px; font-size: 0.82rem; }
