/* ==========================================================================
   Shared game kit: the Tatreez palette in yarn and cloth (see docs/GAMES-THEME.md).
   Tokens, fabric/stitch/yarn/patch pieces, the five thread keyframes, and the shared chrome
   (header, buttons, modal, toast, hub and archive). Every game stylesheet loads after this file.
   Values match static/site.css; every text pair listed in docs/GAMES-THEME.md is WCAG AA.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* surfaces */
  --bg: #FBF5EA;              /* cream linen page */
  --card-bg: #FFFDF8;         /* patches, panels, empty tiles */
  --sand: #F2E7D3;            /* alternate panels, current-entry wash */
  --muted-bg: #E9DCC3;        /* cloth labels: keyboard keys, neutral badges */
  --border: #DCCBAE;          /* decorative hairlines */
  --control-border: #8A7760;  /* inputs: 3.96:1 on bg */

  /* text */
  --fg: #2A2118;              /* 14.56:1 on bg */
  --muted: #5E4F3F;           /* 7.26:1 on bg */
  --link: #4A5A27;            /* 6.95:1 on bg */
  --terra-text: #9A3F22;      /* eyebrows: 6.23:1 on bg */
  --accent: #3B4A1C;          /* primary button (olive) */
  --accent-fg: #FFFDF8;       /* 9.47:1 on accent */
  --accent-hover: #2E3A15;
  --focus: #A4482A;
  --error: #B3261E;

  /* thread colours (the site's --st-* stitch palette) and the text colour that sits on each */
  --thread-red: #8C1C24;      --on-thread-red: #FFFDF8;     /* 8.96 */
  --thread-terra: #B5532E;    --on-thread-terra: #FFFDF8;   /* 4.87 */
  --thread-olive: #55672C;    --on-thread-olive: #FFFDF8;   /* 6.14 */
  --thread-gold: #B8862E;     --on-thread-gold: #2A2118;    /* 4.88 */
  --thread-indigo: #2F4A6B;   --on-thread-indigo: #FFFDF8;  /* 8.93 */
  --thread-ink: #2A2118;      --on-thread-ink: #FFFDF8;     /* 15.54 */
  --thread-cream: #FFFDF8;    --on-thread-cream: #2A2118;   /* 15.54 */

  /* cloth and stitch */
  --fabric: #FBF5EA;
  --fabric-weave: rgba(94, 79, 63, .06);
  --stitch-color: #8A7760;    /* running-stitch outlines: 3.96:1 on bg */
  --stitch-w: 2px;
  --stitch-inset: 3px;        /* gap between a patch edge and its running stitch */
  --stitch-dash: 6 4;         /* SVG stroke-dasharray of a running stitch */

  /* game semantics mapped onto the threads */
  --c-yellow: var(--thread-gold);    --c-yellow-fg: var(--on-thread-gold);
  --c-green: var(--thread-olive);    --c-green-fg: var(--on-thread-olive);
  --c-blue: var(--thread-indigo);    --c-blue-fg: var(--on-thread-indigo);
  --c-purple: var(--thread-terra);   --c-purple-fg: var(--on-thread-terra);
  --tile-correct: #55672C;    --tile-correct-fg: #FFFDF8;   /* 6.14 */
  --tile-present: #B8862E;    --tile-present-fg: #2A2118;   /* 4.88 */
  --tile-absent: #3A3028;     --tile-absent-fg: #FFFDF8;    /* 12.65; 2.06:1 against --tile-correct */

  /* the stitch thread classes used by inline motifs (.s-r, .s-t, ...) read these */
  --st-red: var(--thread-red); --st-terra: var(--thread-terra); --st-olive: var(--thread-olive);
  --st-gold: var(--thread-gold); --st-indigo: var(--thread-indigo); --st-ink: var(--thread-ink);
  --st-cream: var(--thread-cream);

  /* type and shape */
  --font-sans: "Source Sans 3", "Source Sans Pro", "Segoe UI", system-ui, -apple-system, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
  --font-yarn: ui-rounded, "SF Pro Rounded", "Source Sans 3", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --radius: 12px;
  --radius-sm: 6px;

  /* motion */
  --ease-settle: cubic-bezier(.3, 1.45, .55, 1);   /* small overshoot */
  --ease-thread: cubic-bezier(.4, 0, .2, 1);
}

