:root {
  --paper: #fdf8f0;
  --surface: #fffdfa;
  --ink: #2f2a26;
  --muted: #857a6e;
  --line: #e6dccc;
  --primary: #3a7d6c;
  --primary-soft: #e3efea;
  --accent: #e0a03c;
  --correct: #2e7d51;
  --wrong: #c1543f;
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--wrong);
  margin: 0.75rem 0 0;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- login ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login .card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  text-align: center;
  max-width: 24rem;
  width: 100%;
}

.login-mark {
  font-size: 3rem;
  line-height: 1;
}

.login h1 {
  margin: 0.75rem 0 0.25rem;
  font-size: 1.9rem;
}

.login .muted {
  margin: 0 0 1.75rem;
}

#google-button {
  display: flex;
  justify-content: center;
}

/* ---------- shared chrome ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 0.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.topbar h1 {
  font-size: 1.4rem;
  margin: 0;
  color: var(--ink);
}

.topbar nav {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.linklike {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary);
}

.linklike:hover {
  text-decoration: underline;
}

.session-count {
  font-variant-numeric: tabular-nums;
}

/* ---------- drill ---------- */

.drill {
  min-height: 100dvh;
  max-width: 30rem;
  margin: 0 auto;
  padding: 0 1rem calc(1rem + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.problem {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.5rem;
  padding: 1rem 0;
}

.expression {
  display: flex;
  align-items: baseline;
  gap: 0.3em;
  font-size: clamp(2.6rem, 13vw, 4.2rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  /* Uniform line-height keeps the answer slot's underline level with the digits. */
  line-height: 1;
}

.expression .equals {
  color: var(--muted);
}

.entry {
  min-width: 1.6em;
  padding: 0 0.1em 0.12em;
  border-bottom: 7px solid var(--line);
  color: var(--primary);
  text-align: center;
}

.problem.correct .entry {
  border-color: var(--correct);
  color: var(--correct);
}

.problem.wrong .entry {
  border-color: var(--wrong);
  color: var(--wrong);
}

.problem.correct {
  animation: pulse 0.35s ease;
}

.problem.wrong {
  animation: shake 0.35s ease;
}

.feedback {
  margin: 0;
  min-height: 1.8rem;
  font-size: 1.15rem;
  font-weight: 600;
}

.feedback.correct {
  color: var(--correct);
}

.feedback.wrong {
  color: var(--wrong);
}

@keyframes pulse {
  50% {
    transform: scale(1.06);
  }
}

@keyframes shake {
  25% {
    transform: translateX(-9px);
  }
  75% {
    transform: translateX(9px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .problem.correct,
  .problem.wrong {
    animation: none;
  }
}

/* ---------- keypad ---------- */

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}

.keypad button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: var(--radius);
  padding: 0.85rem 0;
  font-size: 1.9rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.keypad button:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
}

.keypad button.primary {
  background: var(--primary);
  border-color: #2c6153;
  color: #fff;
}

.keypad button.secondary {
  background: var(--primary-soft);
  border-color: #cfe1da;
}

.keypad button[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

/* ---------- overview ---------- */

.overview {
  max-width: 46rem;
  margin: 0 auto;
  padding: 0 1rem 3rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
}

.chip {
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  color: var(--ink);
}

.group h2 {
  font-size: 1.1rem;
  margin: 1.75rem 0 0.6rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.6rem, 1fr));
  gap: 0.4rem;
}

.fact {
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0.5rem 0.25rem;
  text-align: center;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.fact small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

/* Speed bands double up as the legend chips. Never colour-only: the card always
   shows its time, and unseen cards say so. */
.fast {
  background: #ddf0e4;
}

.ok {
  background: #fbf0d6;
}

.slow {
  background: #f7ded7;
}

.unseen {
  background: #f1ece3;
}
