/* ============================================================
   Math Playground — chrome, palettes and game styles for the
   four Toolshed math games (Counters, Number Line, Facts,
   Story Problems). Shares the 11 palettes with the Work Cycle
   Timer and the Toolshed site: keep the html[data-theme]
   blocks in sync with site.css (SwankyMcGee.github.io) and
   styles.css (work-cycle-timer). --accent2 is the palette's
   second accent (THEMES chips[4]) and marks "the other group"
   in two-group visuals.
   ============================================================ */

/* ---------- Bundled display font ----------
   Fredoka (variable 300–700, SIL Open Font License) — a friendly
   rounded face for headings, the big problem numbers and choice
   buttons. The woff2 lives in fonts/ so every page stays fully
   offline. Body copy keeps the system stack for legibility. */
@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('fonts/fredoka-latin.woff2') format('woff2');
}

:root {
  --font-display: 'Fredoka', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --bg: #f2f6f8;
  --surface: #ffffff;
  --surface-2: #e9eff3;
  --text: #33414d;
  --dim: #6b7c8a;
  --border: #d5dfe6;
  --accent: #4d84a6;
  --accent2: #628f5d;
  --hold-bg: #fdf3dd;
  --hold-text: #7a5c1e;
  --hold-border: #eeddb3;
}

* { box-sizing: border-box; }

/* Author display beats the UA's [hidden] — the lesson from the site:
   any element we give display:flex needs this guard. */
[hidden] { display: none !important; }

html { font-size: 16px; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  transition: background-color .35s ease, color .35s ease;   /* gentle palette switch */
}

a { color: var(--accent); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Header / nav ---------- */

.site-head {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .7rem 1.2rem;
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 1rem;
  align-items: center;
  transition: box-shadow .2s ease;
}

/* Lifted off the page once content scrolls beneath it. */
.site-head.scrolled { box-shadow: 0 2px 14px rgba(0, 0, 0, .09); }

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-family: var(--font-display);
  font-size: 1.06rem;
  letter-spacing: -.01em;
}

.brand .brand-sub { font-weight: 500; color: var(--dim); font-size: .88rem; letter-spacing: 0; }

.brand-mark { display: inline-flex; }
.brand-mark svg { display: block; width: 26px; height: 26px; }

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem .35rem;
  font-size: .92rem;
}

.site-nav a { text-decoration: none; color: var(--dim); border-radius: 999px; padding: .22rem .7rem; }
.site-nav a:hover { color: var(--accent); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--text); font-weight: 700; background: var(--surface-2); }
.site-nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.head-tools {
  margin-left: auto;
  display: flex;
  gap: .5rem;
  align-items: center;
}

/* The standard Toolshed control cluster (Chime · Fullscreen ·
   Settings · Home) — right-aligned, wraps before anything collides. */
.header-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .5rem;
}

main {
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.2rem 1.2rem 2.5rem;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: clamp(1.9rem, 4vw, 2.3rem); font-weight: 700; margin: .6rem 0 .4rem; }
h2 { font-size: 1.3rem; margin: 1.4rem 0 .5rem; }
p { margin: .45rem 0; }

/* Section headings ("Pick a game") get a hairline rule that runs
   to the edge of the column. */
.section-h { display: flex; align-items: center; gap: .8rem; }
.section-h::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---------- Footer (shared Toolshed scene + rotating wisdom) ---------- */

