:root {
  --bg: #faf8f4;
  --card: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e7e3db;
  --accent: #2f6db3;
  --accent-soft: #dcebf8;
  --good: #2f8c4a;
  --warn: #d28a00;
  --bad: #c44545;

  /* mastery heatmap (new → mastered) */
  --lvl-new: #ebe7df;
  --lvl-struggling: #e6877c;
  --lvl-learning: #f1c876;
  --lvl-strong: #a8d99b;
  --lvl-mastered: #3a9c54;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: #fff;
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 18px; margin: 0; color: var(--accent); letter-spacing: 0.3px; }
.topbar nav { display: flex; gap: 4px; }
.tab {
  background: transparent; border: 1px solid transparent; padding: 6px 14px;
  border-radius: 8px; cursor: pointer; font: inherit; color: var(--muted);
}
.tab.active { color: var(--ink); background: var(--accent-soft); border-color: var(--accent); }

main { max-width: 880px; margin: 0 auto; padding: 20px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.screen { display: block; }
.screen.hidden { display: none !important; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.who-profile { color: var(--ink); font-weight: 500; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; }

button {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff;
  padding: 8px 16px; border-radius: 8px;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { filter: brightness(1.05); }
button.ghost { background: transparent; color: var(--muted); }
button:disabled { opacity: 0.5; cursor: default; }
button.big { padding: 12px 22px; font-size: 16px; }

/* ---------- auth ---------- */
.auth-card { max-width: 460px; margin: 60px auto; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.auth-tab {
  flex: 1; background: transparent; border: none; border-bottom: 2px solid transparent;
  padding: 10px 14px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; border-radius: 0;
}
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-card button.primary { width: 100%; padding: 12px; margin-top: 18px; }
label.block { display: block; margin: 14px 0 6px; font-size: 12px; color: var(--muted); }
label.block input {
  display: block; width: 100%; padding: 10px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 8px; margin-top: 4px;
}
.auth-status { margin-top: 16px; min-height: 1.5em; font-size: 13px; }

/* ---------- profiles ---------- */
.profiles-list { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.profile-row { display: flex; gap: 10px; align-items: center; }
.profile-pick {
  flex: 1; text-align: left; padding: 14px 18px; font-size: 18px;
  background: var(--accent-soft); border-color: var(--accent); color: var(--ink);
}
.profile-pick:hover { filter: brightness(0.98); }
.icon-btn { border: none; background: transparent; font-size: 16px; padding: 4px 8px; color: var(--muted); }
.icon-btn.danger:hover { color: var(--bad); }
.sep { border: none; }
hr.sep { border-top: 1px solid var(--line); margin: 24px 0 12px; }
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }

/* ---------- forms ---------- */
.form-row { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 12px; flex-wrap: wrap; }
.form-row label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.form-row input { font-size: 14px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.warn-msg { color: var(--bad); font-size: 13px; }

/* ---------- stats ---------- */
.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat-tile { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: #fefcf7; }
.stat-tile .tile-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 600; }
.stat-tile .tile-big { font-size: 26px; font-weight: 700; margin: 6px 0 2px; color: var(--accent); }
.stat-tile .tile-sub { font-size: 12px; }

.home-week { display: flex; gap: 8px; flex-wrap: wrap; }
.day-card {
  flex: 1; min-width: 54px; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 6px; text-align: center; background: #fff;
}
.day-card-dow { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.day-card-mark { font-size: 22px; font-weight: 700; line-height: 1.2; height: 26px; }
.day-card-num { font-size: 11px; color: var(--muted); min-height: 14px; }
.day-card.partial { background: #fefcf7; }
.day-card.partial .day-card-mark { color: var(--warn); }
.day-card.none .day-card-mark { color: var(--line); }
.day-card.today { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

/* ---------- goals ---------- */
.prog-bar { background: #f0ece4; border-radius: 6px; height: 10px; margin: 6px 0 4px; overflow: hidden; }
.prog-bar.wide { height: 12px; }
.prog-fill { height: 100%; background: var(--warn); border-radius: 6px; transition: width 0.3s; }
.prog-fill.met { background: var(--good); }
.goal-line { margin: 12px 0; }
.goal-line-head { display: flex; align-items: baseline; gap: 8px; }
.goal-line-head .goal-label { font-weight: 600; }
.goal-line-head .goal-mark { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--muted); }
.goal-line-head .goal-mark.met { color: var(--good); }
.story-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }

/* ======================= multiplication map ======================= */

.map-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.map-title { margin: 0; font-size: 18px; }
.map-sub { margin: 2px 0 0; font-size: 13px; }
.map-prog { min-width: 160px; flex: 1; max-width: 280px; }
.prog-pct { font-size: 12px; text-align: right; margin-top: 2px; }

.mult-grid {
  display: grid;
  gap: 3px;
  width: 100%;
  max-width: 560px;
  margin: 4px auto 0;
}
.mg-corner, .mg-head {
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--muted);
  aspect-ratio: 1 / 1; min-width: 0;
}
.mg-corner { color: var(--accent); }
.mg-cell {
  aspect-ratio: 1 / 1; min-width: 0; width: 100%; padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.06); border-radius: 5px;
  background: var(--lvl-new); cursor: pointer; transition: transform 0.08s, box-shadow 0.08s;
}
.mg-cell:hover { transform: scale(1.12); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18); z-index: 2; outline: 2px solid var(--accent); }
.mg-cell.lvl-new { background: var(--lvl-new); }
.mg-cell.lvl-struggling { background: var(--lvl-struggling); }
.mg-cell.lvl-learning { background: var(--lvl-learning); }
.mg-cell.lvl-strong { background: var(--lvl-strong); }
.mg-cell.lvl-mastered { background: var(--lvl-mastered); }
.mg-cell.pulse { animation: cellPulse 0.6s ease; }
@keyframes cellPulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.3); box-shadow: 0 0 0 3px var(--accent-soft); }
  100% { transform: scale(1); }
}

.map-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; justify-content: center; }
.lg-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.lg-swatch { width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.08); display: inline-block; }
.lg-swatch.lvl-new { background: var(--lvl-new); }
.lg-swatch.lvl-struggling { background: var(--lvl-struggling); }
.lg-swatch.lvl-learning { background: var(--lvl-learning); }
.lg-swatch.lvl-strong { background: var(--lvl-strong); }
.lg-swatch.lvl-mastered { background: var(--lvl-mastered); }

