/*
  Colors. Each state of a tile has its own hue so they can't be mistaken for one another, in either
  mode: plain = the palette's own tint, selected = a warm light, found = gray, hinted = a cool
  contrast to the palette, revealed = pink or red.

  HOW IT FITS TOGETHER. A palette defines every color twice, once as --l-name (for light) and once as
  --d-name (for dark), in a block written against [data-theme="..."]. The page sets that attribute on
  <html>, and the menu's little previews set it on themselves, so one palette never leaks into another.
  A selector layer further down (written once, for all palettes) then points the colors the rest of the
  stylesheet uses (--bg-a, --ink ...) at either the --l- or the --d- set:

      Appearance "System" (no data-mode):  light, or dark when the phone is in dark mode
      data-mode="light":                   always light
      data-mode="dark":                    always dark

  Indigo, the default, comes first and also applies to <html> when no palette has been chosen. Every
  palette defines every color in both modes: the tests check that, and that the text on each color
  stays readable and the tile states stay distinct.
*/

/* ---- Indigo (the default): a pastel wash of blue, violet and pink ---- */
:root, [data-theme="indigo"] {
    --l-bg-a: #dbeafe;
    --l-bg-b: #ede9fe;
    --l-bg-c: #fce7f3;
    --l-surface: #ffffff;
    --l-ink: #1e1b4b;
    --l-muted: #4b5586;
    --l-line: #c7d2fe;
    --l-accent: #4f46e5;
    --l-btn-a: #4f46e5;
    --l-btn-b: #7c3aed;
    --l-brand-a: #4338ca;
    --l-brand-b: #db2777;
    --l-glow: rgba(79, 70, 229, 0.35);
    --l-tile-a: #ffffff;
    --l-tile-b: #e8edff;
    --l-tile-line: #a5b4fc;
    --l-tile-ink: #1e1b4b;
    --l-sel: #fbbf24;
    --l-sel-ink: #3b2300;
    --l-done: #aab2c5;
    --l-done-ink: #2a3042;
    --l-hint: #22d3ee;
    --l-hint-ink: #053340;
    --l-hint-glow: rgba(8, 145, 178, 0.6);
    --l-reveal: #f472b6;
    --l-reveal-ink: #3b0a24;
    --l-chip-reveal: #be185d;
    --l-chip-found: #047857;
    --l-chip-time: #1d4ed8;
    --l-chip-score: #b45309;

    --d-bg-a: #0b1026;
    --d-bg-b: #1a1445;
    --d-bg-c: #2a1245;
    --d-surface: #181d40;
    --d-ink: #eef0ff;
    --d-muted: #a9b1d6;
    --d-line: #343c73;
    --d-accent: #818cf8;
    --d-brand-a: #a5b4fc;
    --d-brand-b: #f0abfc;
    --d-glow: rgba(129, 140, 248, 0.25);
    --d-tile-a: #2a3366;
    --d-tile-b: #222a57;
    --d-tile-line: #4b57a3;
    --d-tile-ink: #eef0ff;
    --d-sel: #fbbf24;
    --d-sel-ink: #2b1a00;
    --d-done: #555e82;
    --d-done-ink: #e1e5f4;
    --d-hint: #22d3ee;
    --d-hint-ink: #032b36;
    --d-hint-glow: rgba(34, 211, 238, 0.65);
    --d-reveal: #f472b6;
    --d-reveal-ink: #3a0620;
    --d-chip-reveal: #f9a8d4;
    --d-chip-found: #34d399;
    --d-chip-time: #60a5fa;
    --d-chip-score: #fbbf24;
    --d-btn-a: #4f46e5;
    --d-btn-b: #7c3aed;
}

/* ---- The other palettes ---- */

[data-theme="ocean"] {
    --l-bg-a: #d6f1f4; --l-bg-b: #dceafc; --l-bg-c: #e3f6ea;
    --l-surface: #ffffff; --l-ink: #0b2f3a; --l-muted: #3f6470; --l-line: #b8dde3;
    --l-accent: #0e7490; --l-btn-a: #0e7490; --l-btn-b: #2563eb;
    --l-brand-a: #0e7490; --l-brand-b: #2563eb; --l-glow: rgba(14, 116, 144, 0.35);
    --l-tile-a: #ffffff; --l-tile-b: #e3f4f6; --l-tile-line: #8fcad3; --l-tile-ink: #0b2f3a;
    --l-sel: #fbbf24; --l-sel-ink: #3b2300;
    --l-done: #9fb6bd; --l-done-ink: #14323b;
    --l-hint: #a78bfa; --l-hint-ink: #1e1042; --l-hint-glow: rgba(124, 58, 237, 0.55);
    --l-reveal: #fb7185; --l-reveal-ink: #4c0519; --l-chip-reveal: #be123c;
    /* dark */
    --d-bg-a: #04171c; --d-bg-b: #082a3a; --d-bg-c: #0b3b3a;
    --d-surface: #0d2830; --d-ink: #e6f8fb; --d-muted: #9ac3cc; --d-line: #1f4a55;
    --d-accent: #22d3ee; --d-btn-a: #0e7490; --d-btn-b: #2563eb;
    --d-brand-a: #67e8f9; --d-brand-b: #93c5fd; --d-glow: rgba(34, 211, 238, 0.25);
    --d-tile-a: #17414d; --d-tile-b: #11343f; --d-tile-line: #2f7585; --d-tile-ink: #e6f8fb;
    --d-sel: #fbbf24; --d-sel-ink: #2b1a00;
    --d-done: #5e7a84; --d-done-ink: #eef7fa;
    --d-hint: #a78bfa; --d-hint-ink: #170a3a; --d-hint-glow: rgba(167, 139, 250, 0.65);
    --d-reveal: #fb7185; --d-reveal-ink: #3f0415; --d-chip-reveal: #fda4af;
}

