/* ============================================================================
   Colearner Education — redesigned UI stylesheet
   Drop-in replacement for the inline <style> block in webapp_router.py (_PAGE).
   Everything the mockups use is here. No other colours, radii or sizes exist.
   Brand references: Figma Brand Materials — Inter, Google Material Symbols,
   Ink Navy #163052, Teal #078C88, Warm Off-White #F8F7F3, White #FFFFFF.
   ========================================================================== */

/* ── 1. Tokens ───────────────────────────────────────────────────────────── */
:root {
  /* surfaces */
  --bg:            #F8F7F3;   /* Warm Off-White: page background */
  --rail:          #163052;   /* Ink Navy: navigation and image letterboxing */
  --brand-navy:    #163052;
  --card:          #FFFFFF;   /* White: cards and panels */
  --input:         #FFFFFF;
  --accent-tint:   #E7F5F1;   /* Soft Mint: quiet highlights */
  --row-hover:     #E8F5FC;   /* Light Blue: summaries and secondary actions */
  --map-bg:        #163052;
  --map-panel:     #163052;

  /* ink — all tinted warm, never pure black/grey */
  --ink:           #163052;   /* Ink Navy: headings and navigation */
  --body:          #163052;
  --muted:         #526884;
  --faint:         #526884;

  /* accent — one green, everywhere */
  --accent:        #078C88;   /* Teal: brand and large controls */
  --accent-press:  #078C88;
  --link:          #0000FF;   /* Electric Blue: links and callouts */
  --emphasis:      #008CFF;   /* Bright Blue: secondary emphasis */

  /* borders */
  --line:          rgba(22, 48, 82, 0.16);
  --line-soft:     rgba(22, 48, 82, 0.09);
  --line-rail:     rgba(22, 48, 82, 0.12);
  --line-strong:   rgba(22, 48, 82, 0.18);

  /* mastery — always paired with its word, never colour alone */
  --mastered:      #078C88;
  --getting:       #008CFF;
  --stuck:         #FF785C;
  --notyet:        #526884;
  --stuck-bg:      #FEF2E8;   /* Light Orange: warm highlights */

  /* type */
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "Inter", system-ui, -apple-system, sans-serif;

  /* radii */
  --r-button: 12px;
  --r-input: 12px;
  --r-row:   12px;
  --r-card:  16px;
  --r-frame: 16px;
  --r-modal: 16px;
  --r-pill:  999px;

  /* elevation */
  --shadow-card:    0 1px 3px rgba(22, 48, 82, 0.07);
  --shadow-hover:   0 2px 8px rgba(22, 48, 82, 0.12);
  --shadow-overlay: 0 10px 25px -5px rgba(22, 48, 82, 0.22), 0 8px 10px -6px rgba(22, 48, 82, 0.14);
  --focus-ring:     0 0 0 3px rgba(0, 140, 255, 0.22);

  /* motion */
  --dur-micro: 150ms;
  --dur-comp:  300ms;
  --ease:      cubic-bezier(0.4, 0, 0.2, 1);
}

/* spacing scale, for reference — use these numbers only:
   4 · 8 · 10 · 12 · 14 · 16 · 18 · 20 · 22 · 24 · 26 · 28 · 32 · 40 · 48 · 56 */

/* ── 2. Reset & base ─────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
h1 { font-weight: 700; }
h1 { font-size: 28px; }
h2 { font-size: 24px; }
h3 { font-size: 19px; }
h4 { font-size: 17px; }
p  { margin: 0; }
a  { color: var(--link); text-decoration: none; }
a:hover { color: var(--emphasis); text-decoration: underline; }
::selection { background: var(--accent-tint); }
.material-symbols-outlined {
  display: inline-block; font-family: "Material Symbols Outlined"; font-style: normal; font-weight: 400;
  line-height: 1; white-space: nowrap; direction: ltr; letter-spacing: normal; text-transform: none;
  -webkit-font-feature-settings: "liga"; -webkit-font-smoothing: antialiased;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
}

/* Labels, supporting text, and metadata all use the Figma Inter type system. */
.label {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}
.label--tight { font-size: 11px; letter-spacing: 0.02em; }
.meta  { font-family: var(--sans); font-size: 12px; color: var(--faint); }
.hint  { font-size: 13px; color: var(--muted); line-height: 1.55; }
.body  { font-size: 15px; color: var(--body); line-height: 1.6; }

