:root {
  --bg: #f7f4ed;
  --paper: #fffefa;
  --ink: #20211f;
  --muted: #6b6a63;
  --line: #e3ded2;
  --accent: #b45309;
  --accent-2: #0f766e;
  --accent-soft: #fff3e0;
  --code: #f2eee5;
  --shadow: 0 24px 60px rgba(60, 40, 20, .12);
  --max: 1120px;
  --prose: 760px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --paper: #1a1b1e;
    --ink: #f1efe9;
    --muted: #a7a49b;
    --line: #303136;
    --accent: #f2a35e;
    --accent-2: #5eead4;
    --accent-soft: #2a2118;
    --code: #24252a;
    --shadow: 0 24px 60px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  background:
    radial-gradient(900px 520px at 8% -8%, rgba(180, 83, 9, .10), transparent 62%),
    radial-gradient(800px 520px at 100% 0%, rgba(15, 118, 110, .08), transparent 62%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 17px;
  line-height: 1.85;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
::selection { background: var(--accent); color: #fff; }

.progress {
  display: none;
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 100;
  background: linear-gradient(90deg, var(--accent), #f59e0b, var(--accent-2));
  transform-origin: 0 50%;
  transform: scaleX(0);
}
@supports (animation-timeline: scroll()) {
  .progress {
    display: block;
    animation: reading-progress linear;
    animation-timeline: scroll(root block);
  }
}
@keyframes reading-progress {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 80;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
@supports (background: color-mix(in srgb, #fff 80%, transparent)) {
  .topbar {
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }
}
.topbar-inner {
  max-width: var(--max);
  flex-wrap: wrap;
  margin: 0 auto;
  padding: 13px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: .01em;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-size: 9px;
  letter-spacing: .08em;
}
.topbar-links { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; min-width: 0; font-size: 14px; }
.topbar-links a { color: var(--muted); text-decoration: none; }
.topbar-links a:hover { color: var(--accent); }

.hero {
  max-width: var(--max);
  margin: 0 auto;
  padding: 82px 24px 54px;
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(260px, .88fr);
  gap: 56px;
  align-items: center;
}
.hero-copy { min-width: 0; }
.badge {
  display: inline-block;
  margin: 0 0 18px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .06em;
}
.hero h1 {
  margin: 0;
  font-size: clamp(42px, 6.4vw, 76px);
  line-height: 1.04;
  letter-spacing: -.045em;
  font-weight: 800;
  text-wrap: balance;
}
.subtitle {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: clamp(20px, 2.3vw, 28px);
  line-height: 1.35;
}
.lede {
  max-width: 34em;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.8;
}
.chips {
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
}
.chips li {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.actions { max-width: 100%; display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: transform .16s ease, border-color .16s ease;
}
.button:hover { transform: translateY(-1px); border-color: var(--accent); }
.button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.button.primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.hero-cover { display: flex; justify-content: center; }
.cover {
  position: relative;
  width: min(100%, 350px);
  aspect-ratio: 3 / 4;
  display: flex;
  flex-direction: column;
  padding: 0;
  border-radius: 5px 18px 18px 5px;
  background: #080909;
  color: #f8f1e7;
  border: 1px solid rgba(235, 184, 122, .18);
  box-shadow: var(--shadow), 0 2px 0 rgba(255,255,255,.16) inset;
  transform: rotate(2.4deg);
  overflow: hidden;
}
.cover::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, .16);
  z-index: 5;
}
.cover-art {
  position: relative;
  flex: 0 0 56%;
  background:
    linear-gradient(180deg, rgba(6, 7, 7, .08) 0%, transparent 55%, rgba(6, 7, 7, .40) 100%),
    url("cover-v1.webp") center 38% / cover no-repeat,
    #080909;
  border-bottom: 1px solid rgba(240, 180, 123, .26);
}
.cover-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(255,255,255,.018) 28px),
    radial-gradient(220px 180px at 80% 20%, rgba(240, 169, 94, .08), transparent 72%);
  pointer-events: none;
}
.cover-label {
  position: absolute;
  top: 24px;
  left: 32px;
  z-index: 2;
  color: #e0ad74;
  font-size: 9px;
  letter-spacing: .22em;
  text-transform: uppercase;
  text-shadow: 0 1px 8px rgba(0,0,0,.7);
}
.cover-copy {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 22px 14px 34px;
  background: linear-gradient(180deg, #0b0c0b 0%, #080909 100%);
}
.cover-title {
  margin: 0;
  font-size: clamp(26px, 3.2vw, 32px);
  line-height: 1.02;
  letter-spacing: -.035em;
  font-weight: 800;
}
.cover-title em { color: #f0b47b; font-style: normal; }
.cover-sub {
  margin-top: 8px;
  color: #c3b09d;
  font-size: 11px;
  line-height: 1.5;
}
.cover-foot {
  margin-top: auto;
  padding-top: 9px;
  border-top: 1px solid rgba(255, 255, 255, .14);
  color: #9d8d7d;
  font-size: 9px;
  letter-spacing: .08em;
}

.layout {
  max-width: var(--max);
  margin: 0 auto;
  padding: 18px 24px 72px;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 58px;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 84px;
  min-width: 0;
}
.sidebar-inner {
  max-height: calc(100vh - 108px);
  overflow: auto;
  padding: 4px 16px 18px 0;
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}
.sidebar-kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.sidebar h2 {
  margin: 0 0 14px;
  font-size: 17px;
  letter-spacing: -.01em;
}
.chapter-list { margin: 0; padding: 0; list-style: none; }
.chapter-list li { margin: 2px 0; }
.chapter-list a {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 6px 8px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-decoration: none;
}
.chapter-list a:hover { background: var(--accent-soft); color: var(--ink); }
.chapter-list .num {
  flex: 0 0 1.7em;
  color: var(--accent);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
}
.sidebar-note {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.book {
  min-width: 0;
  max-width: var(--prose);
  font-size: 17.5px;
  line-height: 1.92;
}
.book h1 {
  position: relative;
  margin: 4.2rem 0 1rem;
  padding: 1.5rem 0 0 20px;
  border-top: 1px solid var(--line);
  font-size: clamp(28px, 3.8vw, 38px);
  line-height: 1.3;
  letter-spacing: -.025em;
  scroll-margin-top: 96px;
}
.book h1::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1.55rem;
  bottom: .2rem;
  width: 4px;
  border-radius: 2px;
  background: var(--accent);
}
.book h1:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.book h1:first-child::before { top: .2rem; }
.book h2 {
  margin: 2.6rem 0 .8rem;
  font-size: clamp(22px, 2.6vw, 27px);
  line-height: 1.35;
  letter-spacing: -.015em;
  scroll-margin-top: 96px;
}
.book h3 { margin: 1.8rem 0 .6rem; font-size: 19px; line-height: 1.45; }
.book p { margin: .9rem 0; }
.book ul, .book ol { padding-left: 1.55em; }
.book li { margin: .35rem 0; }
.book strong { font-weight: 700; }
.book blockquote {
  margin: 1.3rem 0;
  padding: 12px 18px;
  border-left: 4px solid var(--accent);
  border-radius: 0 9px 9px 0;
  background: var(--accent-soft);
}
.book blockquote p { margin: .3rem 0; }
.book code {
  padding: .15em .35em;
  border-radius: 5px;
  background: var(--code);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: .88em;
}
.book pre {
  margin: 1.15rem 0;
  padding: 17px 18px;
  overflow-x: auto;
  background: var(--code);
  border: 1px solid var(--line);
  border-radius: 11px;
  line-height: 1.55;
}
.book pre code { padding: 0; background: transparent; font-size: 13.5px; }
.book pre, .book table { max-width: 100%; }
.book table {
  display: block;
  width: 100%;
  margin: 1.25rem 0;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 14.5px;
  line-height: 1.65;
}
.book th, .book td {
  padding: 9px 11px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.book th { background: var(--code); white-space: nowrap; font-weight: 600; }
.book tr:nth-child(even) td { background: color-mix(in srgb, var(--code) 42%, transparent); }
.book hr { margin: 2.8rem 0; border: 0; border-top: 1px solid var(--line); }
.book img { max-width: 100%; height: auto; border-radius: 8px; }
.chapter-meta {
  margin: 8px 0 1.5rem 20px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .03em;
}
.chapter { margin-bottom: 1.8rem; }
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 40px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.pager a {
  display: block;
  min-width: 0;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.45;
  transition: border-color .16s ease, transform .16s ease;
}
.pager a:hover { border-color: var(--accent); transform: translateY(-1px); }
.pager small { display: block; margin-bottom: 3px; color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.pager .next { text-align: right; grid-column: 2; }
.pager .next span { display: block; }
.pager .prev span { display: block; }
.chapter-list a span:last-child { min-width: 0; overflow-wrap: anywhere; }

footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 28px 24px 56px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}
footer p { margin: .35rem 0; }
footer a { color: var(--muted); }
footer a:hover { color: var(--accent); }

.top-link {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  font-size: 19px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
  z-index: 60;
}
.top-link:hover { border-color: var(--accent); color: var(--accent); }

@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; gap: 36px; padding-top: 56px; }
  .hero-cover { display: flex; order: 2; margin-top: 4px; }
  .cover { width: min(72vw, 300px); transform: rotate(1.4deg); }
  .layout { grid-template-columns: 1fr; gap: 34px; }
  .sidebar { position: static; }
  .sidebar-inner {
    max-height: none;
    overflow: visible;
    padding: 0 0 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .chapter-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2px 14px;
  }
  .sidebar-note { display: none; }
}
@media (max-width: 620px) {
  body { font-size: 16px; }
  .topbar-inner { padding: 11px 16px; }
  .topbar-links { gap: 12px; }
  .topbar-links a:nth-child(2) { display: none; }
  .hero { padding: 40px 16px 38px; }
  .hero h1 { font-size: clamp(36px, 11vw, 54px); }
  .layout { padding: 8px 16px 48px; }
  .book { font-size: 16.5px; }
  .chapter-list { grid-template-columns: 1fr; }
  .book table { font-size: 13.5px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: auto; }
  .top-link { right: 12px; bottom: 12px; width: 38px; height: 38px; }
  footer { padding-left: 16px; padding-right: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .progress { display: none; }
}
@media print {
  :root {
    --bg: #fff; --paper: #fff; --ink: #000; --muted: #444;
    --line: #ccc; --code: #f2f2f2; --accent: #000;
  }
  body { background: #fff; font-size: 11pt; }
  .topbar, .progress, .sidebar, .hero-cover, .top-link, .pager { display: none; }
  .hero { display: block; padding: 0 0 12mm; }
  .hero h1 { font-size: 28pt; }
  .layout { display: block; padding: 0; }
  .book { max-width: none; font-size: 11pt; }
  .book h1 { break-before: page; }
  .book h1:first-child { break-before: auto; }
  .book h1::before { display: none; }
  .book a { color: #000; text-decoration: none; }
  .book pre, .book table { break-inside: avoid; }
}

/* --- Landing page and per-chapter navigation --- */
.landing {
  max-width: var(--max);
  margin: 0 auto;
  padding: 12px 24px 72px;
}
.landing-section { margin-top: 54px; }
.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}
.section-heading h2 {
  margin: 0;
  font-size: clamp(24px, 3vw, 32px);
  letter-spacing: -.02em;
}
.section-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.book-map {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.chapter-card {
  display: flex;
  flex-direction: column;
  min-height: 156px;
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.chapter-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 10px 28px rgba(60, 40, 20, .08);
}
.chapter-card .num {
  color: var(--accent);
  font-size: 10px;
  letter-spacing: .14em;
  font-variant-numeric: tabular-nums;
}
.chapter-card h3 {
  margin: 10px 0 0;
  font-size: 18px;
  line-height: 1.35;
  letter-spacing: -.01em;
}
.chapter-card p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.chapter-card .meta {
  margin-top: auto;
  padding-top: 14px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .03em;
}
.chapter-card.appendix { background: var(--code); }
.reading-paths {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.path {
  padding: 18px;
  border-top: 2px solid var(--accent);
  background: var(--paper);
  border-radius: 0 0 10px 10px;
}
.path strong { display: block; font-size: 15px; }
.path span { display: block; margin-top: 8px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.about-book {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 28px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
}
.about-book p { margin: 0; color: var(--muted); line-height: 1.8; }
.about-book .about-meta { font-size: 13px; }
.breadcrumb {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.chapter-list a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--ink);
  box-shadow: inset 3px 0 0 var(--accent);
}
.lang-switch { font-weight: 600; color: var(--ink) !important; }
@media (max-width: 900px) {
  .book-map { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reading-paths { grid-template-columns: 1fr; }
  .about-book { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .landing { padding: 8px 16px 48px; }
  .hero-cover { margin-top: 0; }
  .cover { width: min(70vw, 280px); }
  .cover-copy { padding: 12px 16px 10px 28px; }
  .cover-title { font-size: 25px; }
  .cover-sub { font-size: 10px; }
  .cover-label { top: 18px; left: 26px; font-size: 8px; }
  .landing-section { margin-top: 38px; }
  .section-heading { display: block; }
  .section-heading p { margin-top: 6px; }
  .book-map { grid-template-columns: 1fr; }
  .chapter-card { min-height: 0; }
}

/* --- Cognition article --- */
.series-kicker {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.page-head {
  max-width: 820px;
  margin: 46px auto 0;
  padding: 0 24px;
}
.page-head h1 {
  margin: 0;
  font-size: clamp(36px, 5.5vw, 62px);
  line-height: 1.06;
  letter-spacing: -.045em;
}
.page-head .lede { max-width: 720px; }
.cognition-body {
  max-width: 820px;
  margin: 24px auto 0;
  padding: 0 24px;
}
.cognition-body h2 { margin-top: 2.4em; }
.cognition-body h2:first-child { margin-top: 1em; }
.cognition-card { max-width: 760px; }
@media (max-width: 620px) {
  .page-head { margin-top: 26px; padding: 0 16px; }
  .cognition-body { padding: 0 16px; }
}