[data-theme="sunset"] {
    --l-bg-a: #ffe9d6; --l-bg-b: #ffe1e6; --l-bg-c: #fdeacb;
    --l-surface: #ffffff; --l-ink: #3b1409; --l-muted: #7a4a38; --l-line: #f2c9b0;
    --l-accent: #c2410c; --l-btn-a: #c2410c; --l-btn-b: #be185d;
    --l-brand-a: #c2410c; --l-brand-b: #be185d; --l-glow: rgba(194, 65, 12, 0.3);
    --l-tile-a: #ffffff; --l-tile-b: #fff0e4; --l-tile-line: #f0b890; --l-tile-ink: #3b1409;
    --l-sel: #f59e0b; --l-sel-ink: #2a1500;
    --l-done: #bfae9f; --l-done-ink: #2e2118;
    --l-hint: #22d3ee; --l-hint-ink: #053340; --l-hint-glow: rgba(8, 145, 178, 0.6);
    --l-reveal: #e879f9; --l-reveal-ink: #3b0b44; --l-chip-reveal: #a21caf;
    /* dark */
    --d-bg-a: #1c0b05; --d-bg-b: #2a0f12; --d-bg-c: #301a08;
    --d-surface: #2a1710; --d-ink: #fff1e6; --d-muted: #d4a98f; --d-line: #5a3320;
    --d-accent: #fb923c; --d-btn-a: #c2410c; --d-btn-b: #be185d;
    --d-brand-a: #fdba74; --d-brand-b: #f9a8d4; --d-glow: rgba(251, 146, 60, 0.25);
    --d-tile-a: #4a2a1a; --d-tile-b: #3d2114; --d-tile-line: #8a4f2e; --d-tile-ink: #fff1e6;
    --d-sel: #fbbf24; --d-sel-ink: #2b1a00;
    --d-done: #7a6658; --d-done-ink: #f6ece4;
    --d-hint: #22d3ee; --d-hint-ink: #032b36; --d-hint-glow: rgba(34, 211, 238, 0.65);
    --d-reveal: #e879f9; --d-reveal-ink: #3a0a42; --d-chip-reveal: #f0abfc;
}

[data-theme="forest"] {
    --l-bg-a: #dcf3df; --l-bg-b: #e4f1d3; --l-bg-c: #d5ece6;
    --l-surface: #ffffff; --l-ink: #10301c; --l-muted: #466a52; --l-line: #bcdcc3;
    --l-accent: #15803d; --l-btn-a: #15803d; --l-btn-b: #0f766e;
    --l-brand-a: #15803d; --l-brand-b: #0f766e; --l-glow: rgba(21, 128, 61, 0.3);
    --l-tile-a: #ffffff; --l-tile-b: #e6f5e8; --l-tile-line: #9fd1aa; --l-tile-ink: #10301c;
    --l-sel: #fbbf24; --l-sel-ink: #3b2300;
    --l-done: #a6b4a9; --l-done-ink: #15231a;
    --l-hint: #38bdf8; --l-hint-ink: #04293d; --l-hint-glow: rgba(2, 132, 199, 0.6);
    --l-reveal: #fb7185; --l-reveal-ink: #4c0519; --l-chip-reveal: #be123c;
    /* dark */
    --d-bg-a: #06150b; --d-bg-b: #0b2412; --d-bg-c: #0a2a22;
    --d-surface: #10281a; --d-ink: #e8f8ec; --d-muted: #9cc4a8; --d-line: #25513a;
    --d-accent: #4ade80; --d-btn-a: #15803d; --d-btn-b: #0f766e;
    --d-brand-a: #86efac; --d-brand-b: #5eead4; --d-glow: rgba(74, 222, 128, 0.25);
    --d-tile-a: #1d4a30; --d-tile-b: #173c27; --d-tile-line: #3f7f58; --d-tile-ink: #e8f8ec;
    --d-sel: #fbbf24; --d-sel-ink: #2b1a00;
    --d-done: #61776a; --d-done-ink: #f0f8f3;
    --d-hint: #38bdf8; --d-hint-ink: #03263a; --d-hint-glow: rgba(56, 189, 248, 0.65);
    --d-reveal: #fb7185; --d-reveal-ink: #3f0415; --d-chip-reveal: #fda4af;
}

