/* ---------- design tokens ---------- */
:root {
  --bg: #f4f6ff;
  --bg-grad-1: #eef1ff;
  --bg-grad-2: #fdf0ff;
  --surface: #ffffff;
  --surface-2: #f7f8ff;
  --ink: #1f2340;
  --ink-2: #5a5f80;
  --muted: #9aa0c0;
  --line: #e6e8f5;

  --brand: #5b5bef;      /* indigo — primary */
  --brand-dark: #3f3fd0;
  --accent: #12b3a6;     /* teal — secondary */
  --accent-warm: #ff8c42;/* orange — energy */
  --gold: #f5b400;

  --good: #17a673;       /* status: correct */
  --good-bg: #e5f8f0;
  --bad: #e5484d;        /* status: incorrect */
  --bad-bg: #fdeaea;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(46, 50, 120, 0.10);
  --shadow-lg: 0 20px 50px rgba(46, 50, 120, 0.18);
  --font: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--bg-grad-2), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, var(--bg-grad-1), transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
b { font-weight: 800; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 22px;
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.brand-logo { font-size: 28px; }
.brand-name { font-weight: 900; font-size: 22px; letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.topbar-stats { display: flex; align-items: center; gap: 10px; }
.chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 999px; font-weight: 700; font-size: 14px;
  box-shadow: 0 2px 6px rgba(46,50,120,0.05);
}
.chip-emoji { font-size: 16px; }
.chip-streak b { color: var(--accent-warm); }
.xp-meter { width: 90px; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.xp-meter-fill { height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--accent)); transition: width .6s cubic-bezier(.2,.8,.2,1); }

