/* SAT Math Coach — app styles */
:root {
  --bg: #f6f7fb; --surface: #ffffff; --surface-2: #eef1f7; --border: #dfe3ec;
  --text: #16203a; --muted: #5b6480; --accent: #1f5fbf; --accent-2: #0f8b8d; --accent-soft: #e4edfb;
  --ok: #1d8f5a; --ok-soft: #e2f5ea; --warn: #b7791f; --warn-soft: #fbf1dc; --bad: #c0392b; --bad-soft: #fbe5e2;
  --c0: #6b7280; --c1: #1f5fbf; --c2: #7c3aed; --c3: #0f8b8d; --c4: #d97706;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px; --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --fs: 18px;
}
:root:not([data-theme="light"]) { color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1420; --surface: #171d2d; --surface-2: #1f2739; --border: #2c3650; --text: #e8ecf5; --muted: #9aa5c0;
    --accent: #6ea0ff; --accent-2: #3fc1c3; --accent-soft: #1e2d4d; --ok: #3ccf87; --ok-soft: #15362a; --warn: #f0b24a; --warn-soft: #3a2d14; --bad: #ff7b6b; --bad-soft: #42201c;
    --c0: #8b93a7; --c1: #6ea0ff; --c2: #b088ff; --c3: #3fc1c3; --c4: #f5a524;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 18px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1420; --surface: #171d2d; --surface-2: #1f2739; --border: #2c3650; --text: #e8ecf5; --muted: #9aa5c0;
  --accent: #6ea0ff; --accent-2: #3fc1c3; --accent-soft: #1e2d4d; --ok: #3ccf87; --ok-soft: #15362a; --warn: #f0b24a; --warn-soft: #3a2d14; --bad: #ff7b6b; --bad-soft: #42201c;
  --c0: #8b93a7; --c1: #6ea0ff; --c2: #b088ff; --c3: #3fc1c3; --c4: #f5a524;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 18px rgba(0,0,0,.35);
}
:root[data-bigtext="1"] { --fs: 21px; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs); line-height: 1.55; min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--accent); }
button { font: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.7em; font-weight: 700; }
h2 { font-size: 1.3em; font-weight: 650; }
h3 { font-size: 1.05em; font-weight: 650; }
p { margin: .4rem 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.hidden { display: none !important; }
.sr { position: absolute; left: -9999px; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 16px; padding-top: env(safe-area-inset-top); }
.topbar-inner { max-width: 1040px; margin: 0 auto; display: flex; align-items: center; gap: 12px; height: 58px; }
.brand { font-weight: 800; letter-spacing: -.02em; font-size: 1.05em; display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: inline-grid; place-items: center; color: #fff; font-weight: 900; font-size: 14px; }
.nav { display: flex; gap: 2px; margin-left: auto; }
.nav a { text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: 10px; font-weight: 600; font-size: .9em; }
.nav a.active, .nav a:hover { color: var(--accent); background: var(--accent-soft); }
.iconbtn { background: transparent; border: 1px solid var(--border); border-radius: 10px; width: 40px; height: 40px; display: inline-grid; place-items: center; cursor: pointer; color: var(--text); }
.iconbtn:hover { background: var(--surface-2); }
.tabbar { display: none; }
@media (max-width: 760px) {
  .nav { display: none; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { flex: 1; text-align: center; padding: 8px 2px 6px; text-decoration: none; color: var(--muted); font-size: .72em; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--accent); }
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
}
main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 40px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card h2, .card h3 { margin-top: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.center { text-align: center; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 11px 18px; border-radius: 12px; cursor: pointer; font-weight: 600; text-decoration: none; min-height: 46px; transition: transform .05s, background .15s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 7px 12px; min-height: 36px; font-size: .88em; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.tool { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn.tool:hover { filter: brightness(.97); }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* Forms */
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea { font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); width: 100%; max-width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 1px; }
label.field { display: block; margin-bottom: 12px; font-weight: 600; font-size: .92em; }
label.field span { display: block; margin-bottom: 4px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 0; }
.switch input { width: 22px; height: 22px; }

/* Badges / chips */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .78em; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.chip.c0 { background: color-mix(in srgb, var(--c0) 18%, transparent); color: var(--c0); }
.chip.c1 { background: color-mix(in srgb, var(--c1) 18%, transparent); color: var(--c1); }
.chip.c2 { background: color-mix(in srgb, var(--c2) 18%, transparent); color: var(--c2); }
.chip.c3 { background: color-mix(in srgb, var(--c3) 18%, transparent); color: var(--c3); }
.chip.c4 { background: color-mix(in srgb, var(--c4) 18%, transparent); color: var(--c4); }
.chip.new { background: var(--surface-2); }
.chip.learning { background: var(--warn-soft); color: var(--warn); }
.chip.practicing { background: var(--accent-soft); color: var(--accent); }
.chip.mastered { background: var(--ok-soft); color: var(--ok); }

/* Progress */
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
.bar.ok > i { background: var(--ok); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 1.6em; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .82em; font-weight: 600; }
.ring { width: 96px; height: 96px; }

/* Skill map */
.skillmap { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.skill-tile { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--surface); cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 76px; }
.skill-tile:hover { border-color: var(--accent); }
.skill-tile .name { font-weight: 650; font-size: .86em; line-height: 1.25; }
.skill-tile .dots { display: flex; gap: 3px; }
.skill-tile .dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-2); }
.skill-tile .dots i.on { background: var(--accent); }
.skill-tile.mastered { border-color: var(--ok); background: var(--ok-soft); }
.skill-tile.practicing { border-color: var(--accent); }
.skill-tile.learning { border-color: var(--warn); }
.skill-tile.locked { opacity: .55; }

/* Question panel */
.qpanel { max-width: 760px; margin: 0 auto; }
.qstem { font-size: 1.12em; line-height: 1.6; }
.qmeta { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.choices { display: grid; gap: 10px; margin: 14px 0; }
.choice { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; text-align: left; width: 100%; font-size: 1.05em; }
.choice:hover { border-color: var(--accent); }
.choice .letter { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border); display: inline-grid; place-items: center; font-weight: 700; flex-shrink: 0; font-size: .9em; }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice.selected .letter { background: var(--accent); color: #fff; border-color: var(--accent); }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.correct .letter { background: var(--ok); color: #fff; border-color: var(--ok); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.wrong .letter { background: var(--bad); color: #fff; border-color: var(--bad); }
.choice.eliminated { opacity: .45; text-decoration: line-through; }
.spr { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.spr input { max-width: 220px; font-size: 1.3em; font-family: var(--font); letter-spacing: .02em; }
.spr .preview { font-size: 1.3em; min-width: 80px; }
.feedback { border-radius: 12px; padding: 12px 16px; margin: 12px 0; border: 1px solid var(--border); }
.feedback.ok { background: var(--ok-soft); border-color: var(--ok); }
.feedback.bad { background: var(--bad-soft); border-color: var(--bad); }
.feedback.info { background: var(--accent-soft); border-color: transparent; }
.feedback.hint { background: var(--warn-soft); border-color: transparent; }
.steps { margin: 8px 0 0; padding-left: 0; list-style: none; counter-reset: step; }
.steps li { position: relative; padding: 8px 0 8px 40px; border-top: 1px dashed var(--border); }
.steps li::before { counter-increment: step; content: counter(step); position: absolute; left: 0; top: 8px; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: .8em; font-weight: 700; }
.vizwrap { margin: 12px 0; display: flex; justify-content: center; }
.viz { max-width: 100%; height: auto; max-height: 340px; }
.viz-graph { max-width: 360px; }
.timerbox { font-variant-numeric: tabular-nums; font-weight: 700; padding: 6px 12px; border-radius: 10px; background: var(--surface-2); }
.timerbox.low { background: var(--bad-soft); color: var(--bad); }

/* Math rendering */
.m { font-family: 'Inter', 'Cambria', 'Times New Roman', serif; white-space: nowrap; }
.m .mvar { font-style: italic; font-family: 'Cambria', 'Times New Roman', Georgia, serif; }
.m .mop { padding: 0 .18em; }
.m .msym { padding: 0 .05em; }
.mfrac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 .15em; line-height: 1.15; font-size: .95em; }
.mfrac .mnum { border-bottom: 1.5px solid currentColor; padding: 0 .25em .05em; }
.mfrac .mden { padding: .05em .25em 0; }
.msqrt { display: inline-flex; align-items: stretch; margin: 0 .1em; }
.msqrt .mradsign { font-size: 1.15em; line-height: 1; align-self: flex-end; }
.msqrt .mrad { border-top: 1.5px solid currentColor; padding: 0 .25em 0 .15em; line-height: 1.25; }
.msqrt .midx { font-size: .6em; vertical-align: super; margin-right: -.15em; align-self: flex-start; }
.msup { font-size: .72em; vertical-align: super; line-height: 0; }
.msub { font-size: .72em; vertical-align: sub; line-height: 0; }
.mtext { font-family: var(--font); }
.mbold { font-weight: 700; }
.mover { text-decoration: overline; }
.mboxed { border: 1px solid currentColor; padding: 0 .3em; border-radius: 4px; }
.mblock { text-align: center; margin: 10px 0; font-size: 1.15em; }
.mdisplay { white-space: normal; }
.mbig { font-size: 1.2em; }

/* Tables */
.dtable { border-collapse: collapse; margin: 10px auto; font-size: .95em; }
.dtable th, .dtable td { border: 1px solid var(--border); padding: 6px 14px; text-align: center; }
.dtable th { background: var(--surface-2); }

/* SVG viz theme */
.vz-axis { stroke: var(--text); stroke-width: 1.5; fill: none; }
.vz-grid { stroke: var(--border); stroke-width: 1; }
.vz-fill { fill: var(--text); }
.vz-label { fill: var(--text); font-size: 15px; font-family: var(--font); }
.vz-strong { font-weight: 700; }
.vz-tick { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.vz-point { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.vz-open { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.vz-dot { fill: var(--accent-2); }
.vz-range { stroke: var(--accent); stroke-width: 6; stroke-linecap: round; opacity: .7; }
.vz-arc { stroke: var(--accent-2); stroke-width: 2; fill: none; }
.vz-shaded { fill: color-mix(in srgb, var(--accent) 55%, transparent); stroke: var(--text); stroke-width: 1; }
.vz-empty { fill: var(--surface); stroke: var(--text); stroke-width: 1; }
.vz-curve { fill: none; stroke-width: 3; stroke-linecap: round; }
.vz-c0 { stroke: var(--accent); } .vz-c1 { stroke: var(--c4); } .vz-c2 { stroke: var(--accent-2); } .vz-c3 { stroke: var(--c2); }
.vz-shade { fill: color-mix(in srgb, var(--accent) 18%, transparent); }
.vz-bar { fill: var(--accent); opacity: .85; }
.vz-shape { fill: color-mix(in srgb, var(--accent) 10%, transparent); stroke: var(--text); stroke-width: 2; }

/* Lesson */
.lesson-nav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.lesson-nav span { padding: 6px 12px; border-radius: 999px; background: var(--surface-2); font-size: .82em; font-weight: 700; color: var(--muted); }
.lesson-nav span.on { background: var(--accent); color: #fff; }
.lesson-nav span.done { background: var(--ok-soft); color: var(--ok); }
.bigidea { border-left: 4px solid var(--accent); padding: 10px 16px; background: var(--accent-soft); border-radius: 0 12px 12px 0; margin: 12px 0; }
.example { border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin: 10px 0; }
.tip { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px dashed var(--border); }

/* Lists */
.plan { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.plan li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.plan li.done { opacity: .6; }
.plan .check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; flex-shrink: 0; font-size: .8em; }
.plan li.done .check { background: var(--ok); color: #fff; border-color: var(--ok); }
.plan .grow { flex: 1; min-width: 0; }
.plan .grow b { display: block; font-size: .95em; }
.plan .grow span { color: var(--muted); font-size: .82em; }

/* Calculator */
.calc { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 820px) { .calc { grid-template-columns: 320px 1fr; } }
.calc-keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.calc-keys button { padding: 10px 4px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; }
.calc-keys button.op { background: var(--surface-2); }
.calc-keys button.eq { background: var(--accent); color: #fff; border-color: var(--accent); }
.calc-display { font-family: ui-monospace, Menlo, monospace; font-size: 1.1em; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; min-height: 48px; word-break: break-all; }
.calc-result { font-size: 1.4em; font-weight: 800; padding: 6px 12px; min-height: 40px; }
canvas.graph { width: 100%; height: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); touch-action: none; }
.exprlist { display: flex; flex-direction: column; gap: 6px; }
.exprlist .row { gap: 6px; }
.exprlist .sw { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }

/* Test */
.testnav { display: flex; gap: 4px; flex-wrap: wrap; margin: 10px 0; }
.testnav button { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 700; font-size: .85em; }
.testnav button.answered { background: var(--accent-soft); border-color: var(--accent); }
.testnav button.flagged { border-color: var(--warn); box-shadow: inset 0 0 0 2px var(--warn); }
.testnav button.current { background: var(--accent); color: #fff; }
.testnav button.right { background: var(--ok-soft); border-color: var(--ok); }
.testnav button.wrong { background: var(--bad-soft); border-color: var(--bad); }

/* Toast + modal */
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; padding: 20px; max-width: 520px; width: 100%; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.hero { background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 14%, var(--surface)), color-mix(in srgb, var(--accent-2) 12%, var(--surface))); }
.domain-head { display: flex; align-items: center; gap: 10px; margin: 18px 0 8px; }
.domain-head .sw { width: 12px; height: 12px; border-radius: 3px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .8em; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.ai-box textarea { min-height: 70px; }
.ai-answer { white-space: pre-wrap; }
.fade { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media print { .topbar, .tabbar, .btnrow { display: none; } }
