/*
 * Cozy Sudoku — the whole look lives here.
 *
 * Rules of thumb the rest of the file follows:
 *  - Warm neutrals, never pure white or pure black. Paper, not screen.
 *  - Two-layer shadows: a hard 2px "lip" plus a soft ambient blur. That is what
 *    makes a flat rectangle feel like a physical tile you could pick up.
 *  - Generous radii and generous space. Cramped is the opposite of cozy, so
 *    when in doubt add air rather than another border.
 *  - Every theme sets the same token names, so nothing below needs to branch.
 */

/* Nunito, SIL Open Font License 1.1 — self-hosted latin subset, variable 400-800. */
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('/fonts/nunito-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                 U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
                 U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------------------------------------------------------------- themes -- */

:root {
  --r-xl: 30px;
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;
  --lip: 0 2px 0;
  --ease: cubic-bezier(.34, 1.4, .5, 1);
  --font: 'Nunito', ui-rounded, "SF Pro Rounded", system-ui, -apple-system,
          "Segoe UI", Roboto, sans-serif;

  /*
   * The room paintings keep their own material colour and light. These tokens
   * grade that authored art back into whichever board palette is active, so a
   * Cream room feels sun-warmed and a Midnight room feels genuinely nocturnal
   * without maintaining nine exports of every collection.
   */
  --scene-art-opacity: .88;
  --scene-art-filter: saturate(.74) contrast(.88) brightness(1.02);
  --scene-grade-top: color-mix(in srgb, var(--bg) 18%, transparent);
  --scene-grade-bottom: color-mix(in srgb, var(--bg-2) 28%, transparent);
  --scene-grade-edge: color-mix(in srgb, var(--bg-2) 34%, transparent);

  /*
   * What a tile is *made of*.
   *
   * The board theme owns the tile *face* (`--tile-hi` / `--tile-lo`); a tile
   * collection owns its glyph palette and surface. Keeping the material tied to
   * theme tokens prevents a frosted or polished face from becoming unreadable
   * on a dark board, while the artwork can use subject-specific colour. Every
   * mix below resolves against the loaded theme, so a new theme gets all sixteen
   * materials for free and a new collection gets all nine themes for free.
   *
   * These four are the neutral material — plain matte paper. Every set that
   * wants something else overrides them in the block after the themes.
   */
  --tile-face: linear-gradient(157deg, var(--tile-hi) 12%, var(--tile-lo) 100%);
  /* Painted *over* the face, so it is transparent almost everywhere. */
  --tile-fx: none;
  /* The lit top lip. A material may harden or soften it. */
  --tile-edge: inset 0 1px 0 var(--tile-hi);
  /* Applied to the artwork itself. `opacity(1)` is the identity filter — a
     real no-op, so the property can be concatenated into a filter list
     unconditionally rather than guarded at every call site. */
  --glyph-fx: opacity(1);
}

:root[data-theme="cream"] {
  --bg: #f5ecdd;
  --seam: rgba(122, 90, 58, .55);
  --well: rgba(126, 94, 62, .055);
  --mat: #f0e5d2;
  --scene: rgba(255, 238, 205, .55);
  --bg-2: #ecdfc9;
  --board: #fffbf4;
  --cell-alt: #fdf5ea;
  --line: rgba(140, 105, 70, .15);
  --line-strong: rgba(122, 90, 58, .40);
  --text: #52402f;
  --muted: #70604d;
  --chip: #fdf6ec;
  --sel: #f3d0a8;
  --sel-ink: #b3702f;
  --peer: rgba(216, 176, 132, .17);
  --same: rgba(216, 176, 132, .38);
  --bad: #d0655f;
  --bad-soft: rgba(208, 101, 95, .17);
  --given-chip: rgba(126, 94, 62, .17);
  --tile-hi: #fffdf8;
  --tile-lo: #f6ead7;
  --pale: #fffbf4;
  --shadow: rgba(126, 94, 62, .17);
  --shadow-lip: rgba(126, 94, 62, .12);
  --grain: .035;
}

:root[data-theme="sage"] {
  --bg: #e8ede1;
  --seam: rgba(74, 100, 66, .52);
  --well: rgba(72, 96, 64, .055);
  --mat: #e0e8d8;
  --scene: rgba(238, 250, 228, .50);
  --bg-2: #d8e3cd;
  --board: #fafcf7;
  --cell-alt: #f2f7ec;
  --line: rgba(88, 116, 78, .15);
  --line-strong: rgba(74, 100, 66, .38);
  --text: #42513b;
  --muted: #5a6550;
  --chip: #f4f8ef;
  --sel: #cbe0b6;
  --sel-ink: #567a41;
  --peer: rgba(150, 186, 130, .18);
  --same: rgba(150, 186, 130, .38);
  --bad: #c96a63;
  --bad-soft: rgba(201, 106, 99, .16);
  --given-chip: rgba(72, 96, 64, .16);
  --tile-hi: #fdfffb;
  --tile-lo: #ecf4e5;
  --pale: #fafcf7;
  --shadow: rgba(72, 96, 64, .16);
  --shadow-lip: rgba(72, 96, 64, .11);
  --grain: .035;
}

:root[data-theme="blush"] {
  --bg: #f5e8e6;
  --seam: rgba(140, 88, 88, .50);
  --well: rgba(122, 80, 80, .050);
  --mat: #f0dedb;
  --scene: rgba(255, 238, 236, .50);
  --bg-2: #eed9d7;
  --board: #fff9f8;
  --cell-alt: #fdefee;
  --line: rgba(150, 100, 100, .14);
  --line-strong: rgba(140, 88, 88, .36);
  --text: #59403f;
  --muted: #765a59;
  --chip: #fdf2f1;
  --sel: #f4cbc6;
  --sel-ink: #b0645d;
  --peer: rgba(226, 168, 164, .19);
  --same: rgba(226, 168, 164, .40);
  --bad: #cc5f5f;
  --bad-soft: rgba(204, 95, 95, .17);
  --given-chip: rgba(122, 80, 80, .15);
  --tile-hi: #fffbfa;
  --tile-lo: #fbe8e6;
  --pale: #fff9f8;
  --shadow: rgba(122, 80, 80, .16);
  --shadow-lip: rgba(122, 80, 80, .11);
  --grain: .035;
}

:root[data-theme="sky"] {
  --bg: #e5edf3;
  --seam: rgba(68, 96, 126, .50);
  --well: rgba(64, 90, 116, .050);
  --mat: #dce7f1;
  --scene: rgba(236, 247, 255, .55);
  --bg-2: #d4e2ee;
  --board: #f8fcff;
  --cell-alt: #eef5fb;
  --line: rgba(80, 110, 140, .14);
  --line-strong: rgba(68, 96, 126, .36);
  --text: #3e4e5c;
  --muted: #556471;
  --chip: #f2f8fc;
  --sel: #bfd9ec;
  --sel-ink: #47738f;
  --peer: rgba(150, 190, 220, .19);
  --same: rgba(150, 190, 220, .40);
  --bad: #c8635e;
  --bad-soft: rgba(200, 99, 94, .16);
  --given-chip: rgba(64, 90, 116, .15);
  --tile-hi: #fbfeff;
  --tile-lo: #e7f1f9;
  --pale: #f8fcff;
  --shadow: rgba(64, 90, 116, .16);
  --shadow-lip: rgba(64, 90, 116, .11);
  --grain: .035;
}

:root[data-theme="honey"] {
  --bg: #f7edd2;
  --seam: rgba(130, 98, 34, .55);
  --well: rgba(134, 102, 40, .055);
  --mat: #f2e5c2;
  --scene: rgba(255, 246, 214, .55);
  --bg-2: #efe0b4;
  --board: #fffcf0;
  --cell-alt: #fdf6e2;
  --line: rgba(150, 115, 40, .15);
  --line-strong: rgba(130, 98, 34, .40);
  --text: #57451d;
  --muted: #6f6142;
  --chip: #fdf7e6;
  --sel: #f4d98e;
  --sel-ink: #a87d20;
  --peer: rgba(224, 190, 110, .18);
  --same: rgba(224, 190, 110, .40);
  --bad: #cf655e;
  --bad-soft: rgba(207, 101, 94, .17);
  --given-chip: rgba(134, 102, 40, .16);
  --tile-hi: #fffef6;
  --tile-lo: #f7ecd0;
  --pale: #fffcf0;
  --shadow: rgba(134, 102, 40, .17);
  --shadow-lip: rgba(134, 102, 40, .12);
  --grain: .035;
}

:root[data-theme="lavender"] {
  --bg: #ece7f4;
  --seam: rgba(95, 80, 135, .50);
  --well: rgba(90, 74, 130, .050);
  --mat: #e5ddf0;
  --scene: rgba(246, 240, 255, .50);
  --bg-2: #ded5ec;
  --board: #fbfaff;
  --cell-alt: #f3f0fa;
  --line: rgba(110, 95, 150, .14);
  --line-strong: rgba(95, 80, 135, .36);
  --text: #48405c;
  --muted: #625977;
  --chip: #f5f2fb;
  --sel: #d3c7ee;
  --sel-ink: #6f5aa8;
  --peer: rgba(178, 160, 220, .18);
  --same: rgba(178, 160, 220, .38);
  --bad: #cc5f6a;
  --bad-soft: rgba(204, 95, 106, .16);
  --given-chip: rgba(90, 74, 130, .15);
  --tile-hi: #fdfcff;
  --tile-lo: #eee9f8;
  --pale: #fbfaff;
  --shadow: rgba(90, 74, 130, .16);
  --shadow-lip: rgba(90, 74, 130, .11);
  --grain: .035;
}

:root[data-theme="dusk"] {
  --bg: #26201e;
  --seam: rgba(255, 236, 214, .38);
  --well: rgba(0, 0, 0, .16);
  --mat: #221c1a;
  --scene: rgba(255, 206, 150, .10);
  --bg-2: #191514;
  --board: #332c28;
  --cell-alt: #3a322e;
  --line: rgba(255, 240, 224, .085);
  --line-strong: rgba(255, 236, 214, .28);
  --text: #eddfd0;
  --muted: #ab9c8d;
  --chip: #3c3330;
  --sel: #74594a;
  --sel-ink: #f4cfa6;
  --peer: rgba(214, 170, 126, .12);
  --same: rgba(214, 170, 126, .24);
  --bad: #e08078;
  --bad-soft: rgba(224, 128, 120, .19);
  --given-chip: rgba(0, 0, 0, .26);
  --tile-hi: #413833;
  --tile-lo: #2e2724;
  --pale: #f6ece0;
  --shadow: rgba(0, 0, 0, .42);
  --shadow-lip: rgba(0, 0, 0, .3);
  --grain: .05;
}

:root[data-theme="forest"] {
  --bg: #1e2621;
  --seam: rgba(216, 245, 224, .36);
  --well: rgba(0, 0, 0, .16);
  --mat: #1a221d;
  --scene: rgba(180, 255, 200, .07);
  --bg-2: #141a16;
  --board: #2a352d;
  --cell-alt: #303c33;
  --line: rgba(226, 255, 234, .08);
  --line-strong: rgba(216, 245, 224, .27);
  --text: #ddeadd;
  --muted: #9bae9c;
  --chip: #334036;
  --sel: #4f6b52;
  --sel-ink: #b9e0b4;
  --peer: rgba(150, 205, 155, .12);
  --same: rgba(150, 205, 155, .24);
  --bad: #e0837b;
  --bad-soft: rgba(224, 131, 123, .19);
  --given-chip: rgba(0, 0, 0, .26);
  --tile-hi: #3a473c;
  --tile-lo: #253028;
  --pale: #eaf4e8;
  --shadow: rgba(0, 0, 0, .42);
  --shadow-lip: rgba(0, 0, 0, .3);
  --grain: .05;
}

:root[data-theme="midnight"] {
  --bg: #1d222e;
  --seam: rgba(214, 226, 252, .38);
  --well: rgba(0, 0, 0, .17);
  --mat: #191e29;
  --scene: rgba(170, 200, 255, .08);
  --bg-2: #131722;
  --board: #293040;
  --cell-alt: #2f374a;
  --line: rgba(224, 234, 255, .085);
  --line-strong: rgba(214, 226, 252, .28);
  --text: #dfe6f2;
  --muted: #9da5b6;
  --chip: #313a4e;
  --sel: #4b5a80;
  --sel-ink: #b6c8f0;
  --peer: rgba(150, 175, 230, .12);
  --same: rgba(150, 175, 230, .24);
  --bad: #e0807e;
  --bad-soft: rgba(224, 128, 126, .19);
  --given-chip: rgba(0, 0, 0, .28);
  --tile-hi: #333c52;
  --tile-lo: #232a3a;
  --pale: #edf1fa;
  --shadow: rgba(0, 0, 0, .45);
  --shadow-lip: rgba(0, 0, 0, .32);
  --grain: .05;
}

/* A daylight painting graded only by hue still looks like a lit screen on a
   dark board. Pull the whole scene into the theme's exposure range, then let
   its real highlights and shadows survive underneath the colour wash. */
:root[data-theme="dusk"],
:root[data-theme="forest"],
:root[data-theme="midnight"] {
  --scene-art-opacity: .78;
  --scene-art-filter: saturate(.6) contrast(.9) brightness(.5);
  --scene-grade-top: color-mix(in srgb, var(--bg) 34%, transparent);
  --scene-grade-bottom: color-mix(in srgb, var(--bg-2) 50%, transparent);
  --scene-grade-edge: color-mix(in srgb, var(--bg-2) 58%, transparent);
}

/* -------------------------------------------------------- tile materials -- */
/*
 * One material per collection.
 *
 * A set used to change only *what* was drawn on the tile, never what the tile
 * was, so every collection read as one sticker pack with the subjects
 * swapped — which is exactly the thing you cannot charge for. A gemstone
 * should sit on something polished and a snowflake on something frosted.
 *
 * Two rules keep this from turning into noise:
 *
 * 1. **Every material effect is mixed from the theme's own tokens.**
 *    `--tile-hi` is the light end of the tile on a cream board and a warm
 *    near-black on a midnight one, so a specular mixed toward it stays a
 *    specular in both and nothing here has to know which theme is loaded. The
 *    glyph itself gets subject colour from `TILE_PALETTES` in tiles.js.
 * 2. **The effect layers are nearly transparent.** This is the surface under
 *    a puzzle. A material you notice while scanning for a 7 is too strong —
 *    it should register when you switch sets and disappear while you play.
 *
 * Four of the seven free sets are deliberately the plainest. That is not a
 * paywall trick: numerals, pips, shapes and garden are the sets you pick
 * *because* you want the board to get out of the way, and dressing them up
 * would be working against the reason somebody chose them.
 */

/* Garden — matte, with a soft bloom where the light lands. */
[data-tiles="garden"] {
  --tile-fx: radial-gradient(72% 58% at 22% 12%,
    color-mix(in srgb, var(--tile-hi) 55%, transparent) 0%, transparent 70%);
}

/* Breakfast — soft and creamy, a wide gentle gloss across the top. */
[data-tiles="breakfast"] {
  --tile-fx: linear-gradient(168deg,
    color-mix(in srgb, var(--tile-hi) 62%, transparent) 0%, transparent 46%);
}

/* Celestial — night. The face deepens toward the board and the artwork carries
   its own faint bloom, the way a light source drawn *on* a tile would spill. */
[data-tiles="celestial"] {
  --tile-face:
    radial-gradient(84% 70% at 26% 12%,
      color-mix(in srgb, var(--tile-hi) 82%, transparent) 0%, transparent 72%),
    linear-gradient(157deg,
      color-mix(in srgb, var(--tile-lo) 62%, var(--tile-hi)) 6%,
      color-mix(in srgb, var(--tile-lo) 66%, var(--shadow)) 100%);
  --glyph-fx: drop-shadow(0 0 2.6px color-mix(in srgb, currentColor 52%, transparent));
}

/* Tidepool — wet. One broad soft gloss over the top third, nothing hard. */
[data-tiles="ocean"] {
  --tile-fx:
    radial-gradient(128% 58% at 50% -12%,
      color-mix(in srgb, var(--tile-hi) 95%, transparent) 0%, transparent 72%),
    linear-gradient(0deg,
      color-mix(in srgb, var(--shadow) 16%, transparent) 0%, transparent 34%);
  --tile-edge: inset 0 1.6px 0 var(--tile-hi);
}

/* Autumn — dry. A fine paper tooth instead of a shine, which is the one
   material here that should look like it would feel rough. */
[data-tiles="autumn"] {
  --tile-fx:
    repeating-linear-gradient(51deg,
      color-mix(in srgb, var(--shadow) 11%, transparent) 0 1px,
      transparent 1px 5px),
    radial-gradient(70% 56% at 24% 14%,
      color-mix(in srgb, var(--tile-hi) 46%, transparent) 0%, transparent 72%);
}

/* Sweets — icing. A tight bright specular blob rather than a wide wash, which
   is the whole difference between a glazed thing and a matte one. */
[data-tiles="sweets"] {
  --tile-fx:
    radial-gradient(34% 26% at 26% 16%,
      color-mix(in srgb, var(--tile-hi) 100%, transparent) 0%,
      color-mix(in srgb, var(--tile-hi) 62%, transparent) 46%, transparent 72%),
    linear-gradient(196deg,
      transparent 58%, color-mix(in srgb, var(--tile-lo) 76%, var(--shadow)) 100%);
  --tile-edge: inset 0 1.5px 0 var(--tile-hi);
}

/* Winter — frosted. Cool, and lit faintly on every edge rather than only the
   top lip, the way rime picks out a rim all the way round. */
[data-tiles="winter"] {
  --tile-fx: linear-gradient(157deg,
    color-mix(in srgb, var(--tile-hi) 72%, transparent) 0%,
    transparent 42%,
    color-mix(in srgb, var(--tile-hi) 42%, transparent) 100%);
  --tile-edge:
    inset 0 1px 0 var(--tile-hi),
    inset 0 0 0 1px color-mix(in srgb, var(--tile-hi) 34%, transparent);
}

/* Gemstones — polished. The only hard-edged material in the set: a narrow
   facet band cutting the face on the diagonal, and a crisp lit border. */
[data-tiles="gemstones"] {
  --tile-fx: linear-gradient(126deg,
    transparent 33%,
    color-mix(in srgb, var(--tile-hi) 58%, transparent) 39%,
    color-mix(in srgb, var(--tile-hi) 58%, transparent) 43%,
    transparent 49%);
  --tile-edge:
    inset 0 1.4px 0 var(--tile-hi),
    inset 0 0 0 1px color-mix(in srgb, var(--tile-hi) 46%, transparent);
  --glyph-fx: drop-shadow(0 .6px .6px var(--shadow-lip));
}

/* Origami — paper. One soft crease running across the face, and a tooth fine
   enough to be felt rather than seen. The crease is deliberately *soft*: a hard
   line is Gemstones' facet, and paper folded then flattened catches the light
   over a few millimetres rather than along an edge. */
[data-tiles="origami"] {
  --tile-fx:
    linear-gradient(148deg,
      transparent 26%,
      color-mix(in srgb, var(--tile-hi) 46%, transparent) 40%,
      color-mix(in srgb, var(--tile-hi) 46%, transparent) 46%,
      transparent 60%),
    repeating-linear-gradient(74deg,
      color-mix(in srgb, var(--shadow) 7%, transparent) 0 1px,
      transparent 1px 4px);
  --tile-edge: inset 0 1.2px 0 var(--tile-hi);
}

/* Market — wet. A broad soft bloom across the shoulder and a faint lift off the
   bottom, which is how anything just rinsed reads: not a highlight sitting on
   the surface, but the whole surface being slightly brighter than it is dry. */
[data-tiles="market"] {
  --tile-fx:
    radial-gradient(58% 40% at 34% 14%,
      color-mix(in srgb, var(--tile-hi) 78%, transparent) 0%, transparent 74%),
    linear-gradient(0deg,
      color-mix(in srgb, var(--tile-hi) 30%, transparent) 0%, transparent 26%);
}

/* Stitchcraft — wool, which is the one material here with no shine at all.
   Everything else on the shelf answers the light with a specular of some kind;
   a soft thing answers it by going evenly pale on the lit side and nowhere
   else. The fibre is two fine speckles at different angles, kept under the
   floor of visibility so it reads as nap rather than as noise. */
[data-tiles="stitch"] {
  --tile-fx:
    repeating-linear-gradient(28deg,
      color-mix(in srgb, var(--tile-hi) 22%, transparent) 0 1px,
      transparent 1px 3px),
    repeating-linear-gradient(-64deg,
      color-mix(in srgb, var(--shadow) 6%, transparent) 0 1px,
      transparent 1px 5px),
    linear-gradient(154deg,
      color-mix(in srgb, var(--tile-hi) 40%, transparent) 0%, transparent 58%);
  --tile-edge: inset 0 1px 0 color-mix(in srgb, var(--tile-hi) 72%, transparent);
}

/* Fruit — sun-warmed skin. A soft shoulder bloom and one restrained dapple
   give the face the faint waxy lift of fruit without turning the board glossy. */
[data-tiles="fruit"] {
  --tile-fx:
    radial-gradient(58% 44% at 27% 13%,
      color-mix(in srgb, var(--tile-hi) 72%, transparent) 0%, transparent 72%),
    radial-gradient(10% 8% at 72% 68%,
      color-mix(in srgb, var(--shadow) 10%, transparent) 0%, transparent 76%);
  --tile-edge: inset 0 1.3px 0 color-mix(in srgb, var(--tile-hi) 82%, transparent);
}

/* Houseplants — daylight. Not a specular at all: a broad soft band of window
   light falling across the face at a steep angle, which is the thing every
   plant on a shelf is arranged around. The one mottle low and right is unglazed
   clay, and like every material here it should only register when you switch
   sets. */
[data-tiles="houseplant"] {
  --tile-fx:
    linear-gradient(104deg,
      transparent 6%,
      color-mix(in srgb, var(--tile-hi) 56%, transparent) 23%,
      color-mix(in srgb, var(--tile-hi) 56%, transparent) 44%,
      transparent 63%),
    radial-gradient(30% 26% at 76% 74%,
      color-mix(in srgb, var(--shadow) 9%, transparent) 0%, transparent 76%);
  --tile-edge: inset 0 1.2px 0 color-mix(in srgb, var(--tile-hi) 78%, transparent);
}

/* Woodland — grain.
   Two bands at deliberately incommensurate periods (7px and 11px), because a
   single repeat at one spacing reads as corduroy rather than as wood: the eye
   locks onto the rhythm instantly. Beating the two against each other gives a
   figure that never quite repeats inside one tile, which is what timber
   actually looks like. Both are near the floor of visibility on purpose. */
[data-tiles="woodland"] {
  --tile-fx:
    repeating-linear-gradient(93deg,
      color-mix(in srgb, var(--shadow) 15%, transparent) 0 1px,
      transparent 1px 7px),
    repeating-linear-gradient(93deg,
      color-mix(in srgb, var(--shadow) 9%, transparent) 0 2px,
      transparent 2px 11px),
    radial-gradient(76% 60% at 22% 14%,
      color-mix(in srgb, var(--tile-hi) 46%, transparent) 0%, transparent 74%);
}

/* ------------------------------------------------------------------ base -- */

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
[hidden] { display: none !important; }

/*
 * The room the board sits in.
 *
 * Three stacked washes rather than one flat field: a light bloom from the upper
 * left, a soft pooling of surface at the foot, and the original base gradient
 * under both. The bloom comes from the upper left on purpose — every tile set
 * is drawn with its light source there, so the page and the artwork are lit
 * from the same window instead of disagreeing about where the sun is.
 *
 * These gradients are also the no-script, not-yet-decoded and offline fallback
 * under the authored room. The paper grain still lays over both scene and UI.
 */
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(58% 45% at 16% 4%, var(--scene) 0%, transparent 62%),
    radial-gradient(100% 55% at 50% 106%, var(--bg-2) 0%, transparent 72%),
    radial-gradient(130% 100% at 50% -15%, var(--bg) 0%, var(--bg-2) 78%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding: max(14px, env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

/*
 * One cohesive painting now carries the wall, window, desk and collection
 * dressing. The two desktop image layers are double-buffered: app.js decodes
 * the next room off-screen and only then crossfades, so switching collections
 * never flashes an empty background. A small portrait crop gives phones the
 * same painted plaster and desk without downloading mostly-hidden room art.
 */
.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
  background: transparent;
}

.scene-art,
.scene-mobile,
.scene-grade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene-art {
  display: none;
  object-fit: cover;
  opacity: 0;
  filter: var(--scene-art-filter);
  transform: scale(1.008);
  transition: opacity .9s ease;
  user-select: none;
}

.scene-art.is-visible { opacity: var(--scene-art-opacity); }

.scene-mobile {
  display: none;
  background-image: url('/art/rooms/mobile.webp?v=83');
  background-position: center 48%;
  background-repeat: no-repeat;
  background-size: cover;
  filter: var(--scene-art-filter);
  opacity: var(--scene-art-opacity);
}

.scene-grade {
  background:
    radial-gradient(72% 70% at 50% 42%, transparent 25%, var(--scene-grade-edge) 100%),
    linear-gradient(180deg, var(--scene-grade-top), var(--scene-grade-bottom));
}

@media (min-width: 900px) and (min-height: 600px) {
  .scene-art { display: block; }

  /* Celestial is already authored at night. Scope its gentler exposure pull
     to the desktop painting: phones always show the daylight Study crop, no
     matter which collection is selected. */
  :root[data-tiles="celestial"][data-theme="dusk"] .scene-art,
  :root[data-tiles="celestial"][data-theme="forest"] .scene-art,
  :root[data-tiles="celestial"][data-theme="midnight"] .scene-art {
    --scene-art-opacity: .84;
    --scene-art-filter: saturate(.68) contrast(.92) brightness(.74);
  }

  :root[data-tiles="celestial"][data-theme="dusk"] .scene-grade,
  :root[data-tiles="celestial"][data-theme="forest"] .scene-grade,
  :root[data-tiles="celestial"][data-theme="midnight"] .scene-grade {
    --scene-grade-top: color-mix(in srgb, var(--bg) 28%, transparent);
    --scene-grade-bottom: color-mix(in srgb, var(--bg-2) 42%, transparent);
    --scene-grade-edge: color-mix(in srgb, var(--bg-2) 48%, transparent);
  }
}

/* Portrait and ordinary phone layouts get the lightweight painted crop. Very
   short landscape viewports keep the gradient fallback instead of decoding a
   portrait image only to crop almost all of it away. */
@media (max-width: 899px) and (min-height: 500px) {
  .scene-mobile { display: block; }
}

@media (forced-colors: active) {
  .scene { display: none; }

  /* Forced colors removes shadows and flattens cell backgrounds. Keep the
     input target and the first hint visible in the player's system palette. */
  .cell.sel::after,
  .cell.nudge::after {
    outline: 2.5px solid Highlight;
  }
}

/* A whisper of paper grain. Without it the flat fills read as plastic. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}

.shell {
  position: relative;
  /* Above the scene (0) and the grain (1). */
  z-index: 2;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

h1, h2 { margin: 0; font-weight: 800; letter-spacing: -.015em; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }
a { color: inherit; }

/* --------------------------------------------------------------- topbar -- */

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
}

.title-block { text-align: center; min-width: 0; }
/* Never let the wordmark wrap. At 22px it needs ~156px, which a 360px phone
   does not have once the buttons and timer have taken their share — so it broke
   to two lines and shoved the subtitle under the topbar. It scales down with
   the viewport instead, and truncates rather than reflowing the header. */
.title-block h1 {
  font-size: clamp(16px, 5vw, 22px);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color .2s;
}

.topbar-right { display: flex; align-items: center; gap: 8px; }

.timer {
  position: relative;
  font-variant-numeric: tabular-nums;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--muted);
  min-width: 44px;
  text-align: right;
  border: 0;
  background: none;
  padding: 4px 2px;
  transition: color .15s;
}
.timer:hover { color: var(--text); }
.timer[hidden] { display: none; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: var(--chip);
  box-shadow: var(--lip) var(--shadow-lip), 0 5px 14px -8px var(--shadow);
  color: var(--muted);
  transition: transform .13s var(--ease), color .13s;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:hover { color: var(--text); }
.icon-btn:active { transform: translateY(2px); box-shadow: none; }
.icon-btn:disabled { opacity: .38; cursor: default; transform: none; }
.icon-btn[hidden] { display: none; }
.ghost-btn { position: relative; width: 38px; height: 38px; border-radius: 12px; }
.ghost-btn svg { width: 18px; height: 18px; }
.pause-btn .play-mark { display: none; }
.pause-btn[aria-pressed="true"] { background: var(--sel); color: var(--sel-ink); }
.pause-btn[aria-pressed="true"] .pause-mark { display: none; }
.pause-btn[aria-pressed="true"] .play-mark { display: block; }

/*
 * The quiet controls are small on purpose and hittable anyway.
 *
 * Progress and the clock are deliberately lighter than the primary + button —
 * that is what makes the header read as one thing to press and two things to
 * glance at. But it put both under every touch minimum there is (38x38 and
 * 38x27 against 44), on the one page where a mis-tap costs you the puzzle you
 * were looking at. The hit area is grown without growing the object: a centred,
 * invisible overlay reaches 44px in whichever axis falls short and changes
 * nothing about how the header looks. The 8px header gap is wider than the
 * 3px each side this can add, so neither one steals from its neighbour.
 */
.ghost-btn::after,
.timer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  width: max(100%, 44px);
  height: max(100%, 44px);
}