/* ---------- practice ---------- */
.play-card { display: flex; flex-direction: column; align-items: center; }
.play-start { text-align: center; }
.play-start p { max-width: 46ch; margin: 0 auto 14px; }
.play-start-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.sess-bar { display: flex; align-items: center; gap: 10px; font-size: 14px; width: 100%; max-width: 360px; margin-bottom: 12px; }
.sess-bar .sep { color: var(--line); }
.sess-bar .good { color: var(--good); }
.sess-bar .stop-btn { margin-left: auto; padding: 4px 12px; font-size: 13px; }

.prob {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  font-size: 46px; font-weight: 700; margin: 6px 0 4px; min-height: 64px;
}
.prob-x, .prob-eq { color: var(--muted); font-weight: 400; }
.prob-ans { min-width: 70px; text-align: left; color: var(--accent); border-bottom: 3px solid var(--accent-soft); }

.feedback { min-height: 24px; font-size: 16px; font-weight: 600; margin: 4px 0 12px; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.numpad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  width: 100%; max-width: 300px;
}
.np {
  aspect-ratio: 3 / 2; font-size: 24px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  display: flex; align-items: center; justify-content: center; min-height: 52px;
}
.np:hover { background: var(--accent-soft); border-color: var(--accent); }
.np:active { transform: translateY(1px); }
.np-del { color: var(--muted); }
.np-ok { background: var(--accent); color: #fff; border-color: var(--accent); }
.np-ok:hover { filter: brightness(1.05); background: var(--accent); }

@media (max-width: 600px) {
  main { padding: 14px; }
  .card { padding: 14px; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  #main-nav { order: 3; width: 100%; justify-content: center; }
  .stat-tiles { grid-template-columns: repeat(3, 1fr); }
  .mg-head, .mg-corner { font-size: 11px; }
  .prob { font-size: 38px; }
  .mult-grid { gap: 2px; }
}
