/* Clear (default) — light, high contrast, blue actions. Red is reserved
   for errors (see docs/STYLE_GUIDE.md). */
:root {
  --header-fg: #F5F7FA; /* the dark app bar is never themed; its light ink is one token */
  --header-bg: #0F0F10; /* ...and so is its background */
  --header-line: #8A93A3;
  /* Skullfire pixel-art palette: constant across themes; chrome uses shared tokens. */
  --color-game-cupday-gold: #ffe08a;
  --color-game-cupday-blue: #95d9ff;
  --color-game-cupday-lilac: #e9b9ff;
  --color-game-cupday-white: #f5f1df;
  --color-game-cupday-orange: #ffae71;
  --color-game-cupday-mint: #9cf0c0;
  --color-game-cupday-turf: #264d3c;
  --color-game-cupday-track: #be9563;
  --color-game-cupday-rail: #e9d5a3;
  --color-game-cupday-light: #f6efcf;
  --color-game-cupday-dust: #a88054;
  --color-game-cupday-ink: #172732;
  --color-game-cupday-cream: #fff2d0;
  --color-game-cupday-horse: #73502f;
  --color-game-cupday-mane: #342b2e;
  --color-game-cupday-sky: #8fd0ee;
  --color-game-cupday-dusk: #7b8798;
  --color-game-cupday-turf-bright: #4f9e4a;
  --color-game-cupday-turf-dull: #3f7f3c;
  --color-game-cupday-coat: #a9662f;
  --color-game-cupday-coat-dark: #7d4a20;
  --color-game-cupday-muzzle: #d7a877;
  --color-game-cupday-silk: #f2c230;
  --color-game-cupday-pink: #e77fb3;
  --color-game-cupday-cloud: #a9b1bd;
  --color-game-cupday-cloud-dark: #858d9a;
  --color-game-cupday-rain: #4a90e2;
  --color-game-skullfire-bone-outline: #302735;
  --color-game-skullfire-bone-shadow: #a39792;
  --color-game-skullfire-bone: #e8dfba;
  --color-game-skullfire-bone-highlight: #fff1cf;
  --color-game-skullfire-socket-edge: #312532;
  --color-game-skullfire-socket: #100e19;
  --color-game-skullfire-nose: #241d2b;
  --color-game-skullfire-cheek: #d0c49f;
  --color-game-skullfire-tooth-highlight: #f8eaca;
  --color-game-skullfire-crack: #51404a;
  --color-game-skullfire-crack-light: #746769;
  --color-game-skullfire-jaw: #b3a48c;
  --color-game-skullfire-temple: #665665;
  --color-game-skullfire-ice-spark: #b5e4ef;
  --color-game-skullfire-fire: #ffb64f;
  --color-game-skullfire-cloak-highlight: #86bde7;
  --color-game-skullfire-hood: #568bc5;
  --color-game-skullfire-cloak: #3760a0;
  --color-game-skullfire-cloak-shadow: #244574;
  --color-game-skullfire-face: #101726;
  --color-game-skullfire-mage-eyes: #d8f5ff;
  --color-game-skullfire-cloak-fold: #659fda;
  --color-game-skullfire-staff: #b8a386;
  --color-game-skullfire-staff-recharge: #6593b4;
  --color-game-skullfire-staff-ice: #c5f5ff;
  --color-game-skullfire-ice-core: #efffff;
  --color-game-skullfire-flame: #ef9c3c;
  --color-game-skullfire-flame-tip: #ffe4a0;
  --color-game-skullfire-ash: #493b4a;
  --color-game-skullfire-fire-shadow: #a66b30;
  --color-game-skullfire-mouth: #e99b3d;
  --color-game-skullfire-mouth-core: #ffe1a1;
  --color-game-skullfire-teeth: #f6e5bd;
  --color-game-skullfire-eye-core: #fff4bf;
  --color-game-skullfire-ice: #8acde9;
  --color-game-skullfire-fire-core: #fff0b5;
  --color-game-skullfire-ice-trail: #416b9c;
  --color-game-skullfire-tomb: #0d0b14;
  --color-game-skullfire-masonry: #1c1828;
  --color-game-skullfire-aura: #211727;
  --color-game-skullfire-aura-edge: #0d0b14;
  --color-game-skullfire-circle: #79628b;
  --color-game-skullfire-circle-marker: #c3a9d7;

  --color-bg: #F7F8FA;
  --color-surface: #FFFFFF;
  --color-surface-alt: #E8ECF2;
  --color-text: #14181F;
  --color-text-muted: #4A5361;
  --color-accent: #1D4ED8;
  --color-accent-secondary: #1D4ED8;
  --color-on-accent: #FFFFFF;
  --color-success: #15803D;
  --color-on-success: #FFFFFF;
  /* Hand-drawn artwork is dark ink on white paper: it sits on this white in EVERY
     theme (deliberately not redefined for dark), so the lines never vanish. */
  --color-paper: #FFFFFF;
  --color-on-paper: #14181F;
  --color-danger: #B91C1C;
  --color-on-danger: #FFFFFF;
  --color-warning: #B45309;
  --color-border: #C9CFD8;
  --color-selected: rgba(29, 78, 216, 0.16);
  --color-danger-bg: rgba(185, 28, 28, 0.12);
  /* The Mystery letter reveal's highlight (glow, sparkles, rings): its own gold, never
     red (red means wrong). Light #F2B705, dark #E0B04F. */
  --color-highlight: #F2B705;
  /* Game-state palette (docs/DESIGN_TOKENS.md). Blue + amber, never green/red:
     correct/present differ in hue AND by >= 3:1 luminance, so they hold up
     under deuteranopia/protanopia. Red stays reserved for danger. */
  --color-game-correct: #061650;
  --color-game-on-correct: #FFFFFF;
  --color-game-present: #B36A06;
  --color-game-on-present: #000000;
  --color-game-present-ring: #2B1502;
  --color-game-absent: #F2F4F8;
  --color-game-found: #1D4ED8;
  --color-game-found-bg: #DCE5FA;
  --color-game-mark-x: #1D4ED8;
  --color-game-mark-o: #963F00;
  --color-game-board-light: #F2F4F8;
  --color-game-board-dark: #A3B1C7;
  /* Cat-astrophe: shelf lines, cardboard boxes and the [=] / [-] mark on them. */
  --color-game-shelf: #8A5A2B;
  /* Cat-astrophe: the shelf colour changes each level (walnut above, then these). */
  --color-game-shelf-teal: #2C7A7B;
  --color-game-shelf-plum: #7A4B8C;
  --color-game-shelf-olive: #5F6B21;
  --color-game-box: #D9B98A;
  --color-game-on-box: #2B1A05;
  /* Cat-astrophe item colours (1 mug … 7 fishbowl): fill each drawing; the number
     on top is --color-text, so each needs 4.5:1 with it. None is red-adjacent. */
  --color-game-item-mug: #F2D27A;
  --color-game-item-jar: #C9B3F0;
  --color-game-item-plant: #A8D8A0;
  --color-game-item-glass: #A6E3E9;
  --color-game-item-book: #9EC5F0;
  --color-game-item-vase: #E6B3E8;
  --color-game-item-fishbowl: #D4E89A;

  /* Solitaire cards (shared by later card games). Faces sit on --color-paper
     (white) in every theme, so the suit pair is the same in all of them and
     must keep 4.5:1 against white. Suits are also told apart by shape. Red here
     is a card suit, never "wrong". Backs are fixed art, not theme-driven. */
  --color-card-suit-red: #B3122B;
  --color-card-suit-black: #14181F;
  --color-card-back-classic: #1F3F9C;
  --color-card-back-classic-line: #FFFFFF;
  --color-card-back-arcade: #101826;
  --color-card-back-arcade-a: #F2B632;
  --color-card-back-arcade-b: #2FC4B2;
  --color-card-back-arcade-border: #F2B632;

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;

  --radius: 12px;
  --font-base: 18px;
  --font-sm: 15px;
  --font-lg: 24px;
  --tap-min: 48px;
  --ribbon-h: 57px;       /* the ribbon's height (owner, 8 Nov) */
  --ribbon-btn: 36px;     /* a game icon's visible box; its hit area is padded to 48px (#438) */
  --ribbon-btn-lg: 40px;  /* Home and the menu button */
  --ribbon-gap: 4px;
  --btn-h: 48px;          /* THE button height (#555): every .btn, primary or secondary, is this tall (min) */
  --btn-w: 140px;         /* a finish-row button's width: every button in the row is this wide (#555) */
  --key-h: 56px;          /* a keyboard key (Word Guess, Crossword) */
}

/* Clear Dark — the same Clear family (blue actions, neutral surfaces),
   deliberately tuned for a dark background rather than a straight
   invert: the accent lightens to #7AA2FF so it still reads as "tap me"
   at 4.5:1 on dark surfaces, and success/danger/present shift to lighter,
   slightly desaturated tones that hold contrast without turning
   fluorescent. Selectable explicitly in Admin > Appearance via
   data-theme="dark". Clear itself (:root, above) stays light regardless
   of the phone's own dark-mode setting — this is the only way to get a
   dark look, deliberately, not an automatic fallback. */
:root[data-theme="dark"] {
  /* Skullfire pixel-art palette: constant across themes; chrome uses shared tokens. */
  --color-game-cupday-gold: #ffe08a;
  --color-game-cupday-blue: #95d9ff;
  --color-game-cupday-lilac: #e9b9ff;
  --color-game-cupday-white: #f5f1df;
  --color-game-cupday-orange: #ffae71;
  --color-game-cupday-mint: #9cf0c0;
  --color-game-cupday-turf: #264d3c;
  --color-game-cupday-track: #be9563;
  --color-game-cupday-rail: #e9d5a3;
  --color-game-cupday-light: #f6efcf;
  --color-game-cupday-dust: #a88054;
  --color-game-cupday-ink: #172732;
  --color-game-cupday-cream: #fff2d0;
  --color-game-cupday-horse: #73502f;
  --color-game-cupday-mane: #342b2e;
  --color-game-cupday-sky: #8fd0ee;
  --color-game-cupday-dusk: #7b8798;
  --color-game-cupday-turf-bright: #4f9e4a;
  --color-game-cupday-turf-dull: #3f7f3c;
  --color-game-cupday-coat: #a9662f;
  --color-game-cupday-coat-dark: #7d4a20;
  --color-game-cupday-muzzle: #d7a877;
  --color-game-cupday-silk: #f2c230;
  --color-game-cupday-pink: #e77fb3;
  --color-game-cupday-cloud: #a9b1bd;
  --color-game-cupday-cloud-dark: #858d9a;
  --color-game-cupday-rain: #4a90e2;
  --color-game-skullfire-bone-outline: #302735;
  --color-game-skullfire-bone-shadow: #a39792;
  --color-game-skullfire-bone: #e8dfba;
  --color-game-skullfire-bone-highlight: #fff1cf;
  --color-game-skullfire-socket-edge: #312532;
  --color-game-skullfire-socket: #100e19;
  --color-game-skullfire-nose: #241d2b;
  --color-game-skullfire-cheek: #d0c49f;
  --color-game-skullfire-tooth-highlight: #f8eaca;
  --color-game-skullfire-crack: #51404a;
  --color-game-skullfire-crack-light: #746769;
  --color-game-skullfire-jaw: #b3a48c;
  --color-game-skullfire-temple: #665665;
  --color-game-skullfire-ice-spark: #b5e4ef;
  --color-game-skullfire-fire: #ffb64f;
  --color-game-skullfire-cloak-highlight: #86bde7;
  --color-game-skullfire-hood: #568bc5;
  --color-game-skullfire-cloak: #3760a0;
  --color-game-skullfire-cloak-shadow: #244574;
  --color-game-skullfire-face: #101726;
  --color-game-skullfire-mage-eyes: #d8f5ff;
  --color-game-skullfire-cloak-fold: #659fda;
  --color-game-skullfire-staff: #b8a386;
  --color-game-skullfire-staff-recharge: #6593b4;
  --color-game-skullfire-staff-ice: #c5f5ff;
  --color-game-skullfire-ice-core: #efffff;
  --color-game-skullfire-flame: #ef9c3c;
  --color-game-skullfire-flame-tip: #ffe4a0;
  --color-game-skullfire-ash: #493b4a;
  --color-game-skullfire-fire-shadow: #a66b30;
  --color-game-skullfire-mouth: #e99b3d;
  --color-game-skullfire-mouth-core: #ffe1a1;
  --color-game-skullfire-teeth: #f6e5bd;
  --color-game-skullfire-eye-core: #fff4bf;
  --color-game-skullfire-ice: #8acde9;
  --color-game-skullfire-fire-core: #fff0b5;
  --color-game-skullfire-ice-trail: #416b9c;
  --color-game-skullfire-tomb: #0d0b14;
  --color-game-skullfire-masonry: #1c1828;
  --color-game-skullfire-aura: #211727;
  --color-game-skullfire-aura-edge: #0d0b14;
  --color-game-skullfire-circle: #79628b;
  --color-game-skullfire-circle-marker: #c3a9d7;

  --color-bg: #0F1115;
  --color-surface: #1B1F27;
  --color-surface-alt: #2A303B;
  --color-text: #F5F7FA;
  --color-text-muted: #B4BCC8;
  --color-accent: #7AA2FF;
  --color-accent-secondary: #7AA2FF;
  --color-on-accent: #0B1220;
  --color-success: #4ADE80;
  --color-on-success: #0B1220;
  --color-danger: #F87171;
  --color-on-danger: #1A0505;
  --color-warning: #FBBF24;
  --color-border: #3A4150;
  --color-selected: rgba(122, 162, 255, 0.25);
  --color-danger-bg: rgba(248, 113, 113, 0.2);
  --color-highlight: #E0B04F;
  --color-game-correct: #3660D6;
  --color-game-on-correct: #FFFFFF;
  --color-game-present: #FFC72C;
  --color-game-on-present: #14181F;
  --color-game-present-ring: #14181F;
  --color-game-absent: #14171D;
  --color-game-found: #7AA2FF;
  --color-game-found-bg: #22335C;
  --color-game-mark-x: #7AA2FF;
  --color-game-mark-o: #FFC72C;
  --color-game-board-light: #3A4150;
  --color-game-board-dark: #0E1014;
  --color-game-shelf: #C79A62;
  --color-game-shelf-teal: #6CC4C4;
  --color-game-shelf-plum: #C49AD6;
  --color-game-shelf-olive: #B5C46A;
  --color-game-box: #8C6A3F;
  --color-game-on-box: #FFFFFF;
  --color-game-item-mug: #6B5410;
  --color-game-item-jar: #4B3A7A;
  --color-game-item-plant: #2F5E2A;
  --color-game-item-glass: #1F5F66;
  --color-game-item-book: #24497A;
  --color-game-item-vase: #6A2E6E;
  --color-game-item-fishbowl: #4D5E16;
}

/* Dark themes: shared tokens (they used to cascade from :root when it was
   dark; :root is light now, so they must be restated here). */
:root[data-theme="classic"],
:root[data-theme="soft"],
:root[data-theme="playful"] {
  /* Skullfire pixel-art palette: constant across themes; chrome uses shared tokens. */
  --color-game-cupday-gold: #ffe08a;
  --color-game-cupday-blue: #95d9ff;
  --color-game-cupday-lilac: #e9b9ff;
  --color-game-cupday-white: #f5f1df;
  --color-game-cupday-orange: #ffae71;
  --color-game-cupday-mint: #9cf0c0;
  --color-game-cupday-turf: #264d3c;
  --color-game-cupday-track: #be9563;
  --color-game-cupday-rail: #e9d5a3;
  --color-game-cupday-light: #f6efcf;
  --color-game-cupday-dust: #a88054;
  --color-game-cupday-ink: #172732;
  --color-game-cupday-cream: #fff2d0;
  --color-game-cupday-horse: #73502f;
  --color-game-cupday-mane: #342b2e;
  --color-game-cupday-sky: #8fd0ee;
  --color-game-cupday-dusk: #7b8798;
  --color-game-cupday-turf-bright: #4f9e4a;
  --color-game-cupday-turf-dull: #3f7f3c;
  --color-game-cupday-coat: #a9662f;
  --color-game-cupday-coat-dark: #7d4a20;
  --color-game-cupday-muzzle: #d7a877;
  --color-game-cupday-silk: #f2c230;
  --color-game-cupday-pink: #e77fb3;
  --color-game-cupday-cloud: #a9b1bd;
  --color-game-cupday-cloud-dark: #858d9a;
  --color-game-cupday-rain: #4a90e2;
  --color-game-skullfire-bone-outline: #302735;
  --color-game-skullfire-bone-shadow: #a39792;
  --color-game-skullfire-bone: #e8dfba;
  --color-game-skullfire-bone-highlight: #fff1cf;
  --color-game-skullfire-socket-edge: #312532;
  --color-game-skullfire-socket: #100e19;
  --color-game-skullfire-nose: #241d2b;
  --color-game-skullfire-cheek: #d0c49f;
  --color-game-skullfire-tooth-highlight: #f8eaca;
  --color-game-skullfire-crack: #51404a;
  --color-game-skullfire-crack-light: #746769;
  --color-game-skullfire-jaw: #b3a48c;
  --color-game-skullfire-temple: #665665;
  --color-game-skullfire-ice-spark: #b5e4ef;
  --color-game-skullfire-fire: #ffb64f;
  --color-game-skullfire-cloak-highlight: #86bde7;
  --color-game-skullfire-hood: #568bc5;
  --color-game-skullfire-cloak: #3760a0;
  --color-game-skullfire-cloak-shadow: #244574;
  --color-game-skullfire-face: #101726;
  --color-game-skullfire-mage-eyes: #d8f5ff;
  --color-game-skullfire-cloak-fold: #659fda;
  --color-game-skullfire-staff: #b8a386;
  --color-game-skullfire-staff-recharge: #6593b4;
  --color-game-skullfire-staff-ice: #c5f5ff;
  --color-game-skullfire-ice-core: #efffff;
  --color-game-skullfire-flame: #ef9c3c;
  --color-game-skullfire-flame-tip: #ffe4a0;
  --color-game-skullfire-ash: #493b4a;
  --color-game-skullfire-fire-shadow: #a66b30;
  --color-game-skullfire-mouth: #e99b3d;
  --color-game-skullfire-mouth-core: #ffe1a1;
  --color-game-skullfire-teeth: #f6e5bd;
  --color-game-skullfire-eye-core: #fff4bf;
  --color-game-skullfire-ice: #8acde9;
  --color-game-skullfire-fire-core: #fff0b5;
  --color-game-skullfire-ice-trail: #416b9c;
  --color-game-skullfire-tomb: #0d0b14;
  --color-game-skullfire-masonry: #1c1828;
  --color-game-skullfire-aura: #211727;
  --color-game-skullfire-aura-edge: #0d0b14;
  --color-game-skullfire-circle: #79628b;
  --color-game-skullfire-circle-marker: #c3a9d7;

  --color-on-accent: #FFFFFF;
  --color-success: #4caf80;
  --color-on-success: #0B1220;
  --color-danger: #e0654f;
  --color-warning: #E0B04F;
  /* These three used to read "var(--color-x)" (each pointing at itself), which
     is invalid CSS: every tint compared as empty and rendered transparent. */
  --color-selected: rgba(122, 162, 255, 0.25);
  --color-danger-bg: rgba(248, 113, 113, 0.2);
  --color-highlight: #e0b04f;
  /* Red-accent themes can't derive "correct" from their accent (red means
     wrong), so they share Clear Dark's blue + amber game palette. */
  --color-game-correct: #3660D6;
  --color-game-on-correct: #FFFFFF;
  --color-game-present: #FFC72C;
  --color-game-on-present: #14181F;
  --color-game-present-ring: #14181F;
  --color-game-absent: #111113;
  --color-game-found: #7AA2FF;
  --color-game-found-bg: #22335C;
  --color-game-mark-x: #7AA2FF;
  --color-game-mark-o: #FFC72C;
  --color-game-board-light: #3A3A40;
  --color-game-board-dark: #0A0A0B;
  --color-game-shelf: #C79A62;
  --color-game-shelf-teal: #6CC4C4;
  --color-game-shelf-plum: #C49AD6;
  --color-game-shelf-olive: #B5C46A;
  --color-game-box: #8C6A3F;
  --color-game-on-box: #FFFFFF;
  --color-game-item-mug: #6B5410;
  --color-game-item-jar: #4B3A7A;
  --color-game-item-plant: #2F5E2A;
  --color-game-item-glass: #1F5F66;
  --color-game-item-book: #24497A;
  --color-game-item-vase: #6A2E6E;
  --color-game-item-fishbowl: #4D5E16;
}

/* Classic Tool — bold Swiss red on deep charcoal (from SAW Design Brief) */
:root[data-theme="classic"] {
  --color-bg: #0F0F10;
  --color-surface: #1C1C1E;
  --color-surface-alt: #242428;
  --color-text: #F5F5F7;
  --color-text-muted: #A9A9B0;
  --color-accent: #E63946;
  --color-accent-secondary: #E63946;
  --color-border: #2A2A2D;
}

/* Soft Utility — warmer, calmer terracotta accent */
:root[data-theme="soft"] {
  --color-bg: #121212;
  --color-surface: #1C1C1E;
  --color-surface-alt: #262626;
  --color-text: #F8F5F0;
  --color-text-muted: #A89F91;
  --color-accent: #C45C4A;
  --color-accent-secondary: #C45C4A;
  --color-border: #2A2A2A;
}

