/* ===== Tokens ===== */
:root {
  color-scheme: light;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f1f2f8;
  --surface-3: #e5e7f0;
  --text: #161a2e;
  --muted: #5b6075;
  --faint: #8d92a6;
  --border: #e4e6ef;
  --border-strong: #cdd0dd;
  --accent: #3b45e6;
  --accent-strong: #2a33c4;
  --accent-soft: #eceefe;
  --on-accent: #ffffff;
  --success: #16a34a;
  --success-soft: #e7f6ec;
  --warning: #b45309;
  --warning-soft: #fdf3e2;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --c-def: #2563eb;
  --c-law: #7c3aed;
  --c-formula: #3b45e6;
  --c-note: #b45309;
  --c-trap: #dc2626;
  --c-example: #16a34a;
  --c-tip: #0e7490;
  --shadow: 0 1px 2px rgba(22, 26, 46, 0.04), 0 6px 20px rgba(22, 26, 46, 0.05);
  --radius: 18px;
  --radius-sm: 10px;
  --font-ui: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --max: 1200px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1220;
    --surface: #171b2d;
    --surface-2: #1e2338;
    --surface-3: #282e47;
    --text: #e8eaf4;
    --muted: #a2a7bd;
    --faint: #767c95;
    --border: #262b42;
    --border-strong: #3a4060;
    --accent: #8b93ff;
    --accent-strong: #aab0ff;
    --accent-soft: #23284a;
    --on-accent: #0f1220;
    --success: #4ade80;
    --success-soft: #16301f;
    --warning: #fbbf24;
    --warning-soft: #352a12;
    --danger: #f87171;
    --danger-soft: #3a1a1d;
    --c-def: #60a5fa;
    --c-law: #c4b5fd;
    --c-formula: #8b93ff;
    --c-note: #fbbf24;
    --c-trap: #f87171;
    --c-example: #4ade80;
    --c-tip: #22d3ee;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 20px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1220;
  --surface: #171b2d;
  --surface-2: #1e2338;
  --surface-3: #282e47;
  --text: #e8eaf4;
  --muted: #a2a7bd;
  --faint: #767c95;
  --border: #262b42;
  --border-strong: #3a4060;
  --accent: #8b93ff;
  --accent-strong: #aab0ff;
  --accent-soft: #23284a;
  --on-accent: #0f1220;
  --success: #4ade80;
  --success-soft: #16301f;
  --warning: #fbbf24;
  --warning-soft: #352a12;
  --danger: #f87171;
  --danger-soft: #3a1a1d;
  --c-def: #60a5fa;
  --c-law: #c4b5fd;
  --c-formula: #8b93ff;
  --c-note: #fbbf24;
  --c-trap: #f87171;
  --c-example: #4ade80;
  --c-tip: #22d3ee;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 84px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-ui); font-size: 16px; line-height: 1.6; }
a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; height: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.08rem; font-weight: 700; }
p { margin: 0 0 0.8em; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { left: 8px; }
.noscript { padding: 24px; text-align: center; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ===== Top bar ===== */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border); }
.topbar__inner { max-width: var(--max); margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); flex-shrink: 0; font-weight: 800; letter-spacing: -0.01em; }
.brand__mark { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent); }
.brand__mark svg { width: 18px; height: 18px; }
.brand__text b { color: var(--accent); }
.mainnav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin-left: auto; }
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a { text-decoration: none; color: var(--muted); padding: 7px 12px; border-radius: 10px; white-space: nowrap; font-weight: 600; font-size: 0.92rem; display: flex; align-items: center; gap: 6px; }
.mainnav a:hover { color: var(--text); background: var(--surface-2); }
.mainnav a.is-active { color: var(--accent); background: var(--accent-soft); }
.icon-btn { flex-shrink: 0; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 1.05rem; }
.icon-btn:hover { background: var(--surface-2); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 0.72rem; font-weight: 700; }
@media (max-width: 820px) {
  .topbar__inner { flex-wrap: wrap; gap: 8px 10px; padding: 10px 16px 8px; }
  .brand { margin-right: auto; }
  .mainnav { order: 3; margin-left: 0; width: 100%; }
  .mainnav a { padding: 6px 10px; font-size: 0.88rem; }
  html { scroll-padding-top: 120px; }
}