/* ---------------------------------------------------------- level home -- */

/*
 * The level journey is the front door, and it is made of the board.
 *
 * One tray holds the whole home: the chapter's name, its ten levels as slots,
 * the button that plays the next one, and two quiet rows under a hairline.
 * A finished level is a lit tile, the next one is the selected square, the
 * rest are dished wells, exactly as on the board. There are no cards on cards,
 * no capitalised labels and no badges: hierarchy comes from size and weight.
 */
.shell.home-mode {
  max-width: 640px;
  gap: clamp(14px, 2.5vh, 22px);
}

.home-view {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  border-radius: 34px;
  background: linear-gradient(170deg, var(--board), var(--cell-alt));
  box-shadow:
    inset 0 1px 0 var(--tile-hi),
    var(--lip) var(--shadow-lip),
    0 26px 60px -34px var(--shadow);
}

.chapter {
  display: grid;
  gap: 22px;
  padding: clamp(24px, 5vw, 40px) clamp(20px, 5vw, 40px) 22px;
}

.chapter-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}
.chapter-head h2 {
  font-size: clamp(32px, 6vw, 44px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -.015em;
}
.chapter-blurb {
  max-width: 34ch;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
}

/* The tray. Ten slots, one row where it fits, two rows of five where not. */
.level-tray {
  list-style: none;
  margin: 0;
  padding: clamp(8px, 1.6vw, 12px);
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: clamp(5px, 1.2vw, 9px);
  border-radius: 22px;
  background: var(--cell-alt);
  box-shadow: inset 0 0 0 1px var(--line), 0 1px 0 var(--tile-hi);
}
.level-slot {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: clamp(15px, 2.6vw, 19px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  /* A dished well: shadow under the top lip, light on the bottom one. */
  background: var(--well);
  box-shadow: inset 0 3px 4px var(--shadow), inset 0 -1px 0 var(--tile-hi);
  transition: transform .13s var(--ease), box-shadow .13s;
}
.level-slot:disabled {
  cursor: default;
  color: color-mix(in srgb, var(--muted) 62%, transparent);
}
/* Finished: a tile sitting on the tray, the same face a placed answer wears. */
.level-slot.done {
  color: var(--text);
  background: var(--tile-face);
  box-shadow: var(--tile-edge), var(--lip) var(--shadow-lip), 0 6px 10px -7px var(--shadow);
}
.level-slot.done:active { transform: translateY(2px); box-shadow: var(--tile-edge); }
/* Next: the selected square. */
.level-slot.current {
  color: var(--text);
  background: var(--sel);
  box-shadow: 0 0 0 2px var(--sel-ink), var(--lip) var(--shadow-lip);
}

.journey-primary {
  min-height: 56px;
  border: 0;
  border-radius: 18px;
  background: var(--sel);
  color: var(--text);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--tile-hi) 70%, transparent), var(--lip) var(--shadow-lip),
    0 12px 22px -16px var(--shadow);
  font-size: 17px;
  font-weight: 800;
  transition: transform .13s var(--ease), box-shadow .13s;
}
.journey-primary:active { transform: translateY(2px); box-shadow: none; }