/* Playful Contrast — deep navy base, bold red, soft gold highlights */
:root[data-theme="playful"] {
  --color-bg: #0F0F10;
  --color-surface: #1D3557;
  --color-surface-alt: #24406b;
  --color-text: #F5F5F7;
  --color-text-muted: #BCC6D9;
  --color-accent: #E63946;
  --color-accent-secondary: #E9C46A; /* used sparingly — icons, badges, special states */
  --color-accent-text: #FF6B76; /* red accent as text on navy needs to be lighter */
  --color-border: #2a4a75;
  --color-game-correct: #3760D2;
  --color-game-present: #F6D060;
  --color-game-absent: #0A182D;
  --color-game-found: #8FB0FF;
  --color-game-found-bg: #244172;
  --color-game-mark-x: #8FB0FF;
  --color-game-mark-o: #F6D060;
  --color-game-board-light: #2F4F82;
  --color-game-board-dark: #08111F;
}

/* JAMscapade studio tokens (#619). Used by the section pages (Arcade, Standalone
   games, Enigma, and the Pocket Arcade section chrome) only. Clear and Clear Dark
   are the two themes; these follow data-theme, never the phone's dark mode, as
   the rest of the shell does. Values from the JAMscapade design system
   (project/tokens.json). Use these names, not literal colours. */
:root {
  --jam-paper: #f4efe4;
  --jam-paper-raised: #fffdf7;
  --jam-ink: #1b1d2a;
  --jam-ink-muted: #5a5d6b;
  --jam-signal: #e4502b;
  --jam-signal-ink: #000000;
  --jam-teal: #16706b;
  --jam-gold: #e0a526;
  --jam-rule: #d6d0c2;
  --jam-focus: #1b1d2a;
}
:root[data-theme="dark"] {
  --jam-paper: #14161f;
  --jam-paper-raised: #1d2030;
  --jam-ink: #f4efe4;
  --jam-ink-muted: #b4b6c2;
  --jam-signal: #ff7a52;
  --jam-signal-ink: #14161f;
  --jam-teal: #4fc3bb;
  --jam-gold: #f2c14e;
  --jam-rule: #33374a;
  --jam-focus: #f4efe4;
}

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
  width: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  max-width: 100vw;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--font-base);
  -webkit-tap-highlight-color: transparent;
}

/* One dark bar, never themed: the full logo on Home, a compact bar (Home button,
   small logo, menu) everywhere else so the game gets the height. */
/* Boot: the bar stays hidden until the shell has set its state (the flags, the section menu, the
   translated labels), so a refresh never flashes the static markup. core.js removes data-boot after
   its first render; the fallback reveal below shows the bar anyway if the scripts never finish. */
.update-applied-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: var(--space-md); background: rgba(0, 0, 0, 0.6); }
.update-applied-card { max-width: 90vw; padding: var(--space-md); border-radius: 8px; background: var(--color-bg); color: var(--color-text, inherit); border: 1px solid var(--color-border); display: grid; gap: var(--space-sm); text-align: center; }
.update-applied-text { margin: 0; }
.app-header[data-boot="pending"] { visibility: hidden; animation: app-header-boot-reveal 0s linear 1.5s forwards; }
@keyframes app-header-boot-reveal { to { visibility: visible; } }
.app-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: #0F0F10;
  color: #F5F7FA;
  padding: var(--space-sm) var(--space-md);
  padding-top: calc(var(--space-sm) + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--color-border);
}
.app-header-logo {
  display: block;
  width: 128px;
  max-width: 40vw;
  height: auto;
  margin-right: auto;
}
.app-header-compact { padding-top: calc(4px + env(safe-area-inset-top, 0px)); padding-bottom: 4px; box-sizing: border-box; min-height: calc(var(--ribbon-h) + env(safe-area-inset-top, 0px)); }
.app-header-compact .app-header-logo { width: 84px; }
.home-btn,
.hamburger-btn {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  color: #F5F7FA;
  border: 1px solid var(--header-line);
  border-radius: 8px;
  padding: 0 var(--space-md);
  font-size: var(--font-base);
  font-weight: 700;
  min-width: var(--ribbon-btn-lg);
  min-height: var(--ribbon-btn-lg);
}
/* Visible size is not the touch target (#438): the box is 40px, an invisible pseudo-element pads the
   hit area out to at least 48x48 (STYLE_GUIDE section 5, "Ribbon buttons"). */
.home-btn::before,
.hamburger-btn::before,
.header-action-btn::before { content: ""; position: absolute; inset: -5px; }
.header-action-btn::before { inset: -6px; } /* 36px box, no border: 48px. Home and the menu have a 1px border, so -5px gives 48px */
.home-btn[hidden] { display: none; }
/* The header slot (shell/header-actions.js): a game's icon buttons sit beside the menu
   button. Same dark-bar look, same 48px target; the bar does not grow. */
.header-slot { display: flex; align-items: center; gap: var(--ribbon-gap); margin-left: auto; }
.app-header.has-slot { gap: var(--ribbon-gap); }
.header-slot[hidden] { display: none; }
.app-header.has-slot .app-header-logo { margin-right: 0; }
.header-action-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(245, 247, 250, 0.08);
  color: var(--header-fg);
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: var(--ribbon-btn);
  height: var(--ribbon-btn);
}
.header-action-btn > svg { width: 22px; height: 22px; }
.header-action-btn { position: relative; }
.header-action-btn[aria-pressed="true"] { background: rgba(245, 247, 250, 0.22); box-shadow: inset 0 -3px 0 var(--header-fg); }
.header-action-btn:disabled { opacity: 0.45; }
/* A button the player should notice now (Solitaire's Auto-finish, #382): solid light fill with a dark glyph
   (the bar's own colours, 12:1 on the bar) and a ring, so it reads without colour; a pulse for those who allow motion. */
.header-action-btn.is-attention { background: var(--header-fg); color: var(--header-bg); box-shadow: 0 0 0 2px var(--header-bg), 0 0 0 4px var(--header-fg); }
@media (prefers-reduced-motion: no-preference) {
  .header-action-btn.is-attention { animation: header-attention 1.6s ease-in-out infinite; }
}
@keyframes header-attention { 0%, 100% { box-shadow: 0 0 0 2px var(--header-bg), 0 0 0 4px var(--header-fg); } 50% { box-shadow: 0 0 0 2px var(--header-bg), 0 0 0 8px rgba(245, 247, 250, 0.35); } }
/* A small count on an icon (Hint, 3 left): the number is also in the accessible name. */
.header-badge { position: absolute; top: -2px; right: -2px; min-width: 16px; padding: 0 3px; border-radius: 8px; background: var(--header-fg); color: var(--header-bg); font-size: 11px; font-weight: 700; line-height: 16px; text-align: center; }
/* "More": the buttons that did not fit, as 48px rows with icon and text. */
.header-more-panel { position: absolute; top: 100%; right: var(--space-md); z-index: 60; min-width: 220px; padding: 6px; background: var(--header-bg); color: var(--header-fg); border: 2px solid var(--header-line); border-radius: 12px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); }
.header-more-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: var(--tap-min); padding: 0 10px; background: none; border: 0; border-radius: 8px; color: inherit; font: inherit; font-weight: 600; text-align: left; }
.header-more-item:disabled { opacity: 0.45; }
.header-more-item:focus-visible { outline: 3px solid var(--header-fg); outline-offset: -3px; }
.header-action-btn:focus-visible { outline: 3px solid var(--header-fg); outline-offset: 2px; }
.header-slot.is-menu { outline: 3px solid var(--header-fg); outline-offset: 4px; border-radius: 12px; }
/* With game buttons in the bar, the Home button shrinks to its icon and, on a phone, the
   logo steps aside, so the bar keeps its height. */
.app-header.has-slot .home-btn { padding: 0; }
.app-header.has-slot .home-btn > span:not([aria-hidden]) { display: none; }
@media (max-width: 480px) { .app-header.has-slot .app-header-logo { display: none; } }
.hamburger-btn { font-size: var(--font-lg); padding: 0; }
.home-btn:focus-visible,
.hamburger-btn:focus-visible { outline: 3px solid #F5F7FA; outline-offset: 2px; }
/* Version and copyright: one small muted line under Home and the Admin screens. It scrolls with the page. */
.app-footer {
  padding: var(--space-xs) var(--space-md);
  text-align: center;
  font-size: var(--font-sm);
  color: var(--color-text-muted);
}
.app-notice {
  display: inline;
}



.app-header-logo {
  cursor: pointer;
}

/* ---- Home screen: a Resume tile, then a tile grid per section ---- */
.home {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding-bottom: var(--space-lg);
}
.home-section-heading {
  color: var(--color-text-muted);
  font-size: var(--font-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: var(--space-md) var(--space-xs) 0;
}
.home-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-sm);
}
@media (min-width: 600px) {
  .home-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.home-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  width: 100%;
  min-height: var(--tap-min);
  margin: var(--space-md) 0 0;
  padding: 0 var(--space-xs);
  background: transparent;
  color: var(--color-text-muted);
  border: 0;
  font: inherit;
  font-size: var(--font-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  cursor: pointer;
}
.home-section-toggle:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.home-section-toggle .home-section-chevron { transition: transform 0.15s; }
.home-section-toggle[aria-expanded="true"] .home-section-chevron { transform: rotate(90deg); }
.home-section-body { display: flex; flex-direction: column; gap: var(--space-sm); }
.home-section-body[hidden] { display: none; }
/* The genre filter hides tiles and empty headings with the hidden attribute; author display rules must not win. */
.home .home-tile[hidden], .home .home-section-toggle[hidden], .home .home-section-heading[hidden], .home .home-grid[hidden], .home .home-subgenres[hidden] { display: none; }
.home-genres, .home-subgenres { display: flex; flex-wrap: wrap; gap: var(--space-xs); }
.home-genres .btn, .home-subgenres .btn { min-height: var(--tap-min); padding: 0 var(--space-md); font-size: var(--font-sm); }
.home-genres .btn[aria-pressed="true"], .home-subgenres .btn[aria-pressed="true"] { font-weight: bold; border-style: double; border-width: 4px; }
.home-genres .btn[aria-pressed="true"]::before, .home-subgenres .btn[aria-pressed="true"]::before { content: "\2713 "; }
.hamburger-search {
  width: 100%;
  min-height: var(--tap-min);
  padding: 0 var(--space-md);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font: inherit;
  font-size: var(--font-base);
}
.hamburger-empty { color: var(--color-text-muted); font-size: var(--font-sm); margin: 0 var(--space-xs); }
.games-sheet-heading { font-weight: 700; font-size: var(--font-lg); margin: var(--space-xs) var(--space-xs) 0; }
.games-sheet-section { color: var(--color-text-muted); font-size: var(--font-sm); margin: var(--space-sm) var(--space-xs) 0; }
.debug-only-badge { display: inline-block; font-weight: 800; font-size: var(--font-sm); letter-spacing: .06em; padding: 2px 8px; margin: var(--space-xs) 0; border: 2px solid var(--color-warning); border-radius: 4px; color: var(--color-text); }
.debug-intro { color: var(--color-text-muted); font-size: var(--font-sm); }
.debug-stats-table { border-collapse: collapse; font-size: var(--font-sm); margin: var(--space-sm) 0; width: 100%; }
.debug-stats-table th, .debug-stats-table td { border: 1px solid var(--color-border); padding: 4px 6px; text-align: left; vertical-align: top; }
.hamburger-item:focus-visible, .hamburger-search:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.home-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-sm);
  min-height: 112px;
  padding: var(--space-md);
  text-align: left;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
}
.home-tile:active {
  background: var(--color-selected);
}
.home-tile:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}
.home-tile-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--color-accent);
}
.home-tile-icon svg {
  width: 100%;
  height: 100%;
}
.home-tile-icon-letter {
  border-radius: var(--radius);
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-size: var(--font-lg);
  font-weight: 700;
}
.home-tile-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.home-tile-name {
  font-size: var(--font-base);
  font-weight: 600;
  line-height: 1.25;
}
.home-tile-status {
  font-size: var(--font-sm);
  color: var(--color-text-muted);
  min-height: 1.25em;
}
/* The "Next game in 3 hours" line (shell/daily-reset-ui.js): one calm line, never red. On Home it sits
   under the Daily heading. Inside a game it is a small pill in blank space, fixed and click-through,
   so it takes no room and nothing moves. */
.daily-reset {
  margin: 0;
  font-size: var(--font-sm);
  line-height: 1.3;
  color: var(--color-text-muted);
}
.daily-reset-home { margin: 0 0 var(--space-sm); }
.daily-reset-pill {
  position: fixed;
  z-index: 5;
  top: calc(var(--ribbon-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 2 * var(--space-md));
  padding: 2px var(--space-sm);
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
}
/* Word Guess, landscape (#502): the title is one line beside the pill in the top right. */
@media (orientation: landscape) {
  .ribbon-on .game-head .game-title { font-size: var(--font-sm); }
}
/* Sudoku, landscape (#502, #550): the title would sit above the grid and shrink it, so it goes in the blank corner
   under the keypad, above the daily pill. The board is the input, so it is on the right by default (STYLE_GUIDE, Which
   side) and the keypad, title and pill are in the left column; the "Landscape controls side" setting mirrors them. */
@media (orientation: landscape) {
  .ribbon-on .sudoku-head { position: fixed; left: calc(var(--rail-w, 64px) + var(--space-md)); bottom: 44px; max-width: 40vw; z-index: 4; text-align: left; }
  :root[data-controls-side="left"] .ribbon-on .sudoku-head { left: auto; right: var(--space-md); text-align: right; }
  .ribbon-on .sudoku-head .game-title { font-size: var(--font-base); }
}
/* Portrait (#502): Word Guess and Sudoku show their title at the top left; the pill is its own row above it (below), so a wide font can never make them collide. */
@media (orientation: portrait) {
  .ribbon-on .sudoku-head .game-title { font-size: var(--font-base); } /* "Sudoku · Medium" must clear the pill */
}
/* The pill never covers a game (#528). Portrait, games with no title row for it: it is its own centred row at the
   top of the screen (the game puts it first), so the board is sized and placed below it. Landscape: the game keeps
   blank space for it (Web of Words reserves it under the grid, data-fit-reserve). */
@media (orientation: portrait) {
  .daily-reset-pill {
    position: static; transform: none; align-self: center; width: fit-content; margin: 0 auto var(--space-xs); flex: 0 0 auto;
  }
}
/* Landscape: the ribbon is a rail on the left and the boards fill the height, so the pill goes in the
   blank corner each game leaves: above Word Guess's keyboard, below the keys and word lists on the right. */
@media (orientation: landscape) {
  .daily-reset-pill { top: auto; left: auto; transform: none; right: var(--space-md); bottom: var(--space-md); }
  .daily-reset-pill[data-game="wordle"] { top: var(--space-md); bottom: auto; }
  .daily-reset-pill[data-game="webofwords"] { right: auto; left: calc(var(--rail-w, 64px) + var(--space-md)); }
  /* Word Search (#534): the board is the input, on the right, so the pill takes the blank corner under the left column. */
  .daily-reset-pill[data-game="wordsearch"], .daily-reset-pill[data-game="sudoku"] { right: auto; left: calc(var(--rail-w, 64px) + var(--space-md)); }
  :root[data-controls-side="left"] .daily-reset-pill[data-game="wordsearch"],
  :root[data-controls-side="left"] .daily-reset-pill[data-game="sudoku"] { left: auto; right: var(--space-md); }
}
/* Resume: one full-width tile on top, icon beside the text. */
.home-tile-resume {
  flex-direction: row;
  align-items: center;
  min-height: 88px;
  margin-top: var(--space-sm);
  border: 2px solid var(--color-accent);
}
.home-tile-kicker {
  font-size: var(--font-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-accent);
}
.home-tile-resume .home-tile-name {
  font-size: var(--font-lg);
}

.hamburger-menu {
  position: fixed;
  inset: 0;
  z-index: 100;
}
.hamburger-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.hamburger-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(80vw, 320px);
  background: var(--color-bg);
  border-right: 1px solid var(--color-border);
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.hamburger-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
}
.hamburger-panel-header h2 {
  margin: 0;
  font-size: var(--font-lg);
}
.hamburger-close-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: var(--font-lg);
  padding: var(--space-xs);
}
.hamburger-list {
  display: flex;
  flex-direction: column;
  padding: var(--space-sm);
  gap: var(--space-xs);
}
.hamburger-section-header {
  color: var(--color-text-muted);
  font-size: var(--font-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: var(--space-sm) var(--space-xs) 0;
}
.hamburger-section-header:first-child {
  margin-top: 0;
}
.hamburger-item {
  text-align: left;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
  font-size: var(--font-base);
}
.hamburger-item.active {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* "What's new" — a dot on the ☰ button and a "New" word on the menu row. */
.hamburger-btn.has-news::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-accent);
  border: 2px solid #0F0F10;
}
.news-badge {
  margin-left: var(--space-sm);
  padding: 2px var(--space-sm);
  border-radius: 999px;
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-size: var(--font-sm);
  font-weight: 600;
}
.whatsnew-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.whatsnew-card[hidden] {
  display: none;
}
.whatsnew-older-btn {
  align-self: stretch;
  margin-bottom: var(--space-md);
}
.whatsnew-shot {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  object-position: top;
  background: var(--color-paper);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.whatsnew-card-game {
  margin: 0;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--color-text-muted);
}
.whatsnew-card-title {
  margin: 0;
  font-size: var(--font-lg);
}
.whatsnew-card-text {
  margin: 0;
  line-height: 1.4;
  font-size: var(--font-base);
}
.whatsnew-play {
  align-self: flex-start;
}

.plugin-container {
  padding: var(--space-md);
}
/* #664: the landscape Home menu uses the full width of the screen (no side gutters), on every landscape size. */
@media (orientation: landscape) {
  main.plugin-container:has(> .home) { padding-left: 0; padding-right: 0; }
}
.empty-state {
  color: var(--color-text-muted);
  text-align: center;
  margin-top: var(--space-lg);
}

/* Admin screen */
.admin-section-heading {
  margin: 0 0 var(--space-md);
  font-size: var(--font-lg);
  color: var(--color-accent);
}

/* Settings list: one full-width button per page; a page opens with a Back button above its heading. */
.admin-page-list { display: flex; flex-direction: column; gap: var(--space-sm); }
.admin-page-link { width: 100%; min-height: var(--tap-min); justify-content: flex-start; text-align: left; font-size: var(--font-base); }
.admin-back { min-height: var(--tap-min); margin: 0 0 var(--space-md); font-size: var(--font-base); }
/* Pocket Arcade's sub-items in the burger menu: indented under the Pocket Arcade row (owner, 2026-11-20). */
.hamburger-item.hamburger-sub { padding-left: 32px; }

.admin-category-header {
  color: var(--color-text-muted);
  font-size: var(--font-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: var(--space-md) 0 var(--space-xs);
}
.admin-category-header:first-child {
  margin-top: 0;
}
.admin-game-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-sm);
}
.admin-game-name {
  flex: 1;
  font-size: var(--font-base);
}
.admin-game-handle {
  background: transparent;
  color: var(--color-text-muted);
  border: none;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  margin-left: calc(var(--space-sm) * -1);
  font-size: 1.25rem;
  touch-action: none; /* the handle alone is dragged; the page still scrolls */
  cursor: grab;
}
.admin-game-handle:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}
.admin-game-row.dragging {
  position: relative;
  z-index: 1;
  border-color: var(--color-accent);
  opacity: 0.85;
}
.admin-game-row.drop-before {
  box-shadow: 0 calc(var(--space-sm) / -2 - 1px) 0 var(--color-accent);
}
.admin-game-row.drop-after {
  box-shadow: 0 calc(var(--space-sm) / 2 + 1px) 0 var(--color-accent);
}
.admin-games-reset {
  margin-top: var(--space-sm);
}
.btn-icon {
  background: var(--color-surface);
  color: var(--color-accent-text, var(--color-accent));
  border: 2px solid var(--color-accent);
  border-radius: var(--radius);
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
/* Disabled stays readable: never faded-out. */
.btn-icon:disabled {
  background: var(--color-surface-alt);
  border-color: var(--color-border);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 48px; /* full tap target; the visible track is inset below */
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  inset: 7px 0;
  background: var(--color-text-muted);
  border: 2px solid var(--color-text-muted);
  border-radius: 24px;
  transition: background 0.15s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 26px;
  width: 26px;
  left: 2px;
  top: 2px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  transition: transform 0.15s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--color-accent);
  border-color: var(--color-accent);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(26px);
}
.toggle-switch input:disabled + .toggle-slider {
  opacity: 0.5;
}
.toggle-switch input:focus-visible + .toggle-slider {
  outline: 3px solid var(--color-text);
  outline-offset: 2px;
}

.admin-diagnostics-actions {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}
.btn-danger {
  background: var(--color-danger);
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}
.log-entry {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  font-size: var(--font-sm);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--space-xs);
}
.log-time {
  color: var(--color-text-muted);
}
.log-level {
  text-transform: uppercase;
  font-weight: bold;
}
.log-level-error .log-level { color: var(--color-danger); }
.log-level-warn .log-level { color: #e0b04f; }
.log-level-info .log-level { color: var(--color-text-muted); }
.log-source {
  color: var(--color-accent);
}
.log-message {
  flex-basis: 100%;
}

/* Phrasebook */
.phrasebook-controls {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}
.phrasebook-pack-select,
.phrasebook-search {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-sm);
  font-size: var(--font-base);
}
.phrasebook-search {
  flex: 1;
  min-width: 150px;
}
.phrasebook-pack-header {
  color: var(--color-text-muted);
  font-size: var(--font-sm);
  margin-bottom: var(--space-sm);
}
.phrasebook-category h3 {
  font-size: var(--font-base);
  color: var(--color-accent);
  margin: var(--space-md) 0 var(--space-sm);
}
.phrasebook-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}
.phrasebook-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: var(--space-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-sm);
  align-items: baseline;
}
.phrasebook-base {
  color: var(--color-text-muted);
}