/* ===== Layout ===== */
main { max-width: var(--max); margin: 0 auto; padding: 28px 16px 80px; outline: none; }
.page-head { margin-bottom: 22px; }
.eyebrow { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.lead { color: var(--muted); max-width: 72ch; }
.crumbs { font-size: 0.88rem; color: var(--faint); margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.stack > * + * { margin-top: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row--between { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.grid--tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid--chapters { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
@media (max-width: 400px) { .grid--chapters { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card--flat { box-shadow: none; }
.card--soft { background: var(--surface-2); box-shadow: none; border-color: transparent; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 34px 0 14px; flex-wrap: wrap; }
.section-title h2 { margin: 0; }

/* ===== Buttons & controls ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; font-size: 0.94rem; transition: background 0.12s, border-color 0.12s, transform 0.05s; }
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--small { padding: 6px 11px; font-size: 0.85rem; border-radius: 10px; }
.btn--large { padding: 12px 22px; font-size: 1rem; }
.btn--success { border-color: var(--success); color: var(--success); }
.btn--success.is-on { background: var(--success); color: var(--surface); }
.btn--warning { border-color: var(--warning); color: var(--warning); }
.btn--warning.is-on { background: var(--warning); color: var(--surface); }
.btn--danger { border-color: var(--danger); color: var(--danger); }
.btn--danger.is-on { background: var(--danger); color: var(--surface); }
.link-btn { all: unset; cursor: pointer; color: var(--accent); font-weight: 600; font-size: 0.9rem; }
.link-btn:hover { text-decoration: underline; }
.link-btn:focus-visible { outline: 2px solid var(--accent); border-radius: 4px; }
.kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.75em; padding: 1px 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); cursor: pointer; font-size: 0.88rem; user-select: none; font-weight: 500; }
.chip input { accent-color: var(--accent); margin: 0; }
.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border); flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; padding: 6px 12px; border-radius: 9px; cursor: pointer; font-size: 0.88rem; color: var(--muted); font-weight: 600; }
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.field { display: grid; gap: 6px; }
.field label, .field .label { font-weight: 700; font-size: 0.9rem; }
.input, select.input, textarea.input { width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface); }
textarea.input { min-height: 110px; resize: vertical; line-height: 1.5; font-size: 0.92rem; }
.form-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

/* ===== Progress ===== */
.meter { display: grid; gap: 4px; }
.meter__label { display: flex; justify-content: space-between; gap: 8px; font-size: 0.8rem; color: var(--muted); }
.meter__label b { color: var(--text); font-weight: 700; }
.meter__track { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter__fill { height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.3s; }
.meter--success .meter__fill { background: var(--success); }
.meter--warning .meter__fill { background: var(--warning); }

/* ===== Dashboard ===== */
.hero { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; margin-bottom: 6px; }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; } }
.hero__main { display: grid; align-content: center; gap: 6px; padding: 26px; background: linear-gradient(135deg, var(--accent) 0%, #6a4cf0 100%); color: #fff; border: 0; }
.hero__main h1 { font-size: 2rem; margin: 0; }
.hero__main p { color: rgba(255, 255, 255, 0.86); margin: 0; }
.hero__main .row { margin-top: 12px; }
.hero__main .btn { background: #fff; color: #2a33c4; border-color: #fff; }
.hero__main .btn--ghost { background: rgba(255, 255, 255, 0.14); color: #fff; border-color: transparent; }
.countdown { display: grid; gap: 4px; align-content: center; justify-items: start; }
.countdown__value { font-size: 2.6rem; font-weight: 800; line-height: 1; letter-spacing: -0.03em; color: var(--accent); }
.tile { display: grid; gap: 2px; align-content: start; }
.tile__value { font-size: 1.8rem; font-weight: 800; line-height: 1.15; letter-spacing: -0.02em; }
.tile__label { color: var(--muted); font-size: 0.86rem; }
.tile .btn { margin-top: 10px; justify-self: start; }
.chapter-card { display: grid; gap: 14px; align-content: start; text-decoration: none; color: var(--text); transition: border-color 0.15s, transform 0.15s; }
.chapter-card:hover { border-color: var(--accent); color: var(--text); transform: translateY(-2px); }
.chapter-card__head { display: flex; gap: 12px; align-items: flex-start; }
.chapter-num { flex-shrink: 0; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem; background: var(--tint-soft, var(--accent-soft)); color: var(--tint, var(--accent)); }
.chapter-card__title { font-weight: 700; font-size: 1.02rem; line-height: 1.35; }
.chapter-card__sub { color: var(--faint); font-size: 0.82rem; }
.chapter-card__meters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.tint-e { --tint: #3b45e6; --tint-soft: #eceefe; }
.tint-c { --tint: #0e7490; --tint-soft: #e0f4f8; }
.tint-m { --tint: #b45309; --tint-soft: #fdf3e2; }
.tint-i { --tint: #be185d; --tint-soft: #fce7f3; }
:root[data-theme="dark"] .tint-e, :root[data-theme="dark"] .tint-c, :root[data-theme="dark"] .tint-m, :root[data-theme="dark"] .tint-i { --tint-soft: var(--surface-2); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) :is(.tint-e, .tint-c, .tint-m, .tint-i) { --tint-soft: var(--surface-2); } }
:root[data-theme="dark"] .tint-e { --tint: #8b93ff; } :root[data-theme="dark"] .tint-c { --tint: #22d3ee; } :root[data-theme="dark"] .tint-m { --tint: #fbbf24; } :root[data-theme="dark"] .tint-i { --tint: #f472b6; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tint-e { --tint: #8b93ff; }
  :root:not([data-theme="light"]) .tint-c { --tint: #22d3ee; }
  :root:not([data-theme="light"]) .tint-m { --tint: #fbbf24; }
  :root:not([data-theme="light"]) .tint-i { --tint: #f472b6; }
}
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); grid-auto-columns: 12px; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap span { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-3); }
.heatmap span[data-level="1"] { background: color-mix(in srgb, var(--accent) 30%, var(--surface-3)); }
.heatmap span[data-level="2"] { background: color-mix(in srgb, var(--accent) 55%, var(--surface-3)); }
.heatmap span[data-level="3"] { background: color-mix(in srgb, var(--accent) 80%, var(--surface-3)); }
.heatmap span[data-level="4"] { background: var(--accent); }

/* ===== Chapter page ===== */
.chapter-head { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; }
.chapter-head h1 { margin: 0; }
.chapter-head .chapter-num { width: 54px; height: 54px; font-size: 1.25rem; border-radius: 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { text-decoration: none; color: var(--muted); padding: 10px 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 600; font-size: 0.94rem; }
.tabs a:hover { color: var(--text); }
.tabs a.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { color: var(--faint); font-weight: 500; margin-left: 4px; font-size: 0.85em; }
.reader { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 32px; align-items: start; }
@media (max-width: 960px) { .reader { grid-template-columns: 1fr; } }
.toc { position: sticky; top: 84px; max-height: calc(100vh - 104px); overflow: auto; padding-right: 6px; font-size: 0.9rem; }
@media (max-width: 960px) { .toc { position: static; max-height: none; } }
.toc ol { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 2px; }
.toc button { all: unset; box-sizing: border-box; display: flex; gap: 8px; width: 100%; padding: 6px 8px; border-radius: 10px; cursor: pointer; color: var(--muted); line-height: 1.35; }
.toc button:hover { background: var(--surface-2); color: var(--text); }
.toc button:focus-visible { outline: 2px solid var(--accent); }
.toc .check { flex-shrink: 0; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--border-strong); display: grid; place-items: center; font-size: 11px; margin-top: 1px; }
.toc li.is-read .check { background: var(--success); border-color: var(--success); color: var(--surface); }
.toc li.is-current button { color: var(--accent); background: var(--accent-soft); }
.toc-mobile { display: none; }
@media (max-width: 960px) { .toc-desktop { display: none; } .toc-mobile { display: block; } }

/* ===== Article / markdown ===== */
.article { font-size: 1.02rem; line-height: 1.75; min-width: 0; }
.article-section { padding-bottom: 28px; margin-bottom: 28px; border-bottom: 1px dashed var(--border-strong); }
.article-section > h2 { font-size: 1.4rem; margin-top: 6px; }
.article-section__foot { display: flex; justify-content: flex-end; margin-top: 18px; }
.md > :last-child, .block__body > :last-child { margin-bottom: 0; }
.md ul, .md ol { padding-left: 1.4em; }
.md li + li { margin-top: 0.3em; }
.md h3 { margin-top: 1.3em; }
.md blockquote { margin: 0 0 1em; padding: 6px 14px; border-left: 3px solid var(--border-strong); color: var(--muted); }
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md img { display: block; margin: 12px auto; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md strong { font-weight: 700; }
.table-wrap { overflow-x: auto; margin: 0 0 1em; }
.md table { border-collapse: collapse; font-size: 0.94em; min-width: 50%; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 700; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.katex { font-size: 1.06em; }
.math-error { color: var(--danger); font-family: monospace; }
.block { margin: 0 0 1.1em; padding: 12px 16px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--c-block, var(--border)) 25%, var(--border)); border-left: 4px solid var(--c-block, var(--border-strong)); background: color-mix(in srgb, var(--c-block, var(--surface-2)) 6%, var(--surface)); }
.block__title { font-weight: 800; font-size: 0.86rem; color: var(--c-block, var(--text)); margin: 0 0 6px; letter-spacing: 0.01em; }
.block--def { --c-block: var(--c-def); }
.block--law { --c-block: var(--c-law); }
.block--formula { --c-block: var(--c-formula); }
.block--note { --c-block: var(--c-note); }
.block--trap { --c-block: var(--c-trap); }
.block--example { --c-block: var(--c-example); }
.block--tip { --c-block: var(--c-tip); }
details.block > summary { cursor: pointer; font-weight: 700; font-size: 0.9rem; color: var(--c-block, var(--muted)); list-style: none; display: flex; align-items: center; gap: 8px; }
details.block > summary::-webkit-details-marker { display: none; }
details.block > summary::before { content: "▸"; transition: transform 0.15s; display: inline-block; }
details.block[open] > summary::before { transform: rotate(90deg); }
details.block[open] > summary { margin-bottom: 8px; }

/* ===== Problems ===== */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.problem-list { display: grid; gap: 10px; }
.problem-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px 16px; text-decoration: none; color: var(--text); border-radius: 14px; }
.problem-row:hover { border-color: var(--accent); color: var(--text); }
.problem-row__num { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-weight: 800; color: var(--muted); }
.problem-row__num[data-status="correct"] { background: var(--success-soft); color: var(--success); }
.problem-row__num[data-status="partial"] { background: var(--warning-soft); color: var(--warning); }
.problem-row__num[data-status="wrong"] { background: var(--danger-soft); color: var(--danger); }
.problem-row__text { min-width: 0; }
.problem-row__title { font-weight: 700; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.problem-row__preview { color: var(--muted); font-size: 0.88rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.problem-row__meta { display: flex; gap: 8px; align-items: center; color: var(--faint); font-size: 0.85rem; }
.stars { color: #f59e0b; letter-spacing: 1px; font-size: 0.82rem; }
.src-tag { font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.topic-tag { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.problem { display: grid; gap: 16px; }
.problem__head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.problem__head h1 { margin: 0; font-size: 1.5rem; }
.problem__statement { font-size: 1.04rem; line-height: 1.75; }
.problem__layout { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; align-items: start; }
@media (max-width: 760px) { .problem__layout { grid-template-columns: 1fr; } }
.figure { margin: 0; padding: 10px; background: #fff; border-radius: 14px; border: 1px solid var(--border); justify-self: center; max-width: min(420px, 100%); }
.figure img { display: block; margin: 0 auto; max-height: 340px; width: auto; }
.part { border-top: 1px solid var(--border); padding-top: 16px; display: grid; gap: 12px; }
.part__q { display: flex; gap: 10px; align-items: baseline; }
.part__label { flex-shrink: 0; width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 0.9rem; }
.part__text { min-width: 0; line-height: 1.7; }
.answers { display: grid; gap: 10px; }
.answer { display: grid; grid-template-columns: auto minmax(120px, 260px) auto auto; gap: 8px 10px; align-items: center; justify-content: start; }
@media (max-width: 560px) { .answer { grid-template-columns: auto minmax(0, 1fr) auto; } .answer__fb { grid-column: 1 / -1; } }
.answer__key { font-weight: 600; white-space: nowrap; }
.answer__input { font-variant-numeric: tabular-nums; }
.answer__input.is-correct { border-color: var(--success); background: var(--success-soft); }
.answer__input.is-wrong { border-color: var(--danger); background: var(--danger-soft); }
.answer__unit { color: var(--muted); font-size: 0.92rem; white-space: nowrap; }
.answer__fb { font-size: 0.86rem; font-weight: 600; }
.answer__fb.is-correct { color: var(--success); }
.answer__fb.is-wrong { color: var(--danger); }
.answer__fb.is-close { color: var(--warning); }
.part__tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.solution { margin: 0; }
.assess { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 14px 16px; border-radius: 14px; background: var(--surface-2); }
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 0.76rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.status-pill--correct { background: var(--success-soft); color: var(--success); }
.status-pill--partial { background: var(--warning-soft); color: var(--warning); }
.status-pill--wrong { background: var(--danger-soft); color: var(--danger); }
.flag-btn { all: unset; cursor: pointer; font-size: 1.3rem; line-height: 1; color: var(--faint); padding: 2px 4px; border-radius: 6px; }
.flag-btn.is-on { color: #f59e0b; }
.flag-btn:focus-visible { outline: 2px solid var(--accent); }
.pager { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.input-help { font-size: 0.82rem; color: var(--faint); }

/* ===== Flashcards ===== */
.study { max-width: 760px; margin: 0 auto; }
.study__bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; font-size: 0.9rem; color: var(--muted); flex-wrap: wrap; }
.flashcard { min-height: 280px; display: grid; grid-template-rows: auto 1fr auto; gap: 14px; padding: 24px; }
.flashcard__front { font-size: 1.2rem; font-weight: 700; line-height: 1.5; }
.flashcard__prompt { color: var(--muted); font-size: 0.92rem; margin-top: 6px; font-weight: 500; }
.flashcard__back { border-top: 1px solid var(--border); padding-top: 16px; line-height: 1.7; }
.rating { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rating button { display: grid; gap: 2px; padding: 10px 6px; border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; text-align: center; font-weight: 700; }
.rating button small { color: var(--muted); font-size: 0.74rem; font-weight: 500; }
.rating button:hover { background: var(--surface-2); }
.rating button[data-rating="again"] { border-color: var(--danger); color: var(--danger); }
.rating button[data-rating="hard"] { border-color: var(--warning); color: var(--warning); }
.rating button[data-rating="good"] { border-color: var(--success); color: var(--success); }
.rating button[data-rating="easy"] { border-color: var(--accent); color: var(--accent); }
.card-list { display: grid; gap: 10px; }
.card-list details { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; }
.card-list summary { cursor: pointer; display: flex; gap: 10px; align-items: baseline; }
.card-list .card-body { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.srs-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-3); flex-shrink: 0; align-self: center; }
.srs-dot[data-state="learning"] { background: var(--warning); }
.srs-dot[data-state="due"] { background: var(--danger); }
.srs-dot[data-state="learned"] { background: var(--success); }

/* ===== Quiz ===== */
.quiz { max-width: 820px; margin: 0 auto; }
.question { display: grid; gap: 14px; }
.question__text { font-size: 1.06rem; line-height: 1.65; font-weight: 500; }
.options { display: grid; gap: 10px; }
.option { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--border-strong); background: var(--surface); cursor: pointer; line-height: 1.5; }
.option:hover:not(:disabled) { border-color: var(--accent); }
.option:disabled { cursor: default; }
.option__key { flex-shrink: 0; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); font-weight: 800; font-size: 0.85rem; }
.option__text { min-width: 0; flex: 1; }
.option.is-correct { border-color: var(--success); background: var(--success-soft); }
.option.is-correct .option__key { background: var(--success); color: var(--surface); }
.option.is-wrong { border-color: var(--danger); background: var(--danger-soft); }
.option.is-wrong .option__key { background: var(--danger); color: var(--surface); }
.feedback { padding: 14px 16px; border-radius: 14px; border: 1px solid var(--border); }
.feedback--correct { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 40%, transparent); }
.feedback--wrong { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.feedback__title { font-weight: 800; margin-bottom: 6px; }
.quiz-progress { height: 5px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin-bottom: 18px; }
.quiz-progress > div { height: 100%; background: var(--accent); transition: width 0.25s; }
.score-big { font-size: 3rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }

/* ===== Exam ===== */
.exam-timer { position: sticky; top: 70px; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; margin-bottom: 18px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); flex-wrap: wrap; }
@media (max-width: 820px) { .exam-timer { top: 108px; } }
.exam-timer__clock { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.2rem; }
.exam-timer__clock.is-low { color: var(--danger); }
.points { font-weight: 700; font-size: 0.85rem; color: var(--muted); }
.history { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.history th, .history td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.history th { color: var(--muted); font-weight: 600; }

/* ===== Formula sheet ===== */
.formula-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.formula { display: grid; gap: 6px; padding: 14px 16px; }
.formula__name { font-weight: 700; font-size: 0.92rem; }
.formula__body { overflow-x: auto; }

/* ===== Misc ===== */
.loading-state, .empty-state, .error-state { padding: 40px 16px; text-align: center; color: var(--muted); }
.error-state { color: var(--danger); }
.error-state .btn { margin-top: 12px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2.5px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -3px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast-region { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(92vw, 420px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 0.92rem; animation: toast-in 0.2s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.note-banner { font-size: 0.88rem; color: var(--muted); padding: 10px 14px; background: var(--surface-2); border-radius: 12px; margin-bottom: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 0.92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; }
.footer { max-width: var(--max); margin: 0 auto; padding: 18px 16px 36px; color: var(--faint); font-size: 0.85rem; border-top: 1px solid var(--border); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print {
  .topbar, .tabs, .toc, .footer, .article-section__foot, .toolbar, .part__tools, .assess, .no-print { display: none !important; }
  main { padding: 0; }
  .reader { display: block; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
