/* Design notes
   - Lab notebook: cool paper with a faint graph grid; ink-navy text.
   - Chapter colours are flame-test colours: Ch1 sodium (yellow), Ch2 copper (blue-green), Ch3 potassium (lilac).
     They appear only where they encode chapter — mastery bars, tiles, chips.
   - The periodic-table tile is the one memorable motif (brand + quiz progress strip). */
:root {
  --paper: #f3f6f5;
  --grid: rgba(40, 90, 110, 0.07);
  --surface: #ffffff;
  --ink: #16212b;
  --muted: #56636e;
  --line: #cfd8d6;
  --ch1: #b58400;
  --ch1-soft: #fbf1cf;
  --ch2: #147a6c;
  --ch2-soft: #d8f0eb;
  --ch3: #7552ad;
  --ch3-soft: #ebe3f7;
  --good: #1f7a45;
  --good-soft: #e1f3e8;
  --bad: #b3372b;
  --bad-soft: #fbe6e3;
  --focus: #1b64d1;
  --radius-s: 6px;
  --radius-m: 10px;
  --font-body: 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif;
  --font-display: 'Bricolage Grotesque', 'Atkinson Hyperlegible', 'Segoe UI', sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141c22; --grid: rgba(140, 200, 220, 0.05); --surface: #1c262e; --ink: #e6edf0; --muted: #9eadb7;
    --line: #33424c; --ch1: #e6b93a; --ch1-soft: #3a3118; --ch2: #4cc3ad; --ch2-soft: #16362f; --ch3: #b69ae6;
    --ch3-soft: #2f2544; --good: #5ccf8b; --good-soft: #173526; --bad: #ff8a7d; --bad-soft: #402220; --focus: #7fb0ff;
  }
}
:root[data-theme="dark"] {
  --paper: #141c22; --grid: rgba(140, 200, 220, 0.05); --surface: #1c262e; --ink: #e6edf0; --muted: #9eadb7;
  --line: #33424c; --ch1: #e6b93a; --ch1-soft: #3a3118; --ch2: #4cc3ad; --ch2-soft: #16362f; --ch3: #b69ae6;
  --ch3-soft: #2f2544; --good: #5ccf8b; --good-soft: #173526; --bad: #ff8a7d; --bad-soft: #402220; --focus: #7fb0ff;
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--ink);
  font: 17px/1.6 var(--font-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--ch2); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: 1rem; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; letter-spacing: -0.01em; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.8rem, 4.5vw, 2.6rem); font-weight: 800; }
h2 { font-size: 1.35rem; font-weight: 700; margin-top: 2rem; }
h3 { font-size: 1.08rem; font-weight: 700; }
p { margin: .4rem 0 .8rem; max-width: 68ch; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 1.2rem; padding: .6rem clamp(.8rem, 3vw, 2rem);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .7rem; text-decoration: none; color: inherit; }
.tile {
  width: 52px; height: 58px; border: 2px solid var(--ink); border-radius: 4px; background: var(--surface);
  display: grid; grid-template-rows: auto 1fr auto; padding: 2px 4px; font-family: var(--font-display); line-height: 1;
}
.tile-z { font-size: .62rem; font-weight: 700; }
.tile-sym { font-size: 1.35rem; font-weight: 800; align-self: center; text-align: center; }
.tile-name { font-size: .52rem; text-align: center; }
.brand-title { display: block; font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; }
.brand-sub { display: block; font-size: .8rem; color: var(--muted); }
.tabs { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; margin-left: auto; max-width: 100%; }
.tabs a {
  text-decoration: none; color: var(--muted); padding: .4rem .7rem; border-radius: var(--radius-s);
  white-space: nowrap; font-weight: 700; font-size: .95rem;
}
.tabs a:hover { color: var(--ink); background: var(--surface); }
.tabs a[aria-current="page"] { color: var(--ink); background: var(--surface); box-shadow: inset 0 -3px 0 var(--ink); }
@media (max-width: 720px) { .tabs { margin-left: 0; width: 100%; } }

main { flex: 1; width: 100%; max-width: 880px; margin: 0 auto; padding: 1.6rem clamp(.9rem, 3vw, 1.6rem) 3rem; outline: none; }
.foot {
  display: flex; gap: 1.2rem; justify-content: center; flex-wrap: wrap;
  padding: 1rem; font-size: .85rem; color: var(--muted); border-top: 1px solid var(--line);
}
.foot a { color: var(--muted); }