/* Dashboard */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-sm);
}
/* Card-style <button>s: browsers give buttons their own text colour and font,
   which rendered black-on-dark in dark mode. Inherit ours. */
button.card {
  color: var(--color-text);
  font: inherit;
}
.dashboard-tile {
  text-align: left;
  cursor: pointer;
}
.dashboard-tile-title {
  color: var(--color-text);
  font-weight: bold;
  font-size: var(--font-sm);
  margin: 0 0 var(--space-xs);
}
.dashboard-tile-value {
  font-size: 1.25rem;
  font-weight: bold;
  margin: 0 0 var(--space-xs);
}
.dashboard-tile-subtitle {
  font-size: var(--font-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-xs);
}
.dashboard-tile-updated {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  margin: 0;
}

/* Appearance / theme picker */
.theme-option {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.theme-option-active {
  border-color: var(--color-accent);
}
.theme-swatch {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid var(--color-border);
}
.theme-swatch-clear { background: linear-gradient(135deg, #F7F8FA 50%, #1D4ED8 50%); border: 1px solid #C9CFD8; }
.theme-swatch-dark { background: linear-gradient(135deg, #0F1115 50%, #7AA2FF 50%); }
.theme-swatch-classic { background: linear-gradient(135deg, #0F0F10 50%, #E63946 50%); }
.theme-swatch-soft { background: linear-gradient(135deg, #121212 50%, #C45C4A 50%); }
.theme-swatch-playful { background: linear-gradient(135deg, #1D3557 50%, #E9C46A 50%); }
.theme-option-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.theme-option-name {
  font-weight: bold;
}
.theme-option-desc {
  font-size: var(--font-sm);
  color: var(--color-text-muted);
}

/* ---- Shared game chrome and boards (docs/STYLE_GUIDE.md) ----
   A new game builds on these and adds only what is its own (a per-game look is an
   exception: see "Exceptions" in the guide). Order on screen: .game-head, .game-options,
   .game-status, the board, .game-record, .game-actions. Tokens only; red means wrong. */
.game-head {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-height: var(--tap-min);
  margin-bottom: var(--space-sm);
}
.game-head > .game-heading { flex: 1 1 auto; min-width: 0; }
.game-head > .btn { flex: 0 0 auto; min-height: var(--tap-min); font-size: var(--font-base); }
/* A status line inside the header sits under the title: small, muted, left. */
.game-head .game-status { margin: 0; font-size: var(--font-sm); font-weight: 400; text-align: left; color: var(--color-text-muted); min-height: 0; }
.game-title { margin: 0; font-size: var(--font-lg); line-height: 1.15; }
/* The loading screen for a game being fetched (shell/game-loading-ui.js, #675): name, one status line,
   a progress bar, the buttons. Compact, never scrolls. */
.game-loading { display: grid; gap: var(--space-md); max-width: 28rem; margin: 0 auto; padding: var(--space-md) 0; }
.game-loading .game-status { margin: 0; font-weight: 400; }
.game-loading-bar { width: 100%; height: 12px; accent-color: var(--color-accent); }
.game-loading .game-actions { display: grid; gap: var(--space-sm); }
/* The note a card carries for a game not on the device ("Download (0.2 MB)", "Not available offline"). */
/* Settings > Storage (#676): a game row is the Games-page row with its size under the name. */
.storage-row .admin-game-name { min-width: 0; display: grid; }
.storage-row .btn { flex: 0 0 auto; margin-left: var(--space-sm); min-height: var(--tap-min); }
.storage-usage { text-align: left; }
.pkg-note { display: block; font-size: var(--font-sm); color: var(--color-text-muted); }
[data-pkg-blocked="true"] { opacity: 0.6; cursor: not-allowed; }
/* Status line: plain words, never colour alone. Always the same size and place. */
.game-status {
  margin: 0 0 var(--space-sm);
  font-size: var(--font-base);
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  min-height: 1.25em;
}
/* Option bar: a row of equal buttons choosing a mode, size or opponent. The chosen
   one is outlined and bold (not a solid fill, so it is never taken for the primary). */
.game-options {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}
.game-options .btn { font-size: var(--font-base); padding: 8px 6px; min-width: 0; }
.game-option-active {
  background: var(--color-surface-alt);
  color: var(--color-text);
  box-shadow: 0 0 0 2px var(--color-accent);
  font-weight: 800;
}
/* Options button (shell/options-control.js): one compact button showing the current
   choice; opens an inline chooser. Chosen item = check mark + bold + outline. */
.game-option { display: flex; flex-direction: column; gap: var(--space-xs); min-width: 0; }
.game-options > .game-option { min-width: 0; }
.game-head > .game-option { flex: 0 1 auto; }
.game-option-btn {
  display: flex; align-items: center; gap: var(--space-xs);
  min-height: var(--tap-min); width: 100%; padding: 8px 10px;
  font-size: var(--font-base); text-align: left;
}
.game-option-label { color: var(--color-text-muted); font-weight: 400; white-space: nowrap; }
.game-option-label::after { content: ":"; }
.game-option-value { flex: 1 1 auto; min-width: 0; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-option-chooser { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: var(--space-xs); }
.game-option-chooser[hidden] { display: none; }
.game-option-chooser .btn { min-height: var(--tap-min); font-size: var(--font-base); padding: 8px 6px; }
.game-record { margin: var(--space-xs) 0 var(--space-md); font-size: var(--font-sm); color: var(--color-text-muted); text-align: center; }
.game-result .game-record, .crossword-result .game-record { margin: var(--space-xs) 0 0; }
.game-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}
.game-actions .btn { flex: 1 1 140px; }
/* End of game: buttons stacked full width, the primary first. */
.game-actions-stack { flex-direction: column; flex-wrap: nowrap; }
.game-actions-stack .btn { flex: 0 0 auto; }

/* Board. Default kind is a continuous grid: cells share edges, one outer border, thin
   lines between cells drawn in --board-line (so there are never gaps where cells meet).
   data-lines="none" drops the inner lines (alternating-tone boards: set data-tone on the
   cells). data-kind="tiles" is for separate objects (cards, guess tiles): spaced, rounded. */
.board {
  --board-cols: 8;
  --board-line: var(--color-text-muted);
  --board-line-w: 1px;
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(var(--board-cols), minmax(0, 1fr));
  gap: var(--board-line-w);
  width: 100%;
  max-width: 600px;
  margin: 0 auto var(--space-md);
  background: var(--board-line);
  border: 3px solid var(--color-text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.board[data-lines="none"] { gap: 0; background: var(--color-surface); }
.board[data-kind="tiles"] {
  --board-line-w: 8px;
  background: none;
  border: 0;
}
.board-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: clamp(1rem, calc(100cqw / var(--board-cols) * 0.6), 3.5rem);
  font-weight: 800;
  line-height: 1;
  touch-action: manipulation;
}
.board[data-kind="tiles"] .board-cell {
  border: 2px solid var(--color-text-muted);
  border-radius: 10px;
}
.board-cell[data-tone="light"] { background: var(--color-game-board-light); }
.board-cell[data-tone="dark"] { background: var(--color-game-board-dark); }
.board-cell:focus-visible { outline: 3px solid var(--color-text); outline-offset: -3px; z-index: 1; }
/* Disabled keeps the contents fully readable; only the pointer changes. */
.board-cell:disabled { color: var(--color-text); opacity: 1; cursor: default; }
/* States: each has a shape, so none relies on colour. selected = heavy solid ring;
   target (a legal move) = a dot; last (the last move) = a dashed ring;
   win = tint + heavy border + a tick badge. */
.board-cell[data-state="selected"] { box-shadow: inset 0 0 0 4px var(--color-text); }
.board-cell[data-state="last"] { box-shadow: inset 0 0 0 3px var(--color-text); outline: 0; }
.board-cell[data-state="last"]::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 3px dashed var(--color-text);
  pointer-events: none;
}
.board-cell[data-state="target"]::after {
  content: "";
  width: 28%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: var(--color-text);
  box-shadow: 0 0 0 3px var(--color-bg);
}
.board-cell[data-state="win"] {
  background: var(--color-game-found-bg);
  box-shadow: inset 0 0 0 4px var(--color-text);
}
.board-cell[data-state="win"]::after {
  content: "\2713";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-text);
  color: var(--color-bg);
  font-size: var(--font-sm);
  font-weight: 700;
}
/* Piece: a disc, 72% of the square. Side "a" is solid, side "b" is hollow with a heavy
   ring, so the two sides differ by shape and not by colour alone. data-king adds a crown. */
.board-piece {
  width: 72%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5em;
  pointer-events: none;
}
.board-piece[data-side="a"] {
  background: var(--color-text);
  color: var(--color-bg);
  box-shadow: inset 0 0 0 4px var(--color-text), inset 0 0 0 6px var(--color-bg);
}
.board-piece[data-side="b"] {
  background: var(--color-surface);
  color: var(--color-text);
  border: 5px solid var(--color-text);
}
.board-piece[data-king]::after { content: "\265B"; }

/* Games / Word Guess (Wordle-style). Tile size is set from JS via --wt so all
   six rows fit the screen; falls back to a width-based size. Every state has
   a non-colour marker (data-mark, drawn by ::after) per
   docs/STYLE_GUIDE.md: correct = solid fill + check, present =
   thick ring + dot, absent = dimmed + cross. */
/* The board is the shared tile board (.board[data-kind="tiles"], 5 columns, 4px gaps so six
   rows fit above the keyboard); a row only groups its tiles for screen readers. */
.wordle-row { display: contents; }
.board .wordle-tile {
  --wt-size: calc((100cqw - 16px) / 5);
  width: auto;
  height: auto;
  aspect-ratio: 1 / 1;
}
.wordle-tile {
  --wt-size: var(--wt, min(15vw, 68px));
  position: relative;
  width: var(--wt-size);
  height: var(--wt-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: calc(var(--wt-size) * 0.65);
  line-height: 1;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  text-transform: uppercase;
}
.wordle-tile-filled {
  border-color: var(--color-text);
}
.wordle-tile-correct {
  background: var(--color-game-correct);
  border-color: var(--color-game-correct);
  color: var(--color-game-on-correct);
}
.wordle-tile-present {
  background: var(--color-game-present);
  border: 4px solid var(--color-game-present-ring);
  color: var(--color-game-on-present);
}
.wordle-tile-absent {
  background: var(--color-game-absent);
  border-color: var(--color-border);
  color: var(--color-text-muted);
}
/* Corner marker: same corner on every state so it can be scanned at a glance. */
.wordle-tile[data-mark]::after {
  content: attr(data-mark);
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: max(13px, calc(var(--wt-size) * 0.26));
  font-weight: 900;
  line-height: 1;
}
.wordle-tile-correct[data-mark]::after { color: var(--color-game-on-correct); }
.wordle-tile-present[data-mark]::after { color: var(--color-game-present-ring); top: -1px; right: 0; }
.wordle-tile-absent[data-mark]::after { color: var(--color-text-muted); }

.wordle-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 10px;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: var(--font-sm);
  color: var(--color-text-muted);
}
.wordle-legend li {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.wordle-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 3px solid var(--color-border);
  border-radius: 5px;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}
.wordle-swatch.wordle-tile-present { border-width: 3px; color: var(--color-game-present-ring); }

/* Slot under the board: the legend normally, a plain-words notice when a
   guess needs attention. Fixed height so the keyboard never jumps. */
.wordle-info {
  min-height: 2.6em;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.wordle-legend[hidden],
.wordle-notice[hidden] { display: none; }
.wordle-notice {
  margin: 0;
  text-align: center;
  font-size: var(--font-sm);
  font-weight: 700;
  line-height: 1.3;
  color: var(--color-text);
}
.wordle-notice-error { color: var(--color-danger); }

.game-result {
  text-align: center;
  margin-bottom: var(--space-sm);
}
.game-result-title {
  font-size: var(--font-lg);
  font-weight: bold;
  margin: 0 0 var(--space-xs);
}
.game-result .empty-state {
  margin: 0;
}
/* Keyboard: spans the full screen width (bleeds through the 16px container
   padding), 56px keys. Also used by the crossword. */
.wordle-keyboard {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  align-items: stretch;
  width: calc(100% + 24px);
  margin: var(--space-sm) -12px 0;
}
.wordle-keyboard-row {
  display: flex;
  gap: 4px;
  width: 100%;
}
.wordle-key {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: var(--key-h);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface-alt);
  color: var(--color-text);
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
  /* quick repeated taps are typing, not a double-tap zoom */
  touch-action: manipulation;
}
.wordle-key-wide {
  flex: 1.5 1 0;
  font-size: 1rem;
  text-transform: none;
}
.wordle-key-enter {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-on-accent);
}
.wordle-key[data-mark]::after {
  content: attr(data-mark);
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 0.8rem;
  font-weight: 900;
  line-height: 1;
}
.wordle-key-correct {
  background: var(--color-game-correct);
  border-color: var(--color-game-correct);
  color: var(--color-game-on-correct);
}
/* "Present" = amber fill + dark ring + dot (colour is never the only signal).
   The heavier ring is drawn inset so the key keeps the same 1px border (and
   therefore the same width) as every other key: a wider border would make
   yellow keys wider and nudge their neighbours sideways. */
.wordle-key-present {
  background: var(--color-game-present);
  border-color: var(--color-game-present-ring);
  box-shadow: inset 0 0 0 2px var(--color-game-present-ring);
  color: var(--color-game-on-present);
}
.wordle-key-gone {
  visibility: hidden;
  pointer-events: none;
}
.wordle-key-correct[data-mark]::after { color: var(--color-game-on-correct); }
.wordle-key-present[data-mark]::after { color: var(--color-game-present-ring); top: -1px; right: 1px; }
@media (min-width: 640px) {
  .wordle-keyboard {
    width: 100%;
    max-width: 600px;
    margin-inline: auto;
  }
}

/* Word Guess, short portrait (360x640): the "Next game" pill is its own row now, so the keys drop to the 48px tap minimum
   to pay for it and the keyboard still ends inside the screen with no scroll. */
@media (orientation: portrait) and (max-height: 680px) {
  .wordle-key { height: var(--tap-min); }
}

/* #535: Word Guess on a very short landscape screen (a phone with the browser bars showing): the keys drop to the 48px
   tap minimum and the slot under the grid shrinks, so title, notice, keyboard and the "Next game" row fit without scrolling. */
@media (orientation: landscape) and (max-height: 340px) {
  .wordle-key { height: var(--tap-min); }
  .wordle-keyboard { gap: 4px; margin-top: 4px; }
  .wordle-info { min-height: 1.4em; }
}
@media (orientation: landscape) and (max-height: 310px) {
  .wordle-key { height: 44px; } /* the one place under the 48px tap minimum: 300px of height has no room for more (issue 535) */
}

/* Word Search highlighter colours, one per word (8, round-robin). Drawn as a
   translucent pill under the letters, so each is a mid tone the text stays
   readable on. No red or orange (red means wrong) and no amber (the pending
   selection is amber). Dark themes get deeper tones for the light text. */
:root {
  --word-search-hl-0: hsl(205, 90%, 58%);
  --word-search-hl-1: hsl(170, 70%, 45%);
  --word-search-hl-2: hsl(125, 60%, 50%);
  --word-search-hl-3: hsl(80, 65%, 50%);
  --word-search-hl-4: hsl(235, 85%, 72%);
  --word-search-hl-5: hsl(275, 75%, 68%);
  --word-search-hl-6: hsl(310, 65%, 65%);
  --word-search-hl-7: hsl(30, 45%, 55%);
}
:root[data-theme="dark"],
:root[data-theme="classic"],
:root[data-theme="soft"],
:root[data-theme="playful"] {
  --word-search-hl-0: hsl(205, 85%, 45%);
  --word-search-hl-1: hsl(170, 75%, 33%);
  --word-search-hl-2: hsl(125, 55%, 38%);
  --word-search-hl-3: hsl(80, 60%, 36%);
  --word-search-hl-4: hsl(235, 70%, 60%);
  --word-search-hl-5: hsl(275, 60%, 55%);
  --word-search-hl-6: hsl(310, 55%, 50%);
  --word-search-hl-7: hsl(30, 45%, 42%);
}
.word-search-hint {
  text-align: center;
}
/* The puzzle's theme line (#495): the shared status line, muted and small, in the blank space above the
   grid; in landscape it is the first line of the column beside the grid (never over the pill at the bottom). */
.word-search-theme { margin: 0 0 var(--space-xs); font-size: var(--font-sm); font-weight: 600; color: var(--color-text-muted); }
/* No gap between cells and no cell borders: the grid lines are drawn by the
   highlighter layer (an SVG in cell units), so it lines up exactly with the
   cells at any size and a highlight can cover the lines. */
.board[data-puzzle=word-search] {
  position: relative;
  background: var(--color-surface);
  /* Dragging across letters selects a word, so the grid (and only the grid)
     must not scroll, select text or open the long-press menu. */
  touch-action: none;
}
/* The highlighter layer sits under the letters (cells are transparent and
   stacked above it) and never takes a pointer event. */
.word-search-highlights {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  overflow: visible;
  pointer-events: none;
}
.word-search-cell {
  position: relative;
  z-index: 1;
  aspect-ratio: 1 / 1;
  width: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Letter ≈ 65% of the tile (10 columns in ~358px at 390px wide), sized
     against viewport width; the max matches the 600px board cap. */
  font-size: clamp(1.1rem, calc(100cqw / var(--board-cols) * 0.6), 2.35rem);
  line-height: 1;
  font-weight: bold;
  text-transform: uppercase;
  background: transparent;
  color: var(--color-text);
  border: 0;
  border-radius: 0;
  padding: 0;
}
/* FOUND: the word's pill (SVG, one per word) is the marker, drawn over the grid
   lines and under the letters. Crossing words get their own colours and overlap
   translucently. */
.word-search-lines {
  fill: none;
  stroke: var(--color-border);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}
.word-search-pill {
  stroke-width: 0.05;
  stroke-linejoin: round;
}
.word-search-pill-0 { fill: var(--word-search-hl-0); stroke: var(--word-search-hl-0); }
.word-search-pill-1 { fill: var(--word-search-hl-1); stroke: var(--word-search-hl-1); }
.word-search-pill-2 { fill: var(--word-search-hl-2); stroke: var(--word-search-hl-2); }
.word-search-pill-3 { fill: var(--word-search-hl-3); stroke: var(--word-search-hl-3); }
.word-search-pill-4 { fill: var(--word-search-hl-4); stroke: var(--word-search-hl-4); }
.word-search-pill-5 { fill: var(--word-search-hl-5); stroke: var(--word-search-hl-5); }
.word-search-pill-6 { fill: var(--word-search-hl-6); stroke: var(--word-search-hl-6); }
.word-search-pill-7 { fill: var(--word-search-hl-7); stroke: var(--word-search-hl-7); }
.word-search-pill {
  fill-opacity: 0.5;
  stroke-opacity: 0.9;
}
/* SELECTED (the live drag, or the first letter tapped): exactly the found-word
   pill (same shape, opacity and solid edge) in a neutral colour, since the
   word's own colour is not known until it is found. */
.word-search-pill-selected {
  fill: var(--color-text-muted);
  stroke: var(--color-text-muted);
}
.word-search-cell:focus-visible {
  outline: 3px solid var(--color-text);
  outline-offset: -3px;
  z-index: 2;
}
.word-search-word-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs) var(--space-md);
  justify-content: center;
  padding: 0;
  margin: 0 0 var(--space-md);
}
.word-search-word-list li {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-base);
  font-weight: 600;
  color: var(--color-text);
  text-transform: uppercase;
  border-left: 3px solid transparent;
  padding-left: 6px;
}
/* Match the grid colours in the word list for visual connection */
.word-search-colour-0 { border-left-color: var(--word-search-hl-0); }
.word-search-colour-1 { border-left-color: var(--word-search-hl-1); }
.word-search-colour-2 { border-left-color: var(--word-search-hl-2); }
.word-search-colour-3 { border-left-color: var(--word-search-hl-3); }
.word-search-colour-4 { border-left-color: var(--word-search-hl-4); }
.word-search-colour-5 { border-left-color: var(--word-search-hl-5); }
.word-search-colour-6 { border-left-color: var(--word-search-hl-6); }
.word-search-colour-7 { border-left-color: var(--word-search-hl-7); }
/* FOUND word: a ✓ before it AND a line through it, plus muted text. The
   ✓ is inline-block-ish (own flex item) so the line-through doesn't cross it. */
.word-search-word-found {
  color: var(--color-text-muted);
}
.word-search-word-found .word-search-word-text {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}
.word-search-tick {
  color: var(--color-game-found);
  font-weight: 900;
}
.word-search-result-back {
  margin-top: var(--space-sm);
}
/* Screen-reader-only text (announced, not drawn). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.crossword-clue-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin: calc(var(--space-sm) * -1) 0 var(--space-sm);
}
.crossword-clue-row .crossword-active-clue {
  flex: 1;
  min-width: 0;
  margin: 0;
}
.crossword-nav {
  flex: none;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  font-size: 1.6rem;
  line-height: 1;
}
.crossword-active-clue {
  text-align: center;
  font-size: calc(var(--font-base) * 1.15);
  font-weight: bold;
  line-height: 1.25;
  /* pull up under the game selector so board + keyboard fit at 360x740 */
  margin: calc(var(--space-sm) * -1) 0 var(--space-sm);
}
/* Crossword (the Daily Crossword's 15x15 and the Mystery's hosted 5x5). Colours come
   only from theme tokens. Focus cues:
   - selected cell: 2px accent ring, drawn inside the cell (no bars)
   - active word:   light tint
   - active clue:   the clue strip under the grid
   Letter, number and padding scale with the cell (100cqw / columns), so a 15x15
   cell on a phone (about 22px) stays square once it holds a letter. */
.board[data-puzzle=crossword] { margin-bottom: var(--space-sm); }
.crossword-cell {
  touch-action: manipulation;
  position: relative;
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  /* buttons don't inherit colour; without this the cell's own text colour
     is the browser default (black), unreadable on dark themes */
  color: var(--color-text);
  border: 0;
  border-radius: 0;
  padding: min(10px, calc(100cqw / var(--board-cols) * 0.18)) 0 0;
}
.crossword-cell-black {
  background: var(--color-text-muted);
}
.crossword-cell-letter {
  font-size: clamp(0.6rem, calc(100cqw / var(--board-cols) * 0.6), 3.5rem);
  line-height: 1;
  font-weight: bold;
  color: var(--color-text);
  text-transform: uppercase;
}
.crossword-cell-number {
  position: absolute;
  top: min(2px, calc(100cqw / var(--board-cols) * 0.04));
  left: min(4px, calc(100cqw / var(--board-cols) * 0.08));
  font-size: min(var(--font-sm), calc(100cqw / var(--board-cols) * 0.32));
  line-height: 1;
  color: var(--color-text-muted);
}
.crossword-cell-active {
  background: linear-gradient(var(--color-selected), var(--color-selected)), var(--color-surface);
}
.crossword-cell-selected {
  z-index: 1;
  box-shadow: inset 0 0 0 2px var(--color-accent);
}
.crossword-cell-incorrect {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--color-error);
  color: var(--color-error);
}
.crossword-cell-incorrect .crossword-cell-letter {
  color: var(--color-error);
}
/* A correct word locks: green tint and a lock mark, so the letter is clearly fixed (not by colour alone). */
.crossword-cell-locked { background: var(--color-game-correct); color: var(--color-game-on-correct); }
.crossword-cell-locked .crossword-cell-letter { color: var(--color-game-on-correct); }
.crossword-cell-locked::after { content: "🔒"; position: absolute; top: 1px; right: 2px; font-size: .55em; line-height: 1; pointer-events: none; }
.crossword-cell:focus-visible {
  outline: 3px solid var(--color-text);
  outline-offset: -3px;
  z-index: 2;
}
.crossword-result {
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-sm);
}
.crossword-result .empty-state {
  margin: 0;
}
.board[data-puzzle=crossword] + .wordle-keyboard {
  margin-top: var(--space-sm);
  gap: 6px;
}
/* Card states never rely on colour alone (docs/STYLE_GUIDE.md):
   face-down = striped card back with a strong outline; flipped = heavy
   ring; matched = outlined, no fill, dimmed face, and a check badge. */
.memory-card {
  color: var(--color-text);
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Face fills ~65% of the card. Card width = (content width - 3 gaps) / 4,
     content width = the grid's width (a container: shell/layout-fit.js). */
  font-size: clamp(1.25rem, calc((100cqw - 24px) / 4 * var(--memory-face-scale, 0.52)), 6rem);
  line-height: 1;
  background: repeating-linear-gradient(45deg, var(--color-surface-alt) 0 7px, var(--color-surface) 7px 14px);
  border: 2px solid var(--color-text-muted);
  border-radius: 10px;
  padding: 0;
}
.memory-card:focus-visible {
  outline: 3px solid var(--color-text);
  outline-offset: 3px;
}
.memory-card-flipped {
  background: var(--color-surface);
  border-color: var(--color-text);
  box-shadow: 0 0 0 3px var(--color-text);
}
.memory-card-matched {
  background: var(--color-bg);
  border-color: var(--color-game-correct);
}
.memory-card-matched .memory-card-face {
  opacity: 0.6;
}
.memory-card-matched::after {
  content: "\2713";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-text);
  color: var(--color-bg);
  font-size: var(--font-sm);
  font-weight: 700;
  line-height: 1;
}

.sudoku-cell {
  position: relative;
  isolation: isolate; /* lets the conflict stripes sit behind the digit */
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.5rem, calc(100cqw / 9 * 0.62), 2.4rem);
  font-weight: 400; /* entered digits: regular */
  line-height: 1;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-text-muted); /* strong enough to read on a phone */
  padding: 0;
}
/* Given digits: bold on a tinted cell. Entered digits: regular weight in the accent colour. */
.sudoku-cell-given {
  font-weight: 800;
  color: var(--color-text);
  background: var(--color-surface-alt);
}
/* 3x3 box borders stay heavier than cell borders in every theme. */
.sudoku-cell-box-left {
  border-left: 3px solid var(--color-text);
}
.sudoku-cell-box-top {
  border-top: 3px solid var(--color-text);
}
/* Entered digits: regular weight in the accent colour (givens are bold and black). */
.sudoku-cell-entered:not(.sudoku-cell-conflict) {
  color: var(--color-accent);
}
/* Same digit as the selected one: a filled disc behind a bold digit (shape and
   weight, not just colour). */
