:root {
  --paper: #f6f1e7;
  --paper-2: #fffdf8;
  --ink: #292a25;
  --muted: #6d6d63;
  --sage: #667865;
  --sage-soft: #e3e9df;
  --wheat: #c78a3e;
  --wheat-soft: #f3dfbd;
  --red: #a6513d;
  --line: rgba(41, 42, 37, .12);
  --shadow: 0 12px 40px rgba(68, 54, 36, .09);
  --radius: 22px;
  --reading: 720px;
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; background: var(--paper); }
body { margin: 0; min-width: 320px; background: var(--paper); line-height: 1.7; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
img { display: block; width: 100%; height: auto; }

.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; padding: 10px 14px; background: var(--ink); color: white; border-radius: 10px; }
.skip-link:focus { top: 12px; }

.topbar { position: sticky; top: 0; z-index: 30; height: 66px; padding: 0 16px; display: flex; align-items: center; gap: 18px; background: rgba(246, 241, 231, .9); border-bottom: 1px solid var(--line); backdrop-filter: blur(16px); }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand-mark { width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center; flex: 0 0 auto; color: #fff; background: var(--sage); font-family: serif; }
.brand strong, .brand small { display: block; white-space: nowrap; }
.brand strong { font-size: 15px; letter-spacing: .04em; }
.brand small { font-size: 10px; color: var(--muted); }
.desktop-nav { display: none; margin-left: auto; gap: 6px; }
.desktop-nav a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 14px; }
.desktop-nav a.active { color: var(--ink); background: var(--paper-2); box-shadow: 0 3px 14px rgba(0,0,0,.05); }
.icon-button { margin-left: auto; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper-2); color: var(--ink); font-size: 26px; line-height: 1; cursor: pointer; }
.progress-line { position: fixed; top: 65px; left: 0; right: 0; z-index: 31; height: 2px; }
.progress-line span { display: block; width: 0; height: 100%; background: var(--wheat); transition: width .1s linear; }

main { min-height: calc(100vh - 66px); padding-bottom: 92px; }
.view { animation: rise .28s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.reading { width: min(var(--reading), calc(100% - 32px)); margin: 0 auto; }

.hero { overflow: hidden; padding: 28px 0 14px; }
.hero-grid { display: grid; gap: 24px; align-items: center; }
.eyebrow { margin: 0 0 10px; color: var(--sage); font-size: 12px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.hero h1 { margin: 0; max-width: 10em; font-family: "Songti SC", "STSong", serif; font-size: clamp(38px, 11vw, 70px); line-height: 1.08; letter-spacing: -.04em; }
.hero h1 em { color: var(--wheat); font-style: normal; }
.lede { margin: 18px 0 0; max-width: 32em; color: var(--muted); font-size: 16px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 46px; padding: 11px 18px; border: 0; border-radius: 999px; background: var(--sage); color: white; text-decoration: none; font-weight: 700; cursor: pointer; }
.button.secondary { background: var(--paper-2); color: var(--ink); border: 1px solid var(--line); }
.button.small { min-height: 38px; padding: 8px 14px; font-size: 13px; }
.hero-art { position: relative; max-width: 540px; margin: auto; border-radius: 32px; overflow: hidden; box-shadow: var(--shadow); background: var(--paper-2); }
.hero-art img { height: auto; aspect-ratio: auto; object-fit: contain; }
.hero-caption { position: absolute; left: 16px; right: 16px; bottom: 16px; padding: 12px 14px; border-radius: 15px; color: #fff; background: rgba(41,42,37,.72); backdrop-filter: blur(8px); font-weight: 700; }

.section { padding: 42px 0; }
.section-head { display: flex; gap: 18px; justify-content: space-between; align-items: end; margin-bottom: 20px; }
.section-head h2, .page-head h1 { margin: 0; font-family: "Songti SC", "STSong", serif; line-height: 1.15; }
.section-head h2 { font-size: clamp(28px, 8vw, 42px); }
.section-head p { max-width: 34em; margin: 8px 0 0; color: var(--muted); }
.kicker { color: var(--wheat); font-size: 12px; font-weight: 800; letter-spacing: .12em; }

.quick-grid, .lesson-grid, .principle-grid, .glossary-grid { display: grid; gap: 14px; }
.quick-card, .lesson-card, .principle-card, .glossary-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-2); box-shadow: 0 8px 26px rgba(68,54,36,.045); }
.quick-card { padding: 22px; text-decoration: none; }
.quick-card span { display: inline-grid; width: 38px; height: 38px; place-items: center; border-radius: 12px; background: var(--wheat-soft); color: #754f22; font-weight: 800; }
.quick-card h3 { margin: 16px 0 5px; font-size: 18px; }
.quick-card p { margin: 0; color: var(--muted); font-size: 14px; }
.principle-card { padding: 20px; }
.principle-card strong { display: block; margin-bottom: 6px; color: var(--sage); font-size: 17px; }
.principle-card p { margin: 0; color: var(--muted); font-size: 14px; }

.page-head { padding: 34px 0 18px; }
.page-head h1 { font-size: clamp(36px, 10vw, 58px); }
.page-head p { margin: 10px 0 0; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0; }
.search-input { width: 100%; min-height: 48px; padding: 0 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper-2); color: var(--ink); outline: none; }
.search-input:focus { border-color: var(--sage); box-shadow: 0 0 0 3px var(--sage-soft); }
.filter-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 999px; padding: 8px 13px; background: transparent; color: var(--muted); cursor: pointer; }
.chip.active { background: var(--ink); color: white; border-color: var(--ink); }