/* ── 3. App shell ────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }

.rail {
  --rail-ink: #FFFFFF;
  --rail-muted: #E8F5FC;
  --rail-hover: rgba(255, 255, 255, 0.08);
  --rail-active: rgba(255, 255, 255, 0.12);
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  background: var(--brand-navy);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  padding: 22px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.rail__brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; color: var(--rail-ink); font-size: 16px; font-weight: 500; }
.rail__brand img { width: 32px; height: 32px; display: block; flex: 0 0 auto; object-fit: contain; }
.rail__brand .rail__brand-wordmark { width: 100px; height: auto; filter: brightness(0) invert(1); }
.rail__brand--auth img { width: 40px; height: 40px; }
.rail__brand--auth .rail__brand-wordmark { width: 140px; height: auto; filter: none; }
.rail__brand--sidebar { gap: 12px; }
.rail__brand--sidebar img { width: 44px; height: 44px; }
.rail__brand--sidebar img:first-child { width: 40px; height: 44px; }
.rail__brand--sidebar .rail__brand-wordmark { width: 138px; height: auto; filter: none; }
.rail__tag {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-tint); border-radius: 4px; padding: 3px 5px;
}
.rail__group { display: grid; gap: 6px; }
.rail__head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 8px; }
.rail__section { border-top: 1px solid rgba(255, 255, 255, 0.12); padding-top: 18px; }
.rail__foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, 0.12); padding: 16px 0 0; }

.navitem {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--r-input);
  color: var(--rail-muted); font-size: 14px; font-weight: 500;
  background: none; border: none; font-family: inherit; text-align: left; width: 100%;
  cursor: pointer; transition: background var(--dur-micro) var(--ease);
}
.navitem:hover { background: var(--rail-hover); color: var(--rail-ink); text-decoration: none; }
.navitem.on { background: var(--rail-active); color: var(--rail-ink); font-weight: 500; }
.navitem .material-symbols-outlined { font-size: 20px; flex: none; }
.navitem .dot { margin-left: auto; width: 7px; height: 7px; border-radius: 50%; }

.childchip { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: var(--r-row); color: var(--rail-ink); }
.childchip:hover { background: var(--rail-hover); text-decoration: none; }
.avatar {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-tint); color: var(--accent);
  font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: center;
}

/* content pane */
.pane__top {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 32px; border-bottom: 1px solid var(--line-rail);
  background: rgba(255, 255, 255, 0.84);
  position: sticky; top: 0; z-index: 5;
  backdrop-filter: blur(8px);
}
.pane__body { padding: 32px; display: grid; gap: 28px; max-width: 940px; }
/* Give the map the full content width, including room for external topic details. */
.pane__body:has(#learningMap) { max-width: none; min-width: 0; }

/* ── 4. Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--card); border: none;
  border-radius: var(--r-button); padding: 11px 20px;
  font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background var(--dur-micro) var(--ease);
}
.btn:hover  { background: var(--accent-press); }
.btn:active { background: var(--accent-press); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn .material-symbols-outlined { font-size: 19px; line-height: 1; }

.btn--secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn--secondary:hover { background: var(--row-hover); }
.btn--ghost { background: transparent; color: var(--accent); font-weight: 500; padding: 11px 14px; }
.btn--ghost:hover { background: var(--accent-tint); }
.btn--quiet { background: transparent; color: var(--muted); font-weight: 500; padding: 11px 14px; }
.btn--quiet:hover { background: var(--row-hover); color: var(--ink); }
.btn--danger { background: var(--card); color: var(--stuck); border: 1px solid var(--line); }
.btn--danger:hover { background: var(--stuck-bg); border-color: var(--stuck); }
.btn--sm  { padding: 7px 13px; font-size: 12px; }
.btn--lg  { padding: 13px 22px; font-size: 15px; }
.btn--block { width: 100%; }
.btn--icon { width: 32px; height: 32px; padding: 0; }   /* needs aria-label */
.rail .meta { color: var(--rail-muted); }
.rail__grade.on { background: var(--rail-active); }

/* ── 5. Forms ────────────────────────────────────────────────────────────── */
.field { display: block; }
.field > .label { display: block; margin-bottom: 7px; }
.field .label .opt { text-transform: none; letter-spacing: 0; color: var(--faint); }
input[type="text"], input[type="email"], input[type="password"], input:not([type]), select, textarea {
  width: 100%; background: var(--input); border: 1px solid var(--line);
  border-radius: var(--r-input); padding: 11px 13px;
  font-family: inherit; font-size: 15px; color: var(--ink);
  transition: border-color var(--dur-micro) var(--ease), box-shadow var(--dur-micro) var(--ease);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--focus-ring);
}
input::placeholder { color: var(--faint); }
.setrow select {
  appearance: none; -webkit-appearance: none;
  padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23163052' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 16px;
}
/* Keep the upload subject chevron comfortably inset from the field edge. */
.upload-page__subject { position: relative; }
.upload-page__subject select { appearance: none; -webkit-appearance: none; padding-right: 44px; }
.upload-page__subject::after {
  content: "expand_more"; position: absolute; right: 14px; bottom: 9px;
  font-family: "Material Symbols Outlined"; font-size: 22px; line-height: 1;
  color: var(--ink); pointer-events: none;
}
/* roomier input — the custom-topic entry is the hero of its row */
.input--lg { padding: 14px 16px; font-size: 16px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

/* checkbox row (onboarding starter subjects) */
.check { display: flex; gap: 11px; align-items: flex-start; background: var(--input);
  border: 1px solid var(--line); border-radius: var(--r-row); padding: 13px 14px; cursor: pointer; }
.check:hover { border-color: var(--accent); }
.check:has(input:checked) { border-color: var(--accent); }

/* ── 6. Cards, rows, tables ──────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-card); padding: 24px; box-shadow: var(--shadow-card);
}
.card--tint { background: var(--accent-tint); border-color: rgba(7, 140, 136, 0.22); box-shadow: none; }
.card--inset { background: var(--accent-tint); border-color: rgba(7, 140, 136, 0.22); box-shadow: none; }
.card--flush { padding: 0; overflow: hidden; }   /* wrapper for row lists / tables */

/* subject card (home) */
.subject {
  display: grid; grid-template-columns: 44px 1fr 200px 20px; gap: 18px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: 20px 22px; color: var(--ink); box-shadow: var(--shadow-card);
  transition: border-color var(--dur-micro) var(--ease), box-shadow var(--dur-micro) var(--ease);
}
.subject:hover { border-color: var(--accent); box-shadow: var(--shadow-hover); text-decoration: none; }
.subject__icon {
  width: 44px; height: 44px; border-radius: var(--r-row);
  background: var(--accent-tint); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.subject__name { font-size: 17px; font-weight: 600; }
.subject__desc { font-size: 14px; color: var(--muted); line-height: 1.5; margin-top: 3px; }
.subject__meta { font-family: var(--mono); font-size: 11px; color: var(--faint); margin-top: 8px; }

/* mastery bar */
.bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: var(--row-hover); }
.bar span { display: block; height: 100%; }
.bar .is-mastered { background: var(--mastered); }
.bar .is-getting  { background: var(--getting); }
.bar .is-stuck    { background: var(--stuck); }

/* curriculum / worksheet / attention rows — one bordered block, hairline between rows */
.rows { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 1fr 128px 18px; gap: 16px; align-items: center;
  padding: 15px 20px; border-bottom: 1px solid var(--line-soft); color: var(--ink);
  transition: background var(--dur-micro) var(--ease);
}
.row:last-child { border-bottom: none; }
.row:hover { background: var(--row-hover); text-decoration: none; }
.row.is-next { background: var(--stuck-bg); }
.row__name { font-size: 15px; font-weight: 600; }
.row__desc { font-size: 13px; color: var(--muted); margin-top: 2px; }
.row--ws   { grid-template-columns: 1fr 150px 300px; }
.rows__head {
  display: grid; grid-template-columns: 1fr 150px 300px; gap: 16px;
  padding: 11px 20px; background: var(--row-hover); border-bottom: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
}
.rowacts { display: flex; gap: 6px; justify-content: flex-end; }

/* topic accordion */
.row--topic { cursor: pointer; }
.row.is-open { border-bottom: none; background: var(--row-hover); }
.row__expand { padding: 2px 20px 18px; border-bottom: 1px solid var(--line-soft); background: var(--row-hover); }
.row__expand:last-child { border-bottom: none; }
.chev { display: flex; transition: transform var(--dur-micro) var(--ease); }
.chev--open { transform: rotate(90deg); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 0 0 10px; }
.legend .status { font-size: 12px; color: var(--muted); }
.generr { font-size: 13px; }
.err { color: var(--stuck); }

/* status = dot + word, always both */
.status { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--body); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot--mastered { background: var(--mastered); }
.dot--getting  { background: var(--getting); }
.dot--stuck    { background: var(--stuck); }
.dot--notyet   { background: var(--notyet); }

/* pills / badges */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  color: var(--muted); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 4px 10px;
}
.pill--next { color: var(--stuck); border-color: rgba(255, 120, 92, 0.5); }
.chip {
  background: var(--card); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--r-pill); padding: 8px 15px; font-family: inherit; font-size: 13px;
  font-weight: 500; cursor: pointer; transition: background var(--dur-micro) var(--ease);
}
.chip--selected, .chip--selected:hover { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.chip:hover { background: var(--accent-tint); border-color: var(--accent); }
.chip--selected:hover { background: var(--accent-press); }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 20px; }
.stat__n { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin-top: 8px; }
.pane__top:has(.home-page-head) { align-items: center; justify-content: space-between; flex-wrap: wrap; padding-top: 22px; padding-bottom: 22px; }
.home-page-head { display: grid; flex: 1 1 300px; min-width: 0; gap: 3px; }
.home-page-actions { display: flex; align-items: center; flex: 0 0 auto; gap: 8px; }
.home-page-actions > * { white-space: nowrap; }
.home-greeting { color: var(--accent); font-size: 14px; font-weight: 500; }
.home-page-head h1 { font-size: 28px; line-height: 1.25; }
.home-page-head > p:last-child { color: var(--muted); font-size: 14px; line-height: 1.5; }
.home-start { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 28px 30px; }
.home-start__copy { display: grid; gap: 8px; max-width: 560px; }
.home-start__copy h2 { font-size: 22px; }
.home-start .btn { flex: none; }
.home-how { display: grid; gap: 18px; }
.home-section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.home-section-head h2 { margin-top: 5px; font-size: 19px; }
.home-how__steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.home-how__step { display: flex; align-items: flex-start; gap: 12px; }
.home-how__step .step__n { flex: none; }
.home-how__step b { display: block; margin: 2px 0 5px; font-size: 14px; }
.home-subjects { display: grid; gap: 16px; }

