:root {
  --paper: #efe7d4;
  --paper-2: #e3d8bf;
  --paper-card: #fffaf0;

  --ink: #2a3554;
  --ink-2: #4d5072;
  --ink-3: #8b8aa0;

  --blue: #5a6c8d;
  --mauve: #8378a3;
  --sage: #6f8c5a;
  --butter: #c9a64a;
  --coral: #c47b5a;
  --brown: #8a6849;
  --muted: #7a7058;

  --font-display: 'Yeseva One', 'ZCOOL XiaoWei', serif;
  --font-body: 'Nunito', 'Noto Sans SC', system-ui, sans-serif;
  --font-cn: 'ZCOOL XiaoWei', 'Ma Shan Zheng', serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
button { font: inherit; color: inherit; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  min-height: 100dvh;
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: .45;
  background-image:
    radial-gradient(circle at 18% 22%, rgba(0,0,0,.04) 1px, transparent 2px),
    radial-gradient(circle at 70% 55%, rgba(120,80,30,.03) 1px, transparent 2px),
    radial-gradient(circle at 40% 84%, rgba(0,0,0,.035) 1px, transparent 2px);
  background-size: 220px 220px, 180px 180px, 240px 240px;
  mix-blend-mode: multiply;
}

.site-header {
  position: relative;
  z-index: 5;
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(42,53,84,.10);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 36px; height: 36px; display: block; flex: 0 0 36px; }
.brand-name {
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1;
  color: var(--ink);
  letter-spacing: 0;
}
.brand-tagline {
  font-family: var(--font-cn);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 1.5px;
  margin-top: 4px;
  white-space: nowrap;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--paper-card);
  background: var(--ink);
  border: 0;
  border-radius: 999px;
  padding: 9px 16px;
  font-family: var(--font-cn);
  font-size: 14px;
  letter-spacing: 1px;
  cursor: pointer;
}
.tool-btn:hover { background: var(--ink-2); }
.tool-icon { font-family: var(--font-body); font-weight: 800; }

.practice-shell {
  position: relative;
  z-index: 5;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 0;
}

.score-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.progress-dots {
  display: grid;
  grid-template-columns: repeat(10, minmax(12px, 1fr));
  gap: 6px;
  flex: 1;
}
.progress-dot {
  height: 10px;
  border-radius: 999px;
  background: rgba(42,53,84,.12);
  border: 1px solid rgba(42,53,84,.16);
}
.progress-dot.done { background: var(--sage); border-color: var(--sage); }
.progress-dot.active { background: var(--butter); border-color: var(--brown); }

.stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.stats span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 30px;
  padding: 5px 10px;
  border: 1.5px solid rgba(42,53,84,.18);
  border-radius: 999px;
  background: rgba(255,250,240,.58);
  color: var(--ink-2);
  font-family: var(--font-cn);
  font-size: 14px;
  letter-spacing: 1px;
}
.stats b { color: var(--ink); font-family: var(--font-body); font-weight: 800; }

.practice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: stretch;
}

.equation-card,
.place-card,
.result-panel {
  background: var(--paper-card);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 5px 0 rgba(42,53,84,.16);
}

.equation-card,
.place-card {
  padding: 18px 22px;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  container-type: inline-size;
}

.column-labels,
.number-line {
  display: grid;
  grid-template-columns: 64px minmax(72px, 1fr) minmax(72px, 1fr);
  align-items: center;
  gap: 12px;
}

.column-labels {
  color: var(--muted);
  font-family: var(--font-cn);
  font-size: 17px;
  letter-spacing: 2px;
  text-align: center;
  margin-bottom: 6px;
}

.number-line {
  min-height: 92px;
}

.operator {
  color: var(--coral);
  font-family: var(--font-display);
  font-size: 4rem;
  line-height: 1;
  text-align: center;
}

.digit,
.answer-slot {
  height: 82px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(42,53,84,.16);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(3rem, 14cqi, 5.8rem);
  line-height: 1;
  font-weight: 800;
}

.digit.blank {
  color: transparent;
  border-style: dashed;
  background: rgba(227,216,191,.38);
}

.answer-rule {
  height: 4px;
  margin: 8px 0 14px 76px;
  background: var(--ink);
  border-radius: 999px;
}

.answer-slot {
  background: #f6ecd4;
  border-color: var(--brown);
  color: var(--blue);
  position: relative;
}
.answer-slot.empty::after {
  content: "";
  width: 34%;
  height: 3px;
  border-radius: 999px;
  background: rgba(42,53,84,.2);
}
.answer-slot.active {
  background: #fff4c9;
  border-color: var(--butter);
  box-shadow: 0 0 0 4px rgba(201,166,74,.24);
}
.answer-slot.active::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 2px dashed rgba(42,53,84,.28);
  border-radius: 6px;
  pointer-events: none;
}
.answer-line.correct .answer-slot {
  background: #e5efd8;
  border-color: var(--sage);
  color: var(--sage);
  box-shadow: none;
}
.answer-line.wrong .answer-slot {
  background: #f8ddd1;
  border-color: var(--coral);
  color: var(--coral);
  animation: nudge .28s ease-in-out;
}