/* First run only: the one way from the numbers board to the picture tiles. */
.tiles-offer { justify-self: center; align-self: center; margin: 2px auto 0; }
.tiles-offer[hidden] { display: none; }
.shell.paused .tiles-offer { visibility: hidden; }

.chapter-foot {
  margin: -6px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 700;
}
.text-link {
  border: 0;
  padding: 4px 0;
  background: none;
  color: var(--sel-ink);
  font-size: 13.5px;
  font-weight: 800;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}

/* The sill: a painted ledge, objects standing on it, one per day. */
.sill {
  display: grid;
  gap: 10px;
  padding: 18px clamp(20px, 5vw, 40px) 0;
  border-top: 1px solid var(--line);
}
.sill[hidden] { display: none; }
.sill-copy {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
}
.sill-copy strong { color: var(--text); font-weight: 900; }
.sill-shelf {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  min-height: 48px;
  padding: 0 8px 7px;
  overflow: hidden;
}
/* The ledge itself, drawn under the objects so they stand on it. */
.sill-shelf::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 8px;
  border-radius: 4px;
  background: var(--mat);
  box-shadow: inset 0 1px 0 var(--tile-hi), 0 2px 0 var(--shadow-lip), 0 6px 10px -6px var(--shadow);
}
.keepsake {
  position: relative;
  z-index: 1;
  flex: none;
  width: 40px;
  height: 40px;
  margin-bottom: -2px;
}
.keepsake .glyph {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 1.5px var(--shadow-lip));
}
.keepsake.today { animation: keepsake-arrive .7s var(--ease) both; }
@keyframes keepsake-arrive {
  from { transform: translateY(-14px) scale(.85); opacity: 0; }
}