[data-theme="berry"] {
    --l-bg-a: #f3e3fb; --l-bg-b: #fbe0ef; --l-bg-c: #e9e2fb;
    --l-surface: #ffffff; --l-ink: #3b0a45; --l-muted: #6e3d7a; --l-line: #e3c4ee;
    --l-accent: #a21caf; --l-btn-a: #a21caf; --l-btn-b: #7e22ce;
    --l-brand-a: #a21caf; --l-brand-b: #7e22ce; --l-glow: rgba(162, 28, 175, 0.3);
    --l-tile-a: #ffffff; --l-tile-b: #f6e7fc; --l-tile-line: #d9a8ea; --l-tile-ink: #3b0a45;
    --l-sel: #fbbf24; --l-sel-ink: #3b2300;
    --l-done: #b2a5be; --l-done-ink: #241a2b;
    --l-hint: #2dd4bf; --l-hint-ink: #022f2a; --l-hint-glow: rgba(13, 148, 136, 0.6);
    --l-reveal: #f87171; --l-reveal-ink: #450a0a; --l-chip-reveal: #b91c1c;
    /* dark */
    --d-bg-a: #14061a; --d-bg-b: #240a2e; --d-bg-c: #1b0d33;
    --d-surface: #26112e; --d-ink: #fbeaff; --d-muted: #d0a8dc; --d-line: #512a60;
    --d-accent: #e879f9; --d-btn-a: #a21caf; --d-btn-b: #7e22ce;
    --d-brand-a: #f0abfc; --d-brand-b: #c4b5fd; --d-glow: rgba(232, 121, 249, 0.25);
    --d-tile-a: #472259; --d-tile-b: #3a1a4a; --d-tile-line: #7d4a95; --d-tile-ink: #fbeaff;
    --d-sel: #fbbf24; --d-sel-ink: #2b1a00;
    --d-done: #5c4a68; --d-done-ink: #d4c4dd;
    --d-hint: #2dd4bf; --d-hint-ink: #022a26; --d-hint-glow: rgba(45, 212, 191, 0.65);
    --d-reveal: #f87171; --d-reveal-ink: #3f0a0a; --d-chip-reveal: #fca5a5;
}

[data-theme="graphite"] {
    --l-bg-a: #f4f5f7; --l-bg-b: #eceef1; --l-bg-c: #f2f2f2;
    --l-surface: #ffffff; --l-ink: #111418; --l-muted: #4a5059; --l-line: #c9ced6;
    --l-accent: #1d4ed8; --l-btn-a: #1f2937; --l-btn-b: #1d4ed8;
    --l-brand-a: #111418; --l-brand-b: #1d4ed8; --l-glow: rgba(17, 20, 24, 0.25);
    --l-tile-a: #ffffff; --l-tile-b: #eef0f3; --l-tile-line: #9aa3af; --l-tile-ink: #111418;
    --l-sel: #fbbf24; --l-sel-ink: #2a1a00;
    --l-done: #a7adb7; --l-done-ink: #1c2026;
    --l-hint: #38bdf8; --l-hint-ink: #04293d; --l-hint-glow: rgba(2, 132, 199, 0.6);
    --l-reveal: #fb7185; --l-reveal-ink: #4c0519; --l-chip-reveal: #be123c;
    /* dark */
    --d-bg-a: #0b0d10; --d-bg-b: #111419; --d-bg-c: #0e1013;
    --d-surface: #181c22; --d-ink: #f3f4f6; --d-muted: #a3abb7; --d-line: #2c333d;
    --d-accent: #60a5fa; --d-btn-a: #374151; --d-btn-b: #1d4ed8;
    --d-brand-a: #e5e7eb; --d-brand-b: #93c5fd; --d-glow: rgba(255, 255, 255, 0.1);
    --d-tile-a: #2a313b; --d-tile-b: #222830; --d-tile-line: #4b5563; --d-tile-ink: #f3f4f6;
    --d-sel: #fbbf24; --d-sel-ink: #2b1a00;
    --d-done: #626a76; --d-done-ink: #f1f3f6;
    --d-hint: #38bdf8; --d-hint-ink: #03263a; --d-hint-glow: rgba(56, 189, 248, 0.65);
    --d-reveal: #fb7185; --d-reveal-ink: #3f0415; --d-chip-reveal: #fda4af;
}

/* ---- Choosing between the two sets ---- */

:root { color-scheme: light dark; }
:root[data-mode="light"] { color-scheme: light; }
:root[data-mode="dark"] { color-scheme: dark; }

/* Light: the default. */
:root, [data-theme] {
    --bg-a: var(--l-bg-a);
    --bg-b: var(--l-bg-b);
    --bg-c: var(--l-bg-c);
    --surface: var(--l-surface);
    --ink: var(--l-ink);
    --muted: var(--l-muted);
    --line: var(--l-line);
    --accent: var(--l-accent);
    --btn-a: var(--l-btn-a);
    --btn-b: var(--l-btn-b);
    --brand-a: var(--l-brand-a);
    --brand-b: var(--l-brand-b);
    --glow: var(--l-glow);
    --tile-a: var(--l-tile-a);
    --tile-b: var(--l-tile-b);
    --tile-line: var(--l-tile-line);
    --tile-ink: var(--l-tile-ink);
    --sel: var(--l-sel);
    --sel-ink: var(--l-sel-ink);
    --done: var(--l-done);
    --done-ink: var(--l-done-ink);
    --hint: var(--l-hint);
    --hint-ink: var(--l-hint-ink);
    --hint-glow: var(--l-hint-glow);
    --reveal: var(--l-reveal);
    --reveal-ink: var(--l-reveal-ink);
    --chip-reveal: var(--l-chip-reveal);
    --chip-found: var(--l-chip-found);
    --chip-time: var(--l-chip-time);
    --chip-score: var(--l-chip-score);
}

