/* ---------------------------------------------------------------
   Unit 1 practice app - dyslexia-first stylesheet.
   Design rules used throughout:
     - never pure black on pure white (visual stress)
     - short line length, generous line height, ragged right edge
     - big touch targets, no timers, no flashing
     - all sizing driven by CSS variables the student can change
   --------------------------------------------------------------- */

:root {
  --fs: 118%;
  --lh: 1.75;
  --ls: 0.02em;
  --ws: 0.10em;
  --font: Verdana, Geneva, Tahoma, sans-serif;
  --maxw: 44rem;
  --radius: 14px;
  --pad: 1.25rem;
}

/* ---------- themes ---------- */
[data-theme="cream"] {
  --bg: #faf3e3; --panel: #fffcf3; --panel2: #f4ead4;
  --ink: #33302a; --muted: #6b6357; --line: #ddceae;
  --accent: #2f6f5e; --accent-ink: #ffffff; --accent-soft: #dbeee7;
  --ok: #2c6e49; --ok-bg: #e2f2e6; --err: #9c3b28; --err-bg: #fbe7e1;
}
[data-theme="blue"] {
  --bg: #e9f1f8; --panel: #f7fbfe; --panel2: #dceaf5;
  --ink: #23303a; --muted: #5d6c78; --line: #c2d8e8;
  --accent: #1f5c8b; --accent-ink: #ffffff; --accent-soft: #d9e9f5;
  --ok: #1c6349; --ok-bg: #dcf0e6; --err: #93321f; --err-bg: #fae2da;
}
[data-theme="mint"] {
  --bg: #e9f4ec; --panel: #f7fdf9; --panel2: #d9ecdf;
  --ink: #27332b; --muted: #5c6d61; --line: #c2ddca;
  --accent: #2b6b4f; --accent-ink: #ffffff; --accent-soft: #d8ecdf;
  --ok: #2b6b4f; --ok-bg: #d9efe1; --err: #8f3524; --err-bg: #f9e3dc;
}
[data-theme="peach"] {
  --bg: #fbeee6; --panel: #fff9f5; --panel2: #f6e0d2;
  --ink: #3a2e28; --muted: #71615a; --line: #e6cbb8;
  --accent: #a2542c; --accent-ink: #ffffff; --accent-soft: #f6e2d5;
  --ok: #4a6b2c; --ok-bg: #eaf1de; --err: #94331f; --err-bg: #fbe3da;
}
[data-theme="dark"] {
  --bg: #23272c; --panel: #2e343a; --panel2: #383f46;
  --ink: #e9e6e0; --muted: #a9b1b9; --line: #4a525a;
  --accent: #7fc8a9; --accent-ink: #14201b; --accent-soft: #354741;
  --ok: #8ed4ae; --ok-bg: #2c3f36; --err: #f0a48f; --err-bg: #45302b;
}
[data-theme="contrast"] {
  --bg: #000000; --panel: #101010; --panel2: #1c1c1c;
  --ink: #ffffff; --muted: #d8d8d8; --line: #6a6a6a;
  --accent: #ffd400; --accent-ink: #000000; --accent-soft: #3a3200;
  --ok: #7dff9b; --ok-bg: #082c12; --err: #ff9a8a; --err-bg: #350f08;
}

* { box-sizing: border-box; }

html { font-size: var(--fs); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: var(--lh);
  letter-spacing: var(--ls);
  word-spacing: var(--ws);
  text-align: left;
  -webkit-font-smoothing: antialiased;
}

/* Never justify: uneven word gaps create "rivers" that are hard to track. */
p, li, td, th, label, div { text-align: left; }

h1, h2, h3 { line-height: 1.3; letter-spacing: 0.01em; margin: 0 0 0.6em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.08rem; }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--accent);
  color: var(--accent-ink); padding: 0.6rem 1rem; z-index: 100;
}
.skip-link:focus { left: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 3px solid var(--line);
}
.icon-btn {
  font: inherit; font-size: 0.92rem;
  background: var(--panel2); color: var(--ink);
  border: 2px solid var(--line); border-radius: 999px;
  padding: 0.5rem 1rem; cursor: pointer; min-height: 44px;
}
.icon-btn:hover { border-color: var(--accent); }
.account-area { display: flex; align-items: center; gap: 0.55rem; margin-left: auto; }
.account-area[hidden] { display: none; }
.account-name { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.78rem; }
.sync-status { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.sync-status.sync-error { color: var(--err); }
.progress-wrap { flex: 1; min-width: 0; }
.progress-text { font-size: 0.9rem; color: var(--muted); }
.progress-bar {
  height: 12px; background: var(--panel2);
  border: 2px solid var(--line); border-radius: 999px; overflow: hidden;
}
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.25s ease; }

/* ---------- layout ---------- */
main { max-width: var(--maxw); margin: 0 auto; padding: 1.5rem 1rem 5rem; }
main:focus { outline: none; }

.site-footer {
  max-width: var(--maxw); margin: 0 auto; padding: 0 1rem 1.5rem;
  color: var(--muted); font-size: 0.75rem;
}
.site-footer p { margin: 0; text-align: center; }