.lesson-card { position: relative; overflow: hidden; }
.lesson-card a { display: block; padding: 20px; text-decoration: none; }
.lesson-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lesson-index { color: var(--wheat); font-size: 12px; font-weight: 900; letter-spacing: .1em; }
.lesson-card h2 { margin: 12px 0 6px; font-size: 20px; line-height: 1.35; }
.lesson-card p { margin: 0; color: var(--muted); font-size: 14px; }
.duration { color: var(--muted); font-size: 12px; }
.done-dot { width: 20px; height: 20px; border: 1px solid var(--line); border-radius: 50%; display: grid; place-items: center; font-size: 12px; }
.lesson-card.done .done-dot { background: var(--sage); color: white; border-color: var(--sage); }
.lesson-card.done { border-color: rgba(102,120,101,.35); }

.course-progress { display: grid; gap: 8px; padding: 18px; margin-bottom: 18px; border-radius: 18px; background: var(--sage-soft); }
.course-progress div { display: flex; justify-content: space-between; font-size: 14px; }
.meter { height: 8px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.75); }
.meter span { display: block; height: 100%; width: 0; background: var(--sage); border-radius: inherit; transition: width .3s; }

.lesson-view { padding: 24px 0 50px; }
.lesson-article { width: min(var(--reading), calc(100% - 32px)); margin: 0 auto; }
.lesson-meta { display: flex; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.lesson-title { margin: 14px 0 14px; font-family: "Songti SC", "STSong", serif; font-size: clamp(34px, 10vw, 54px); line-height: 1.16; }
.lesson-intro { margin: 0 0 28px; color: var(--muted); font-size: 17px; }
.lesson-article h2 { margin: 36px 0 12px; font-size: 25px; line-height: 1.35; }
.lesson-article h3 { margin: 24px 0 8px; font-size: 18px; }
.lesson-article p { margin: 0 0 14px; }
.lesson-article ul, .lesson-article ol { padding-left: 1.3em; }
.lesson-article li { margin: 7px 0; }
.lesson-figure { margin: 28px 0; overflow: hidden; border-radius: 24px; background: var(--paper-2); box-shadow: var(--shadow); }
.lesson-figure img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: auto;
  object-fit: contain;
}
.lesson-figure figcaption { padding: 14px 16px 16px; color: var(--muted); font-size: 13px; }
.callout { margin: 22px 0; padding: 18px; border-left: 4px solid var(--wheat); border-radius: 0 16px 16px 0; background: var(--wheat-soft); }
.callout strong { display: block; margin-bottom: 4px; }
.remember { margin: 32px 0; padding: 22px; border-radius: 22px; color: white; background: var(--sage); }
.remember h2 { margin-top: 0; color: white; }
.remember li { margin: 9px 0; }
.lesson-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding-top: 22px; border-top: 1px solid var(--line); }
.lesson-actions .button:first-child { flex: 1; }