/* Dark, when the phone is in dark mode, unless the player has asked for light. */
@media (prefers-color-scheme: dark) {
    :root:not([data-mode="light"]),
    :root:not([data-mode="light"]) [data-theme] {
        --bg-a: var(--d-bg-a);
        --bg-b: var(--d-bg-b);
        --bg-c: var(--d-bg-c);
        --surface: var(--d-surface);
        --ink: var(--d-ink);
        --muted: var(--d-muted);
        --line: var(--d-line);
        --accent: var(--d-accent);
        --btn-a: var(--d-btn-a);
        --btn-b: var(--d-btn-b);
        --brand-a: var(--d-brand-a);
        --brand-b: var(--d-brand-b);
        --glow: var(--d-glow);
        --tile-a: var(--d-tile-a);
        --tile-b: var(--d-tile-b);
        --tile-line: var(--d-tile-line);
        --tile-ink: var(--d-tile-ink);
        --sel: var(--d-sel);
        --sel-ink: var(--d-sel-ink);
        --done: var(--d-done);
        --done-ink: var(--d-done-ink);
        --hint: var(--d-hint);
        --hint-ink: var(--d-hint-ink);
        --hint-glow: var(--d-hint-glow);
        --reveal: var(--d-reveal);
        --reveal-ink: var(--d-reveal-ink);
        --chip-reveal: var(--d-chip-reveal);
        --chip-found: var(--d-chip-found);
        --chip-time: var(--d-chip-time);
        --chip-score: var(--d-chip-score);
    }
}

/* Dark, when the player has asked for it. */
:root[data-mode="dark"],
:root[data-mode="dark"] [data-theme] {
    --bg-a: var(--d-bg-a);
    --bg-b: var(--d-bg-b);
    --bg-c: var(--d-bg-c);
    --surface: var(--d-surface);
    --ink: var(--d-ink);
    --muted: var(--d-muted);
    --line: var(--d-line);
    --accent: var(--d-accent);
    --btn-a: var(--d-btn-a);
    --btn-b: var(--d-btn-b);
    --brand-a: var(--d-brand-a);
    --brand-b: var(--d-brand-b);
    --glow: var(--d-glow);
    --tile-a: var(--d-tile-a);
    --tile-b: var(--d-tile-b);
    --tile-line: var(--d-tile-line);
    --tile-ink: var(--d-tile-ink);
    --sel: var(--d-sel);
    --sel-ink: var(--d-sel-ink);
    --done: var(--d-done);
    --done-ink: var(--d-done-ink);
    --hint: var(--d-hint);
    --hint-ink: var(--d-hint-ink);
    --hint-glow: var(--d-hint-glow);
    --reveal: var(--d-reveal);
    --reveal-ink: var(--d-reveal-ink);
    --chip-reveal: var(--d-chip-reveal);
    --chip-found: var(--d-chip-found);
    --chip-time: var(--d-chip-time);
    --chip-score: var(--d-chip-score);
}

* { box-sizing: border-box; }

html {
    min-height: 100%;
    background-color: var(--bg-a);
    background-image: linear-gradient(160deg, var(--bg-a) 0%, var(--bg-b) 55%, var(--bg-c) 100%);
    background-attachment: fixed;
}

body {
    margin: 0;
    min-height: 100%;
    background: transparent;
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}

.shell {
    min-height: 100dvh;
    max-width: 760px;
    margin: 0 auto;
    padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
             max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.masthead { text-align: center; }

.brand {
    border: 0;
    font: inherit;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    padding: 6px 12px;
    cursor: pointer;
    /* The name in a pink-to-indigo gradient. */
    background: linear-gradient(90deg, var(--brand-a), var(--brand-b));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 4px solid var(--accent);
    border-radius: 14px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 10px 28px -14px var(--glow);
}

/* A game waiting to be picked up: green, like the "found" counter, and above the new-game card. */
.card.resume { border-top-color: var(--chip-found); }

/*
  The color picker. Each swatch carries its own data-theme, so everything inside it is painted in that
  palette's colors (in the player's current light or dark mode), whatever palette the page itself wears.
  The four chips show a button, a selected tile, a hinted tile and a found tile.
*/
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.swatch {
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    color: var(--ink);
    background: var(--surface);
    border: 2px solid var(--tile-line);
    border-radius: 12px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: center;
}
.swatch .preview {
    display: flex;
    justify-content: center;
    gap: 5px;
    padding: 8px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--bg-a), var(--bg-b) 55%, var(--bg-c));
}
.swatch .preview i { display: block; width: 18px; height: 18px; border-radius: 5px; }
.swatch .preview .a { background: linear-gradient(135deg, var(--btn-a), var(--btn-b)); }
.swatch .preview .b { background: var(--sel); }
.swatch .preview .c { background: var(--hint); }
.swatch .preview .d { background: var(--done); }
.swatch.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.swatch.on .name::after { content: " ✓"; }

.card h2 { margin: 0; font-size: 1.4rem; }
.eyebrow { margin: 0; color: var(--accent); font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }
.hint { margin: 0; color: var(--muted); line-height: 1.45; }

