/* ALES Kampı — phone first, light/dark, motion via transform/opacity only. */

:root {
  --bg: #f4f5fb;
  --bg-2: #eceefa;
  --surface: #ffffff;
  --surface-2: #f7f7fd;
  --text: #15172b;
  --muted: #5d6280;
  --line: #e1e3f0;
  --accent: #6d4aff;
  --accent-2: #0ea5c6;
  --accent-ink: #ffffff;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --xp: #d97706;
  --gold: #f59e0b;
  --paper: #ffffff;
  --ink: #111111;
  --shadow: 0 1px 2px rgb(20 20 60 / 6%), 0 8px 24px rgb(20 20 60 / 8%);
  --radius: 16px;
  --radius-sm: 10px;
  --gutter: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0e1c;
    --bg-2: #13152a;
    --surface: #181a33;
    --surface-2: #1f2240;
    --text: #eceefe;
    --muted: #9aa0c3;
    --line: #2b2f55;
    --accent: #8b6dff;
    --accent-2: #22d3ee;
    --good: #4ade80;
    --good-bg: #12351f;
    --bad: #f87171;
    --bad-bg: #3b1518;
    --xp: #fbbf24;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 30px rgb(0 0 0 / 35%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0e1c;
  --bg-2: #13152a;
  --surface: #181a33;
  --surface-2: #1f2240;
  --text: #eceefe;
  --muted: #9aa0c3;
  --line: #2b2f55;
  --accent: #8b6dff;
  --accent-2: #22d3ee;
  --good: #4ade80;
  --good-bg: #12351f;
  --bad: #f87171;
  --bad-bg: #3b1518;
  --xp: #fbbf24;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 30px rgb(0 0 0 / 35%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent),
    radial-gradient(900px 500px at 110% 0%, color-mix(in srgb, var(--accent-2) 10%, transparent), transparent), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.5 var(--font);
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
button { font: inherit; color: inherit; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .7rem .8rem; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px;
}
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.page { width: 100%; max-width: 1100px; margin: 0 auto; padding: var(--gutter); padding-bottom: 6rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem;
}
.grid2 { display: grid; gap: var(--gutter); margin-top: var(--gutter); }
@media (min-width: 768px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* ---------- header / HUD ---------- */
.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .6rem max(var(--gutter), calc((100% - 1100px) / 2 + var(--gutter)));
  padding-top: max(.6rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; color: var(--text); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand span { display: none; }
@media (min-width: 560px) { .brand span { display: inline; } }
.hud { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 0; }
.lvl {
  display: flex; align-items: center; gap: .35rem; padding: .2rem .55rem .2rem .2rem; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 700; white-space: nowrap;
}
.lvl-num {
  display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%;
  background: rgb(255 255 255 / 22%); font-size: .9rem;
}
.lvl-rank { font-size: .8rem; display: none; }
@media (min-width: 420px) { .lvl-rank { display: inline; } }
.xpbar {
  position: relative; flex: 1; min-width: 70px; max-width: 280px; height: 1.25rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); overflow: hidden;
}
.xpbar-fill {
  position: absolute; inset: 0; transform-origin: left center;
  background: linear-gradient(90deg, var(--gold), #fb923c);
  transition: transform .6s cubic-bezier(.2, .8, .2, 1);
}
.xpbar-text { position: relative; display: block; text-align: center; font-size: .72rem; font-weight: 700; line-height: 1.2rem; }
.streak { font-size: .95rem; white-space: nowrap; filter: grayscale(1); opacity: .6; }
.streak.on { filter: none; opacity: 1; }
.countdown {
  display: none; font-size: .8rem; font-weight: 700; padding: .25rem .6rem; border-radius: 999px;
  background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); white-space: nowrap;
}
@media (min-width: 640px) { .countdown { display: block; } }
.menu { position: relative; }
.icon-btn {
  width: 2.5rem; height: 2.5rem; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 1.1rem;
}
.menu-pop {
  position: absolute; right: 0; top: calc(100% + .4rem); min-width: 13rem; display: grid;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: .35rem; animation: pop .14s ease-out;
}
.menu-pop a, .menu-pop button {
  display: block; text-align: left; padding: .6rem .7rem; border-radius: 8px; border: 0; background: none;
  color: var(--text); cursor: pointer;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-2); text-decoration: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 2.75rem; padding: .55rem 1.1rem; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 650; cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, var(--accent-2))); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; }

