:root {
  color-scheme: light;
  --bg: #f7f4ec;
  --paper: #fffdf7;
  --paper-strong: #ffffff;
  --ink: #161616;
  --muted: #60635f;
  --line: #ded8ca;
  --accent: #156f67;
  --accent-strong: #0b4f4a;
  --warm: #b85c38;
  --code-bg: #181c1b;
  --code-text: #f5f2ea;
  --shadow: 0 18px 48px rgba(25, 22, 16, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
  line-height: 1.78;
}

a {
  color: inherit;
}

img {
  max-width: 100%;
  display: block;
}

.progress {
  position: fixed;
  inset: 0 auto auto 0;
  height: 3px;
  width: 0;
  background: var(--accent);
  z-index: 20;
}

.brand {
  font-weight: 800;
  letter-spacing: 0;
  text-decoration: none;
}

.home-header,
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 244, 236, 0.94);
  backdrop-filter: blur(12px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 12;
}

.text-link {
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

.home-nav,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.lang-link {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.92rem;
  text-decoration: none;
}

.lang-link:hover {
  color: var(--accent-strong);
}

.site-footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
}

.notfound {
  max-width: 720px;
  margin: 0 auto;
  padding: 96px 28px;
  text-align: center;
}

.notfound h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
}

.notfound .hero-actions {
  justify-content: center;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 56px;
  align-items: center;
  max-width: 1180px;
  min-height: calc(100vh - 140px);
  margin: 0 auto;
  padding: 72px 28px 56px;
}

.hero-copy {
  max-width: 680px;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--warm);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  line-height: 1.2;
  letter-spacing: 0;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.3rem, 5vw, 5rem);
}

.lead {
  margin: 26px 0 0;
  max-width: 640px;
  color: var(--muted);
  font-size: 1.12rem;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 34px;
}

.button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-weight: 800;
  text-decoration: none;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.button.secondary {
  background: var(--paper);
}

.diagram {
  margin: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.principles,
.contents {
  max-width: 1180px;
  margin: 0 auto;
  padding: 64px 28px;
}

.principles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  padding-top: 0;
}

.principles > div {
  min-height: 210px;
  padding: 26px;
  border: 1px solid var(--line);
  background: var(--paper);
}

.principles span {
  color: var(--warm);
  font-weight: 900;
}

.principles h2,
.section-heading h2 {
  margin: 12px 0;
  font-size: clamp(1.6rem, 3vw, 2.6rem);
}

.principles p,
.chapter-card p {
  margin: 0;
  color: var(--muted);
}

.section-heading {
  max-width: 720px;
  margin-bottom: 24px;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.chapter-card {
  min-height: 220px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  text-decoration: none;
}

.chapter-card:hover {
  border-color: var(--accent);
}

.chapter-card span {
  color: var(--warm);
  font-weight: 900;
}

.chapter-card strong {
  display: block;
  margin: 12px 0 10px;
  font-size: 1.05rem;
  line-height: 1.35;
}

.reader-shell {
  display: grid;
  grid-template-columns: 286px minmax(0, 760px) 230px;
  gap: 34px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 34px 28px 72px;
}

.sidebar,
.toc {
  position: sticky;
  top: 88px;
  align-self: start;
  max-height: calc(100vh - 110px);
  overflow: auto;
}

.chapter-nav {
  display: grid;
  gap: 4px;
}

.chapter-nav a,
.toc a {
  display: block;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}

.chapter-nav a {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  padding: 9px 10px;
  font-size: 0.92rem;
  line-height: 1.35;
}

.chapter-nav a[aria-current="page"] {
  background: var(--paper);
  color: var(--ink);
  font-weight: 800;
}

.chapter-nav span {
  color: var(--warm);
  font-weight: 900;
}

.toc {
  padding-left: 16px;
  border-left: 1px solid var(--line);
}

.toc a {
  padding: 5px 0;
  font-size: 0.86rem;
  line-height: 1.35;
}

.toc-level-3 {
  padding-left: 14px !important;
}

.book {
  min-width: 0;
}

.chapter {
  padding: 42px 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  box-shadow: var(--shadow);
}

.chapter h1 {
  margin: 0 0 30px;
  font-size: clamp(2rem, 4vw, 3.8rem);
}

.chapter h2 {
  margin: 44px 0 14px;
  font-size: 1.65rem;
}

.chapter h3 {
  margin: 30px 0 10px;
  font-size: 1.22rem;
}

.chapter p,
.chapter li {
  color: #2f322f;
  font-size: 1.02rem;
}

.chapter ul,
.chapter ol {
  padding-left: 1.3rem;
}

.chapter code {
  border-radius: 4px;
  background: #efe8d8;
  padding: 0.1rem 0.28rem;
  font-size: 0.92em;
}

.chapter pre {
  overflow: auto;
  margin: 22px 0;
  padding: 18px;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  line-height: 1.55;
}

.chapter pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.chapter blockquote {
  margin: 22px 0;
  padding: 14px 18px;
  border-left: 4px solid var(--accent);
  background: #edf3ee;
  color: #2c423f;
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 52px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.pager a {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  text-decoration: none;
}

.pager a:last-child {
  text-align: right;
}

.icon-button {
  display: none;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  font-weight: 800;
}

@media (max-width: 1080px) {
  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .chapter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .reader-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
  }

  .sidebar {
    position: fixed;
    inset: 64px 0 0 auto;
    z-index: 11;
    width: min(360px, 86vw);
    max-height: none;
    padding: 18px;
    border-left: 1px solid var(--line);
    background: var(--bg);
    transform: translateX(100%);
    transition: transform 180ms ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .toc {
    display: none;
  }
}

@media (max-width: 680px) {
  .home-header,
  .topbar {
    padding: 0 16px;
  }

  .hero,
  .principles,
  .contents,
  .reader-shell {
    padding-left: 16px;
    padding-right: 16px;
  }

  .hero {
    padding-top: 44px;
  }

  .principles,
  .chapter-grid {
    grid-template-columns: 1fr;
  }

  .chapter {
    padding: 28px 20px;
  }

  .pager {
    grid-template-columns: 1fr;
  }

  .pager a:last-child {
    text-align: left;
  }
}
