/* ==========================================================================
   Solitaire UI kit. Owner: Art / UI kit.
   Tokens, themes, components, app chrome, card faces, card backs, slot markers.
   Loaded before styles.css. Living style guide: /kit.html
   Selectors for themes, backs and the four-colour deck are unscoped attribute selectors
   ([data-theme=...], not html[data-theme=...]) so any element can preview a theme (kit.html does).
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */
:root {
  /* type */
  --font-ui: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-card: system-ui, -apple-system, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: var(--font-display); /* pair with font-variant-numeric: tabular-nums (.tnum) */
  --fs-2xs: 10px;
  --fs-xs: 11px;
  --fs-sm: 13px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 20px;
  --fs-2xl: 26px;
  --fs-3xl: 34px;
  --fs-xxl: var(--fs-2xl);
  --lh-tight: 1.15;
  --lh-body: 1.4;
  --tracking-caps: 0.08em;

  /* spacing (4 px grid) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;

  /* radii */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 999px;
  /* Card radius follows the nearest --cw: it is re-declared on .card, .slot and .back-swatch (section 6), so a
     preview with its own --cw (kit.html, settings thumbnails) gets its own radius. */
  --r-card: calc(var(--cw, 48px) * 0.1);

  /* touch */
  --tap: 44px;
  --tap-lg: 52px;

  /* shadows */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-3: 0 22px 56px rgba(0, 0, 0, 0.5), 0 4px 14px rgba(0, 0, 0, 0.28);
  /* Cards in a pile share one spot, so their shadows add up. The edge ring is inset (it can never stack past the
     top card) and the drop shadow is tucked under the card (spread -1.2 px, blur 1 px: its sides stay inside the
     card box, only the 1.5 px drop shows below): a full pile shows at most a 1 px
     thickness line along its bottom edge, never an outline. Fully covered cards (.card.buried, set by board.js)
     drop their shadow altogether. */
  --shadow-card: inset 0 0 0 0.6px var(--c-card-edge), 0 1.5px 1px -1.2px rgba(0, 0, 0, 0.45);
  --shadow-back: 0 1.5px 1px -1.2px rgba(0, 0, 0, 0.45);
  --shadow-lift: 0 14px 26px rgba(0, 0, 0, 0.38), 0 3px 6px rgba(0, 0, 0, 0.22), inset 0 0 0 0.6px var(--c-card-edge);

  /* motion */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in-out: cubic-bezier(0.45, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.3, 1.45, 0.5, 1);
  --dur-instant: 80ms;
  --dur-fast: 140ms;
  --dur-med: 220ms;
  --dur-slow: 340ms;

  /* layers */
  --z-hud: 10;
  --z-toast: 7200; /* above sheets and the win dialog (screens: 7000-7101), below the updater */
  --z-sheet: 6000;
  --z-dialog: 7000;
  --z-updater: 9000;

  /* colours that do not change with the theme (card and court colours that charcoal dims are in section 2) */
  --c-card-edge: rgba(20, 16, 8, 0.24);
  --court-gold: #e9b640;
  --court-gold-edge: #8a5d0c;
  --court-skin: #f8e2c8;
  --court-ink: #2a2320;
  --c-danger: #c8372f;      /* fills (danger buttons, badges); white text on it is 5.1:1 */
  --c-danger-text: #ff8f86; /* danger-coloured text on dark surfaces */
  --c-danger-ink: #ffffff;
  --c-success: #4cc27e;     /* success-coloured text/icons on dark surfaces */
  --c-success-fill: #1f7a4a;
}

/* 2. Themes ---------------------------------------------------------------- */
/* green: classic felt (default) */
:root,
[data-theme="green"] {
  --c-felt-1: #1c7351;
  --c-felt-2: #115438;
  --c-felt-3: #082e20;
  --c-chrome: #0c3d2b;
  --c-surface: #10271e;
  --c-surface-2: #183729;
  --c-surface-3: #214535;
  --c-line: rgba(255, 255, 255, 0.1);
  --c-scrim: rgba(2, 12, 8, 0.56);
  --c-ink: #f5f2e9;
  --c-ink-dim: #b9c9bf;
  --c-ink-faint: rgba(245, 242, 233, 0.4); /* non-text only (chevrons, dividers): fails AA as text */
  --c-accent: #f6c552;
  --c-accent-ink: #231a03;
  --c-accent-soft: rgba(246, 197, 82, 0.16);
  --c-glass: rgba(0, 20, 12, 0.26);
  --c-slot: rgba(255, 255, 255, 0.06);
  --c-slot-edge: rgba(255, 255, 255, 0.2);
  --c-slot-mark: rgba(255, 255, 255, 0.3);
  --felt-noise: 0.55;
}
/* blue: midnight */
[data-theme="blue"] {
  --c-felt-1: #22507f;
  --c-felt-2: #16345a;
  --c-felt-3: #0a1830;
  --c-chrome: #0f2442;
  --c-surface: #0f1b31;
  --c-surface-2: #172841;
  --c-surface-3: #213453;
  --c-line: rgba(255, 255, 255, 0.1);
  --c-scrim: rgba(3, 8, 18, 0.58);
  --c-ink: #f1f4fa;
  --c-ink-dim: #b3c1d6;
  --c-ink-faint: rgba(241, 244, 250, 0.4);
  --c-accent: #f6c552;
  --c-accent-ink: #231a03;
  --c-accent-soft: rgba(246, 197, 82, 0.16);
  --c-glass: rgba(2, 10, 24, 0.28);
  --c-slot: rgba(255, 255, 255, 0.06);
  --c-slot-edge: rgba(255, 255, 255, 0.2);
  --c-slot-mark: rgba(255, 255, 255, 0.3);
  --felt-noise: 0.5;
}
/* Card and court colours. Every theme declares them, not only :root, so a [data-theme] preview inside a page on
   another theme (settings pickers, kit.html) never inherits the page's cards. Charcoal overrides them below. */