.card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 1.25rem;
}
.card-accent { border-left: 10px solid var(--accent); }

.stack > * + * { margin-top: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.row-end { justify-content: flex-end; }
.spacer { flex: 1; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; cursor: pointer;
  border-radius: var(--radius);
  padding: 0.75rem 1.35rem;
  min-height: 52px;
  border: 2px solid var(--line);
  background: var(--panel2); color: var(--ink);
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible {
  outline: 4px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-big { font-size: 1.15rem; padding: 1rem 1.8rem; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.select, input[type="text"], input[type="number"] {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 2px solid var(--line); border-radius: 10px;
  padding: 0.55rem 0.7rem; min-height: 48px;
}
.select { width: 100%; }

/* ---------- home ---------- */
.hero-title { margin-bottom: 0.2rem; }
.hero-sub { color: var(--muted); margin-top: 0; }
.auth-card { margin-top: 8vh; }
.auth-card .btn { margin-top: 0.7rem; }
.privacy-note { color: var(--muted); font-size: 0.85rem; }

.pill {
  display: inline-block; background: var(--accent-soft); color: var(--ink);
  border-radius: 999px; padding: 0.2rem 0.8rem; font-size: 0.85rem;
  border: 2px solid var(--line);
}

.lesson-grid { display: grid; gap: 0.85rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.lesson-card {
  text-align: left; display: block; width: 100%;
  background: var(--panel); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 0.9rem 1rem; cursor: pointer;
  font: inherit; color: var(--ink);
}
.lesson-card:hover { border-color: var(--accent); background: var(--panel2); }
.lesson-code { font-size: 0.8rem; color: var(--muted); display: block; }
.lesson-name { font-weight: 700; display: block; }
.dots { margin-top: 0.4rem; display: flex; gap: 4px; align-items: center; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--panel2); border: 2px solid var(--line); }
.dot.on { background: var(--accent); border-color: var(--accent); }
.dots-label { font-size: 0.78rem; color: var(--muted); margin-left: 0.4rem; }

/* ---------- problem view ---------- */
.prompt {
  font-size: 1.18rem;
  margin: 0 0 1rem;
}
.prompt .sentence { display: block; margin-bottom: 0.35rem; }

.task-label {
  display: inline-block; font-size: 0.85rem; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 0.35rem;
}

/* maths display */
.mathblock {
  background: var(--panel2); border: 2px solid var(--line); border-radius: 10px;
  padding: 0.85rem 1rem; margin: 0.75rem 0;
  font-size: 1.3rem; line-height: 1.9; word-spacing: 0.16em;
  font-variant-numeric: tabular-nums lining-nums;
  overflow-x: auto;
}
.math { font-variant-numeric: tabular-nums lining-nums; word-spacing: 0.14em; white-space: nowrap; }
.math sup { font-size: 0.7em; }

.sysbrace { display: inline-flex; align-items: center; gap: 0.5rem; }
.sysbrace .brace { font-size: 2.6em; line-height: 0.8; color: var(--accent); }
.sysbrace .eqs { display: flex; flex-direction: column; gap: 0.35rem; }

.fraction { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 0.15em; }
.fraction .num { border-bottom: 2px solid currentColor; padding: 0 0.28em; }
.fraction .den { padding: 0 0.28em; }

/* matrices */
.matrix { display: inline-flex; align-items: stretch; gap: 0.3rem; vertical-align: middle; margin: 0.25rem 0.35rem; }
.matrix .bracket { width: 12px; border: 3px solid var(--ink); }
.matrix .bracket.left { border-right: none; border-radius: 4px 0 0 4px; }
.matrix .bracket.right { border-left: none; border-radius: 0 4px 4px 0; }
.matrix table { border-collapse: collapse; }
.matrix td {
  padding: 0.35rem 0.7rem; text-align: right; min-width: 2.6rem;
  font-variant-numeric: tabular-nums lining-nums;
}

/* ---------- answer fields ---------- */
.fields { display: flex; flex-direction: column; gap: 1.1rem; margin-top: 1.25rem; }
.field > .flabel { display: block; font-weight: 700; margin-bottom: 0.35rem; }
.field .fhelp { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.4rem; }

.ans {
  font: inherit; font-size: 1.25rem; text-align: center;
  width: 7.5rem; min-height: 56px; padding: 0.4rem;
  background: var(--panel); color: var(--ink);
  border: 3px solid var(--line); border-radius: 10px;
  font-variant-numeric: tabular-nums lining-nums;
}
.ans.wide { width: 14rem; text-align: left; padding-left: 0.7rem; }
.ans:focus { border-color: var(--accent); }
.ans.mark-ok { border-color: var(--ok); background: var(--ok-bg); }
.ans.mark-err { border-color: var(--err); background: var(--err-bg); }

.point-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.point-row .paren { font-size: 1.9rem; color: var(--muted); }

.choice-list { display: flex; flex-direction: column; gap: 0.6rem; }
.choice {
  display: flex; gap: 0.75rem; align-items: center;
  border: 3px solid var(--line); border-radius: 12px;
  padding: 0.75rem 1rem; cursor: pointer; background: var(--panel);
}
.choice:hover { border-color: var(--accent); }
.choice input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.choice.mark-ok { border-color: var(--ok); background: var(--ok-bg); }
.choice.mark-err { border-color: var(--err); background: var(--err-bg); }

.check-row { display: flex; gap: 0.65rem; align-items: center; margin-top: 0.5rem; }
.check-row input { width: 24px; height: 24px; accent-color: var(--accent); }

.matrix-input { display: inline-flex; align-items: stretch; gap: 0.3rem; }
.matrix-input .bracket { width: 12px; border: 3px solid var(--ink); }
.matrix-input .bracket.left { border-right: none; border-radius: 4px 0 0 4px; }
.matrix-input .bracket.right { border-left: none; border-radius: 0 4px 4px 0; }
.matrix-input .cells { display: grid; gap: 0.4rem; padding: 0.3rem; }
.matrix-input .ans { width: 5rem; min-height: 50px; font-size: 1.1rem; }

/* ---------- feedback ---------- */
.feedback { border-radius: var(--radius); padding: 1rem 1.15rem; border: 3px solid var(--line); margin-top: 1.25rem; }
.feedback h3 { margin: 0 0 0.4rem; }
.feedback.ok { border-color: var(--ok); background: var(--ok-bg); }
.feedback.err { border-color: var(--err); background: var(--err-bg); }
.feedback p:last-child { margin-bottom: 0; }

.steps { counter-reset: step; list-style: none; padding: 0; margin: 0.6rem 0 0; }
.steps li {
  counter-increment: step; position: relative;
  padding: 0.6rem 0 0.6rem 2.6rem; border-top: 2px solid var(--line);
}
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0.6rem;
  width: 1.9rem; height: 1.9rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 0.9rem;
}

.hintbox { background: var(--accent-soft); border: 3px dashed var(--line); border-radius: var(--radius); padding: 0.9rem 1.1rem; margin-top: 1rem; }
.hintbox p { margin: 0.35rem 0; }

.hint-note { font-size: 0.85rem; color: var(--muted); }

/* ---------- graph ---------- */
.graph-holder { margin: 1rem 0; }
.graph-holder canvas {
  width: 100%; max-width: 460px; height: auto; display: block;
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px;
  touch-action: manipulation;
}
canvas.clickable { cursor: crosshair; }

/* ---------- drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 60; }
.drawer-scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.drawer-panel {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(26rem, 100%);
  background: var(--panel); border-left: 3px solid var(--line);
  padding: 1.1rem; overflow-y: auto;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.drawer fieldset { border: 2px solid var(--line); border-radius: var(--radius); margin: 1rem 0; padding: 0.85rem; }
.drawer legend { font-weight: 700; padding: 0 0.4rem; }
.slider-row { display: grid; grid-template-columns: 1fr auto; gap: 0.35rem 0.75rem; align-items: center; margin-bottom: 0.75rem; }
.slider-row input[type="range"] { grid-column: 1 / -1; width: 100%; height: 34px; accent-color: var(--accent); }
.slider-row output { font-variant-numeric: tabular-nums; color: var(--muted); }

.swatches { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.swatch {
  width: 4.4rem; height: 3.2rem; border-radius: 10px; cursor: pointer;
  border: 3px solid var(--line); font: inherit; font-size: 0.72rem;
  display: grid; place-items: end center; padding-bottom: 3px;
}
.swatch[aria-pressed="true"] { outline: 4px solid var(--accent); outline-offset: 2px; }

/* ---------- reading ruler ---------- */
.reading-ruler {
  position: fixed; left: 0; right: 0; height: 3.4rem; z-index: 5;
  pointer-events: none;
  border-top: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  background: rgba(255, 235, 120, 0.16);
}
[data-theme="dark"] .reading-ruler, [data-theme="contrast"] .reading-ruler {
  background: rgba(255, 255, 255, 0.10);
}

/* ---------- summary ---------- */
.score-big { font-size: 2.6rem; font-weight: 700; color: var(--accent); line-height: 1.1; }
.review-list { list-style: none; padding: 0; margin: 0; }
.review-list li { border-top: 2px solid var(--line); padding: 0.6rem 0; display: flex; gap: 0.75rem; align-items: baseline; }
.tick { font-weight: 700; }
.tick.ok { color: var(--ok); }
.tick.err { color: var(--err); }

table.data { border-collapse: collapse; margin: 0.75rem 0; }
table.data th, table.data td { border: 2px solid var(--line); padding: 0.45rem 0.8rem; text-align: left; }
table.data th { background: var(--panel2); }

@media (max-width: 480px) {
  :root { --pad: 1rem; }
  .topbar { flex-wrap: wrap; }
  .account-area { width: 100%; margin-left: 0; }
  .account-name { flex: 1; max-width: none; }
  .ans { width: 6rem; }
  /* Three-variable equations are wide; shrink them a little so they fit on
     a phone rather than needing a sideways scroll. */
  .mathblock { font-size: 1.08rem; word-spacing: 0.1em; padding: 0.7rem; }
  .matrix td { padding: 0.3rem 0.45rem; min-width: 2rem; }
  .matrix-input .ans { width: 4.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
