/* ==========================================================================
   mastery.css — the self-study mastery pages (mastery/*.html) and the shared
   pieces of the Year 7 Maths pilot page. Mobile-first from 320px: media
   queries only ever add (min-width). Colours come from tokens.css and the
   app-shared.css theme tokens (dark default, [data-theme="light"] daylight);
   nothing here introduces a raw colour except the subject accent tokens,
   re-declared per subject exactly as tokens.css's SUBJECT ACCENT TOKENS
   block asks each subject page to.
   ========================================================================== */

/* Subject accent tokens (tokens.css): Maths #d97706 -> #fbbf24. */
[data-subject="maths"] {
  --blue: #d97706;
  --blue-mid: #f59e0b;
  --cyan: #d97706;
  --cyan-bright: #fbbf24;
  --blue-rgb: 217,119,6;
  --blue-mid-rgb: 245,158,11;
  --cyan-bright-rgb: 251,191,36;
  --grad-physics: linear-gradient(135deg, #d97706, #fbbf24);
  --grad-physics-vivid: linear-gradient(135deg, #b45309 0%, #d97706 50%, #fbbf24 100%);
}

/* Aliases used below: accent fill, accent text (AA on each theme's canvas). */
body {
  --m-accent: var(--blue);
  --m-accent-2: var(--cyan-bright);
  --m-accent-rgb: var(--blue-rgb);
  --m-accent-text: var(--cyan-bright);
  --m-grad: var(--grad-physics);
  --m-surface: var(--navy2);
  --m-inset: var(--navy3);
  --m-good: var(--success);
  --m-work: var(--orange);
  --m-radius: var(--radius-sm);
  font-family: var(--font-body);
}
[data-theme="light"] body { --m-accent-text: var(--orange); }

/* ── Shell ──────────────────────────────────────────────────────────── */
.m-skip { position: absolute; left: -999px; top: 0; padding: .5rem 1rem; background: var(--gold); color: var(--navy); z-index: 300; }
.m-skip:focus { left: .5rem; top: .5rem; }
.m-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.m-toplink { font-size: .82rem; font-weight: 600; color: var(--muted); padding: .45rem .7rem; border-radius: var(--r); min-height: 44px; display: inline-flex; align-items: center; }
.m-toplink:hover, .m-toplink:focus-visible { color: var(--white); background: var(--navy3); }

.m-main { width: 100%; max-width: 760px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.m-main--narrow { max-width: 640px; }
.m-main--lesson { max-width: 720px; }
.m-main--wide { max-width: 1200px; }

.m-demo { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem 1rem; font-size: .82rem;
  background: rgba(var(--m-accent-rgb), .14); border-bottom: 1px solid rgba(var(--m-accent-rgb), .4); }
.m-demo span { flex: 1 1 100%; }
.m-offline, .m-pending { margin: 0; padding: .6rem 1rem; font-size: .85rem; background: var(--navy3); border-bottom: 1px solid var(--border); }
.m-pending { color: var(--muted); }
.m-demo[hidden], .m-offline[hidden], .m-pending[hidden], [hidden] { display: none !important; }

.m-toast { position: fixed; left: 1rem; right: 1rem; bottom: 1rem; z-index: 250; padding: .85rem 1rem; border-radius: var(--m-radius);
  background: var(--navy2); border: 1px solid var(--border); box-shadow: 0 8px 28px rgba(0,0,0,.25); font-size: .9rem; }

/* ── Type ───────────────────────────────────────────────────────────── */
.m-h1 { font-family: var(--font-display); font-weight: 700; font-size: 1.7rem; line-height: 1.2; margin: .15rem 0 .5rem; }
.m-h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; line-height: 1.25; margin: 0 0 .5rem; }
.m-h3 { font-size: 1rem; font-weight: 700; margin: 0 0 .35rem; }
.m-kicker { font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--m-accent-text); margin: 0; }
.m-small { font-size: .84rem; color: var(--muted); margin: .35rem 0; }
.m-link { color: var(--m-accent-text); text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.m-label { display: block; font-size: .85rem; font-weight: 600; margin: 0 0 .3rem; }
p { margin: 0 0 .6rem; }

/* ── Controls ───────────────────────────────────────────────────────── */
.m-btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 48px; padding: .7rem 1.2rem;
  border-radius: var(--m-radius); border: 1px solid var(--border); background: var(--m-surface); color: var(--white);
  font: 600 .95rem var(--font-body); cursor: pointer; text-align: center;
  transition: transform .25s var(--spring-out), border-color var(--transition), background var(--transition); }
.m-btn:hover { border-color: var(--m-accent); }
.m-btn:active { transform: scale(.97); }
.m-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.m-btn--primary { background: var(--m-grad); border-color: transparent; color: var(--ia-text); }
.m-btn--primary:hover { border-color: transparent; filter: brightness(1.05); }
.m-btn--wide { width: 100%; }
.m-btn--small { min-height: 36px; padding: .35rem .8rem; font-size: .8rem; }
.m-btn:focus-visible, .m-option:focus-visible, .m-input:focus-visible, .m-link:focus-visible, summary:focus-visible, .m-concept-link:focus-visible {
  outline: 3px solid var(--m-accent-2); outline-offset: 2px; }
.m-input { width: 100%; min-height: 48px; padding: .6rem .8rem; border-radius: var(--m-radius); border: 1px solid var(--border);
  background: var(--navy); color: var(--white); font: 400 1rem var(--font-body); }
textarea.m-input { min-height: 96px; resize: vertical; }
.m-check-label { display: flex; gap: .6rem; align-items: center; margin: .75rem 0; min-height: 44px; font-size: .9rem; }
.m-check-label input { width: 22px; height: 22px; accent-color: var(--m-accent); }

/* ── Panels and cards ───────────────────────────────────────────────── */
.m-panel { background: var(--m-surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.15rem;
  box-shadow: inset 0 1px 0 var(--card-3d-top, rgba(255,255,255,.05)), inset 0 -2px 0 var(--card-3d-bottom, rgba(0,0,0,.2)); margin: 0 0 1rem; }
.m-panel--quiet { background: transparent; }
.m-panel--staff { border-color: var(--gold); }
.m-panel > :last-child { margin-bottom: 0; }
.m-intro .m-btn { margin-top: .75rem; }
.m-hero { margin: .25rem 0 1.25rem; }
.m-parent-note { display: inline-flex; gap: .4rem; align-items: center; font-size: .82rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: .25rem .75rem; margin: .25rem 0 0; }
.m-ticks { list-style: none; padding: 0; margin: .5rem 0 .75rem; }
.m-ticks li { position: relative; padding-left: 1.6rem; margin: .4rem 0; }
.m-ticks li::before { content: '✓'; position: absolute; left: 0; color: var(--m-accent-text); font-weight: 700; }

.m-loading { display: flex; align-items: center; gap: .6rem; color: var(--muted); padding: 1rem 0; }
.m-spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--m-accent); animation: m-spin .8s linear infinite; }
@keyframes m-spin { to { transform: rotate(360deg); } }