:root,
[data-theme="green"],
[data-theme="blue"],
[data-theme="burgundy"] {
  --c-card: #fcfbf7;
  --c-card-2: #f3f0e7;
  --c-red: #c8283a;
  --c-black: #1b2130;
  --c-diamond: #1d5fc2;
  --c-club: #17783a;
  --court-pale: #fffdf7;
}
/* charcoal: dark and low glare (cards a touch dimmer, no bright whites anywhere) */
[data-theme="charcoal"] {
  --c-felt-1: #232528;
  --c-felt-2: #141517;
  --c-felt-3: #000000;
  --c-chrome: #000000;
  --c-surface: #121315;
  --c-surface-2: #1c1d20;
  --c-surface-3: #27292d;
  --c-line: rgba(255, 255, 255, 0.09);
  --c-scrim: rgba(0, 0, 0, 0.66);
  --c-ink: #e7e4dd;
  --c-ink-dim: #a9a6a0;
  --c-ink-faint: rgba(231, 228, 221, 0.38);
  --c-accent: #e2b650;
  --c-accent-ink: #1e1602;
  --c-accent-soft: rgba(226, 182, 80, 0.15);
  --c-glass: rgba(255, 255, 255, 0.05);
  --c-slot: rgba(255, 255, 255, 0.045);
  --c-slot-edge: rgba(255, 255, 255, 0.16);
  --c-slot-mark: rgba(255, 255, 255, 0.24);
  --c-card: #e9e6de;
  --c-card-2: #dedad0;
  --c-red: #b02636;
  --c-black: #16191f;
  --c-diamond: #1c56ad;
  --c-club: #146b33;
  --court-pale: #f1eee6;
  --felt-noise: 0.35;
}
/* burgundy */
[data-theme="burgundy"] {
  --c-felt-1: #7d2a3c;
  --c-felt-2: #561827;
  --c-felt-3: #2c0912;
  --c-chrome: #3f0f1b;
  --c-surface: #2a1219;
  --c-surface-2: #3a1c25;
  --c-surface-3: #4a2631;
  --c-line: rgba(255, 255, 255, 0.1);
  --c-scrim: rgba(20, 3, 8, 0.58);
  --c-ink: #f8efe9;
  --c-ink-dim: #dcbcc2;
  --c-ink-faint: rgba(248, 239, 233, 0.4);
  --c-accent: #f6c552;
  --c-accent-ink: #231a03;
  --c-accent-soft: rgba(246, 197, 82, 0.16);
  --c-glass: rgba(30, 2, 10, 0.26);
  --c-slot: rgba(255, 255, 255, 0.06);
  --c-slot-edge: rgba(255, 255, 255, 0.2);
  --c-slot-mark: rgba(255, 255, 255, 0.3);
  --felt-noise: 0.55;
}

/* Derived tokens and legacy names used by styles.css and older markup, recomputed wherever a theme applies. */
:root,
[data-theme] {
  --c-bg: var(--c-felt-2);
  --swatch: radial-gradient(130% 90% at 50% 38%, var(--c-felt-1), var(--c-felt-2) 52%, var(--c-felt-3));
  --felt-1: var(--c-felt-1);
  --felt-2: var(--c-felt-3);
  --ink: var(--c-ink);
  --ink-dim: var(--c-ink-dim);
  --card: var(--c-card);
  --card-edge: var(--c-card-edge);
  --red: var(--c-red);
  --black: var(--c-black);
  --accent: var(--c-accent);
  --slot: var(--c-slot);
  --slot-edge: var(--c-slot-edge);
  --sheet: var(--c-surface);
  --back-1: #2a4fa3;
  --back-2: #1a347a;
  color-scheme: dark;
}