.related-box { margin: 34px 0; padding: 20px; border: 1px solid var(--line); border-radius: 20px; background: var(--paper); }
.related-box h2 { margin: 4px 0 12px; font-size: 22px; }

.tool-grid, .atlas-grid, .product-grid, .case-grid, .ingredient-grid, .variable-grid, .timer-grid { display: grid; gap: 14px; }
.tool-card, .atlas-card, .product-card, .case-card, .ingredient-card, .variable-card, .making-card, .timer-card { border: 1px solid var(--line); border-radius: 20px; background: var(--paper-2); box-shadow: 0 8px 26px rgba(68,54,36,.045); }
.tool-card { padding: 18px; }
.tool-card h2, .atlas-card h2, .product-card h2, .case-card h2, .ingredient-card h2, .variable-card h2, .timer-section h2 { margin: 0 0 12px; font-size: 21px; line-height: 1.3; }
.field { display: block; margin: 11px 0; }
.field > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 13px; font-weight: 700; }
.field > div { position: relative; }
.field input { width: 100%; min-height: 44px; padding: 0 42px 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); }
.field em { position: absolute; top: 9px; right: 12px; color: var(--muted); font-size: 14px; font-style: normal; }
output { display: grid; gap: 8px; margin-top: 14px; padding: 13px; border-radius: 13px; color: var(--ink); background: var(--sage-soft); }
output span { display: flex; justify-content: space-between; gap: 14px; font-size: 14px; }
output b { color: var(--sage); }
.fine-print { margin: 12px 0 0; color: var(--muted); font-size: 12px; }