.sudoku-cell-highlighted:not(.sudoku-cell-conflict) {
  background-image: radial-gradient(circle at center, color-mix(in srgb, var(--color-accent) 50%, transparent) 0 56%, transparent 58%);
  font-weight: 800;
}
/* Same row or column as the selection: an accent tint over the cell's own fill,
   so a given stays tinted. Cells that share only the 3x3 box get no wash (the
   heavy box border already frames them). */
.sudoku-cell-peer-line {
  background-image: linear-gradient(color-mix(in srgb, var(--color-accent) 26%, transparent), color-mix(in srgb, var(--color-accent) 26%, transparent));
}
.sudoku-cell-peer-line.sudoku-cell-highlighted:not(.sudoku-cell-conflict) {
  background-image: radial-gradient(circle at center, color-mix(in srgb, var(--color-accent) 50%, transparent) 0 56%, transparent 58%), linear-gradient(color-mix(in srgb, var(--color-accent) 26%, transparent), color-mix(in srgb, var(--color-accent) 26%, transparent));
}
/* Selected cell: a thick accent ring (4px, then a 2px gap) on a tinted cell, above
   its neighbours' borders. It reads on any fill and without colour. */
.sudoku-cell-selected {
  z-index: 1;
  background-image: none;
  box-shadow: inset 0 0 0 4px var(--color-accent), inset 0 0 0 6px var(--color-surface);
  font-weight: 800;
}
.sudoku-cell-selected:not(.sudoku-cell-conflict) {
  background-color: color-mix(in srgb, var(--color-accent) 22%, var(--color-surface));
}
/* Conflict: danger colour + diagonal stripes + wavy underline (+ a warning
   line in the status text). Reads without colour. */
.sudoku-cell-conflict {
  color: var(--color-danger);
  background: var(--color-danger-bg);
  text-decoration: underline wavy var(--color-danger);
  text-decoration-thickness: 2px;
  text-underline-offset: 1px; /* small: a bigger offset pushes the wave out of the cell and clips it */
}
.sudoku-cell-conflict::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  opacity: 0.4;
  background: repeating-linear-gradient(135deg, var(--color-danger) 0 2px, transparent 2px 7px);
  pointer-events: none;
}
.sudoku-keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}
@media (max-height: 800px) {
  .sudoku-key {
    height: 48px;
  }
}
.sudoku-key {
  position: relative;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1.6rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface-alt);
  color: var(--color-text);
}
.sudoku-key-wide {
  font-size: 1rem;
}
.sudoku-key:disabled {
  cursor: default;
}
/* Digit fully placed: still readable, but struck through with a tick and a
   dashed border, so it looks switched off (not just faded or missing). */
.sudoku-key-done,
.sudoku-key-done:disabled {
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  border: 2px dashed var(--color-text-muted);
  text-decoration: line-through;
  text-decoration-thickness: 3px;
}
.sudoku-key-done::after {
  content: "\2713";
  position: absolute;
  top: 1px;
  right: 6px;
  font-size: 1rem;
  font-weight: 800;
  color: var(--color-text);
  text-decoration: none;
}
.sudoku-key-active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-on-accent);
}
.sudoku-key-legend {
  margin: var(--space-sm) 0 0;
  text-align: center;
  font-size: var(--font-sm);
  color: var(--color-text-muted);
}
/* Finished screen: result card, then a full-width primary, then secondary. */

/* "Share result" on a finished daily game: a secondary button under the primary,
   with a quiet status line (copied / could not share) that a screen reader hears. */
.share-result {
  display: grid;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}
.share-result .share-status {
  margin: 0;
  text-align: center;
  font-size: var(--font-sm);
  color: var(--color-text-muted);
}

/* Backup */
.backup-import-input {
  display: block;
  margin-top: var(--space-sm);
}
.phrasebook-native {
  font-weight: bold;
}
.phrasebook-pron {
  font-size: var(--font-sm);
  color: var(--color-text-muted);
  font-style: italic;
}

.toolkit-toast {
  position: fixed;
  left: var(--space-md);
  right: var(--space-md);
  bottom: calc(var(--space-lg) + var(--space-md) + env(safe-area-inset-bottom, 0px));
  max-width: 480px;
  margin: 0 auto;
  background: var(--color-surface);
  border: 1px solid var(--color-danger);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text);
  font-size: var(--font-sm);
  text-align: center;
  z-index: 500;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toolkit-toast-visible {
  opacity: 1;
  transform: translateY(0);
}
.toolkit-toast-warn {
  border-color: var(--color-accent);
}
.toolkit-toast-error {
  border-color: var(--color-danger);
}

.god-mode-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  z-index: 800;
}
.god-mode-panel {
  width: 100%;
  max-width: 360px;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.god-mode-input {
  min-height: var(--tap-min);
  font-size: var(--font-base);
  text-transform: uppercase;
  padding: 0 var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
}
.god-mode-message { min-height: 1.4em; font-size: var(--font-sm); }
.god-mode-actions { display: flex; gap: var(--space-sm); }
.god-mode-actions button {
  flex: 1;
  min-height: var(--btn-h);
  font-size: var(--font-base);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  color: var(--color-text);
}
.god-mode-actions button[type="submit"] {
  background: var(--color-accent);
  color: var(--color-on-accent);
  border-color: var(--color-accent);
}

.crash-overlay {
  position: fixed;
  inset: 0;
  background: #200a0a;
  color: #ffb4a8;
  padding: var(--space-md);
  padding-top: calc(var(--space-md) + env(safe-area-inset-top, 0px));
  overflow: auto;
  z-index: 9999;
  font-size: var(--font-sm);
}
.crash-overlay pre {
  white-space: pre-wrap;
  word-break: break-word;
  border-bottom: 1px solid #402020;
  padding-bottom: var(--space-sm);
  margin-bottom: var(--space-sm);
}

/* Shared components plugins may use */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
}
.btn {
  background: var(--color-accent);
  color: var(--color-on-accent);
  border: 2px solid var(--color-accent);
  border-radius: var(--radius);
  min-height: var(--btn-h);
  padding: 10px var(--space-md);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}
/* The one focus ring for every button (issue 510): two tones, so it shows on the button's fill AND on the page.
   The inner 2px band is the button's own text colour (currentColor: always readable on its fill, white on
   the blue button, dark on the yellow one); the outer 3px band is --color-text (readable on the page and
   on cards). A single black ring on blue was 2.5:1 and nearly invisible. scripts/theme-contrast.test.mjs
   holds both halves to 3:1 in Clear and Clear Dark. */
.btn:focus-visible,
.btn-icon:focus-visible,
.sudoku-key:focus-visible,
.wordle-key:focus-visible {
  outline: 3px solid var(--color-text);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px currentColor;
}
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-accent-text, var(--color-accent));
  border-color: var(--color-accent);
}
.btn.btn-danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: var(--color-on-danger, #fff);
}
/* Full-width primary action, thumb-sized. One per screen. */
.btn-block {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}
/* Disabled stays readable: never faded-out text. */
.btn:disabled {
  background: var(--color-surface-alt);
  border-color: var(--color-border);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

/* Web version banners (shell/pwa-ui.js): "update ready" and the iOS
   "Add to Home Screen" hint. Pinned to the bottom, clear of the home indicator. */
.pwa-banner {
  position: fixed;
  left: max(var(--space-md), env(safe-area-inset-left, 0px));
  right: max(var(--space-md), env(safe-area-inset-right, 0px));
  bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
  max-width: 480px;
  margin: 0 auto;
  background: var(--color-surface);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  padding: var(--space-md);
  color: var(--color-text);
  font-size: var(--font-sm);
  z-index: 600;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.pwa-banner-visible {
  opacity: 1;
  transform: translateY(0);
}
.pwa-banner-head {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--color-accent-text, var(--color-accent));
}
.pwa-banner-title {
  font-size: var(--font-base);
  color: var(--color-text);
}
.pwa-banner-text {
  margin: var(--space-sm) 0 0;
  line-height: 1.4;
}
.pwa-banner-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}
.pwa-banner-update .pwa-banner-text {
  margin-top: 0;
  font-size: var(--font-base);
}
.pwa-banner-update .pwa-banner-actions {
  margin-top: var(--space-sm);
}

/* Noughts and Crosses: the shared continuous board (3 columns, 1px lines) with its own
   cell look. X and O are different letters in their own mark colours (never colour alone);
   the winning line is the shared win state, with its badge in the winner's colour. */
.noughts-cell { font-size: clamp(2.5rem, calc(100cqw / 3 * 0.6), 6rem); }
html[data-input="pad"] :is(button, a, input, select, [tabindex]):focus {
  outline: 3px solid var(--color-text);
  outline-offset: -4px;
}
html[data-input="pad"] .app-header :focus { outline-color: currentColor; }
/* Controller focus on a button: the same two-tone ring as keyboard focus, outside the button (the inset ring above
   put a dark line on the blue fill at 2.5:1, issue 510). */
html[data-input="pad"] :is(.btn, .btn-icon, .sudoku-key, .wordle-key):focus {
  outline: 3px solid var(--color-text);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px currentColor;
}
html[data-input="pad"] .sol-card:focus { z-index: 5; }
[data-input-prompt] { display: none; margin: var(--space-xs) 0; font-size: var(--font-sm); color: var(--color-text-muted); text-align: center; }
html[data-input="pad"] [data-input-prompt] { display: block; }
/* Keyboard legend (#635): a chip by the highlighted pause-menu control, only with the menu open and keys in use.
   Text from a data attribute: not focusable, no layout, never over the board (the menu sits above the dimmed board). */
body.input-keys-legend [data-key-focus] { position: relative; }
body.input-keys-legend [data-key-focus]:focus-visible::after {
  content: attr(data-key-focus); position: absolute; top: 100%; left: 50%; transform: translateX(-50%); z-index: 5; white-space: nowrap; pointer-events: none;
  padding: 0 var(--space-xs); font-size: var(--font-sm); font-weight: normal; color: var(--color-text); background: var(--color-surface); border-radius: var(--radius);
}
[data-input-readout] { max-width: 100%; max-height: 18rem; overflow: auto; font-size: var(--font-sm); }
[data-input-setting] { margin: var(--space-xs); }
.input-bindings { display: grid; grid-template-columns: repeat(2, minmax(0, 14rem)); justify-content: start; gap: var(--space-xs); margin: var(--space-xs) 0; }
.input-bindings [data-input-setting] { margin: 0; min-height: var(--tap-min); text-align: left; }
[data-input-setting][aria-pressed="true"] { font-weight: bold; border-style: double; border-width: 4px; }
[data-input-setting][aria-pressed="true"]::before { content: "\2713 "; }
.dialog-controller { max-width: min(420px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; background: var(--color-surface); color: var(--color-text); border: 3px solid var(--color-text); border-radius: var(--radius); padding: var(--space-md); }
@media (orientation: landscape) {
  [data-input-game="noughts"] {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) calc(100dvh - 12px);
    gap: 0 var(--space-md);
    align-items: center;
  }
  [data-input-game="noughts"] > .board { grid-column: 2; grid-row: 1 / span 9; margin: 0; } /* the grid is the input: right by default */
  /* The landscape rail frees the full height (#454): the shared 600px board cap lifts, the fit rule sizes the board. */
  .board[data-fit-board] { max-width: none; }
  [data-input-game="noughts"] > :not(.board):not(dialog) { grid-column: 1; margin: 0; }
  :root[data-controls-side="left"] [data-input-game="noughts"] { grid-template-columns: calc(100dvh - 12px) minmax(160px, 1fr); }
  :root[data-controls-side="left"] [data-input-game="noughts"] > .board { grid-column: 1; }
  :root[data-controls-side="left"] [data-input-game="noughts"] > :not(.board):not(dialog) { grid-column: 2; }
  /* Landscape split: a game whose board is marked data-fit-landscape="split" shows its
     title, options and buttons in a column beside the board, so on a short landscape
     screen the board takes the whole height (shell/layout-fit.js computeSplitSide). */
  div:has(> .board[data-fit-landscape="split"]) {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: var(--space-xs) var(--space-md);
    align-items: start;
  }
  div:has(> .board[data-fit-landscape="split"]) > .board { grid-column: 1; grid-row: 1 / span 12; margin: 0; width: var(--board-side, 40vw); }
  div:has(> .board[data-fit-landscape="split"]) > :not(.board):not(dialog) { grid-column: 2; margin: 0; }
  /* #535 / #547: the side column never clips and never scrolls. The split is exactly one screen tall and its content
     (a result card, its buttons, the daily pill) is compacted until it fits (below). The "Next game in X" pill is the
     column's last row, in flow, so it can never sit over text or buttons: it takes the spare height at the bottom. */
  div:has(> .board[data-fit-landscape="split"]) {
    box-sizing: border-box;
    height: calc(100dvh - 12px);
    overflow: hidden;
    grid-template-rows: repeat(11, auto) 1fr;
    align-content: start;
  }
  div:has(> .board[data-fit-landscape="split"]) > .board { position: sticky; top: 0; align-self: start; }
  /* Compact first (#535): a finished game's side column drops the how-to-play hint and tightens its result card, so
     it fits a 360px-high screen before it ever has to scroll. */
  div:has(> .board[data-fit-landscape="split"]):has(> .game-result) > .word-search-hint { display: none; }
  div:has(> .board[data-fit-landscape="split"]) .game-result { padding: var(--space-xs) var(--space-sm); margin-bottom: 0; }
  div:has(> .board[data-fit-landscape="split"]) .game-result .btn,
  div:has(> .board[data-fit-landscape="split"]) .game-result .btn-block { min-height: var(--tap-min); font-size: var(--font-base, 1rem); margin-top: var(--space-xs); }
  div:has(> .board[data-fit-landscape="split"]) .game-result .share-result { margin-top: 0; }
  div:has(> .board[data-fit-landscape="split"]) .game-result .game-result-title { font-size: var(--font-base, 1rem); margin: 0; }
  /* A solved Word Search drops its crossed-out word list (every word is already highlighted on the grid), so the
     column fits without scrolling. */
  div:has(> .board[data-fit-landscape="split"]):has(> .game-result) > .word-search-word-list { display: none; }
  div:has(> .board[data-fit-landscape="split"]) > .daily-reset-pill { position: static; grid-row: 12; align-self: end; justify-self: end; max-width: 100%; }
  /* Which side (#534): when tapping the board is the input (Word Search, Memory Match, Minesweeper, Checkers) the board is
     on the RIGHT by default and the title/status/buttons on the left; a keyboard or pad in the column keeps the board left. */
  div:has(> .board[data-fit-landscape="split"][data-input-board]) { grid-template-columns: minmax(0, 1fr) max-content; }
  div:has(> .board[data-fit-landscape="split"][data-input-board]) > .board { grid-column: 2; }
  div:has(> .board[data-fit-landscape="split"][data-input-board]) > :not(.board):not(dialog) { grid-column: 1; }
  .sol-screen > .sol-board {
    width: 100%; height: var(--board-height, calc(100dvh - 100px)); aspect-ratio: auto;
    overflow-y: auto; overflow-x: hidden;
    /* #384: in landscape the table is a plain page-colour field, not a tinted panel, so the empty width reads as
       calm negative space. Piles keep their own contrast: slot outlines are --color-text-muted on it (4.5:1 or more)
       and card faces are white with a --color-card-suit-black edge. Clear and Clear Dark both hold it. */
    background: var(--color-bg);
  }
}
.noughts-cell.noughts-mark-x { color: var(--color-game-mark-x); }
.noughts-cell.noughts-mark-o { color: var(--color-game-mark-o); }
.noughts-mark-x[data-state="win"]::after { background: var(--color-game-mark-x); }
.noughts-mark-o[data-state="win"]::after { background: var(--color-game-mark-o); }

/* Checkers: the shared alternating board (tones, selected, target, last move, discs). State is
   never colour-only: the two sides differ in shape (a solid disc and a ringed disc), kings
   carry a crown, a piece that can move has a light ring, a landing square a dot, the
   selected piece a heavy ring, the last move a dashed ring. Red is not used. */
.checkers-sq-movable { box-shadow: inset 0 0 0 3px var(--color-bg); }

/* Move markers. A landing square lights up amber with a heavy border (never a small copy of a
   piece); data-step says what the move does: move = plain, jump = a cross (the piece
   it takes is ringed), chain = a cross and a double border (more jumps follow). The selected
   piece gets a double ring and a lifted disc, so selecting and putting it back are clear.
   Amber is the shared "present" colour; red is never used. */