.site-foot {
  max-width: 62rem;
  margin: 0 auto;
  padding: 0 1.2rem 1.4rem;
  color: var(--dim);
  font-size: .85rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.foot-scene {
  position: relative;
  display: block;
  width: min(100%, 1080px);
  aspect-ratio: 1100 / 160;
  margin: 0 auto;
  padding-top: .4rem;
  /* One generated panorama per palette, painted from --foot-img so it
     tracks the theme switch. The twinkles stay inline SVG on top. */
  background: var(--foot-img) center / cover no-repeat;
}
.foot-scene svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.foot-phrase { margin: .3rem 0 0; font-size: .95rem; font-weight: 700; color: var(--text); }
.foot-phrase a { color: var(--accent); }
.foot-wisdom {
  margin: .35rem 0 0;
  min-height: 1.4em;
  font-style: italic;
  color: var(--dim);
  transition: opacity .6s ease;
}
.foot-wisdom.fading { opacity: 0; }
.foot-meta { margin: .55rem 0 0; font-size: .8rem; }

/* Scene life — slow sways, switched off under reduced motion. */
.foot-scene .sway { transform-box: fill-box; transform-origin: 50% 0%; }
.foot-scene .nod { transform-box: fill-box; transform-origin: 50% 100%; }
@media (prefers-reduced-motion: no-preference) {
  .foot-scene .sway { animation: toolSway 6s ease-in-out infinite alternate; }
  .foot-scene .nod { animation: sproutNod 7s ease-in-out infinite alternate; }
  .foot-scene .glow { animation: twinkle 4.5s ease-in-out infinite alternate; }
}
@keyframes toolSway { from { transform: rotate(-1.6deg); } to { transform: rotate(1.6deg); } }
@keyframes sproutNod { from { transform: rotate(-2deg); } to { transform: rotate(2deg); } }
@keyframes twinkle { from { opacity: .3; } to { opacity: .85; } }
@media (prefers-reduced-motion: reduce) {
  .foot-wisdom { transition: none; }
}

/* ---------- Hold-to-activate (kid-safe buttons) ----------
   Each holdable button sets --hold-dur (1s home/skip, 3s gear);
   the .holding class runs the fill for that long. */

.hold-btn {
  --hold-dur: 1s;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font: inherit;
  font-size: .92rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .34rem .8rem;
  min-height: 40px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.hold-btn:hover { border-color: var(--accent); }
.hold-btn.holding { border-color: var(--accent); color: var(--accent); }
.hold-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hold-btn .hold-emoji { font-size: 1.05rem; }
.hold-icon { display: inline-flex; align-items: center; }
.hold-icon svg { display: block; }

.hold-track {
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: 4px;
  height: 4px;
  border-radius: 2px;
  background: var(--surface);
  overflow: hidden;
}

.hold-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
}

.holding .hold-fill {
  animation: holdFill var(--hold-dur, 1s) linear forwards;
}

@keyframes holdFill {
  from { width: 0; }
  to   { width: 100%; }
}

/* ---------- Header palette picker (math.js injects this) ---------- */

.theme-wrap {
  position: relative;
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font: inherit;
  font-size: .92rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .34rem .8rem;
  min-height: 40px;
  cursor: pointer;
}

.theme-btn:hover { border-color: var(--accent); }

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

.theme-panel {
  position: absolute;
  right: 0;
  top: calc(100% + .45rem);
  z-index: 30;
  width: min(21.5rem, calc(100vw - 2rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .15);
  padding: .5rem;
}

.theme-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .7rem;
  width: 100%;
  font: inherit;
  font-size: .95rem;
  text-align: left;
  color: var(--text);
  background: none;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: .45rem .6rem;
  cursor: pointer;
}

.theme-opt:hover { background: var(--surface-2); }

.theme-opt.active {
  border-color: var(--accent);
  background: var(--surface-2);
}

.theme-opt:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.theme-name { flex: 1; }

.theme-chips {
  display: inline-flex;
  gap: 3px;
  flex: none;
}

.theme-chip {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--border);
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.1rem;
}

.card h3 { margin: 0 0 .3rem; font-size: 1.05rem; }
.card p { color: var(--dim); font-size: .93rem; }

/* ---------- Home: hero + game chooser ---------- */

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.1rem 0 .5rem;
}

.hero-art {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: min(330px, 74vw);
  aspect-ratio: 1;
  z-index: 1;
}

/* Soft tinted disc behind the shed so the art reads as a badge. */
.hero-art::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

/* The shed itself is a generated WebP per palette (--hero-img, set in
   the theme blocks below); the tinted disc behind stays pure CSS so
   the art still reads as a badge. */
.hero-art::after {
  content: '';
  position: absolute;
  inset: 4%;
  background: var(--hero-img) center / contain no-repeat;
}

.hero-kicker {
  display: inline-block;
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  border-radius: 999px;
  padding: .22rem .85rem;
  margin: 0 0 .55rem;
}

.hero h1 { margin: .1rem 0 .35rem; }