/* ---------- Building blocks ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1.1rem 1.25rem; margin: 1rem 0; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: baseline; }
.btn {
  font: inherit; font-weight: 700; cursor: pointer; border-radius: var(--radius-s);
  border: 2px solid var(--ink); background: var(--ink); color: var(--paper); padding: .5rem 1rem; line-height: 1.3;
}
.btn:hover { filter: brightness(1.15); }
.btn.secondary { background: transparent; color: var(--ink); }
.btn.quiet { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 400; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: .25rem .6rem; font-size: .88rem; }
label.field { display: grid; gap: .25rem; font-weight: 700; font-size: .92rem; }
select, input[type="text"], input[type="password"], textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1.5px solid var(--line);
  border-radius: var(--radius-s); padding: .45rem .6rem; min-width: 0;
}
textarea { width: 100%; resize: vertical; }
.segmented { display: inline-flex; flex-wrap: wrap; border: 1.5px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.segmented button {
  font: inherit; background: var(--surface); color: var(--muted); border: 0; border-right: 1.5px solid var(--line);
  padding: .45rem .8rem; cursor: pointer; font-weight: 700;
}
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin: 1rem 0; }
.notice { border-left: 4px solid var(--ch2); background: var(--ch2-soft); padding: .7rem 1rem; border-radius: 0 var(--radius-s) var(--radius-s) 0; margin: 1rem 0; }
.notice.warn { border-color: var(--ch1); background: var(--ch1-soft); }
.chip { display: inline-block; font-size: .78rem; font-weight: 700; padding: .05rem .5rem; border-radius: 99px; border: 1.5px solid currentColor; }
.ch1 { --c: var(--ch1); --c-soft: var(--ch1-soft); }
.ch2 { --c: var(--ch2); --c-soft: var(--ch2-soft); }
.ch3 { --c: var(--ch3); --c-soft: var(--ch3-soft); }
.chip.ch1, .chip.ch2, .chip.ch3 { color: var(--c); }

/* ---------- Progress / home ---------- */
.readiness { display: grid; grid-template-columns: auto 1fr; gap: 1.4rem; align-items: center; }
.readiness-num { font-family: var(--font-display); font-weight: 800; font-size: clamp(3.2rem, 11vw, 5.5rem); line-height: .9; }
.readiness-num small { font-size: .4em; }
.stats { display: flex; gap: 1.6rem; flex-wrap: wrap; margin-top: .4rem; }
.stats div { font-size: .9rem; color: var(--muted); }
.stats b { display: block; color: var(--ink); font-size: 1.25rem; font-family: var(--font-display); }
.chapter-block { margin-top: 1.6rem; }
.chapter-block h2 { display: flex; align-items: center; gap: .6rem; margin-top: 0; }
.chapter-block h2::before { content: ''; width: 14px; height: 14px; border-radius: 3px; background: var(--c); flex: none; }
.topic-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 140px auto; gap: .8rem; align-items: center;
  padding: .45rem 0; border-bottom: 1px dashed var(--line);
}
.topic-row .name { min-width: 0; }
.topic-row .level { font-size: .78rem; color: var(--muted); }
.bar { height: 10px; background: var(--c-soft); border-radius: 99px; overflow: hidden; border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); }
.bar span { display: block; height: 100%; background: var(--c); border-radius: 99px; }
@media (max-width: 560px) {
  .topic-row { grid-template-columns: 1fr auto; }
  .topic-row .bar { grid-column: 1 / -1; grid-row: 2; }
  .readiness { grid-template-columns: 1fr; gap: .6rem; }
}