.checkers-sq[data-state="target"] {
  background: var(--color-game-present);
  color: var(--color-game-on-present);
  box-shadow: inset 0 0 0 4px var(--color-game-present-ring);
}
.checkers-sq[data-state="target"][data-step="chain"] {
  box-shadow: inset 0 0 0 4px var(--color-game-present-ring), inset 0 0 0 8px var(--color-game-present), inset 0 0 0 11px var(--color-game-present-ring);
}
.checkers-sq[data-state="target"]::after {
  content: none;
  width: auto;
  aspect-ratio: auto;
  border-radius: 0;
  background: none;
  box-shadow: none;
  line-height: 1;
  font-weight: 800;
}
.checkers-sq[data-state="target"][data-step="jump"]::after,
.checkers-sq[data-state="target"][data-step="chain"]::after {
  content: "\0D7";
  position: absolute;
  font-size: 1.8em;
}
.checkers-sq .board-piece[data-jumped] {
  box-shadow: 0 0 0 4px var(--color-game-present), 0 0 0 7px var(--color-game-present-ring);
}
.checkers-sq[data-state="selected"] {
  background: var(--color-game-found-bg);
  box-shadow: inset 0 0 0 4px var(--color-text), inset 0 0 0 8px var(--color-game-found-bg), inset 0 0 0 11px var(--color-text);
}
.checkers-sq[data-state="selected"] .board-piece {
  transform: scale(1.1);
  box-shadow: 0 0 0 3px var(--color-text);
}

/* Minesweeper: the shared continuous board with its own cell look. State is never
   colour-only: hidden squares are raised (bevel, darker tone), dug squares are flat and
   show their count, flags are a glyph, the mine you hit gets a heavy ring, wrong flags a
   cross. Red (danger) marks only what was wrong: the mine hit, a wrong flag. */
.minesweeper-cell { font-size: clamp(0.8rem, calc(100cqw / var(--board-cols) * 0.6), 1.8rem); }
.minesweeper-hidden,
.minesweeper-flag {
  background: var(--color-game-board-dark);
  box-shadow: inset 3px 3px 0 var(--color-surface), inset -3px -3px 0 var(--color-text-muted);
}
.minesweeper-open { background: var(--color-surface); }
.minesweeper-flag { color: var(--color-text); }
.minesweeper-open[data-count="1"] { color: var(--color-game-mark-x); }
.minesweeper-open[data-count="2"] { color: var(--color-game-mark-o); }
.minesweeper-hit {
  background: var(--color-danger-bg);
  box-shadow: inset 0 0 0 4px var(--color-danger);
}
.minesweeper-wrongFlag {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}
/* Dig / Flag and New Game share one row so the board keeps the height: the mode bar's
   buttons sit directly in the options row. */
.game-options-inline { display: contents; }
/* Many options: two columns, as many rows as needed (Memory Match themes). */
.game-options-wrap { grid-auto-flow: row; grid-template-columns: repeat(2, 1fr); }


/* ---- Cat-astrophe (docs/CATASTROPHE_DESIGN.md "Look") ----
   A shelf unit: 7 column buttons, each a stack of 7 cells drawn bottom up, with a
   shelf line under every cell. Items are round tokens (art behind, number in
   front); boxes are square and show [=] or [-]. The paw and the peeking cat sit
   in .catastrophe-board-wrap, which clips them so nothing scrolls sideways. */
/* The shelf colour changes each level: walnut, teal, plum, olive, then round again
   (data-shelf is set by catastrophe-ui.js). */
.catastrophe { --catastrophe-shelf: var(--color-game-shelf); }
.catastrophe[data-shelf="teal"] { --catastrophe-shelf: var(--color-game-shelf-teal); }
.catastrophe[data-shelf="plum"] { --catastrophe-shelf: var(--color-game-shelf-plum); }
.catastrophe[data-shelf="olive"] { --catastrophe-shelf: var(--color-game-shelf-olive); }
.catastrophe-status {
  font-size: var(--font-base);
  margin: 0 0 var(--space-sm);
}
.catastrophe-line { display: block; font-weight: 700; }
.catastrophe-news {
  display: block;
  font-size: var(--font-sm);
  line-height: 1.35;
  /* Exactly two lines, always: a longer message is clipped, never grows, so the board below never moves. */
  height: 2.7em;
  overflow: hidden;
}
.catastrophe-hand {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
  /* Tall enough for the catnip picker (its numbers wrap to two rows on a phone), so the board does not move
     when it opens (see the Cat-astrophe layout check). */
  min-height: 6.6rem;
  align-content: center;
}
.catastrophe-hand-label {
  font-size: var(--font-sm);
  color: var(--color-text-muted);
}
/* The power-ups: three icon buttons with their counts (catnip, furball, yarn). */
.catastrophe-powers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}
/* Empty rows that keep the room of the hand and the power-ups when the game is over. */
.catastrophe-spacer { visibility: hidden; }
.catastrophe-powers.catastrophe-spacer { min-height: var(--tap-min); }
.catastrophe-power {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding-left: 6px;
  padding-right: 6px;
  /* On a narrow button (most phones, and larger phone font sizes) the Yarn pips
     move under the count instead of sticking out of the button. */
  flex-wrap: wrap;
  row-gap: 3px;
  container-type: inline-size;
  /* A power-up is held in the thumb zone but does not need a 56px box (#438): 48px is the touch target. */
  min-height: var(--tap-min);
  padding-top: 2px;
  padding-bottom: 2px;
}
@container (max-width: 7.5em) {
  .catastrophe-pips {
    flex-basis: 100%;
    justify-content: center;
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }
}
.catastrophe-power[aria-pressed="true"] {
  background: var(--color-accent);
  color: var(--color-on-accent);
}
.catastrophe-power-icon { width: 1.6em; height: 1.6em; display: inline-block; flex: none; }
.catastrophe-power-icon svg,
.catastrophe-power-icon img { width: 100%; height: 100%; display: block; }
.catastrophe-pips {
  display: inline-flex;
  gap: 3px;
  margin-left: 4px;
  padding-left: 7px;
  border-left: 1px solid currentColor;
}
.catastrophe-pip {
  width: 7px;
  height: 7px;
  border: 1.5px solid currentColor;
  border-radius: 1px;
}
.catastrophe-pip-on { background: currentColor; }
/* Yarn: a button per row over the board (row 0 at the bottom), lined up with
   the shelf rows (the board's 2px border + 4px padding). */
.catastrophe-rows {
  position: absolute;
  inset: 6px;
  display: flex;
  flex-direction: column-reverse;
  z-index: 3;
}
.catastrophe-row {
  flex: 1;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}
.catastrophe-row:not(:disabled) { outline: 2px dashed var(--color-text); outline-offset: -3px; }
.catastrophe-row:not(:disabled):hover,
.catastrophe-row:focus-visible { outline-style: solid; outline-width: 3px; }
.catastrophe-row:disabled { cursor: default; }
/* The furball landing on the shelf, and its burst. */
.catastrophe-furball {
  width: 88%;
  height: 88%;
  color: var(--color-text);
  display: block;
}
.catastrophe-furball svg,
.catastrophe-furball img { width: 100%; height: 100%; display: block; }
.catastrophe-poof { animation: catastrophe-poof 400ms ease-out forwards; }
@keyframes catastrophe-poof {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5) rotate(25deg); opacity: 0.8; }
  100% { transform: scale(2) rotate(60deg); opacity: 0; }
}
/* The yarn ball rolling along the chosen row. */
.catastrophe-yarn-roll {
  position: absolute;
  width: 13%;
  color: var(--color-text);
  bottom: calc((var(--yarn-row) + 0.5) / 7 * 100% - 6.5%);
  left: -14%;
  pointer-events: none;
  z-index: 2;
  animation: catastrophe-yarn-roll 700ms ease-in-out forwards;
}
.catastrophe-yarn-roll svg,
.catastrophe-yarn-roll img { width: 100%; display: block; }
@keyframes catastrophe-yarn-roll {
  from { transform: translateX(0) rotate(0); }
  to { transform: translateX(860%) rotate(720deg); }
}
.catastrophe-pick { min-width: 48px; }
.catastrophe-board-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 600px;
  margin: 0 auto var(--space-md);
}
.catastrophe-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  background: var(--color-surface);
  border: 2px solid var(--catastrophe-shelf);
  border-radius: 8px;
  padding: 4px;
}
.catastrophe-col {
  display: flex;
  flex-direction: column-reverse; /* row 0 at the bottom */
  gap: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--color-text);
  cursor: pointer;
  min-width: 0;
}
.catastrophe-col:focus-visible {
  outline: 3px solid var(--color-text);
  outline-offset: 2px;
}
/* Full (or game over): the contents stay fully readable; only the pointer changes. */
.catastrophe-col:disabled { cursor: default; }
.catastrophe-cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 3px solid var(--catastrophe-shelf);
}
.catastrophe-item {
  position: relative;
  width: 88%;
  height: 88%;
  border-radius: 50%;
  background: var(--item-fill, var(--color-surface));
  border: 2px solid var(--color-text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.catastrophe-item-art {
  position: absolute;
  inset: 4%;
  color: var(--color-text);
}
.catastrophe-item-art svg { width: 100%; height: 100%; display: block; }
/* The whole token takes its item's colour, and the drawing is a lighter
   silhouette on it. The number stays the signal. */
.catastrophe-item-art .f { fill: var(--color-surface); fill-opacity: 0.6; }
.catastrophe-item[data-n="1"] { --item-fill: var(--color-game-item-mug); }
.catastrophe-item[data-n="2"] { --item-fill: var(--color-game-item-jar); }
.catastrophe-item[data-n="3"] { --item-fill: var(--color-game-item-plant); }
.catastrophe-item[data-n="4"] { --item-fill: var(--color-game-item-glass); }
.catastrophe-item[data-n="5"] { --item-fill: var(--color-game-item-book); }
.catastrophe-item[data-n="6"] { --item-fill: var(--color-game-item-vase); }
.catastrophe-item[data-n="7"] { --item-fill: var(--color-game-item-fishbowl); }
.catastrophe-item-num {
  position: relative;
  /* A halo in the item's colour keeps the number clear of the drawing's lines
     (--color-text on every item colour is 4.5:1, see theme-contrast.test). */
  text-shadow:
    -2px 0 var(--item-fill), 2px 0 var(--item-fill),
    0 -2px var(--item-fill), 0 2px var(--item-fill),
    -1.5px -1.5px var(--item-fill), 1.5px 1.5px var(--item-fill),
    -1.5px 1.5px var(--item-fill), 1.5px -1.5px var(--item-fill);
  /* ~65% of the token: column width = (content width - 6 gaps - padding) / 7. */
  font-size: clamp(1.1rem, calc((min(100vw - 32px, 600px) - 36px) / 7 * 0.55), 2.2rem);
  font-weight: 800;
  line-height: 1;
}
.catastrophe-held { width: 56px; height: 56px; }
.catastrophe-held .catastrophe-item-num { font-size: 1.8rem; }
.catastrophe-next { width: 36px; height: 36px; }
.catastrophe-next .catastrophe-item-num { font-size: 1.1rem; }
/* A taped box in the hand (#50): the box art, centred in the item's space. */
.catastrophe-hand-box { display: flex; align-items: center; justify-content: center; }
.catastrophe-box {
  width: 94%;
  height: 94%;
  color: var(--color-game-on-box); /* outline, tape strips and paw stamp */
  display: block;
}
.catastrophe-box svg,
.catastrophe-box img { width: 100%; height: 100%; display: block; }
.catastrophe-box .f { fill: var(--color-game-box); }
.catastrophe-box .t { fill: currentColor; stroke: none; }

/* ---- animation (skipped by a tap; see catastrophe-ui.js) ---- */
.catastrophe-dropped { animation: catastrophe-drop 300ms ease-in; }
@keyframes catastrophe-drop {
  from { transform: translateY(-300%); }
  to { transform: translateY(0); }
}
.catastrophe-swat { animation: catastrophe-swat 400ms ease-in forwards; }
@keyframes catastrophe-swat {
  0% { transform: none; }
  30% { transform: rotate(-12deg); }
  100% { transform: translateX(var(--swat-x, 160%)) rotate(70deg); opacity: 0; }
}
.catastrophe-paw {
  position: absolute;
  width: 22%;
  color: var(--color-text);
  /* Row r's middle, measured from the bottom of the board. */
  bottom: calc((var(--paw-row) + 0.5) / 7 * 100% - 11%);
  pointer-events: none;
}
.catastrophe-paw svg,
.catastrophe-paw img { width: 100%; display: block; }
.catastrophe-paw-left { left: 0; animation: catastrophe-paw-left 400ms ease-out; transform: rotate(90deg); }
.catastrophe-paw-right { right: 0; animation: catastrophe-paw-right 400ms ease-out; transform: rotate(-90deg); }
@keyframes catastrophe-paw-left {
  from { transform: translateX(-120%) rotate(90deg); }
  60% { transform: translateX(10%) rotate(90deg); }
  to { transform: rotate(90deg); }
}
@keyframes catastrophe-paw-right {
  from { transform: translateX(120%) rotate(-90deg); }
  60% { transform: translateX(-10%) rotate(-90deg); }
  to { transform: rotate(-90deg); }
}
/* The artist's paws are drawn already pointing right, arm on the left: no turn for the
   left side, a mirror for the right. (The SVG paw points up and is turned above.) */
.catastrophe-paw-art { width: 30%; bottom: calc((var(--paw-row) + 0.5) / 7 * 100% - 15%); }
.catastrophe-paw-art.catastrophe-paw-left { transform: none; animation-name: catastrophe-paw-art-left; }
.catastrophe-paw-art.catastrophe-paw-right { transform: scaleX(-1); animation-name: catastrophe-paw-art-right; }
/* The tuxedo's black arm would vanish on the dark board: a light edge round every paw there. */
:root[data-theme="dark"] .catastrophe-paw-art img,
:root[data-theme="dark"] .catastrophe-intro-paw-art img { filter: drop-shadow(0 0 1.5px var(--color-text)); }
@keyframes catastrophe-paw-art-left {
  from { transform: translateX(-120%); }
  60% { transform: translateX(10%); }
  to { transform: none; }
}
@keyframes catastrophe-paw-art-right {
  from { transform: translateX(120%) scaleX(-1); }
  60% { transform: translateX(-10%) scaleX(-1); }
  to { transform: scaleX(-1); }
}
.catastrophe-peek {
  position: absolute;
  top: 0;
  right: 0;
  width: 30%;
  color: var(--color-text);
  background: var(--color-surface);
  border: 2px solid var(--color-text);
  border-radius: 12px;
  padding: 4px;
  text-align: center;
  pointer-events: none;
}
.catastrophe-peek-chain { animation: catastrophe-peek 700ms ease-out; }
.catastrophe-peek svg,
.catastrophe-peek img { width: 70%; display: block; margin: 0 auto; }
.catastrophe-peek-badge { font-weight: 800; font-size: var(--font-sm); }
/* The small cards in the hand row (#453): the tougher-box warning and the chain cat, beside Holding and
   Next, the same height as the hand boxes, so the board does not move or get covered. The art keeps its
   shape (contain) at the small size; the chain card takes this place while it plays. */
.catastrophe-hand > .catastrophe-peek {
  position: static; width: auto; margin-left: auto; display: flex; flex-direction: row; align-items: center;
  gap: 4px; padding: 2px 6px; border-radius: 10px;
}
.catastrophe-hand > .catastrophe-peek img,
.catastrophe-hand > .catastrophe-peek svg { width: 36px; height: 36px; margin: 0; object-fit: contain; }
.catastrophe-hand > .catastrophe-peek .catastrophe-peek-badge { font-size: 12px; line-height: 16px; white-space: nowrap; }
@keyframes catastrophe-peek {
  from { transform: translateY(-110%); }
  30% { transform: translateY(0); }
}
.catastrophe-rising .catastrophe-board { animation: catastrophe-rise 400ms ease-out; }
/* Beat 1 of a knock-off round: what is about to go, and what it scores. */
.catastrophe-marked {
  outline: 3px solid var(--color-text);
  outline-offset: 1px;
  animation: catastrophe-mark 550ms ease-in-out;
}
@keyframes catastrophe-mark {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.12); }
}
.catastrophe-points {
  position: absolute;
  top: -0.9em;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 4px;
  border-radius: 8px;
  background: var(--color-text);
  color: var(--color-surface);
  font-size: var(--font-sm);
  font-weight: 800;
  line-height: 1.3;
  white-space: nowrap;
  z-index: 1;
}
.catastrophe-hit { animation: catastrophe-hit 550ms ease-in-out; }
@keyframes catastrophe-hit {
  0%, 100% { transform: none; }
  25% { transform: rotate(-8deg); }
  75% { transform: rotate(8deg); }
}
/* Beat 3: blocks drop from where they were (--fall-rows cells higher). */
.catastrophe-fall { animation: catastrophe-fall 300ms ease-in; }
@keyframes catastrophe-fall {
  from { transform: translateY(calc(var(--fall-rows) * -114%)); }
  to { transform: none; }
}
/* The round counter, top left of the board while a chain plays. */
.catastrophe-knock {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--color-text);
  color: var(--color-surface);
  font-weight: 800;
  font-size: var(--font-base);
  pointer-events: none;
  z-index: 2;
}
.catastrophe-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}
@keyframes catastrophe-rise {
  from { transform: translateY(14%); }
  to { transform: none; }
}
/* Game over: a card over the board (the board shows faintly behind it). */
.catastrophe-over {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: var(--space-md);
  text-align: center;
  color: var(--color-text);
  background: color-mix(in srgb, var(--color-surface) 90%, transparent);
  border-radius: 8px;
  overflow-y: auto;
}
.catastrophe-over h3 {
  margin: 0;
  font-size: clamp(2rem, 10vw, 3.4rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
}
.catastrophe-over p { margin: 0; font-size: var(--font-sm); }
.catastrophe-over .btn { width: var(--btn-w); max-width: 100%; margin-top: var(--space-sm); } /* the standard button width */
.catastrophe-over .catastrophe-finish-actions { width: 100%; flex-wrap: wrap; gap: var(--space-xs); }
.catastrophe-over .catastrophe-finish-actions > .btn,
.catastrophe-over .catastrophe-finish-actions > .share-result > .btn { flex: 1 1 calc(50% - 2px); width: auto; margin: 0; }
/* Landscape (#152 / #394): the board is only as tall as the screen, so the card sizes its picture and title by the screen height and fits without scrolling. */
@media (orientation: landscape) {
  .catastrophe-over { padding: var(--space-sm); gap: 2px; }
  .catastrophe-over h3 { font-size: clamp(1.4rem, 9dvh, 2.6rem); }
  .catastrophe-over .btn { margin-top: 4px; }
  .catastrophe-over .catastrophe-shock { width: min(34%, 15dvh); }
  .catastrophe-over .catastrophe-shock-art { width: min(44%, 20dvh); }
}
.catastrophe-shock {
  width: min(34%, 150px);
  color: var(--color-text);
  animation: catastrophe-shock 700ms ease-out;
}
.catastrophe-shock-art { width: min(44%, 190px); } /* the artist's head is cropped to the face, so wider than the square drawing */
.catastrophe-shock svg,
.catastrophe-shock img { width: 100%; display: block; }
.catastrophe-shock .f,
.catastrophe-shock .e { fill: var(--color-surface); }
/* It jumps up in fright, then trembles. */
@keyframes catastrophe-shock {
  0% { transform: translateY(40%) scale(0.6); opacity: 0; }
  35% { transform: translateY(-12%) scale(1.15); opacity: 1; }
  50% { transform: rotate(-6deg); }
  60% { transform: rotate(6deg); }
  70% { transform: rotate(-4deg); }
  80% { transform: rotate(3deg); }
  100% { transform: none; }
}
.catastrophe-new-best { font-weight: 800; }
.catastrophe-confirm {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
}
.catastrophe-confirm p { width: 100%; margin: 0; }

/* Reduce Motion: no paw, no slides. Cleared items fade; the peek is a static
   badge; the marks and points still show. catastrophe-ui.js decides (the device
   setting, or the tester's force-full-motion switch) and sets the class. */
.catastrophe-reduced .catastrophe-paw,
.catastrophe-reduced .catastrophe-yarn-roll { display: none; }
.catastrophe-reduced .catastrophe-poof { animation: catastrophe-fade 240ms linear forwards; }
.catastrophe-reduced .catastrophe-dropped,
.catastrophe-reduced.catastrophe-rising .catastrophe-board,
.catastrophe-reduced .catastrophe-marked,
.catastrophe-reduced .catastrophe-hit,
.catastrophe-reduced .catastrophe-fall,
.catastrophe-reduced .catastrophe-peek-chain,
.catastrophe-reduced .catastrophe-shock { animation: none; }
.catastrophe-reduced .catastrophe-swat { animation: catastrophe-fade 240ms linear forwards; }
@keyframes catastrophe-fade { to { opacity: 0; } }

/* ---- Cat-astrophe intro (docs/CATASTROPHE_DESIGN.md "Intro") ----
   Timings come from logic.introTimeline via --intro-<phase>-at / -ms. */
.catastrophe-intro {
  position: relative;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  overflow: hidden;
  background: var(--color-bg);
  cursor: pointer;
  animation: catastrophe-intro-out var(--intro-shelf-ms) ease-in var(--intro-shelf-at) forwards;
}
.catastrophe-intro-stage {
  position: relative;
  width: min(80vw, 320px);
  aspect-ratio: 1 / 1;
  overflow: hidden; /* the cat rises from the stage's bottom edge */
}
/* Leave room for the title, gap and surrounding shell on short landscape screens. */
@media (orientation: landscape) {
  .catastrophe-intro-stage { width: min(80vw, 320px, max(0px, calc(100dvh - 136px))); }
}
.catastrophe-intro-stage svg,
.catastrophe-intro-stage img { width: 100%; height: 100%; display: block; }
.catastrophe-intro-shelf {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 40%;
  border-bottom: 6px solid var(--color-game-shelf);
}
.catastrophe-intro-cat {
  position: absolute;
  left: 20%;
  bottom: 0;
  width: 60%;
  color: var(--color-text);
  transform: translateY(110%);
  animation: catastrophe-intro-peek var(--intro-peek-ms) ease-out var(--intro-peek-at) forwards;
}
/* The artist's head is cropped to the face (wider than tall) and a little bigger than the drawn one. */
.catastrophe-intro-cat-art { left: 15%; width: 70%; }
.catastrophe-intro-stage .catastrophe-intro-cat-art img { height: auto; }
.catastrophe-intro-mug {
  position: absolute;
  left: 58%;
  top: 16%;
  width: 24%;
  color: var(--color-text);
  transform-origin: 50% 100%;
  animation:
    catastrophe-intro-wobble var(--intro-wobble-ms) ease-in-out var(--intro-wobble-at),
    catastrophe-intro-knock var(--intro-swipe-ms) ease-in calc(var(--intro-swipe-at) + var(--intro-swipe-ms) * 0.6) forwards;
}
/* The line-drawn SVG mug sits on a round paper patch; the artist's PNG is transparent. */
.catastrophe-intro-mug svg { background: var(--color-paper); border-radius: 50%; }
.catastrophe-intro-paw {
  position: absolute;
  left: 0;
  top: 12%;
  width: 34%;
  color: var(--color-text);
  transform: translateX(-140%) rotate(90deg);
  animation: catastrophe-intro-swipe var(--intro-swipe-ms) ease-out var(--intro-swipe-at) forwards;
}
.catastrophe-intro-title {
  margin: 0;
  font-size: var(--font-lg);
  font-weight: 800;
  opacity: 0;
  animation: catastrophe-intro-title var(--intro-title-ms) ease-out var(--intro-title-at) forwards;
}
.catastrophe-intro-skip { position: absolute; right: var(--space-md); bottom: var(--space-md); }
@keyframes catastrophe-intro-peek { to { transform: translateY(0); } }
@keyframes catastrophe-intro-wobble {
  25% { transform: rotate(-8deg); }
  75% { transform: rotate(8deg); }
}
@keyframes catastrophe-intro-swipe {
  60% { transform: translateX(80%) rotate(90deg); }
  to { transform: translateX(40%) rotate(90deg); }
}
@keyframes catastrophe-intro-knock {
  30% { transform: rotate(-15deg); }
  to { transform: translate(120%, 160%) rotate(120deg); opacity: 0; }
}
/* The artist's paw already points right (the SVG one points up and is turned above).
   Its arm is long, so it stays on the stage's left edge while the paw reaches the mug (moved
   closer to the left for this paw), and the paw pulls back out after. */
.catastrophe-intro-stage-art .catastrophe-intro-mug { left: 38%; }
.catastrophe-intro-paw-art { width: 44%; top: 3%; transform: translateX(-100%); animation-name: catastrophe-intro-swipe-art; }
@keyframes catastrophe-intro-swipe-art {
  60% { transform: translateX(30%); }
  to { transform: translateX(-100%); }
}
@keyframes catastrophe-intro-title {
  from { transform: translateY(-40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes catastrophe-intro-out { to { transform: translateY(-100%); opacity: 0; } }

/* Reduce Motion: nothing slides. The cat, mug and title fade in together. */
.catastrophe-intro-reduced,
.catastrophe-intro-reduced .catastrophe-intro-cat,
.catastrophe-intro-reduced .catastrophe-intro-mug,
.catastrophe-intro-reduced .catastrophe-intro-paw,
.catastrophe-intro-reduced .catastrophe-intro-title { animation: none; }
.catastrophe-intro-reduced .catastrophe-intro-cat { transform: none; }
.catastrophe-intro-reduced .catastrophe-intro-paw { display: none; }
.catastrophe-intro-reduced .catastrophe-intro-stage,
.catastrophe-intro-reduced .catastrophe-intro-title {
  opacity: 1;
  animation: catastrophe-intro-fade var(--intro-fade-ms) linear var(--intro-fade-at) both;
}
@keyframes catastrophe-intro-fade { from { opacity: 0; } }

/* Mystery (puzzle mystery case file). Tokens only; red is never used here
   because red means wrong. State is always also a word ("Solved ✓", "Next",
   "Locked") and a border style, never colour alone. */
.mystery-kicker {
  color: var(--color-text-muted);
  font-size: var(--font-sm);
  text-align: center;
  margin: 0;
}
.mystery-intro p,
.mystery-story,
.mystery-reveal-text p {
  margin: 0 0 var(--space-sm);
}
.mystery-story {
  font-size: var(--font-base);
}
/* Longer text wraps (owner decision, #64); it never shrinks below the base size. */
.mystery-card-title,
.mystery-card-note,
.mystery-story,
.mystery-reveal-title,
.mystery-letter-found,
.mystery-art-idea,
.mystery-art-soon,
.mystery-kicker,
.mystery-card .btn,
.mystery-god-btn {
  overflow-wrap: anywhere;
}
.mystery-slots {
  display: flex;
  flex-wrap: wrap; /* a long secret word wraps to a second row rather than running off the screen */
  justify-content: center;
  gap: var(--space-sm);
  margin: var(--space-md) 0 var(--space-sm);
}
.mystery-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 52px;
  min-width: 36px;
  height: 60px;
  border: 2px dashed var(--color-text-muted);
  border-radius: 8px;
  color: var(--color-text-muted);
  font-size: var(--font-lg);
  font-weight: 700;
}
.mystery-slot[data-filled="true"] {
  border-style: solid;
  border-color: var(--color-text);
  background: var(--color-surface);
  color: var(--color-text);
}
.mystery-status {
  margin: 0 0 var(--space-md);
}
.mystery-letter-found {
  font-size: var(--font-lg);
  font-weight: 700;
  text-align: center;
  margin: var(--space-md) 0 0;
}
.mystery-card {
  border-width: 2px;
  scroll-margin-top: var(--space-md); /* the open card lands just below the top edge, not flush */
}
.mystery-card[data-state="open"] {
  border-color: var(--color-accent);
}
.mystery-card[data-state="solved"] {
  border-color: var(--color-text);
}
.mystery-card[data-state="locked"] {
  border-style: dashed;
  border-color: var(--color-text-muted);
  color: var(--color-text-muted);
}
.mystery-card-head {
  display: flex;
  flex-wrap: wrap; /* longer translated labels drop to a second line, never clip */
  justify-content: space-between;
  gap: var(--space-sm);
  margin: 0 0 var(--space-xs);
  color: var(--color-text-muted);
  font-size: var(--font-sm);
}
.mystery-card-state {
  color: var(--color-text);
}
.mystery-card[data-state="locked"] .mystery-card-state {
  color: var(--color-text-muted);
}
.mystery-card-title {
  margin: 0 0 var(--space-xs);
  font-size: var(--font-base);
}
.mystery-card-note {
  margin: 0 0 var(--space-sm);
}
.mystery-reveal {
  text-align: center;
  border: 3px double var(--color-text);
}
.mystery-reveal-title {
  margin: 0 0 var(--space-sm);
  font-size: var(--font-lg);
  letter-spacing: 0.2em;
}
.mystery-art {
  margin: 0 0 var(--space-md);
  padding: var(--space-sm);
  background: var(--color-paper);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
}
.mystery-art img {
  display: block;
  width: 100%;
  height: auto; /* the width/height attributes still reserve the right shape */
}
.mystery-art-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  box-sizing: border-box;
  text-align: center;
  color: var(--color-on-paper); /* text on the white paper card, dark in every theme */
  border-style: dashed;
}
.mystery-art-soon {
  margin: 0;
  font-weight: 700;
}
.mystery-art-idea {
  margin: 0;
  font-size: var(--font-sm);
}
.mystery-card .mystery-art {
  max-width: 28rem;
  margin: 0 auto var(--space-sm);
}
.mystery-reveal .mystery-art {
  max-width: 16rem;
  margin: 0 auto var(--space-md);
}
.mystery-play {
  position: relative; /* the light sweep is placed inside it */
  min-height: 1px;
}

/* The letter reveal (addons/games/mystery-reveal.js). Gold is --color-highlight, never
   red. The letter's tile keeps the normal text colour on the normal surface. */
:root {
  --mystery-sheen: rgba(255, 255, 255, 0.9);
}
:root[data-theme="dark"],
:root[data-theme="classic"],
:root[data-theme="soft"],
:root[data-theme="playful"] {
  --mystery-sheen: rgba(255, 255, 255, 0.55);
}
/* the game's own Back button is replaced by ours, which arrives with the story */
.mystery-revealing [data-action="back-to-case-file"] {
  display: none;
}
.mystery-revealing .mystery-after [data-action="back-to-case-file"] {
  display: block;
}
.mystery-secret {
  margin: var(--space-md) 0;
  padding: var(--space-sm);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  text-align: center;
  transition: border-color 0.4s;
}
.mystery-secret-on {
  border-style: solid;
  border-color: var(--color-text);
}
.mystery-secret-label {
  display: block;
  color: var(--color-text-muted);
  font-size: var(--font-sm);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.mystery-secret .mystery-slots {
  margin: var(--space-xs) 0 0;
}
.mystery-secret .mystery-letter-found {
  margin: var(--space-sm) 0 0;
  font-size: var(--font-base);
  min-height: 1.4em; /* the line's space is reserved before the letter is found */
}
.mystery-skip-row {
  margin: 0 0 var(--space-sm);
}
.mystery-skip-row .btn {
  min-height: var(--btn-h);
}
.mystery-after {
  margin-top: var(--space-sm);
}
/* while the letter travels, every cell but its source steps back */
.mystery-grid-fx > * {
  transition: opacity 0.45s;
}
.mystery-grid-dim > *:not([data-letter-cell]) {
  opacity: 0.25;
}
[data-letter-cell] {
  position: relative;
  z-index: 2;
}
.mystery-glow {
  animation: mystery-glow calc(0.45s * var(--mystery-speed, 1)) ease-in-out 2;
}
@keyframes mystery-glow {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 22px 7px var(--color-highlight), 0 0 0 3px var(--color-highlight); }
}
.mystery-shimmer {
  position: relative;
  overflow: hidden;
}
.mystery-shimmer::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, var(--mystery-sheen) 50%, transparent 65%);
  transform: translateX(-130%);
  animation: mystery-band calc(0.9s * var(--mystery-speed, 1)) ease-in-out 1 forwards;
}
@keyframes mystery-band {
  to { transform: translateX(130%); }
}
/* the cell the letter was lifted from: an empty hole */
.mystery-taken {
  color: transparent !important;
  background: var(--color-surface-alt) !important;
  outline: 2px dashed var(--color-text-muted);
  outline-offset: -4px;
}
.mystery-circled {
  box-shadow: inset 0 0 0 3px var(--color-highlight);
  border-radius: 50%;
}
.mystery-source {
  box-shadow: inset 0 0 0 3px var(--color-accent);
}
.mystery-pad {
  animation: mystery-padpulse calc(0.7s * var(--mystery-speed, 1)) ease-in-out infinite;
  border-color: var(--color-highlight);
}
@keyframes mystery-padpulse {
  50% { box-shadow: 0 0 0 6px transparent, 0 0 14px 2px var(--color-highlight); }
}
/* One fixed layer over the whole page: the flying letter, sparkles and rings play here,
   so they are visible wherever the page is scrolled. */