/* Two quiet rows, separated by hairlines, for everything that is not the journey. */
.home-rows {
  display: grid;
  margin-top: 16px;
  border-top: 1px solid var(--line);
}
.home-row {
  width: 100%;
  min-height: 64px;
  border: 0;
  padding: 12px clamp(20px, 5vw, 40px);
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  text-align: left;
  transition: background-color .15s;
}
.home-row + .home-row { border-top: 1px solid var(--line); }
.home-row:last-child { border-radius: 0 0 34px 34px; }
.home-row:active { background: var(--peer); }
.home-row-text { flex: 1; min-width: 0; }
.home-row-text strong,
.home-row-text small { display: block; }
.home-row-text strong { font-size: 15.5px; font-weight: 800; }
.home-row-text small { margin-top: 1px; color: var(--muted); font-size: 13px; font-weight: 600; }
.home-row-go { width: 20px; height: 20px; flex: none; color: var(--sel-ink); }
.home-row .daily-badge {
  flex: none;
  padding: 0;
  border-radius: 0;
  background: none;
  color: var(--sel-ink);
  font-size: 13px;
  font-weight: 800;
}
.daily-strip.is-done .home-row-text strong { color: var(--muted); }

@media (max-width: 560px) {
  .home-view { border-radius: 28px; }
  .home-row:last-child { border-radius: 0 0 28px 28px; }
  .chapter { gap: 18px; }
  .level-tray { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .level-slot { font-size: 18px; }
  .keepsake { width: 34px; height: 34px; }
  .keepsake:nth-last-child(n+9) { display: none; }
}

/* ---------------------------------------------------------------- board -- */

/* `main` has to lay itself out: .shell's gap only separates header / main /
   footer, so with main left as a plain block the board and the tile pad sat
   flush against each other with zero space between them. */
main {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.board-wrap {
  position: relative;
  --board-pad: 12px;
  --seam-w: 3px;
}

/*
 * The nine rows are stated, not implied.
 *
 * The board only ever declared its columns and let the 81 cells fall into
 * *implicit* rows, which are `auto` — they fill the square only because
 * `align-content: normal` stretches auto tracks into the leftover space. That
 * is one engine's reading of a height that came from `aspect-ratio` rather than
 * from a number, and WebKit does not share it: the rows size to their content
 * instead. An empty cell has no content at all (its well is an absolutely
 * positioned `::before` and there is no glyph), so a row with no clues and no
 * answers in it collapses to a sliver, the cage's thirds stop lining up with
 * the boxes, and the board leaves a gap at the bottom. That is what an iPhone
 * was showing: a squashed middle row with nothing in it.
 *
 * `repeat(9, 1fr)` resolves against the definite height directly, so nothing
 * depends on how a UA stretches auto tracks, and a row's height no longer
 * depends on whether anything is standing in it.
 */
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  aspect-ratio: 1;
  background: var(--board);
  border-radius: var(--r-xl);
  padding: var(--board-pad);
  box-shadow:
    inset 0 0 0 1px var(--line),
    inset 0 2px 5px -2px var(--shadow-lip),
    0 2px 0 var(--shadow-lip),
    0 1px 2px var(--shadow-lip),
    0 16px 38px -14px var(--shadow);
  overflow: hidden;
  touch-action: manipulation;
}

/*
 * The 3x3 cage, as its own layer over the cells.
 *
 * It used to be a heavier border on every third cell, which failed twice. A
 * cell's background paints right up to its own border, so the instant you
 * selected a square the row/column/box shading swallowed the box rule exactly
 * where you were looking — the structure disappeared precisely when you needed
 * it. And at .40 alpha it was barely heavier than the hairlines it was meant to
 * dominate, so even unshaded the nine boxes never read as boxes.
 *
 * A 3x3 grid pinned over the board cannot be painted over by anything, and its
 * lines land on exact thirds by construction rather than by rounding a
 * percentage. It sits above the cells but below the veil.
 */
.cage {
  position: absolute;
  inset: var(--board-pad);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
  z-index: 2;
}
.cage i {
  border-right: var(--seam-w) solid var(--seam);
  border-bottom: var(--seam-w) solid var(--seam);
}
.cage i:nth-child(3n) { border-right: 0; }
.cage i:nth-child(n + 7) { border-bottom: 0; }

/* A `role="grid"` is only a grid if its cells sit in rows. These wrappers exist
   purely for the accessibility tree — `display: contents` keeps the nine-column
   CSS grid on .board addressing the cells directly, exactly as before. */
.board-row { display: contents; }

.cell {
  position: relative;
  display: grid;
  place-items: center;
  isolation: isolate;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 4px;
  /* Keep the shading inside the rule rather than under it. With the default
     border-box clip, a translucent hairline sits on top of whatever the cell is
     currently tinted and muddies to a different colour in every state. */
  background-clip: padding-box;
  transition: background-color .16s ease;
  cursor: pointer;
  user-select: none;
}
.cell.edge-x { border-right: 0; }
.cell.edge-y { border-bottom: 0; }

.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.bad  { background: var(--bad-soft); }
.cell.sel  { background: var(--sel); }

/* The selection also gets a ring, so it stays obvious on a shaded row. */
.cell.sel::after {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 9px;
  box-shadow: 0 0 0 2.5px var(--sel-ink);
  z-index: 2;
  pointer-events: none;
}

@media (hover: hover) {
  .cell:hover { background: var(--peer); }
  .cell.sel:hover { background: var(--sel); }
}

.cell .glyph {
  width: 78%;
  height: 78%;
  pointer-events: none;
  position: relative;
  z-index: 1;
}

/*
 * Every filled square carries a physical tile, which is most of what makes the
 * board feel cozy rather than like a spreadsheet with pictures in it.
 *
 * Givens are pressed *into* the board — flat, faintly recessed, part of the
 * printed grid. The player's own answers are laid *on top* of it: a lit face,
 * a bright top edge and a small drop shadow. So the difference between "this
 * was here when I started" and "I put this here" is something you feel rather
 * than something you have to work out.
 */
/*
 * An empty square is a slot waiting for a tile, not a hole in the page.
 *
 * Before this only *filled* squares had any physicality, so two thirds of a
 * fresh board was flat nothing and the tray metaphor collapsed the moment you
 * looked at a real puzzle. A shallow dish in every empty square is what makes
 * the board read as one object with somewhere to put things.
 *
 * The fill has to stay translucent: `.sel`, `.peer` and `.same` paint the cell
 * background, which sits *below* this pseudo-element, so an opaque well would
 * hide the row/column/box highlighting on exactly the squares still in play.
 */
.cell:not(.given):not(.guess)::before {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 10px;
  background: var(--well);
  /* Dished, and the exact inverse of the tile above: shadow gathers under the
     top lip and light catches the bottom one. That one flip is what separates
     "a hole to put something in" from "a thing sitting there", and it has to
     survive next to a placed tile without any colour difference to lean on. */
  box-shadow:
    inset 0 2px 3px -1.5px var(--shadow),
    inset 0 -1px 0 var(--tile-hi);
  z-index: 0;
}

/*
 * A given wears the collection's material too.
 *
 * Without this the material was nearly invisible for the first half of a
 * puzzle: a fresh board is almost all givens, so the surface you paid for only
 * showed up on squares you had already solved.
 *
 * It goes on as an extra background layer rather than as a second
 * pseudo-element, because `::after` on a cell is already the selection and
 * hint ring — and those rules come later in this file, so a `.cell.given::after`
 * would lose to them and the material would blink off the instant you tapped a
 * given. The given keeps its recessed chip and inset shadow underneath, so it
 * still reads as pressed into the tray rather than sitting on it.
 */
.cell.given::before {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 10px;
  background: var(--tile-fx), var(--given-chip);
  box-shadow: inset 0 1.5px 3px -1px var(--shadow);
  z-index: 0;
}

.cell.guess::before {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 10px;
  background: var(--tile-fx), var(--tile-face);
  box-shadow:
    var(--tile-edge),
    0 1px 0 var(--shadow-lip),
    0 3px 6px -2px var(--shadow);
  z-index: 0;
}

/* Lift the artwork off its tile face by a hair. `--glyph-fx` is the tile
   collection's own contribution and defaults to a no-op, so a set that wants
   its artwork to glow or to cast a harder shadow says so once. */
.cell.given .glyph { filter: drop-shadow(0 .5px 0 var(--shadow-lip)) var(--glyph-fx); }
.cell.guess .glyph { filter: drop-shadow(0 1px 1.5px var(--shadow-lip)) var(--glyph-fx); }

/* A placed tile drops in with a small overshoot — the tactile bit. */
.cell.pop .glyph { animation: pop .28s var(--ease); }
@keyframes pop {
  0%   { transform: scale(.4); opacity: 0; }
  70%  { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); }
}