/* Upload worksheet */
.pane__top:has(.upload-page-head) { align-items: center; padding-top: 22px; padding-bottom: 22px; }
.upload-page-head { display: grid; min-width: 0; gap: 3px; }
.upload-page-head h1 { font-size: 28px; line-height: 1.25; }
.upload-page-head > p { color: var(--muted); font-size: 14px; line-height: 1.5; }
.upload-page { display: grid; gap: 18px; }
.upload-page__subject { max-width: 340px; }
.upload-workspace { display: grid; grid-template-columns: minmax(250px, 0.9fr) minmax(300px, 1.1fr); align-items: stretch; gap: 18px; }
.upload-card, .upload-preview { min-width: 0; min-height: 270px; }
.upload-card { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; }
.upload-card h2, .upload-preview h2 { font-size: 17px; line-height: 1.4; }
.upload-card__icon, .upload-preview__icon {
  display: inline-flex; width: 48px; height: 48px; flex: none; align-items: center; justify-content: center;
  border-radius: 12px; background: var(--accent-tint); color: var(--accent);
}
.upload-card__choose { min-width: 148px; margin-top: 4px; cursor: pointer; }
.upload-card__choose:hover { text-decoration: none; }
.upload-card__formats { margin-top: 2px; }
.upload-card__input {
  position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.upload-card:focus-within { box-shadow: var(--focus-ring); }
.upload-preview { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 26px; }
.upload-preview__selected { display: flex; max-width: 100%; flex-direction: column; align-items: center; gap: 12px; overflow-wrap: anywhere; }
.upload-preview__image { display: block; width: 100%; max-width: 270px; max-height: 138px; object-fit: contain; border-radius: var(--r-input); background: var(--input); }
.upload-preview__message { margin-top: 3px; }
.upload-spinner { width: 20px; height: 20px; border: 2px solid rgba(7, 140, 136, 0.2); border-top-color: var(--accent); border-radius: 50%; animation: mm-spin 800ms linear infinite; }
.upload-diagnosis { min-width: 0; }
.upload-diagnosis:empty { display: none; }
.upload-diagnosis__loading { padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-row); }