@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-5px); }
  70% { transform: translateX(5px); }
}

.status {
  min-height: 32px;
  margin-top: 12px;
  text-align: center;
  color: var(--ink-2);
  font-family: var(--font-cn);
  font-size: 20px;
  letter-spacing: 2px;
}
.status.good { color: var(--sage); font-weight: 700; }
.status.bad { color: var(--coral); font-weight: 700; }
.visual-status-spacer { visibility: hidden; }

.ten-stack,
.one-stack {
  height: 82px;
  padding: 8px;
  border: 1.5px solid rgba(42,53,84,.14);
  border-radius: 8px;
  background: rgba(239,231,212,.62);
}

.ten-stack {
  display: grid;
  grid-template-columns: repeat(3, 26px);
  gap: 8px;
  align-content: center;
  justify-content: center;
  justify-items: center;
  align-items: center;
}

.one-stack {
  display: grid;
  grid-template-columns: repeat(3, 26px);
  gap: 8px;
  justify-content: center;
  justify-items: center;
  align-content: center;
  align-items: center;
}
.count-shape {
  width: 20px;
  height: 20px;
  background: var(--shape-color);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.32);
}
.ten-item { --shape-color: var(--blue); color: var(--blue); }
.one-item { --shape-color: var(--butter); color: var(--butter); }
.shape-circle {
  border-radius: 50%;
}
.shape-square {
  border-radius: 5px;
}
.shape-circle,
.shape-square,
.shape-stick {
  border: 1px solid rgba(42,53,84,.18);
}
.shape-triangle {
  width: 0;
  height: 0;
  background: transparent;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 20px solid currentColor;
  box-shadow: none;
}
.shape-stick {
  width: 30px;
  height: 8px;
  border-radius: 999px;
}
.ten-stack.is-empty,
.one-stack.is-empty { background: rgba(239,231,212,.35); }

.keypad {
  width: min(720px, 100%);
  margin: 16px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.keypad button,
.next-btn {
  border: 2px solid currentColor;
  border-radius: 8px;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, opacity .12s;
  user-select: none;
}

.keypad button {
  min-height: 50px;
  background: var(--paper-card);
  color: var(--blue);
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
}
.keypad button:nth-child(3n + 1) { color: var(--sage); }
.keypad button:nth-child(3n + 2) { color: var(--butter); }
.keypad button:nth-child(3n) { color: var(--mauve); }

/* 0 in middle column, delete at right */
.keypad button:nth-child(10) { grid-column: 2; }
.keypad button:nth-child(11) { grid-column: 3; }
.keypad .erase { color: var(--ink-2); background: var(--paper-2); }
.keypad button:hover:not(:disabled),
.next-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 0 rgba(42,53,84,.18);
}
.keypad button:disabled,
.next-btn:disabled {
  cursor: default;
  opacity: .45;
}

.actions {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}
.next-btn {
  min-width: 160px;
  min-height: 44px;
  padding: 9px 24px;
  color: var(--paper-card);
  background: var(--ink);
  font-family: var(--font-cn);
  font-size: 16px;
  letter-spacing: 1px;
}

.result-panel {
  margin: 24px auto 0;
  width: min(420px, 100%);
  padding: 24px;
  text-align: center;
}
.result-panel h1 {
  font-family: var(--font-cn);
  font-size: 32px;
  letter-spacing: 4px;
}
.result-panel p {
  margin: 12px 0 18px;
  color: var(--sage);
  font-family: var(--font-display);
  font-size: 48px;
  line-height: 1;
}

.confetti {
  position: fixed;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 30;
  animation: fall 1.6s ease-in forwards;
}

@keyframes fall {
  to {
    transform: translate(var(--x), 110vh) rotate(var(--r));
    opacity: .85;
  }
}

.site-footer {
  position: relative;
  z-index: 5;
  margin: 24px 0 18px;
  display: flex;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.site-footer .dot { opacity: .6; }

@media (max-width: 760px) {
  .site-header {
    align-items: flex-start;
    padding: 14px 18px;
  }
  .brand-tagline {
    white-space: normal;
    line-height: 1.35;
  }
  .tool-btn span:last-child { display: none; }
  .practice-shell {
    width: min(100% - 24px, 560px);
    padding-top: 18px;
  }
  .score-strip {
    align-items: stretch;
    flex-direction: column;
  }
  .stats { justify-content: flex-start; }
  .practice-grid { grid-template-columns: 1fr; }
  .equation-card,
  .place-card { min-height: auto; }
  .equation-card { padding: 18px 14px; }
  .column-labels,
  .number-line {
    grid-template-columns: 44px minmax(58px, 1fr) minmax(58px, 1fr);
    gap: 8px;
  }
  .number-line { min-height: 86px; }
  .digit,
  .answer-slot {
    height: 76px;
    font-size: clamp(2.8rem, 14cqi, 4.6rem);
  }
  .operator { font-size: 3rem; }
  .answer-rule { margin-left: 52px; }
  .place-card { padding: 14px; }
  .ten-stack,
  .one-stack { min-height: 78px; }
}