/* Theme previews without switching the theme (settings pickers): background: var(--swatch). */
[data-theme-swatch="green"] { --swatch: radial-gradient(130% 90% at 50% 38%, #1c7351, #115438 52%, #082e20); }
[data-theme-swatch="blue"] { --swatch: radial-gradient(130% 90% at 50% 38%, #22507f, #16345a 52%, #0a1830); }
[data-theme-swatch="charcoal"] { --swatch: radial-gradient(130% 90% at 50% 38%, #232528, #141517 52%, #000000); }
[data-theme-swatch="burgundy"] { --swatch: radial-gradient(130% 90% at 50% 38%, #7d2a3c, #561827 52%, #2c0912); }

/* 3. Base ------------------------------------------------------------------ */
/* Felt: light pool in the middle, falloff to the edges, and a fine fibre noise (inline SVG, no network). */
.felt,
body {
  background-color: var(--c-felt-3);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n' x='0' y='0'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 .9 0 0 0 -.38'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(130% 90% at 50% 38%, var(--c-felt-1) 0%, var(--c-felt-2) 52%, var(--c-felt-3) 100%);
  background-size: 180px 180px, 100% 100%;
  background-blend-mode: soft-light, normal;
}
/* Painted felt (art/table, a seamless tile per theme) under a soft light pool and edge falloff. */
[data-theme="green"] { --felt-tex: url("art/table/green.webp"); }
[data-theme="blue"] { --felt-tex: url("art/table/blue.webp"); }
[data-theme="charcoal"] { --felt-tex: url("art/table/charcoal.webp"); }
[data-theme="burgundy"] { --felt-tex: url("art/table/burgundy.webp"); }
.felt,
body {
  background-image:
    radial-gradient(130% 90% at 50% 38%, rgba(255, 255, 255, 0.07) 0%, rgba(0, 0, 0, 0) 52%, rgba(0, 0, 0, 0.42) 100%),
    var(--felt-tex),
    radial-gradient(130% 90% at 50% 38%, var(--c-felt-1) 0%, var(--c-felt-2) 52%, var(--c-felt-3) 100%);
  background-size: 100% 100%, 256px 256px, 100% 100%;
  background-blend-mode: normal;
}
body {
  color: var(--c-ink);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
.num,
.tnum {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
/* Components below set display; the hidden attribute must still hide them anywhere (not only inside #app). */
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible,
.kit-focus {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
svg.i,
.btn svg,
.icon-btn svg {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* 4. Components ------------------------------------------------------------ */

/* .btn -------------------------------------------------------------------- */
/* Buttons are content-width; .btn.block is full width. The legacy v0.1 win button (<button class="primary"
   id="btn-win-new"> without .btn) is matched on its own, so no other .primary button stretches. */
.btn,
.win-card > button.primary:not(.btn) {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap-lg); padding: 0 var(--sp-5);
  border: 0; border-radius: var(--r-md);
  background: var(--c-surface-2); color: var(--c-ink);
  font: 650 var(--fs-md) / 1 var(--font-ui); letter-spacing: 0.005em;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--c-line);
  transition: transform var(--dur-fast) var(--ease-out), background-color var(--dur-fast), filter var(--dur-fast), box-shadow var(--dur-fast);
  touch-action: manipulation;
}
.btn:active,
.btn.is-pressed { transform: scale(0.97); background: var(--c-surface-3); }
.btn.primary,
.win-card > button.primary:not(.btn) {
  background: var(--c-accent); color: var(--c-accent-ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 6px 16px -6px rgba(0, 0, 0, 0.5);
  font-weight: 750;
}
.btn.primary:active,
.btn.primary.is-pressed,
.win-card > button.primary:not(.btn):active { transform: scale(0.97); filter: brightness(0.93); background: var(--c-accent); }
.btn.ghost { background: transparent; box-shadow: none; color: var(--c-ink); }
.btn.ghost:active,
.btn.ghost.is-pressed { background: rgba(255, 255, 255, 0.08); }
.btn.danger { background: var(--c-danger); color: var(--c-danger-ink); box-shadow: none; }
.btn.danger:active { background: var(--c-danger); filter: brightness(0.92); }
.btn.block,
.win-card > button.primary:not(.btn) { width: 100%; }
/* Small buttons stay visually compact (36 px) but their hit area is 44 px tall and at least 44 px wide. */
.btn.small { position: relative; min-height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.small::after {
  content: ""; position: absolute;
  top: min(0px, calc((100% - var(--tap)) / 2)); bottom: min(0px, calc((100% - var(--tap)) / 2));
  left: min(0px, calc((100% - var(--tap)) / 2)); right: min(0px, calc((100% - var(--tap)) / 2));
}
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }
/* A disabled primary goes neutral (accent at 40% over the felt reads as a muddy olive). */
.btn.primary:disabled,
.btn.primary[aria-disabled="true"] { opacity: 0.6; background: var(--c-surface-2); color: var(--c-ink-dim); box-shadow: inset 0 0 0 1px var(--c-line); }
.btn-row { display: flex; gap: var(--sp-2); }
.btn-row > .btn { flex: 1; }

/* .icon-btn --------------------------------------------------------------- */
.icon-btn,
.hud-btn {
  -webkit-appearance: none; appearance: none;
  display: inline-grid; place-items: center; flex: none;
  width: var(--tap); height: var(--tap); padding: 0;
  border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--c-ink); cursor: pointer; font-family: inherit;
  transition: background-color var(--dur-fast), transform var(--dur-fast) var(--ease-out);
  touch-action: manipulation;
}
.icon-btn:active,
.icon-btn.is-pressed,
.hud-btn:active { background: rgba(255, 255, 255, 0.12); transform: scale(0.92); }
.icon-btn.filled { background: var(--c-glass); box-shadow: inset 0 0 0 1px var(--c-line); }
.icon-btn:disabled { opacity: 0.35; pointer-events: none; }

/* .sheet + .sheet-row ------------------------------------------------------ */
.sheet,
#sheet {
  background: var(--c-surface); color: var(--c-ink);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: 0 -1px 0 var(--c-line), 0 -18px 48px rgba(0, 0, 0, 0.45);
}
.sheet-grip { width: 40px; height: 5px; border-radius: var(--r-pill); background: rgba(255, 255, 255, 0.22); margin: 6px auto 12px; }
.sheet h2,
#sheet h2 { margin: 0 0 var(--sp-3); font: 750 var(--fs-xl) / var(--lh-tight) var(--font-display); letter-spacing: -0.01em; }
.sheet-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  min-height: var(--tap-lg); padding: var(--sp-2) var(--sp-4);
  background: var(--c-surface-2);
  font-family: inherit; font-size: var(--fs-md); font-weight: 550; text-align: left; color: var(--c-ink);
  width: 100%; border: 0;
}
/* Tappable rows. A toggle row is a <label class="sheet-row">, so the whole 52 px row flips the switch. */
button.sheet-row,
a.sheet-row,
label.sheet-row { cursor: pointer; transition: background-color var(--dur-fast); -webkit-tap-highlight-color: transparent; }
button.sheet-row:active,
button.sheet-row.is-pressed,
a.sheet-row:active,
label.sheet-row:active { background: var(--c-surface-3); }
.sheet-row > :first-child { flex: 1; min-width: 0; }
.sheet-row .value,
.sheet-row small { color: var(--c-ink-dim); font-weight: 500; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.sheet-row .sub { display: block; color: var(--c-ink-dim); font-size: var(--fs-xs); font-weight: 500; margin-top: 2px; }
.sheet-row .chev { width: 18px; height: 18px; color: var(--c-ink-faint); }
/* Rows stack into a rounded group, iOS-settings style. */
.group { border-radius: var(--r-md); overflow: hidden; margin: 0 0 var(--sp-4); background: var(--c-surface-2); }
.group > .sheet-row + .sheet-row { box-shadow: inset 0 1px 0 var(--c-line); }
.sheet-row:only-child,
.sheet > .sheet-row,
#sheet-body > .sheet-row { border-radius: var(--r-md); margin-bottom: var(--sp-2); }

/* legacy .sheet-btn (ui.js v0.1) renders as a sheet row */
.sheet-btn {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: var(--sp-3);
  min-height: var(--tap-lg); padding: var(--sp-2) var(--sp-4); margin: 0 0 var(--sp-2);
  border-radius: var(--r-md); background: var(--c-surface-2); color: var(--c-ink);
  font-size: var(--fs-md); font-weight: 600; text-align: left;
  transition: background-color var(--dur-fast), transform var(--dur-fast) var(--ease-out);
}
.sheet-btn:active { background: var(--c-surface-3); transform: scale(0.99); }
.sheet-btn small { color: var(--c-ink-dim); font-weight: 500; font-size: var(--fs-sm); }

/* .toggle ----------------------------------------------------------------- */
input.toggle {
  -webkit-appearance: none; appearance: none; margin: 0; flex: none;
  position: relative; width: 52px; height: 32px; border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.16); cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  transition: background-color var(--dur-med) var(--ease-out);
}
input.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  transition: transform var(--dur-med) var(--ease-spring);
}
/* The switch is drawn 32 px tall; its hit area is 44 px (::before), and inside a label.sheet-row the whole row. */
input.toggle::before { content: ""; position: absolute; inset: -6px -4px; }
input.toggle:checked { background: var(--c-accent); box-shadow: none; }
input.toggle:checked::after { transform: translateX(20px); }
input.toggle:disabled { opacity: 0.4; }

/* .segmented -------------------------------------------------------------- */
.segmented {
  /* 44 px segments in a 50 px track */
  display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.28); box-shadow: inset 0 0 0 1px var(--c-line);
}
.segmented > button {
  -webkit-appearance: none; appearance: none; border: 0; cursor: pointer;
  min-width: 48px; min-height: var(--tap); padding: 0 var(--sp-3); border-radius: calc(var(--r-sm) - 3px);
  background: transparent; color: var(--c-ink-dim);
  font: 650 var(--fs-sm) / 1 var(--font-ui); font-variant-numeric: tabular-nums;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.segmented > button[aria-pressed="true"] { background: var(--c-ink); color: var(--c-surface); box-shadow: var(--shadow-1); }
.segmented > button:active { transform: scale(0.96); }
.segmented.block { display: flex; }
.segmented.block > button { flex: 1; }

/* .stat-tile -------------------------------------------------------------- */
.stat-grid,
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); margin: 0 0 var(--sp-4); }
.stat-tile,
.stats-grid > div {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 68px; padding: var(--sp-3) var(--sp-2); border-radius: var(--r-md);
  background: var(--c-surface-2); text-align: center;
}
.stat-tile .v,
.stat-tile b,
.stats-grid b {
  display: block; font: 750 var(--fs-xl) / 1.1 var(--font-display); color: var(--c-ink);
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.stat-tile .l,
.stat-tile span:not(.badge),
.stats-grid span { font-size: var(--fs-xs); font-weight: 600; color: var(--c-ink-dim); letter-spacing: 0.02em; }
.stat-tile.accent .v,
.stat-tile.accent b { color: var(--c-accent); }

/* .toast ------------------------------------------------------------------ */
/* One line for any normal message, never over the cards: centred just above the toolbar, over the empty felt
   near the thumb. The box is as wide as its text (width: max-content, centred with auto margins; a left: 50% +
   translate box would be capped at half the screen and wrap early), up to min(88vw, 420px). A long message
   wraps into a rounded box (--r-lg), a one-line message is a pill (the radius is more than half its height).
   --tb-h is the toolbar height (screens keeps it current); the fallback matches the v0.1 toolbar.
   #app > #toast (2 ids) outranks the v0.1 #toast block in styles.css whichever side a merge keeps. */
.toast,
#app > #toast {
  position: fixed; z-index: var(--z-toast);
  left: 0; right: 0; top: auto; bottom: calc(var(--tb-h, calc(var(--safe-b, 0px) + 66px)) + var(--sp-3));
  width: max-content; max-width: min(88vw, 420px); margin-inline: auto;
  transform: translateY(8px) scale(0.98);
  padding: 10px 16px; border-radius: var(--r-lg);
  background: rgba(14, 16, 18, 0.94); color: #f7f5ef;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  font-size: var(--fs-sm); font-weight: 600; line-height: 1.3; text-align: center; text-wrap: balance;
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-med) var(--ease-out), transform var(--dur-med) var(--ease-out);
}
.toast.show,
#app > #toast.show { opacity: 1; transform: none; }
/* Keep clear of the unwinnable banner (screens) when it is up; over a sheet, sit in the scrim above it. The banner
   sits 6 px above the toolbar and is about 82 px tall at 360 with its text on four lines; --banner-h, if screens
   sets it, gives the exact height. */
#app:has(> #banner:not([hidden])) > #toast { bottom: calc(var(--tb-h, calc(var(--safe-b, 0px) + 66px)) + 6px + var(--banner-h, 96px) + var(--sp-3)); }
#app:has(> #sheet:not([hidden])) > #toast { top: calc(var(--safe-t, 0px) + var(--sp-3)); bottom: auto; transform: translateY(-8px) scale(0.98); }
#app:has(> #sheet:not([hidden])) > #toast.show { transform: none; }

/* .badge ------------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.12); color: var(--c-ink);
  font: 700 var(--fs-xs) / 1 var(--font-ui); letter-spacing: 0.02em; font-variant-numeric: tabular-nums;
  white-space: nowrap; vertical-align: middle;
}
.badge.accent { background: var(--c-accent); color: var(--c-accent-ink); }
.badge.success { background: var(--c-success-fill); color: #fff; }
.badge.danger { background: var(--c-danger); color: var(--c-danger-ink); }
.badge.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--c-slot-edge); }

/* .dialog ----------------------------------------------------------------- */
.dialog,
.win-card {
  width: min(88vw, 360px); padding: var(--sp-6) var(--sp-5) var(--sp-5); border-radius: var(--r-xl);
  background: var(--c-surface); color: var(--c-ink); text-align: center;
  box-shadow: var(--shadow-3), inset 0 0 0 1px var(--c-line);
}
.dialog h2,
.dialog .title { margin: 0 0 var(--sp-2); font: 800 var(--fs-2xl) / var(--lh-tight) var(--font-display); letter-spacing: -0.015em; }
.dialog p { margin: 0 0 var(--sp-4); color: var(--c-ink-dim); }
.dialog .actions { display: grid; gap: var(--sp-2); margin-top: var(--sp-5); }

/* .list ------------------------------------------------------------------- */
.list { list-style: none; margin: 0 0 var(--sp-4); padding: 0; border-radius: var(--r-md); overflow: hidden; background: var(--c-surface-2); }
.list > li,
.list > .list-item {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  min-height: 48px; padding: var(--sp-2) var(--sp-4); font-size: var(--fs-md);
}
.list > li + li,
.list > .list-item + .list-item { box-shadow: inset 0 1px 0 var(--c-line); }
.list .meta { color: var(--c-ink-dim); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.list.plain { background: transparent; }
.list.bullets > li { justify-content: flex-start; align-items: baseline; min-height: 0; padding: 6px 0 6px 18px; position: relative; color: var(--c-ink); }
.list.bullets > li::before { content: ""; position: absolute; left: 4px; top: 0.95em; width: 6px; height: 6px; border-radius: 50%; background: var(--c-accent); }
.list.bullets > li + li { box-shadow: none; }

/* .section-title ---------------------------------------------------------- */
.section-title {
  margin: var(--sp-5) var(--sp-1) var(--sp-2);
  font: 700 var(--fs-xs) / 1.2 var(--font-ui); letter-spacing: var(--tracking-caps); text-transform: uppercase;
  color: var(--c-ink-dim);
}
.section-title:first-child { margin-top: var(--sp-1); }

/* 5. App chrome (visual only; element ids and structure belong to screens) --- */
#hud { gap: var(--sp-2); padding-left: max(var(--sp-2), env(safe-area-inset-left, 0px)); padding-right: max(var(--sp-2), env(safe-area-inset-right, 0px)); }
.hud-btn svg,
.tool svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hud-stats {
  flex: 1 1 auto; display: flex; justify-content: center; align-items: stretch; gap: 0;
  max-width: 300px; margin: 0 auto; padding: 5px 4px; border-radius: var(--r-pill);
  background: var(--c-glass); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.07);
}
.hud-stats .stat { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; min-width: 0; padding: 0 6px; }
.hud-stats .stat + .stat { box-shadow: -1px 0 0 rgba(255, 255, 255, 0.1); }
.stat-label { font: 700 var(--fs-2xs) / 1.2 var(--font-ui); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--c-ink-dim); }
.stat-val { font: 700 var(--fs-lg) / 1.15 var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; color: var(--c-ink); white-space: nowrap; }

#toolbar {
  gap: var(--sp-1);
  padding-left: max(var(--sp-2), env(safe-area-inset-left, 0px)); padding-right: max(var(--sp-2), env(safe-area-inset-right, 0px));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.34), rgba(0, 0, 0, 0.12) 70%, rgba(0, 0, 0, 0));
}
.tool {
  position: relative; flex: 1 1 0; max-width: 96px; min-height: var(--tap-lg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 6px 4px; border-radius: var(--r-md); color: var(--c-ink);
  font: 650 var(--fs-xs) / 1.1 var(--font-ui); letter-spacing: 0.02em;
  border: 0; background: transparent; cursor: pointer;
  transition: background-color var(--dur-fast), transform var(--dur-fast) var(--ease-out), opacity var(--dur-med);
  touch-action: manipulation;
}
.tool:active { background: rgba(255, 255, 255, 0.1); transform: scale(0.94); }
.tool:disabled { opacity: 0.32; }

#sheet-backdrop {
  background: var(--c-scrim);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  animation: kitFade var(--dur-med) var(--ease-out);
}
#sheet { padding: var(--sp-1) var(--sp-4) calc(var(--safe-b, 0px) + var(--sp-4)); max-height: 88vh; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain; }
#sheet-body { -webkit-user-select: none; user-select: none; }