.hero-tagline {
  color: var(--dim);
  font-size: 1.03rem;
  margin: .3rem auto 0;
  max-width: 42em;
}

@media (min-width: 880px) {
  .hero {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: 'art copy';
    align-items: center;
    gap: 2.2rem;
    text-align: left;
    padding: 1.4rem 0 .8rem;
  }
  .hero-art { grid-area: art; width: min(330px, 24vw); }
  .hero-copy { grid-area: copy; }
  .hero-tagline { margin-left: 0; }
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: .9rem;
  margin-top: .9rem;
}

.game-card {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.1rem 1.15rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 5px 16px rgba(0, 0, 0, .05);
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}

.game-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .05), 0 12px 26px rgba(0, 0, 0, .09);
}
.game-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Icon sits in a tinted rounded tile. */
.game-card .gc-icon {
  width: 56px;
  height: 56px;
  padding: 10px;
  box-sizing: border-box;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  border-radius: 14px;
}

.game-card h3 { margin: 0; font-size: 1.12rem; }
.game-card p { margin: 0; color: var(--dim); font-size: .92rem; flex: 1; }

.game-card .gc-go {
  align-self: flex-start;
  color: var(--accent);
  background: var(--surface-2);
  border-radius: 999px;
  padding: .26rem .9rem;
  font-weight: 700;
  font-size: .88rem;
}
.game-card:hover .gc-go { background: color-mix(in srgb, var(--accent) 12%, var(--surface-2)); }

/* ---------- Home: continue strip (last game played) ---------- */

.continue-strip {
  display: flex;
  align-items: center;
  gap: .7rem;
  margin-top: 1rem;
  padding: .85rem 1.1rem;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 5px 16px rgba(0, 0, 0, .05);
  transition: background-color .15s ease, box-shadow .15s ease;
}

.continue-strip:hover { background: var(--surface-2); box-shadow: 0 2px 4px rgba(0, 0, 0, .05), 0 10px 22px rgba(0, 0, 0, .08); }
.continue-strip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.continue-strip .cs-emoji { color: var(--accent); font-size: 1.1rem; }
.continue-strip .cs-text { flex: 1; font-size: .97rem; }

/* ---------- Setup bar (grade + operations) ---------- */

.setup {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .9rem 1.1rem;
  margin-top: 1rem;
}

.setup-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  margin: 0 0 .5rem;
}

.setup-row {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  align-items: center;
  margin-bottom: .55rem;
}

.setup-label {
  font-size: .85rem;
  font-weight: 700;
  color: var(--dim);
  width: 100%;
  margin-bottom: .1rem;
}

.chip {
  font: inherit;
  font-family: var(--font-display);
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: .38rem .9rem;
  min-height: 42px;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}

.chip:hover { border-color: var(--accent); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

/* On the four dark palettes the accent is light — white text on it
   would fail, so pressed chips switch to a dark label there. */
html[data-theme="high"] .chip[aria-pressed="true"],
html[data-theme="dark"] .chip[aria-pressed="true"],
html[data-theme="midnight"] .chip[aria-pressed="true"],
html[data-theme="warm"] .chip[aria-pressed="true"] {
  color: #0b0d10;
}

.chip[disabled] {
  opacity: .45;
  cursor: not-allowed;
}

.setup-note {
  font-size: .87rem;
  color: var(--dim);
  margin: .3rem 0 0;
}

/* ---------- Game page layout ---------- */

.game-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: clamp(1rem, 3vw, 1.8rem);
  margin-top: 1rem;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .04), 0 8px 26px rgba(0, 0, 0, .05);
}

.problem {
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 7vw, 3.4rem);
  font-weight: 600;
  letter-spacing: .01em;
  margin: .2rem 0 .6rem;
  font-variant-numeric: tabular-nums;
}

.problem .op { color: var(--accent); padding: 0 .12em; }

.prompt-line {
  color: var(--dim);
  font-size: .97rem;
  margin: 0 0 .8rem;
  min-height: 1.5em;
}

/* Big answer choices — one row of up to 4, wrapping. */
.choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .7rem;
  margin: .8rem 0 .4rem;
}

.choice {
  font: inherit;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 4vw, 1.9rem);
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: .55rem 1.3rem;
  min-width: 5.4rem;
  min-height: 62px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
  transition: border-color .15s ease, transform .12s ease, box-shadow .15s ease;
}