/* The one next action */
.m-next { position: relative; background: var(--m-surface); border: 1px solid rgba(var(--m-accent-rgb), .45); border-radius: var(--radius);
  padding: 1.25rem; margin: 0 0 1rem; overflow: hidden; box-shadow: inset 0 1px 0 var(--card-3d-top, rgba(255,255,255,.05)); }
.m-next::before { content: ''; position: absolute; inset: 0 0 auto; height: 4px; background: var(--m-grad); }
.m-next-title { font-family: var(--font-display); font-weight: 700; font-size: 1.35rem; line-height: 1.25; margin: .35rem 0 .4rem; }
.m-next-why { color: var(--muted); margin-bottom: 1rem; }
.m-next-help { font-size: .85rem; color: var(--muted); margin: .85rem 0 0; }
.m-next--inline { margin-top: 1rem; }

/* Weekly stats: checks passed and mix-ups fixed, never volume */
.m-stats { display: grid; grid-template-columns: 1fr; gap: .6rem; margin: 0 0 1.5rem; }
.m-stat { display: grid; grid-template-columns: auto 1fr; column-gap: .75rem; align-items: baseline; background: var(--m-surface);
  border: 1px solid var(--border); border-radius: var(--m-radius); padding: .75rem 1rem; }
.m-stat-n { grid-row: span 2; font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; color: var(--m-accent-text); min-width: 2ch; }
.m-stat-label { font-weight: 600; }
.m-stat-sub { font-size: .8rem; color: var(--muted); }