.mystery-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  overflow: hidden;
  pointer-events: none;
}
/* the secret word (and, on the last letter, the reveal card) lights up as the letter nears */
.mystery-secret-glow,
.mystery-card-glow {
  border-color: var(--color-highlight);
  box-shadow: 0 0 18px 4px var(--color-highlight), 0 0 0 3px var(--color-highlight);
}
.mystery-secret-pulse,
.mystery-pulse {
  animation: mystery-near calc(0.5s * var(--mystery-speed, 1)) ease-in-out 3;
}
@keyframes mystery-near {
  50% { box-shadow: 0 0 30px 10px var(--color-highlight), 0 0 0 3px var(--color-highlight); }
}
/* the flying copy of the letter */
.mystery-fly {
  position: absolute;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid var(--color-text);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 800;
  transform-origin: center;
  will-change: transform;
  pointer-events: none;
}
.mystery-sparkle {
  position: absolute;
  z-index: 25;
  pointer-events: none;
  background: var(--color-highlight);
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.mystery-ring {
  position: absolute;
  z-index: 5;
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-highlight);
  border-radius: 50%;
  pointer-events: none;
}
.mystery-sweep {
  position: absolute;
  z-index: 6;
  overflow: hidden;
  pointer-events: none;
  border-radius: 6px;
}
.mystery-sweep b {
  position: absolute;
  top: -10%;
  bottom: -10%;
  left: 0;
  width: 34%;
  opacity: 0;
  transform: translateX(-130%);
  background: linear-gradient(105deg, transparent, var(--mystery-sheen), transparent);
}

/* Tester controls in the Mystery screens (god mode only). */
.mystery-god-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
  padding: var(--space-sm);
  border: 1px dashed var(--color-warning);
  border-radius: var(--radius);
}
.mystery-god-label { font-size: var(--font-sm); color: var(--color-text-muted); }
.mystery-god-heading { margin: 0 0 var(--space-sm); font-weight: 700; text-transform: uppercase; color: var(--color-text); }
.mystery-god-row .mystery-god-btn { flex: 1 1 120px; width: auto; }
/* Cheat prev/next inside a puzzle or story: solid warning border, unlike the dashed rows. */
.mystery-god-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
  padding: var(--space-sm);
  border: 3px solid var(--color-warning);
  border-radius: var(--radius);
  background: var(--color-surface-alt);
}
.mystery-god-nav .mystery-god-label { font-weight: 700; text-transform: uppercase; color: var(--color-text); }
.mystery-god-nav .mystery-god-btn { flex: 1 1 120px; width: auto; border: 2px solid var(--color-warning); }

/* ---- Fit-to-screen boards (shell/layout-fit.js) ----
   A board marked data-fit-board gets --board-side (px) from the shell so the
   board and the keyboard/keypad under it fit the visible height. Digits and
   marks scale with the board, not the viewport width. */
[data-fit-board] {
  width: min(100%, var(--board-side, 600px));
  margin-left: auto;
  margin-right: auto;
  container-type: inline-size;
}
.board[data-puzzle=sudoku] .sudoku-cell { font-size: clamp(1rem, 6.4cqw, 2.4rem); }

/* ---- WoW: Web of Words ----
   Board of crossing word squares, the current word, the letter wheel (letters
   are real buttons over an SVG for the ring and the drag line), then Shuffle and
   Hint. The board gives way to the wheel on short phones (shell/layout-fit.js).
   Filled = solid navy with the letter; hint = amber with a ring; empty = an
   outlined square, so state is never colour alone. Red is only the "not a word" text. */
