:root {
  color-scheme: light;
  --paper: #f8f8f3;
  --card: #fffefa;
  --ink: #162e2a;
  --secondary: #53635c;
  --line: #dce2d8;
  --wash: #edf1e7;
  --deep: #153832;
  --bright: #e4ef97;
  --serif: "Instrument Serif", "Noto Serif SC", "Songti SC", STSong, SimSun, serif;
  --sans: "Instrument Sans", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 1.4rem; -webkit-text-size-adjust: 100%; }
body { margin: 0; color: var(--ink); background: var(--paper); font: 16px/1.65 var(--sans); }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
figure, h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid #276c58; outline-offset: 4px; }
.shell { width: min(1160px, calc(100% - 80px)); margin-inline: auto; }
.sr-only, .skip-nav:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-nav:focus { position: absolute; z-index: 5; margin: 10px; padding: 8px 16px; background: var(--card); }

.masthead { border-bottom: 1px solid var(--line); }
.masthead-inner { display: flex; justify-content: space-between; align-items: center; min-height: 74px; gap: 18px; }
.wordmark { display: inline-flex; align-items: center; gap: 11px; font: 750 19px/1.05 var(--sans); letter-spacing: -.035em; }
.wordmark small { display: block; margin-top: 6px; color: var(--secondary); font: 500 11px/1 var(--sans); letter-spacing: .14em; }
.mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--deep); color: var(--bright); font: italic 700 23px/.9 Georgia, serif; }
.masthead nav { display: flex; align-items: center; gap: clamp(16px, 3vw, 38px); font-size: 14px; font-weight: 650; }
.masthead nav a:hover, .text-link:hover, .breadcrumbs a:hover { color: #27705a; }
.nav-search { display: inline-flex; align-items: center; gap: 9px; }
.nav-search span { width: 12px; height: 12px; border: 1.5px solid; border-radius: 50%; position: relative; margin-right: 3px; }
.nav-search span::after { content: ""; width: 5px; height: 1.5px; background: currentColor; position: absolute; right: -4px; bottom: -2px; transform: rotate(48deg); }

.hero { display: grid; grid-template-columns: 1fr minmax(0, .94fr); gap: clamp(30px, 6vw, 82px); align-items: center; padding: 58px 0 55px; }
.eyebrow { display: flex; align-items: center; gap: 8px; color: #3d5d51; font-size: 13px; font-weight: 700; letter-spacing: .12em; }
.eyebrow > span { width: 8px; height: 8px; border-radius: 50%; background: #648769; flex: 0 0 8px; }
.hero h1 { margin-top: 15px; font: 800 clamp(47px, 5.9vw, 84px)/1.08 var(--serif); letter-spacing: -.075em; }
.hero h1 span { display: block; color: #376453; }
.hero-description { margin: 23px 0; color: var(--secondary); line-height: 1.85; }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 15px 24px; }
.button, .text-link { display: inline-flex; align-items: center; gap: 12px; font-size: 14px; font-weight: 700; }
.button.primary { border-radius: 7px; padding: 10px 17px; background: var(--deep); color: #f8f9ef; }
.button.primary:hover { background: #265349; }
.button.primary span { color: var(--bright); }
.text-link { padding: 7px 0; }
.text-link span { color: #427461; }

.hero-figure { background: #143831; color: #f3f7e7; border-radius: 15px; padding: 19px clamp(17px, 2.5vw, 30px) 16px; }
.figure-top, .hero-figure figcaption { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.figure-top { color: #e0eadc; font-size: 13px; font-weight: 600; }
.figure-top span + span { color: #aabfb1; font: italic 16px Georgia, serif; }
#function-graph { display: block; width: 100%; height: clamp(158px, 22vw, 264px); margin: 7px 0 2px; }
.hero-figure figcaption { border-top: 1px solid #3f5f52; padding-top: 10px; }
.hero-formula { font-size: 19px; color: #e6efad; }
.hero-figure a { color: #e0eadc; font-size: 12px; white-space: nowrap; }
.hero-figure a:hover { color: var(--bright); text-decoration: underline; }
.hero-figure :focus-visible { outline-color: var(--bright); }

.library { border-top: 1px solid var(--line); padding: 31px 0 68px; }
.library-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.library-intro h2 { font: 800 32px/1.23 var(--serif); letter-spacing: -.045em; }
.library-intro p { margin-top: 5px; color: var(--secondary); font-size: 14px; }
.search { display: flex; width: min(100%, 350px); gap: 5px; padding: 4px; background: var(--card); border: 1px solid #cfd9cc; border-radius: 8px; }
.search:focus-within { border-color: #568470; }
.search input { width: 100%; min-width: 0; padding: 6px 8px; border: 0; background: transparent; color: var(--ink); font-size: 14px; }
.search input::placeholder { color: #66766b; }
.search button { border: 0; padding: 4px 13px; border-radius: 5px; background: var(--wash); color: var(--ink); font-size: 14px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.search button:hover { background: #dde9d8; }
.chapter-jumps { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 19px; }
.chapter-jumps a, .inline-toc a { padding: 4px 11px; border: 1px solid var(--line); border-radius: 99px; color: #426152; font-size: 13px; }
.chapter-jumps a:hover, .inline-toc a:hover { border-color: #85a290; background: var(--wash); }
.chapter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.chapter-card { background: var(--card); border: 1px solid var(--line); border-radius: 11px; min-width: 0; }
.chapter-card:target { border-color: #65927f; box-shadow: 0 0 0 2px #d9e9da; }
.chapter-card header { padding: 16px 17px 13px; }
.chapter-card h3 { font-size: 19px; line-height: 1.35; font-weight: 750; }
.chapter-card header p { color: var(--secondary); font-size: 13px; margin-top: 5px; }
.chapter-symbol { display: inline-flex; align-items: center; min-width: 40px; min-height: 32px; padding: 2px 7px; margin-bottom: 9px; border-radius: 6px; background: var(--wash); color: #386354; font-size: 15px; }
.chapter-card ul, .side-nav ul, .side-nav ol, .search-results ul { list-style: none; padding: 0; margin: 0; }
.chapter-card li a { position: relative; display: grid; padding: 10px 36px 11px 17px; gap: 2px; border-top: 1px solid var(--line); }
.chapter-card li a:hover { color: #255e4e; background: #f0f5eb; }
.chapter-card li:last-child a { border-radius: 0 0 10px 10px; }
.chapter-card li strong { font-size: 14px; }
.chapter-card li span { color: var(--secondary); font-size: 12px; }
.chapter-card li b { position: absolute; right: 15px; top: 10px; color: #4f7563; font-weight: 500; }

.search-results { margin-top: 15px; padding: 14px 16px; border: 1px solid #cddbcf; border-radius: 9px; background: var(--card); }
.search-results h3 { font-size: 16px; }
.search-results p { font-size: 13px; color: var(--secondary); margin: 2px 0 4px; }
.search-results li + li { border-top: 1px solid var(--line); }
.search-results li a { display: grid; padding: 7px 6px; border-radius: 4px; }
.search-results li a:hover { background: var(--wash); }
.search-results li small { color: var(--secondary); }

.breadcrumbs { display: flex; align-items: center; gap: 8px; margin: 21px 0; color: var(--secondary); font-size: 13px; }
.reading-layout { display: grid; grid-template-columns: minmax(170px, 205px) minmax(0, 780px); gap: clamp(22px, 7vw, 90px); padding-bottom: 68px; }
.lesson-aside { position: sticky; top: 20px; align-self: start; margin-top: 8px; }
.side-nav { margin-bottom: 18px; }
.side-nav h2 { margin-bottom: 7px; font-size: 13px; color: var(--secondary); }
.side-nav a { display: block; padding: 6px 9px; border-radius: 5px; font-size: 13px; }
.side-nav a[aria-current], .side-nav a:hover { background: var(--wash); color: #225645; }
.side-nav a[aria-current] { font-weight: 700; }
.page-toc { border-top: 1px solid var(--line); padding-top: 14px; }
.page-toc a { padding-left: 0; }
.lesson-header { border-bottom: 1px solid var(--line); padding: 8px 0 20px; }
.lesson-header h1 { margin: 9px 0 10px; font: 800 clamp(32px, 4.4vw, 59px)/1.2 var(--serif); letter-spacing: -.055em; }
.lesson-header p:last-child { color: var(--secondary); }
.inline-toc { display: none; }
.lesson-section { padding: 21px 0; }
.lesson-section + .lesson-section { border-top: 1px solid var(--line); }
.lesson-section h2 { font: 800 26px/1.28 var(--serif); }
.lesson-section h3 { margin: 16px 0 4px; font-size: 17px; }
.lesson-section p { margin-top: 9px; }
.lesson-section ul, .lesson-section ol { margin: 9px 0; padding-left: 1.45em; }
.lesson-section li { padding-block: 2px; }
.lesson-section li p { margin: 0; }
.lesson-section blockquote { background: var(--wash); margin: 12px 0; padding: 8px 14px; border-left: 3px solid #789d86; border-radius: 2px 5px 5px 2px; }
.lesson-section blockquote p { margin: 0; }
.math-display { max-width: 100%; overflow-x: auto; overflow-y: hidden; color: #173b31; background: #eef3e9; padding: 5px 13px; margin: 12px 0; border-radius: 7px; }
.math-display .katex-display { margin: .45em 0 .55em; min-width: max-content; }
.math-inline { display: inline; }
.lesson-section .katex { font-size: 1.08em; }
.lesson-section table { max-width: 100%; margin: 12px 0; border-collapse: collapse; }
.lesson-section th, .lesson-section td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
.lesson-section th { background: var(--wash); }
.problem { background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 14px; margin-top: 12px; }
.problem h3 { margin: 0; }
.problem details { margin-top: 11px; border-top: 1px solid var(--line); }
.problem summary { cursor: pointer; padding: 8px 0 2px; color: #295e4d; font-size: 14px; font-weight: 700; }
.problem summary span { margin-left: 4px; }
.solution { padding: 0 0 3px; }
.sequence { border-top: 1px solid var(--line); padding-top: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.sequence a { display: grid; gap: 3px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; }
.sequence a:hover { background: var(--wash); }
.sequence span { color: var(--secondary); font-size: 12px; }
.sequence strong { font-size: 14px; }
.footer { border-top: 1px solid var(--line); color: var(--secondary); font-size: 13px; }
.footer .shell { display: flex; justify-content: space-between; gap: 12px; padding-block: 19px; }
.footer a:hover { text-decoration: underline; }
.footer b { color: #427461; font-weight: 400; }

@media (max-width: 960px) {
  .shell { width: min(1160px, calc(100% - 52px)); }
  .hero { gap: 28px; padding-block: 44px; }
  .hero h1 { font-size: clamp(44px, 6.6vw, 68px); }
  .chapter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 690px) {
  .shell { width: calc(100% - 32px); }
  .masthead-inner { min-height: 61px; }
  .wordmark { font-size: 16px; gap: 8px; }
  .wordmark small { font-size: 9px; }
  .mark { width: 33px; height: 33px; border-radius: 7px; font-size: 20px; }
  .masthead nav { gap: 12px; font-size: 13px; }
  .nav-search span { display: none; }
  .hero { grid-template-columns: minmax(0, 1fr); padding: 28px 0 25px; gap: 22px; }
  .hero h1 { font-size: clamp(42px, 8.9vw, 58px); margin-top: 10px; }
  .hero-description { margin: 14px 0; font-size: 15px; }
  .hero-actions { gap: 10px 17px; }
  .desktop-break { display: none; }
  .hero-figure { padding: 12px 14px 11px; border-radius: 10px; }
  #function-graph { height: 155px; }
  .library { padding: 22px 0 45px; }
  .library-intro { align-items: stretch; flex-direction: column; gap: 10px; }
  .library-intro h2 { font-size: 28px; }
  .search { width: 100%; }
  .search input { font-size: 16px; }
  .chapter-jumps { gap: 6px; margin: 12px 0 14px; }
  .chapter-jumps a { padding: 3px 8px; }
  .chapter-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .breadcrumbs { margin: 14px 0; }
  .reading-layout { grid-template-columns: minmax(0, 1fr); padding-bottom: 36px; }
  .lesson-aside { display: none; }
  .inline-toc { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
  .math-display { padding-inline: 7px; }
}

@media print {
  body { background: white; color: black; }
  .masthead, .footer, .lesson-aside, .inline-toc, .sequence, .breadcrumbs { display: none; }
  .shell { width: 100%; }
  .reading-layout { display: block; padding: 0; }
  .problem { break-inside: avoid; }
}