.feature-figure, .module-figure { margin: 20px 0 28px; overflow: hidden; border: 1px solid var(--line); border-radius: 24px; background: var(--paper-2); box-shadow: var(--shadow); }
.feature-figure button { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.feature-figure img, .module-figure img { width: 100%; height: auto; object-fit: contain; }
.feature-figure figcaption, .module-figure figcaption { padding: 12px 15px 15px; color: var(--muted); font-size: 13px; }
.atlas-card { padding: 19px; }
.atlas-card > span, .case-card > span, .ingredient-card > span, .product-card > span, .making-card > span, .timer-card > span { display: inline-block; margin-bottom: 10px; color: var(--wheat); font-size: 12px; font-weight: 900; letter-spacing: .08em; }
.atlas-card p, .case-card p, .ingredient-card p, .product-card p, .variable-card p { margin: 0; color: var(--muted); font-size: 14px; }
.atlas-card a, .case-card a { display: inline-block; margin-top: 13px; color: var(--sage); font-size: 14px; font-weight: 800; }
.product-card { display: block; min-height: 210px; padding: 21px; color: inherit; text-decoration: none; }
.product-card strong { display: block; margin-top: 18px; color: var(--sage); font-size: 14px; }
.product-detail .page-head { padding-top: 18px; }
.step-list { display: grid; gap: 12px; margin: 26px 0; padding: 0; list-style: none; }
.step-list li { display: grid; grid-template-columns: 36px 1fr; gap: 12px; padding: 15px; border-radius: 16px; background: var(--paper-2); border: 1px solid var(--line); }
.step-list li > span { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 10px; color: #754f22; background: var(--wheat-soft); font-weight: 800; }
.step-list p { margin: 1px 0; }

.question-card { margin-top: 22px; padding: 18px; border-radius: 18px; background: var(--wheat-soft); }
.question-card small { color: #754f22; font-weight: 800; }
.question-card h3 { margin: 8px 0 14px; font-size: 19px; line-height: 1.4; }
.answer-row, .diagnose-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.result-panel { margin-top: 18px; }
.result-panel h3 { margin: 0 0 8px; }

.making-steps { display: grid; gap: 12px; }
.making-card { padding: 19px; }
.making-card h2 { margin: 0 0 7px; font-size: 22px; }
.making-card p { margin: 0 0 12px; color: var(--muted); }
.making-card strong { color: var(--sage); font-size: 14px; }
.timer-section { margin: 30px 0; padding: 20px; border-radius: 22px; background: var(--sage-soft); }
.timer-section > p { margin-top: -2px; color: var(--muted); font-size: 14px; }
.timer-card { padding: 16px; background: rgba(255,253,248,.8); box-shadow: none; }
.timer-card strong { display: block; margin: 4px 0 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 32px; letter-spacing: .04em; }
.timer-card div { display: flex; flex-wrap: wrap; gap: 6px; }
.timer-card .chip { padding: 6px 9px; font-size: 12px; }

.case-card, .ingredient-card, .variable-card { padding: 19px; }
.case-card strong { display: block; margin-top: 12px; color: var(--sage); font-size: 14px; }
.variable-card label > strong { display: block; margin-bottom: 6px; font-size: 19px; }
.variable-card label > span { display: block; color: var(--muted); font-size: 14px; }
.variable-card input { width: 100%; margin: 18px 0 8px; accent-color: var(--sage); }
.variable-card output { margin: 0; min-height: 74px; color: var(--muted); background: var(--paper); font-size: 14px; }

.image-dialog { width: min(900px, calc(100% - 20px)); max-height: calc(100vh - 20px); padding: 12px; border: 0; border-radius: 22px; background: var(--paper); box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.image-dialog::backdrop { background: rgba(24,25,22,.7); backdrop-filter: blur(4px); }
.image-dialog form { display: flex; justify-content: flex-end; padding: 0 4px 8px; }
.image-dialog img { width: 100%; max-height: calc(100vh - 95px); object-fit: contain; }

.settings-button { font-size: 14px; font-weight: 800; }
.settings-dialog { width: min(420px, calc(100% - 20px)); border: 0; border-radius: 22px; background: var(--paper); color: var(--ink); box-shadow: 0 24px 80px rgba(0,0,0,.2); }
.settings-dialog::backdrop { background: rgba(24,25,22,.48); }
.settings-body { padding: 4px 18px 22px; }
.settings-body p { margin: 15px 0 8px; color: var(--muted); font-size: 13px; font-weight: 800; }
.segmented { display: flex; gap: 8px; }
.segmented button { min-height: 40px; flex: 1; border: 1px solid var(--line); border-radius: 12px; background: var(--paper-2); color: var(--ink); cursor: pointer; }
.switch-row { display: flex; align-items: center; gap: 9px; min-height: 44px; }

html[data-font="large"] { font-size: 18px; }
html[data-font="xlarge"] { font-size: 20px; }
html.high-contrast { --paper: #fff; --paper-2: #fff; --ink: #101010; --muted: #343434; --line: rgba(0,0,0,.38); --sage: #1d4c2d; --sage-soft: #d8eadc; --wheat: #875000; --wheat-soft: #ffedc9; }

.status-grid { display: grid; gap: 10px; margin: 22px 0; }
.status-card { padding: 18px; border-radius: 18px; background: var(--paper-2); border: 1px solid var(--line); }
.status-card[data-state="good"] { border-top: 4px solid var(--sage); }
.status-card[data-state="warn"] { border-top: 4px solid var(--wheat); }
.status-card[data-state="bad"] { border-top: 4px solid var(--red); }
.status-card h3 { margin: 0 0 8px; }
.status-card p { margin: 0; color: var(--muted); font-size: 14px; }

.diagnose-layout { display: grid; gap: 18px; padding-bottom: 44px; }
.symptom-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.symptom-button { min-height: 92px; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper-2); color: var(--ink); text-align: left; cursor: pointer; }
.symptom-button strong { display: block; margin-bottom: 4px; }
.symptom-button small { color: var(--muted); }
.symptom-button.active { border-color: var(--wheat); box-shadow: 0 0 0 3px var(--wheat-soft); }
.diagnosis-panel { min-height: 280px; padding: 22px; border-radius: 24px; background: var(--paper-2); border: 1px solid var(--line); }
.diagnosis-panel h2 { margin-top: 0; }
.cause-list { display: grid; gap: 10px; padding: 0; list-style: none; }
.cause-list li { padding: 14px; border-radius: 14px; background: var(--paper); }
.cause-list strong { display: block; color: var(--sage); }
.evidence { margin-top: 18px; padding: 16px; border-radius: 16px; background: var(--sage-soft); }
.evidence h3 { margin: 0 0 8px; }
.evidence ol { margin: 0; padding-left: 1.2em; }

.glossary-card { padding: 18px; }
.glossary-card h2 { margin: 0 0 6px; font-size: 19px; }
.glossary-card p { margin: 0; color: var(--muted); font-size: 14px; }
.glossary-card .alias { display: inline-block; margin-top: 10px; color: var(--wheat); font-size: 12px; font-weight: 700; }

.search-dialog { width: min(680px, calc(100% - 20px)); max-height: min(720px, calc(100vh - 20px)); padding: 0; border: 0; border-radius: 24px; background: var(--paper); color: var(--ink); box-shadow: 0 24px 80px rgba(0,0,0,.2); }
.search-dialog::backdrop { background: rgba(24,25,22,.48); backdrop-filter: blur(4px); }
.search-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 18px 10px; }
.search-head label { font-weight: 800; }
.text-button { border: 0; background: none; color: var(--sage); cursor: pointer; }
#global-search { width: calc(100% - 36px); margin: 0 18px 14px; min-height: 50px; padding: 0 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper-2); }
.search-results { max-height: 55vh; overflow: auto; padding: 0 18px 18px; }
.search-result { display: block; padding: 14px 2px; border-top: 1px solid var(--line); text-decoration: none; }
.search-result strong { display: block; }
.search-result small { color: var(--muted); }
.empty { padding: 34px 10px; color: var(--muted); text-align: center; }

.mobile-nav { position: fixed; z-index: 40; left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); height: 62px; display: grid; grid-template-columns: repeat(4, 1fr); padding: 5px; border: 1px solid var(--line); border-radius: 21px; background: rgba(255,253,248,.94); box-shadow: 0 12px 40px rgba(0,0,0,.16); backdrop-filter: blur(16px); }
.mobile-nav a { display: grid; place-items: center; align-content: center; gap: 1px; border-radius: 16px; color: var(--muted); text-decoration: none; }
.mobile-nav a span { font-size: 18px; line-height: 1; }
.mobile-nav a small { font-size: 10px; }
.mobile-nav a.active { color: var(--sage); background: var(--sage-soft); }

@media (min-width: 680px) {
  .topbar { padding-inline: 28px; }
  .desktop-nav { display: flex; }
  .icon-button { margin-left: 0; }
  .hero { padding-top: 46px; }
  .hero-grid { grid-template-columns: minmax(0, 1fr) minmax(300px, .72fr); }
  .quick-grid { grid-template-columns: repeat(3, 1fr); }
  .principle-grid { grid-template-columns: repeat(3, 1fr); }
  .lesson-grid { grid-template-columns: repeat(2, 1fr); }
  .status-grid { grid-template-columns: repeat(3, 1fr); }
  .glossary-grid { grid-template-columns: repeat(2, 1fr); }
  .diagnose-layout { grid-template-columns: minmax(280px, .8fr) minmax(0, 1.2fr); align-items: start; }
  .diagnosis-panel { position: sticky; top: 92px; }
  .tool-grid { grid-template-columns: repeat(2, 1fr); }
  .atlas-grid, .ingredient-grid, .variable-grid { grid-template-columns: repeat(2, 1fr); }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
  .case-grid { grid-template-columns: repeat(2, 1fr); }
  .timer-grid { grid-template-columns: repeat(3, 1fr); }
  .mobile-nav { display: none; }
  main { padding-bottom: 30px; }
}

@media (min-width: 980px) {
  .lesson-grid { grid-template-columns: repeat(3, 1fr); }
  .glossary-grid { grid-template-columns: repeat(3, 1fr); }
  .atlas-grid, .ingredient-grid, .variable-grid { grid-template-columns: repeat(3, 1fr); }
  .case-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