/* Night-sky dark mode: the same threads, brighter, on deep navy cloth. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111827; --card-bg: #1A2336; --sand: #0E1626; --muted-bg: #535F7A; --border: #2E3A55; --control-border: #7A88A8;
    --fg: #F4ECDD; --muted: #C9BEAA; --link: #B4C77A; --terra-text: #F0A27E;
    --accent: #B4C77A; --accent-fg: #111827; --accent-hover: #C8D893; --focus: #E7C477; --error: #F2959A;
    --thread-red: #E0626A;    --on-thread-red: #111827;
    --thread-terra: #EE9A74;  --on-thread-terra: #111827;
    --thread-olive: #A9BC6E;  --on-thread-olive: #111827;
    --thread-gold: #E7C477;   --on-thread-gold: #111827;
    --thread-indigo: #8FB0DC; --on-thread-indigo: #111827;
    --thread-ink: #F4ECDD;    --on-thread-ink: #111827;
    --thread-cream: #F4ECDD;  --on-thread-cream: #111827;
    --fabric: #111827; --fabric-weave: rgba(244, 236, 221, .04); --stitch-color: #7A88A8;
    --tile-correct: #83994B; --tile-correct-fg: #111827;
    --tile-present: #E7C477; --tile-present-fg: #111827;
    --tile-absent: #3E372F;  --tile-absent-fg: #F4ECDD;
  }
}
:root[data-theme="dark"] {
  --bg: #111827; --card-bg: #1A2336; --sand: #0E1626; --muted-bg: #535F7A; --border: #2E3A55; --control-border: #7A88A8;
  --fg: #F4ECDD; --muted: #C9BEAA; --link: #B4C77A; --terra-text: #F0A27E;
  --accent: #B4C77A; --accent-fg: #111827; --accent-hover: #C8D893; --focus: #E7C477; --error: #F2959A;
  --thread-red: #E0626A;    --on-thread-red: #111827;
  --thread-terra: #EE9A74;  --on-thread-terra: #111827;
  --thread-olive: #A9BC6E;  --on-thread-olive: #111827;
  --thread-gold: #E7C477;   --on-thread-gold: #111827;
  --thread-indigo: #8FB0DC; --on-thread-indigo: #111827;
  --thread-ink: #F4ECDD;    --on-thread-ink: #111827;
  --thread-cream: #F4ECDD;  --on-thread-cream: #111827;
  --fabric: #111827; --fabric-weave: rgba(244, 236, 221, .04); --stitch-color: #7A88A8;
  --tile-correct: #83994B; --tile-correct-fg: #111827;
  --tile-present: #E7C477; --tile-present-fg: #111827;
  --tile-absent: #3E372F;  --tile-absent-fg: #F4ECDD;
}

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

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  color: var(--fg);
  line-height: 1.45;
  background-color: var(--fabric);
  background-image:
    repeating-linear-gradient(0deg, var(--fabric-weave) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, var(--fabric-weave) 0 1px, transparent 1px 4px);
}

a {
  color: inherit;
}

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

.visually-hidden {
  position: absolute !important;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Inline counted-stitch motifs (the same look as the site's sprite). */