/* ---------- layout ---------- */
main { max-width: 860px; margin: 0 auto; padding: 26px 20px 80px; }
.view { animation: rise .4s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.card { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.card + .card { margin-top: 18px; }

h1 { font-size: 30px; font-weight: 900; letter-spacing: -0.6px; margin: 0 0 6px; }
h2 { font-size: 20px; font-weight: 800; margin: 0 0 12px; }
.subtle { color: var(--ink-2); }
.tiny { font-size: 13px; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  font-family: inherit; font-weight: 800; font-size: 16px; cursor: pointer;
  border: none; border-radius: 14px; padding: 13px 22px; color: #fff;
  background: linear-gradient(180deg, var(--brand), var(--brand-dark));
  box-shadow: 0 8px 20px rgba(91,91,239,0.35); transition: transform .12s ease, box-shadow .12s ease, filter .12s;
}
/* Links styled as buttons need these; <button> gets them for free. */
a.btn { display: inline-block; text-decoration: none; text-align: center; }
.btn:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(91,91,239,0.42); }
.btn:active { transform: translateY(0); filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-lg { font-size: 19px; padding: 17px 30px; border-radius: 16px; }
.btn-ghost { background: var(--surface-2); color: var(--ink); box-shadow: none; border: 1px solid var(--line); }
.btn-ghost:hover { box-shadow: 0 6px 16px rgba(46,50,120,0.08); }
.btn-accent { background: linear-gradient(180deg, var(--accent), #0e9488); box-shadow: 0 8px 20px rgba(18,179,166,.32); }
.btn-warm { background: linear-gradient(180deg, var(--accent-warm), #ef6f1e); box-shadow: 0 8px 20px rgba(255,140,66,.32); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- dashboard ---------- */
.hero { background: linear-gradient(135deg, #5b5bef, #7a5cf0 55%, #12b3a6);
  color: #fff; border: none; position: relative; overflow: hidden; }
.hero h1 { color: #fff; }
.hero .subtle { color: rgba(255,255,255,.9); }
.hero-mascot { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); font-size: 96px; opacity: .95; filter: drop-shadow(0 6px 12px rgba(0,0,0,.15)); }
.hero .btn { background: #fff; color: var(--brand-dark); box-shadow: 0 10px 24px rgba(0,0,0,.18); }
.hero .btn:hover { filter: brightness(1); }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 16px; box-shadow: 0 4px 12px rgba(46,50,120,0.05); }
.tile .tile-label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.tile .tile-value { font-size: 30px; font-weight: 900; line-height: 1.1; margin-top: 4px; letter-spacing: -1px; }
.tile .tile-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
@media (max-width: 640px) { .tiles { grid-template-columns: repeat(2, 1fr); } }

/* mastery bars — sequential single hue (magnitude) */
.mastery-row { display: grid; grid-template-columns: 150px 1fr 46px; align-items: center; gap: 12px; margin: 10px 0; }
.mastery-name { font-weight: 700; font-size: 14px; text-transform: capitalize; }
.mastery-track { height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; }
.mastery-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #a9b0ff, var(--brand)); transition: width .7s ease; }
.mastery-pct { font-weight: 800; font-size: 14px; text-align: right; color: var(--ink-2); }
@media (max-width: 640px) { .mastery-row { grid-template-columns: 96px 1fr 40px; } .mastery-name { font-size: 12px; } }

/* badges */
.badge-shelf { display: flex; flex-wrap: wrap; gap: 12px; }
.badge { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 84px; text-align: center; }
.badge-coin { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; font-size: 28px;
  background: radial-gradient(circle at 35% 30%, #fff6d6, #ffe08a); border: 2px solid var(--gold); box-shadow: 0 6px 14px rgba(245,180,0,.3); }
.badge.locked .badge-coin { background: var(--surface-2); border-color: var(--line); filter: grayscale(1); opacity: .5; }
.badge-name { font-size: 11px; font-weight: 800; color: var(--ink-2); line-height: 1.2; }

/* ---------- solve view ---------- */
.progress-dots { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.dot { width: 30px; height: 8px; border-radius: 999px; background: var(--line); transition: background .3s; }
.dot.done { background: var(--good); }
.dot.current { background: var(--brand); }
.dot.wrong { background: var(--bad); }

.pill { display: inline-block; font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); text-transform: capitalize; }
.pill-diff { background: #eef0ff; color: var(--brand-dark); border-color: #dfe2ff; }

.problem-prompt { font-size: 21px; line-height: 1.5; margin: 14px 0 22px; font-weight: 600; }

.choices { display: grid; gap: 10px; }
.choice { display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px;
  font-family: inherit; font-size: 17px; font-weight: 600; cursor: pointer; transition: all .12s; color: var(--ink); }
.choice:hover { border-color: #c9cdf5; transform: translateY(-1px); }
.choice .letter { width: 32px; height: 32px; flex: 0 0 32px; border-radius: 9px; background: var(--surface-2);
  display: grid; place-items: center; font-weight: 900; color: var(--brand-dark); }
.choice.selected { border-color: var(--brand); background: #f2f3ff; }
.choice.selected .letter { background: var(--brand); color: #fff; }
.choice.correct { border-color: var(--good); background: var(--good-bg); }
.choice.correct .letter { background: var(--good); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.choice.wrong .letter { background: var(--bad); color: #fff; }
.choice:disabled { cursor: default; }

.numeric-input { font-family: inherit; font-size: 22px; font-weight: 800; text-align: center;
  padding: 14px; width: 220px; border: 2px solid var(--line); border-radius: 14px; color: var(--ink); }
.numeric-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(91,91,239,.15); }

.hint-box { background: #fff9e9; border: 1px solid #ffe6a3; border-radius: 12px; padding: 12px 16px; margin-top: 12px;
  animation: rise .3s ease both; }
.hint-box .hint-label { font-weight: 800; color: #b8860b; font-size: 13px; }

.feedback { border-radius: 14px; padding: 16px 18px; margin-top: 16px; font-weight: 700; animation: rise .3s ease both; }
.feedback.good { background: var(--good-bg); border: 1px solid #b7ecd6; color: #0c7a54; }
.feedback.bad { background: var(--bad-bg); border: 1px solid #f6c5c6; color: #b3272c; }
.feedback-title { font-size: 18px; font-weight: 900; display: flex; align-items: center; gap: 8px; }

.solution { background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--brand);
  border-radius: 12px; padding: 16px 18px; margin-top: 14px; line-height: 1.6; animation: rise .3s ease both; }
.solution h3 { margin: 0 0 8px; font-size: 15px; color: var(--brand-dark); }
.review-answer { font-size: 17px; font-weight: 600; padding: 10px 2px; }

.reasoning-wrap { margin-top: 16px; }
.reasoning-wrap textarea { width: 100%; min-height: 70px; font-family: inherit; font-size: 15px; padding: 12px;
  border: 2px solid var(--line); border-radius: 12px; resize: vertical; color: var(--ink); }
.reasoning-wrap textarea:focus { outline: none; border-color: var(--brand); }

.mini-lesson { background: linear-gradient(135deg, #f0f4ff, #f7f0ff); border: 1px solid #e2e6ff; }
.mini-lesson ol { margin: 8px 0 0; padding-left: 20px; }
.mini-lesson li { margin: 6px 0; }

/* ---------- results view ---------- */
.result-hero { text-align: center; }
.result-score { font-size: 64px; font-weight: 900; letter-spacing: -2px;
  background: linear-gradient(90deg, var(--brand), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.earned-badges { display: flex; justify-content: center; gap: 18px; margin: 18px 0; flex-wrap: wrap; }
.pop { animation: pop .5s cubic-bezier(.2,1.4,.4,1) both; }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(31,35,64,.5); backdrop-filter: blur(4px);
  display: grid; place-items: center; z-index: 40; animation: rise .2s ease both; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 30px; max-width: 440px; width: 100%; text-align: center; }
.modal .numeric-input { width: 100%; text-align: left; font-size: 18px; margin: 14px 0; }

/* ---------- toast ---------- */
#toast-layer { position: fixed; top: 74px; left: 0; right: 0; display: flex; flex-direction: column;
  align-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: var(--ink); color: #fff; font-weight: 800; padding: 12px 20px; border-radius: 999px;
  box-shadow: var(--shadow-lg); animation: toastIn .3s ease both; }
.toast.xp { background: linear-gradient(90deg, var(--brand), var(--accent)); }
.toast.badge { background: linear-gradient(90deg, var(--gold), var(--accent-warm)); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }

#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 60; }

.center { text-align: center; }
.mt { margin-top: 16px; }

/* ---------- profile picker (main page) ---------- */
.chip-user { cursor: pointer; font-family: inherit; }
.chip-user:hover { border-color: var(--brand); }

.user-menu { position: fixed; z-index: 30; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-lg); padding: 8px; min-width: 190px; animation: rise .15s ease both; }
.user-menu-head { padding: 8px 10px; font-size: 14px; color: var(--ink-2); border-bottom: 1px solid var(--line);
  margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.user-menu-item { display: block; width: 100%; text-align: left; font-family: inherit; font-size: 15px; font-weight: 700;
  padding: 10px 12px; border: none; background: transparent; border-radius: 10px; cursor: pointer; color: var(--ink); }
.user-menu-item:hover { background: var(--surface-2); }
#um-logout { color: var(--bad); }

.landing { max-width: 720px; }
.landing-hero { text-align: center; padding: 26px 0 6px; }
.landing-logo { font-size: 68px; line-height: 1; filter: drop-shadow(0 8px 16px rgba(91,91,239,0.25)); animation: floaty 3.5s ease-in-out infinite; }
@keyframes floaty { 50% { transform: translateY(-8px); } }
.landing-title { font-size: 46px; font-weight: 900; letter-spacing: -1.5px; margin: 6px 0 2px;
  background: linear-gradient(90deg, var(--brand), var(--accent) 60%, var(--accent-warm));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.landing-tag { color: var(--ink-2); font-weight: 600; font-size: 16px; margin: 0; }

.picker { padding: 30px 24px; }
.picker-q { text-align: center; font-size: 24px; margin-bottom: 2px; }
.profile-grid { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; margin-top: 22px; }
.profile-card { position: relative; width: 140px; padding: 22px 12px 18px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: 6px; box-shadow: 0 4px 14px rgba(46,50,120,0.06);
  transition: transform .14s cubic-bezier(.2,.8,.2,1), border-color .14s, box-shadow .14s; }
.profile-card:hover { transform: translateY(-5px); border-color: var(--brand); box-shadow: var(--shadow-lg); }
.profile-avatar { font-size: 46px; line-height: 1; width: 84px; height: 84px; display: grid; place-items: center;
  border-radius: 50%; background: radial-gradient(circle at 35% 30%, #eef1ff, #e3e7ff);
  box-shadow: inset 0 0 0 3px #fff, 0 6px 14px rgba(91,91,239,.18); }
.profile-name { font-weight: 800; font-size: 18px; margin-top: 4px; }
.profile-meta { font-size: 12px; color: var(--muted); font-weight: 700; }
.profile-card.add { border-style: dashed; color: var(--ink-2); justify-content: center; box-shadow: none; }
.profile-card.add .profile-avatar { background: var(--surface-2); color: var(--brand); font-weight: 900; font-size: 40px; box-shadow: inset 0 0 0 3px #fff; }
.profile-lock { position: absolute; top: 10px; left: 10px; font-size: 14px; opacity: .8; }
.profile-del { position: absolute; top: 6px; right: 8px; font-size: 13px; font-weight: 900; color: var(--muted);
  opacity: 0; transition: opacity .12s; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; }
.profile-card:hover .profile-del { opacity: 1; }
.profile-del:hover { background: var(--bad-bg); color: var(--bad); }

.avatar-grid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.avatar-opt { font-size: 26px; width: 46px; height: 46px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--surface); cursor: pointer; transition: all .1s; }
.avatar-opt:hover { border-color: #c9cdf5; }
.avatar-opt.selected { border-color: var(--brand); background: #f2f3ff; transform: scale(1.05); }

/* ---------- PIN keypad ---------- */
.pin-modal { max-width: 320px; }
.pin-lock { font-size: 40px; }
.pin-modal h1 { font-size: 22px; margin: 6px 0 2px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 16px 0 6px; }
.pin-dot { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--line); background: transparent; transition: all .12s; }
.pin-dot.filled { background: var(--brand); border-color: var(--brand); transform: scale(1.1); }
.pin-error { color: var(--bad); font-size: 13px; font-weight: 700; min-height: 18px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 8px; }
.key { font-family: inherit; font-size: 24px; font-weight: 800; height: 62px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer; transition: all .1s; }
.key:hover { border-color: var(--brand); background: #f2f3ff; }
.key:active { transform: scale(.94); background: #e7e9ff; }
.shake { animation: shake .4s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-8px)} 40%,80%{transform:translateX(8px)} }
.empty-state { text-align: center; color: var(--ink-2); padding: 30px; }
.empty-state .big { font-size: 54px; }

/* ---------- parent dashboard ---------- */
.act-chart { display: flex; align-items: flex-end; gap: 6px; height: 130px; padding-top: 8px; overflow-x: auto; }
.act-col { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 26px; }
.act-bar { width: 20px; background: var(--line); border-radius: 5px; display: flex; flex-direction: column-reverse; overflow: hidden; }
.act-correct { width: 100%; background: var(--good); }
.act-label { font-size: 10px; color: var(--muted); white-space: nowrap; }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: middle; margin-right: 3px; }
.swatch-good { background: var(--good); }
.swatch-mut { background: var(--line); }

.reason-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-top: 10px; background: var(--surface-2); }
.reason-prompt { font-weight: 600; margin: 6px 0; }
.reason-said { font-size: 14px; color: var(--ink-2); margin-top: 4px; }

/* ---------- mock exam ---------- */
.mock-topbar { position: sticky; top: 66px; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 16px; box-shadow: var(--shadow); }
.mock-timer { font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: 1px; color: var(--ink); }
.mock-timer.urgent { color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.palette { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.pal { width: 40px; height: 40px; border-radius: 10px; border: 2px solid var(--line); background: var(--surface);
  font-family: inherit; font-weight: 800; font-size: 15px; cursor: pointer; color: var(--ink-2); position: relative; transition: all .1s; }
.pal:hover { border-color: #c9cdf5; }
.pal.answered { background: #eef2ff; border-color: #c7ccff; color: var(--brand-dark); }
.pal.current { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(91,91,239,.18); }
.pal.flagged::after { content: "🚩"; position: absolute; top: -8px; right: -6px; font-size: 12px; }

/* ---------- printable worksheet ---------- */
#print-region { display: none; }
@media print {
  body { background: #fff; }
  .no-print, .topbar { display: none !important; }
  #print-region { display: block; }
  .ws-page { page-break-after: always; padding: 8px; color: #000; }
  .ws-keypage { page-break-after: auto; }
  .ws-head { border-bottom: 2px solid #000; margin-bottom: 16px; padding-bottom: 8px; }
  .ws-head h1 { font-size: 20px; margin: 0 0 6px; }
  .ws-name { font-size: 13px; }
  .ws-problem { margin: 0 0 22px; break-inside: avoid; }
  .ws-q { font-size: 15px; line-height: 1.5; }
  .ws-choices { margin: 8px 0 0 18px; display: flex; flex-wrap: wrap; gap: 6px 24px; }
  .ws-choice { font-size: 14px; }
  .ws-work { margin: 10px 0 0 18px; font-size: 14px; }
  .ws-space { height: 70px; border-bottom: 1px dotted #bbb; margin-top: 8px; }
  .ws-key-item { font-size: 14px; margin: 8px 0; line-height: 1.5; break-inside: avoid; }
}

/* ---------- app top bar: back to QubitKid ---------- */
.topbar-left { display: flex; align-items: center; gap: 12px; }
.back-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink-2); text-decoration: none; font-weight: 900; font-size: 17px;
  transition: background 0.15s ease, color 0.15s ease;
}
.back-link:hover { background: var(--brand); color: #fff; border-color: transparent; }

/* =====================================================================
   MOBILE
   The app is used on phones as much as laptops, so everything below
   reflows rather than shrinking. Three steps: small laptop, tablet,
   phone — plus fixes for touch devices, which have no hover at all.
   ===================================================================== */

/* Nothing may push the page sideways. */
html, body { max-width: 100%; overflow-x: hidden; }

/* Long equations scroll inside their own box instead of stretching the page. */
.problem-prompt, .solution, .reason-prompt, .mini-lesson, .review-answer, .hint-box {
  overflow-x: auto;
  overflow-wrap: break-word;
}
.choice, .feedback, .card { overflow-wrap: break-word; }

/* Parent dashboard: the detailed mastery row (5 columns on a laptop). */
.mastery-row-detail { grid-template-columns: 150px 1fr 46px auto auto; }
.m-right { width: 70px; text-align: right; }
.m-hints { width: 90px; text-align: right; }
.hero-sub { max-width: 70%; }
.ws-pin-input { width: 120px; font-size: 14px; padding: 6px; text-align: left; }

/* ---------- small laptops / large tablets ---------- */
@media (max-width: 860px) {
  main { padding: 22px 16px 70px; }
  .hero-mascot { font-size: 72px; right: 10px; opacity: .5; }
  .hero-sub { max-width: 78%; }
}

/* ---------- tablets and big phones ---------- */
@media (max-width: 700px) {
  main { padding: 16px 13px 64px; }
  .card { padding: 17px 15px; }
  .card + .card { margin-top: 14px; }

  h1 { font-size: 25px; }
  h2 { font-size: 18px; }
  .problem-prompt { font-size: 19px; margin: 12px 0 18px; }

  /* Top bar: keep the brand, shrink the stats, never wrap. */
  .topbar { padding: 10px 13px; gap: 10px; }
  .brand-logo { font-size: 23px; }
  .brand-name { font-size: 18px; }
  .topbar-stats { gap: 6px; }
  .chip { padding: 6px 9px; font-size: 13px; gap: 6px; }
  .xp-meter { width: 54px; }
  .chip-user span:not(.chip-emoji) { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* The mascot competes with the greeting on a narrow screen. */
  .hero-mascot { font-size: 56px; right: 4px; opacity: .32; }
  .hero-sub { max-width: 100%; }

  .result-score { font-size: 52px; }
  .modal { padding: 22px 18px; }
  .landing-title { font-size: 36px; }
  .landing-logo { font-size: 54px; }

  /* Mock test: title, clock and submit stack rather than squeeze. */
  .mock-topbar { flex-wrap: wrap; justify-content: center; text-align: center; padding: 10px 12px; top: 60px; }
  .mock-timer { font-size: 22px; }

  /* Dashboard detail row drops the two right-hand stats onto their own line. */
  .mastery-row-detail {
    grid-template-columns: 1fr auto;
    grid-template-areas: "name pct" "track track" "right hints";
    gap: 4px 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
  }
  .mastery-row-detail .mastery-name { grid-area: name; }
  .mastery-row-detail .mastery-track { grid-area: track; }
  .mastery-row-detail .mastery-pct { grid-area: pct; }
  .mastery-row-detail .m-right { grid-area: right; width: auto; text-align: left; }
  .mastery-row-detail .m-hints { grid-area: hints; width: auto; }
}

/* ---------- phones ---------- */
@media (max-width: 460px) {
  body { font-size: 15.5px; }
  main { padding: 14px 11px 60px; }
  .card { padding: 15px 13px; border-radius: 14px; }

  h1 { font-size: 22px; }
  .problem-prompt { font-size: 18px; }

  /* Two tiles per row already; tighten them so nothing clips. */
  .tiles { gap: 10px; }
  .tile { padding: 12px 11px; }
  .tile .tile-value { font-size: 25px; }
  .tile .tile-sub { font-size: 11px; }

  /* Full-width buttons are far easier to hit with a thumb. */
  .btn { padding: 13px 18px; font-size: 15.5px; }
  .btn-lg { font-size: 17px; padding: 15px 20px; width: 100%; }
  .row > .btn, .row-between > .btn { flex: 1 1 auto; }

  .choice { padding: 12px 13px; font-size: 16px; gap: 11px; }
  .choice .letter { width: 28px; height: 28px; flex: 0 0 28px; }

  /* The answer box should fill the width on a phone, not sit at 220px. */
  .numeric-input { width: 100%; font-size: 20px; padding: 13px; }

  /* Profile cards: two per row, whatever the phone width. */
  .profile-grid { gap: 12px; }
  .profile-card { width: calc(50% - 6px); padding: 16px 8px 14px; }
  .profile-avatar { width: 66px; height: 66px; font-size: 36px; }
  .profile-name { font-size: 16px; }

  .badge { width: 68px; }
  .badge-coin { width: 48px; height: 48px; font-size: 23px; }
  .badge-name { font-size: 10px; }

  .dot { width: 22px; }
  .pal { width: 36px; height: 36px; font-size: 14px; }

  .landing-title { font-size: 30px; }
  .landing-tag { font-size: 14.5px; }
  .picker { padding: 20px 14px; }
  .picker-q { font-size: 20px; }

  .result-score { font-size: 44px; }
  .hero-mascot { display: none; }

  /* Keypad keys stay big — they're the main control on the PIN screen. */
  .key { height: 56px; font-size: 22px; }
  .keypad { gap: 10px; }
  .modal { padding: 20px 15px; }

  #toast-layer { top: 64px; }
  .toast { font-size: 14px; padding: 10px 16px; max-width: 92vw; }

  .ws-pin-input { width: 100%; }
}

/* ---------- touch devices ---------- */
/* Hover doesn't exist here, so anything hover-only is unreachable. The ✕ that
   removes a learner was invisible on a phone until this. */
@media (hover: none) {
  .profile-del { opacity: .55; width: 26px; height: 26px; font-size: 15px; }
  .profile-card:active { transform: scale(.98); }
  .btn:hover, .choice:hover, .profile-card:hover, .pal:hover, .key:hover {
    transform: none;
    box-shadow: inherit;
  }
}

/* Respect people who ask for less movement. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- parent dashboard: coach's notes & messages ---------- */
.next-focus {
  margin-top: 14px; padding: 14px 16px;
  background: linear-gradient(135deg, #f0f4ff, #eefbf8);
  border: 1px solid #dbe3ff; border-left: 4px solid var(--brand);
  border-radius: 0 12px 12px 0;
}
.next-focus-label {
  font-size: 11px; font-weight: 900; letter-spacing: .09em; text-transform: uppercase;
  color: var(--brand); margin-bottom: 6px;
}
.md { font-size: 15px; line-height: 1.6; color: var(--ink-2); }
.md h3, .md h4, .md h5 { font-size: 14px; font-weight: 900; color: var(--ink); margin: 14px 0 4px; }
.md p { margin: 6px 0; }
.md ul { margin: 6px 0; padding-left: 20px; }
.md li { margin: 3px 0; }
.md strong { color: var(--ink); }
.md code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 5px; font-size: .88em; }
.md > :first-child { margin-top: 0; }

.plan-more { margin-top: 14px; }
.plan-more summary {
  cursor: pointer; font-weight: 800; font-size: 14px; color: var(--brand);
  padding: 8px 0; list-style: none;
}
.plan-more summary::-webkit-details-marker { display: none; }
.plan-more summary::before { content: '▸ '; display: inline-block; transition: transform .15s ease; }
.plan-more[open] summary::before { content: '▾ '; }
.plan-more summary:hover { text-decoration: underline; }
.plan-more > .md { padding-top: 6px; border-top: 1px solid var(--line); }

.note-form textarea {
  width: 100%; font-family: inherit; font-size: 15px; padding: 12px 14px;
  border: 2px solid var(--line); border-radius: 12px; resize: vertical;
  color: var(--ink); background: var(--surface); min-height: 76px;
}
.note-form textarea:focus { outline: none; border-color: var(--brand); }

.note-history { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.note-history-head { font-weight: 800; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.note-item { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 13px; margin-bottom: 8px; }
.note-item-head { display: flex; align-items: center; gap: 9px; margin-bottom: 5px; }
.note-text { font-size: 14.5px; color: var(--ink); white-space: pre-wrap; overflow-wrap: break-word; }
.note-badge { font-size: 10.5px; font-weight: 800; padding: 2px 8px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .04em; }
.note-badge.new { background: #fff3d9; color: #a5741a; }
.note-badge.done { background: var(--good-bg); color: var(--good); }
.note-del { margin-left: auto; border: none; background: none; cursor: pointer;
  color: var(--muted); font-weight: 900; font-size: 13px; padding: 2px 5px; border-radius: 6px; }
.note-del:hover { background: var(--bad-bg); color: var(--bad); }