/* ---------- auth ---------- */
.auth { display: grid; place-items: center; min-height: calc(100dvh - 9rem); }
.auth-card {
  width: 100%; max-width: 400px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 2rem 1.4rem;
}
.auth-logo { border-radius: 18px; margin-bottom: .5rem; }
.auth form { display: grid; gap: .9rem; margin: 1.2rem 0 1rem; text-align: left; }
.auth label { display: grid; gap: .35rem; font-size: .9rem; font-weight: 600; }
.form-error { color: var(--bad); background: var(--bad-bg); border-radius: 8px; padding: .55rem .7rem; margin: 0; font-size: .9rem; }

/* ---------- home ---------- */
.hero { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.hero h1 { font-size: 1.35rem; }
.ring { width: 96px; height: 96px; flex: none; }
.ring-bg { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.ring-fg {
  fill: none; stroke: url(#none) var(--gold); stroke: var(--gold); stroke-width: 10; stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .8s cubic-bezier(.2, .8, .2, 1);
}
.ring-num { font-size: 24px; font-weight: 800; text-anchor: middle; fill: var(--text); }
.ring-sub { font-size: 11px; text-anchor: middle; fill: var(--muted); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: var(--gutter); }
@media (min-width: 768px) { .actions { grid-template-columns: repeat(4, 1fr); } }
.action {
  position: relative; display: grid; gap: .15rem; align-content: start; min-height: 7.2rem;
  padding: 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); color: var(--text); transition: transform .12s ease, box-shadow .12s ease;
}
.action:hover { text-decoration: none; transform: translateY(-2px); }
.action:active { transform: scale(.98); }
.action-icon { font-size: 1.6rem; }
.action-title { font-weight: 750; }
.action-sub { font-size: .8rem; color: var(--muted); }
.action-pills { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.action-pills a {
  padding: .35rem .7rem; border-radius: 999px; font-size: .82rem; font-weight: 700;
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
}
.action-pills a:hover { text-decoration: none; background: color-mix(in srgb, var(--accent) 20%, transparent); }
.action.primary {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--accent-2)));
  color: #fff; border-color: transparent;
}
.action.primary .action-sub { color: rgb(255 255 255 / 85%); }
.action.big { grid-column: 1 / -1; min-height: 8rem; }
@media (min-width: 768px) { .action.big { grid-column: span 2; } }
.badge {
  position: absolute; top: .6rem; right: .6rem; min-width: 1.5rem; height: 1.5rem; padding: 0 .4rem; border-radius: 999px;
  display: grid; place-items: center; background: var(--bad); color: #fff; font-size: .78rem; font-weight: 800;
}
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: .5rem; padding: 0; margin: 0; }
.chips a {
  display: inline-flex; gap: .4rem; align-items: baseline; padding: .45rem .75rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
}
.chips small { color: var(--muted); }
.big-number { font-size: 2.2rem; font-weight: 850; margin: 0; letter-spacing: -.02em; }
.big-number small { font-size: .9rem; color: var(--muted); font-weight: 600; }