/* ---------- Quiz ---------- */
.strip { display: flex; gap: 4px; flex-wrap: wrap; margin: .2rem 0 1rem; }
.strip .cell {
  width: 30px; height: 34px; border: 1.5px solid var(--line); border-radius: 3px; background: var(--surface);
  display: grid; place-items: center; font-family: var(--font-display); font-size: .8rem; font-weight: 700; color: var(--muted);
  border-top: 4px solid var(--c, var(--line));
}
.strip .cell.current { border-color: var(--ink); color: var(--ink); border-top-color: var(--c); }
.strip .cell.right { background: var(--good-soft); color: var(--good); }
.strip .cell.wrong { background: var(--bad-soft); color: var(--bad); }
.strip .cell.done { background: var(--paper); color: var(--ink); }
.qmeta { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .4rem; font-size: .88rem; color: var(--muted); }
.stem { font-size: 1.22rem; font-weight: 700; margin: .4rem 0 1rem; max-width: 60ch; }
.options { display: grid; gap: .55rem; }
.option {
  display: grid; grid-template-columns: 2rem 1fr; gap: .6rem; align-items: start; text-align: left;
  font: inherit; color: inherit; background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-m);
  padding: .65rem .85rem; cursor: pointer;
}
.option:hover:not(:disabled) { border-color: var(--ink); }
.option .key {
  width: 1.7rem; height: 1.7rem; border-radius: 4px; border: 1.5px solid var(--line); display: grid; place-items: center;
  font-weight: 700; font-size: .85rem; color: var(--muted);
}
.option:disabled { cursor: default; }
.option.is-correct { border-color: var(--good); background: var(--good-soft); }
.option.is-correct .key { border-color: var(--good); color: var(--good); }
.option.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.is-wrong .key { border-color: var(--bad); color: var(--bad); }
.option.is-picked { border-color: var(--ink); }
.option .why { display: block; font-size: .93rem; color: var(--muted); margin-top: .25rem; }
.feedback { margin-top: 1rem; border-radius: var(--radius-m); padding: 1rem 1.15rem; border: 1.5px solid var(--line); background: var(--surface); }
.feedback.good { border-color: var(--good); }
.feedback.bad { border-color: var(--bad); }
.verdict { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; margin: 0 0 .3rem; }
.feedback.good .verdict { color: var(--good); }
.feedback.bad .verdict { color: var(--bad); }
.tip { margin-top: .8rem; padding: .6rem .8rem; border-radius: var(--radius-s); background: var(--ch1-soft); }
.tip b { margin-right: .3rem; }
details.others { margin-top: .8rem; }
details.others summary { cursor: pointer; font-weight: 700; }
details.others ul { padding-left: 1.2rem; margin: .5rem 0 0; }
details.others li { margin: .35rem 0; }
@media (prefers-reduced-motion: no-preference) {
  .feedback { animation: reveal .22s ease-out; }
  @keyframes reveal { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
.score-big { font-family: var(--font-display); font-weight: 800; font-size: clamp(2.8rem, 9vw, 4.2rem); line-height: 1; }
table.breakdown { border-collapse: collapse; width: 100%; font-size: .95rem; }
table.breakdown th, table.breakdown td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
.review-item { border-top: 1px solid var(--line); padding: .9rem 0; }
.timer { font-family: var(--font-display); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Flashcards ---------- */
.deck-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .8rem; margin-top: 1rem; }
.deck {
  text-align: left; font: inherit; color: inherit; background: var(--surface); border: 1.5px solid var(--line);
  border-top: 5px solid var(--c); border-radius: var(--radius-m); padding: .8rem 1rem; cursor: pointer; display: grid; gap: .3rem;
}
.deck:hover { border-color: var(--ink); border-top-color: var(--c); }
.boxes { display: flex; gap: 3px; }
.boxes span { flex: 1; height: 6px; border-radius: 2px; background: var(--line); }
.boxes span.on { background: var(--c); }
.card-stage { perspective: 1200px; margin: 1rem 0; }
.flashcard {
  position: relative; width: 100%; min-height: 230px; border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer;
  transform-style: preserve-3d; transition: transform .45s ease;
}
.flashcard.flipped { transform: rotateY(180deg); }
@media (prefers-reduced-motion: reduce) { .flashcard { transition: none; } }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; background: var(--surface); border: 2px solid var(--ink);
  border-radius: var(--radius-m); display: grid; place-items: center; padding: 1.4rem; text-align: center;
}
.face.back { transform: rotateY(180deg); background: var(--c-soft); }
.face .label { position: absolute; top: .6rem; left: .9rem; font-size: .8rem; color: var(--muted); }
.face .big { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.6rem, 6vw, 2.6rem); line-height: 1.15; }
.face .big.long { font-size: clamp(1.05rem, 3.4vw, 1.35rem); font-weight: 700; }