.field-label { display: flex; flex-direction: column; gap: 10px; font-weight: 600; }
.field-label input[type=range] { width: 100%; accent-color: var(--accent); margin: 0; min-height: 32px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

button.primary, button.secondary, button.quiet {
    font: inherit;
    font-weight: 600;
    border-radius: 10px;
    padding: 12px 20px;
    min-height: 46px;
    cursor: pointer;
    border: 1px solid transparent;
}
button.primary {
    background: linear-gradient(135deg, var(--btn-a), var(--btn-b));
    color: #ffffff;
    box-shadow: 0 8px 18px -10px var(--btn-a);
}
button.secondary { background: var(--surface); color: var(--ink); border-color: var(--tile-line); }
button.quiet { background: transparent; color: var(--muted); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* The Hint button wears the hint color, so it's clear which tiles it will light. */
button#hint::before {
    content: "";
    display: inline-block;
    width: 0.65em;
    height: 0.65em;
    margin-right: 0.55em;
    border-radius: 50%;
    background: var(--hint);
    box-shadow: 0 0 0 2px var(--hint-glow);
}

/* Give up wears the "revealed" pink; asked "are you sure?", it fills in. */
button#giveup::before {
    content: "";
    display: inline-block;
    width: 0.65em;
    height: 0.65em;
    margin-right: 0.55em;
    border-radius: 50%;
    background: var(--reveal);
}
button.danger { background: var(--reveal); color: var(--reveal-ink); border-color: transparent; }
button.danger::before { background: var(--reveal-ink); }

.game { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }

.stats {
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.chip {
    --chip: var(--muted);
    padding: 4px 12px;
    border-radius: 999px;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--line);
}
@supports (background: color-mix(in srgb, red 10%, blue)) {
    .chip {
        background: color-mix(in srgb, var(--chip) 14%, var(--surface));
        border-color: color-mix(in srgb, var(--chip) 38%, transparent);
    }
}
.chip b { color: var(--chip); font-variant-numeric: tabular-nums; }
.chip-found { --chip: var(--chip-found); }
.chip-time { --chip: var(--chip-time); }
.chip-score { --chip: var(--chip-score); }

.win {
    --chip: var(--chip-found);
    margin: 0;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--chip);
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
}
@supports (background: color-mix(in srgb, red 10%, blue)) {
    .win {
        background: color-mix(in srgb, var(--chip) 14%, var(--surface));
        border-color: color-mix(in srgb, var(--chip) 38%, transparent);
    }
}

/* The line under the win message saying where the time landed. */
.win .note { display: block; margin-top: 4px; font-size: 0.95rem; font-weight: 600; }

/* Top scores: a row of grid-size filters, and the list. */
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filter {
    font: inherit;
    font-weight: 600;
    padding: 6px 14px;
    min-height: 38px;
    border-radius: 999px;
    cursor: pointer;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--tile-line);
}
.filter.on {
    color: #ffffff;
    border-color: transparent;
    background: linear-gradient(135deg, var(--btn-a), var(--btn-b));
}

/*
  Five columns on a phone. The widths are fixed (and everything centred) rather than left to the browser:
  an automatic table hands spare width to whichever column has the longest content, and a long heading
  like "Total points" would then swell its column and bunch the others up around it.
*/
.score-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    font-size: 0.88rem;
}
/* Each column is its content plus about the same slack, so the gaps between them match. Points is the
   narrowest: its figures are short, and its two-line heading ("Total / points") is the widest thing in it. */
.score-table col.c-rank { width: 8%; }
.score-table col.c-time { width: 22%; }
.score-table col.c-points { width: 16.5%; }
.score-table col.c-grid { width: 21%; }
.score-table col.c-date { width: 32.5%; }
.score-table th, .score-table td { text-align: center; }
.score-table th {
    vertical-align: bottom;
    padding: 0;
    border-bottom: 2px solid var(--line);
}
.score-table td { padding: 10px 3px; border-bottom: 1px solid var(--line); }
/* Numbers and sizes never break across lines ("12 × 12" in two halves is unreadable); only the date,
   which can split after the comma, gives way when the screen is narrow. */
.score-table td:not(:last-child) { white-space: nowrap; }
.score-table td.time { font-weight: 700; color: var(--chip-time); }
.score-table td.points { font-weight: 700; color: var(--chip-score); }
.score-table td.rank.first { font-weight: 800; color: var(--chip-score); }

/* A heading you can tap to sort by; the arrow shows the column in use and its direction. */
.score-table th button.sort {
    font: inherit;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: center;
    color: var(--muted);
    background: none;
    border: 0;
    border-radius: 6px;
    padding: 8px 3px;
    min-height: 40px;
    width: 100%;
    cursor: pointer;
}
.score-table th button.sort.on { color: var(--accent); }
.score-table th button.sort:hover { background: var(--line); }

/* The very smallest phones (320 px wide): a little less type so the headings keep clear of each other. */
@media (max-width: 340px) {
    .score-table { font-size: 0.8rem; }
    .score-table th button.sort { font-size: 0.64rem; letter-spacing: 0; padding-inline: 1px; }
}
/* The score you've just earned. */
.score-table tr.new td { background: var(--sel); color: var(--sel-ink); }
.score-table tr.new td.time { color: var(--sel-ink); }
@supports (background: color-mix(in srgb, red 10%, blue)) {
    .score-table tr.new td { background: color-mix(in srgb, var(--sel) 35%, transparent); color: var(--ink); }
    .score-table tr.new td.time { color: var(--chip-time); }
}

/* A quiet line under the board. */
.caption {
    margin: 0;
    text-align: center;
    font-size: 0.85rem;
    color: var(--muted);
}