/* segmented toggle (Map | List) */
.segment { display: flex; background: var(--row-hover); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 3px; }
.segment button {
  background: transparent; border: none; color: var(--muted); border-radius: var(--r-pill);
  padding: 7px 16px; font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.segment button.on { background: var(--card); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(22, 48, 82, 0.08); }
.progress-tabs { justify-self: start; width: max-content; max-width: 100%; }
.progress-tabs button { min-width: 82px; }
.progress-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pane__top:has(.progress-page-head) { align-items: flex-start; padding-top: 22px; padding-bottom: 18px; }
.progress-page-head { display: grid; gap: 2px; }
.progress-page-head h1 { font-size: 28px; line-height: 1.25; }
.progress-page-head p { color: var(--muted); font-size: 15px; line-height: 1.5; }
.progress-empty {
  display: grid; justify-items: center; gap: 12px; width: min(100%, 390px); min-height: 250px;
  margin: 12px auto 0; padding: 28px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-card);
}
.progress-empty__icon {
  display: flex; align-items: center; justify-content: center; width: 52px; height: 52px;
  border-radius: 50%; background: var(--accent-tint); color: var(--accent);
}
.progress-empty h2 { font-size: 18px; }
.progress-empty .body { margin-top: -7px; }
.progress-empty .btn { margin-top: 4px; }
/* compact segment — matches .btn--sm height (30px) in the topic gen row */
.segment--sm { padding: 2px; }
.segment--sm button { padding: 4px 12px; font-size: 12px; line-height: 16px; }
.history-list { display: grid; gap: 12px; }
.history-item { display: flex; width: 100%; flex-direction: column; gap: 8px; text-align: left; color: var(--ink); cursor: pointer; }
.history-item:hover { border-color: var(--accent); }
.history-item__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.history-item__subject { font-size: 13px; font-weight: 600; color: var(--accent); }
.history-item__weakness { font-size: 17px; font-weight: 600; }
.history-item__open { display: inline-flex; align-items: center; gap: 5px; margin-top: 4px; font-size: 12px; font-weight: 500; color: var(--link); }

