:root {
  --paper: #f8f9f4;
  --panel: #fffef9;
  --rail: #f0f3e9;
  --ink: #1b3028;
  --muted: #556459;
  --line: #d5decd;
  --green: #173e31;
  --leaf: #2a5f45;
  --soft: #e5eddb;
  --gold: #edcb8c;
  --error: #944a34;
  --font: "Times New Roman", Times, Georgia, serif;
  --mono: "Times New Roman", Times, Georgia, serif;
  color-scheme: light;
  font-family: var(--font);
  font-size: 16.5px;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; line-height: 1.62; font-family: var(--font); }
a { color: var(--leaf); text-underline-offset: 4px; }
button, input, textarea, select { font-family: var(--font); font-size: inherit; color: inherit; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; background: none; border: 0; }
button:disabled { cursor: default; opacity: .58; }
button:hover:not(:disabled), a:hover { filter: brightness(.9); }
:focus-visible { outline: 3px solid #ba822e; outline-offset: 3px; }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { line-height: 1.25; font-weight: 600; }
h1 { font-size: clamp(2.1rem, 3.4vw, 3.45rem); letter-spacing: -.025em; }
h2 { font-size: 1.65rem; letter-spacing: -.015em; }
h3 { font-size: 1.18rem; }
h4 { font-size: 1.02rem; }
p + p { margin-top: 12px; }
ul, ol { padding-left: 1.45em; }
li + li { margin-top: 7px; }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.skip { position: fixed; left: 16px; top: -70px; z-index: 60; background: #fff; padding: 12px; border: 1px solid var(--line); }
.skip:focus { top: 10px; }

/* Header & top navigation */
.topbar {
  min-height: 76px;
  padding: 12px clamp(18px, 3vw, 48px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: #fdfef9;
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: var(--green); white-space: nowrap; }
.brand strong { font-size: 1.75rem; letter-spacing: -.03em; }
.brand > span { font-size: .92rem; border-left: 1px solid #bcc9b7; padding-left: 12px; color: var(--muted); font-weight: 600; }
.modes { display: flex; flex-wrap: wrap; gap: 3px; background: #edf1e6; padding: 4px; border: 1px solid var(--line); border-radius: 9px; }
.modes a { padding: 6px 14px; font-size: .95rem; white-space: nowrap; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 600; }
.modes a.active { background: var(--green); color: #fff; }
.header-tools { display: flex; gap: 18px; align-items: center; }
.search-button { display: flex; align-items: center; gap: 7px; color: var(--muted); font-weight: 600; }
.search-button > span:first-child { font-size: 1.35rem; line-height: 1; }
.library-link { font-size: .95rem; text-decoration: none; white-space: nowrap; font-weight: 600; }
.library-link.active { text-decoration: underline; text-decoration-thickness: 2px; color: var(--green); }
kbd { font-family: var(--font); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; font-size: .85rem; background: var(--panel); }

/* Sticky Chapter Shortcut Bar */
.chapter-bar-wrap {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #edf1e7;
  border-bottom: 1px solid #c8d3c1;
  color: var(--green);
}
.chapter-bar {
  max-width: 1660px;
  margin: auto;
  padding: 5px clamp(16px, 3vw, 48px);
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 44px;
}
.contents-link {
  font-size: .92rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--green);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.contents-link[aria-current="page"] { text-decoration: underline; text-decoration-thickness: 2px; }
.chapter-shortcuts { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.chapter-shortcuts a {
  border-radius: 5px;
  min-width: 40px;
  padding: 4px 9px;
  text-align: center;
  font-size: .9rem;
  font-weight: 700;
  color: var(--green);
  text-decoration: none;
}
.chapter-shortcuts a:hover { background: #d8e3d0; }
.chapter-shortcuts a[aria-current="page"] { background: var(--green); color: #fff; }
.chapter-bar-right { margin-left: auto; font-size: .88rem; color: var(--muted); white-space: nowrap; }
#chapter-jump { display: none; }

/* Main Layout */
.layout { display: grid; grid-template-columns: 268px minmax(0, 1fr); max-width: 1660px; margin: 0 auto; min-height: calc(100vh - 170px); }
.layout.directory-mode { grid-template-columns: minmax(0, 1fr); }
.layout.directory-mode .rail { display: none; }
.rail { border-right: 1px solid var(--line); padding: 26px 16px 24px 24px; background: var(--rail); }
.rail-content { position: sticky; top: 60px; }
.rail-heading h2 { font-size: 1.55rem; margin: 6px 0; }
.rail-heading p { font-size: .9rem; color: var(--muted); }
.eyebrow { font-size: .82rem; letter-spacing: .1em; text-transform: uppercase; color: var(--leaf); font-weight: 700; display: inline-block; }
.progress-label { display: flex; justify-content: space-between; font-size: .88rem; color: var(--muted); margin-top: 20px; }
.progress-track { height: 5px; background: #d5dec9; margin: 7px 0 18px; border-radius: 3px; overflow: hidden; }
.progress-track > span { display: block; height: 100%; background: #53825b; transition: width .2s; }
.chapter-link { display: flex; gap: 11px; align-items: center; padding: 9px 9px; margin-bottom: 4px; border-radius: 8px; text-decoration: none; color: var(--ink); min-height: 56px; }
.chapter-link.active { background: #dde8d2; }
.chapter-link:hover { background: #e5ecdf; }
.chapter-number { width: 32px; height: 32px; border: 1px solid #b5c5aa; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: .84rem; font-weight: 700; }
.chapter-link.active .chapter-number { background: var(--green); color: #fff; border-color: var(--green); }
.chapter-label { font-size: .95rem; line-height: 1.35; font-weight: 600; }
.chapter-label small { display: block; font-size: .82rem; color: var(--muted); font-weight: 400; margin-top: 2px; }
.rail-bottom { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.rail-bottom > a, .rail-bottom > button { display: block; font-size: .93rem; text-decoration: none; padding: 5px 0; color: var(--leaf); font-weight: 600; text-align: left; }
.rail-bottom p { font-size: .82rem; color: var(--muted); line-height: 1.5; margin-top: 8px; }
.mobile-menu { display: none; }
main { min-width: 0; padding: 34px clamp(22px, 3.6vw, 58px) 58px; outline: none; }

/* Directory Home Page */
.directory-wrap { max-width: 1220px; margin: 0 auto; }
.directory-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; padding-bottom: 28px; border-bottom: 2px solid var(--green); }
.directory-intro h1 { margin: 8px 0 10px; }
.directory-intro p { color: var(--muted); max-width: 60ch; }
.directory-stats { display: grid; grid-template-columns: repeat(3, auto); gap: 4px 22px; border-left: 1px solid #b5c4ae; padding-left: 24px; flex-shrink: 0; }
.directory-stats b { font-size: 2rem; line-height: 1.1; color: var(--green); }
.directory-stats span { font-size: .84rem; color: var(--muted); display: block; }
.directory-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: clamp(22px, 4vw, 56px); }
.directory-row { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 14px; padding: 22px 0 18px; border-bottom: 1px solid var(--line); align-content: start; }
.chapter-id-badge { height: 38px; border-radius: 8px; background: #e1ebd8; color: var(--green); display: grid; place-items: center; font-weight: 700; font-size: .95rem; }
.directory-row-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.directory-row-head h2 { font-size: 1.35rem; }
.directory-row-head h2 a { text-decoration: none; color: var(--ink); }
.directory-row-head h2 a:hover { text-decoration: underline; }
.directory-meta-pill { font-size: .82rem; color: var(--leaf); white-space: nowrap; font-weight: 600; }
.directory-focus { font-size: .95rem; color: var(--muted); margin: 6px 0 10px; }
.directory-actions { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: .9rem; font-weight: 600; }
.workshop-band { margin-top: 38px; }
.workshop-band h2 { margin-bottom: 6px; }
.workshop-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 16px; }
.workshop-card { background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 20px; display: flex; flex-direction: column; gap: 9px; }
.workshop-card h3 { font-size: 1.2rem; }
.workshop-card p { font-size: .92rem; color: var(--muted); }
.workshop-card-links { margin-top: auto; padding-top: 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--line); font-size: .88rem; }

/* Hero & Interactive Circuit Bench */
.hero { display: grid; grid-template-columns: minmax(250px, .9fr) minmax(320px, 1.1fr); gap: 34px; align-items: start; }
.hero h1 { margin: 10px 0 8px; }
.english-title { display: block; font-size: .46em; letter-spacing: 0; color: #5c705f; margin-top: 7px; font-style: italic; font-weight: 400; }
.hero .intro { margin-top: 14px; color: var(--muted); max-width: 52ch; font-size: 1.02rem; line-height: 1.72; }
.metadata { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; font-size: .88rem; color: var(--muted); margin-top: 18px; }
.badge { border: 1px solid #b6c5ac; border-radius: 20px; padding: 2px 11px; background: #edf2e6; color: var(--green); font-weight: 600; }
.badge.good { background: #d6e9cd; border-color: #73936d; }
.badge.warn { background: #f8ebdc; border-color: #c89f72; color: #7b471e; }
.metadata button { font-size: .88rem; color: var(--leaf); text-decoration: underline; text-underline-offset: 3px; }

.lab { border: 1px solid #b7c8ad; border-radius: 13px; overflow: hidden; background: #edf2e6; box-shadow: 0 6px 16px #173e310d; }
.lab-board { padding: 14px 16px 10px; background: var(--green); color: #edf3df; }
.board-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: .88rem; color: #d5e5cd; font-weight: 600; }
.board-tag { color: var(--gold); font-size: .84rem; }
.lab-plot { display: block; aspect-ratio: 440/216; width: 100%; }
.lab-plot.probe-svg { touch-action: none; cursor: crosshair; }
.lab-plot text { font-family: var(--font); font-size: 13px; fill: #d7e5d1; }
.board-controls { padding: 6px 0 2px; display: flex; align-items: center; justify-content: flex-start; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid #527263; border-radius: 7px; overflow: hidden; }
.seg button { padding: 5px 10px; color: #e2ecde; font-size: .84rem; font-weight: 600; border-right: 1px solid #496b5b; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: #d8e8cb; color: #153f30; }
.lab-controls { padding: 12px 16px 10px; background: #f0f3e8; }
.lab-sliders { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 16px; }
.lab-slider label { display: flex; justify-content: space-between; gap: 8px; font-size: .86rem; font-weight: 600; color: var(--ink); }
.lab-slider output { color: var(--leaf); font-weight: 700; }
.lab-slider input[type="range"] { width: 100%; accent-color: var(--leaf); margin: 4px 0 0; min-height: 22px; }
.lab-values { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px 14px; border-top: 1px solid var(--line); padding-top: 9px; margin: 9px 0 2px; }
.lab-values dt { font-size: .8rem; color: var(--muted); }
.lab-values dd { margin: 2px 0 0; font-size: .95rem; font-weight: 700; color: var(--green); }
.lab-note { font-size: .86rem; color: var(--muted); padding: 8px 2px 0; line-height: 1.5; }

/* Lesson & 5-stage sequence */
.lesson { margin-top: 38px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.section-heading p { color: var(--muted); font-size: .92rem; }
.section-select {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 7px;
  padding: 9px 36px 9px 12px;
  max-width: 56%;
  font-size: .98rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='10'%3E%3Cpath d='M2 2l6 6 6-6' fill='none' stroke='%2345634e' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.stages { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); }
.stages button { padding: 11px 6px; border-right: 1px solid var(--line); font-size: .93rem; font-weight: 600; display: flex; gap: 7px; justify-content: center; align-items: center; }
.stages button:last-child { border-right: 0; }
.stages button[aria-selected="true"] { color: #fff; background: var(--green); }
.tab-count { font-size: .8rem; opacity: .75; }
.stage-card { margin-top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 26px 30px; }
.card-topline { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; color: var(--muted); font-size: .88rem; flex-wrap: wrap; }
.source-link { color: var(--leaf); font-size: .88rem; text-decoration: underline; text-underline-offset: 3px; padding: 0; text-align: left; font-weight: 600; }
.stage-card > h3 { font-size: 1.55rem; margin-bottom: 16px; }
.prose { max-width: 78ch; }
.prose p { line-height: 1.82; color: #2d4034; }

.callout { border-left: 3px solid #74936a; border-radius: 0 7px 7px 0; background: #edf3e5; padding: 13px 17px; margin: 18px 0 0; font-size: .96rem; }
.callout h4 { margin-bottom: 6px; color: var(--green); }
.callout ul { margin: 4px 0; }

.formula { border-bottom: 1px solid var(--line); padding: 18px 0; }
.formula:first-child { padding-top: 4px; }
.formula:last-child { border-bottom: 0; }
.formula .math { font-size: 1.15rem; overflow-x: auto; margin: 12px 0; color: var(--green); padding-bottom: 4px; }
.formula .math .katex-display { text-align: left; margin: .5em 0; }
.formula p { font-size: .94rem; color: var(--muted); line-height: 1.65; }
.katex { font-size: 1.08em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; }

/* Linked deep-review highlight from quiz */
.linked-card { outline: 2px solid #5c8a56; outline-offset: 6px; border-radius: 7px; background: #f2f8ea; padding: 14px 16px !important; }
.review-return {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: 8px;
  background: #e5f0db;
  border: 1px solid #b4caaa;
  font-size: .92rem;
}
.review-return a { font-weight: 700; color: var(--green); }

/* Step-by-step walkthrough & Timer */
.step-list { list-style: none; padding: 0; counter-reset: steps; margin: 12px 0; }
.step-list li { counter-increment: steps; position: relative; padding: 0 0 16px 42px; margin: 0; }
.step-list li:before {
  content: counter(steps);
  position: absolute;
  left: 0;
  top: 1px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid #bacaad;
  border-radius: 50%;
  font-size: .88rem;
  font-weight: 700;
  background: var(--rail);
  color: var(--green);
}
.walk-step { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.walk-step:first-child { border-top: 0; padding-top: 4px; }
.walk-seq { width: 28px; height: 28px; border-radius: 50%; background: #edf2e6; border: 1px solid #b5c5aa; display: grid; place-items: center; font-size: .86rem; font-weight: 700; color: var(--green); }
.walk-step h4 { margin-bottom: 5px; font-size: 1.02rem; }
.walk-eq { margin: 6px 0; color: var(--green); overflow-x: auto; }
.walk-step p { color: var(--muted); font-size: .94rem; }

.timer-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
  background: #f1f4ea;
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 9px;
}
.timer-digits { font-size: 1.55rem; font-weight: 700; color: var(--green); margin-right: auto; font-variant-numeric: tabular-nums; }
.timer-msg { width: 100%; font-size: .9rem; color: var(--leaf); font-weight: 600; }

.hint-details { margin: 14px 0; border-top: 1px solid var(--line); padding-top: 10px; }
.hint-details summary { cursor: pointer; color: var(--leaf); font-weight: 700; font-size: .96rem; }
.hint-details p { margin-top: 8px; color: var(--muted); }
.answer { padding: 11px 15px; background: var(--soft); border-radius: 7px; font-weight: 600; color: var(--green); margin-top: 12px; }
.reveal-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 14px 0 6px; }
.status-pill { font-size: .85rem; padding: 3px 10px; border-radius: 20px; background: #eff2e8; color: var(--muted); font-weight: 600; }

/* Buttons & shared controls */
.lesson-bottom { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.primary, .secondary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: .94rem; font-weight: 600; border-radius: 7px; padding: 8px 16px; line-height: 1.4; text-decoration: none; }
.primary { color: #fff; background: var(--green); border: 1px solid var(--green); }
.secondary { color: var(--ink); background: var(--panel); border: 1px solid #adbda3; }
.small { font-size: .86rem; padding: 6px 12px; }
.done-button[aria-pressed="true"], .conf-btn[aria-pressed="true"] { background: #d6e9cd; color: var(--green); border-color: #73936d; }
.muted { color: var(--muted); font-size: .93rem; }
.note-area { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 16px; }
.note-label { display: flex; justify-content: space-between; font-size: .92rem; font-weight: 600; margin-bottom: 7px; }
.note-label span { color: var(--muted); font-size: .84rem; font-weight: 400; }
textarea { width: 100%; min-height: 105px; resize: vertical; border: 1px solid #b7c5ab; border-radius: 7px; background: #fffefb; padding: 12px; line-height: 1.6; }

/* Calculate (Numerical Practice) & Workshop Grid */
.study-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(240px, .6fr); gap: 26px; align-items: start; }
.study-aside { border-left: 1px solid var(--line); padding-left: 22px; }
.study-aside h3 { font-size: 1.25rem; margin-bottom: 6px; }
.check-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0 8px; }
.number-box { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #9eb198; border-radius: 7px; background: #fff; padding: 5px 12px; }
.number-box input { width: 125px; border: 0; background: transparent; padding: 4px 2px; font-size: 1.05rem; outline-offset: 0; }
.unit-tag { font-weight: 700; color: var(--leaf); font-size: .95rem; }
.num-feedback { font-size: .96rem; font-weight: 600; color: #2b603b; margin: 8px 0 12px; }
.num-feedback.wrong { color: var(--error); }
.conf-row { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }

/* QR Scan Section */
.scan-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(210px, .8fr); gap: 28px; align-items: center; }
.scan-code { text-align: center; display: grid; justify-items: center; gap: 10px; }
.scan-code canvas { display: block; width: min(100%, 260px); height: auto; image-rendering: pixelated; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.scan-address { font-size: .86rem; overflow-wrap: anywhere; color: var(--leaf); font-weight: 600; }
.publish-form { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.publish-form label { display: block; font-weight: 700; font-size: .92rem; }
.publish-form input { width: 100%; margin: 7px 0; padding: 8px 10px; border: 1px solid #acb9a6; border-radius: 6px; background: #fff; }
.qr-large-img { width: min(72vh, 80vw); max-width: 460px; height: auto; display: block; margin: 10px auto; image-rendering: pixelated; border: 1px solid var(--line); padding: 8px; background: #fff; }

/* Page headers, toolbars, formula handbook, quiz, library, notes */
.page-heading { max-width: 840px; margin-bottom: 24px; }
.page-heading h1 { margin: 8px 0 10px; }
.page-heading p { color: var(--muted); }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 16px 0 22px; }
.toolbar label { font-size: .92rem; font-weight: 600; }
.toolbar select, .toolbar input { font-size: .96rem; border: 1px solid #b6c4ac; background: var(--panel); border-radius: 7px; padding: 8px 12px; }
.toolbar input { flex: 1; min-width: 190px; }
.formula-group { margin: 24px 0; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 24px; }
.formula-group h2 { font-size: 1.45rem; margin-bottom: 12px; }
.empty { padding: 34px 20px; text-align: center; border: 1px dashed #bbcab0; border-radius: 10px; color: var(--muted); background: var(--panel); }

.quiz-shell { max-width: 840px; margin: 0 auto; }
.quiz-summary { display: flex; align-items: center; gap: 16px; color: var(--muted); font-size: .92rem; margin-bottom: 12px; justify-content: space-between; }
.quiz-track { display: flex; gap: 4px; margin-bottom: 18px; }
.quiz-track span { height: 5px; border-radius: 2px; flex: 1; background: var(--line); }
.quiz-track span.current { background: #95ad83; }
.quiz-track span.complete { background: var(--green); }
.question-card { padding: 26px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.question-card h2 { font-size: 1.4rem; line-height: 1.48; margin: 10px 0 18px; }
.quiz-options { display: grid; gap: 9px; }
.quiz-option { display: flex; align-items: center; gap: 12px; border: 1px solid #b4c2aa; border-radius: 7px; padding: 13px 15px; text-align: left; background: #fffefa; line-height: 1.5; }
.quiz-option:disabled { opacity: 1; }
.quiz-letter { width: 27px; height: 27px; flex: none; border: 1px solid #bdc9b3; border-radius: 50%; display: grid; place-items: center; font-size: .88rem; font-weight: 700; }
.quiz-option.correct { background: #e8f1df; border-color: #6c9958; }
.quiz-option.wrong { background: #fbebe3; border-color: #c08a72; }
.quiz-feedback { margin-top: 18px; padding: 16px; border-left: 3px solid #759761; background: #eff4e8; border-radius: 0 7px 7px 0; }
.quiz-feedback.wrong { border-color: #ac6e4a; background: #faf0e7; }
.quiz-feedback h3 { margin-bottom: 6px; }
.quiz-actions { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-top: 20px; flex-wrap: wrap; }
.result-score { font-size: 3.6rem; line-height: 1.1; color: var(--green); margin: 14px 0; }
.result-score small { font-size: 1.4rem; color: var(--muted); }
.result-row { border-top: 1px solid var(--line); padding: 16px 0; }
.result-row h3 { font-size: 1.05rem; margin: 4px 0 6px; }
.status-good { color: #2f6b3a; font-weight: 700; }
.status-miss { color: var(--error); font-weight: 700; }

/* Timed Mock Exam */
.exam-shell { max-width: 960px; margin: 0 auto; }
.exam-presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 18px 0; }
.exam-preset {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 20px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.exam-preset.recommended { border-color: var(--leaf); background: #f3f8ec; }
.exam-preset h3 { font-size: 1.25rem; color: var(--green); }
.exam-preset p { font-size: .92rem; color: var(--muted); }
.exam-option-row { display: flex; align-items: center; gap: 10px; margin: 14px 0 22px; font-size: .96rem; }
.exam-option-row input { width: 17px; height: 17px; accent-color: var(--green); }
.exam-banner {
  position: sticky;
  top: 46px;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--green);
  color: #edf3df;
  padding: 12px 18px;
  border-radius: 10px;
  margin-bottom: 18px;
  box-shadow: 0 4px 12px #173e3124;
}
.exam-clock { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.exam-clock.warn { color: #f6d586; }
.exam-clock.urgent { color: #ffb5a1; }
.exam-banner .secondary { background: #fffef9; color: var(--green); border-color: #fffef9; }
.exam-layout { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 20px; align-items: start; }
.exam-nav-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 16px; position: sticky; top: 118px; }
.exam-nav-panel h3 { font-size: 1.05rem; margin-bottom: 10px; }
.exam-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.exam-num {
  position: relative;
  height: 36px;
  border: 1px solid #b5c5aa;
  border-radius: 6px;
  background: #fffefb;
  font-weight: 700;
  font-size: .9rem;
  color: var(--ink);
}
.exam-num.answered { background: #dcebd2; border-color: #6b9464; color: var(--green); }
.exam-num.current { background: var(--green); border-color: var(--green); color: #fff; }
.exam-num.flagged::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c87b22;
}
.exam-legend { display: flex; flex-wrap: wrap; gap: 8px 12px; font-size: .8rem; color: var(--muted); margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.quiz-option.selected { background: #e3efdb; border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); }
.flag-btn[aria-pressed="true"] { background: #f8ebdc; border-color: #c89f72; color: #7b471e; }
.confirm-bar { margin-top: 14px; padding: 12px 16px; border-radius: 8px; background: #faf0e7; border: 1px solid #c99a74; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.diag-table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: .94rem; }
.diag-table th, .diag-table td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.diag-table th { color: var(--muted); font-size: .86rem; text-transform: uppercase; letter-spacing: .05em; }
.mini-bar { height: 7px; width: 96px; background: #dfe6d7; border-radius: 4px; overflow: hidden; display: inline-block; vertical-align: middle; }
.mini-bar > span { display: block; height: 100%; background: var(--leaf); }
.mini-bar.low > span { background: var(--error); }
.exam-promo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 28px;
  padding: 20px 24px;
  border-radius: 12px;
  background: #edf3e5;
  border: 1px solid #b9cbaf;
}
/* Knowledge graph */
.graph-page { max-width: 1700px; margin: 0 auto; }
.graph-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 14px; }
.graph-heading h1 { font-size: clamp(1.7rem, 2.6vw, 2.5rem); margin-top: 4px; }
.graph-heading p { max-width: 62ch; }
.graph-app { border: 1px solid #25493c; border-radius: 12px; overflow: hidden; background: #12231d; color: #e4eedd; }
.graph-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 14px; background: #183229; border-bottom: 1px solid #25493c; }
.graph-toolbar input[type="search"] { flex: 1 1 220px; min-width: 180px; max-width: 360px; padding: 7px 12px; border-radius: 7px; border: 1px solid #3d6656; background: #102019; color: #eaf3e4; }
.graph-toolbar .secondary { background: #20463a; color: #e9f3e3; border-color: #3d6656; }
.graph-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.graph-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 16px; border: 1px solid #3d6656; color: #e0ecd9; font-size: .84rem; font-weight: 600; opacity: .5; }
.graph-chip[aria-pressed="true"] { opacity: 1; background: #20463a; }
.graph-seg { display: inline-flex; border: 1px solid #3d6656; border-radius: 7px; overflow: hidden; }
.graph-seg button { padding: 5px 12px; color: #e0ecd9; font-size: .86rem; font-weight: 600; }
.graph-seg button[aria-pressed="true"] { background: #d8e8cb; color: #153f30; }
.graph-depth { font-size: .86rem; display: inline-flex; align-items: center; gap: 6px; }
.graph-depth select { background: #102019; color: #eaf3e4; border: 1px solid #3d6656; border-radius: 5px; padding: 3px 6px; }
.graph-body { display: grid; grid-template-columns: minmax(0, 1fr) 340px; height: clamp(520px, 74vh, 860px); }
.graph-stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.graph-stage canvas { display: block; touch-action: none; outline-offset: -3px; }
.graph-hint { position: absolute; left: 12px; bottom: 10px; font-size: .78rem; color: #96ad9d; pointer-events: none; background: #12231dcc; padding: 2px 8px; border-radius: 5px; }
.graph-forces { position: absolute; right: 12px; top: 10px; display: grid; gap: 4px; padding: 10px 12px; border-radius: 9px; background: #183229e6; border: 1px solid #2f5646; font-size: .8rem; }
.graph-forces label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.graph-forces input[type="range"] { width: 100px; accent-color: #8fcf8a; }
.graph-legend { position: absolute; left: 12px; top: 10px; font-size: .8rem; color: #96ad9d; pointer-events: none; }
.graph-panel { border-left: 1px solid #25493c; background: #183229; padding: 18px 18px 24px; overflow-y: auto; font-size: .94rem; line-height: 1.55; }
.graph-panel h2 { font-size: 1.28rem; margin: 8px 0 8px; color: #f3f8ee; }
.graph-panel .muted { color: #9db3a4; }
.graph-panel .eyebrow { color: #a9d6a4; }
.graph-panel .badge { background: #20463a; border-color: #4a7a68; color: #e8f3e2; margin-right: 6px; }
.panel-desc { color: #d3e1cb; }
.panel-desc sub, .panel-desc sup { font-size: .75em; }
.panel-math { margin: 10px 0; padding: 8px 10px; background: #102019; border-radius: 7px; overflow-x: auto; color: #f0f6ea; font-size: 1.05rem; }
.panel-math .katex-display { margin: .3em 0; text-align: left; }
.panel-formulas { margin: 4px 0 6px; padding-left: 1.2em; font-size: .88rem; color: #d3e1cb; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.graph-panel .primary { background: #d8e8cb; color: #153f30; border-color: #d8e8cb; }
.graph-panel .secondary { background: #20463a; color: #e9f3e3; border-color: #3d6656; }
.conn-group { margin-top: 12px; }
.conn-group h4 { font-size: .86rem; text-transform: uppercase; letter-spacing: .05em; color: #a9d6a4; margin-bottom: 4px; }
.conn-group ul { list-style: none; padding: 0; margin: 0; }
.conn-group li { margin: 0; }
.conn-group li button { display: flex; align-items: baseline; gap: 8px; width: 100%; text-align: left; padding: 4px 6px; border-radius: 5px; color: #e4eedd; font-size: .9rem; }
.conn-group li button:hover { background: #20463a; filter: none; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.swatch.diamond { border-radius: 1px; transform: rotate(45deg) scale(.85); }
.swatch.square { border-radius: 2px; }
.panel-keys { list-style: none; padding: 0; margin: 12px 0; }
.panel-keys li { display: flex; align-items: center; gap: 9px; margin: 6px 0; font-size: .9rem; }
@media (max-width: 960px) {
  .graph-body { grid-template-columns: 1fr; height: auto; }
  .graph-stage { height: 62vh; min-height: 380px; }
  .graph-panel { border-left: 0; border-top: 1px solid #25493c; max-height: 50vh; }
  .graph-forces { display: none; }
}
@media print { .graph-page { display: none; } }

@media (max-width: 960px) {
  .exam-presets { grid-template-columns: 1fr; }
  .exam-layout { grid-template-columns: 1fr; }
  .exam-nav-panel { position: static; }
  .exam-grid { grid-template-columns: repeat(8, 1fr); }
}
@media (max-width: 600px) {
  .exam-grid { grid-template-columns: repeat(4, 1fr); }
}

.library-list { display: grid; gap: 13px; }
.resource { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 18px; padding: 20px 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.resource-index { height: 44px; width: 44px; border: 1px solid #b8c9ac; border-radius: 9px; display: grid; place-items: center; font-size: 1.2rem; font-weight: 700; color: var(--green); background: var(--soft); }
.resource h2 { font-size: 1.25rem; margin-bottom: 4px; }
.resource p { font-size: .92rem; color: var(--muted); }
.resource-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.coverage { border-left: 3px solid #879a6b; padding: 13px 17px; background: var(--soft); margin: 22px 0; color: #39503e; font-size: .95rem; }
.note-card { background: var(--panel); padding: 20px 22px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 14px; }
.note-card h2 { font-size: 1.2rem; margin-bottom: 8px; }
.note-card p { white-space: pre-wrap; margin-bottom: 12px; }

.footer { max-width: 1660px; margin: auto; display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 18px 30px; border-top: 1px solid var(--line); font-size: .86rem; color: var(--muted); }
.footer button { font-size: .88rem; color: var(--leaf); font-weight: 600; }

/* Dialogs & Toast */
dialog { width: min(760px, calc(100% - 28px)); max-height: 86vh; border: 1px solid #b5c5ab; border-radius: 13px; padding: 24px; background: var(--panel); color: var(--ink); }
dialog::backdrop { background: #0e261ba6; backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.dialog-head h2 { font-size: 1.5rem; }
.dialog-head button { font-size: 1.75rem; line-height: 1; width: 34px; height: 34px; }
#search-input { display: block; width: 100%; font-size: 1.05rem; border: 1px solid #aabda0; border-radius: 7px; padding: 11px 14px; background: #fff; }
#search-summary { margin: 10px 0; }
.search-result { display: block; text-decoration: none; border-top: 1px solid var(--line); padding: 13px 4px; color: var(--ink); }
.search-result strong { font-size: 1.08rem; }
.search-result p { font-size: .9rem; color: var(--muted); margin-top: 4px; }
.search-result small { font-size: .84rem; color: var(--leaf); font-weight: 600; }
mark { background: #ead99d; color: var(--ink); border-radius: 2px; padding: 0 2px; }
.source-file { overflow-wrap: anywhere; font-size: .98rem; font-weight: 700; margin-bottom: 12px; }
.source-slide { border-top: 1px solid var(--line); padding: 14px 0; }
.source-slide h3 { font-size: 1rem; margin-bottom: 6px; }
.source-slide p { font-size: .92rem; white-space: pre-wrap; color: var(--muted); line-height: 1.7; }
.loading { padding: 72px 20px; text-align: center; color: var(--muted); }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60; pointer-events: none; background: var(--green); color: #fff; border-radius: 7px; padding: 10px 18px; max-width: 90vw; opacity: 0; transition: opacity .2s; font-size: .95rem; }
#toast.visible { opacity: 1; }

/* Projection / Focus View */
.focused .rail { display: none; }
.focused .layout { display: block; max-width: 1320px; }
.focused main { font-size: clamp(18px, 1.35vw, 22px); }
.focused .stage-card { padding: 32px 38px; }
.focus-exit { position: fixed; bottom: 20px; right: 20px; z-index: 30; box-shadow: 0 4px 14px #00000022; }
.key-help { font-size: .88rem; color: var(--muted); margin-top: 8px; }

/* Responsive */
@media (max-width: 1180px) {
  .brand strong { font-size: 1.5rem; }
  .brand > span { display: none; }
  .layout { grid-template-columns: 232px minmax(0, 1fr); }
  .study-grid { grid-template-columns: 1fr; }
  .study-aside { border-left: 0; border-top: 1px solid var(--line); padding: 18px 0 0; }
  .workshop-grid { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; }
  .directory-grid { grid-template-columns: 1fr; }
  .directory-intro { flex-direction: column; align-items: flex-start; }
  .directory-stats { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 14px; }
  .scan-layout { grid-template-columns: 1fr; }
  .footer > span:nth-child(2) { display: none; }
}
@media (max-width: 720px) {
  .topbar { padding: 11px 14px; flex-wrap: wrap; gap: 10px; }
  .modes { order: 3; width: 100%; justify-content: space-between; }
  .modes a { flex: 1; text-align: center; padding: 6px 6px; font-size: .86rem; }
  .chapter-shortcuts, .chapter-bar-right { display: none; }
  #chapter-jump { display: block; margin-left: auto; max-width: 54%; padding: 5px 8px; border: 1px solid #b2c3a8; border-radius: 5px; background: var(--panel); color: var(--green); }
  .layout { display: block; }
  .rail { padding: 0 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .mobile-menu { display: flex; justify-content: space-between; width: 100%; padding: 11px 0; font-weight: 700; }
  .rail-content { display: none; position: static; padding-bottom: 18px; }
  .rail.open .rail-content { display: block; }
  .rail-heading { display: none; }
  #chapter-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
  main { padding: 22px 16px 40px; }
  .section-heading { display: block; }
  .section-select { max-width: 100%; width: 100%; margin-top: 10px; }
  .stages { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .stages button { grid-column: span 2; font-size: .84rem; padding: 9px 4px; gap: 3px; }
  .stages button:nth-last-child(-n+2) { grid-column: span 3; border-top: 1px solid var(--line); }
  .stages button:nth-child(3) { border-right: 0; }
  .tab-count { display: none; }
  .stage-card { padding: 18px 16px; }
  .resource { grid-template-columns: 42px 1fr; }
  .resource-actions { grid-column: 2; }
}
@media print {
  .topbar, .chapter-bar-wrap, .rail, .footer, .lab, .lab-note, .stages, .lesson-bottom, .note-area, .toolbar, .focus-exit, #toast, .source-link, .resource-actions, .quiz-actions, .timer-box { display: none !important; }
  .layout, .hero, .study-grid { display: block; max-width: none; }
  main { padding: 0; }
  .stage-card, .formula-group, .question-card, .resource { border: 0; padding: 8px 0; break-inside: avoid; }
  body { background: #fff; color: #000; font-size: 11pt; }
}