/* After giving up: a line saying how it went, and the answers spelled out. */
.gaveup {
    --chip: var(--chip-reveal);
    margin: 0;
    text-align: center;
    font-weight: 600;
    color: var(--chip);
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
}
@supports (background: color-mix(in srgb, red 10%, blue)) {
    .gaveup {
        background: color-mix(in srgb, var(--chip) 14%, var(--surface));
        border-color: color-mix(in srgb, var(--chip) 38%, transparent);
    }
}

.missed {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}
.missed li {
    padding: 4px 12px;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--reveal);
}

/* The board is as large as fits the screen. Its tiles size their numbers from the board's own width,
   so a 4 x 4 grid gets big digits and a 12 x 12 gets small ones. */
.board {
    --gap: 4px;
    container-type: inline-size;
    display: grid;
    grid-template-columns: repeat(var(--n), 1fr);
    gap: var(--gap);
    width: min(100%, calc(100dvh - var(--game-chrome)));
    min-width: 240px;
    aspect-ratio: 1;
    margin: 0 auto;
    /* A drag across the board selects; it must never scroll the page or select text. */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.tile {
    display: grid;
    place-items: center;
    border-radius: 8px;
    border: 1px solid var(--tile-line);
    background: linear-gradient(180deg, var(--tile-a), var(--tile-b));
    color: var(--tile-ink);
    box-shadow: 0 2px 0 var(--tile-line);
    font-size: calc(100cqw / var(--n) * 0.38);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    -webkit-tap-highlight-color: transparent;
}

/* Being dragged over: amber, lit up. */
.tile.sel {
    background: var(--sel);
    color: var(--sel-ink);
    border-color: transparent;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

/* Found: grayed out and flat. */
.tile.done {
    background: var(--done);
    color: var(--done-ink);
    border-color: transparent;
    box-shadow: none;
}
.tile.done.sel { outline: 3px solid var(--sel); outline-offset: -3px; }

/* Pointed at by a hint: cyan and pulsing. Dragging over it still shows the amber selection, and a
   square shared with a found equation stays gray but is ringed in cyan. */
.tile.hinted:not(.sel) {
    background: var(--hint);
    color: var(--hint-ink);
    border-color: transparent;
    animation: hint-pulse 1.2s ease-in-out infinite;
}
.tile.hinted.done:not(.sel) {
    background: var(--done);
    color: var(--done-ink);
    outline: 3px solid var(--hint);
    outline-offset: -3px;
}

/* Left unfound, shown once the player gives up: pink. A square also in a found equation stays gray but
   is ringed in pink, the same way a hint is. */
.tile.revealed:not(.sel) {
    background: var(--reveal);
    color: var(--reveal-ink);
    border-color: transparent;
}
.tile.revealed.done:not(.sel) {
    background: var(--done);
    color: var(--done-ink);
    outline: 3px solid var(--reveal);
    outline-offset: -3px;
}

@keyframes hint-pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--hint-glow); }
    50% { box-shadow: 0 0 0 4px var(--hint-glow); }
}

@media (prefers-reduced-motion: reduce) {
    .tile.hinted:not(.sel) { animation: none; box-shadow: 0 0 0 3px var(--hint-glow); }
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    padding: 12px 16px;
    background: #b3261e;
    color: #fff;
    text-align: center;
    z-index: 10;
}
#blazor-error-ui a { color: #fff; font-weight: 700; margin-left: 8px; }

.loading { display: grid; place-items: center; min-height: 60dvh; color: var(--muted); font-weight: 600; }

/* ---- The full game and the daily puzzle ---- */

/* The tester build says what it is across the top of every screen. */
.tester-banner {
    margin: 0;
    padding: 6px 12px;
    border-radius: 10px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--reveal-ink);
    background: var(--reveal);
}

/* The daily puzzle: wears the "hint" color, so it's a different card from a game waiting to be resumed. */
.card.daily { border-top-color: var(--hint); }
.chip-daily { --chip: var(--accent); color: var(--accent); font-weight: 700; }

/* Something the full game adds: a small tag, on a swatch, on the grid size, and the like. */
.locked-tag {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    vertical-align: middle;
}
.swatch .locked-tag { margin: 0 auto; }
.swatch.locked .preview { opacity: 0.85; }
.free-note { color: var(--muted); font-size: 0.85rem; font-weight: 400; }

/* The unlock page. */
.card.unlock { border-top-color: var(--chip-score); }
.unlock .reason {
    margin: 0;
    padding: 10px 14px;
    border-radius: 12px;
    font-weight: 600;
    line-height: 1.4;
    background: var(--sel);
    color: var(--sel-ink);
}
.unlock .includes { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: 8px; line-height: 1.4; }
.warn { margin: 0; text-align: center; font-weight: 600; color: var(--muted); }

/* ---- Statistics, the tutorial, puzzle codes, and the feedback switches ---- */

/* The practice grid's card: a green top edge like a game waiting, so it's clearly a lesson. */
.card.tutorial { border-top-color: var(--chip-found); }

/* Statistics: a grid of big numbers with their labels. */
.stats-page h3 { margin: 4px 0 0; font-size: 1rem; color: var(--muted); font-weight: 700; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    text-align: center;
}
.stat b { font-size: 1.5rem; font-variant-numeric: tabular-nums; color: var(--accent); }
.stat span { font-size: 0.85rem; color: var(--muted); }
.size-table td, .size-table th { text-align: center; }

