:root {
  --bg: #f4f1ea;
  --paper: #fffdf8;
  --paper-2: #f9f4ea;
  --ink: #1b1b18;
  --muted: #69665e;
  --line: #ded5c5;
  --line-strong: #c4b59d;
  --accent: #0f766e;
  --accent-2: #b45309;
  --danger: #a32020;
  --danger-bg: #fff1ed;
  --note-bg: #edf7f5;
  --tip-bg: #fff8df;
  --shadow: 0 18px 50px rgba(31, 27, 18, 0.16);
  --radius: 8px;
  --sidebar: 330px;
  color-scheme: light;
}

body.dark {
  --bg: #111315;
  --paper: #191c1e;
  --paper-2: #202427;
  --ink: #f3efe4;
  --muted: #c8bfae;
  --line: #36322c;
  --line-strong: #5a5044;
  --accent: #4db6ac;
  --accent-2: #f0a044;
  --danger: #ff8b7e;
  --danger-bg: #351f1d;
  --note-bg: #152928;
  --tip-bg: #302817;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  color-scheme: dark;
}

* {
  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", sans-serif;
  line-height: 1.6;
}

.menu-toggle-input {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.menu-trigger,
.menu-close,
.site-menu-backdrop {
  cursor: pointer;
}

.site-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgba(8, 11, 12, 0.62);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.site-menu {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 40;
  width: min(440px, 94vw);
  height: 100vh;
  overflow-y: auto;
  background: var(--paper);
  color: var(--ink);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 0.2s ease;
}

#menuToggle:checked ~ .site-menu-backdrop {
  opacity: 1;
  pointer-events: auto;
}

#menuToggle:checked ~ .site-menu {
  transform: translateX(0);
}

.site-menu-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.site-menu-head h2 {
  margin: 2px 0 0;
  font-size: 1.65rem;
  line-height: 1.1;
}