.cell.bad .glyph { animation: shake .32s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2.5px); }
  75% { transform: translateX(2.5px); }
}

/* Stage one of a hint: this square can be worked out. It says nothing about
   *what* goes here, so it is a ring that breathes rather than a label. */
.cell.nudge::after {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 9px;
  box-shadow: 0 0 0 2.5px var(--sel-ink);
  z-index: 2;
  pointer-events: none;
  animation: nudge 1.5s var(--ease) 3;
}
@keyframes nudge {
  0%, 100% { opacity: 1; transform: scale(1); }
  40% { opacity: .45; transform: scale(1.06); }
}

/* The win: every tile lifts in a ring spreading out from the last square
   filled, so the board gets a beat of its own before the dialog arrives. */
.cell.finale .glyph { animation: finale .68s var(--ease); }
@keyframes finale {
  0%, 100% { transform: translateY(0) scale(1); }
  38% { transform: translateY(-8px) scale(1.16); }
}

/* A finished row / column / box gets a soft sweep of light.
   This animates the cell itself rather than ::before, because ::before now
   carries the tile face — sweeping it would blank the tile mid-animation. */
.cell.cleared { animation: sweep .66s ease; }
.cell.cleared .glyph { animation: lift .66s var(--ease); }
@keyframes sweep {
  0%, 100% { background-color: transparent; }
  35% { background-color: var(--sel); }
}
@keyframes lift {
  0%, 100% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-2.5px) scale(1.07); }
}

/* Pencil marks. Rows are stated for the same reason the board's are: nine marks
   in three implicit auto rows bunch against the top of the cell wherever those
   tracks are not stretched. */
.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 94%;
  height: 94%;
  place-items: center;
  pointer-events: none;
  position: relative;
  z-index: 1;
}
.notes .glyph { width: 80%; height: 80%; opacity: .85; }
/* Candidates the game worked out sit fainter than marks you made yourself —
   but still legibly so. At .32 they were a smudge rather than information. */
.notes.auto .glyph { opacity: .5; }

/* SVG keeps its authored palette in forced colors, even when the tray becomes
   black. Fading those colors makes the small marks disappear. Use the user's
   foreground/background for the artwork and keep both kinds of mark solid. */
@media (forced-colors: active) {
  .notes .glyph,
  .notes.auto .glyph {
    color: CanvasText !important;
    --ink: CanvasText !important;
    --lite: Canvas !important;
    --pale: Canvas !important;
    opacity: 1;
    filter: none;
  }
}

.board-veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  border-radius: var(--r-xl);
  background: color-mix(in srgb, var(--board) 90%, transparent);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  z-index: 3;
}
.board-veil[hidden] { display: none; }

/* Paused covers the board rather than merely stopping the clock. A frozen timer
   over a readable grid is a free thinking seat, and every best time would be
   worth nothing. Fully opaque, and the whole cover is the resume button. */
.board-veil.paused {
  background: var(--board);
  cursor: pointer;
  font-size: 15px;
}
.board-veil.paused .spinner { display: none; }

/* The pad and tools go quiet with it. They already refuse to do anything while
   paused; looking live and doing nothing is how a game reads as broken.
   Controls dim the way `.tool:disabled` already does — the pad hint is prose,
   so it hides outright rather than being faded, because fading text with
   opacity is exactly the thing the contrast rule above forbids. */
.shell.paused .pad,
.shell.paused .tools { opacity: .4; pointer-events: none; }
.shell.paused .pad-hint { visibility: hidden; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--sel-ink);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ side -- */

.side { display: flex; flex-direction: column; gap: 13px; }

/*
 * Five over four, not nine across.
 *
 * Nine in a row put the game's primary control at 36px on a 390px phone — under
 * every touch-target minimum there is (44pt Apple, 48dp Android, 44px WCAG), and
 * the failure mode is the horizontal one: you hit the tile next to the one you
 * wanted. Nine across cannot be made wider on a phone (9x44 plus gaps needs
 * ~452px), so the row splits. Ten columns with each tile spanning two is what
 * centres the second row of four under the first row of five.
 */
.pad { display: grid; grid-template-columns: repeat(10, 1fr); gap: 8px; }

.pad-btn {
  position: relative;
  grid-column: span 2;
  /* Height follows width until the tile would drop under the touch minimum,
     which is what stops a wide viewport from producing letterbox-flat tiles
     and a narrow one from producing tiles too small to hit. */
  aspect-ratio: 1.4;
  min-height: 54px;
  /*
   * The track decides the width. The ratio only decides the height.
   *
   * Without a definite width it decided both, and wrongly: an aspect ratio
   * transfers a clamped height back into a width, so `min-height: 54` became a
   * 76px minimum width the grid track had never agreed to. The five tiles ran
   * past the pad's right edge on every phone measured, and at 320px they
   * overlapped each other by 14px — 70px buttons laid into 56px slots — so the
   * tile you pressed was partly covered by the tile after it. That is exactly
   * the horizontal mis-hit this row splits itself in two to avoid, reintroduced
   * by the rule that was meant to keep the tiles big enough to hit.
   */
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--tile-fx), var(--tile-face);
  box-shadow:
    var(--tile-edge),
    var(--lip) var(--shadow-lip),
    0 5px 12px -8px var(--shadow);
  display: grid;
  place-items: center;
  transition: transform .15s var(--ease), opacity .2s, background-color .16s, box-shadow .15s;
}
/* Sized from the button's height, not from four insets.
   Percentage width alone collapses to the SVG's intrinsic 24px (the button's
   inner grid track is content-sized), which is why these tiles once came out
   smaller than the identical artwork on the board. But insetting all four
   sides breaks the other way the moment the button is not square: the SVG
   keeps its 1:1 ratio, takes the wider axis, and spills out of the tile. Pin
   it to the short axis and let the width follow. */
.pad-btn .glyph {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  height: 70%;
  width: auto;
  aspect-ratio: 1;
  pointer-events: none;
  /* The pad is the same tile as the board, so it wears the same material. */
  filter: drop-shadow(0 1px 1.5px var(--shadow-lip)) var(--glyph-fx);
}
/* The second row holds four, offset by one column so it sits centred. */
.pad-btn:nth-child(6) { grid-column: 2 / span 2; }

.pad-btn:active { transform: translateY(2px); box-shadow: none; }

/* A picked-up tile lifts off the row and keeps a ring, so it is obvious that
   tapping it again puts it down. Being stuck holding a tile with no way out
   was the worst bit of the first version. */
.pad-btn.armed {
  background: var(--sel);
  box-shadow: 0 0 0 2.5px var(--sel-ink), 0 12px 20px -10px var(--shadow);
  transform: translateY(-5px);
}
.pad-btn.armed:active { transform: translateY(-3px); }

/* All nine of a tile placed: it sinks flush into the tray rather than fading
   out. A used-up tile is not a disabled button, it is a spent one — and the
   dish it leaves behind matches the empty squares on the board. */
.pad-btn.done {
  background: var(--well);
  box-shadow:
    inset 0 2px 4px -1px var(--shadow),
    inset 0 -1px 0 var(--tile-hi);
  transform: none;
}
.pad-btn.done .glyph { opacity: .3; }
.pad-btn.done:active { transform: none; }

.pad-count {
  position: absolute;
  bottom: 3px;
  right: 7px;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.pad-btn.armed .pad-count { color: var(--sel-ink); }
.pad-btn.done .pad-count { opacity: 0; }

@media (forced-colors: active) {
  /* Forced colors removes shadow rings. Exhausted tiles can still be held,
     and their flush position cannot carry the selection by itself. */
  .pad-btn.armed { outline: 3px solid Highlight; outline-offset: -3px; }
}

/* Instructions sit over the room or mat, whose painted surfaces can be darker
   than the theme background. Keep the full text tone in every input state. */
.pad-hint {
  margin: -2px 0 0;
  text-align: center;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  min-height: 17px;
  transition: color .2s;
}

/* Six tools fit the full control set without growing the row. At the narrowest
   supported width the tighter gap below keeps every button over 44px wide. */
.tools { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; }

.tool {
  border: 0;
  border-radius: var(--r-md);
  background: var(--chip);
  box-shadow: var(--lip) var(--shadow-lip), 0 5px 12px -8px var(--shadow);
  padding: 11px 4px 10px;
  display: grid;
  justify-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  position: relative;
  transition: transform .13s var(--ease), color .15s;
}
.tool svg { width: 21px; height: 21px; }
.tool:hover { color: var(--text); }
.tool:active { transform: translateY(2px); box-shadow: none; }
.tool:disabled { opacity: .38; cursor: default; transform: none; }
/* The accent is for rings and fills; small text over --sel needs --text. */
.tool[aria-pressed="true"] { background: var(--sel); color: var(--text); }
/* No opacity, for the reason the whole file gives: `--muted` is picked to clear
   4.5:1 and fading it undoes that. At .6 this badge measured 2.4:1 — on 8.5px
   text, which is the size that can least afford it — and it is the only thing
   on the button that says whether notes mode is currently on. */
.tool em {
  position: absolute;
  top: 6px;
  right: 9px;
  font-style: normal;
  font-size: 8.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ----------------------------------------------------------------- about -- */

.noscript {
  background: var(--chip);
  border-radius: var(--r-md);
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
}

/* ------------------------------------------------------- the about page -- */

.page-head { display: grid; gap: 14px; padding-top: 4px; }
.page-head h1 { font-size: 25px; }
.back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  justify-self: start;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
  background: var(--chip);
  box-shadow: var(--lip) var(--shadow-lip);
  border-radius: 999px;
  padding: 8px 15px 8px 11px;
  transition: transform .13s var(--ease), color .15s;
}
.back svg { width: 17px; height: 17px; }
.back:hover { color: var(--text); }
.back:active { transform: translateY(2px); box-shadow: none; }

.prose { color: var(--muted); max-width: 64ch; }
.prose h2 { font-size: 17px; color: var(--text); margin: 30px 0 8px; }
.prose h2:first-child { margin-top: 4px; }
.prose h3 { font-size: 14.5px; color: var(--text); margin: 22px 0 6px; font-weight: 800; }
.prose p { margin: 0 0 11px; font-size: 14.5px; line-height: 1.72; }
.prose ul { margin: 0 0 12px; padding-left: 20px; }
.prose li { font-size: 14.5px; line-height: 1.7; margin-bottom: 5px; }
.prose strong { color: var(--text); font-weight: 700; }
.prose a { color: var(--sel-ink); text-decoration: none; border-bottom: 1px solid var(--sel); }

/* A worked example beside each technique. The prose is complete without these —
   they are drawn by a few lines of inline script and are illustration only, so
   the page still reads with scripting off (and to a crawler). */
.mini {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(280px, 100%);
  aspect-ratio: 1;
  margin: 14px 0 18px;
  background: var(--board);
  border-radius: var(--r-md);
  padding: 7px;
  box-shadow: inset 0 0 0 1px var(--line), 0 8px 20px -12px var(--shadow);
}
.mini i {
  display: grid;
  place-items: center;
  font-style: normal;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.mini i:nth-child(3n) { border-right: 2px solid var(--line-strong); }
.mini i:nth-child(9n) { border-right: 0; }
.mini i.r3, .mini i.r6 { border-bottom: 2px solid var(--line-strong); }
.mini i.r9 { border-bottom: 0; }
.mini i.hl { background: var(--peer); }
.mini i.key { background: var(--sel); color: var(--sel-ink); border-radius: 4px; }
.mini i.dim { color: var(--muted); opacity: .55; }
.mini-cap { font-size: 12.5px; margin: -8px 0 20px; color: var(--muted); }

/* Every tile set, shown at a size where the artwork can actually be judged. */
.set-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 12px; margin: 18px 0 8px; }
.set-card { background: var(--chip); border-radius: var(--r-md); padding: 14px 12px; box-shadow: var(--lip) var(--shadow-lip); }
.set-card .row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 9px; }
.set-card .row svg { width: 26px; height: 26px; }
.set-card b { display: block; font-size: 13.5px; color: var(--text); }
.set-card small { font-size: 11.5px; color: var(--muted); }

