:root {
  --cell: clamp(40px, 10vw, 58px);
  --bg: #fff8e7;
  --ink: #2b2d42;
  --grid: #c9dcee;
  --orange: #ff9f1c;
  --green: #2a9d4a;
  --red: #e63946;
  --pink: #ff4d8d;
  --yellow: #fff1a1;
  --blue: #4361ee;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Varela Round', 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(#ffe2a8 1.5px, transparent 1.5px);
  background-size: 22px 22px;
  color: var(--ink);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: #7a7d99; }

#app { max-width: 820px; margin: 0 auto; padding: 12px 16px 24px; }

/* ---------- menu ---------- */
.menu-head { display: flex; align-items: center; gap: 12px; margin: 8px 0 16px; }
.menu-head h1 { font-size: clamp(24px, 6vw, 36px); margin: 0; flex: 1; }
.logo { font-size: 52px; animation: bob 2.4s ease-in-out infinite; }
.stars-total {
  background: #fff; border: 3px solid var(--orange); border-radius: 999px;
  padding: 6px 14px; font-size: 22px; font-weight: bold;
}
.big-btn {
  display: block; width: 100%; border: 0; border-radius: 18px;
  background: var(--green); color: #fff; font-size: 26px; padding: 16px;
  box-shadow: 0 6px 0 #1d6e34; margin: 10px 0 22px; transition: transform .1s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #1d6e34; }
.big-btn.secondary { background: var(--blue); box-shadow: 0 6px 0 #2a3fa8; }
.page { background: #fff; border-radius: 20px; padding: 16px; margin-bottom: 18px; box-shadow: 0 4px 0 #f0d9a8; }
.page h2 { margin: 0 0 8px; font-size: 22px; }
.progress { height: 14px; background: #eee; border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.progress > div { height: 100%; background: linear-gradient(90deg, #52d17c, #2a9d4a); border-radius: 99px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card {
  border: 3px solid #ffd27a; background: #fffdf3; border-radius: 16px; padding: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 18px;
}
.card:hover { transform: scale(1.04); }
.card .lbl { font-weight: bold; color: var(--orange); font-size: 20px; }
.card .ex { font-size: 20px; }
.card.done { border-color: #9be3b0; background: #effff3; }
.card .st { min-height: 22px; }
.reset { background: none; border: 0; color: #aaa; text-decoration: underline; font-size: 14px; margin-top: 10px; }

/* ---------- play ---------- */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.qtitle { flex: 1; font-size: 24px; font-weight: bold; display: flex; gap: 10px; align-items: baseline; }
.qtitle .muted { font-size: 16px; font-weight: normal; }
.icon-btn {
  font-size: 26px; width: 52px; height: 52px; border-radius: 14px;
  border: 3px solid #ffd27a; background: #fff;
}
.icon-btn.off { opacity: .4; }
.streak { font-size: 22px; font-weight: bold; color: #e85d04; min-width: 60px; text-align: center; }
.streak.bump { animation: pop .4s; }

.coach { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; min-height: 90px; }
.mascot { font-size: 64px; line-height: 1; transition: transform .2s; }
.mascot.happy { animation: jump .5s; }
.mascot.sad { animation: shake .4s; }
.bubble {
  position: relative; flex: 1; background: #fff; border: 3px solid var(--ink);
  border-radius: 20px; padding: 12px 16px; font-size: 20px; line-height: 1.5;
}
.bubble::before {
  content: ''; position: absolute; right: -14px; top: 22px;
  border: 10px solid transparent; border-left-color: var(--ink);
}
.bubble.good { border-color: var(--green); background: #effff3; }
.bubble.good::before { border-left-color: var(--green); }
.bubble.bad { border-color: var(--red); background: #fff0f0; }
.bubble.bad::before { border-left-color: var(--red); }

.board-wrap {
  background: #fff; border-radius: 20px; padding: 16px; overflow-x: auto;
  display: flex; justify-content: center; box-shadow: 0 4px 0 #f0d9a8;
}
.board { display: grid; direction: ltr; grid-auto-rows: auto; }
.cell {
  width: var(--cell); height: var(--cell); position: relative;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cell) * .62); border: 1px solid var(--grid); margin: 0 -1px -1px 0;
  background: #fff; user-select: none;
}
.cell.sign { font-size: calc(var(--cell) * .6); color: #555; }
.cell.under { border-bottom: 4px solid var(--ink); }
.cell.carry {
  height: calc(var(--cell) * .55); font-size: calc(var(--cell) * .36); color: var(--pink);
  border-color: #f3f3f3; background: #fcfcff;
}
.cell.carry:not(.blank) { border: 1px dashed #f3b6cf; cursor: pointer; }
.cell.carry.selected { outline: 3px solid var(--pink); z-index: 2; background: #fff0f6; }
.cell.input { background: #fffdf0; }
.cell.ghost { color: #b4b8cc; }
.cell.hl { background: var(--yellow); }
.cell.dec-hl { background: #ffd6ea; }
.cell.active {
  outline: 4px solid var(--orange); z-index: 2; background: #fff6df;
  animation: glow 1.1s ease-in-out infinite;
}
.cell.ok { color: var(--green); background: #effff3; animation: pop .3s; }
.cell.wrong { color: var(--red); background: #ffe3e3; animation: shake .4s; }
.cell.pad { color: var(--blue); z-index: 1; animation: pop .3s; }
.cell.dot::after {
  content: ''; position: absolute; width: 12px; height: 12px; border-radius: 50%;
  background: var(--ink); right: -7px; bottom: 7px; z-index: 3;
}
.cell.dot.ok::after, .cell.dot.pad::after { background: var(--pink); animation: pop .5s; }
.gap {
  width: 32px; height: 32px; padding: 0; border-radius: 50%;
  border: 3px dashed var(--pink); background: rgba(255, 77, 141, .15);
  justify-self: start; align-self: end; transform: translate(-50%, 35%); z-index: 4;
  animation: breathe 1.4s ease-in-out infinite;
}
.gap:hover { background: rgba(255, 77, 141, .45); }
.gap.wrong { animation: shake .4s; border-color: var(--red); }

.floater {
  position: fixed; pointer-events: none; font-size: 26px; font-weight: bold; color: var(--green);
  animation: floatUp .9s ease-out forwards; z-index: 50;
}

/* ---------- numpad ---------- */
.numpad {
  direction: ltr; display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px;
  margin-top: 14px; max-width: 520px; margin-inline: auto;
}
.numpad button {
  font-size: 30px; height: 62px; border: 0; border-radius: 16px;
  background: #fff; box-shadow: 0 5px 0 #f0c36b; color: var(--ink);
}
.numpad button:active { transform: translateY(3px); box-shadow: 0 2px 0 #f0c36b; }
.numpad .del { background: #ffe3e3; box-shadow: 0 5px 0 #f3a7a7; }

/* ---------- done overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(43, 45, 66, .55);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20;
}
.done-card {
  background: #fff; border-radius: 28px; padding: 24px; text-align: center;
  width: min(440px, 100%); animation: pop .4s;
}
.done-emoji { font-size: 70px; animation: jump 1s infinite; }
.done-card h2 { margin: 6px 0; font-size: 30px; }
.done-answer { font-size: 32px; margin: 8px 0; color: var(--blue); font-weight: bold; }
.done-stars { font-size: 46px; margin: 10px 0; letter-spacing: 6px; }
.done-stars .dim { filter: grayscale(1); opacity: .3; }
.done-buttons .big-btn { margin: 10px 0; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; width: 100%; height: 100%; }

@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes jump { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-16px) rotate(-8deg); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes glow { 0%, 100% { outline-color: var(--orange); } 50% { outline-color: #ffd166; } }
@keyframes breathe { 0%, 100% { transform: translate(-50%, 35%) scale(1); } 50% { transform: translate(-50%, 35%) scale(1.15); } }
@keyframes floatUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-60px); } }

@media (max-width: 520px) {
  .mascot { font-size: 44px; }
  .bubble { font-size: 17px; }
  .icon-btn { width: 44px; height: 44px; font-size: 22px; }
  .numpad button { height: 54px; font-size: 26px; }
}

/* ---------- personal + custom question ---------- */
.menu-head h1 small { display: block; font-size: 18px; color: #7a7d99; font-weight: normal; margin-top: 2px; }
.custom { border: 3px dashed var(--pink); }
.custom-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; }
.custom-nums { display: flex; align-items: center; gap: 8px; font-size: 30px; }
.custom-nums input {
  width: 130px; font-size: 28px; font-family: inherit; text-align: center; padding: 8px;
  border: 3px solid #ffd27a; border-radius: 14px; background: #fffdf3; color: var(--ink);
}
.custom-nums input:focus { outline: none; border-color: var(--pink); }
.go-btn {
  border: 0; border-radius: 14px; background: var(--pink); color: #fff; font-size: 24px;
  padding: 12px 22px; box-shadow: 0 5px 0 #c2185b;
}
.go-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #c2185b; }
.err { color: var(--red); text-align: center; min-height: 24px; margin-top: 8px; font-size: 18px; }
@media (max-width: 520px) { .custom-nums input { width: 100px; font-size: 24px; } }