/* The puzzle code box on the menu. */
.code-entry { display: flex; flex-direction: column; gap: 8px; }
.code-row { display: flex; gap: 10px; align-items: stretch; }
.code-row input {
    flex: 1;
    min-width: 0;
    font: inherit;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--tile-line);
    border-radius: 10px;
    padding: 10px 14px;
    min-height: 46px;
}
.code-row input::placeholder { color: var(--muted); opacity: 0.7; font-weight: 400; }
.code-row button { white-space: nowrap; }
.stat-grid.three { grid-template-columns: repeat(3, 1fr); }

/* ---- Levels, modes, themes, scoring ---- */

/* A level or mode the free game doesn't have: dimmed a little, with its tag. */
.filter.locked { opacity: 0.85; }
.filter .locked-tag { margin-left: 6px; }
.filter.on .locked-tag { color: inherit; border-color: currentColor; }

/* The level and the mode, as chips in a game. */
.chip-level { --chip: var(--accent); color: var(--accent); font-weight: 700; }
.chip-goal { --chip: var(--chip-reveal); }

/* A number to work out: the "?" square. Dashed, so it reads as a hole in the grid. */
.tile.mystery {
    font-weight: 800;
    border-style: dashed;
    border-width: 2px;
    border-color: var(--accent);
    color: var(--accent);
}
.tile.mystery.sel { color: var(--sel-ink); }