.page-nav { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 26px 0 0; font-size: 13px; }
.page-nav a { color: var(--sel-ink); text-decoration: none; border-bottom: 1px solid var(--sel); }

.cta {
  display: inline-block;
  margin: 6px 0 4px;
  background: var(--sel);
  color: var(--sel-ink);
  border-radius: var(--r-md);
  padding: 13px 22px;
  font-weight: 800;
  font-size: 14.5px;
  text-decoration: none;
  box-shadow: var(--lip) var(--shadow-lip);
}
.cta:active { transform: translateY(2px); box-shadow: none; }

.foot {
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  padding: 4px 0 2px;
}
.foot a + a { margin-left: 2px; }
.foot a { text-decoration: none; border-bottom: 1px solid var(--line); }

/* --------------------------------------------------------------- sheets -- */

.sheet {
  border: 0;
  padding: 0;
  width: min(440px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  border-radius: var(--r-xl);
  background: var(--board);
  color: var(--text);
  box-shadow: 0 28px 70px -14px rgba(0, 0, 0, .38);
  overflow: auto;
}
.sheet::backdrop { background: rgba(38, 28, 22, .46); backdrop-filter: blur(4px); }
.sheet form { padding: 24px 24px 18px; }
.sheet h2 { font-size: 19px; }
.sheet-intro,
.journey-sheet-intro {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.group-label {
  margin: 22px 0 10px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
}

.sheet-foot { display: flex; gap: 10px; margin: 24px 0 0; padding: 0; }
.sheet-foot button {
  flex: 1;
  border: 0;
  border-radius: var(--r-md);
  padding: 13px;
  font-weight: 800;
  font-size: 14.5px;
  transition: transform .13s var(--ease);
}
.sheet-foot button:active { transform: translateY(2px); }
.ghost { background: var(--chip); color: var(--muted); box-shadow: var(--lip) var(--shadow-lip); }
.ghost.danger { color: var(--bad); flex: 0 0 34%; }
.primary { background: var(--sel); color: var(--text); box-shadow: var(--lip) var(--shadow-lip); }

/* The full journey map is a picker, not a dashboard. Chapters stay compact,
   every available level is a real button, and locked numbers retain full text
   contrast instead of being faded with opacity. */
.sheet.journey-sheet { width: min(560px, calc(100vw - 28px)); }
.journey-sheet-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 40px;
  align-items: center;
  gap: 12px;
  margin: -24px -4px 0;
  padding: 20px 4px 10px;
  background: linear-gradient(var(--board) 78%, color-mix(in srgb, var(--board) 0%, transparent));
}
.journey-sheet-head button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--chip);
  box-shadow: var(--lip) var(--shadow-lip);
}
.journey-sheet-head button:active { transform: translateY(2px); box-shadow: none; }
.journey-sheet-head svg { width: 18px; height: 18px; }
/* The full map uses the home tray's three states: tile, selected square, well. */
.chapter-list { display: grid; margin-top: 14px; }
.chapter-card { padding: 14px 0; }
.chapter-card + .chapter-card { border-top: 1px solid var(--line); }
.chapter-card-head { margin-bottom: 10px; }
.chapter-card-head h3 { margin: 0; font-size: 15px; font-weight: 800; }
.chapter-card-head span { display: block; margin-top: 1px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.chapter-nodes { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.journey-node {
  min-width: 0;
  aspect-ratio: 1;
  border: 0;
  border-radius: 9px;
  background: var(--well);
  color: var(--muted);
  box-shadow: inset 0 2px 3px var(--shadow), inset 0 -1px 0 var(--tile-hi);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: transform .13s var(--ease), box-shadow .13s, background-color .15s;
}
.journey-node:not(:disabled):active { transform: translateY(2px); box-shadow: none; }
.journey-node.done {
  background: var(--tile-face);
  color: var(--text);
  box-shadow: var(--tile-edge), var(--lip) var(--shadow-lip);
}
.journey-node.current { background: var(--sel); box-shadow: 0 0 0 2px var(--sel-ink); color: var(--text); }
.journey-node:disabled { cursor: default; color: color-mix(in srgb, var(--muted) 62%, transparent); }
.endless-note {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: var(--r-md);
  color: var(--muted);
  background: var(--cell-alt);
  font-size: 12px;
}
.endless-note strong,
.endless-note span { display: block; }
.endless-note strong { color: var(--text); font-size: 14px; }
.endless-note span { margin-top: 2px; }

/* Daily card */
.daily-card {
  width: 100%;
  border: 0;
  border-radius: var(--r-lg);
  background: var(--cell-alt);
  box-shadow: var(--lip) var(--shadow-lip);
  padding: 15px 16px;
  display: flex;
  align-items: center;
  gap: 13px;
  text-align: left;
  margin-top: 16px;
  transition: transform .13s var(--ease);
}
.daily-card:active { transform: translateY(2px); box-shadow: none; }
.daily-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 13px;
  background: var(--sel);
  color: var(--sel-ink);
  flex: none;
}
.daily-mark svg { width: 22px; height: 22px; }
.daily-text { flex: 1; min-width: 0; }
.daily-text strong { display: block; font-size: 15.5px; }
.daily-text small { color: var(--muted); font-size: 12px; }
.daily-badge {
  font-size: 11px;
  font-weight: 800;
  color: var(--sel-ink);
  background: var(--sel);
  padding: 5px 10px;
  border-radius: 999px;
  flex: none;
}
.daily-badge:empty { display: none; }

/* Difficulty list */
.level-list { display: grid; gap: 8px; }
.level-btn {
  border: 0;
  width: 100%;
  border-radius: var(--r-md);
  background: var(--chip);
  box-shadow: var(--lip) var(--shadow-lip);
  padding: 13px 16px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-align: left;
  transition: transform .13s var(--ease);
}
.level-btn:active { transform: translateY(2px); box-shadow: none; }
.level-btn strong { font-size: 15px; }
.level-btn small { color: var(--muted); font-size: 12px; flex: 1; }
.level-dots { display: flex; gap: 3.5px; flex: none; align-self: center; }
.level-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line-strong); opacity: .25; }
.level-dots i.on { opacity: 1; background: var(--sel-ink); }

/* Settings tabs */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 18px 0 4px;
  padding: 4px;
  border-radius: var(--r-md);
  background: var(--cell-alt);
}
.tab {
  border: 0;
  border-radius: 12px;
  background: none;
  padding: 9px 4px;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  transition: color .15s, background-color .15s;
}
.tab.on {
  background: var(--board);
  color: var(--text);
  box-shadow: var(--lip) var(--shadow-lip), 0 4px 10px -8px var(--shadow);
}
.tab-panel[hidden] { display: none; }

/* Volume */
/* A separate label row also survives text-only zoom, which does not trigger
   narrow-viewport breakpoints. Keep the range and its changing percentage on
   the same row so adjusting a value cannot rewrap the control mid-gesture. */
.vol-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 3px 12px;
  margin: 20px 0 4px;
  padding: 0 2px;
}
.vol-row + .vol-row { margin-top: 8px; }
.vol-label { font-size: 14px; font-weight: 700; grid-column: 1 / -1; }
.vol-value {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: right;
  flex: none;
}
.vol {
  width: 100%;
  min-width: 0;
  height: 26px;
  -webkit-appearance: none;
  appearance: none;
  background: none;
}
.vol::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--sel-ink) 0 var(--fill, 85%), var(--line) var(--fill, 85%) 100%);
  box-shadow: inset 0 1px 2px -1px var(--shadow);
}
.vol::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--sel-ink) 0 var(--fill, 85%), var(--line) var(--fill, 85%) 100%);
}
/* The thumb carries the same lit-tile treatment as everything else you press. */
.vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -7px;
  border-radius: 50%;
  background: linear-gradient(157deg, var(--tile-hi) 10%, var(--tile-lo) 100%);
  box-shadow: 0 0 0 2.5px var(--sel-ink), 0 3px 6px -2px var(--shadow);
}
.vol::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(157deg, var(--tile-hi) 10%, var(--tile-lo) 100%);
  box-shadow: 0 0 0 2.5px var(--sel-ink), 0 3px 6px -2px var(--shadow);
}
/* Sound off: the slider is inert and says so with the muted token rather than
   by fading, which is what the contrast rule requires of text. */
.vol-row.off .vol-label,
.vol-row.off .vol-value { color: var(--muted); }
.vol-row.off .vol { filter: grayscale(1); opacity: .5; cursor: default; }