/* ---------- toasts / level up ---------- */
.toasts {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: grid; gap: .4rem; z-index: 60; pointer-events: none; width: min(92vw, 420px);
}
.toast {
  padding: .7rem 1rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-weight: 650; text-align: center; animation: rise .22s ease-out;
}
.toast.good { background: var(--good-bg); color: var(--good); }
.toast.bad { background: var(--bad-bg); color: var(--bad); }
.toast.xp { color: var(--xp); }
.levelup {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  background: rgb(10 10 30 / 55%); backdrop-filter: blur(4px); animation: fade .2s ease-out;
}
.levelup-card {
  position: relative; overflow: hidden; text-align: center; padding: 2.2rem 2.6rem; border-radius: 24px;
  background: var(--surface); box-shadow: var(--shadow); animation: pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
.levelup-burst {
  position: absolute; inset: -40%;
  background: conic-gradient(from 0deg, transparent, color-mix(in srgb, var(--gold) 35%, transparent), transparent 30%);
  animation: spin 3s linear infinite; pointer-events: none;
}
.levelup-small { position: relative; font-size: .8rem; letter-spacing: .2em; font-weight: 800; color: var(--muted); }
.levelup-num {
  position: relative; font-size: 5rem; font-weight: 900; line-height: 1;
  background: linear-gradient(135deg, var(--gold), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.levelup-rank { position: relative; font-weight: 750; margin: .3rem 0 1.2rem; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

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

/* ---------- icons ---------- */
.ico { flex: none; display: inline-block; vertical-align: -0.2em; }
.menu-pop a, .menu-pop button { display: flex; align-items: center; gap: .6rem; }
.icon-btn { display: inline-grid; place-items: center; color: var(--text); }
.icon-btn:hover { text-decoration: none; }
.action-icon {
  display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 12px; margin-bottom: .35rem;
  background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
}
.action.primary .action-icon { background: rgb(255 255 255 / 18%); color: #fff; }
.streak { display: inline-flex; align-items: center; gap: .2rem; color: #f97316; }
.countdown { align-items: center; gap: .3rem; }
@media (min-width: 640px) { .countdown { display: inline-flex; } }
.levelup-card .ico { color: var(--gold); }

/* ---------- drill ---------- */
.drill-bar { display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem; }
.drill-bar h1 { font-size: 1.15rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo, .qtimer {
  display: inline-flex; align-items: center; gap: .3rem; padding: .3rem .65rem; border-radius: 999px;
  font-size: .85rem; font-weight: 750; font-variant-numeric: tabular-nums; background: var(--surface); border: 1px solid var(--line);
}
.combo { color: #f97316; border-color: color-mix(in srgb, #f97316 40%, var(--line)); animation: pop .25s ease-out; }
.qtimer.slow { color: var(--bad); }
.drill-grid { display: grid; gap: var(--gutter); }
@media (min-width: 1024px) {
  .drill-grid { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
  .drill-side { position: sticky; top: 5rem; }
}
.drill-side { display: grid; gap: .8rem; align-content: start; }

/* the booklet page: always light paper so ink and scans read the same in both themes */
.qwrap {
  position: relative; border-radius: var(--radius); overflow: hidden; background: var(--paper); color: var(--ink);
  border: 1px solid var(--line); box-shadow: var(--shadow); touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.qwrap.drawing, .qwrap.pen { touch-action: none; cursor: crosshair; }
.qwrap.drawing { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent), var(--shadow); }
.qcard { padding: 1rem; display: grid; gap: .75rem; }
.qcard-label { font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #6b6f8a; }
.q-img { display: block; width: 100%; max-width: 760px; height: auto; margin: 0 auto; image-rendering: auto; -webkit-user-drag: none; }
.q-stem { padding-bottom: .75rem; border-bottom: 1px dashed #d4d6e4; }
.scratch {
  position: relative; min-height: max(180px, 32vh); border-top: 1px dashed #d4d6e4;
  background-image: radial-gradient(#e3e5f0 1px, transparent 1px); background-size: 22px 22px;
}
.scratch span {
  position: absolute; left: 1rem; top: .6rem; font-size: .72rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: #a3a7bf;
}
canvas.sketch { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sketch-tools {
  display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; padding: .4rem; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); width: fit-content;
}
.tool {
  display: inline-flex; align-items: center; gap: .35rem; min-width: 2.6rem; height: 2.6rem; padding: 0 .65rem;
  border-radius: 10px; border: 1px solid transparent; background: none; cursor: pointer; color: var(--text); font-weight: 650;
}
.tool:hover { background: var(--surface-2); }
.tool[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.tool:disabled { opacity: .35; cursor: default; }
.tool-draw[aria-pressed="true"] { background: var(--accent); color: #fff; }
.swatch .dot { width: 1.1rem; height: 1.1rem; border-radius: 50%; display: block; box-shadow: inset 0 0 0 2px rgb(255 255 255 / 60%); }

/* answer bubbles, optical-form style */
.bubbles { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.bubble-col { display: grid; justify-items: center; gap: .3rem; }
.bubble {
  width: 3.2rem; height: 3.2rem; border-radius: 50%; border: 2px solid var(--line); background: var(--surface);
  font-size: 1.15rem; font-weight: 800; cursor: pointer; transition: transform .1s ease, background .15s ease, border-color .15s ease;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.bubble:hover { border-color: var(--accent); }
.bubble:active { transform: scale(.92); }
.bubble.selected { background: var(--accent); border-color: var(--accent); color: #fff; transform: scale(1.05); }
.bubble.struck { color: var(--muted); background: repeating-linear-gradient(135deg, transparent 0 6px, color-mix(in srgb, var(--muted) 18%, transparent) 6px 8px); text-decoration: line-through; opacity: .7; }
.bubble.correct { background: var(--good); border-color: var(--good); color: #fff; animation: pop .25s ease-out; }
.bubble.wrong { background: var(--bad); border-color: var(--bad); color: #fff; animation: shake .3s ease-out; }
.bubble-strike {
  display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.bubble-strike[aria-pressed="true"] { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.answer-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip-toggle {
  display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .8rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 650; font-size: .9rem;
}
.chip-toggle small { color: var(--muted); font-weight: 500; }
.chip-toggle[aria-pressed="true"] { background: color-mix(in srgb, var(--xp) 16%, transparent); border-color: var(--xp); color: var(--xp); }
.chip-toggle:disabled { opacity: .5; cursor: default; }
.feedback {
  display: flex; align-items: center; gap: .5rem; padding: .8rem 1rem; border-radius: 14px; font-size: 1.05rem;
  animation: pop .25s cubic-bezier(.2, 1.4, .4, 1);
}
.feedback.good { background: var(--good-bg); color: var(--good); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }
.btn .ico { margin-left: .1rem; }

/* solutions and hints */
.hint-box, .solution {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.hint-box { border-color: color-mix(in srgb, var(--xp) 45%, var(--line)); animation: rise .2s ease-out; }
.hint-head { display: flex; align-items: center; gap: .45rem; font-weight: 700; color: var(--xp); margin-bottom: .6rem; }
.solution { display: grid; gap: .8rem; animation: rise .25s ease-out; }
.solution-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.topic-chip {
  display: inline-flex; align-items: center; gap: .3rem; padding: .3rem .7rem; border-radius: 999px; font-size: .85rem;
  font-weight: 750; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
}
.topic-chip:hover { text-decoration: none; }
.topic-path { font-size: .85rem; color: var(--muted); }
.formulas-box {
  border-radius: 14px; padding: .85rem 1rem;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 10%, var(--surface)), color-mix(in srgb, var(--accent-2) 8%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
}
.formulas-box h3 { display: flex; align-items: center; gap: .4rem; font-size: .95rem; color: var(--accent); margin-bottom: .5rem; }
.formulas { list-style: none; margin: 0; padding: 0; display: grid; gap: .65rem; }
.formula { display: grid; gap: .1rem; }
.formula-name { font-size: .72rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.formula-expr { font-family: "STIX Two Math", "Cambria Math", "Latin Modern Math", Georgia, serif; font-size: 1.2rem; line-height: 1.35; }
.formula-when { font-size: .82rem; color: var(--muted); }
.key-idea, .trap { display: flex; gap: .5rem; align-items: flex-start; padding: .6rem .75rem; border-radius: 12px; font-size: .95rem; }
.key-idea { background: color-mix(in srgb, var(--xp) 10%, transparent); }
.key-idea .ico { color: var(--xp); margin-top: .15rem; }
.trap { background: var(--bad-bg); }
.trap .ico { color: var(--bad); margin-top: .15rem; }
.steps { margin: 0; padding-left: 1.3rem; display: grid; gap: .45rem; }
.steps li::marker { color: var(--accent); font-weight: 800; }
.report { display: grid; gap: .5rem; }
.link-btn { display: inline-flex; align-items: center; gap: .35rem; border: 0; background: none; color: var(--muted); cursor: pointer; padding: .3rem 0; font-size: .9rem; }
.link-btn:hover { color: var(--bad); }

/* topic picker, empty states */
.picker h2 { margin-top: 1.2rem; color: var(--muted); font-size: .85rem; letter-spacing: .06em; text-transform: uppercase; }
.topic-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }
.topic-tile {
  display: grid; gap: .35rem; padding: 1rem; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--text);
}
.topic-tile:hover { text-decoration: none; border-color: var(--accent); }
.topic-name { font-weight: 750; }
.meter { display: block; height: .45rem; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter-fill { display: block; height: 100%; transform-origin: left; background: var(--c-say, var(--accent)); }
.empty-state { display: grid; justify-items: center; text-align: center; gap: .5rem; padding: 2.2rem 1rem; }
.empty-state > .ico { color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.skeleton { min-height: 320px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }

@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (max-width: 480px) {
  .sketch-tools { gap: .15rem; padding: .3rem; width: 100%; justify-content: space-between; }
  .tool { min-width: 2.35rem; padding: 0 .45rem; }
}

/* ---------- chart tokens (validated: dataviz validate_palette, light + dark, CVD ΔE 15.2) ---------- */
:root { --c-correct: #0e9f8e; --c-wrong: #e8590c; --c-blank: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- mock runner ---------- */
.mock-bar {
  position: sticky; top: 3.6rem; z-index: 20; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .55rem .7rem; margin: 0 0 .8rem; border-radius: 14px; background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line); box-shadow: var(--shadow); backdrop-filter: blur(8px);
}
.mock-bar h1 { font-size: 1rem; margin: 0; }
.mock-pos { color: var(--muted); font-size: .85rem; flex: 1; min-width: 8rem; }
.mock-timer {
  display: inline-flex; align-items: center; gap: .3rem; font-weight: 800; font-variant-numeric: tabular-nums;
  padding: .3rem .7rem; border-radius: 999px; background: var(--surface-2);
}
.mock-timer.low { color: #fff; background: var(--bad); animation: pulse 1s ease-in-out infinite alternate; }
.btn.danger-outline { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); color: var(--bad); min-height: 2.3rem; }
.banner { display: flex; align-items: center; gap: .5rem; padding: .55rem .8rem; border-radius: 12px; margin-bottom: .8rem; font-size: .9rem; }
.banner.warn { background: color-mix(in srgb, var(--xp) 16%, transparent); color: var(--xp); }
.mock-grid { display: grid; gap: var(--gutter); }
@media (min-width: 1024px) { .mock-grid { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; } }
.mock-answer { display: grid; gap: .8rem; margin-top: .8rem; }
.mock-nav { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .5rem; }
.mock-nav .btn.flag-on { color: var(--xp); border-color: var(--xp); background: color-mix(in srgb, var(--xp) 12%, transparent); }
.sheet-toggle { justify-self: center; }
.mock-side {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .8rem; max-height: calc(100dvh - 9rem); overflow: auto;
}
.mock-side-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.mock-side-head .muted { flex: 1; }
.sheet-close { display: none; width: 2.2rem; height: 2.2rem; }
@media (min-width: 1024px) {
  .mock-side { position: sticky; top: 8.6rem; }
  .sheet-toggle { display: none; }
}
@media (max-width: 1023px) {
  .mock-side {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-height: 75dvh; border-radius: 20px 20px 0 0;
    transform: translateY(105%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
    padding-bottom: max(.8rem, env(safe-area-inset-bottom));
  }
  .mock-side.open { transform: none; }
  .sheet-close { display: inline-grid; }
}

/* optical form */
.optical { display: grid; gap: .8rem; }
.optical-head { font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: .3rem; }
.optical-rows { display: grid; gap: 2px; }
.nav-cell {
  display: grid; grid-template-columns: 2rem 1fr .7rem; align-items: center; gap: .4rem; padding: .2rem .35rem;
  border: 1px solid transparent; border-radius: 8px; background: none; cursor: pointer; text-align: left;
}
.nav-cell:hover { background: var(--surface-2); }
.nav-cell.current { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.nav-num { font-size: .8rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.nav-dots { display: flex; gap: .25rem; }
.nav-dot {
  width: 1.3rem; height: 1.3rem; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center;
  font-size: .62rem; font-weight: 700; color: var(--muted);
}
.nav-dot.filled { background: var(--text); border-color: var(--text); color: var(--surface); }
.nav-flag { width: .55rem; height: .55rem; border-radius: 2px; }
.nav-cell.flagged .nav-flag { background: var(--xp); }

/* dialog */
.dialog-backdrop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 1rem; background: rgb(10 10 30 / 50%); animation: fade .15s ease-out; }
.dialog { width: min(100%, 420px); background: var(--surface); border-radius: 20px; padding: 1.4rem; box-shadow: var(--shadow); animation: pop .2s ease-out; }
.dialog .row { justify-content: flex-end; margin-top: 1rem; }

/* exams list */
.exam-list { display: grid; gap: .6rem; margin-top: .8rem; }
.exam-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.exam-name { font-weight: 750; }

/* ---------- results ---------- */
.result { display: grid; gap: var(--gutter); }
.result > .grid2 { margin-top: 0; }
.hero-result-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.xp-chip { font-weight: 800; color: var(--xp); background: color-mix(in srgb, var(--xp) 14%, transparent); padding: .25rem .6rem; border-radius: 999px; }
.estimate { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin: .6rem 0 .4rem; }
.est-tile { display: grid; justify-items: center; padding: .8rem .4rem; border-radius: 14px; background: var(--surface-2); }
.est-label { font-size: .75rem; font-weight: 800; letter-spacing: .08em; color: var(--muted); }
.est-num { font-size: 2rem; font-weight: 850; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.est-note { margin: 0; }
.section-tile .tile-label { font-size: .8rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.net { font-size: 2.4rem; font-weight: 850; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.net small { font-size: .9rem; color: var(--muted); font-weight: 650; }
.dyb { display: flex; flex-wrap: wrap; gap: .8rem; color: var(--muted); font-size: .9rem; }
.dyb span { display: inline-flex; align-items: center; gap: .25rem; }
.coach { display: flex; gap: .7rem; align-items: flex-start; border-color: color-mix(in srgb, var(--xp) 45%, var(--line)); }
.coach .ico { color: var(--xp); margin-top: .1rem; }
.coach p { margin: 0; }

/* charts */
.legend { display: flex; flex-wrap: wrap; gap: .9rem; margin-bottom: .7rem; font-size: .82rem; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: .3rem; }
.sw { width: .85rem; height: .85rem; border-radius: 3px; display: inline-block; }
.sw-correct { background: var(--c-correct); }
.sw-wrong { background: var(--c-wrong); }
.sw-blank { border: 1.5px dashed var(--c-blank); }
.obars { display: grid; gap: .55rem; }
.obar-row { display: grid; grid-template-columns: minmax(6rem, 9rem) 1fr auto; align-items: center; gap: .7rem; }
.obar-label { font-size: .88rem; }
.obar-track { display: flex; gap: 2px; height: 1.1rem; }
.seg { height: 100%; min-width: 4px; }
.seg:first-child { border-radius: 4px 0 0 4px; }
.seg:last-child { border-radius: 0 4px 4px 0; }
.seg:only-child { border-radius: 4px; }
.seg-correct { background: var(--c-correct); }
.seg-wrong { background: var(--c-wrong); }
.seg-blank { border: 1.5px dashed var(--c-blank); }
.obar-nums { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.obar-nums b { color: var(--text); }
.timestrip { margin: 0; }
.timestrip svg { width: 100%; height: 140px; display: block; }
.tb-correct { fill: var(--c-correct); }
.tb-wrong { fill: var(--c-wrong); }
.tb-blank { fill: none; stroke: var(--c-blank); stroke-width: 1.5; stroke-dasharray: 3 2; vector-effect: non-scaling-stroke; }
.pace { stroke: var(--text); stroke-width: 1.5; stroke-dasharray: 6 4; opacity: .55; vector-effect: non-scaling-stroke; }

/* review list */
.review-head-row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; margin-bottom: .6rem; }
.seg-control { display: inline-flex; padding: .2rem; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.seg-control button { border: 0; background: none; padding: .4rem .8rem; border-radius: 9px; cursor: pointer; font-weight: 650; font-size: .88rem; color: var(--muted); }
.seg-control button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.review-list { display: grid; gap: .45rem; }
.review-item { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.review-head { display: flex; align-items: center; gap: .6rem; width: 100%; padding: .6rem .7rem; border: 0; background: var(--surface); cursor: pointer; text-align: left; }
.review-head:hover { background: var(--surface-2); }
.ri-badge { display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; flex: none; color: #fff; }
.ri-correct .ri-badge { background: var(--c-correct); }
.ri-wrong .ri-badge { background: var(--c-wrong); }
.ri-blank .ri-badge { border: 1.5px dashed var(--c-blank); }
.ri-text { flex: 1; font-size: .9rem; }
.ri-time { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.review-body { display: grid; gap: .8rem; padding: .8rem; background: var(--bg-2); }

@keyframes pulse { to { opacity: .75; } }

/* ---------- stats ---------- */
:root { --c-say: #6d4aff; --c-soz: #0e9fb8; }
.stats-page, .admin, .admin-user, .formulas-page { display: grid; gap: var(--gutter); }
.stats-page > .grid2, .admin > .grid2, .admin-user > .grid2 { margin-top: 0; }
.stat-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
@media (min-width: 768px) { .stat-tiles { grid-template-columns: repeat(4, 1fr); } }
.stat { display: grid; gap: .2rem; }
.stat-label { font-size: .75rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.stat-num { font-size: 1.8rem; font-weight: 850; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.topic-table { display: grid; gap: 2px; font-size: .9rem; }
.tt-row { display: grid; grid-template-columns: minmax(7rem, 1.4fr) 3rem 4.6rem minmax(5rem, 1fr) minmax(6rem, 1.2fr); gap: .6rem; align-items: center; padding: .35rem .2rem; }
.tt-head { font-size: .72rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.tt-section { padding: .7rem .2rem .2rem; font-size: .78rem; font-weight: 800; color: var(--accent); letter-spacing: .05em; text-transform: uppercase; }
.tt-num { font-variant-numeric: tabular-nums; color: var(--muted); }
.tt-acc { text-align: center; border-radius: 8px; padding: .25rem 0; font-weight: 750; font-variant-numeric: tabular-nums; color: var(--muted); }
.tt-acc.has { background: color-mix(in srgb, var(--c-say) var(--shade), var(--surface)); color: var(--text); }
.tt-mastery, .tt-time { display: grid; grid-template-columns: 1fr auto; gap: .4rem; align-items: center; }
.time-track { position: relative; height: .5rem; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.time-fill { position: absolute; inset: 0; transform-origin: left; background: var(--c-soz); }
.time-fill.slow { background: var(--c-wrong); }
.time-pace { position: absolute; top: -2px; bottom: -2px; left: 50%; width: 2px; background: var(--text); opacity: .5; }
@media (max-width: 640px) {
  .tt-row { grid-template-columns: 1fr 2.4rem 3.8rem; }
  .tt-mastery, .tt-time, .tt-head span:nth-child(n+4) { display: none; }
}
.trend { margin: 0; }
.trend svg { width: 100%; height: auto; display: block; }
.trend .grid { stroke: var(--line); stroke-width: 1; }
.trend .axis { font-size: 11px; fill: var(--muted); }
.trend-line { fill: none; stroke: var(--c-say); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.trend-dot { fill: var(--c-say); stroke: var(--surface); stroke-width: 2; }
.trend-label { font-size: 13px; font-weight: 800; fill: var(--text); }
.daily-bars { margin: 0; }
.daily-bars svg { width: 100%; height: 120px; display: block; }
.db-bar { fill: color-mix(in srgb, var(--c-say) 45%, var(--surface)); }
.db-bar.met { fill: var(--c-say); }
.db-bar.today { stroke: var(--text); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.daily-bars .goal { stroke: var(--text); stroke-width: 1.5; stroke-dasharray: 6 4; opacity: .5; vector-effect: non-scaling-stroke; }

/* ---------- formulas page ---------- */
.formulas-layout { display: grid; gap: var(--gutter); }
.topic-index { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .2rem; scrollbar-width: thin; }
.topic-index a {
  flex: none; padding: .4rem .8rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  color: var(--text); font-size: .88rem; font-weight: 650;
}
.topic-index a:hover { text-decoration: none; border-color: var(--accent); }
@media (min-width: 1024px) {
  .formulas-layout { grid-template-columns: 210px minmax(0, 1fr); align-items: start; }
  .topic-index { position: sticky; top: 5rem; flex-direction: column; overflow: visible; }
  .topic-index a { border-radius: 10px; }
}
.formula-topics { display: grid; gap: var(--gutter); }
.formula-topic { scroll-margin-top: 5rem; display: grid; gap: .8rem; }
.ft-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap; }
.ft-head h2 { margin: 0; }
.ft-sub h3 { font-size: .9rem; color: var(--accent); margin-bottom: .5rem; }
.ft-sub .formula { padding: .6rem .8rem; border-radius: 12px; background: var(--surface-2); }
.formula-example { font-size: .85rem; color: var(--text); opacity: .85; border-left: 3px solid var(--c-soz); padding-left: .5rem; margin-top: .2rem; }

/* ---------- admin ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th { text-align: left; font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 800; padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
table.data td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr.disabled td { opacity: .5; }
table.data.compact td { padding: .35rem .5rem; }
.th-sort { border: 0; background: none; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; padding: 0; }
.th-sort[aria-pressed="true"] { color: var(--accent); }
.seg-control button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.invite { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-top: .9rem; }
.invite label { display: grid; gap: .3rem; }
.invite select { width: auto; }
.invite-out { display: flex; gap: .5rem; margin-top: .7rem; }
.invite-out input { font-family: var(--mono); font-size: .8rem; }
.report-list, .activity { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.report-list li { display: grid; gap: .15rem; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.activity { max-height: 420px; overflow: auto; }
.activity li { display: grid; grid-template-columns: 6.5rem 4.5rem 1fr; gap: .5rem; font-size: .9rem; align-items: baseline; }
.act-kind { font-size: .75rem; font-weight: 700; color: var(--accent); }
.row.start { justify-content: flex-start; margin-bottom: .8rem; }
.admin-user label { display: grid; gap: .3rem; margin-bottom: .6rem; }
.sample-grid { display: grid; gap: var(--gutter); margin-top: .9rem; }
@media (min-width: 1024px) { .sample-grid { grid-template-columns: 1fr 1fr; } }
.sample { display: grid; gap: .6rem; }
.sample-meta { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .9rem; }