.m-section { margin: 1.75rem 0; }
.m-chip { display: inline-block; font-size: .74rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.m-tier { font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.m-due { font-size: .72rem; font-weight: 700; color: var(--m-accent-text); white-space: nowrap; }

/* ── The calm level visual: four pips ────────────────────────────────── */
.m-level { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; font-size: .76rem; color: var(--muted); }
.m-pips { display: inline-flex; gap: 3px; }
.m-pip { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--border); }
.m-pip.is-on { background: var(--m-accent); border-color: var(--m-accent); }
.m-level--secure .m-pip.is-on { background: var(--m-good); border-color: var(--m-good); }
.m-level--secure .m-level-label { color: var(--white); font-weight: 600; }
.m-level--work .m-pip.is-on { background: transparent; border-color: var(--m-work); }
.m-level--refresh .m-pip.is-on { background: var(--gold); border-color: var(--gold); }

/* ── Unit map ──────────────────────────────────────────────────────── */
.m-units { display: grid; gap: .75rem; }
.m-unit { background: var(--m-surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 1rem; }
.m-unit.is-current { border-color: rgba(var(--m-accent-rgb), .55); }
.m-unit.is-locked { opacity: .8; }
.m-unit > summary { list-style: none; cursor: pointer; padding: .9rem 0; display: flex; flex-direction: column; gap: .15rem; min-height: 48px; }
.m-unit > summary::-webkit-details-marker { display: none; }
.m-unit-name { font-weight: 700; }
.m-unit-status { font-size: .8rem; color: var(--muted); }
.m-unit.is-locked .m-unit-name::before { content: '🔒 '; }
.m-unit-lock { font-size: .84rem; color: var(--muted); margin: 0 0 .5rem; }
.m-concepts { list-style: none; padding: 0; margin: 0 0 .75rem; }
.m-concept + .m-concept { border-top: 1px solid var(--border); }
.m-concept-link { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .75rem; padding: .7rem 0; min-height: 48px; }
.m-concept-link:not(.is-locked):hover .m-concept-name { color: var(--m-accent-text); }
.m-concept-name { flex: 1 1 100%; font-size: .92rem; }
.m-unit > .m-link { display: inline-block; margin: 0 0 1rem; }

/* ── Questions ─────────────────────────────────────────────────────── */
.m-run { margin-top: .5rem; }
.m-q-count { font-size: .8rem; font-weight: 700; color: var(--muted); letter-spacing: .04em; margin: 0 0 .5rem; }
.m-q-text { font-size: 1.12rem; line-height: 1.5; margin: 0 0 1rem; outline: none; overflow-wrap: anywhere; }
.m-q-diagram { margin: 0 0 1rem; max-width: 100%; overflow-x: auto; color: var(--white); }
.m-q-diagram .maths-diagram { display: block; width: 100%; max-width: 22rem; height: auto; margin: 0 auto; }
.m-q-diagram--text { padding: .65rem .85rem; border-radius: var(--m-radius); border: 1.5px dashed var(--border); font-size: .95rem; line-height: 1.5; }
.m-options { display: grid; gap: .55rem; margin-bottom: .55rem; }
.m-option { display: flex; align-items: center; gap: .75rem; width: 100%; min-height: 52px; padding: .65rem .85rem; text-align: left;
  border-radius: var(--m-radius); border: 1.5px solid var(--border); background: var(--m-surface); color: var(--white);
  font: 500 1rem var(--font-body); cursor: pointer; transition: border-color var(--transition), transform .25s var(--spring-out); }
.m-option:hover { border-color: rgba(var(--m-accent-rgb), .6); }
.m-option:active { transform: scale(.985); }
.m-option.is-chosen { border-color: var(--m-accent); background: rgba(var(--m-accent-rgb), .12); }
.m-option:disabled { cursor: default; }
.m-option-letter { flex: 0 0 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; background: var(--m-inset); }
.m-option.is-chosen .m-option-letter { background: var(--m-accent); color: var(--ia-text); }
.m-option-text { flex: 1; overflow-wrap: anywhere; }
.m-option--unsure { justify-content: center; font-size: .9rem; color: var(--muted); border-style: dashed; }
.m-q-numrow { display: flex; gap: .5rem; }
.m-q-unit { flex: 0 0 7rem; }
.m-q-actions { margin-top: 1rem; }
.m-q-actions .m-btn { width: 100%; }
.m-q-feedback { margin-top: .75rem; font-weight: 600; min-height: 1.4em; }
.m-q-feedback.is-right { color: var(--m-good); }
.m-q-feedback.is-wrong { color: var(--m-work); }
.m-q-feedback.is-saved { color: var(--muted); font-weight: 500; }
.m-timer { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); text-align: right; margin: 0; }

/* ── Results ───────────────────────────────────────────────────────── */
.m-result-title { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; margin: 0 0 .6rem; outline: none; }
.m-outcomes { list-style: none; padding: 0; margin: .5rem 0 1rem; display: grid; gap: .5rem; }
.m-outcome { display: flex; gap: .65rem; align-items: flex-start; padding: .65rem .8rem; border-radius: var(--m-radius); background: var(--m-inset); }
.m-outcome-mark { flex: 0 0 1.4rem; font-weight: 700; color: var(--m-accent-text); }
.m-outcome.is-good .m-outcome-mark { color: var(--m-good); }
.m-outcome-text { display: block; font-size: .88rem; color: var(--muted); }
.m-celebrate { border: 1px solid var(--gold); border-radius: var(--m-radius); padding: .75rem 1rem; margin: 0 0 1rem; }
.m-celebrate-title { font-weight: 700; color: var(--gold); margin-bottom: .25rem; }
.m-celebrate ul { margin: 0; padding-left: 1.1rem; }
.m-review { margin: 0 0 1rem; }
.m-review > summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; color: var(--m-accent-text); }
.m-review-list { padding-left: 1.2rem; margin: .5rem 0 0; }
.m-review-item { margin: 0 0 1rem; padding: .25rem 0 .75rem; border-bottom: 1px solid var(--border); }
.m-review-q { margin-bottom: .35rem; overflow-wrap: anywhere; }
.m-review-line { font-size: .9rem; margin: .2rem 0; }
.m-review-tag { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: .05rem .45rem;
  border-radius: 4px; margin-right: .35rem; background: var(--m-inset); }