.music-now {
  margin: 12px 2px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.music-notice {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--cell-alt);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.music-play {
  display: block;
  margin-top: 7px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 900;
  text-align: left;
}

/*
 * Option grids
 *
 * The set list counts its own columns rather than always asking for three.
 * A card cannot be narrower than its swatch — three 30px tiles and their gaps
 * plus the padding is 112px — and `1fr` is `minmax(auto, 1fr)`, so three of
 * them in the 299px a 375px phone leaves inside the sheet did not shrink, they
 * overflowed: the third column of every row was sliced off at the sheet edge,
 * hiding a third of the collections on the one screen whose job is to show
 * what a collection looks like. The track floor is the card's real minimum, so
 * the count drops to two before anything is ever clipped.
 */
.set-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 9px; }
.set-btn {
  position: relative;
  min-width: 0;
  border: 0;
  border-radius: var(--r-md);
  background: var(--chip);
  box-shadow: var(--lip) var(--shadow-lip);
  padding: 12px 6px 10px;
  display: grid;
  justify-items: center;
  gap: 7px;
  transition: transform .13s var(--ease);
}
/* Locked sets keep their art visible — the artwork is the sales pitch — just
   dimmed enough that the padlock reads as the reason they will not select. */
.set-btn.locked .set-preview, .set-btn.locked b { opacity: .6; }
.set-btn.locked small { opacity: .75; }
.set-btn .lock {
  position: absolute;
  top: 6px;
  right: 7px;
  width: 13px;
  height: 13px;
  color: var(--muted);
}
.premium-copy { margin: 0 2px 4px; font-size: 13.5px; line-height: 1.55; color: var(--muted); }
.set-btn:active { transform: translateY(2px); }
.set-btn.on { background: var(--sel); box-shadow: 0 0 0 2.5px var(--sel-ink); }
/* The swatch is a real tile, not a loose glyph on the chip.
   The artwork is the sales pitch for a locked set, and half of what a
   collection now is lives in the surface under the artwork — showing the glyph
   alone sells only half of it. Big enough that a facet band or a grain can
   actually be seen: at the old 18px bare glyph there was nowhere to show one. */
.set-preview { display: flex; gap: 5px; }
.set-tile {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--tile-fx), var(--tile-face);
  box-shadow: var(--tile-edge), 0 1px 2px -1px var(--shadow);
  display: grid;
  place-items: center;
}
.set-preview .glyph {
  width: 20px;
  height: 20px;
  filter: drop-shadow(0 .5px 1px var(--shadow-lip)) var(--glyph-fx);
}
.set-btn b { font-size: 12.5px; font-weight: 800; }
.set-btn small { font-size: 10px; color: var(--muted); }
/* The selected fill needs the text token; the accent and muted tones are too pale. */
.set-btn.on small { color: var(--text); }

.theme-list { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-btn {
  width: 48px; height: 48px;
  border: 0;
  border-radius: 15px;
  box-shadow: var(--lip) var(--shadow-lip);
  position: relative;
  transition: transform .13s var(--ease);
}
.theme-btn:active { transform: translateY(2px); }
.theme-btn.on { box-shadow: 0 0 0 2.5px var(--sel-ink); }
.theme-btn span { position: absolute; inset: 27%; border-radius: 7px; }

/* Switches */
.switch-list { display: grid; }
.switch-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}
.switch-row:last-child { border-bottom: 0; }
.switch-row .label { flex: 1; }
.switch-row b { display: block; font-size: 14px; font-weight: 700; }
.switch-row small { color: var(--muted); font-size: 11.5px; line-height: 1.4; }

.switch {
  flex: none;
  width: 46px; height: 27px;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background-color .2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: var(--board);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .22s var(--ease);
}
.switch[aria-checked="true"] { background: var(--sel-ink); }
.switch[aria-checked="true"]::after { transform: translateX(19px); }

/* ----------------------------------------------------------------- stats -- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 16px; }
.stat { background: var(--chip); border-radius: var(--r-md); padding: 13px 6px; text-align: center; }
.stat b { display: block; font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat small { font-size: 10.5px; color: var(--muted); font-weight: 600; }

.stat-table { display: grid; }
.stat-row {
  display: grid;
  grid-template-columns: 1fr 46px 46px 58px;
  gap: 10px;
  align-items: baseline;
  padding: 11px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.stat-row:last-child { border-bottom: 0; }
.stat-row.head {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  padding-bottom: 7px;
}
.stat-row b { font-weight: 700; }
.stat-row span { font-variant-numeric: tabular-nums; text-align: right; }
.stat-row .dim { color: var(--muted); opacity: .6; }

.stat-note { margin: 18px 0 0; font-size: 12px; line-height: 1.55; color: var(--muted); }

/* ----------------------------------------------------------- daily archive -- */

.archive-head { display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; gap: 8px; }
.archive-head h2 { text-align: center; font-size: 17px; }
.arch-nav {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 0; border-radius: 12px;
  background: var(--chip);
  color: var(--muted);
  box-shadow: var(--lip) var(--shadow-lip);
  transition: transform .13s var(--ease), color .15s;
}
.arch-nav svg { width: 18px; height: 18px; }
.arch-nav:hover:not(:disabled) { color: var(--text); }
.arch-nav:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.arch-nav:disabled { opacity: .3; cursor: default; }

.cal-dow {
  display: grid; grid-template-columns: repeat(7, 1fr);
  margin: 16px 0 6px;
  font-size: 10.5px; font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; text-align: center; color: var(--muted);
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }

.cal-day {
  position: relative;
  aspect-ratio: 1;
  min-height: 42px;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--chip);
  box-shadow: var(--lip) var(--shadow-lip);
  font-size: 13.5px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  display: grid; place-items: center;
  transition: transform .13s var(--ease);
}
.cal-day { text-decoration: none; }
.cal-day:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.cal-day.blank { background: none; box-shadow: none; pointer-events: none; }
/* Days before the game existed, and days that have not happened yet. */
.cal-day:disabled { opacity: .28; box-shadow: none; cursor: default; }

/* A solved day is a tile, with its date tucked into the corner so the month is
   still navigable. Unaided days keep the accent background; hinted ones sit on
   the plain chip, which is the whole of the distinction. */
.cal-day.done { overflow: hidden; }
.cal-day.done .glyph { width: 74%; height: 74%; }
.cal-day.done i {
  position: absolute;
  top: 2px; left: 5px;
  font-style: normal;
  font-size: 9px;
  font-weight: 800;
  color: var(--muted);
}
.cal-day.done.unaided { background: var(--sel); }
.cal-day.done.unaided i { color: var(--text); }
.cal-day.today { box-shadow: 0 0 0 2.5px var(--sel-ink); }

/* The standalone calendar uses date links rather than picture tiles. */
.cal-solved {
  position: absolute;
  right: 4px; bottom: 4px;
  font-size: 12px; line-height: 1;
}

@media (forced-colors: active) {
  /* Completed levels and unaided days lose their background distinction;
     current levels and today's date lose their shadow ring. Keep independent
     solid and dashed markers, including on an unaided daily solved today. */
  .journey-node.done,
  .cal-day.done.unaided { border: 2px solid ButtonText; }
  .journey-node.current,
  .cal-day.today { outline: 2px dashed Highlight; outline-offset: -4px; }
}

/* Win */
.share-btn {
  width: 100%;
  margin-top: 18px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--chip);
  color: var(--muted);
  box-shadow: var(--lip) var(--shadow-lip);
  padding: 13px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  font-size: 14px; font-weight: 800;
  transition: transform .13s var(--ease), color .15s, background-color .2s;
}
.share-btn svg { width: 18px; height: 18px; }
.share-btn:hover { color: var(--text); }
.share-btn:active { transform: translateY(2px); box-shadow: none; }
.share-btn.done { background: var(--sel); color: var(--sel-ink); }

.win .win-art { display: flex; justify-content: center; gap: 8px; margin-bottom: 16px; }
.win .win-art .glyph { width: 36px; height: 36px; animation: rise .5s var(--ease) backwards; }
@keyframes rise { from { transform: translateY(16px) scale(.4); opacity: 0; } }
.win h2 { text-align: center; font-size: 23px; }
.win-line { text-align: center; color: var(--muted); font-size: 13.5px; margin: 8px 0 0; }

/* What a hint costs: this badge and the personal best. Nothing is ever withheld
   and nothing scolds — an aided solve just states itself plainly. */
.win-badge {
  display: block;
  width: fit-content;
  margin: 12px auto 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .02em;
}
.win-badge.clean { background: var(--sel); color: var(--text); }

/* ------------------------------------------------------------------ wide -- */

/*
 * Once there is room for nine tiles at a proper size, put them back in one row.
 *
 * The split into five over four exists only because nine across cannot reach
 * 44px on a phone. From about 520px up it can — nine tiles plus eight gaps need
 * roughly 450px — so the row reassembles and the pad stops eating the ~110px of
 * height that pushed tablet portrait into scrolling.
 */
@media (min-width: 520px) {
  .pad { grid-template-columns: repeat(9, 1fr); }
  .pad-btn { grid-column: auto; aspect-ratio: 1; min-height: 0; }
  .pad-btn:nth-child(6) { grid-column: auto; }
}

@media (min-width: 760px) {
  .shell { max-width: 588px; gap: 24px; }
  main { gap: 22px; }
  .title-block h1 { font-size: 25px; }
  .pad { gap: 10px; }
  .tools { gap: 11px; }
  .tool { padding: 13px 6px 12px; font-size: 12.5px; }
  .tool svg { width: 22px; height: 22px; }
}

@media (max-width: 420px) {
  .chapter-nodes { grid-template-columns: repeat(5, 1fr); gap: 8px; }
  .journey-node { max-width: 42px; justify-self: center; width: 100%; }
}

/* --------------------------------------------------------------- narrow -- */

/*
 * Phones are constrained by height, not by width.
 *
 * The stacked layout only ever asked how *wide* the viewport was, so the board
 * took the full width and everything under it went wherever it landed. On a
 * 375x667 phone that put every tool below the board
 * completely below the fold, with 124px of document hanging off the bottom and
 * nothing on screen to say they existed. Counting the browser's own chrome, the
 * same was true of almost every phone in portrait: the game shipped with its
 * controls hidden.
 *
 * So the board is capped by what is left once everything that has to stay
 * reachable has taken its share, exactly as the wide layout has always sized
 * itself off the viewport height. The reserve below is measured against the
 * trimmed values in the block after it, not padded — every pixel guessed high
 * here is board given away on every phone.
 *
 * Two deliberate exclusions. The footer sits outside the reserve, because a row
 * of links just under the fold is ordinary and a Hint button under the fold is
 * not. And the cap has a floor: under about a 600px viewport the arithmetic
 * wants a board too small to read a mushroom on, and a short scroll is the
 * better trade than an unplayable board.
 *
 * `svh`, not `dvh`. The dynamic unit tracks the address bar as it hides and
 * shows, which would resize the board while you scroll; the small unit is the
 * worst case and stays put.
 */