/* ── 7. Grade a photo ────────────────────────────────────────────────────── */
.drop {
  border: 1.5px dashed rgba(22, 48, 82, 0.3); border-radius: var(--r-card); background: var(--bg);
  padding: 40px 28px; display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center;
  transition: border-color var(--dur-micro) var(--ease), background var(--dur-micro) var(--ease);
}
.drop.is-over { border-color: var(--accent); background: var(--accent-tint); }
.drop__icon {
  width: 46px; height: 46px; border-radius: var(--r-card);
  background: var(--accent-tint); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.score {
  flex: none; width: 78px; height: 78px; border-radius: 50%; border: 3px solid var(--getting);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.score.is-good { border-color: var(--mastered); }
.score.is-bad  { border-color: var(--stuck); }
.score b { font-size: 22px; font-weight: 700; line-height: 1; }
.grade-result {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(260px, 0.95fr);
  align-items: start; gap: 16px;
}
.grade-result__assessment, .grade-result__photo { min-width: 0; }
.grade-assessment { display: grid; gap: 14px; margin-top: 12px; }
.grade-assessment .body { white-space: pre-line; overflow-wrap: anywhere; }
.grade-assessment__section { display: grid; gap: 12px; min-width: 0; }
.grade-assessment__section > h4 { margin: 0; font-size: 16px; color: var(--ink); }
.grade-assessment__section .body { margin: 0; }
.grade-assessment__steps { padding-left: 24px; }
.grade-assessment__steps li + li { margin-top: 8px; }
.grade-assessment__question {
  padding: 14px; border: 1px solid var(--line-soft); border-radius: var(--r-input); background: var(--card);
}
.grade-assessment__question h5 { margin: 0 0 7px; font-size: 14px; font-weight: 700; color: var(--ink); }
.grade-photo__open {
  display: block; width: 100%; overflow: hidden; padding: 0; border: 1px solid var(--line);
  border-radius: var(--r-input); background: var(--rail); line-height: 0; text-align: left; cursor: zoom-in;
}
.grade-photo__open:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.grade-photo__open[aria-disabled="true"] { cursor: default; }
.grade-photo__image {
  display: block; width: 100%; max-height: min(72vh, 760px);
  object-fit: contain; margin: 0 auto;
}
.grade-photo__fallback {
  min-height: 160px; padding: 20px; display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--line); border-radius: var(--r-input); color: var(--muted); text-align: center;
}
.grade-photo__open .grade-photo__fallback { border-color: rgba(232, 245, 252, 0.35); color: #E8F5FC; }
.grade-photo__hint { margin-top: 9px; }
.grade-photo__ocr-toggle { margin-top: 12px; }
.grade-photo__ocr-empty { margin-top: 12px; }
.grade-photo-viewer__panel--comparison { width: min(100%, 1360px); overflow: hidden; }
.grade-photo-viewer__comparison {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px;
  min-height: 0; flex: 1;
}
.grade-photo-viewer__comparison-pane { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; }
.grade-photo-viewer__photo-frame {
  display: flex; align-items: center; justify-content: center; height: min(72vh, 900px); min-height: 0;
  overflow: hidden; border: 1px solid var(--line); border-radius: var(--r-input); background: var(--rail);
}
.grade-photo-viewer__comparison-image { display: block; width: 100%; height: 100%; object-fit: contain; }
.grade-photo-viewer__photo-fallback {
  min-height: 160px; width: 100%; margin: 0; padding: 20px; display: flex; align-items: center;
  justify-content: center; color: #E8F5FC; text-align: center;
}
.grade-photo-viewer__text {
  width: 100%; min-height: 0; max-height: min(72vh, 900px); flex: 1; margin: 0; padding: 16px; overflow: auto; white-space: pre-wrap;
  overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: var(--r-input);
  background: var(--row-hover); color: var(--ink); font: 13px/1.6 var(--sans);
}
.grade-photo-viewer {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(22, 48, 82, 0.88);
}
.grade-photo-viewer__panel {
  display: flex; flex-direction: column; gap: 14px; width: min(100%, 1200px); max-height: 100%;
  padding: 18px; overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-modal);
}
.grade-photo-viewer__head { display: flex; align-items: center; justify-content: space-between; }
.grade-photo-viewer__close {
  width: 44px; height: 44px; border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--accent-tint); color: var(--ink); font: inherit; font-size: 26px; line-height: 1; cursor: pointer;
}
.grade-photo-viewer__close:hover { border-color: var(--accent); background: var(--accent-tint); }
.grade-photo-viewer__image {
  display: block; max-width: 100%; max-height: min(78vh, 1000px); width: auto; height: auto; margin: auto;
  object-fit: contain;
}

