@font-face {
  font-family: Instrument Serif;
  src: url('./assets/instrument-serif-latin-400-normal.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: Instrument Serif;
  src: url('./assets/instrument-serif-latin-400-italic.woff2') format('woff2');
  font-style: italic;
  font-display: swap;
}
:root {
  color-scheme: light;
  --paper: #f8f5ed;
  --card: #fffdf8;
  --ink: #20382c;
  --sub: #546254;
  --green: #25563d;
  --line: #e8e1d3;
  --sage: #eaf2e4;
  --gold: #a56512;
  --carry-light: #daebf9;
  --carry-blue: #8bbce1;
  --carry-ink: #214f73;
  --serif: 'Instrument Serif', Georgia, serif;
  font-family: 'Avenir Next', Avenir, system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #b1782c;
  outline-offset: 3px;
}
.topbar { border-bottom: 1px solid var(--line); background: #fffcf5; }
.topbar-inner {
  min-height: 76px;
  width: min(1080px, calc(100% - 56px));
  margin: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-icon, .pony-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 14px;
  color: #fff5db;
  background: var(--green);
  font: 32px Georgia, serif;
}
.brand strong { display: block; font-size: 19px; line-height: 1.2; letter-spacing: -.03em; }
.brand small { color: var(--sub); font-size: 13px; font-weight: 600; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.sound-toggle {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 10px;
  border: 1px solid #cddaca;
  border-radius: 999px;
  background: var(--sage);
  color: var(--green);
  font-size: 14px;
  font-weight: 750;
}
.sound-toggle:hover { background: #dfecda; }
.sound-icon { position: relative; font-size: 20px; line-height: 1; }
.sound-toggle[aria-pressed="false"] { background: var(--card); color: var(--sub); }
.sound-toggle[aria-pressed="false"] .sound-icon::after {
  position: absolute;
  content: '';
  height: 2px;
  width: 17px;
  background: currentColor;
  left: -4px;
  top: 9px;
  transform: rotate(-42deg);
}
.plaque-counter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 7px 12px;
  border: 1px solid #dfc99b;
  border-radius: 999px;
  background: #fff8e6;
  color: #754a15;
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
}
.plaque-icon {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border: 1px solid #b47a2f;
  border-radius: 50%;
  background: #ffdf95;
  font: 17px/1 Georgia, serif;
}
main { width: min(1080px, calc(100% - 56px)); margin: auto; padding-bottom: 52px; }
.intro { padding: 37px 0 26px; }
h1 { font: 400 clamp(3.8rem, 7.1vw, 6.5rem)/.98 var(--serif); letter-spacing: -.034em; margin: 0 0 11px; }
h1 em { color: #416849; font-weight: 400; }
.intro p { margin: 0; color: var(--sub); font-size: 17px; font-weight: 550; }
.practice { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 15px; }
.mode { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 16px; background: #f0ebdf; }
.mode button {
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  min-height: 41px;
  padding: 0 16px;
  font-weight: 750;
  font-size: 14px;
}
.mode button span { margin-right: 4px; font-size: 16px; }
.mode button:hover { background: #fffcf4; }
.mode button[aria-pressed="true"] { background: var(--green); color: white; }
.level { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--sub); font-weight: 680; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: '';
  position: absolute;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--green);
  border-bottom: 2px solid var(--green);
  transform: rotate(45deg);
  top: 17px;
  right: 15px;
  pointer-events: none;
}
select { appearance: none; border: 1px solid var(--line); border-radius: 12px; background: var(--card); padding: 10px 38px 10px 14px; min-height: 44px; font-weight: 650; color: var(--ink); }
.game-layout { display: grid; grid-template-columns: minmax(0, 1.77fr) minmax(290px, 1fr); align-items: start; gap: 19px; }
.sidebar { display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 23px; box-shadow: 0 6px 16px #47341508; }
.game { padding: 22px 25px 24px; min-height: 502px; }
.equation { margin: 12px 0 2px; text-align: center; font-size: clamp(2rem, 4vw, 3rem); font-weight: 800; line-height: 1.16; letter-spacing: -.055em; }
.equation span { color: #686d49; font-weight: 600; margin: 0 3px; }
.step-title { font-size: 16px; color: var(--green); text-align: center; margin: 4px 0 15px; font-weight: 750; }
.board { display: grid; gap: 7px; margin: 0 auto 16px; max-width: 475px; }
.place-row {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 47px;
  padding: 5px 12px;
  background: #f6f2e9;
  border: 1px solid #eee7d9;
  border-radius: 12px;
}
.place-row[aria-current="step"] {
  background: var(--sage);
  border: 2px solid #86a988;
  padding: 4px 11px;
}
.place-tag { color: var(--sub); font-size: 15px; font-weight: 750; }
.place-row[aria-current="step"] .place-tag { color: var(--green); }
.place-visual { grid-column: 1 / -1; min-width: 0; margin-bottom: 3px; }
.block-calculation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 7px;
  background: #f9fcf6;
  color: var(--green);
  font-weight: 750;
}
.row-calculation { font-size: clamp(1rem, 3.6vw, 1.35rem); font-weight: 740; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-result { color: #6a6659; }
.place-row[aria-current="step"] .row-result, .solved .row-result { color: var(--green); }
.incoming { color: var(--carry-ink); }
.row-notes { display: flex; gap: 3px; border-left: 1px solid #d4c5a8; padding-left: 7px; }
.row-note { background: #ffe4a9; color: #754a15; border-radius: 6px; padding: 3px 5px; font-size: 12px; font-weight: 750; white-space: nowrap; }
.carry-note { background: var(--carry-light); color: var(--carry-ink); }
.moved { animation: nudge .48s ease both; }
.guidance { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; margin-bottom: 9px; }
.calc-prompt { font-size: 14px; color: var(--sub); font-weight: 700; }
.hint { background: #fff4da; color: #754a15; border: 1px solid #f0deb4; min-height: 40px; padding: 5px 13px; border-radius: 11px; font-weight: 750; }
.hint:hover { background: #ffebbe; }
.hint-text, .feedback { border-radius: 9px; margin: 0 0 9px; padding: 8px 10px; font-size: 14px; font-weight: 650; }
.hint-text { background: #fff4da; color: #754a15; }
.feedback { background: #f9ece3; color: #814735; }
.number-pad { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 5px; }
.number-pad button {
  min-height: 44px;
  padding: 0;
  border: 1px solid #e6e1d3;
  border-bottom-width: 3px;
  border-radius: 10px;
  background: #f8f5ed;
  font-size: 19px;
  font-weight: 800;
}
.number-pad button:hover { background: var(--sage); border-color: #a4b9a1; }
.number-pad button[aria-pressed="true"] { background: #d9e9d6; border-color: #6e9476; color: #1d4532; }
.primary { border: 1px solid var(--green); background: var(--green); color: white; padding: 9px 15px; border-radius: 11px; min-height: 44px; font-weight: 770; }
.primary:hover { background: #1a422e; }
.primary:disabled { background: #e8eee3; border-color: #e8eee3; color: #536950; cursor: default; }
.check { margin-top: 12px; width: 100%; }
.check span { margin-left: 4px; }
.result-form {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid #d7e3d2;
  border-radius: 12px;
  background: var(--sage);
}
.result-form label { display: block; margin-bottom: 8px; color: var(--green); font-weight: 750; }
.result-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.result-controls input {
  flex: 1 1 64px;
  min-width: 0;
  min-height: 46px;
  padding: 5px 10px;
  border: 1px solid #a8bda5;
  border-radius: 9px;
  color: var(--ink);
  background: white;
  font: inherit;
  font-size: 21px;
  font-weight: 750;
}
.result-controls input[aria-invalid="true"] { border-color: #a45c45; }
.result-form .feedback { margin: 8px 0 0; }
.result-form .feedback:empty { display: none; }
.parent-footer { margin-top: 24px; text-align: right; }
.parent-footer a { color: var(--sub); font-size: 14px; font-weight: 700; text-underline-offset: 3px; }
.exchange {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  background: #fff5dd;
  border: 1px solid #edd8a9;
  border-radius: 13px;
  color: #67451f;
  padding: 12px;
}
.exchange p { margin: 3px 0 0; font-size: 14px; }
.exchange-blocks { display: flex; gap: 8px; align-items: center; justify-content: center; }
.exchange-blocks .counted-blocks { flex-direction: column; align-items: flex-start; }
.exchange .primary { grid-column: 1 / -1; }
.ten-panel {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid #edd8a9;
  border-radius: 13px;
  background: #fff5dd;
  color: #67451f;
}
.ten-instruction p { margin: 4px 0 0; font-size: 14px; }
.ten-visual { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.ten-field {
  display: grid;
  grid-template-columns: max-content;
  gap: 4px;
  width: max-content;
  padding: 6px;
  border: 2px solid #dfcb9e;
  border-radius: 9px;
  background: #fffdf8;
}
.ten-field.full { border-color: #ad7924; background: #ffedb8; animation: ten-glow .6s ease-out; }
.chip { display: block; width: 22px; height: 22px; border-radius: 5px; }
.chip.empty { border: 1px dashed #b3a27d; background: #f7f1e4; }
.chip-original { border: 1px solid #40644a; background: #7d9e78; box-shadow: inset 0 -3px #547455; }
.chip-added { border: 1px solid #9b631d; background: #e9b450; box-shadow: inset 0 -3px #bd8432; }
.chip-overflow { border: 1px solid var(--carry-ink); background: var(--carry-blue); box-shadow: inset 0 -3px #5b8eb6; }
.ten-field.full .chip-added, .ten-field.full .chip-overflow { animation: fill-ten .38s ease-out both; }
.ten-extra, .ten-remainder { display: grid; gap: 5px; font-size: 14px; font-weight: 700; }
.ten-chips { display: grid; gap: 4px; width: max-content; }
.ten-chips .count-band, .ten-field .count-band { gap: 4px; }
.ten-bundled {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px 14px;
  padding: 8px 10px;
  border-radius: 9px;
  background: #fff5dd;
  color: #67451f;
  font-size: 14px;
  font-weight: 700;
}
.ten-bundled .ten-remainder { display: flex; align-items: center; gap: 7px; }
.place-row .ten-transfer {
  position: absolute;
  right: 63px;
  top: 13px;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  animation: transfer-ten .56s ease-in-out both;
}
@keyframes fill-ten {
  from { transform: translate(18px, -3px) scale(.8); opacity: .45; }
  to { transform: translate(0) scale(1); opacity: 1; }
}
@keyframes ten-glow {
  45% { box-shadow: 0 0 0 4px #e6b54c55; }
}
@keyframes transfer-ten {
  0% { top: 13px; transform: scale(.8); opacity: 0; }
  20% { opacity: 1; }
  75% { top: calc(100% + 17px); transform: scale(1); opacity: 1; }
  100% { top: calc(100% + 22px); opacity: 0; }
}
.blocks { display: grid; gap: 2px; grid-template-columns: repeat(5, auto); justify-content: center; }
.blocks i { display: block; }
.blocks.counted-blocks { display: flex; flex-wrap: wrap; justify-content: start; gap: 4px 6px; max-width: 100%; }
.count-band { display: inline-flex; align-items: center; gap: 3px; }
.count-divider { color: #514730; font: 700 15px/1 ui-monospace, monospace; letter-spacing: -.1em; }
.blocks-0 i { width: 9px; height: 9px; border-radius: 2px; background: #c98b39; box-shadow: inset 0 -2px #92591e; }
.blocks-1 i { width: 6px; height: 18px; border-radius: 1px; background: repeating-linear-gradient(#81a180 0 2px, #5d815e 2px 3px); }
.blocks-2 i { width: 22px; height: 22px; border: 1px solid #63816c; border-radius: 2px; background: repeating-linear-gradient(90deg, #63816c70 0 1px, transparent 1px 3px), repeating-linear-gradient(#63816c 0 1px, #a2bb9b 1px 3px); }
.block-calculation .blocks-0 i { width: 12px; height: 12px; background: #7d9e78; box-shadow: inset 0 -2px #547455; }
.block-calculation .blocks-added.blocks-0 i { background: #e9b450; box-shadow: inset 0 -2px #bd8432; }
.block-calculation .blocks-added.blocks-1 i { background: repeating-linear-gradient(#e9b450 0 2px, #a56d24 2px 3px); }
.block-calculation .blocks-added.blocks-2 i {
  border-color: #a56d24;
  background: repeating-linear-gradient(90deg, #a56d246b 0 1px, transparent 1px 3px), repeating-linear-gradient(#a56d24 0 1px, #e9b450 1px 3px);
}
.blocks-carry.blocks-1 i, .blocks-1 .loan-block {
  background: repeating-linear-gradient(var(--carry-blue) 0 2px, var(--carry-ink) 2px 3px);
}
.blocks-carry.blocks-2 i, .blocks-2 .loan-block {
  border-color: var(--carry-ink);
  background: repeating-linear-gradient(90deg, #214f7366 0 1px, transparent 1px 3px), repeating-linear-gradient(var(--carry-ink) 0 1px, var(--carry-blue) 1px 3px);
}
.block-calculation .blocks .removed { position: relative; opacity: .55; filter: grayscale(1); }
.block-calculation .blocks .loan-block { opacity: 1; filter: none; }
.block-calculation .removed::after {
  position: absolute;
  inset: 0;
  content: '';
  background: linear-gradient(to bottom right, transparent 44%, #29362f 46% 54%, transparent 56%);
}
.equation + .board { margin-top: 12px; }
.completed {
  background: radial-gradient(ellipse at 50% 0, #ffedb1, #fcf5df 67%);
  border: 1px solid #ecd6a0;
  text-align: center;
  border-radius: 16px;
  padding: 13px 12px 12px;
  display: grid;
  gap: 5px;
}
.celebration-heading {
  margin: 0;
  color: var(--green);
  font: 400 clamp(2.6rem, 7vw, 4rem)/1 var(--serif);
  animation: celebration-praise .62s cubic-bezier(.2,.8,.25,1) both;
}
.completed strong { font-size: 20px; }
.completed span { font-size: 14px; color: var(--green); font-weight: 720; }
.completed button { margin-top: 7px; }
.completed.celebrate { border-color: #d5a541; background: #fff0ca; animation: nudge .55s ease both; }
.reward-burst {
  position: relative;
  justify-self: center;
  color: #ab6308;
  font: 48px/1 system-ui, sans-serif;
  pointer-events: none;
  animation: reward-pop .85s cubic-bezier(.19,.8,.28,1) both;
}
.reward-burst.plaque-burst { animation: plaque-reveal .9s cubic-bezier(.19,.8,.28,1) both; }
.completed .horse-plaque {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border: 3px solid #b27626;
  border-radius: 50%;
  color: #754a15;
  background: linear-gradient(135deg, #d3943c, #ffedb0 32%, #ffd573 63%, #ca842e);
  box-shadow: inset 0 0 0 5px #fff3cd, inset 0 0 0 7px #bc7929, 0 4px 9px #88602034;
  font: 58px/1 Georgia, serif;
}
.completed .plaque-prize { color: #754a15; }
.reward-spark {
  position: absolute;
  inset: 50% auto auto 50%;
  color: #b17719;
  font: normal 19px/1 Georgia, serif;
  opacity: 0;
  animation: reward-spark .8s ease-out both;
}
.reward-spark:nth-child(1) { --x: -94px; --y: -16px; }
.reward-spark:nth-child(2) { --x: -51px; --y: -47px; animation-delay: .06s; }
.reward-spark:nth-child(3) { --x: 36px; --y: -49px; }
.reward-spark:nth-child(4) { --x: 82px; --y: -19px; animation-delay: .08s; }
.reward-spark:nth-child(5) { --x: 66px; --y: 22px; animation-delay: .1s; }
body:has(.plaque-burst) .plaque-counter { animation: plaque-counter-pop .65s .28s ease both; }
@keyframes plaque-reveal {
  0% { transform: perspective(360px) rotateY(-105deg) scale(.4); opacity: 0; }
  52% { transform: perspective(360px) rotateY(16deg) scale(1.12); opacity: 1; }
  100% { transform: perspective(360px) rotateY(0) scale(1); opacity: 1; }
}
@keyframes celebration-praise {
  0% { transform: translateY(10px) scale(.8); opacity: 0; }
  58% { transform: translateY(0) scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes reward-pop {
  0% { transform: scale(.45) rotate(-22deg); opacity: 0; }
  42% { transform: scale(1.32) rotate(12deg); opacity: 1; }
  72% { transform: scale(.94) rotate(-5deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
@keyframes reward-spark {
  0% { transform: translate(-50%, -50%) scale(.25); opacity: 0; }
  29% { opacity: 1; }
  100% { transform: translate(var(--x), var(--y)) scale(.75); opacity: 0; }
}
@keyframes plaque-counter-pop {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.09); background: #ffe0a0; }
}
.pony { overflow: hidden; }
.pony img { display: block; width: 100%; height: auto; aspect-ratio: 1.51; object-fit: cover; object-position: center 7%; background: #dfd3a3; }
.pony-caption { padding: 14px 16px; display: flex; align-items: center; gap: 11px; }
.pony-mark { width: 38px; height: 38px; border-radius: 999px; font-size: 24px; background: #eaf0e4; color: var(--green); }
.sidebar h2 { margin: 0; font: 400 29px/1 var(--serif); }
.sidebar p { margin: 4px 0 0; color: var(--sub); font-size: 14px; line-height: 1.3; font-weight: 600; }
.cup { padding: 15px 16px; }
.cup-head { display: flex; gap: 11px; align-items: center; margin-bottom: 12px; }
.cup-icon { display: grid; flex: none; place-items: center; background: #faedcf; width: 44px; height: 44px; font-size: 22px; border-radius: 13px; }
.cup.won { border-color: #d7a850; background: #fffae9; }
.cup-progress { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; font-size: 14px; }
.cup-dots { display: flex; gap: 3px; }
.cup-dots span { width: clamp(16px, 4vw, 20px); aspect-ratio: 1; display: grid; place-items: center; color: #948674; background: #f1ede4; border-radius: 50%; font-size: 11px; filter: grayscale(1); opacity: .5; }
.cup-dots .filled { background: #ffe2a0; filter: none; opacity: 1; }
@keyframes nudge { 0% { transform: scale(.97); } 55% { background-color: #fff0c1; transform: scale(1.04); } 100% { transform: scale(1); } }
@media (max-width: 830px) {
  .number-pad { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .game { min-height: 0; }
}
@media (max-width: 650px) {
  .topbar-inner, main { width: calc(100% - 28px); }
  .topbar-inner { min-height: 64px; }
  .sound-label, .plaque-label { display: none; }
  .header-actions { flex: none; gap: 5px; }
  .intro { padding: 24px 0 17px; }
  .intro p { max-width: 34ch; font-size: 15px; }
  .practice { flex-wrap: wrap; }
  .game-layout { grid-template-columns: 1fr; }
  .game { padding: 16px; }
  .sidebar { grid-template-columns: 1fr; }
  .pony img { aspect-ratio: 1.75; }
  h1 { font-size: clamp(3rem, 11.8vw, 4.8rem); }
}
@media (max-width: 360px) {
  .brand { gap: 8px; }
  .brand-icon { width: 38px; height: 38px; }
  .brand strong { font-size: 16px; }
  .mode button { padding-inline: 10px; }
  .plaque-counter { padding-inline: 8px; }
  .place-row { grid-template-columns: 20px minmax(0, 1fr) auto; gap: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}