/* ---------- Drills ---------- */
.drill-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .5rem; margin: 1rem 0; }
.drill-pick { text-align: left; font: inherit; color: inherit; background: var(--surface); border: 1.5px solid var(--line); border-left: 5px solid var(--c); border-radius: var(--radius-s); padding: .5rem .8rem; cursor: pointer; }
.drill-pick:hover { border-color: var(--ink); border-left-color: var(--c); }
.answer-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.answer-row input { flex: 1 1 220px; font-size: 1.1rem; }

/* ---------- Assistant ---------- */
.chat { display: grid; gap: .8rem; margin: 1rem 0; }
.msg { max-width: 92%; padding: .7rem 1rem; border-radius: var(--radius-m); border: 1.5px solid var(--line); background: var(--surface); }
.msg.user { justify-self: end; background: var(--ch2-soft); border-color: color-mix(in srgb, var(--ch2) 40%, transparent); }
.msg p { margin: .3rem 0; }
.msg ul { margin: .3rem 0; padding-left: 1.2rem; }
.msg.pending { color: var(--muted); font-style: italic; }
.composer { display: grid; gap: .5rem; }
.composer .row { justify-content: space-between; }
.quick { display: flex; gap: .4rem; flex-wrap: wrap; margin: .6rem 0; }

/* ---------- Notes ---------- */
.note-topic { border-top: 1px solid var(--line); padding: .9rem 0; }
.note-topic ul { padding-left: 1.2rem; margin: .3rem 0 .6rem; }
.note-topic li { margin: .25rem 0; max-width: 70ch; }
.search { width: 100%; font-size: 1.05rem; }
@media (max-width: 720px) { .topbar { position: static; backdrop-filter: none; } }

/* ---------- Exam simulator ---------- */
.exam-part { margin-top: .5rem; }
.exam-q { border-top: 1px solid var(--line); padding: 1.1rem 0; }
.exam-q h3 { margin-bottom: .3rem; }
.qnum { font-family: var(--font-display); font-weight: 800; margin-right: .25rem; }
.table-wrap { overflow-x: auto; margin: .6rem 0; }
table.exam-table { border-collapse: collapse; min-width: 100%; background: var(--surface); font-size: .95rem; }
.exam-table th, .exam-table td { border: 1.5px solid var(--line); padding: .35rem .5rem; text-align: left; vertical-align: top; }
.exam-table th { background: var(--paper); font-weight: 700; }
input.blank {
  width: 100%; min-width: 5.5rem; font: inherit; color: var(--ink); background: var(--ch2-soft);
  border: 0; border-bottom: 2px solid var(--ch2); border-radius: 4px 4px 0 0; padding: .3rem .4rem;
}
input.blank.inline { width: 11rem; display: inline-block; margin: 0 .25rem; }
ol.fillins { padding-left: 1.4rem; }
ol.fillins li { margin: .55rem 0; line-height: 2.1; }
.fr-parts { display: grid; gap: .9rem; margin-top: .8rem; }
.fr-part label { display: block; margin-bottom: .3rem; }
.fr-part .answer-row input { flex: 0 1 18rem; font-size: 1rem; }
.unit { align-self: center; color: var(--muted); font-weight: 700; }
.mark { font-weight: 700; padding: .05rem .35rem; border-radius: 4px; white-space: nowrap; }
.mark.ok { color: var(--good); background: var(--good-soft); }
.mark.bad { color: var(--bad); background: var(--bad-soft); }
.keyans { display: block; font-size: .85rem; font-weight: 700; color: var(--good); margin-top: .15rem; }
.keyans::before { content: 'Key: '; font-weight: 400; color: var(--muted); }
pre.work-shown { white-space: pre-wrap; font: inherit; background: var(--paper); border: 1px dashed var(--line); padding: .6rem .8rem; border-radius: var(--radius-s); }
.timer.urgent { color: var(--bad); }

@media print {
  body { background: #fff; color: #000; font-size: 12pt; }
  .topbar, .foot, .no-print, .skip { display: none !important; }
  .exam-part[hidden] { display: block !important; }
  main { max-width: none; padding: 0; }
  .option { border: 1px solid #999; break-inside: avoid; }
  .exam-q { break-inside: avoid; }
  input.blank { background: none; border-bottom: 1px solid #000; }
  textarea { border: 1px solid #999; min-height: 8rem; }
}
ol.fillins .keyans { display: inline; margin-left: .35rem; }