/* ── 8. Knowledge map ────────────────────────────────────────────────────── */
.progress-map-subjects { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.map {
  border-radius: var(--r-card); overflow: hidden; border: 1px solid var(--line);
  display: grid; grid-template-columns: 1fr 300px; background: var(--map-bg);
}
.map__canvas { position: relative; height: 520px; background: var(--map-bg); }
.map__legend { position: absolute; left: 16px; top: 16px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 6; }
.legpill {
  display: flex; align-items: center; gap: 7px;
  background: rgba(22, 48, 82, 0.78); backdrop-filter: blur(4px);
  border: 1px solid rgba(232, 245, 252, 0.28); color: #E8F5FC;
  border-radius: var(--r-pill); padding: 6px 13px; font-family: inherit; font-size: 12px; font-weight: 500; cursor: pointer;
}
.legpill:hover { background: rgba(232, 245, 252, 0.18); }
.legpill.on { background: var(--accent); border-color: var(--accent); color: #FFFFFF; font-weight: 500; }
.legpill i { width: 9px; height: 9px; border-radius: 50%; }
.legpill .c { font-family: var(--mono); opacity: 0.65; }
/* Whatever the map says instead of drawing (loading, WebGL off, load failure).
   z-index 7 so it covers the legend (6): both live in the top-left corner, and a
   message painted under the pills is a message nobody reads. */
.map__msg {
  position: absolute; inset: 0; z-index: 7; background: var(--map-bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; text-align: center; padding: 32px;
}
.map__msg h4 { color: #FFFFFF; font-size: 16px; }
.map__msg p { color: rgba(232, 245, 252, 0.78); font-size: 14px; line-height: 1.6; max-width: 46ch; }
.map__msg ol {
  color: rgba(232, 245, 252, 0.78); font-size: 14px; line-height: 1.7; text-align: left;
  max-width: 46ch; padding-left: 20px; display: flex; flex-direction: column; gap: 4px;
}
.map__msg ol b { color: #E7F5F1; font-weight: 600; }
.map__msg .map__msg-foot { color: rgba(232, 245, 252, 0.62); font-size: 12px; }
.map__hint { position: absolute; left: 16px; bottom: 14px; font-family: var(--sans); font-size: 12px; color: rgba(232, 245, 252, 0.72); z-index: 6; }
.map__zoom { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; z-index: 6; }
.map__zoom button {
  width: 36px; height: 36px; border-radius: var(--r-button); background: rgba(255, 255, 255, 0.92);
  border: none; color: var(--map-bg); font-family: inherit; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.map__zoom button:hover { background: #FFFFFF; }
.map__zoom .material-symbols-outlined { font-size: 20px; }
.map__panel {
  background: var(--map-panel); border-left: 1px solid rgba(232, 245, 252, 0.16);
  padding: 24px; display: flex; flex-direction: column; gap: 20px;
}
.map__panel h4 { color: #FFFFFF; font-size: 19px; }
.map__panel .label { color: rgba(232, 245, 252, 0.72); }
.map__panel p { color: rgba(232, 245, 252, 0.82); font-size: 14px; line-height: 1.6; }
.map__panel .sect { border-top: 1px solid rgba(232, 245, 252, 0.16); padding-top: 16px; }
.map__panel .btn { background: var(--accent); color: #FFFFFF; width: 100%; margin-top: auto; }
.map__panel .btn:hover { background: var(--accent-press); }

/* ── 9. Settings sections (flat, label column) ───────────────────────────── */
.setrow { display: grid; grid-template-columns: 220px 1fr; gap: 32px; padding: 30px 0; border-bottom: 1px solid var(--line-strong); }
.setrow:first-child { padding-top: 0; }
.setrow:last-child  { border-bottom: none; padding-bottom: 0; }
.setrow__title { font-size: 16px; font-weight: 600; }

/* ── 10. States ──────────────────────────────────────────────────────────── */
.empty { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 40px 28px; text-align: center; }
.empty__icon { display: inline-flex; width: 44px; height: 44px; border-radius: 11px; background: var(--accent-tint); color: var(--accent); align-items: center; justify-content: center; }

.skel { display: block; border-radius: 4px; background: var(--row-hover); }
.skel--line { height: 11px; background: var(--line-soft); }
/* build skeletons at the REAL row height so nothing shifts on arrival */

.alert {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--stuck-bg); border: 1px solid rgba(255, 120, 92, 0.45);
  border-radius: var(--r-row); padding: 14px 16px;
}
.alert__title { font-size: 14px; font-weight: 600; color: var(--ink); }
.alert .material-symbols-outlined { flex: none; margin-top: 1px; color: var(--stuck); }

.spinner { animation: mm-spin 1s linear infinite; }
@keyframes mm-spin { to { transform: rotate(360deg); } }
.progressbar { height: 4px; border-radius: 2px; background: var(--row-hover); overflow: hidden; }
.progressbar span { display: block; height: 100%; background: var(--accent); transition: width var(--dur-comp) var(--ease); }

/* ── 11. Overlay / modal ─────────────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(22, 48, 82, 0.5); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 32px; }
.modal { width: 100%; max-width: 470px; background: var(--card); border-radius: var(--r-modal);
  padding: 30px; box-shadow: var(--shadow-overlay); }
/* worksheet print preview — centered, tall, paper inside */
.modal--preview { max-width: 860px; height: min(88vh, 1100px); display: flex; flex-direction: column; padding: 22px; }
.previewframe { width: 100%; flex: 1; border: 1px solid var(--line); border-radius: var(--r-input); background: #FFFFFF; }
.step { display: flex; gap: 13px; align-items: flex-start; }
.step__n {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--row-hover); color: var(--ink);
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
}
.step--key .step__n { background: var(--accent-tint); color: var(--accent); }

/* ── 12. Auth ────────────────────────────────────────────────────────────── */
.boot-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 32px;
  background: var(--bg); color: var(--ink); text-align: center;
}
.boot-screen__content { display: grid; justify-items: center; gap: 14px; width: min(100%, 380px); }
.boot-screen__brand { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.boot-screen__brand img:first-child { width: 38px; height: 38px; object-fit: contain; }
.boot-screen__brand img:last-child { width: 142px; height: auto; }
.boot-screen__spinner {
  display: block; width: 26px; height: 26px; border: 3px solid rgba(7, 140, 136, 0.2);
  border-top-color: var(--accent); border-radius: 50%; animation: mm-spin 800ms linear infinite;
}
.boot-screen__title { color: var(--ink); font-size: 16px; font-weight: 600; }
.boot-screen__detail { color: var(--muted); font-size: 14px; line-height: 1.5; }
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth__form { display: flex; align-items: center; justify-content: center; padding: 48px; }
.auth__form > div { width: 100%; max-width: 380px; }
.auth__aside { background: var(--brand-navy); border-left: 1px solid rgba(255, 255, 255, 0.08); color: #FFFFFF; padding: 48px;
  display: flex; flex-direction: column; justify-content: center; gap: 22px; }
.auth__aside .label { color: #E8F5FC; }
.auth__aside .step h4 { color: #FFFFFF; }
.auth__aside .step .hint { color: #E8F5FC; }
.auth__aside .step__n { background: rgba(7, 140, 136, 0.2); color: #FFFFFF; }
.auth__aside .step--key .step__n { background: var(--accent-tint); color: var(--accent); }

/* ── 13. Print (worksheet + answer key) ──────────────────────────────────── */
.sheet { background: #FFFFFF; color: var(--ink); padding: 52px 56px; max-width: 720px; margin: 0 auto; font-family: var(--sans); }
.sheet__head { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--ink); padding-bottom: 12px; }
.sheet__title { font-size: 20px; font-weight: 600; }
.sheet__sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.sheet__q { font-size: 16px; line-height: 1.5; }
.sheet__q .n { font-family: var(--mono); font-weight: 600; margin-right: 10px; }
.sheet__rule { border-bottom: 1px solid var(--line); height: 30px; max-width: 300px; margin-top: 10px; }
.sheet__a { font-size: 14px; color: var(--accent); margin-top: 6px; padding-left: 30px; }
.sheet__foot { font-family: var(--sans); font-size: 12px; font-weight: 500;
  color: var(--muted); margin-top: 48px; border-top: 1px solid var(--line); padding-top: 12px; }
@media print {
  .sheet { padding: 24px 0; max-width: none; }
  .sheet__q { break-inside: avoid; }
}

/* ── 14. Operator console (slate, deliberately not cream) ────────────────── */
.admin { background: var(--bg); color: var(--ink); }
.admin .mono { font-family: var(--mono); }
.admin__top { display: flex; align-items: center; gap: 14px; padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.admin__tabs { display: flex; gap: 2px; flex-wrap: wrap; padding: 10px 20px 0; }
.admin__tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  border-radius: var(--r-button) var(--r-button) 0 0; padding: 8px 14px;
  font-family: var(--sans); font-size: 12px; font-weight: 500; cursor: pointer;
}
.admin__tab.on { background: var(--accent-tint); border-color: var(--line); border-bottom-color: var(--accent-tint); color: var(--ink); font-weight: 500; }
.admin__editor {
  background: var(--card); border: 1px solid var(--line); border-radius: 0 0 var(--r-input) var(--r-input); padding: 18px;
  font-family: var(--sans); font-size: 13px; line-height: 1.7; color: var(--ink); min-height: 300px; width: 100%;
}

/* ── 15. Responsive: rail becomes a bottom tab bar ───────────────────────── */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .rail {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 20;
    align-self: auto; height: auto; overflow: visible;
    flex-direction: row; gap: 0; padding: 8px 6px 14px;
    background: rgba(22, 48, 82, 0.97); backdrop-filter: blur(8px);
    border-right: none; border-top: 1px solid rgba(255, 255, 255, 0.12);
  }
  .rail__brand, .rail__head, .rail__foot, .rail__section { display: none; }
  .rail__group { grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
  .navitem { flex-direction: column; gap: 4px; min-height: 48px; font-size: 11px; justify-content: center; }
  .navitem.on { background: transparent; color: #FFFFFF; }
  .pane__body { padding: 18px; padding-bottom: 96px; gap: 18px; }
  .pane__top { padding: 16px 18px; }
  .pane__top:has(.upload-page-head) { padding: 16px 18px; }
  .upload-page-head h1 { font-size: 24px; }
  .subject { grid-template-columns: 38px 1fr 17px; }
  .subject > .bar, .subject__meta { display: none; }
  .row, .row--ws, .rows__head { grid-template-columns: 1fr auto; }
  .rows__head { display: none; }
  .rowacts { grid-column: 1 / -1; justify-content: flex-start; flex-wrap: wrap; }
  .map { grid-template-columns: 1fr; }
  .map__canvas { height: 380px; }
  .setrow, .auth { grid-template-columns: 1fr; }
  .auth__aside { display: none; }
  .stats { grid-template-columns: 1fr 1fr; }
  .pane__top:has(.home-page-head) { align-items: flex-start; flex-wrap: wrap; gap: 10px 12px; padding: 16px 18px; }
  .home-page-head { flex: 1 1 100%; }
  .home-page-actions { width: 100%; justify-content: space-between; }
  .home-start { align-items: flex-start; flex-direction: column; gap: 16px; padding: 22px; }
  .home-start .btn { width: 100%; }
  .home-how__steps { grid-template-columns: 1fr; gap: 16px; }
  .grade-result { grid-template-columns: 1fr; }
  .grade-photo-viewer__panel--comparison { overflow: auto; }
  .grade-photo-viewer__comparison {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(180px, 34vh) minmax(220px, 40vh);
    flex: 0 0 auto;
  }
  .grade-photo-viewer__photo-frame { height: 100%; }
  .grade-photo-viewer__comparison-image { max-height: 100%; }
  .grade-photo-viewer__text { max-height: none; flex: 1; }
  /* every tap target ≥ 44px on phone */
  .btn, input, select, .chip { min-height: 46px; }
  .btn--sm { min-height: 40px; }
  .segment--sm { min-height: 40px; }
}
@media (max-width: 600px) {
  .grade-photo-viewer { padding: 10px; }
  .grade-photo-viewer__panel { padding: 12px; gap: 10px; }
  .grade-photo-viewer__image { max-height: 80vh; }
  .upload-workspace { grid-template-columns: minmax(0, 1fr); }
  .upload-card, .upload-preview { min-height: 230px; }
  .upload-page__subject { max-width: none; }
}