.menu-kicker {
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.menu-close {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  color: var(--ink);
  font-size: 1.65rem;
  line-height: 1;
}

.site-menu-links {
  display: grid;
  padding: 10px 18px 24px;
}

.site-menu-links a {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  column-gap: 10px;
  padding: 14px 4px;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

.site-menu-links a:hover {
  color: var(--accent);
}

.site-menu-links span {
  grid-row: 1 / 3;
  color: var(--accent-2);
  font-weight: 800;
}

.site-menu-links strong,
.site-menu-links small {
  min-width: 0;
}

.site-menu-links small {
  color: var(--muted);
  line-height: 1.35;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 20;
  transform: translateY(-80px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.skip-link:focus {
  transform: translateY(0);
}

.hero {
  position: relative;
  min-height: 88vh;
  display: grid;
  align-items: end;
  overflow: hidden;
  isolation: isolate;
  color: #fffdf8;
}

.hero-image,
.hero-shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hero-image {
  object-fit: cover;
  z-index: -3;
}

.hero-shade {
  z-index: -2;
  background:
    linear-gradient(90deg, rgba(8, 11, 12, 0.88), rgba(8, 11, 12, 0.48) 48%, rgba(8, 11, 12, 0.18)),
    linear-gradient(0deg, rgba(8, 11, 12, 0.88), rgba(8, 11, 12, 0.1) 56%);
}

.topbar {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 22px clamp(18px, 4vw, 54px);
}

.brand,
.top-actions,
.hero-buttons,
.toolbar-actions,
.quick-panel {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.13);
  backdrop-filter: blur(12px);
}

.icon-button,
.tool-button,
.button {
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  border-radius: var(--radius);
  min-height: 42px;
  padding: 0 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(14px);
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 20px;
}

.icon-button.small {
  width: 34px;
  min-height: 34px;
  border-color: var(--line);
  background: var(--paper-2);
  color: var(--muted);
}

.button.primary {
  background: #f0a044;
  color: #1b1208;
  border-color: transparent;
  font-weight: 800;
}

.hero-content {
  width: min(930px, calc(100% - 36px));
  padding: 0 0 clamp(62px, 12vh, 120px) clamp(18px, 6vw, 86px);
}

.eyebrow,
.toolbar-kicker {
  margin: 0 0 12px;
  color: #f0a044;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  max-width: 820px;
  font-size: clamp(3rem, 9vw, 7.5rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.hero-copy {
  max-width: 680px;
  margin: 24px 0 28px;
  color: rgba(255, 253, 248, 0.88);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--paper);
  border-right: 1px solid var(--line);
  overflow: auto;
  z-index: 8;
}

.sidebar-inner {
  padding: 22px;
}

.search-label {
  display: block;
  margin: 0 0 8px;
  color: var(--muted);
  font-weight: 750;
  font-size: 0.88rem;
}

.search-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

#searchInput {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--paper-2);
  color: var(--ink);
}

.quick-panel {
  flex-wrap: wrap;
  margin: 16px 0 18px;
}

.quick-panel a {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.86rem;
  background: var(--paper-2);
}

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

.chapter-nav a {
  display: block;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.93rem;
}

.chapter-nav a:hover,
.chapter-nav a.active {
  color: var(--ink);
  background: var(--note-bg);
}

.reader {
  min-width: 0;
  padding: clamp(18px, 4vw, 52px);
}

.reader-toolbar {
  display: flex;
  gap: 24px;
  align-items: end;
  justify-content: space-between;
  margin: 0 auto 22px;
  max-width: 1160px;
}

.reader-toolbar h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3.6rem);
  line-height: 1;
}

.toolbar-kicker {
  color: var(--accent-2);
}

.toolbar-actions {
  justify-content: end;
  flex-wrap: wrap;
}

.tool-button {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
  min-height: 40px;
}

.status-card,
.search-results,
.chapter {
  max-width: 1160px;
  margin: 0 auto 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.status-card {
  padding: 18px 20px;
  display: grid;
  gap: 4px;
}

.status-card span {
  color: var(--muted);
}

.search-results {
  padding: 18px;
}

.search-result-list {
  display: grid;
  gap: 10px;
}

.search-result {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-2);
  text-decoration: none;
}

.search-result strong {
  color: var(--accent);
}

.search-result span {
  color: var(--muted);
}

.chapter {
  overflow: hidden;
}

.chapter > summary {
  list-style: none;
  cursor: pointer;
  padding: 22px clamp(18px, 3vw, 34px);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid transparent;
}

.chapter > summary::-webkit-details-marker {
  display: none;
}

.chapter[open] > summary {
  border-bottom-color: var(--line);
}

.chapter-title {
  margin: 0;
  font-size: clamp(1.35rem, 2.5vw, 2.15rem);
  line-height: 1.15;
}

.chapter-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.chevron {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--paper-2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.chapter[open] .chevron {
  transform: rotate(180deg);
}

.chapter-body {
  padding: 8px clamp(18px, 3vw, 34px) 34px;
}

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

.chapter-body h4 {
  margin: 22px 0 8px;
  font-size: 1.08rem;
}

.chapter-body p,
.chapter-body ul,
.chapter-body ol {
  max-width: 860px;
}

.chapter-body a {
  color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.chapter-body blockquote {
  margin: 18px 0;
  max-width: 900px;
  border-left: 5px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--note-bg);
  padding: 15px 18px;
}

.chapter-body blockquote.warning {
  border-left-color: var(--danger);
  background: var(--danger-bg);
}

.chapter-body blockquote.tip {
  border-left-color: var(--accent-2);
  background: var(--tip-bg);
}

.chapter-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0 24px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: block;
  overflow-x: auto;
}

.chapter-body th,
.chapter-body td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  min-width: 130px;
}

.chapter-body th {
  color: var(--ink);
  background: var(--paper-2);
}

.chapter-body code {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
}

.chapter-body pre {
  max-width: 900px;
  overflow: auto;
  background: #171717;
  color: #f9f4ea;
  border-radius: var(--radius);
  padding: 16px;
}

.back-to-top {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 12;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

mark {
  background: #ffe08a;
  color: #261800;
  border-radius: 4px;
  padding: 0 2px;
}

@media (max-width: 980px) {
  .hero {
    min-height: 84vh;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(88vw, 360px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

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

  .reader-toolbar {
    display: grid;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 16px;
  }

  .hero-content {
    width: 100%;
    padding: 0 18px 42px;
  }

  .hero-buttons,
  .toolbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .button,
  .tool-button {
    width: 100%;
  }

  .reader {
    padding: 18px 12px 36px;
  }

  .chapter > summary {
    padding: 18px 16px;
  }

  .chapter-body {
    padding: 6px 16px 24px;
  }
}

@media print {
  .hero,
  .sidebar,
  .reader-toolbar,
  .back-to-top,
  .search-results,
  .status-card {
    display: none !important;
  }

  .app-shell,
  .reader {
    display: block;
    padding: 0;
  }

  body {
    background: #fff;
    color: #000;
  }

  .chapter {
    box-shadow: none;
    border: 0;
    page-break-after: always;
  }

  .chapter:not(.print-target) {
    display: none;
  }

  body.print-all .chapter {
    display: block;
  }

  .chapter > summary {
    display: block;
    padding: 0 0 10px;
  }

  .chevron,
  .chapter-meta {
    display: none;
  }

  .chapter-body {
    padding: 0;
  }
}
