:root {
  color-scheme: light;
  --bg: #F4F6FA;
  --grid: #E3E8F1;
  --card: #FFFFFF;
  --ink: #0F1B33;
  --muted: #5A6680;
  --line: #D8DEE9;
  --accent: #2F5BEA;
  --accent-ink: #FFFFFF;
  --accent-soft: #E7EDFF;
  --good: #11845B;
  --good-soft: #E2F5EC;
  --warn: #A35C00;
  --warn-soft: #FFF1DC;
  --bad: #C0362C;
  --bad-soft: #FDE8E6;
  --shadow: 0 1px 2px rgba(15, 27, 51, .06), 0 4px 16px rgba(15, 27, 51, .06);
  --radius: 14px;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --sans: "Space Grotesk", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0B1120; --grid: #141C2E; --card: #121A2B; --ink: #E7ECF6; --muted: #98A3BA; --line: #26314A;
    --accent: #6F8DFF; --accent-ink: #0B1120; --accent-soft: #1B2647; --good: #4ACB94; --good-soft: #10291F;
    --warn: #F2B35B; --warn-soft: #2D2111; --bad: #FF7D72; --bad-soft: #321614; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B1120; --grid: #141C2E; --card: #121A2B; --ink: #E7ECF6; --muted: #98A3BA; --line: #26314A;
  --accent: #6F8DFF; --accent-ink: #0B1120; --accent-soft: #1B2647; --good: #4ACB94; --good-soft: #10291F;
  --warn: #F2B35B; --warn-soft: #2D2111; --bad: #FF7D72; --bad-soft: #321614; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); background-color: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px; background-position: -1px -1px;
  font: 16px/1.55 var(--sans);
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---- Top bar ---- */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1120px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 16px; }
.logo { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 20px; letter-spacing: -.02em; }
.logo-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--ink); color: var(--bg); display: grid; place-items: center; font: 600 15px var(--mono); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); min-width: 0; }
.top-right .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 32px 16px 64px; }
.narrow { max-width: 760px; }

/* ---- Bits ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 24px; }
.eyebrow { font: 500 12px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin: 0 0 10px; }
h1 { font-size: clamp(32px, 5vw, 48px); line-height: 1.05; letter-spacing: -.03em; margin: 0 0 14px; }
h2 { font-size: 22px; line-height: 1.2; letter-spacing: -.01em; margin: 0 0 6px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-weight: 600;
  cursor: pointer; text-decoration: none; transition: transform .12s, background .12s, border-color .12s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--bad); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; text-decoration: underline; }

.field { margin-top: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); outline: none;
}
.input:focus { border-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.error { color: var(--bad); font-size: 14px; min-height: 20px; margin: 12px 0 0; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font: 500 12px/1.5 var(--mono); background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.dim { background: var(--grid); color: var(--muted); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--grid); margin-bottom: 18px; }
.tab { min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px); }

.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Home ---- */
.hero { display: grid; grid-template-columns: 1.1fr 420px; gap: 56px; align-items: center; min-height: calc(100vh - 160px); }
.hero p.lede { font-size: 18px; color: var(--muted); max-width: 480px; margin: 0; }
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; margin-top: 24px; }
.project { display: flex; flex-direction: column; gap: 10px; padding: 22px; text-decoration: none; color: inherit; transition: transform .15s, border-color .15s; }
a.project:hover { transform: translateY(-2px); border-color: var(--accent); }
.project .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.project .tag { font: 500 12px var(--mono); color: var(--muted); }
.project.soon { border-style: dashed; background: transparent; box-shadow: none; color: var(--muted); }

/* ---- Quiz ---- */
.quiz-layout { display: grid; grid-template-columns: 1fr 230px; gap: 24px; align-items: start; }
.progress { height: 6px; border-radius: 6px; background: var(--grid); overflow: hidden; margin: 0 0 20px; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .25s; }
.qhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.prompt { font-size: 20px; line-height: 1.5; margin: 0 0 22px; }
.choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 10px 14px; text-align: left;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--card); cursor: pointer; font-size: 17px; transition: border-color .12s, background .12s;
}
.choice:hover { border-color: var(--muted); }
.choice .letter { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font: 600 14px var(--mono); background: var(--grid); color: var(--muted); }
.choice[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.choice[aria-checked="true"] .letter { background: var(--accent); color: var(--accent-ink); }
.choice.unsure { min-height: 44px; font-size: 15px; color: var(--muted); border-style: dashed; }
.qnav { display: flex; justify-content: space-between; gap: 10px; margin-top: 24px; }
.qmap { position: sticky; top: 80px; padding: 18px; }
.qmap-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 12px 0 16px; }
.qdot { aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); font: 500 13px var(--mono); cursor: pointer; color: var(--muted); padding: 0; }
.qdot.done { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.qdot.unsure { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.qdot.here { outline: 2px solid var(--accent); outline-offset: 1px; }
.saved { font: 12px var(--mono); color: var(--muted); }

.rules { margin: 18px 0 22px; padding: 0; list-style: none; display: grid; gap: 10px; }
.rules li { display: flex; gap: 12px; align-items: flex-start; }
.rules li b { flex: none; width: 26px; height: 26px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font: 600 13px var(--mono); }
.score-big { font: 600 64px/1 var(--mono); letter-spacing: -.04em; margin: 8px 0; }

/* Tutor */
.tutor-fab { position: fixed; right: 20px; bottom: 20px; z-index: 20; box-shadow: var(--shadow); }
.tutor { position: fixed; right: 20px; bottom: 20px; width: min(400px, calc(100% - 32px)); height: min(560px, calc(100vh - 100px)); z-index: 30; display: flex; flex-direction: column; overflow: hidden; }
.tutor-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.tutor-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: 15px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--grid); border-bottom-left-radius: 4px; }
.tutor-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.tutor-form .input { min-height: 42px; }

/* ---- Admin ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 20px 0; }
.stat { padding: 16px 18px; }
.stat .v { font: 600 30px/1.1 var(--mono); letter-spacing: -.03em; }
.stat .k { font-size: 13px; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar .input { width: auto; min-height: 36px; padding: 6px 10px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { font: 500 12px var(--mono); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--bg); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td .name { font-weight: 600; }
td .email { font-size: 12px; color: var(--muted); }
td select.input { min-height: 32px; padding: 4px 8px; width: auto; }
.bar { height: 8px; border-radius: 8px; background: var(--grid); overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.topic-row { display: grid; grid-template-columns: 160px 1fr 48px; gap: 12px; align-items: center; padding: 6px 0; font-size: 14px; }
.qa-row { display: grid; grid-template-columns: 34px 1fr 60px; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.qa-row:last-child { border-bottom: 0; }
.drawer { position: fixed; inset: 0 0 0 auto; width: min(520px, 100%); z-index: 40; border-radius: 0; display: flex; flex-direction: column; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.scrim { position: fixed; inset: 0; background: rgba(5, 10, 20, .4); z-index: 35; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: 28px; min-height: 0; }
  .quiz-layout { grid-template-columns: 1fr; }
  .qmap { position: static; order: -1; }
  .qmap-grid { grid-template-columns: repeat(10, 1fr); }
  .two { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .wrap { padding-top: 20px; }
  .pad { padding: 18px; }
  .prompt { font-size: 18px; }
  .qmap-grid { grid-template-columns: repeat(5, 1fr); }
  .top-right .who { display: none; }
  .topic-row { grid-template-columns: 110px 1fr 40px; }
}