.choice:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .08);
}
.choice:active { transform: translateY(0); }
.choice:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.choice.correct {
  border-color: var(--accent2);
  background: var(--surface-2);
  color: var(--accent2);
  animation: choicePop .3s ease;
}

@keyframes choicePop {
  50% { transform: scale(1.06); }
}

.choice.soft { opacity: .5; }        /* not the answer — stays visible, no red */

/* Feedback line: gentle, never a buzzer. Success gets a check. */
.feedback {
  min-height: 1.6em;
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--accent2);
  margin: .3rem 0 0;
}

.feedback:not(.neutral):not(:empty)::before { content: '\2713\00a0'; }

.feedback.neutral { color: var(--dim); font-weight: 500; }

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .7rem;
  margin-top: 1rem;
}

/* Plain tap buttons (not hold) for in-game flow. */
.btn {
  font: inherit;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: .55rem 1.3rem;
  min-height: 46px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  transition: border-color .15s ease, background-color .15s ease;
}

.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

html[data-theme="high"] .btn.primary,
html[data-theme="dark"] .btn.primary,
html[data-theme="midnight"] .btn.primary,
html[data-theme="warm"] .btn.primary {
  color: #0b0d10;
}

.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- Counters game (virtual manipulative) ---------- */

.counter-boards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .8rem;
  margin: .6rem 0 .3rem;
}

.board {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: .5rem;
}

.board-label {
  font-size: .8rem;
  font-weight: 700;
  color: var(--dim);
  margin: 0 0 .35rem;
  text-align: center;
}

.ten-frame {
  display: grid;
  grid-template-columns: repeat(5, 34px);
  grid-auto-rows: 34px;
  gap: 5px;
}

.cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  display: grid;
  place-items: center;
}

.counter {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid rgba(0, 0, 0, .18);
}

.counter.group2 { background: var(--accent2); }

/* ---------- Number line game ---------- */

.line-wrap { margin: .5rem auto .2rem; max-width: 560px; }
.line-wrap svg { width: 100%; height: auto; display: block; }

.line-base { stroke: var(--dim); stroke-width: 3; stroke-linecap: round; }
.line-tick { stroke: var(--dim); stroke-width: 2; }
.line-tick.minor { stroke-width: 1; opacity: .5; }
.line-tick.major { stroke-width: 2; }
.line-num { fill: var(--dim); font-size: 15px; font-weight: 600; }
.line-hnum { fill: var(--text); font-size: 16px; font-weight: 800; }
.line-q { fill: var(--accent2); font-size: 19px; font-weight: 800; }
.line-hopper {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 3;
  transition: cx .3s ease, cy .3s ease;
}
.line-arc {
  fill: none;
  stroke: var(--accent2);
  stroke-width: 3;
  stroke-dasharray: 6 5;
  stroke-linecap: round;
}
.line-target {
  fill: none;
  stroke: var(--accent2);
  stroke-width: 3;
  stroke-dasharray: 4 4;
}

/* ---------- Story problems (schema bar model) ---------- */

.story-scene {
  display: flex;
  justify-content: center;
  gap: .8rem;
  flex-wrap: wrap;
  margin: .4rem 0 .8rem;
}