.wow-board {
  display: grid;
  grid-template-columns: repeat(var(--wow-cols, 5), 1fr);
  grid-template-rows: repeat(var(--wow-rows, 5), 1fr);
  aspect-ratio: var(--wow-cols, 5) / var(--wow-rows, 5);
  gap: 3px;
  margin-bottom: var(--space-xs);
}
.wow-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
  border: 2px solid var(--color-text-muted);
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: clamp(0.7rem, calc(52cqw / var(--wow-cols, 5)), 1.9rem);
  font-weight: 800;
  line-height: 1;
}
.wow-cell-found {
  background: var(--color-game-correct);
  border-color: var(--color-game-correct);
  color: var(--color-game-on-correct);
}
.wow-cell-hint {
  background: var(--color-game-present);
  border-color: var(--color-game-present-ring);
  box-shadow: inset 0 0 0 2px var(--color-game-present-ring);
  color: var(--color-game-on-present);
}
.wow-pop { animation: wow-pop 260ms ease-out; }
@keyframes wow-pop {
  0% { transform: scale(0.6); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.wow-entry {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin: var(--space-xs) 0;
}
.wow-entry .btn {
  flex: 0 0 auto;
  min-width: 76px;
  min-height: var(--tap-min);
  padding: 4px 8px;
  font-size: var(--font-base);
}
.wow-entry .btn[aria-disabled="true"],
[data-row="actions"] .btn[aria-disabled="true"] { opacity: 0.55; }
.wow-word {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 3px solid var(--color-text-muted);
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--color-text);
}
.wow-word-empty::before { content: "\2026"; color: var(--color-text-muted); }
.wow-word-flash {
  font-size: 1rem;
  letter-spacing: 0;
  line-height: 1.15;
  text-align: center;
}
/* Only "not a word" is red, and it also has a cross and, in Reduce Motion, an outline, so it is not colour alone. */
.wow-word-wrong { color: var(--color-danger); }
.wow-word-wrong::before { content: "\2717\00a0"; }
.wow-shake { animation: wow-shake 340ms linear; }
@keyframes wow-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
/* #529: the tick and backspace sit in the lower corners but clear of the round pad (never touching it).
   A 48px button tucked into a corner of the wheel's square clears the circle (radius R = W/2) by a gap
   when it is pushed out by G = 92px - 0.49 x R (the 0.245 x W below); a smaller wheel needs a bigger push,
   so the wheel is sized to leave room for both buttons: W + 2 x G fits the width (the second min() term).
   ribbon-smoke measures the real boxes against the circle at every size. */
.wow-wheel {
  --wow-corner: 48px;
  --wow-corner-out: calc(92px - 24.5cqw);
  container-type: inline-size;
  position: relative;
  width: min(100%, 300px, 34vh, calc((100% - 184px) / 0.51));
  aspect-ratio: 1 / 1;
  margin: 0 auto var(--space-xs);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
@supports (height: 1dvh) {
  .wow-wheel { width: min(100%, 300px, 34dvh, calc((100% - 184px) / 0.51)); }
}
/* Short portrait phones (360x640): the wheel gives the board the height it needs to stay readable (150 px or more,
   smoke-test layout fit). 30dvh still fits 48px letters. */
@media (max-height: 700px) and (orientation: portrait) {
  .wow-wheel { width: min(100%, 300px, 30dvh, calc((100% - 184px) / 0.51)); }
}
.wow-wheel { position: relative; }
/* The middle of the wheel is Shuffle (#496); the tick (submit) and backspace sit in the lower corners. */
.wow-wheel .wow-shuffle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 30%;
  min-width: var(--tap-min);
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  z-index: 2;
}
.wow-wheel .wow-corner {
  position: absolute;
  bottom: 0;
  width: var(--wow-corner);
  height: var(--wow-corner);
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  padding: 0;
  border-radius: 50%;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.wow-wheel .wow-submit { right: calc(-1 * var(--wow-corner-out)); }
.wow-wheel .wow-back { left: calc(-1 * var(--wow-corner-out)); }
.wow-wheel .wow-corner[aria-disabled="true"] { opacity: 0.45; }
@media (orientation: landscape) {
  :root[data-controls-side="left"] .wow-wheel .wow-submit { right: auto; left: calc(-1 * var(--wow-corner-out)); }
  :root[data-controls-side="left"] .wow-wheel .wow-back { left: auto; right: calc(-1 * var(--wow-corner-out)); }
}
.wow-wheel-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.wow-disc {
  fill: var(--color-surface-alt);
  stroke: var(--color-border);
  stroke-width: 2;
}
.wow-line {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.75;
}
.wow-letter {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  min-width: 48px;
  min-height: 48px;
  border: 3px solid var(--color-text-muted);
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  touch-action: none;
  pointer-events: none; /* the wheel handles the pointer; buttons stay for keyboards and screen readers */
}
.wow-letter:focus-visible {
  outline: 3px solid var(--color-text);
  outline-offset: 2px;
}
/* Linked letter: solid fill and a heavy ring, so it differs without colour. */
.wow-letter-on {
  background: var(--color-game-correct);
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent);
  color: var(--color-game-on-correct);
}
/* #547: the bonus words are one small button (the count) that opens the shared list dialog; no list on the screen.
   While playing it sits in the blank space under the grid; on the solved card it is a line in the card. */
.wow-bonus { display: block; box-sizing: border-box; margin: var(--space-xs) auto; min-height: var(--tap-min); max-width: 100%; padding: 4px var(--space-sm); font-size: var(--font-sm, 0.95rem); line-height: 1.15; }
.wow > .wow-bonus { margin: 0 auto; }
.wow-result { margin: var(--space-sm) 0; text-align: center; }
/* Reduce Motion: nothing moves; the cue is the text and the static outline. */
/* Landscape (#454): the wheel is the input, so by default it is on the RIGHT and the word grid (with its
   connecting letters) on the left; controls side "left" mirrors it. The grid is sized by layout-fit (split). */
@media (orientation: landscape) {
  /* The wheel is the input: its column is as wide as the height allows (a big, thumb-sized wheel), the grid gets the rest. */
  .wow { --wow-wheel-col: min(calc(100dvh - 84px), 58%); display: grid; grid-template-columns: minmax(0, 1fr) var(--wow-wheel-col); gap: 0 var(--space-md); align-items: start; }
  .wow > .wow-board { grid-column: 1; grid-row: 1 / span 8; margin: 0; }
  .wow > :not(.wow-board):not(dialog) { grid-column: 2; margin: 0; }
  /* The bonus line is placed by script beside or under the grid (#502), out of the flow. */
  .wow { position: relative; }
  .wow > .wow-bonus.wow-bonus { position: absolute; grid-column: auto; margin: 0; }
  .wow .wow-wheel { width: min(100%, calc((100% - 184px) / 0.51)); max-width: none; margin-bottom: 0; }
  .wow > .wow-wheel.wow-wheel { margin-inline: auto; } /* centred in its column, so the buttons beside it stay in the column */
  /* #536: the (column - 184px) / 0.51 sizing above needs a column over ~260px, i.e. a screen over ~345px tall
     (the column is the height minus 84px). A phone landscape with browser bars is shorter, and there the wheel
     collapsed to a few px. (issue 544: the formula's wheel is still only ~180px at 360px tall, too small for 48px letters,
     so the switch is at 370px: the formula wheel there is 200px and up.) Below that height the wheel takes the whole column and the tick and backspace go
     back to the corners of its square (the look before the buttons moved out): a playable wheel comes first. */
  @media (max-height: 369px) {
    .wow .wow-wheel { width: 100%; --wow-corner-out: 0px; }
  }
  /* #535 / #547: a solved board's column (result card, buttons) fits by compacting; it never scrolls. The grid stays put. */
  .wow:has(> .wow-result) { box-sizing: border-box; height: calc(100dvh - 12px); overflow: hidden; }
  .wow:has(> .wow-result) .wow-result { padding: var(--space-xs) var(--space-sm); margin: 0; }
  .wow:has(> .wow-result) .game-actions .btn, .wow:has(> .wow-result) .share-result .btn { min-height: var(--tap-min); font-size: var(--font-base, 1rem); }
  :root[data-controls-side="left"] .wow { grid-template-columns: var(--wow-wheel-col) minmax(0, 1fr); }
  :root[data-controls-side="left"] .wow > .wow-board { grid-column: 2; }
  :root[data-controls-side="left"] .wow > :not(.wow-board):not(dialog) { grid-column: 1; }
}
.wow-reduced .wow-pop,
.wow-reduced .wow-shake { animation: none; }
.wow-reduced .wow-word-wrong { outline: 2px solid var(--color-danger); outline-offset: 2px; }

/* ---- Solitaire (addons/games/solitaire-ui.js) ----
   One board block: top row (stock, waste, four foundations) over seven fanned
   columns. Card sizes and positions are set in px by solitaire-logic.js; the
   board is fitted to the screen by shell/layout-fit.js (data-fit-board). */
.sol-screen { position: relative; display: flex; flex-direction: column; gap: 0; }
/* No permanent status line (#552): the table has the whole area. Status messages go to a screen-reader live region
   (.sol-line is sr-only); the Auto-finish ribbon button lights up when Ready. Moves and time live in a card the clock
   ribbon button opens in the centre of the screen: a deliberate, player-opened overlay (like a dialog, so it is the one
   thing allowed over the table), off every time the game opens, hidden by the button, a tap on the card or Escape / B. */
.sol-clock-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  box-sizing: border-box;
  min-width: 180px;
  max-width: min(320px, calc(100vw - 32px));
  padding: 12px 20px;
  border: 3px solid var(--color-text);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.sol-clock-card[hidden] { display: none; }
.sol-clock-line { font-size: 28px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.sol-clock-time { font-size: 36px; }
.sol-clock-msg { margin-top: 6px; font-size: var(--font-sm); font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.sol-clock-msg[hidden] { display: none; }
.sol-board {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: var(--board-height, calc(100dvh - 57px - env(safe-area-inset-top, 0px) - 32px));
  padding: 8px; /* PAD_Y / PAD_X in solitaire-ui.js */
  border-radius: 10px;
  background: var(--color-surface-alt);
  border: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.sol-pile { position: absolute; }
.sol-slot {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 2px dashed var(--color-text-muted);
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.sol-slot { touch-action: none; }
.sol-slot-plain { pointer-events: none; }
.sol-slot-suit { width: 55%; height: auto; opacity: 0.4; }
.sol-stock-slot { z-index: 3; }
.sol-recycle::after {
  content: "\21BB";
  font-size: 1.8rem;
  color: var(--color-text);
}
.sol-card {
  position: absolute;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  overflow: hidden;
  border-radius: 5px;
  background: var(--color-paper);
  border: 1.5px solid var(--color-card-suit-black);
  touch-action: none;
  font-family: inherit;
}
.sol-face { cursor: pointer; }
.sol-red { color: var(--color-card-suit-red); }
.sol-black { color: var(--color-card-suit-black); }
.sol-idx {
  position: absolute;
  left: 2px;
  top: 0;
  display: flex;
  align-items: center;
  gap: 1px;
  line-height: 1;
  pointer-events: none;
}
.sol-rank { font-size: max(15px, calc(var(--sol-card-w, 45px) * 0.34)); font-weight: 800; line-height: 1.1; }
.sol-idx .sol-suit { width: max(12px, calc(var(--sol-card-w, 45px) * 0.28)); height: max(12px, calc(var(--sol-card-w, 45px) * 0.28)); }
.sol-centre { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sol-down { border-width: 1.5px; }
.sol-back-svg { display: block; width: 100%; height: 100%; pointer-events: none; }
/* Where you are (#386): a 4px ring in the text colour, detached from the card by a 3px gap of board colour, so it
   reads on a small screen in Clear (15:1 on the board) and Clear Dark (12:1). One rule for keyboard and controller
   focus: the shared pad rule (outline inside the card, invisible on white paper in Clear Dark) must not shrink it. */
.sol-card:focus-visible,
.sol-slot:focus-visible,
html[data-input="pad"] .sol-card:focus,
html[data-input="pad"] .sol-slot:focus,
.sol-suggest { outline: 4px solid var(--color-text); outline-offset: 3px; z-index: 5; }
/* A held card: a different shape from focus (a double band inside the card: accent over black) plus the lift shadow. */
.sol-selected { box-shadow: inset 0 0 0 3px var(--color-accent), inset 0 0 0 5px var(--color-card-suit-black), 0 5px 9px rgba(0, 0, 0, 0.35); }
.sol-target > .sol-slot,
.sol-target > .sol-card:last-of-type { outline: 3px dashed var(--color-accent); outline-offset: 2px; }
.sol-dragging { z-index: 100; box-shadow: 0 8px 14px rgba(0, 0, 0, 0.4); cursor: grabbing; }
/* The game controls live in the header slot (shell/header-actions.js); the controller hint
   line never takes board height here (the prompts show in the Start overlay and Settings). */
.sol-screen > [data-input-prompt] { display: none !important; }
/* Start / M opens the toolbar as an overlay: board dimmed, toolbar outlined as one group,
   the focused button filled. */
.sol-menu-open > * { opacity: 0.45; }
/* Start in a game with a .game-actions row: board dimmed and inert, the actions outlined as one group. */
.game-menu-open [data-fit-board] { opacity: 0.45; }
/* Cup Day Dash: the track dims while the menu is open; its HUD stays bright (#634). */
.game-menu-open .cupday-canvas { opacity: 0.45; }
.game-menu-open .game-actions { position: relative; z-index: 2; padding: var(--space-sm); background: var(--color-surface); border: 3px solid var(--color-accent); border-radius: var(--radius); }
.game-menu-open .game-actions .btn { border-color: transparent; }
.game-menu-open .game-actions .btn:focus-visible { background: var(--color-accent); color: var(--color-on-accent); outline: none; box-shadow: none; }
.sol-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6); /* the same backdrop as the menu and tester dialog */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  z-index: 800;
}
.sol-dialog {
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  padding: var(--space-sm) var(--space-md) var(--space-md);
}
.sol-dialog h3 { margin: var(--space-xs) 0; }
.sol-dialog-text { margin: 0 0 var(--space-sm); }
.sol-dialog-buttons { display: grid; gap: var(--space-sm); margin-top: var(--space-sm); }
.sol-option-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); margin-bottom: var(--space-sm); }
.sol-option-label { flex: 1 0 100%; font-weight: 700; }
.sol-option-row .btn { flex: 1; }
.sol-option-on { border-width: 3px; background: var(--color-accent); color: var(--color-on-accent); }
.sol-option-on::before { content: "\2713 "; }
.sol-back-choice { display: flex; align-items: center; gap: var(--space-sm); justify-content: center; }
.sol-back-thumb { display: block; width: 28px; height: 39px; border: 1.5px solid var(--color-card-suit-black); border-radius: 3px; overflow: hidden; flex: none; }
.sol-reduced .sol-card { transition: none; }

/* Overlay chips (#404): 1-2 words of game status laid over the board in a free zone. They never
   take a tap (pointer-events: none) and never push the board down. */
.game-overlay {
  position: absolute;
  z-index: 3;
  max-width: calc(100% - 16px);
  padding: 3px 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--color-surface) 85%, transparent);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: var(--font-sm);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.game-overlay[hidden] { display: none; }

/* A button the ribbon has taken over is hidden for good (author display rules such as .btn would otherwise win). */
button[hidden], .game-actions[hidden], .game-options[hidden] { display: none !important; }

/* Controls adopted into the ribbon (ToolkitHeader.adopt): the old rows take no space, the text
   the player no longer needs is visually hidden (still read by screen readers), and an options
   chooser opens as a popover under the ribbon instead of inside the page. */
.ribbon-empty { position: absolute; width: 0; height: 0; min-height: 0; margin: 0; padding: 0; border: 0; overflow: visible; }
.ribbon-on .game-option-chooser {
  position: fixed;
  top: calc(57px + env(safe-area-inset-top, 0px));
  right: var(--space-sm);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
  padding: 6px;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}
.ribbon-on .game-option-chooser[hidden] { display: none; }

/* Short phones: trim the spacing around the title and status lines so the
   board keeps as much of the height as possible. */
@media (max-height: 700px) {
  .plugin-container { padding-top: var(--space-sm); padding-bottom: var(--space-sm); }
  .noughts-role,
  .word-search-hint { margin: var(--space-xs) 0; }
  .game-status { margin: var(--space-xs) 0; }
  .catastrophe-status { margin-bottom: var(--space-xs); }
  .catastrophe-hand,
  .catastrophe-powers { margin-bottom: var(--space-xs); }
  .catastrophe-board-wrap { margin-bottom: var(--space-sm); }
}

/* ---- How to play: the shared stepped card (#356, STYLE_GUIDE "How to play") ---- */
.howto-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; padding: var(--space-md); z-index: 800; }
.howto-card { box-sizing: border-box; width: 100%; max-width: 420px; max-height: 100%; overflow: hidden; background: var(--color-surface); color: var(--color-text); border: 3px solid var(--color-text); border-radius: var(--radius); padding: var(--space-sm) var(--space-md) var(--space-md); }
.howto-card:focus { outline: none; }
.howto-title { margin: 0 0 var(--space-sm); }
.howto-shot { position: relative; box-sizing: border-box; width: 100%; max-width: 280px; margin: 0 auto var(--space-sm); border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; background: var(--color-paper, var(--color-surface-alt)); }
.howto-img { display: block; width: 100%; height: 100%; }
.howto-ring { position: absolute; box-sizing: border-box; border: 3px solid var(--color-accent); border-radius: 6px; box-shadow: 0 0 0 2px var(--color-surface); pointer-events: none; }
.howto-text { margin: 0 0 var(--space-xs); font-size: var(--font-base); line-height: 1.4; }
.howto-count { margin: 0 0 var(--space-xs); font-size: var(--font-sm); color: var(--color-text-muted); }
.howto-dots { display: flex; justify-content: center; gap: var(--space-sm); margin-bottom: var(--space-sm); }
.howto-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--color-accent); box-sizing: border-box; }
.howto-dot-on { background: var(--color-accent); }
.howto-nav { display: flex; gap: var(--space-sm); }
.howto-nav .btn { flex: 1 1 0; min-width: 0; min-height: var(--tap-min); }
.howto-nav [hidden] { display: none; }

/* Cat-astrophe in the shared ribbon (#404): the shelf has tall cells in portrait (square in landscape,
   sized from the free height so every row lines up); the held item and the power-ups stay above it
   and the score line and the latest news sit below it. */
.ribbon-on .catastrophe { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; align-content: start; }
.ribbon-on .catastrophe > * { grid-column: 1; margin: 0; }
.ribbon-on .catastrophe > .catastrophe-hand { grid-row: 1; justify-content: flex-start; gap: 10px; }
.ribbon-on .catastrophe > .catastrophe-powers { grid-row: 2; }
.ribbon-on .catastrophe > .catastrophe-board-wrap { grid-row: 3; }
.ribbon-on .catastrophe > .catastrophe-status { grid-row: 4; min-height: 3.2em; font-size: var(--font-sm); }
.ribbon-on .catastrophe-cell { aspect-ratio: auto; height: clamp(34px, calc((100dvh - 330px) / 7), 62px); box-sizing: border-box; overflow: hidden; }
.ribbon-on .catastrophe-cell .catastrophe-item { height: auto; aspect-ratio: 1 / 1; width: 80%; }
@media (orientation: landscape) {
  /* The shelf is as wide as the window is tall (square cells) but never takes the room the controls need (#694):
     the controls track keeps its minimum and the shelf track only grows up to the height, so in a window that is
     wide but not wide enough the shelf narrows instead of overlapping the held row, power-ups and score. */
  .ribbon-on .catastrophe { --catastrophe-controls-min: 11rem; grid-template-columns: minmax(var(--catastrophe-controls-min), 1fr) minmax(0, calc(100dvh + 4px)); }
  .ribbon-on .catastrophe > * { grid-column: 1; }
  .ribbon-on .catastrophe > .catastrophe-board-wrap { grid-column: 2; grid-row: 1 / span 6; width: 100%; max-width: none; overflow: visible; }
  .ribbon-on .catastrophe > .catastrophe-hand { grid-row: 1; }
  .ribbon-on .catastrophe > .catastrophe-powers { grid-row: 2; flex-direction: column; }
  .ribbon-on .catastrophe .catastrophe-power { width: 100%; min-height: 52px; }
  .ribbon-on .catastrophe > .catastrophe-status { grid-row: 3; }
  .ribbon-on .catastrophe-cell { height: calc((100dvh - 32px) / 7); }
}

/* The crossword in the shared ribbon (#404): the clue strip (‹ clue ›) sits between the grid and the
   keyboard; a long clue wraps to 3 lines and is clamped, the grid never moves. */
.ribbon-on .crossword-clue-row { min-height: 60px; align-items: center; }
.ribbon-on .crossword-active-clue {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: var(--font-sm);
  line-height: 1.25;
  text-align: center;
}

/* Portrait stage (#404): the game is centred in the height under the ribbon and its inputs (keyboard,
   keypad, wheel, main buttons) sit at the bottom, in reach of the thumb. A game at the top of a tall
   screen with dead space below it is the worst layout. Auto margins do it: the board starts the centred
   group (margin-top: auto), the input starts the bottom group (margin-top: auto), and a game with no
   input of its own centres board and status together. Landscape keeps its split layout. */
@media (orientation: portrait) {
  .ribbon-on { --stage-h: calc(100dvh - 57px - env(safe-area-inset-top, 0px) - 32px); display: flex; flex-direction: column; min-height: var(--stage-h); }
  .ribbon-stage { display: flex; flex-direction: column; flex: 1 1 auto; }
  .ribbon-on .board, .ribbon-on .wow-board, .ribbon-on .catastrophe-board-wrap { margin-top: auto; }
  .ribbon-on .wordle-keyboard, .ribbon-on .sudoku-keypad, .ribbon-on .wow-entry { margin-top: auto; }
  /* Word Search (#495): the theme line is the top of the centred group, right above the grid, so it
     stays clear of the daily reset pill that sits under the ribbon. */
  .ribbon-on .word-search-theme { margin-top: auto; text-align: center; }
  .ribbon-on .word-search-theme ~ .board { margin-top: 0; }
  .ribbon-on:not(:has(.wordle-keyboard, .sudoku-keypad, .wow-entry)) .word-search-theme ~ .word-search-hint:last-of-type,
  .ribbon-on:not(:has(.wordle-keyboard, .sudoku-keypad, .wow-entry)) .game-status.word-search-theme { margin-bottom: var(--space-xs); } /* the word list closes the group */
  /* No input of its own: the status under the board closes the centred group. */
  .ribbon-on:not(:has(.wordle-keyboard, .sudoku-keypad, .wow-entry)) .game-status,
  .ribbon-on:not(:has(.wordle-keyboard, .sudoku-keypad, .wow-entry)) .word-search-hint:last-of-type { margin-bottom: auto; }
  .ribbon-on:not(:has(.wordle-keyboard, .sudoku-keypad, .wow-entry)) .word-search-word-list { margin-bottom: auto; }
  /* Sudoku keeps its status line last. */
  .ribbon-on .sudoku-keypad ~ * { margin-top: 0; }
  /* Cat-astrophe: held item and shelf centred, power-ups at the bottom. */
  .ribbon-on .catastrophe { display: flex; flex-direction: column; flex: 1 1 auto; }
  .ribbon-on .catastrophe > .catastrophe-hand { order: 1; margin-top: auto; }
  .ribbon-on .catastrophe > .catastrophe-board-wrap { order: 2; margin-top: 0; }
  .ribbon-on .catastrophe > .catastrophe-status { order: 3; }
  .ribbon-on .catastrophe > .catastrophe-powers { order: 4; margin-top: auto; }
  /* Skullfire and Cup Day Dash: arena / track centred. */
  .ribbon-on .skullfire-screen { display: flex; flex-direction: column; flex: 1 1 auto; }
  .ribbon-on .skullfire-screen .board { margin-top: auto; }
  .ribbon-on .skullfire-screen .game-record { margin-bottom: auto; }
  .ribbon-on .cupday-screen { display: flex; flex-direction: column; flex: 1 1 auto; padding-bottom: 88px; }
  .ribbon-on .cupday-screen .cupday-canvas { margin-top: auto; }
  .ribbon-on .cupday-screen .cupday-help { margin-bottom: auto; }
}

/* ---- Solitaire zoom (owner, 9 Nov 2026; the control is a ribbon button since #552) ----
   One tap on the ribbon's magnifier steps the zoom up and wraps to 100% after 300% (+ - 0 keys too). Zoomed, the board
   scrolls: a finger scrolls it from the bare felt (a card still drags), a mouse drags the felt to pan, the wheel
   and trackpad scroll. */
.sol-board.sol-zoomed {
  overflow: auto;
  touch-action: pan-x pan-y;
  overscroll-behavior: contain;
  scrollbar-width: none;
  cursor: grab;
}
.sol-board.sol-zoomed::-webkit-scrollbar { display: none; }
.sol-board.sol-panning { cursor: grabbing; }
.sol-zoomed .sol-card, .sol-zoomed .sol-slot { cursor: pointer; }
.sol-sizer { position: absolute; left: 0; top: 0; pointer-events: none; visibility: hidden; }

/* ---- The landscape rail (#454, owner 9 Nov 2026): the ONE rule that turns the ribbon into a vertical
   strip down the left edge, for every game that puts buttons in the ribbon (the bar has .has-slot).
   `orientation: landscape` is the single definition (JS asks the bar itself: header-actions.js measures
   its flex direction). Portrait is untouched. Home on top, the game's buttons below it, the menu button
   at the bottom; buttons that do not fit collapse into the same "more" button by priority. The board
   gets the full height and the width beside the rail; the safe-area inset keeps the rail clear of a
   camera cut-out. --rail-w is the rail's width, used by anything positioned beside it. */
:root { --rail-w: calc(64px + env(safe-area-inset-left, 0px)); }
@media (orientation: landscape) {
  #app:has(> .app-header.has-slot) { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); align-items: start; }
  /* #525: a game screen is exactly one screen tall and never scrolls the page (the owner saw it creep a few px in
     the installed app: fractional device heights, the rail's 100dvh and the board fit rounding, or a drag
     pulling the page). #app is locked to the visible height and clips, and overscroll (pull to refresh) is off. */
  #app:has(> .app-header.has-slot) { height: 100dvh; max-height: 100dvh; overflow: hidden; }
  html:has(#app > .app-header.has-slot), html:has(#app > .app-header.has-slot) body { overflow-y: hidden; overscroll-behavior: none; }
  #app:has(> .app-header.has-slot) > :not(.app-header) { grid-column: 2; }
  #app:has(> .app-header.has-slot) > .app-header {
    grid-column: 1;
    grid-row: 1 / span 12;
    position: sticky;
    top: 0;
    z-index: 20;
    box-sizing: border-box;
    flex-direction: column;
    align-items: center;
    gap: var(--ribbon-gap);
    width: var(--rail-w);
    min-height: 0;
    height: 100dvh;
    padding: calc(6px + env(safe-area-inset-top, 0px)) 8px calc(6px + env(safe-area-inset-bottom, 0px)) calc(8px + env(safe-area-inset-left, 0px));
    border-bottom: 0;
    border-right: 1px solid var(--color-border);
  }
  #app:has(> .app-header.has-slot) > .app-header .app-header-logo { display: none; }
  #app:has(> .app-header.has-slot) > .app-header .header-slot { flex-direction: column; margin: 0; }
  #app:has(> .app-header.has-slot) > .app-header .hamburger-btn { margin-top: auto; }
  #app:has(> .app-header.has-slot) .header-more-panel { left: calc(100% + 6px); right: auto; top: auto; bottom: 6px; }
  #app:has(> .app-header.has-slot) .ribbon-on .game-option-chooser { top: auto; right: auto; bottom: 6px; left: calc(var(--rail-w) + 6px); max-height: calc(100dvh - 12px); overflow-y: auto; }
  #app:has(> .app-header.has-slot) .plugin-container { padding: 6px 8px 6px 6px; }
  #app:has(> .app-header.has-slot) .ribbon-on .word-search-hint { margin: 0; } /* an empty hint line must not add height above 700px */
  /* The Catalogue button (#619, test builds) in the rail: a 48px-high square the width of the rail, with its word
     kept for screen readers. Its text was 76px wide in the 64px rail, so the bar scrolled sideways in every
     landscape game (issues 422 and 344). */
  #app:has(> .app-header.has-slot) > .app-header .catalogue-btn { width: 100%; min-width: 0; height: var(--tap-min); min-height: 0; padding: 0; font-size: 0; flex: none; }
  #app:has(> .app-header.has-slot) > .app-header .catalogue-btn::before { content: "\229E"; font-size: 20px; line-height: 1; }
  /* Home and the Admin screens scroll as a page in landscape, footer included (the footer used to be
     locked to the bottom of a screen-tall column, taking about a third of a phone's height). Games keep
     their own lock (issue 525, above). */
}