.m-review-item.is-right .m-review-tag { color: var(--m-good); }
.m-review-item.is-wrong .m-review-tag { color: var(--m-work); }
.m-review-why { font-size: .9rem; color: var(--muted); border-left: 3px solid var(--m-accent); padding-left: .65rem; margin-top: .4rem; }
.m-review-mis { font-size: .85rem; color: var(--muted); }

/* Parent summary */
.m-child .m-h2 { margin-bottom: .75rem; }
.m-facts { display: grid; grid-template-columns: 1fr; gap: .1rem 1rem; margin: 0 0 .75rem; }
.m-facts dt { font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: .5rem; }
.m-facts dd { margin: 0; }

@media (min-width: 480px) {
  .m-stats { grid-template-columns: repeat(3, 1fr); }
  .m-stat { grid-template-columns: 1fr; }
  .m-stat-n { grid-row: auto; }
  .m-demo span { flex: 1 1 auto; }
  .m-concept-name { flex: 1 1 0; }
  .m-q-actions .m-btn, .m-btn--wide { width: auto; min-width: 220px; }
  .m-toast { left: auto; right: 1.5rem; bottom: 1.5rem; max-width: 380px; }
}
@media (min-width: 768px) {
  .m-main { padding: 2rem 1.5rem 5rem; }
  .m-h1 { font-size: 2.1rem; }
  .m-unit > summary { flex-direction: row; justify-content: space-between; align-items: center; }
  .m-facts { grid-template-columns: 11rem 1fr; }
  .m-facts dt { margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .m-btn, .m-option { transition: none; }
  .m-spinner { animation-duration: 2s; }
}

/* "Ask a parent or carer" box on the course home (mastery-ui-home.js askParent). */
.m-ask-parent { margin-top: 1rem; }
.m-ask-parent .m-label { margin-top: .75rem; }
.m-ask-parent .m-btn { margin-top: 1rem; }