#win { background: var(--c-scrim); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.win-card { position: relative; overflow: hidden; }
.win-title { position: relative; margin-bottom: var(--sp-2); font: 800 var(--fs-3xl) / var(--lh-tight) var(--font-display); letter-spacing: -0.02em; color: var(--c-accent); }
.win-stats { position: relative; margin-bottom: var(--sp-5); color: var(--c-ink-dim); line-height: 1.65; font-variant-numeric: tabular-nums; }
.win-stats b { color: var(--c-ink); font-weight: 750; }

#updater {
  position: fixed; inset: 0; z-index: var(--z-updater); display: grid; place-items: center;
  background: radial-gradient(90% 60% at 50% 40%, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.82)), var(--c-felt-3);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: kitFade var(--dur-slow) var(--ease-out);
}
.upd-card { width: min(82vw, 300px); text-align: center; color: var(--c-ink); }
/* The loader is a card turning over, back to face and back again. */
.upd-spinner {
  position: relative; width: 44px; height: 62px; margin: 0 auto var(--sp-5);
  border: 0; border-radius: 6px; transform-style: preserve-3d;
  animation: kitCardTurn 1.6s var(--ease-in-out) infinite;
}
.upd-spinner::before,
.upd-spinner::after {
  content: ""; position: absolute; inset: 0; border-radius: 6px;
  -webkit-backface-visibility: hidden; backface-visibility: hidden; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}