.motif-defs { position: absolute; inline-size: 0; block-size: 0; overflow: hidden; }
.motif-defs path, svg.stitched path { fill: none; stroke-width: .3; stroke-linecap: round; }
svg.stitched { fill: none; stroke-width: .3; stroke-linecap: round; }
.s-r { stroke: var(--st-red); } .s-t { stroke: var(--st-terra); } .s-o { stroke: var(--st-olive); }
.s-g { stroke: var(--st-gold); } .s-i { stroke: var(--st-indigo); } .s-k { stroke: var(--st-ink); } .s-c { stroke: var(--st-cream); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

/* ==========================================================================
   Kit pieces
   ========================================================================== */

/* Woven surface: even-weave cloth. The page body already wears it; use on a board or panel that sets its own background. */
.fabric {
  background-color: var(--fabric);
  background-image:
    repeating-linear-gradient(0deg, var(--fabric-weave) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, var(--fabric-weave) 0 1px, transparent 1px 4px);
}

/* Running-stitch border: a dashed thread just inside the edge. It follows border-radius and takes no layout space.
   Recolour with --stitch-color, move it with --stitch-inset. svg.stitched is the site's counted-stitch motif class
   (stroke styling above), so the outline skips SVG elements. A focus ring replaces the stitch while focused. */
.stitched:where(:not(svg)) {
  outline: var(--stitch-w) dashed var(--stitch-color);
  outline-offset: calc(-1 * (var(--stitch-w) + var(--stitch-inset)));
}
.stitched:where(:not(svg)):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* A straight running stitch (divider, or the thread that sews a row together). */
.stitch-line {
  display: block;
  block-size: var(--stitch-w);
  background: repeating-linear-gradient(90deg, var(--stitch-color) 0 6px, transparent 6px 10px);
  border-radius: var(--stitch-w);
}

/* Embroidered text: heavy rounded type, a little tracking, a 1px shadow in the thread's darker shade. */
.yarn {
  font-family: var(--font-yarn);
  font-weight: 800;
  letter-spacing: .03em;
  text-shadow: 1px 1px 0 var(--yarn-shade, color-mix(in srgb, currentColor 55%, rgba(0, 0, 0, .55)));
}

/* A cloth patch: card or panel. Add .stitched for the running stitch. */
.patch {
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 var(--border), 0 3px 10px rgba(42, 33, 24, .06);
}

/* A cross-stitch knot: a tiny X in --knot-color. */
.knot {
  display: inline-block;
  inline-size: var(--knot-size, 10px);
  block-size: var(--knot-size, 10px);
  background:
    linear-gradient(45deg, transparent calc(50% - 1.2px), var(--knot-color, var(--thread-red)) calc(50% - 1.2px) calc(50% + 1.2px), transparent calc(50% + 1.2px)),
    linear-gradient(-45deg, transparent calc(50% - 1.2px), var(--knot-color, var(--thread-red)) calc(50% - 1.2px) calc(50% + 1.2px), transparent calc(50% + 1.2px));
  border-radius: 2px;
}

/* ==========================================================================
   Thread animations. Each is a class that a game adds and removes on animationend.
   Static rules equal the final state, so removing the animation (reduced motion) shows the end result.
   ========================================================================== */

/* stitch-in: a letter is sewn into its box. The ::after draws a short diagonal thread from the top-left corner,
   then the glyph settles from scale .7 with a slight overshoot. The box scales unless it holds a .glyph child,
   in which case only that child scales. The box must not use ::after for anything else while animating. */
:where(.stitch-in) { position: relative; }
.stitch-in:not(:has(> .glyph)),
.stitch-in > .glyph {
  animation: stitch-in var(--stitch-in-dur, 220ms) var(--ease-settle) both;
}
.stitch-in::after {
  content: "";
  position: absolute;
  inset: 16%;
  pointer-events: none;
  background: linear-gradient(to top right,
    transparent calc(50% - 1.25px), var(--stitch-in-color, var(--thread-terra)) calc(50% - 1.25px) calc(50% + 1.25px), transparent calc(50% + 1.25px));
  opacity: 0;
  animation: stitch-in-thread var(--stitch-in-dur, 220ms) linear both;
}
@keyframes stitch-in {
  0%   { scale: .7; opacity: .4; }
  35%  { scale: .7; opacity: .55; }
  75%  { scale: 1.08; opacity: 1; }
  100% { scale: 1; opacity: 1; }
}
@keyframes stitch-in-thread {
  0%   { clip-path: inset(0 100% 100% 0); opacity: 1; }
  45%  { clip-path: inset(0 0 0 0); opacity: 1; }
  100% { clip-path: inset(0 0 0 0); opacity: 0; }
}

/* thread-fill: the box fills with thread lines from top to bottom in --fill (default olive),
   starting from --fill-from (default the empty-cloth colour). Set --fill per result, e.g. var(--tile-correct). */
.thread-fill {
  background-image:
    linear-gradient(to bottom, transparent 50%, var(--fill-edge, color-mix(in srgb, var(--fill, var(--thread-olive)), #000 30%)) 50% calc(50% + 2px), var(--fill-from, var(--card-bg)) calc(50% + 2px)),
    repeating-linear-gradient(to bottom, transparent 0 3px, rgba(0, 0, 0, .07) 3px 4px),
    linear-gradient(var(--fill, var(--thread-olive)), var(--fill, var(--thread-olive)));
  background-size: 100% 200%;
  background-repeat: no-repeat;
  background-position: 0 0;
  animation: thread-fill var(--fill-dur, 300ms) var(--ease-thread) var(--fill-delay, 0ms) both;
}
@keyframes thread-fill {
  from { background-position: 0 100%; }
  to   { background-position: 0 0; }
}

/* thread-draw: an SVG stroke drawn along its path. Give the element pathLength="1" (or set --thread-len to
   its real length). Duration in --thread-dur. */
.thread-draw {
  stroke-dasharray: var(--thread-len, 1) var(--thread-len, 1);
  stroke-dashoffset: 0;
  animation: thread-draw var(--thread-dur, 300ms) var(--ease-thread) var(--thread-delay, 0ms) both;
}
@keyframes thread-draw {
  from { stroke-dashoffset: var(--thread-len, 1); }
  to   { stroke-dashoffset: 0; }
}

/* knot-pop: a tiny cross-stitch X blooms, then settles at its resting size (it stays visible). */
.knot-pop {
  animation: knot-pop var(--knot-dur, 160ms) var(--ease-settle) both;
}
@keyframes knot-pop {
  0%   { scale: .2; rotate: -45deg; opacity: 0; }
  65%  { scale: 1.35; rotate: 0deg; opacity: 1; }
  100% { scale: 1; rotate: 0deg; opacity: 1; }
}

/* loose-wiggle: a wrong answer's thread wobbles. Uses rotate/translate, so its motion composes with a transform
   shake. The animation shorthand does not compose: an element with its own shake rule must list both animations
   in one declaration (see .tile.shake.loose-wiggle in irtibat.css). */
.loose-wiggle {
  animation: loose-wiggle var(--wiggle-dur, 240ms) ease-in-out both;
}
@keyframes loose-wiggle {
  0%   { rotate: 0deg; translate: 0 0; }
  20%  { rotate: -2.5deg; translate: -1px 0; }
  45%  { rotate: 2deg; translate: 1px 0; }
  70%  { rotate: -1deg; translate: 0 0; }
  100% { rotate: 0deg; translate: 0 0; }
}

/* Supporting keyframes. stitch-run reveals a running stitch left to right; unravel fades a used knot;
   patch-in settles a patch onto the cloth (the modal, Irtibat's solved bars). */
.stitch-run {
  animation: stitch-run var(--run-dur, 260ms) var(--ease-thread) var(--run-delay, 0ms) both;
}
@keyframes stitch-run {
  from { clip-path: inset(0 100% 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}
[dir="rtl"] .stitch-run { animation-name: stitch-run-rtl; }
@keyframes stitch-run-rtl {
  from { clip-path: inset(0 0 0 100%); }
  to   { clip-path: inset(0 0 0 0); }
}
.unravel {
  opacity: .25;
  scale: .6;
  rotate: 90deg;
  animation: unravel var(--unravel-dur, 220ms) ease-out both;
}
@keyframes unravel {
  0%   { opacity: 1; scale: 1; rotate: 0deg; }
  100% { opacity: .25; scale: .6; rotate: 90deg; }
}
@keyframes patch-in {
  from { opacity: 0; scale: .96; }
  to   { opacity: 1; scale: 1; }
}

/* ==========================================================================
   Shared chrome
   ========================================================================== */

/* ---------- header (rendered by api.js into [data-app-header]) ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px 12px;
  flex-wrap: wrap;
  padding: 10px 16px 12px;
  background:
    repeating-linear-gradient(90deg, var(--stitch-color) 0 6px, transparent 6px 10px) left bottom 4px / 100% var(--stitch-w) no-repeat,
    linear-gradient(var(--border), var(--border)) left bottom / 100% 1px no-repeat;
}

.app-header .app-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.1;
  color: var(--fg);
  text-decoration: none;
}

.app-header .app-name::before {
  content: "";
  inline-size: 12px;
  block-size: 12px;
  flex: none;
  background:
    linear-gradient(45deg, transparent calc(50% - 1.3px), var(--thread-red) calc(50% - 1.3px) calc(50% + 1.3px), transparent calc(50% + 1.3px)),
    linear-gradient(-45deg, transparent calc(50% - 1.3px), var(--thread-red) calc(50% - 1.3px) calc(50% + 1.3px), transparent calc(50% + 1.3px));
}

.app-header .game-title {
  font-family: var(--font-yarn);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: .02em;
  margin-right: auto;
}

.app-header .game-meta {
  font-family: var(--font-sans);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0;
}

.app-header .header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.app-header .btn {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.875rem;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
  outline: 1.5px dashed var(--stitch-color);
  outline-offset: -5px;
  transition: translate .15s ease;
}

.btn:hover {
  background: var(--sand);
}

.btn:active {
  translate: 0 1px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  outline-color: color-mix(in srgb, var(--accent-fg) 55%, transparent);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: .55;
  translate: none;
}

.btn:disabled:hover {
  background: var(--card-bg);
}

.btn-primary:disabled:hover {
  background: var(--accent);
}

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

/* The site bar's Give button carries .btn and .btn-primary; keep it exactly as static/site-bar.css draws it. */
.games-site-bar .btn {
  outline: none;
  translate: none;
}
.games-site-bar .btn:focus-visible {
  outline: 3px solid var(--gs-focus, var(--focus));
  outline-offset: 3px;
}

/* ---------- cards and badges ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  outline: var(--stitch-w) dashed var(--stitch-color);
  outline-offset: calc(-1 * (var(--stitch-w) + var(--stitch-inset) + 2px));
  box-shadow: 0 1px 0 var(--border), 0 3px 10px rgba(42, 33, 24, .06);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
  gap: 14px;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 12px 16px;
  text-align: center;
  text-decoration: none;
  color: inherit;
  transition: translate .15s ease;
}

.game-card:hover {
  translate: 0 -2px;
  outline-color: var(--thread-terra);
}

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

.game-card .game-motif {
  inline-size: 3rem;
  block-size: 3rem;
}

.game-card h3 {
  margin: 0;
  font-family: var(--font-yarn);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: .02em;
  line-height: 1.2;
}

.game-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.35;
  flex: 1;
}

.game-card .game-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  line-height: 1.35;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: .02em;
  background: var(--muted-bg);
  color: var(--fg);
}

.badge-play {
  background: var(--card-bg);
  color: var(--link);
  box-shadow: inset 0 0 0 1.5px var(--link);
}

.badge-done {
  background: var(--thread-olive);
  color: var(--on-thread-olive);
}

.badge-progress {
  background: var(--thread-gold);
  color: var(--on-thread-gold);
}

/* ---------- hub (index.html) ---------- */
/* The intro above the hub heading (templates/games/_intro.html, put in by games/views.py): a stitched patch with an
   eyebrow, a yarn heading, body text at a readable measure and one secondary button. */
.hub-intro {
  margin: 8px 0 22px;
  padding: 22px 26px 24px;
  overflow-wrap: break-word;
}

.hub-intro h2 {
  margin: 0 0 10px;
  font-size: clamp(1.4rem, 4.5vw, 1.75rem);
  line-height: 1.2;
}

.hub-intro-body {
  max-inline-size: 32em;   /* about 60 to 70 characters a line in the body font */
  line-height: 1.55;
}

.hub-intro-body > * {
  margin: 0 0 .8em;
}

.hub-intro-body a {
  color: var(--link);
  text-underline-offset: .15em;
}

.hub-intro-link {
  margin-top: 4px;
  text-align: center;
}

@media (max-width: 30rem) {
  .hub-intro {
    padding: 18px 18px 20px;
  }
}

.hub-head {
  padding: 12px 0 4px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--terra-text);
}

.hub-head h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 2.8rem);
  line-height: 1.1;
  letter-spacing: -.01em;
}

.hub-date {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 600;
}

.hub-band {
  display: block;
  inline-size: 100%;
  block-size: 27px;   /* 9 stitches x 3px */
  margin: 18px 0 22px;
}

@media (max-width: 30rem) {
  .hub-grid .game-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

/* ---------- modal (api.js showModal) ---------- */
dialog.modal {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0;
  background-color: var(--card-bg);
  background-image:
    repeating-linear-gradient(0deg, var(--fabric-weave) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, var(--fabric-weave) 0 1px, transparent 1px 4px);
  color: var(--fg);
  max-width: 480px;
  width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  outline: var(--stitch-w) dashed var(--stitch-color);
  outline-offset: -9px;
  box-shadow: 0 18px 44px rgba(17, 12, 6, .28);
}

dialog.modal[open] {
  animation: patch-in 180ms var(--ease-thread) both;
}

dialog.modal::backdrop {
  background: rgba(30, 22, 14, .55);
}

.modal-body {
  padding: 26px 24px 24px;
}

.modal-body h2 {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 1.15;
}

.modal-content {
  line-height: 1.5;
}

/* Stats block: api.js writes it with inline layout; each figure becomes a small patch with a yarn number. */
.modal-content > div[style*="flex-wrap"] {
  justify-content: center;
}
.modal-content > div[style*="flex-wrap"] > div {
  flex: 1 1 88px;
  padding: 10px 6px 8px;
  border-radius: var(--radius);
  background: var(--sand);
  outline: 1.5px dashed var(--stitch-color);
  outline-offset: -5px;
  font-size: 0.85rem;
  color: var(--muted);
}
.modal-content [style*="font-size:1.5rem"] {
  font-family: var(--font-yarn);
  font-size: 1.75rem !important;
  font-weight: 800;
  line-height: 1.2;
  color: var(--fg);
  text-shadow: 1px 1px 0 color-mix(in srgb, currentColor 30%, transparent);
}
.modal-content ul[style] li {
  padding: 2px 0;
  border-bottom: 1px dashed var(--border);
}

.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
}

/* The once-a-day donate line on a result screen (api.js). */
dialog.modal .donate-line {
  border: 0;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--thread-gold) 14%, var(--card-bg));
  outline: 1.5px dashed var(--thread-gold);
  outline-offset: -4px;
  padding: 10px 14px;
  margin-top: 14px;
}
dialog.modal .donate-line a {
  color: var(--link);
}

/* ---------- toast (api.js toast) ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  translate: 0 8px;
  max-width: calc(100% - 32px);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 700;
  outline: 1.5px dashed var(--thread-gold);
  outline-offset: -5px;
  box-shadow: 0 8px 22px rgba(17, 12, 6, .25);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, translate .2s ease;
}

.toast.visible {
  opacity: 1;
  translate: 0 0;
}

/* ---------- archive ---------- */
table.archive-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

table.archive-table td, table.archive-table th {
  padding: 10px 8px;
  border-bottom: 1px dashed var(--border);
  text-align: left;
  font-size: 0.95rem;
}

table.archive-table th {
  font-size: 0.8rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
}

table.archive-table tr:last-child td {
  border-bottom: 0;
}

table.archive-table td a {
  color: var(--link);
  font-weight: 600;
  text-underline-offset: .18em;
}

.jump-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

.jump-form label {
  font-weight: 700;
}

.archive-panel {
  padding: 10px 18px;
  overflow-x: auto;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  white-space: nowrap;
}

.status::before {
  content: "";
  inline-size: 9px;
  block-size: 9px;
  flex: none;
  background:
    linear-gradient(45deg, transparent calc(50% - 1.2px), var(--status-thread) calc(50% - 1.2px) calc(50% + 1.2px), transparent calc(50% + 1.2px)),
    linear-gradient(-45deg, transparent calc(50% - 1.2px), var(--status-thread) calc(50% - 1.2px) calc(50% + 1.2px), transparent calc(50% + 1.2px));
}

.status-won { --status-thread: var(--thread-olive); }
.status-lost { --status-thread: var(--thread-red); }
.status-progress { --status-thread: var(--thread-gold); }
.status-none { --status-thread: var(--stitch-color); color: var(--muted); font-weight: 400; }

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tabs a {
  padding: 7px 14px;
  border-radius: 999px;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 0.9rem;
  font-weight: 700;
  outline: 1.5px dashed transparent;
  outline-offset: -5px;
}

.tabs a:hover {
  outline-color: var(--stitch-color);
}

.tabs a.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  outline-color: color-mix(in srgb, var(--accent-fg) 55%, transparent);
}

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

.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-weight: 600;
}

input[type="text"], input[type="date"], input[type="search"] {
  min-height: 40px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--control-border);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
  font-size: 0.95rem;
}

footer {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 24px 16px;
}

footer a {
  color: var(--link);
  font-weight: 600;
}

@media (max-width: 480px) {
  .app-header:has(.game-title) .app-name {
    display: none;
  }
}

/* ---------- reduced motion: every animation and transition in every game stylesheet is removed ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  dialog.modal[open] { animation: none !important; }
  [data-motion-only] { display: none !important; }
}
