/* Study Hall. One stylesheet, light and dark, no framework. */
:root {
  color-scheme: light dark;
  --bg: #f6f7fb; --surface: #fff; --raised: #eef0f7; --line: #dcdfea;
  --text: #1c2030; --muted: #5d6478;
  --accent: #4338ca; --accent-text: #fff; --accent-soft: #e8e7fb;
  --algebra: #4338ca; --spelling: #0f766e;
  --good: #15803d; --good-soft: #dcfce7; --bad: #b42318; --bad-soft: #fee4e2; --warn: #92400e; --warn-soft: #fef3c7;
  --radius: 14px; --shadow: 0 1px 2px rgb(20 24 40 / .06), 0 4px 16px rgb(20 24 40 / .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c; --surface: #1b1e2a; --raised: #252938; --line: #343a4d;
    --text: #e8eaf2; --muted: #a2a9bd;
    --accent: #8b85f7; --accent-text: #12141c; --accent-soft: #2b2a52;
    --algebra: #8b85f7; --spelling: #2dd4bf;
    --good: #4ade80; --good-soft: #143222; --bad: #f97066; --bad-soft: #3b1714; --warn: #fbbf24; --warn-soft: #3a2d0c;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 var(--font); color: var(--text); background: var(--bg); }
.page.spelling, .card.subject.spelling { --accent: var(--spelling); }
.page.spelling { --accent-soft: color-mix(in srgb, var(--spelling) 14%, var(--surface)); }
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); line-height: 1.2; margin: .2em 0 .3em; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 0 0 .4em; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
section { margin-top: 2rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 60ch; }
.eyebrow { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin: 0 0 .3em; display: block; }
.boot { text-align: center; padding: 20vh 1rem; color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

/* Buttons */
button, .button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: .6em 1.1em; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4em; min-height: 44px; color: var(--text); background: none; }
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); }
.primary:hover:not(:disabled) { filter: brightness(1.1); }
.secondary { background: var(--accent-soft); color: var(--accent); }
.ghost { border-color: var(--line); color: var(--text); background: var(--surface); }
.ghost:hover, .secondary:hover { border-color: var(--accent); }
.small { min-height: 36px; padding: .35em .8em; }
button.small, .button.small { font-size: .875rem; }
.wide { width: 100%; }
.link { padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; font-weight: 600; }
.danger-button { background: var(--bad); color: #fff; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: 1rem; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.row.sticky { position: sticky; bottom: 0; padding: .8rem 0; background: linear-gradient(transparent, var(--bg) 35%); }
.back { display: inline-block; margin-bottom: .4rem; font-size: .9rem; text-decoration: none; color: var(--muted); }
.back:hover { color: var(--accent); }

/* Shell */
.top { display: flex; align-items: center; gap: 1rem; padding: .6rem clamp(1rem, 4vw, 2rem); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.25rem; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand.big { font-size: clamp(2.4rem, 7vw, 3.4rem); margin: 0 0 .2em; }
.top nav { display: flex; gap: .25rem; flex: 1; }
.top nav a, .who { padding: .45em .8em; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600; }
.top nav a:hover, .who:hover { background: var(--raised); color: var(--text); }
.top nav a[aria-current], .who[aria-current] { background: var(--accent-soft); color: var(--accent); }
.who { border: 1px solid var(--line); }
.save-status { font-size: .8rem; color: var(--muted); }
.save-status.warn { color: var(--warn); }
.page { max-width: 880px; margin: 0 auto; padding: 1.5rem clamp(1rem, 4vw, 2rem) 5rem; outline: none; }

/* Cards and forms */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.stack { display: grid; gap: 1rem; }
.stack.narrow { max-width: 480px; }
.field { display: grid; gap: .3rem; margin-bottom: .9rem; font-weight: 600; }
.field small { font-weight: 400; }
input, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1.5px solid var(--line); border-radius: 10px; padding: .6em .8em; width: 100%; min-height: 44px; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.form-error { color: var(--bad); min-height: 1.2em; margin: .2em 0; }
.form-ok { color: var(--good); }
.card.danger { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }

/* Sign-in */
.auth-page { min-height: 100vh; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 2rem; align-items: center; max-width: 900px; margin: 0 auto; padding: 2rem clamp(1rem, 4vw, 2rem); }
.auth-intro p { font-size: 1.15rem; color: var(--muted); max-width: 34ch; }
.subject-pills { list-style: none; padding: 0; display: flex; gap: .5rem; }
.pill { padding: .3em .9em; border-radius: 99px; font-weight: 600; font-size: .9rem; }
.pill.algebra { background: color-mix(in srgb, var(--algebra) 15%, transparent); color: var(--algebra); }
.pill.spelling { background: color-mix(in srgb, var(--spelling) 15%, transparent); color: var(--spelling); }
.switch { text-align: center; margin: 1rem 0 0; color: var(--muted); }

/* Home */
.subject-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 1rem; margin-top: 1.5rem; }
.card.subject { border-top: 4px solid var(--accent); }
.facts { list-style: none; padding: 0; margin: .6rem 0; }
.facts li { padding: .15em 0; font-weight: 600; }
.nudge { background: var(--warn-soft); color: var(--warn); padding: .6em .9em; border-radius: 10px; font-size: .95rem; }
.nudge a { color: inherit; font-weight: 600; }

/* Course map */
.callout { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 1.5rem; }
.callout p { margin: 0; }
.card.next { margin-top: 1.5rem; border-left: 4px solid var(--accent); }
.focus-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: .8rem; margin-top: .8rem; }
.focus-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: .4rem; }
.count { font-weight: 700; color: var(--warn); background: var(--warn-soft); border-radius: 99px; padding: 0 .6em; font-size: .85rem; }
.skill-list { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.skill-row { display: flex; gap: .8rem 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: .8rem 1rem; border-top: 1px solid var(--line); }
.skill-row:first-child { border-top: 0; }
.skill-main { display: grid; flex: 1 1 260px; }
.skill-name { font-weight: 600; color: var(--text); text-decoration: none; }
a.skill-name:hover { color: var(--accent); }
.skill-side { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.badge { font-size: .75rem; font-weight: 700; padding: .2em .7em; border-radius: 99px; white-space: nowrap; background: var(--raised); color: var(--muted); }
.badge.level-learning { background: var(--warn-soft); color: var(--warn); }
.badge.level-practiced { background: var(--accent-soft); color: var(--accent); }
.badge.level-mastered { background: var(--good-soft); color: var(--good); }
.dots { display: inline-flex; gap: 3px; min-width: 76px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.dots i.ok { background: var(--good); }
.dots i.no { background: var(--bad); }
.dots.stage { min-width: 0; }
.dots.stage i { width: 10px; height: 10px; }
.more ul { padding-left: 1.2rem; }

/* Lessons */
.prose p { max-width: 65ch; font-size: 1.05rem; }
.idea { background: var(--accent-soft); border-radius: var(--radius); padding: 1rem 1.25rem; font-size: 1.15rem; font-weight: 600; margin: 1.2rem 0; }
.examples { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); gap: .8rem; margin-top: .8rem; align-items: start; }
.math { font-family: var(--serif); font-size: 1.2em; white-space: nowrap; }
p.math { font-size: 1.35rem; margin: 0 0 .5em; white-space: normal; }
p.math.big { font-size: clamp(1.7rem, 6vw, 2.3rem); margin: .2em 0 .6em; }
.math i { font-style: italic; padding-right: .04em; }
sup { font-size: .7em; line-height: 0; }
.steps { padding-left: 1.3rem; margin: .5rem 0; }
.steps li { margin: .3em 0; }
.resources { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 1rem; }
.resource { margin: 0; }
.resource figcaption { margin-top: .4rem; font-size: .9rem; }
.video, .sim.open { aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: #000; }
.sim.open { aspect-ratio: 4 / 3; }
.video iframe, .sim iframe { width: 100%; height: 100%; border: 0; display: block; }
.video-start { padding: 0; border: 0; width: 100%; height: 100%; position: relative; border-radius: 0; min-height: 0; }
.video-start img { width: 100%; height: 100%; object-fit: cover; display: block; }
.play { position: absolute; inset: 0; margin: auto; width: 68px; height: 48px; border-radius: 14px; background: rgb(0 0 0 / .72); color: #fff; display: grid; place-items: center; font-size: 1.3rem; }
.video-start:hover .play { background: #e11d48; }
.sim-closed { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; }
.sim-closed p { margin: 0; }
.traps { padding-left: 1.2rem; }
.traps li { margin: .4em 0; }

/* Questions */
.practice-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.progress-row { display: flex; align-items: center; gap: 1rem; margin: .5rem 0 1rem; }
.progress { flex: 1; height: 8px; border-radius: 99px; background: var(--raised); overflow: hidden; margin: .5rem 0 1rem; }
.progress-row .progress { margin: 0; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }
.question .lead { color: var(--muted); font-weight: 600; margin: 0; }
.answer-row { display: flex; align-items: center; gap: .6rem; }
.prefix { font-size: 1.2rem; white-space: nowrap; }
.answer { font-size: 1.25rem; max-width: 320px; font-family: var(--serif); }
.answer.short { max-width: 150px; font-size: 1.1rem; }
.keys { display: flex; gap: .4rem; margin-top: .6rem; }
.key { min-width: 44px; padding: .3em .6em; background: var(--raised); font-family: var(--serif); font-size: 1.1rem; }
.feedback { margin-top: 1rem; }
.feedback:empty { margin: 0; }
.verdict { font-weight: 700; font-size: 1.1rem; margin-bottom: .3em; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }
.hint { background: var(--raised); border-radius: 10px; padding: .6em .9em; }
details summary { cursor: pointer; font-weight: 600; color: var(--accent); margin: .5em 0; }
.typed { font-family: var(--serif); background: var(--bad-soft); padding: 0 .3em; border-radius: 4px; }
.graph { width: min(100%, 280px); display: block; margin: .5rem 0 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.graph .grid { stroke: var(--line); stroke-width: .5; opacity: .6; }
.graph .grid.strong { opacity: 1; stroke-width: .8; }
.graph .axis { stroke: var(--muted); stroke-width: 1.2; }
.graph .tick, .graph .label { font-size: 9px; fill: var(--muted); font-family: var(--font); }
.graph .label { font-size: 10px; fill: var(--text); font-weight: 600; }
.graph .plot { stroke: var(--accent); stroke-width: 2; }
.graph .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; }

/* Workbench */
.bench { margin-top: .8rem; }
.work-lines { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .35rem; }
.work-lines li { display: grid; grid-template-columns: minmax(0, 15rem) 1fr; gap: 1rem; align-items: baseline; padding: .3rem 0; border-bottom: 1px dashed var(--line); }
.work-lines .move { color: var(--muted); font-size: .875rem; }
.work-lines .math { font-size: 1.35rem; }
.move-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.ops { display: inline-flex; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.op { border-radius: 0; min-width: 46px; font-size: 1.25rem; font-family: var(--serif); background: var(--surface); }
.op[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
@media (max-width: 560px) { .work-lines li { grid-template-columns: 1fr; gap: 0; } }

/* Spelling */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; margin: 1.2rem 0; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; display: grid; }
.tile strong { font-size: 1.9rem; line-height: 1.1; color: var(--accent); }
.tile span { color: var(--muted); font-size: .9rem; }
.prompt { font-family: var(--serif); font-size: 1.3rem; line-height: 1.35; margin: 0 0 .8rem; }
.prompt-row { display: flex; gap: 1rem; justify-content: space-between; align-items: flex-start; }
.prompt-row button { flex: none; }
textarea.journal { min-height: 230px; font-size: 1.1rem; line-height: 1.6; resize: vertical; font-family: var(--serif); }
.written { font-family: var(--serif); font-size: 1.1rem; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.was { text-decoration: line-through wavy var(--bad); text-decoration-thickness: 1.5px; text-underline-offset: 2px; color: var(--bad); }
.written .was, .fix .was { text-decoration: underline wavy var(--bad); }
.now { color: var(--good); font-weight: 700; }
.choices { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0; }
.choice { background: var(--raised); font-family: var(--serif); font-size: 1.15rem; border: 1.5px solid transparent; }
.choice.quiet { font-family: var(--font); font-size: .9rem; background: none; border-color: var(--line); color: var(--muted); }
.choice[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.other-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.other { display: flex; gap: .4rem; align-items: center; }
.other.chosen input { border-color: var(--accent); background: var(--accent-soft); }
.fix-summary, .entry-list, .word-table, .chips { list-style: none; padding: 0; }
.fix-summary li { font-family: var(--serif); font-size: 1.2rem; padding: .3em 0; }
.word mark, .show-word mark { background: color-mix(in srgb, var(--warn) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 .05em; }
.entry-list li a { display: grid; gap: .1rem; padding: .8rem 1rem; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; }
.entry-list li a:hover { border-color: var(--accent); }
.entry-date { font-weight: 700; font-size: .85rem; color: var(--accent); }
.entry-text { font-family: var(--serif); }
.spell { text-align: center; display: grid; justify-items: center; gap: .3rem; }
.spell .row { justify-content: center; }
.show-word { font-family: var(--serif); font-size: clamp(2rem, 8vw, 3rem); letter-spacing: .04em; margin: .3em 0; }
.covered { font-size: 2rem; letter-spacing: .25em; color: var(--line); margin: .3em 0; }
.spell .answer { text-align: center; font-size: 1.5rem; letter-spacing: .03em; }
.writes { display: flex; gap: .4rem; margin-bottom: .5rem; }
.writes i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); }
.writes i.ok { background: var(--good); border-color: var(--good); }
.word-table li { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem; padding: .7rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem; }
.word-table .word { font-family: var(--serif); font-size: 1.25rem; min-width: 9rem; }
.word-table .wrote { flex: 1 1 8rem; }
.add-word { display: flex; gap: .6rem; margin: 1rem 0 .3rem; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chips li { background: var(--raised); border-radius: 99px; padding: .15em .3em .15em .8em; display: inline-flex; align-items: center; gap: .2rem; }
.chip-x { min-height: 28px; padding: 0 .5em; border-radius: 50%; color: var(--muted); }

/* Toasts */
#toasts { position: fixed; bottom: 1rem; left: 0; right: 0; display: grid; justify-items: center; gap: .5rem; pointer-events: none; z-index: 20; }
.toast { background: var(--text); color: var(--bg); padding: .7em 1.1em; border-radius: 10px; box-shadow: 0 6px 24px rgb(0 0 0 / .25); max-width: min(90vw, 480px); }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 560px) {
  .top nav { order: 3; flex-basis: 100%; }
  .top .who { margin-left: auto; }
  .tiles { gap: .5rem; }
  .tile { padding: .7rem; }
  .prompt-row { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