.upd-spinner::before {
  border: 3px solid #f7f4ec;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M0 0L8 8M8 0L0 8' stroke='%23fff' stroke-opacity='.22' stroke-width='.9'/%3E%3C/svg%3E") 0 0 / 7px 7px,
    linear-gradient(160deg, #2c56b0, #183576);
}
.upd-spinner::after {
  transform: rotateY(180deg);
  background: #fcfbf7 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath fill='%23c8283a' d='M50 92C46 86 4 62 4 32C4 16 16 6 29 6C39 6 46 12 50 20C54 12 61 6 71 6C84 6 96 16 96 32C96 62 54 86 50 92Z'/%3E%3C/svg%3E") center / 26px 26px no-repeat;
}
.upd-title { font: 750 var(--fs-xl) / var(--lh-tight) var(--font-display); letter-spacing: -0.01em; }
.upd-ver { margin-top: var(--sp-1); color: var(--c-accent); font: 700 var(--fs-sm) / 1.3 var(--font-ui); font-variant-numeric: tabular-nums; }
.upd-notes { margin: var(--sp-2) 0 var(--sp-4); min-height: 1em; color: var(--c-ink-dim); font-size: var(--fs-sm); line-height: 1.45; }
.upd-bar { height: 4px; border-radius: var(--r-pill); background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.upd-fill { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--c-accent), #ffe39a); transition: width var(--dur-med) var(--ease-out); }
.upd-step { margin-top: var(--sp-2); min-height: 1.3em; color: var(--c-ink-dim); font: 600 var(--fs-xs) / 1.3 var(--font-ui); font-variant-numeric: tabular-nums; }
/* phases (platform sets #updater[data-phase]): download shows the bar, install/restart pulse it full */
#updater[data-phase="install"] .upd-fill,
#updater[data-phase="restart"] .upd-fill { width: 100% !important; animation: kitPulse 1.1s var(--ease-in-out) infinite; }
#updater[hidden] { display: none; }
.upd-sub { margin-top: var(--sp-3); color: var(--c-ink-dim); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.02em; }

@keyframes kitFade { from { opacity: 0; } }
@keyframes kitPulse { 50% { opacity: 0.55; } }
@keyframes kitCardTurn {
  0%, 12% { transform: rotateY(0deg); }
  44%, 56% { transform: rotateY(180deg); }
  88%, 100% { transform: rotateY(360deg); }
}

/* 6. Board: slots and empty-pile markers ---------------------------------- */
/* Radius from the local card width (a thumbnail with its own --cw gets its own radius). */
.card,
.slot,
.back-swatch { --r-card: calc(var(--cw, 48px) * 0.1); }
.slot {
  border-radius: var(--r-card);
  background: var(--c-slot);
  box-shadow: inset 0 0 0 1.5px var(--c-slot-edge), inset 0 2px 6px rgba(0, 0, 0, 0.14);
  color: var(--c-slot-mark);
}
.slot .mk { display: block; pointer-events: none; }
.slot .mk-suit { width: 52%; height: 52%; fill: none; stroke: currentColor; stroke-width: 5; stroke-linejoin: round; opacity: 0.95; }
.slot .mk-k { font: 750 calc(var(--cw, 48px) * 0.46) / 1 var(--font-card); letter-spacing: -0.02em; opacity: 0.9; }
.slot.stock-slot { cursor: pointer; }
.slot.stock-slot .mk { width: 46%; height: 46%; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.slot.stock-slot .mk-recycle { display: none; }
.slot.stock-slot .mk-empty { width: 34%; height: 34%; stroke-width: 1.8; opacity: 0.8; }
/* Stock empty with cards in the waste: invite the tap to turn the waste over. */
.slot.stock-slot.empty-recycle { color: var(--c-ink); background: rgba(255, 255, 255, 0.1); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.34); }
.slot.stock-slot.empty-recycle .mk-recycle { display: block; }
.slot.stock-slot.empty-recycle .mk-empty { display: none; }
/* Nothing left anywhere: quiet dashed outline. */
.slot.stock-slot:not(.empty-recycle) { box-shadow: none; background: transparent; outline: 1.5px dashed var(--c-slot-edge); outline-offset: -1.5px; }
.slot.waste-slot { background: transparent; box-shadow: none; }

/* 7. Cards: faces ----------------------------------------------------------- */
.card .face,
.card .back { border-radius: var(--r-card); box-shadow: var(--shadow-card); }
.card .back { box-shadow: var(--shadow-back); }
/* A card fully covered by another card in the same pile (stock, waste under the fan, foundations): board.js sets
   .buried, and the card casts nothing, so a pile of 24 has exactly the edge of one card. */
.card.buried .face,
.card.buried .back { box-shadow: none; }
.card .face {
  color: var(--c-black);
  background: linear-gradient(180deg, var(--c-card) 55%, var(--c-card-2));
  overflow: hidden; contain: paint;
}
.face.red { color: var(--c-red); }
.face.black { color: var(--c-black); }
[data-four-color="true"] .face.s-2 { color: var(--c-diamond); }
[data-four-color="true"] .face.s-3 { color: var(--c-club); }
.face svg { position: absolute; display: block; fill: currentColor; overflow: visible; }
/* Corner index. Rank top left and a big suit top right: the strip that shows in a vertical run (the rank ends
   at about 0.41 cw). A small suit under the rank on the left edge: with the rank it fills the strip that shows
   in the draw-3 waste fan (0.32 cw and wider), so every fanned card shows its suit. It sits below the vertical-run
   strip, so tableau overlaps are unchanged. (.card .face ... selectors outrank the v0.1 .face .r rules.) */
.card .face .idx-r {
  position: absolute; left: calc(var(--cw) * 0.07); top: calc(var(--cw) * 0.02);
  font: 800 calc(var(--cw) * 0.41) / 1 var(--font-card); letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.card .face.rk-10 .idx-r { left: calc(var(--cw) * 0.035); letter-spacing: -0.06em; }
.face .idx-s { right: calc(var(--cw) * 0.07); top: calc(var(--cw) * 0.075); width: calc(var(--cw) * 0.3); height: calc(var(--cw) * 0.3); }
.face .idx-s2 { left: calc(var(--cw) * 0.08); top: calc(var(--cw) * 0.47); width: calc(var(--cw) * 0.2); height: calc(var(--cw) * 0.2); }
/* number cards: one big pip, low and centred */
.face .ctr { left: 50%; top: 63%; width: calc(var(--cw) * 0.56); height: calc(var(--cw) * 0.56); transform: translate(-50%, -50%); }
/* aces: a larger pip with a fine ring, set a little lower so the ring clears the small suit under the rank */
.face.ace .ctr { top: 65%; width: calc(var(--cw) * 0.56); height: calc(var(--cw) * 0.56); }
/* aces: a painted suit medallion (art/aces), a little lower so it clears the small suit under the rank */
.face.ace .ace-img { width: calc(var(--cw) * 0.7); height: calc(var(--cw) * 0.7); object-fit: contain; }
/* J/Q/K: painted portrait panel under the index; its top-left corner is cut away around the small suit */
.face .art { position: absolute; left: 6%; bottom: 5%; width: 88%; height: 63%; object-fit: cover; object-position: 50% 0;
  border-radius: calc(var(--cw) * 0.07); clip-path: polygon(27% 0, 100% 0, 100% 100%, 0 100%, 0 30%, 19% 30%, 27% 22%); }
.face img { position: absolute; display: block; pointer-events: none; -webkit-user-select: none; user-select: none; }

/* selection / drag lift (states belong to motion; this is only their look) */
.card.sel .face { box-shadow: 0 0 0 2.5px var(--c-accent), 0 4px 12px rgba(0, 0, 0, 0.4); }
.card.dragging .face,
.card.dragging .back { box-shadow: var(--shadow-lift); }

/* 8. Card backs ------------------------------------------------------------- */
/* Each back is a set of custom properties, so the nearest [data-back] wins: html for the game, any element
   for previews (settings swatches, kit.html). Sizes are factors of the card width (--cw). */
:root,
[data-back="classic"] {
  --back-edge: #f7f4ec;
  --back-line: rgba(255, 255, 255, 0.34);
  --back-color: #1f418f;
  --back-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Cpath d='M0 0L10 10M10 0L0 10' stroke='%23fff' stroke-opacity='.17' stroke-width='.8'/%3E%3C/svg%3E");
  --back-pattern-w: 0.17;
  --back-pattern-h: 0.17;
  --back-shade: radial-gradient(120% 90% at 50% 30%, #3160c4, #1d3c86 60%, #142b63);
  --back-emblem: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M50 3L97 50L50 97L3 50Z' fill='%231d3c86' stroke='%23f2c14e' stroke-width='6'/%3E%3Cpath d='M50 24L76 50L50 76L24 50Z' fill='%23f2c14e'/%3E%3C/svg%3E");
  --back-emblem-k: 0.34;
}
/* lattice: deep red trellis with gold knots */
[data-back="lattice"] {
  --back-edge: #f7f4ec;
  --back-line: rgba(255, 255, 255, 0.34);
  --back-color: #8d1c2f;
  --back-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Cpath d='M10 0L20 10L10 20L0 10Z' fill='none' stroke='%23f2c14e' stroke-opacity='.5' stroke-width='1.2'/%3E%3Ccircle cx='10' cy='0' r='1.8' fill='%23f2c14e' fill-opacity='.75'/%3E%3Ccircle cx='10' cy='20' r='1.8' fill='%23f2c14e' fill-opacity='.75'/%3E%3Ccircle cx='0' cy='10' r='1.8' fill='%23f2c14e' fill-opacity='.75'/%3E%3Ccircle cx='20' cy='10' r='1.8' fill='%23f2c14e' fill-opacity='.75'/%3E%3C/svg%3E");
  --back-pattern-w: 0.26;
  --back-pattern-h: 0.26;
  --back-shade: radial-gradient(120% 90% at 50% 30%, #b0283f, #871a2d 60%, #5e0f1e);
  --back-emblem: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='46' fill='%23871a2d' stroke='%23f2c14e' stroke-width='6'/%3E%3Cpath fill='%23f2c14e' d='M50 18C54 38 62 46 82 50C62 54 54 62 50 82C46 62 38 54 18 50C38 46 46 38 50 18Z'/%3E%3C/svg%3E");
  --back-emblem-k: 0.36;
}
/* waves: teal sea, layered swell lines */
[data-back="waves"] {
  --back-edge: #f7f4ec;
  --back-line: rgba(255, 255, 255, 0.34);
  --back-color: #0d5f69;
  --back-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='12'%3E%3Cpath d='M0 9C4 9 4 3 8 3S12 9 16 9 20 3 24 3' fill='none' stroke='%23fff' stroke-opacity='.3' stroke-width='1.3'/%3E%3C/svg%3E");
  --back-pattern-w: 0.3;
  --back-pattern-h: 0.15;
  --back-shade: linear-gradient(170deg, #178390, #0c5a64 55%, #073c44);
  --back-emblem: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='46' fill='%230c5a64' stroke='%23e9f6f3' stroke-width='5'/%3E%3Cpath d='M16 58C26 58 28 44 38 44S50 58 60 58 72 44 84 44' fill='none' stroke='%23e9f6f3' stroke-width='7' stroke-linecap='round'/%3E%3C/svg%3E");
  --back-emblem-k: 0.38;
}
/* mono: graphite, low glare (pairs with charcoal). It must read as a card, never as an empty slot: a light
   graphite frame (about 3:1 against the charcoal felt, so face-down strips read on a dimmed screen), a lighter
   inner hairline, a body lifted above the surface tokens and a filled spade medallion. Outlined suits are kept
   for empty-slot markers only. */
[data-back="mono"] {
  --back-edge: #61666f;
  --back-line: rgba(255, 255, 255, 0.3);
  --back-color: #22252a;
  --back-pattern: linear-gradient(transparent, transparent);
  --back-pattern-w: 1;
  --back-pattern-h: 1;
  --back-shade: linear-gradient(160deg, #33363d, #1f2126 62%, #1a1c20);
  --back-emblem: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='46' fill='%23191b1f' stroke='%238a8f99' stroke-width='5'/%3E%3Cpath fill='%23b9bec7' transform='translate(24 23.5) scale(.52)' d='M50 4C62 22 94 38 94 60C94 74 84 82 72 82C64 82 57 78 53 72C54 80 58 88 66 95H34C42 88 46 80 47 72C43 78 36 82 28 82C16 82 6 74 6 60C6 38 38 22 50 4Z'/%3E%3C/svg%3E");
  --back-emblem-k: 0.4;
}
.card .back,
.back-swatch {
  border: calc(var(--cw, 48px) * 0.055) solid var(--back-edge);
  background-color: var(--back-color);
  background-image: var(--back-pattern), var(--back-shade);
  background-size: calc(var(--cw, 48px) * var(--back-pattern-w)) calc(var(--cw, 48px) * var(--back-pattern-h)), 100% 100%;
  background-position: center;
  overflow: hidden;
}
.back-swatch { position: relative; display: block; width: var(--cw, 48px); height: var(--ch, 67px); border-radius: var(--r-card); box-shadow: var(--shadow-back); }
.card .back::before,
.back-swatch::before {
  content: ""; position: absolute; inset: calc(var(--cw, 48px) * 0.045);
  border-radius: calc(var(--r-card) * 0.6);
  box-shadow: inset 0 0 0 max(1px, calc(var(--cw, 48px) * 0.018)) var(--back-line);
  pointer-events: none;
}
.card .back::after,
.back-swatch::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: calc(var(--cw, 48px) * var(--back-emblem-k)); height: calc(var(--cw, 48px) * var(--back-emblem-k));
  transform: translate(-50%, -50%); pointer-events: none;
  background: var(--back-emblem) center / contain no-repeat;
}
/* Painted backs (art/backs, generated from art-source/backs): the image fills inside the ivory edge and replaces the
   pattern, hairline and emblem above. The drawn look stays as the fallback while the image loads. */
[data-back="classic"] { --back-img: url("art/backs/classic.webp"); }
[data-back="lattice"] { --back-img: url("art/backs/lattice.webp"); }
[data-back="waves"] { --back-img: url("art/backs/waves.webp"); }
[data-back="mono"] { --back-img: url("art/backs/mono.webp"); }
.card .back,
.back-swatch {
  background-image: var(--back-img), var(--back-shade);
  background-size: cover, 100% 100%;
}
.card .back::before,
.back-swatch::before,
.card .back::after,
.back-swatch::after { content: none; }

/* 9. Preferences --------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .upd-spinner { animation: none; }
  .btn, .icon-btn, .hud-btn, .tool, input.toggle, input.toggle::after, #app > #toast, .toast, .upd-fill { transition-duration: 1ms; }
  #sheet-backdrop, #updater, #updater[data-phase] .upd-fill { animation: none; }
}
@media (prefers-contrast: more) {
  :root, [data-theme] { --c-ink-dim: var(--c-ink); --c-slot-edge: rgba(255, 255, 255, 0.45); --c-slot-mark: rgba(255, 255, 255, 0.55); }
}
