/* base.css: the shared look. Every page links this first, then its own style.css.
 *
 * Rule for game styles: use the tokens below (var(--text), var(--accent) ...) and the
 * classes at the bottom (.btn, .panel, .row ...). Do not write raw colours in a game,
 * or it will look wrong in the other theme.
 *
 * The theme follows the visitor's system setting: dark by default, light if they ask for it.
 * The light values appear twice (once for the system setting, once for a forced
 * data-theme="light" on <html>); keep the two blocks the same.
 */

:root {
  color-scheme: dark light;

  --bg: #0b1020;          /* page background */
  --surface: #131a2e;     /* panels and cards */
  --surface-2: #1c2542;   /* raised things: buttons, inputs */
  --line: #2f3b66;        /* borders */
  --text: #e6ecfa;
  --muted: #9aa7c7;       /* secondary text */
  --good: #5ee6b0;
  --warn: #ffc857;
  --bad: #ff7a85;
  --grid: rgba(255, 255, 255, 0.025);   /* the faint background grid */

  /* Six accents, one per game. A game picks one:  :root { --accent: var(--accent-3); } */
  --accent-1: #6cb4ff;    /* blue */
  --accent-2: #5ee6b0;    /* green */
  --accent-3: #ffb454;    /* amber */
  --accent-4: #c792ff;    /* violet */
  --accent-5: #ff8fab;    /* pink */
  --accent-6: #5fe1e6;    /* cyan */
  --accent-7: #b5e853;    /* lime */
  --accent-8: #ff8a5c;    /* orange */
  --accent-9: #8c9eff;    /* indigo */
  --accent-10: #f2d45c;   /* yellow */
  --accent-11: #d4a373;   /* tan */
  --accent-12: #cfd8e3;   /* silver */
  --accent: var(--accent-1);
  --on-accent: #08101f;   /* text on top of an accent-coloured button */

  --radius: 10px;
  --gap: 12px;
  --tap: 44px;            /* smallest comfortable touch target */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "DejaVu Sans Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f5fa;
    --surface: #ffffff;
    --surface-2: #e9edf6;
    --line: #c5cde0;
    --text: #131a2e;
    --muted: #55607c;
    --good: #0b7d55;
    --warn: #8f5b00;
    --bad: #c02236;
    --grid: rgba(0, 0, 0, 0.03);
    --accent-1: #1c64c4;
    --accent-2: #0b7d55;
    --accent-3: #9a5a00;
    --accent-4: #7038c8;
    --accent-5: #b72a63;
    --accent-6: #08737a;
    --accent-7: #4d7c0f;
    --accent-8: #b4441c;
    --accent-9: #4054b2;
    --accent-10: #806500;
    --accent-11: #8a5a2b;
    --accent-12: #4b5563;
    --on-accent: #ffffff;
  }
}

:root[data-theme="light"] {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #e9edf6;
  --line: #c5cde0;
  --text: #131a2e;
  --muted: #55607c;
  --good: #0b7d55;
  --warn: #8f5b00;
  --bad: #c02236;
  --grid: rgba(0, 0, 0, 0.03);
  --accent-1: #1c64c4;
  --accent-2: #0b7d55;
  --accent-3: #9a5a00;
  --accent-4: #7038c8;
  --accent-5: #b72a63;
  --accent-6: #08737a;
  --accent-7: #4d7c0f;
  --accent-8: #b4441c;
  --accent-9: #4054b2;
  --accent-10: #806500;
  --accent-11: #8a5a2b;
  --accent-12: #4b5563;
  --on-accent: #ffffff;
}

/* ------------------------------------------------------------------ basics */

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

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 16px/1.5 var(--font);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
}

main { max-width: 960px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }

h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

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

/* ------------------------------------------------------- the shell (top bar) */

.shell-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.shell-home {
  display: inline-flex; align-items: center;
  min-height: var(--tap); padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  font: 600 14px var(--mono); white-space: nowrap;
}
.shell-home:hover { border-color: var(--accent); }
.shell-title { font-size: 18px; }
.shell-error {
  padding: 10px 16px;
  background: var(--bad); color: #1b0509;
  font: 600 14px/1.4 var(--mono);
}

/* ---------------------------------------------------------------- building blocks */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); min-width: var(--tap); padding: 8px 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  font-weight: 600; cursor: pointer; text-decoration: none;
  transition: border-color 120ms, transform 80ms;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-quiet { background: transparent; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}

.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap); }
.stack { display: grid; gap: var(--gap); }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.how { color: var(--muted); }            /* the one line that says how to play */

.pill {
  display: inline-block; padding: 2px 10px;
  border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted); font: 600 12px var(--mono);
  text-transform: uppercase; letter-spacing: 0.06em;
}

.kbd {                                    /* a key hint, e.g. <span class="kbd">R</span> */
  display: inline-block; padding: 0 6px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px;
  background: var(--bg); color: var(--muted);
  font: 600 12px/1.6 var(--mono);
}

/* A horizontal meter. Set the fill with style="--value: 60%". */
.meter {
  height: 12px; overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px;
}
.meter > span { display: block; height: 100%; width: var(--value, 0%); background: var(--accent); }

/* The level picker: an <ol class="levels"> of <button class="btn level-chip">. */
.levels { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.level-chip { flex-direction: column; gap: 0; padding: 4px 10px; font-family: var(--mono); }
.level-chip[aria-current="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.stars { color: var(--warn); font-size: 14px; letter-spacing: 2px; }   /* text such as ★★☆ */

/* The win or lose panel. Add class "lost" for a loss. */
.result { border-left: 4px solid var(--good); }
.result.lost { border-left-color: var(--bad); }

.dev {                                    /* output shown only with ?dev in the URL */
  margin: 0; padding: 8px;
  border-radius: 6px; background: var(--surface-2);
  font: 13px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word;
}

/* A game canvas: scales with the page; touch goes to the game, not to scrolling. */
.stage {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
  touch-action: none;
}

.sr-only {                                /* for screen readers only */
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* ------------------------------------------------------------------- the hub */

.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin: 0; padding: 0; list-style: none; }
.card {
  display: grid; gap: 8px; align-content: start; height: 100%;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  transition: transform 120ms, border-color 120ms;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card h2, .card h3 { font-size: 20px; }
.hub-section > h2 { font-size: 14px; color: var(--muted); font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.08em; }
.card-go { color: var(--accent); font: 600 14px var(--mono); }
.hub-lead { font-size: 20px; font-weight: 600; }
.hub-foot { font-size: 14px; }

/* ------------------------------------------------------------ reduced motion */

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