/* Pictures in helps and solutions (public/visuals.js).
   Consumes the app tokens (--paper, --ink, --red, --marker, --pencil, --muted, --star,
   --font-hand, --font-body) with fallbacks; defines only private --vz-* variables. */

.vz-visual,
.vz-viewer {
  --vz-ink: var(--ink, #2347b8);
  --vz-red: var(--red, #d42a2a);
  --vz-marker: var(--marker, #ffe14a);
  --vz-pencil: var(--pencil, #3a3f47);
  --vz-muted: var(--muted, #9aa1ab);
  --vz-star: var(--star, #f2b300);
  --vz-paper: var(--paper, #fffdf6);
  --vz-grid: var(--grid-line, #d9e4f2);
  --vz-on-marker: #2a2a2a;
  --vz-hand: var(--font-hand, "Caveat", "Comic Neue", "Comic Sans MS", "Segoe Print", cursive);
  --vz-body: var(--font-body, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
}

@media (prefers-color-scheme: dark) {
  .vz-visual,
  .vz-viewer {
    --vz-ink: var(--ink, #8fb2ff);
    --vz-red: var(--red, #ff7a70);
    --vz-marker: var(--marker, #e8c93a);
    --vz-pencil: var(--pencil, #d8dce3);
    --vz-muted: var(--muted, #8b93a0);
    --vz-paper: var(--paper, #1d2128);
  }
}

/* ------------------------------------------------------------ figure */

.vz-visual {
  margin: 0;
  padding: 0;
  width: 100%;
  color: var(--vz-pencil);
  font-family: var(--vz-body);
}
.vz-visual.vz-empty { display: none; }
.vz-body { width: 100%; }
.vz-caption {
  margin: .35rem auto 0;
  max-width: 34rem;
  text-align: center;
  font-family: var(--vz-body);
  font-size: .95rem;
  color: var(--vz-pencil);
  opacity: .85;
}

.vz-svg {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  overflow: visible;
}
.vz-svg text {
  font-family: var(--vz-hand);
  fill: var(--vz-pencil);
  paint-order: stroke;
  stroke: none;
}
.vz-svg text.vz-small { font-family: var(--vz-body); }
.vz-svg text.vz-emoji { font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.vz-svg .vz-num { font-family: var(--vz-body); font-weight: 700; }

.vz-line { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.vz-dash { stroke-dasharray: 6 6; }
.vz-edge { stroke: var(--vz-ink); stroke-width: 3; }
.vz-faded { stroke: var(--vz-muted); stroke-width: 3; stroke-dasharray: 7 7; }
.vz-fade-area { opacity: .5; }
.vz-tick { stroke: var(--vz-ink); stroke-width: 3; }
.vz-tick-s { stroke: var(--vz-ink); stroke-width: 2.2; }
.vz-cell { fill: var(--vz-ink); fill-opacity: .06; stroke: var(--vz-ink); stroke-width: 2.5; stroke-linejoin: round; }
.vz-circle { fill-opacity: .045; stroke-width: 3; }
.vz-perimeter { stroke: var(--vz-red); stroke-width: 7; opacity: .92; }
.vz-one { stroke: var(--vz-ink); stroke-width: 6; }
.vz-band { stroke: var(--vz-marker); opacity: .75; stroke-linecap: butt; }
.vz-band-soft { opacity: .45; }
.vz-strike { text-decoration: line-through; opacity: .75; }
.vz-pill-bg { fill: var(--vz-paper); opacity: .88; }
.vz-num-bg { fill: var(--vz-paper); stroke: var(--vz-red); stroke-width: 1.6; }
.vz-dot { stroke: var(--vz-paper); stroke-width: 1.5; }
.vz-flag { stroke-width: 1.5; stroke-linejoin: round; }

/* timeline */
.vz-play { fill: var(--vz-ink); fill-opacity: .16; }
.vz-break { stroke: none; }
.vz-hatch-bg { fill: var(--vz-muted); fill-opacity: .18; }
.vz-hatch-line { stroke: var(--vz-pencil); stroke-opacity: .55; }
.vz-hi-fill { fill: var(--vz-marker); opacity: .78; }

/* bars */
.vz-seg { stroke-width: 2; }
.vz-seg-ink { fill: var(--vz-ink); fill-opacity: .22; stroke: var(--vz-ink); }
.vz-seg-red { fill: var(--vz-red); fill-opacity: .2; stroke: var(--vz-red); }
.vz-seg-answer { fill: var(--vz-red); fill-opacity: .2; stroke: var(--vz-red); stroke-width: 3; }
.vz-seg-marker { fill: var(--vz-marker); fill-opacity: .85; stroke: var(--vz-pencil); stroke-opacity: .55; }
.vz-seg-muted { fill: var(--vz-muted); fill-opacity: .1; stroke: var(--vz-muted); stroke-dasharray: 5 4; }
.vz-seg-pencil { fill: var(--vz-pencil); fill-opacity: .1; stroke: var(--vz-pencil); }

/* magic square */
.vz-mcell-a { fill: var(--vz-marker); opacity: .7; }
.vz-mcell-b { fill: var(--vz-ink); opacity: .22; }
.vz-mcell-shared { opacity: .6; }
.vz-fill-marker { fill: var(--vz-marker); }
.vz-fill-ink { fill: var(--vz-ink); fill-opacity: .45; }
.vz-mline { stroke-width: 10; opacity: .55; }
.vz-mline-a { stroke: var(--vz-marker); opacity: .9; stroke-width: 8; }
.vz-mline-b { stroke: var(--vz-ink); opacity: .35; stroke-width: 8; }
.vz-gridline { stroke: var(--vz-ink); stroke-width: 2; }

/* per-kind size limits (the SVGs scale with the column) */
.vz-k-magic .vz-svg { max-width: 330px !important; }
.vz-k-circle .vz-svg { max-height: 420px; }

/* ------------------------------------------------------------ HTML kinds */

.vz-math, .vz-chips, .vz-emoji {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: .6rem .7rem;
  padding: .4rem .2rem;
}
.vz-card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  min-width: 3.2rem;
  max-width: 11rem;
  padding: .35rem .7rem .45rem;
  border: 2px solid currentColor;
  border-radius: .7rem;
  color: var(--vz-ink);
  background: color-mix(in srgb, var(--vz-paper) 85%, transparent);
}
.vz-card-val {
  position: relative;
  display: inline-block;
  font-family: var(--vz-hand);
  font-size: clamp(1.7rem, 6vw, 2.4rem);
  line-height: 1.1;
  font-weight: 700;
  padding: 0 .25em;
}
.vz-card-lab {
  font-family: var(--vz-body);
  font-size: .8rem;
  line-height: 1.2;
  text-align: center;
  color: var(--vz-pencil);
  opacity: .9;
}
.vz-card.vz-unknown { border-style: dashed; color: var(--vz-muted); }
.vz-card.vz-tone-answer, .vz-card.vz-tone-red { color: var(--vz-red); }
.vz-card.vz-tone-answer { border-color: transparent; background: transparent; }
.vz-card.vz-tone-marker { background: color-mix(in srgb, var(--vz-marker) 70%, transparent); color: var(--vz-on-marker); }
.vz-mgroup { display: inline-flex; align-items: center; gap: .6rem; flex-wrap: nowrap; }
.vz-op {
  font-family: var(--vz-hand);
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  font-weight: 700;
  color: var(--vz-pencil);
}

/* answer ring: a red pen ellipse around the value */
.vz-ring {
  position: absolute;
  left: -18%;
  top: -22%;
  width: 136%;
  height: 144%;
  pointer-events: none;
  overflow: visible;
}
.vz-ring-path { fill: none; stroke: var(--vz-red); stroke-width: 3; stroke-linecap: round; }

/* emoji */
.vz-emoji { align-items: flex-start; gap: .8rem 1.1rem; }
.vz-egroup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  padding: .45rem .6rem .5rem;
  border: 2px dashed color-mix(in srgb, var(--vz-ink) 45%, transparent);
  border-radius: 1rem;
  max-width: 100%;
}
.vz-ewrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .12em;
  font-size: clamp(1.5rem, 5.5vw, 2rem);
  line-height: 1.15;
}
.vz-ewrap.vz-egrid { display: grid; justify-items: center; }
.vz-single-e .vz-ewrap { font-size: clamp(2.4rem, 9vw, 3rem); }
.vz-elabel.vz-elabel-long { font-size: clamp(.95rem, 3.4vw, 1.1rem); max-width: 12em; }
.vz-egroup.vz-many .vz-ewrap { font-size: clamp(1.2rem, 4.4vw, 1.55rem); }
.vz-ewrap.vz-bubbled { gap: .3em .35em; max-width: 15em; }
.vz-bubble {
  display: inline-flex;
  gap: .02em;
  padding: .06em .22em;
  border: 2px solid color-mix(in srgb, var(--vz-red) 60%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--vz-red) 7%, transparent);
}
.vz-e { display: inline-block; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.vz-elabel {
  font-family: var(--vz-hand);
  font-size: clamp(1.15rem, 4vw, 1.4rem);
  font-weight: 700;
  color: var(--vz-red);
  text-align: center;
}

/* chips */
.vz-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.6em;
  padding: .15em .55em;
  border: 2px solid var(--vz-ink);
  border-radius: .6rem;
  font-family: var(--vz-hand);
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 700;
  color: var(--vz-ink);
  background: color-mix(in srgb, var(--vz-paper) 85%, transparent);
}
.vz-chip.vz-fresh { background: color-mix(in srgb, var(--vz-marker) 65%, transparent); color: var(--vz-on-marker); }
.vz-chip.vz-tone-answer { border-color: transparent; color: var(--vz-red); background: transparent; }
.vz-chip.vz-tone-red { border-color: var(--vz-red); color: var(--vz-red); }
.vz-chip.vz-tone-muted { border-color: var(--vz-muted); color: var(--vz-muted); }

/* place-value table */
.vz-place {
  display: grid;
  grid-template-columns: repeat(var(--vz-cols, 4), minmax(0, 1fr));
  gap: .4rem;
  max-width: 34rem;
  margin: 0 auto;
}
@media (max-width: 420px) { .vz-place { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.vz-pcol {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  padding: .4rem .25rem .5rem;
  border: 2px solid color-mix(in srgb, var(--vz-ink) 55%, transparent);
  border-radius: .7rem;
  min-width: 0;
}
.vz-phead { font-family: var(--vz-body); font-weight: 700; font-size: .85rem; color: var(--vz-ink); text-align: center; }
.vz-prule {
  font-family: var(--vz-hand);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--vz-red);
  border: 2px solid var(--vz-red);
  border-radius: 999px;
  padding: 0 .55em;
  min-height: 1.6em;
  white-space: nowrap;
}
.vz-prule-empty { border-color: transparent; color: var(--vz-muted); }
.vz-pdigits { display: flex; flex-wrap: wrap; justify-content: center; gap: .2rem; max-width: 8.2em; }
.vz-dchip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55em;
  height: 1.55em;
  border-radius: 50%;
  border: 1.5px solid var(--vz-ink);
  font-family: var(--vz-hand);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--vz-ink);
}
.vz-pq { font-family: var(--vz-hand); font-size: 1.6rem; color: var(--vz-muted); }

/* digits (number boxes) */
.vz-digits { display: flex; justify-content: center; gap: .25rem; flex-wrap: nowrap; padding: .4rem 0; }
.vz-slot { display: flex; flex-direction: column; align-items: center; gap: .25rem; min-width: 0; }
.vz-slot-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(2.3rem, 11vw, 3.4rem);
  height: clamp(2.8rem, 13vw, 4rem);
  border: 2.5px solid var(--vz-ink);
  border-radius: .45rem;
  background: color-mix(in srgb, var(--vz-paper) 85%, transparent);
  font-family: var(--vz-hand);
  font-size: clamp(1.8rem, 8vw, 2.7rem);
  font-weight: 700;
  color: var(--vz-ink);
}
.vz-slot-box.vz-tone-red { border-color: var(--vz-red); color: var(--vz-red); background: color-mix(in srgb, var(--vz-red) 8%, transparent); }
.vz-slot-box.vz-slot-empty { border-style: dashed; border-color: var(--vz-muted); }
.vz-slot-digit { display: inline-block; }
.vz-slot-place { font-family: var(--vz-body); font-size: .8rem; font-weight: 700; color: var(--vz-pencil); opacity: .8; }

/* ------------------------------------------------------------ animations */

.vz-a-draw {
  stroke-dasharray: 1 1;
  animation: vz-draw var(--vz-dur, 900ms) ease-in-out var(--vz-delay, 0ms) both;
}
@keyframes vz-draw {
  0% { stroke-dashoffset: 1; opacity: 0; }
  3% { opacity: 1; }
  100% { stroke-dashoffset: 0; opacity: 1; }
}
.vz-a-pop {
  transform-box: fill-box;
  transform-origin: center;
  animation: vz-pop var(--vz-dur, 480ms) ease-out var(--vz-delay, 0ms) both;
}
span.vz-a-pop, div.vz-a-pop { display: inline-block; }
.vz-card.vz-a-pop, .vz-chip.vz-a-pop, .vz-bubble.vz-a-pop, .vz-slot-box.vz-a-pop, .vz-dchip.vz-a-pop { display: inline-flex; }
.vz-elabel.vz-a-pop { display: block; }
@keyframes vz-pop {
  0% { opacity: 0; transform: scale(.25); }
  65% { opacity: 1; transform: scale(1.14); }
  100% { opacity: 1; transform: scale(1); }
}
.vz-a-grow {
  transform-box: fill-box;
  transform-origin: left center;
  animation: vz-grow var(--vz-dur, 600ms) ease-out var(--vz-delay, 0ms) both;
}
@keyframes vz-grow {
  0% { transform: scaleX(0); opacity: .2; }
  100% { transform: scaleX(1); opacity: 1; }
}
.vz-a-fade { animation: vz-fade var(--vz-dur, 500ms) ease-out var(--vz-delay, 0ms) both; }
@keyframes vz-fade { from { opacity: 0; } }

/* ------------------------------------------------------------ viewer */

.vz-viewer {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  color: var(--vz-pencil);
  font-family: var(--vz-body);
  outline: none;
  border-radius: 1rem;
}
.vz-viewer:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--vz-ink) 40%, transparent); }
.vz-viewer-empty { display: none; }

.vz-vhead { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }
.vz-counter { font-family: var(--vz-hand); font-size: 1.3rem; font-weight: 700; color: var(--vz-ink); }
.vz-dots { display: flex; gap: .35rem; flex-wrap: wrap; }
.vz-dot {
  width: 1rem;
  height: 1rem;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--vz-ink);
  background: transparent;
  cursor: pointer;
  transition: transform .2s, background-color .2s;
}
.vz-dot.vz-dot-pic { border-radius: .25rem; }
.vz-dot.vz-seen { background: color-mix(in srgb, var(--vz-ink) 30%, transparent); }
.vz-dot.vz-on { background: var(--vz-red); border-color: var(--vz-red); transform: scale(1.3); }
.vz-single .vz-dots, .vz-single .vz-prev, .vz-single .vz-next { visibility: hidden; }

.vz-frame { touch-action: pan-y; min-height: 6rem; overflow: hidden; }
.vz-fcard {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: .45rem;
  animation: vz-slide-in .35s ease-out both;
}
.vz-fcard.vz-from-left { animation-name: vz-slide-in-left; }
@keyframes vz-slide-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes vz-slide-in-left { from { opacity: 0; transform: translateX(-24px); } }
.vz-ftag {
  align-self: center;
  font-family: var(--vz-hand);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--vz-ink);
}
.vz-ftext {
  margin: 0;
  text-align: center;
  font-size: clamp(1.05rem, 3.6vw, 1.25rem);
  line-height: 1.35;
  color: var(--vz-pencil);
}
.vz-fmath { text-align: center; }
.vz-fmath-in {
  display: inline;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  font-family: var(--vz-hand);
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--vz-ink);
  padding: 0 .3em;
  background: linear-gradient(transparent 62%, color-mix(in srgb, var(--vz-marker) 70%, transparent) 62%, color-mix(in srgb, var(--vz-marker) 70%, transparent) 92%, transparent 92%);
}
.vz-fmath.vz-writing { animation: vz-write .8s steps(18, end) .15s both; }
@keyframes vz-write {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}
.vz-stage { padding: .2rem 0; }

.vz-nav { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.vz-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  min-height: 2.75rem;
  padding: .35rem .95rem;
  border: 2px solid var(--vz-ink);
  border-radius: 999px;
  background: var(--vz-paper);
  color: var(--vz-ink);
  font-family: var(--vz-hand);
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.vz-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--vz-ink) 10%, var(--vz-paper)); }
.vz-btn:disabled { opacity: .35; cursor: default; }
.vz-btn-icon { font-size: 1.5rem; line-height: 1; }
.vz-next { border-color: var(--vz-red); color: var(--vz-red); }
.vz-replay { border-style: dashed; }
@media (max-width: 420px) {
  .vz-btn-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .vz-btn { padding: .35rem .9rem; }
}

/* ------------------------------------------------------------ reduced motion: final state, no movement */

@media (prefers-reduced-motion: reduce) {
  .vz-visual *, .vz-viewer * { animation: none !important; transition: none !important; }
  .vz-a-draw { stroke-dasharray: none !important; }
}

/* chips already have padding: keep their answer rings tight so neighbours do not overlap */
.vz-chip .vz-ring { left: -5%; width: 110%; top: -12%; height: 124%; }
.vz-chips:has(.vz-tone-answer) { gap: .7rem 1.1rem; }