/* Under the board: what the last find was worth. A fixed height, so it appearing never moves the board. */
.find-slot { min-height: 3.4rem; display: flex; align-items: center; justify-content: center; }
.find-note {
    margin: 0;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0 12px;
    align-items: baseline;
    padding: 6px 14px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--chip-found);
    animation: find-pop 0.25s ease-out;
}
.find-note b { font-variant-numeric: tabular-nums; }
.find-note .pts { font-weight: 800; font-size: 1.15rem; color: var(--chip-found); font-variant-numeric: tabular-nums; }
.find-note small { grid-column: 1 / -1; color: var(--muted); }
@keyframes find-pop { from { transform: translateY(4px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .find-note { animation: none; } }

/* After a game: how the score added up. */
.breakdown {
    list-style: none;
    margin: 0;
    padding: 4px 14px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
}
.breakdown li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.breakdown li:last-child { border-bottom: 0; }
.breakdown li b { color: var(--chip-found); }
.breakdown li.minus b { color: var(--chip-reveal); }
.breakdown li.total { font-weight: 800; }
.breakdown li.total b { color: var(--chip-score); }

/* Themes on the menu: each one a button that says what it is. */
.card.themes { border-top-color: var(--chip-reveal); }
.theme-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.theme {
    font: inherit;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    min-height: 48px;
    border-radius: 12px;
    cursor: pointer;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--tile-line);
    box-shadow: 0 2px 0 var(--tile-line);
}
.theme:hover { border-color: var(--accent); }
.theme:active { transform: translateY(1px); box-shadow: none; }
.theme .name { font-weight: 700; }
.theme .blurb { color: var(--muted); font-size: 0.9rem; line-height: 1.35; }
.theme.locked { opacity: 0.9; }

/* The grid-size cell on Top Scores: the level in a smaller voice. */
.lvl { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 600; }

/* The rules page. */
.card.rules { border-top-color: var(--chip-score); }
.rules h3 { margin: 6px 0 0; font-size: 1rem; color: var(--muted); font-weight: 700; }
.rule-table td.what { text-align: left; }
.rule-table td.what b { display: block; }
.rule-table td.what span { display: block; color: var(--muted); font-size: 0.88rem; line-height: 1.35; }
.rule-table td.points { white-space: nowrap; }
.rule-table col.c-what { width: 66%; }
.rule-table col.c-pts { width: 34%; }
.level-list { display: flex; flex-direction: column; gap: 10px; }
.level { padding: 10px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.level p { margin: 0; }
.level .name { font-weight: 700; }
.level .examples { display: flex; flex-wrap: wrap; gap: 6px; }
.example { padding: 2px 10px; border-radius: 999px; border: 1px solid var(--tile-line); font-variant-numeric: tabular-nums; font-weight: 600; }
.rule-table td { vertical-align: top; white-space: normal !important; }
.rule-table td.points { text-align: center; padding-left: 6px; }
.rule-table th:first-child { text-align: left; padding-left: 3px; }
.level .examples > span { display: flex; flex-wrap: wrap; gap: 6px; }
.example { white-space: nowrap; }

/* The buttons under the grid sit in two fixed columns, so a label changing ("Hint · 1 free" to "Hint") never
   moves the others. An odd one out takes the whole last row. */
.game .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; max-width: 26rem; margin: 0 auto; }
.game .actions > button { padding-left: 12px; padding-right: 12px; }
.game .actions > button:last-child:nth-child(odd) { grid-column: 1 / -1; }

.miss-note { margin: 0; text-align: center; color: var(--muted); animation: find-pop 0.25s ease-out; }
@media (prefers-reduced-motion: reduce) { .miss-note { animation: none; } }

/* What is on screen besides the board while a game is open (the header, the chips, the note under the board and the
   buttons), so the board shrinks on a short screen and the buttons stay in view instead of below the fold. The tester
   build's banner takes more. */
:root { --game-chrome: 340px; }
:root:has(.tester-banner) { --game-chrome: 395px; }

/* A short screen (a phone held upright with the browser bars, a foldable's cover screen): the game's own header, chips
   and buttons tighten up so the board and all four buttons fit without scrolling. */
@media (max-height: 760px) {
    :root { --game-chrome: 240px; }
    :root:has(.tester-banner) { --game-chrome: 278px; }
    .shell { gap: 8px; padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .brand { font-size: 1.25rem; line-height: 1.2; }
    .game { gap: 8px; }
    .stats { gap: 6px; }
    .chip { padding: 2px 10px; font-size: 0.9rem; }
    .find-slot { min-height: 3rem; }
    /* The four in-play buttons share one row (a finished game has more, and keeps its two columns). */
    .game .actions:has(> :nth-child(4):last-child) { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: none; gap: 6px; }
    .game .actions > button { min-height: 42px; padding: 8px 4px; font-size: 0.85rem; }
}

/* ---- The board takes whatever height the screen has left ----
   In a game or the practice grid the page is exactly as tall as the window, and the board (a square in a slot that
   can shrink) gives up height before the buttons under it are pushed off the bottom. This holds on any screen: a short
   phone, an iPhone app on an iPad's smaller window, a page in a browser. Where container units aren't known, the
   earlier fixed reserve (--game-chrome above) stays in force. */
@supports (width: 1cqh) {
    .shell:has(.board-slot) { height: 100dvh; }
    .shell:has(.board-slot) > .game { flex: 1 1 0; min-height: 0; }
    .board-slot {
        container: board-slot / size;
        width: 100%;
        aspect-ratio: 1;
        flex: 0 1 auto;
        min-height: 160px;
        display: grid;
        place-items: center;
    }
    .board { width: min(100cqw, 100cqh); min-width: 0; margin: 0; }
    /* A finished or given-up game has more to say (the result, the score, the equations missed): the board keeps its size and
       the page scrolls. */
    .shell:has(.game .win), .shell:has(.game .gaveup) { height: auto; }
    .shell:has(.game .win) > .game, .shell:has(.game .gaveup) > .game { flex: none; min-height: 0; }
    .shell:has(.game .win) .board-slot, .shell:has(.game .gaveup) .board-slot { flex-shrink: 0; }
}

/* A phone (or an iPhone app on an iPad) turned on its side: there is no height to spare, so the board goes on the
   left, as tall as the screen, and everything else beside it. */
@media (orientation: landscape) and (max-height: 520px) {
    @supports (width: 1cqh) {
        :root {
            --bd: min(calc(100dvh - (max(6px, env(safe-area-inset-top)) + max(6px, env(safe-area-inset-bottom)))), 48vw);
        }
        :root:has(.tester-banner) {
            --bd: min(calc(100dvh - (max(6px, env(safe-area-inset-top)) + max(6px, env(safe-area-inset-bottom))) - 40px), 48vw);
        }
        .shell:has(.board-slot) {
            max-width: none;
            height: auto;
            min-height: 100dvh;
            gap: 6px;
            padding-top: max(6px, env(safe-area-inset-top));
            padding-bottom: max(6px, env(safe-area-inset-bottom));
        }
        .shell:has(.board-slot) .masthead { display: none; }

        /* The game: the board is taken out of the flow, on the left; the rest sits in the space beside it. */
        .shell > .game { position: relative; flex: none; min-height: var(--bd); padding-left: calc(var(--bd) + 16px); }
        .game > .board-slot { position: absolute; left: 0; top: 0; width: var(--bd); height: var(--bd); aspect-ratio: auto; min-height: 0; }
        .game .actions:has(> :nth-child(4):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 24rem; }

        /* The practice grid: the board on the right, the words and the button on the left. */
        .shell:has(.tutorial) { position: relative; padding-right: calc(var(--bd) + 32px); }
        .shell:has(.tutorial) > .board-slot { position: absolute; right: max(16px, env(safe-area-inset-right)); top: max(6px, env(safe-area-inset-top)); width: var(--bd); height: var(--bd); aspect-ratio: auto; min-height: 0; }
        .tutorial { padding: 10px 12px; gap: 6px; }
        .tutorial h2 { font-size: 1.1rem; }
        .tutorial .hint { font-size: 0.85rem; line-height: 1.3; }
    }
}

/* A short window (any shape): the practice card says the same in less room, so the board and the button under it fit. */
@media (max-height: 560px) {
    .tutorial { padding: 10px 12px; gap: 6px; }
    .tutorial h2 { font-size: 1.1rem; }
    .tutorial .hint { font-size: 0.85rem; line-height: 1.3; }
    .tutorial .eyebrow { font-size: 0.7rem; }
    @supports (width: 1cqh) { .board-slot { min-height: 140px; } }
}

/* The maker's mark at the foot of the menu: the Apps By DG logo, linking to appsbydg.com. A dark card in every palette. */
.maker-row { display: flex; justify-content: center; margin: 4px 0 8px; }
.maker {
    display: inline-flex; align-items: center; gap: 12px; padding: 10px 20px 10px 12px;
    border-radius: 14px; text-decoration: none; background: #17181c; color: #ffffff; border: 1px solid #343640;
    font: 700 1.15rem/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; letter-spacing: -0.02em;
}
.maker svg { width: 40px; height: 40px; flex: none; }
.maker .by { font-weight: 400; color: #b8bac2; }
.maker .dg { font-weight: 800; color: #db3a6f; }
.maker:hover { border-color: #db3a6f; }
.maker:focus-visible { outline: 3px solid #db3a6f; outline-offset: 3px; }