@media (max-width: 899px) {
  :root {
    /* topbar 50 + pad 106 + hint 17 + tools 62 + shell gaps 20 + main gap 18
       + side gaps 26 + body padding 34. */
    --stack-reserve: 333px;
  }

  .board-wrap {
    width: min(100%, max(240px, calc(100vh - var(--stack-reserve))));
    width: min(100%, max(240px, calc(100svh - var(--stack-reserve))));
    margin-inline: auto;
  }
}

/*
 * Short phones buy the board back out of the chrome around it.
 *
 * Nothing here is removed, only tightened: the same header and the same tools.
 * Trimming the gaps and the padding is worth ~46px
 * of board on a 667px screen, which is the difference between a 271px board and
 * a 317px one — and 317px is where a picture tile is still a picture rather
 * than a coloured square.
 */
@media (max-width: 899px) and (max-height: 800px) {
  :root { --stack-reserve: 297px; }

  .shell { gap: 13px; }
  main { gap: 13px; }
  .side { gap: 10px; }
  /* Still clear of the 44px touch minimum, which is the floor these answer to
     rather than the height that happens to be left over. */
  .pad-btn { min-height: 48px; }
  .pad-hint { min-height: 15px; }
  .tool { padding: 8px 4px 7px; gap: 4px; }
}

/*
 * Below about 570px of viewport the board is already sitting on its floor, so
 * trimming here does not buy board — it buys reach. Every pixel taken out of
 * the chrome on a 320x568 phone is a pixel the tools row moves up, which is the
 * difference between the controls on screen and controls you have to know
 * are there. Nothing shrinks past a touch minimum to get it.
 */
@media (max-width: 899px) and (max-height: 640px) {
  :root { --stack-reserve: 268px; }

  .shell { gap: 10px; }
  main { gap: 10px; }
  .side { gap: 8px; }
  .pad-btn { min-height: 46px; }
  .tool { padding: 6px 4px 5px; }
  .tool svg { width: 19px; height: 19px; }
}

/* ------------------------------------------------------------ landscape -- */

/*
 * Landscape phones, and any window too short to stack anything.
 *
 * Every breakpoint above this one was width-only, so a 844x390 phone on its
 * side matched the tablet rules and got a 588px board in a 390px-tall window:
 * three rows of sudoku on screen and 616px of scrolling to reach a tile to put
 * in them. It was the worst layout in the game and the only one nothing had
 * ever been measured against.
 *
 * Height is the whole constraint here, so this borrows the wide layout's answer
 * — board on the left, 3x3 pad beside it — and sizes the board off the viewport
 * height. It does not borrow the mat: that is a surface with generous bleed on
 * all four sides, and a 390px-tall window has no margin to spend on it.
 */
@media (min-width: 600px) and (max-height: 599px) {
  :root {
    /* Everything stacked above and below the two columns: topbar 50 + footer
       23 + two gaps 24 + body padding 34. */
    --short-chrome: 131px;
    /* And everything stacked under the pad inside the side column: the hint,
       the tools row and the two gaps between them. It is the *side* column, not
       the board, that decides the page height on a short screen — a 3x3 pad is
       as tall as it is wide, so its width has to come out of the height left
       over rather than out of whatever the row has spare. */
    --side-stack: 90px;
    --pane-h: calc(100vh - var(--short-chrome));
    --pane-h: calc(100svh - var(--short-chrome));
  }

  main { flex-direction: row; align-items: center; gap: 22px; }
  /* Sized to exactly board + gap + side, so the topbar spans the two columns
     under it instead of stretching the wordmark across 800px of empty desk. */
  .shell { gap: 12px; max-width: calc(clamp(200px, var(--pane-h), 52vw) + 362px); }

  .board-col { flex: 0 0 auto; }
  .board-wrap { width: clamp(200px, var(--pane-h), 52vw); }

  .side { flex: 1 1 auto; justify-content: center; gap: 10px; max-width: 340px; }

  /* The height budget binds the *pad*, not the column. A 3x3 pad is as tall as
     it is wide, so its width has to come out of the height that is left — but
     applying that to the whole column squeezed the tools under it to 33px
     each and their labels ran outside their own chips, on a viewport with 300px
     of unused width sitting next to them. The pad takes what it can be, centred,
     and the tools take the column. */
  .pad {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    /* The explicit width is load-bearing next to the auto margins: an auto
       cross-axis margin switches a flex item out of `align-items: stretch`, so
       max-width alone left the grid shrink-to-fit at 12px a column. */
    width: 100%;
    max-width: clamp(150px, calc(var(--pane-h) - var(--side-stack)), 340px);
    margin-inline: auto;
  }
  .pad-btn { grid-column: auto; aspect-ratio: 1; min-height: 0; }
  .pad-btn:nth-child(6) { grid-column: auto; }
  .tool { padding: 7px 4px 6px; gap: 3px; }
  .pad-hint { min-height: 15px; }
}

/*
 * A phone actually on its side has no room for page furniture.
 *
 * Above this the daily strip and the footer links are worth their 64px and the
 * board simply gets less. At 390px of viewport they are the difference between
 * a 218px board and a 282px one, on the layout that already has the least room
 * of any in the game. Both are one tap away: the daily leads the New puzzle
 * sheet, and the four footer links are the same four every page carries.
 */
@media (min-width: 600px) and (max-height: 520px) {
  :root { --short-chrome: 108px; }
  .daily-strip, .foot { display: none; }
  .shell.home-mode .daily-strip { display: flex; }
}

/*
 * Wide screens: board beside the pad, sized off the viewport *height*.
 *
 * The first attempt at two columns was dropped for a good reason — it squeezed
 * the pad into a narrow rail and the tiles you aim at came out smaller than the
 * tiles on the board, which is backwards. The fix is not to avoid two columns,
 * it is to stop treating the pad as leftover space: nine tiles arranged 3x3 in
 * a 340px column are ~105px each, comfortably larger than a board cell at this
 * size, and the board grows to fill the height instead of being pinned to 588px.
 *
 * The shell is sized to exactly board + gap + side so the topbar spans the same
 * width as the two columns under it rather than floating over a wider box. The
 * height term is what keeps a 1440x900 laptop from scrolling, which the old
 * fixed 588px column did (931px of document in a 900px window).
 */
@media (min-width: 900px) and (min-height: 600px) {
  :root {
    /* Second declaration wins where dvh is understood, first is the fallback.
       The reserve is everything that is not the board: topbar (50) + footer
       (23) + two shell gaps (max 84) + body padding (34), plus clearance for
       the mat. It is measured because every guessed pixel is board size lost. */
    --board-w: min(calc(100vh - 220px), 56vw, 840px);
    --board-w: min(calc(100dvh - 220px), 56vw, 840px);
    /* The side column, not the board, is what sets the page height on a short
       screen: a 340px column makes a 3x3 pad ~105px a tile, and pad plus hint
       plus tools then stands taller than a board the viewport has squeezed.
       Letting it shrink with the viewport is what keeps a 960x640 window off
       the scrollbar, and it still clears the rule that a pad tile beats a board
       cell (268px column = ~81px a tile against a ~38px cell). */
    --side-w: clamp(268px, 38vh, 340px);
    --col-gap: 30px;
    --mat-pad: clamp(16px, 2.8vh, 30px);
  }

  /* The mat bleeds --mat-pad past main on every side, so the shell's own gap has
     to clear it or the topbar and footer sit on the mat's edge. */
  .shell {
    max-width: calc(var(--board-w) + var(--col-gap) + var(--side-w));
    gap: calc(var(--mat-pad) + 12px);
  }

  /*
   * The mat.
   *
   * On a wide screen the game was a small island in a large flat field — board
   * and pad floating separately with no relationship to each other or to the
   * page. A single warm surface under both makes them one object sitting on a
   * table, which is also what gives the background wash something to be behind.
   *
   * It is drawn as a bleeding pseudo-element rather than as padding on main, so
   * every existing width calculation (and the topbar's alignment with the two
   * columns) keeps working untouched.
   */
  main { position: relative; }
  main::before {
    content: "";
    position: absolute;
    inset: calc(var(--mat-pad) * -1) calc(var(--mat-pad) * -1.1);
    z-index: -1;
    background: var(--mat);
    border-radius: 44px;
    box-shadow:
      inset 0 1px 0 var(--tile-hi),
      0 2px 0 var(--shadow-lip),
      0 30px 60px -34px var(--shadow);
  }

  main { flex-direction: row; align-items: stretch; gap: var(--col-gap); }
  .board-col { flex: 0 0 auto; }
  .board { width: var(--board-w); }

  /* The pad block is shorter than the board, so centre it rather than letting
     it hang off the top with a pool of empty space underneath. */
  .side { flex: 0 0 var(--side-w); justify-content: center; gap: 16px; }
  .pad { grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .pad-btn { grid-column: auto; aspect-ratio: 1; min-height: 0; }
  .pad-btn:nth-child(6) { grid-column: auto; }
  .pad-hint { font-size: 13px; }
}

@media (max-width: 400px) {
  body { padding-left: 12px; padding-right: 12px; }
  .topbar { gap: 8px; }
  .timer { min-width: 38px; font-size: 13.5px; }
  /* "Gentle · Scanning" needs ~108px at 13px and the title block has ~110 once
     four controls have taken their share, so it was ellipsing the technique off
     the end on a 320px phone — the half of the line that says what the
     difficulty actually means. A point smaller and it fits whole. */
  .sub { font-size: 12px; }
  .pad { gap: 6px; }
  .pad-btn { min-height: 50px; }
  .tools { gap: 4px; }
  .tool span { font-size: 10.5px; }
  /* The cage insets itself by --board-pad, so the padding has to move as the
     token rather than as a one-off on .board, or the rules drift off the seams. */
  .board-wrap { --board-pad: 9px; --seam-w: 2.5px; }
  .board { border-radius: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    /* Duration changes only affect future transitions. Removing their
       properties also settles a transition running when the preference changes. */
    transition-property: none !important;
    transition-duration: .01ms !important;
  }
}

:focus-visible { outline: 2.5px solid var(--sel-ink); outline-offset: 2px; border-radius: 8px; }
.cell:focus-visible { outline-offset: -3px; }

/* Announced, never shown. The board reports its own state through aria-labels
   on the cells; this carries the things that have no element of their own —
   hint results, mode changes, the win. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