.scene-icon {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: .5rem .8rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.scene-icon svg { width: 30px; height: 30px; flex: none; }

.story-text {
  font-size: 1.12rem;
  max-width: 34em;
  margin: 0 auto .8rem;
}

/* Bar model: whole bar over part bars (schema-based instruction). */
.bar-model { max-width: 560px; margin: 0 auto .9rem; }

.bar-row { display: flex; gap: 4px; margin-bottom: 4px; }
.bar-row:last-child { margin-bottom: 0; }

.bar {
  border-radius: 6px;
  min-height: 34px;
  min-width: 26px;
  flex: 1 1 0;               /* width is proportional to flex-grow */
  display: grid;
  place-items: center;
  font-size: .85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border: 1.5px solid transparent;
  overflow: hidden;
  white-space: nowrap;
}

.bar.whole { background: var(--accent); color: #ffffff; }
.bar.part1 { background: var(--surface-2); border-color: var(--accent); color: var(--text); }
.bar.part2 { background: var(--surface-2); border-color: var(--accent2); color: var(--text); }
.bar.unknown { background: var(--surface-2); border: 1.5px dashed var(--dim); color: var(--dim); }

html[data-theme="high"] .bar.whole,
html[data-theme="dark"] .bar.whole,
html[data-theme="midnight"] .bar.whole,
html[data-theme="warm"] .bar.whole {
  color: #0b0d10;
}

/* ---------- Round progress dots ---------- */

.progress {
  display: flex;
  justify-content: center;
  gap: .45rem;
  margin-top: .9rem;
}

.pdot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
}

.pdot.done { background: var(--accent2); border-color: var(--accent2); }
.pdot.now {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.progress-label {
  font-size: .83rem;
  color: var(--dim);
  margin-top: .35rem;
  text-align: center;
}

/* ---------- Game visual area, hint, extra controls ---------- */

.visual { margin: .2rem 0 .5rem; }

.hint-line {
  max-width: 34em;
  margin: .6rem auto 0;
  font-size: .97rem;
  color: var(--dim);
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: .55rem .9rem;
  text-align: left;
}

.choice.tried { opacity: .4; }   /* "not that one" — no red, no buzzer */

.check-row {
  display: flex;
  justify-content: center;
  gap: .7rem;
  margin-top: .8rem;
}

.count-line {
  font-size: .97rem;
  font-weight: 700;
  color: var(--text);
  margin: .6rem 0 0;
  font-variant-numeric: tabular-nums;
}

.model-caption {
  font-size: .8rem;
  font-weight: 700;
  color: var(--dim);
  margin: 0 0 .3rem;
  text-align: center;
}

/* ---------- Counters: tray of waiting / taken-away counters ---------- */

.counter-tray {
  background: var(--surface-2);
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  padding: .5rem .7rem;
  margin-top: .7rem;
}

.tray-label {
  font-size: .8rem;
  font-weight: 700;
  color: var(--dim);
  margin: 0 0 .35rem;
  text-align: center;
}

.tray-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: .45rem;
  min-height: 36px;
}

.tray-empty { font-size: .87rem; color: var(--dim); }

.counter-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.counter-btn:hover .counter { transform: scale(1.14); }
.counter-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.counter { transition: transform .12s ease; }

/* ---------- Settings row (grade/ops on every game page) ---------- */

.playing-as {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  color: var(--dim);
  margin-top: .7rem;
}

.playing-as strong { color: var(--text); }

/* ---------- Home background patterns (toggleable) ----------
   Whisper-quiet math motif, home page only. Toggle lives in the
   palette panel ("Background patterns") and shares the site's
   homeMotifs setting. Low/high contrast get no pattern. */

body.home::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-repeat: repeat;
  background-size: 220px 220px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><g fill='none' stroke='%23808080' stroke-opacity='0.13' stroke-width='2' stroke-linecap='round'><path d='M30 30 h16 M38 22 v16'/><path d='M150 40 h14'/><circle cx='170' cy='150' r='7'/><path d='M45 140 h16 M45 154 h16 M48 143 l10 8 M58 143 l-10 8'/><path d='M110 95 h14 M117 88 v14'/><path d='M95 185 h14'/></g></svg>");
}

html.motifs-off body.home::before { display: none; }
html[data-theme="low"] body.home::before,
html[data-theme="high"] body.home::before { display: none; }

/* ---------- Score + round-complete screen ---------- */

.score-pill {
  margin: 0 0 .3rem;
  text-align: right;
  font-size: .92rem;
  font-weight: 700;
  color: var(--dim);
}

.round-done { padding: .4rem 0 .2rem; }
.rd-emoji { font-size: 2.6rem; line-height: 1.1; }
.rd-title { font-size: 1.7rem; margin: .35rem 0 .3rem; font-weight: 700; }
.rd-line { font-size: 1.05rem; margin: .15rem 0; }
.rd-line strong { color: var(--accent2); }
.rd-total { color: var(--dim); font-size: .95rem; margin: .15rem 0 .45rem; }
.rd-ask { font-weight: 700; margin: .2rem 0 .1rem; }

/* ---------- Locked choices (not at the landing yet) ---------- */