/* Landscape controls on the left (Settings > Appearance, shell/controls-side.js): the same layouts
   mirrored. The board column swaps sides; everything else is unchanged. */
@media (orientation: landscape) {
  :root[data-controls-side="left"] div:has(> .board[data-fit-landscape="split"]) { grid-template-columns: minmax(0, 1fr) max-content; }
  :root[data-controls-side="left"] div:has(> .board[data-fit-landscape="split"]) > .board { grid-column: 2; }
  :root[data-controls-side="left"] div:has(> .board[data-fit-landscape="split"]) > :not(.board):not(dialog) { grid-column: 1; }
  :root[data-controls-side="left"] div:has(> .board[data-fit-landscape="split"][data-input-board]) { grid-template-columns: max-content minmax(0, 1fr); }
  :root[data-controls-side="left"] div:has(> .board[data-fit-landscape="split"][data-input-board]) > .board { grid-column: 1; }
  :root[data-controls-side="left"] div:has(> .board[data-fit-landscape="split"][data-input-board]) > :not(.board):not(dialog) { grid-column: 2; }
  :root[data-controls-side="left"] .ribbon-on .catastrophe { grid-template-columns: minmax(0, calc(100dvh + 4px)) minmax(var(--catastrophe-controls-min), 1fr); }
  :root[data-controls-side="left"] .ribbon-on .catastrophe > * { grid-column: 2; }
  :root[data-controls-side="left"] .ribbon-on .catastrophe > .catastrophe-board-wrap { grid-column: 1; }
  :root[data-controls-side="left"] .ribbon-on .cupday-screen { grid-template-columns: minmax(0, 1fr) auto; }
  :root[data-controls-side="left"] .ribbon-on .cupday-screen > * { grid-column: 1; }
  :root[data-controls-side="left"] .ribbon-on .cupday-screen > .cupday-canvas { grid-column: 2; }
}

.header-options-label { padding: 8px 10px 2px; font-size: var(--font-sm); font-weight: 700; opacity: 0.75; }
.header-options-label:first-child { padding-top: 2px; }
.header-more-item[aria-pressed="true"] { font-weight: 700; }
/* Memory Match: tall cards in portrait. */
@media (orientation: portrait) { .ribbon-on .memory-card { aspect-ratio: 3 / 4; height: auto; width: 100%; } }
/* Mystery case file: the Play button of the open puzzle stays in reach while its card is on screen. */
.mystery-card [data-action="play"] { position: sticky; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); z-index: 4; }

/* The finish line (#404): when a game is over the board stays, the result sits under it and ONE clean
   line of buttons follows: Play again, Share, Today's puzzle, side by side. */
/* #555: every button in the finish row is the same size, by construction. Root cause of the mismatch (#543): "Share result" sits in a
   `.share-result` wrapper (a grid of the button and an empty status line, 8px gap). The row stretched "Another" to the wrapper's height
   (button + gap = 64px) while the button inside stayed 56px, and widths followed each label. Now the wrapper adds no box of its own
   (`display: contents`), the status line is out of the flow until it has text, and every button has one width (--btn-w, shrinking
   only when the row is narrower) and one height (--btn-h, the shared .btn rule). Where two do not fit side by side they wrap. */
.game-actions-stack { display: flex; flex-direction: row; flex-wrap: wrap; align-items: stretch; justify-content: center; gap: var(--space-sm); }
.game-actions-stack > .btn, .game-actions-stack > .share-result > .btn { flex: 0 1 var(--btn-w); width: var(--btn-w); min-width: 0; margin: 0; padding-left: var(--space-sm); padding-right: var(--space-sm); white-space: normal; line-height: 1.15; }
.game-actions-stack .share-result { display: contents; }
/* #526: "Next daily: <game>" sits in a row of its own under the finish row, sized to its label (the name can be long),
   never wider than 60% of the row; the label wraps instead. */
.next-daily-row { margin: 0; }
.next-daily-row > .next-daily-btn { flex: 0 1 auto; width: auto; max-width: 60%; line-height: 1.1; padding-top: var(--space-xs); padding-bottom: var(--space-xs); }
/* A short landscape screen has no room for a third action under the result (the screen never scrolls, #547): the
   button is dropped there; the next daily is still one tap away on Home. */
@media (orientation: landscape) and (max-height: 420px) { .next-daily-row { display: none; } }
.game-actions-stack .share-status { flex: 1 0 100%; order: 9; margin: 0; text-align: center; }
.game-actions-stack .share-status:empty { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } /* stays in the accessibility tree for the live region, takes no room */

/* Short screens (landscape phones): tighter card; the picture is hidden by howto-ui.js when too small. */
@media (max-height: 480px) {
  .howto-overlay { padding: var(--space-xs); }
  .howto-card { padding: var(--space-xs) var(--space-md) var(--space-sm); }
  .howto-title { margin-bottom: var(--space-xs); font-size: var(--font-lg, 1.1rem); }
  .howto-text { line-height: 1.3; }
  .howto-dots { margin-bottom: var(--space-xs); }
}

/* ---- Shared list dialog (#547): a list the player opens on purpose; it scrolls inside itself, the screen behind never does. ---- */
.list-dialog-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; padding: var(--space-md); z-index: 900; }
.list-dialog { box-sizing: border-box; display: flex; flex-direction: column; width: 100%; max-width: 420px; max-height: 100%; background: var(--color-surface); color: var(--color-text); border: 3px solid var(--color-text); border-radius: var(--radius); padding: var(--space-sm) var(--space-md) var(--space-md); }
.list-dialog-heading { margin: var(--space-xs) 0 var(--space-sm); }
.list-dialog-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin-bottom: var(--space-sm); }
.list-dialog-list { display: flex; flex-wrap: wrap; gap: var(--space-xs) var(--space-md); margin: 0; padding: 0; list-style: none; font-size: var(--font-base, 1rem); font-weight: 600; }
.list-dialog-close { flex: 0 0 auto; }

/* #547: a solved Word Search has no how-to hint to show, so the screen fits without scrolling. */
div:has(> .game-result) > .word-search-hint { display: none; }


/* The sections (#619) are rows in the ☰ menu (shell/core.js openHamburgerMenu), in test builds only.
   The bar stays dark (its own tokens); the section pages below use the JAMscapade tokens. */

/* Section page (placeholder for Arcade, Standalone games and Enigma). JAMscapade tokens. */
.section-page {
  background: var(--jam-paper); color: var(--jam-ink);
  min-height: 100%; box-sizing: border-box;
  padding: var(--space-lg) var(--space-md);
}
.section-page h1 { margin: 0 0 var(--space-sm); font-size: 26px; line-height: 32px; font-family: "Space Grotesk", Inter, system-ui, sans-serif; }
.section-page p { margin: 0; max-width: 65ch; color: var(--jam-ink-muted); font-size: 14px; line-height: 20px; }
@media (min-width: 760px) { .section-page h1 { font-size: 40px; line-height: 44px; } }

/* Pocket Arcade filter chips in the JAMscapade look (#619), test builds only (body).
   The genre and sub-genre chips keep their .btn base and the check mark (not colour alone). */
body .home-genres .btn, body .home-subgenres .btn {
  background: var(--jam-paper-raised); color: var(--jam-ink); border: 1px solid var(--jam-ink-muted); border-radius: 10px;
}
body .home-genres .btn[aria-pressed="true"], body .home-subgenres .btn[aria-pressed="true"] {
  background: var(--jam-teal); border-color: var(--jam-teal); color: var(--jam-paper); font-weight: 600; border-style: solid; border-width: 1px;
}

/* Game tiles on a section page (#619): the same tiles as Home, in a plain grid. */
.section-games { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-sm); margin-top: var(--space-md); }
/* Featured Home and the Catalogue (#619, test builds): the bar's Catalogue button, the Featured tiles,
   the What's new posts, and the A to Z list. Tokens only, so both themes follow the studio look. */
.catalogue-btn {
  min-height: var(--tap-min); padding: 0 var(--space-sm); border-radius: 10px;
  border: 1px solid var(--header-fg); background: transparent; color: var(--header-fg);
  font: 600 14px/1 Inter, system-ui, sans-serif; cursor: pointer;
}
.catalogue-btn[hidden] { display: none; }
.catalogue-btn[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--jam-signal); }
/* JAMscapade bar (version 3 demo): Home and Catalogue are words on wider screens (icons on small phones, below). The page you are on
   is outlined in orange (and underlined), the same mark on both. */
body .home-btn > span[aria-hidden="true"] { display: none; }
/* In a game the bar has no room for words: Home is its icon at every width (the words are hidden by the has-slot rule). */
body .app-header.has-slot .home-btn > span[aria-hidden="true"] { display: inline; font-size: 22px; line-height: 1; }
body .home-btn, body .catalogue-btn { padding: 0 var(--space-sm); font-size: 14px; }
body .catalogue-btn { min-height: var(--tap-min); }
body .home-btn[aria-current="page"], body .catalogue-btn[aria-current="page"] { border-color: var(--jam-signal); }
/* Small phones (owner, 2026-11-22): the bar was cut off on the right and the burger with it. Home and Catalogue are
   icons here, the JAMscapade wordmark is hidden, and the words stay in the buttons for screen readers. */
@media (max-width: 480px) {
  body .app-header .jam-brand { display: none; }
  body .app-header:not(.has-slot) .home-btn, body .app-header:not(.has-slot) .catalogue-btn { font-size: 0; width: var(--tap-min); min-width: 0; height: var(--tap-min); padding: 0; flex: none; }
  body .app-header:not(.has-slot) .home-btn > span:not([aria-hidden]) { display: none; }
  body .app-header:not(.has-slot) .home-btn > span[aria-hidden="true"] { display: inline; font-size: 22px; line-height: 1; }
  body .app-header:not(.has-slot) .catalogue-btn::before { content: "\229E"; font-size: 20px; line-height: 1; }
}
.featured-home, .catalogue-page {
  background: var(--jam-paper); color: var(--jam-ink); min-height: 100%; box-sizing: border-box;
  padding: var(--space-md) 0;
}
/* The Featured Home and the Catalogue are full width: no grey gutter inside the page frame. */
.plugin-container:has(> .featured-home), .plugin-container:has(> .catalogue-page) { padding: 0; }
.catalogue-page h1 { margin: 0 var(--space-md) var(--space-sm); font: 700 26px/32px "Space Grotesk", Inter, system-ui, sans-serif; }
.featured-home .home-section-heading, .catalogue-page .home-section-heading {
  margin: var(--space-md) var(--space-md) var(--space-sm); font: 700 20px/26px "Space Grotesk", Inter, system-ui, sans-serif;
}
.featured-row { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
@media (min-width: 600px) { .featured-row { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.feat-tile {
  position: relative; aspect-ratio: 4 / 3; overflow: hidden; isolation: isolate; border: 0; border-radius: 0;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; padding: var(--space-sm);
  color: var(--jam-paper); text-align: left; cursor: pointer; background: var(--jam-ink);
}
.feat-tile:focus-visible { outline: 3px solid var(--jam-focus); outline-offset: -3px; }
.feat-art { position: absolute; inset: 0; z-index: -1; background: linear-gradient(135deg, var(--art), var(--jam-ink)); opacity: .9; }
/* Tile artwork (WebP, transparent): the PA logo, and the three cat heads. A dark fade at the bottom keeps the
   name and kind readable on top of the picture. */
.feat-tile[data-entry="pocket-arcade"] .feat-art, .feat-tile[data-entry="catastrophe"] .feat-art { opacity: 1; }
.feat-tile[data-entry="pocket-arcade"] .feat-art {
  background-image: linear-gradient(to bottom, rgba(0,0,0,0) 40%, rgba(0,0,0,.72)), url("feat-pocket-arcade.webp"), linear-gradient(135deg, var(--art), var(--jam-ink));
  background-position: 0 0, right 8px top 24%, 0 0;
  background-size: auto, 66% auto, auto;
  background-repeat: no-repeat;
}
.feat-tile[data-entry="catastrophe"] .feat-art {
  background-image: linear-gradient(to bottom, rgba(0,0,0,0) 40%, rgba(0,0,0,.72)), url("feat-catastrophe.webp"), linear-gradient(135deg, var(--art), var(--jam-ink));
  background-position: 0 0, center 18%, 0 0;
  background-size: auto, 96% auto, auto;
  background-repeat: no-repeat;
}
.feat-logo {
  position: absolute; top: var(--space-sm); left: var(--space-sm); min-width: 34px; height: 34px; padding: 0 6px;
  border-radius: 9px; background: var(--jam-paper); color: var(--jam-ink); display: grid; place-items: center;
  font: 700 14px/1 "Space Grotesk", Inter, system-ui, sans-serif;
}
.feat-kind { font: 600 11px/14px Inter, system-ui, sans-serif; text-transform: uppercase; letter-spacing: .05em; opacity: .9; }
.feat-name { font: 700 16px/20px "Space Grotesk", Inter, system-ui, sans-serif; text-shadow: 0 1px 6px rgba(0,0,0,.45); }
.news-list { display: grid; gap: var(--space-xs); margin: 0 var(--space-md); }
.news-post { display: grid; gap: 2px; background: var(--jam-paper-raised); border-radius: 12px; padding: var(--space-sm) var(--space-md); }
.news-date { font: 600 12px/16px Inter, sans-serif; color: var(--jam-ink-muted); }
.news-post h3 { margin: 0; font: 700 17px/22px "Space Grotesk", Inter, system-ui, sans-serif; }
.news-post p { margin: 0; color: var(--jam-ink-muted); font-size: 14px; line-height: 20px; }
.news-post .news-soon { color: var(--jam-teal); font-weight: 600; }
/* #525: in landscape the Featured Home fits the screen with no scroll. Featured sits on the left and the news
   beside it on the right, so the page is about the height of the tiles, not tiles plus news stacked. */
@media (orientation: landscape) {
  .featured-home {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); column-gap: var(--space-md);
    align-items: start;
  }
  .featured-home > .home-section-heading:first-of-type { grid-column: 1; grid-row: 1; }
  .featured-home > .featured-row { grid-column: 1; grid-row: 2; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0 var(--space-md); }
  .featured-home > .home-section-heading:last-of-type { grid-column: 2; grid-row: 1; margin-left: 0; margin-right: 0; }
  .featured-home > .news-list { grid-column: 2; grid-row: 2; margin: 0 var(--space-md) 0 0; }
}
/* #525: a phone with the browser bars showing (about 320-350px tall): less padding and wider-than-tall tiles, so
   the page still fits without a scroll. */
@media (orientation: landscape) and (max-height: 400px) {
  .featured-home { padding: var(--space-sm) 0; }
  .featured-home .home-section-heading { margin-top: var(--space-sm); }
  .featured-home > .featured-row .feat-tile { aspect-ratio: 16 / 9; }
  .featured-home .news-post { padding: 4px var(--space-md); gap: 0; }
}
.az { display: grid; grid-template-columns: 34px 1fr; gap: var(--space-xs); margin: 0 var(--space-md); }
.az-index { display: grid; gap: 2px; align-content: start; position: sticky; top: var(--space-sm); }
.az-jump {
  min-height: var(--tap-min); min-width: 30px; border: 0; border-radius: 6px; background: transparent;
  color: var(--jam-teal); font: 600 13px/1 Inter, sans-serif; cursor: pointer;
}
.az-group { margin: 0 0 var(--space-sm); }
.az-group h3 { margin: 0 0 4px; font: 700 14px/20px "Space Grotesk", Inter, sans-serif; color: var(--jam-ink-muted); border-bottom: 1px solid var(--jam-rule); padding-bottom: 4px; }
.az-list { list-style: none; margin: 0; padding: 0; }
.az-list li { border-bottom: 1px solid var(--jam-rule); }
.az-row { display: grid; gap: 2px; width: 100%; min-height: var(--tap-min); padding: var(--space-xs) 0; border: 0; background: transparent; color: var(--jam-ink); text-align: left; cursor: pointer; font: inherit; }
.az-row:focus-visible { outline: 3px solid var(--jam-focus); outline-offset: 2px; }
.az-row-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); }
.az-name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.az-tag { flex: none; font: 600 11px/16px Inter, sans-serif; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--jam-teal); color: var(--jam-teal); }
.az-tag-series { border-color: var(--jam-signal); color: var(--jam-signal); }
.az-note { font-size: 13px; line-height: 18px; color: var(--jam-ink-muted); }
@media (min-width: 600px) { .az-list { display: grid; grid-template-columns: 1fr 1fr 1fr; column-gap: var(--space-md); } }

/* The Home screen takes the same paper ground as the section pages in test builds (#619). */
body .home { background: var(--jam-paper); color: var(--jam-ink); min-height: 100%; box-sizing: border-box; }

/* Test builds (#619): the studio's own look over the shell chrome. Production is unchanged.
   Brand: JAMscapade wordmark in place of the Pocket Arcade logo (STYLE_GUIDE: one look).
   Focus ring: 3px focus token, 2px offset, on the shell, Home and section pages.
   Tiles: fill only, no border, radius-md, Space Grotesk name (the card rule). */
.jam-brand { display: none; align-items: center; gap: 8px; text-decoration: none; color: var(--header-fg); }
/* Placeholder mark until the studio has its logo: a signal square with a J. */
.jam-mark { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--jam-signal); color: var(--header-bg); font: 700 16px/28px "Space Grotesk", Inter, system-ui, sans-serif; }
.jam-wordmark { display: none; font: 700 20px/24px "Space Grotesk", Inter, system-ui, sans-serif; white-space: nowrap; }
.jam-wordmark span { color: var(--jam-signal); }
body .jam-brand { display: inline-flex; }
body .app-header-logo { display: none; }
/* The wordmark shows on every width when the bar has no game buttons (the demo: the same bar on a phone). */
body #app:not(:has(> .app-header.has-slot)) .jam-wordmark { display: inline; }
body .app-header :focus-visible,
body .home :focus-visible,
body .section-page :focus-visible { outline: 3px solid var(--jam-focus); outline-offset: 2px; }
body .home-tile {
  background: var(--jam-paper-raised); color: var(--jam-ink); border: 0; border-radius: 10px;
}
body .home-tile-name { font-family: "Space Grotesk", Inter, system-ui, sans-serif; font-weight: 600; font-size: 19px; line-height: 26px; }
body .home-tile-status { color: var(--jam-ink-muted); font-size: 14px; line-height: 20px; }
body .home-tile:hover { box-shadow: inset 0 0 0 1px var(--jam-ink); }
body .home-tile:focus-visible { outline: 3px solid var(--jam-focus); outline-offset: 2px; }
/* Narrow phones (#619): the bar holds the mark, the wordmark, Home, Catalogue and the menu button. */
@media (max-width: 480px) {
  body .jam-brand { gap: 6px; }
  body .jam-wordmark { font-size: 16px; line-height: 20px; }
  body .jam-mark { width: 24px; height: 24px; font-size: 14px; line-height: 24px; }
}
/* A game on a phone keeps the whole bar for its own buttons (#404): no brand there (see the game's bar). */
@media (max-width: 759px) {
  body.in-game .jam-brand { display: none; }
}
/* Seasonal note on a Home tile (#373): words, not colour alone. */
.home-tile-season { display: block; font-size: var(--font-sm, 0.85rem); font-weight: 700; }

/* Beta prototypes use the shared catalogue tokens and remain easy to tap. */
.beta-section { margin: var(--space-md); }
.catalogue-page .beta-section .home-section-heading { margin: 0 0 var(--space-xs); }
.beta-description { margin: 0 0 var(--space-sm); color: var(--jam-ink); }
.beta-games { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: var(--space-sm); }
.beta-game { min-height: var(--tap-min); padding: var(--space-sm); border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); color: var(--color-text); text-align: left; font: inherit; cursor: pointer; }
.beta-game:focus-visible { outline: 3px solid var(--jam-focus); outline-offset: 2px; }

/* Help / FAQ (#459) */
.help-topic { display: flex; flex-direction: column; gap: var(--space-sm); }
.help-heading, .help-subheading, .help-text, .help-note { margin: 0; }
.help-note { font-weight: 600; }
.help-benefits { margin: 0; padding-left: var(--space-lg); line-height: 1.4; }
/* One standard width for the guide buttons (#555: buttons in a row are the same width); long names wrap. */
.help-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-sm); }
.help-picker > .help-pick { width: 100%; min-width: 0; white-space: normal; line-height: 1.15; }
.help-pick[aria-pressed="true"] { border-color: var(--color-accent); border-width: 2px; font-weight: 600; }
.help-guide { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: var(--space-md); display: flex; flex-direction: column; gap: var(--space-sm); }
.help-figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: var(--space-xs); }
.help-art { width: auto; max-width: 100%; height: 140px; }
.help-caption { font-size: var(--font-sm); color: var(--color-text-muted); }
.help-steps { margin: 0; padding-left: var(--space-lg); line-height: 1.4; }
.help-vendor { align-self: flex-start; }
