:root {
  --bg: #eaf4ff;
  --bg-2: #d6e9ff;
  --ink: #1d2b3a;
  --muted: #6b7a8f;
  --primary: #4a90e2;
  --primary-dark: #2f6fb8;
  --good: #32c671;
  --good-soft: #c6f0d8;
  --bad: #f28b3b;
  --bad-soft: #ffd9bd;
  --key-bg: #ffffff;
  --key-ink: #1d2b3a;
  --key-shadow: #b9cde6;
  --go: #32c671;
  --go-dark: #1f9a55;
  --fn: #ffd56a;
  --fn-dark: #c99e2d;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Nunito", "Comic Sans MS", sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

#app {
  max-width: 540px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 24px 4px;
}
.screen.active { display: flex; }

/* ---------- Start ---------- */
#screen-start { justify-content: center; align-items: center; text-align: center; gap: 20px; }
#screen-start h1 { font-size: 3rem; margin: 0; letter-spacing: -0.02em; }
.tagline { font-size: 1.15rem; color: var(--muted); margin: 0 0 8px; }
.last-session {
  background: white;
  border-radius: 18px;
  padding: 14px 20px;
  box-shadow: 0 4px 0 var(--key-shadow);
  font-size: 1rem;
  color: var(--muted);
}
.last-session strong { color: var(--ink); }
.hidden { display: none !important; }

.big-btn {
  font: inherit;
  font-size: 1.6rem;
  font-weight: 800;
  padding: 20px 48px;
  border-radius: 22px;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--primary-dark);
  transition: transform 0.05s ease, box-shadow 0.05s ease;
}
.big-btn.primary { background: var(--primary); color: white; }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--primary-dark); }

.small-btn {
  font: inherit;
  font-size: 0.9rem;
  background: transparent;
  border: 2px solid var(--muted);
  color: var(--muted);
  padding: 8px 18px;
  border-radius: 14px;
  align-self: center;
  margin-top: 16px;
  cursor: pointer;
}

/* ---------- Play ---------- */
.stats-bar {
  display: flex;
  justify-content: space-between;
  background: white;
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: 0 4px 0 var(--key-shadow);
  margin-bottom: 20px;
  font-weight: 700;
}
.stat { display: flex; align-items: center; gap: 4px; font-size: 1rem; }
.stat-icon { font-size: 1.1rem; }
.stat-sep { color: var(--muted); margin: 0 2px; }

.equation {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2.5rem, 11vw, 4.2rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  gap: 0.4ch;
  text-align: center;
  padding: 10px;
  min-height: 180px;
}
.equation .slot {
  display: inline-block;
  min-width: 1.6ch;
  padding: 0 0.15ch;
  border-bottom: 6px solid var(--primary);
  border-radius: 6px;
  color: var(--primary-dark);
}
.equation .slot.filled { color: var(--ink); }
.equation .slot.active { animation: blink 1.1s infinite; }
@keyframes blink {
  0%, 60% { border-bottom-color: var(--primary); }
  61%, 100% { border-bottom-color: transparent; }
}

.feedback {
  min-height: 1.8rem;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--muted);
  transition: color 0.2s ease;
}
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.flash-good { animation: flashGood 0.5s ease; }
.flash-bad { animation: shake 0.45s ease; }
@keyframes flashGood {
  0% { background-color: transparent; }
  30% { background-color: var(--good-soft); }
  100% { background-color: transparent; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* ---------- Keypad ---------- */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 8px;
}
.key {
  font: inherit;
  font-size: 1.9rem;
  font-weight: 800;
  padding: 18px 0;
  min-height: 68px;
  background: var(--key-bg);
  color: var(--key-ink);
  border: none;
  border-radius: 18px;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--key-shadow);
  transition: transform 0.05s ease, box-shadow 0.05s ease;
  touch-action: manipulation;
}
.key:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--key-shadow); }
.key-fn { background: var(--fn); box-shadow: 0 5px 0 var(--fn-dark); }
.key-fn:active { box-shadow: 0 2px 0 var(--fn-dark); }
.key-go { background: var(--go); color: white; box-shadow: 0 5px 0 var(--go-dark); }
.key-go:active { box-shadow: 0 2px 0 var(--go-dark); }

/* ---------- End ---------- */
#screen-end { justify-content: center; align-items: center; text-align: center; gap: 20px; }
#end-headline { font-size: 2.4rem; margin: 0; }
.end-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 380px;
}
.end-stat {
  background: white;
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 4px 0 var(--key-shadow);
}
.end-stat-label { font-size: 0.85rem; color: var(--muted); font-weight: 700; }
.end-stat-value { font-size: 1.8rem; font-weight: 800; margin-top: 4px; }
.end-badge { font-size: 1.1rem; color: var(--muted); min-height: 1.4em; font-weight: 700; }

/* ---------- Confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.confetti-piece {
  position: absolute;
  width: 10px;
  height: 14px;
  top: -20px;
  border-radius: 2px;
  animation: fall 1.2s ease-out forwards;
}
@keyframes fall {
  to {
    transform: translateY(110vh) rotate(540deg);
    opacity: 0;
  }
}