.choice.is-locked { opacity: .45; cursor: not-allowed; }

/* ---------- Counters: drag and drop ---------- */

.counter-btn { touch-action: none; }
.counter-btn.drag-src { opacity: .3; }

.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.cell.drop-ok {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.counter-tray.drop-ok { border-color: var(--accent); }

body.dragging-active,
body.dragging-active * { cursor: grabbing !important; user-select: none; }

/* ---------- Number line: move controls + distance badge ---------- */

.hop-btns {
  display: flex;
  justify-content: center;
  gap: .8rem;
  margin-top: .7rem;
}

.hop-btn {
  min-width: 66px;
  min-height: 52px;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
}

.line-badge-bg {
  fill: var(--surface-2);
  stroke: var(--border);
  stroke-width: 1.5;
}

.line-badge-t {
  fill: var(--text);
  font-size: 15px;
  font-weight: 800;
}

.line-badge.ready .line-badge-bg { stroke: var(--accent2); stroke-width: 2.5; }
.line-badge.ready .line-badge-t { fill: var(--accent2); }

/* On the answer: the hopper goes see-through with an outline, and a
   magnifier floats above the number to show it up close. */
.at-answer .line-hopper {
  fill: var(--accent);
  fill-opacity: .12;
  stroke: var(--accent2);
  stroke-width: 3;
}

.line-lens { display: none; pointer-events: none; }
.line-lens.is-on { display: inline; }

.lens-ring {
  fill: var(--surface-2);
  stroke: var(--accent2);
  stroke-width: 3;
}

.lens-handle {
  stroke: var(--accent2);
  stroke-width: 6;
  stroke-linecap: round;
}

.lens-num {
  fill: var(--text);
  font-size: 24px;
  font-weight: 800;
}

.lens-base { stroke: var(--dim); stroke-width: 3; stroke-linecap: round; }
.lens-tick { stroke: var(--dim); stroke-width: 2; }
.lens-tick.mid { stroke: var(--accent2); stroke-width: 3; }

.line-jumps { fill: var(--dim); font-size: 13px; font-weight: 700; }

.line-hopper {
  cursor: grab;
  touch-action: none;
}

.hop-hit {
  fill: none;
  pointer-events: all;
  cursor: grab;
  touch-action: none;
}

.hop-hit:active,
.line-hopper:active { cursor: grabbing; }

/* ---------- Shared color palettes (all 11) ----------
   math.js sets html[data-theme] before first paint. These blocks
   mirror site.css (SwankyMcGee.github.io) exactly, plus --accent2
   = the palette's second accent (THEMES chips[4]) used for the
   "other group" in two-group visuals. */

html[data-theme="calm"] {
  --bg: #f2f6f8;
  --surface: #ffffff;
  --surface-2: #e9eff3;
  --text: #33414d;
  --dim: #6b7c8a;
  --border: #d5dfe6;
  --accent: #4d84a6;
  --accent2: #628f5d;
  --hold-bg: #fdf3dd;
  --hold-text: #7a5c1e;
  --hold-border: #eeddb3;

  --hero-img: url("img/heroes/calm.webp");
  --foot-img: url("img/footers/calm.jpg");
}

html[data-theme="lavender"] {
  --bg: #f5f3fb;
  --surface: #ffffff;
  --surface-2: #ece8f7;
  --text: #3d3a52;
  --dim: #75708f;
  --border: #ddd7ef;
  --accent: #7a6fc0;
  --accent2: #6a9a76;
  --hold-bg: #fdf3dd;
  --hold-text: #7a5c1e;
  --hold-border: #eeddb3;

  --hero-img: url("img/heroes/lavender.webp");
  --foot-img: url("img/footers/lavender.jpg");
}

html[data-theme="mint"] {
  --bg: #eef8f3;
  --surface: #ffffff;
  --surface-2: #e0f0e8;
  --text: #2f4640;
  --dim: #648076;
  --border: #cfe6dc;
  --accent: #35837e;
  --accent2: #6f9a58;
  --hold-bg: #fdf3dd;
  --hold-text: #7a5c1e;
  --hold-border: #eeddb3;

  --hero-img: url("img/heroes/mint.webp");
  --foot-img: url("img/footers/mint.jpg");
}

html[data-theme="peach"] {
  --bg: #fdf6ef;
  --surface: #fffdfb;
  --surface-2: #f9ece0;
  --text: #4d3f34;
  --dim: #8a7566;
  --border: #f0e0d0;
  --accent: #c26a3c;
  --accent2: #7a9a5a;
  --hold-bg: #fdf3dd;
  --hold-text: #7a5c1e;
  --hold-border: #eeddb3;

  --hero-img: url("img/heroes/peach.webp");
  --foot-img: url("img/footers/peach.jpg");
}

html[data-theme="rose"] {
  --bg: #fdf4f6;
  --surface: #ffffff;
  --surface-2: #f9e7ec;
  --text: #4f3540;
  --dim: #8c6b78;
  --border: #f2dae1;
  --accent: #c25f7e;
  --accent2: #6f9466;
  --hold-bg: #fdf3dd;
  --hold-text: #7a5c1e;
  --hold-border: #eeddb3;

  --hero-img: url("img/heroes/rose.webp");
  --foot-img: url("img/footers/rose.jpg");
}

html[data-theme="ocean"] {
  --bg: #eef8fa;
  --surface: #ffffff;
  --surface-2: #dff0f4;
  --text: #2c4750;
  --dim: #5f7f89;
  --border: #cfe6eb;
  --accent: #2f87a3;
  --accent2: #5f9a6a;
  --hold-bg: #fdf3dd;
  --hold-text: #7a5c1e;
  --hold-border: #eeddb3;

  --hero-img: url("img/heroes/ocean.webp");
  --foot-img: url("img/footers/ocean.jpg");
}

html[data-theme="low"] {
  --bg: #eef1f3;
  --surface: #f6f8f9;
  --surface-2: #eaedef;
  --text: #5b6570;
  --dim: #838d97;
  --border: #e2e6e9;
  --accent: #94b4c3;
  --accent2: #a9c5a5;
  --hold-bg: #f4efe3;
  --hold-text: #8a8172;
  --hold-border: #e8e0cf;

  --hero-img: url("img/heroes/low.webp");
  --foot-img: url("img/footers/low.jpg");
}

html[data-theme="high"] {
  --bg: #000000;
  --surface: #0b0d10;
  --surface-2: #16191e;
  --text: #ffffff;
  --dim: #d0d6dc;
  --border: #ffffff;
  --accent: #56e0ff;
  --accent2: #b7ff5e;
  --hold-bg: #2a2105;
  --hold-text: #ffe066;
  --hold-border: #ffe066;

  --hero-img: url("img/heroes/high.webp");
  --foot-img: url("img/footers/high.jpg");
}

html[data-theme="dark"] {
  --bg: #151a20;
  --surface: #1e242b;
  --surface-2: #252c34;
  --text: #e7edf2;
  --dim: #9aa7b3;
  --border: #323b45;
  --accent: #6fa9c7;
  --accent2: #8fbf88;
  --hold-bg: #3a3320;
  --hold-text: #f0dca6;
  --hold-border: #5c5030;

  --hero-img: url("img/heroes/dark.webp");
  --foot-img: url("img/footers/dark.jpg");
}

html[data-theme="midnight"] {
  --bg: #0a0f1e;
  --surface: #121a30;
  --surface-2: #1a2440;
  --text: #e3e9f7;
  --dim: #9aa6c4;
  --border: #2c3a5e;
  --accent: #6fa8ff;
  --accent2: #67d6a5;
  --hold-bg: #1c2745;
  --hold-text: #a9c6f5;
  --hold-border: #3d5585;

  --hero-img: url("img/heroes/midnight.webp");
  --foot-img: url("img/footers/midnight.jpg");
}

html[data-theme="warm"] {
  --bg: #211a14;
  --surface: #2b221a;
  --surface-2: #352a20;
  --text: #f0e6da;
  --dim: #b3a291;
  --border: #4a3c2e;
  --accent: #d9a05f;
  --accent2: #93b877;
  --hold-bg: #3a3020;
  --hold-text: #f0dca6;
  --hold-border: #5c4c2e;

  --hero-img: url("img/heroes/warm.webp");
  --foot-img: url("img/footers/warm.jpg");
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
  .game-card:hover { transform: none; }
}
