:root {
  --bg: #f8f7f3;
  --surface: #ffffff;
  --surface-muted: #f4f2ed;
  --text: #1a1818;
  --muted: #656565;
  --accent: #1a8917;
  --border: #e6e3db;
  --divider-strong: #c29b56;
  --radius: 12px;
  --font-serif: 'Charter', 'Georgia', 'Times New Roman', serif;
  --font-sans: 'Helvetica Neue', Arial, sans-serif;
  --side-width: 260px;
  --main-pad: clamp(3rem, 5vw, 5.5rem);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-serif);
  background: #ffffff;
  color: var(--text);
  line-height: 1.75;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 1.05rem;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  color: var(--accent);
}

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

h1,
h2,
h3,
h4,
h5,
h6,
.section-title {
  font-family: var(--font-serif);
}

h1 {
  margin: 0 0 1.6rem;
}

h2 {
  margin: 0 0 1.4rem;
}

h3,
h4,
h5,
h6 {
  margin: 0 0 1.1rem;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.site-header.navbar {
  padding: 0;
}

.site-header .inner {
  width: min(1500px, 100% - 2rem);
  max-width: 1500px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
}

.logo {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  display: inline-block;
}

@media (min-width: 1200px) {
  .logo {
    min-width: var(--side-width);
    max-width: var(--side-width);
  }

  .site-header .inner {
    display: grid;
    grid-template-columns: var(--side-width) 1fr auto auto;
    align-items: center;
  }
}

.primary-nav {
  width: 100%;
}

.primary-nav .navbar-nav {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
}

.primary-nav .nav-link {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 0.35rem 0.6rem;
  color: var(--muted);
  border-radius: 8px;
}

.primary-nav .nav-link.active {
  color: var(--text);
  font-weight: 600;
}

.download-btn {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.nav-download-btn {
  width: 100%;
  max-width: 260px;
  margin-left: 0 !important;
  margin-right: 0 !important;
  justify-content: flex-start;
  text-align: left;
}

.download-btn:hover {
  color: #fff;
  background: #157313;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.download-btn span {
  font-size: inherit;
  opacity: 0.9;
}

.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
}

.language-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.3rem;
  min-width: 130px;
  justify-content: space-between;
}

.language-toggle__btn {
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  flex: 1 1 0;
  text-align: center;
}

.language-toggle__btn:hover {
  color: var(--text);
}

.language-toggle__btn.is-active {
  background: var(--text);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.layout {
  width: min(1500px, 100% - 2rem);
  max-width: 1500px;
  margin: 0 auto;
  flex: 1;
  padding: 2rem 0 4rem;
}

.main-content {
  padding: 0 var(--main-pad) 1rem;
  border-right: 1px solid var(--border);
  background: transparent;
}

.chapter-sidebar,
.progress-sidebar {
  align-self: start;
  position: sticky;
  top: 96px;
  background: transparent;
  font-family: var(--font-serif);
}

.chapter-sidebar {
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  padding-right: 1.5rem;
}

.chapter-sidebar::-webkit-scrollbar {
  width: 6px;
}

.chapter-sidebar::-webkit-scrollbar-thumb {
  background: #c8c8c8;
  border-radius: 999px;
}

.chapter-links,
.sub-chapter-links,
.progress-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.chapter-links a,
.chapter-links span {
  color: var(--muted);
  font-size: 0.95rem;
  display: block;
  padding: 0.25rem 0.3rem;
  border-radius: 8px;
}

.chapter-links > li {
  margin-bottom: 1rem;
}

.chapter-links > li:last-child {
  margin-bottom: 0;
}

.chapter-parent {
  font-family: var(--font-serif);
  font-weight: 400;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.chapter-links a:hover,
.progress-list a:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.chapter-links a.current {
  color: var(--accent);
  background: var(--surface-muted);
  box-shadow: inset 0 0 0 1px rgba(239, 227, 206, 0.8);
}

.sub-chapter-links {
  margin-left: 0.8rem;
  border-left: 1px solid var(--border);
  padding-left: 0.8rem;
  gap: 0.4rem;
}

.sub-chapter-links li {
  margin-bottom: 0.6rem;
}

.sub-chapter-links li:last-child {
  margin-bottom: 0;
}

.progress-sidebar {
  padding-left: 1.5rem;
}

.progress-sidebar h2 {
  font-size: 0.9rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #9a9384;
  margin-top: 0;
}

.progress-list a {
  color: var(--muted);
  font-size: 0.9rem;
  display: block;
  padding: 0.25rem 0.3rem;
  border-radius: 8px;
}

.progress-list a.is-active {
  color: var(--accent);
  font-weight: 600;
}

.progress-meter {
  margin-top: 1rem;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-meter-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
}

.content-section + .content-section {
  margin-top: 3rem;
}

.section-label {
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-size: 0.8rem;
  color: #a7a29a;
  font-weight: 600;
}

.section-title {
  margin: 0.4rem 0 1.2rem;
  font-size: 2.1rem;
  font-weight: 600;
}

.section-intro {
  color: var(--muted);
}

.card-grid,
.structure-map,
.stat-grid,
.link-grid,
.example-list {
  display: grid;
  gap: 1rem;
}

.card-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.structure-map,
.link-grid,
.example-list {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.info-card,
.structure-card,
.link-card,
.example-card,
.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  background: var(--surface);
}

.info-card h3,
.structure-card h3,
.example-card h3 {
  margin-top: 0;
}

.stat-card {
  text-align: center;
}

.stat-card strong {
  font-size: 1.6rem;
  display: block;
  margin-bottom: 0.2rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 1rem 0;
}

.tag {
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: var(--surface-muted);
  font-size: 0.85rem;
  color: var(--muted);
}

blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.2rem;
  border-left: 3px solid var(--border);
  background: var(--surface-muted);
  border-radius: 6px;
  font-style: italic;
}

pre,
code {
  font-family: 'JetBrains Mono', 'Fira Code', 'SFMono-Regular', Menlo, Consolas, monospace;
  /* background: var(--surface-muted); */
  border-radius: 8px;
}

pre {
  padding: 1rem;
  overflow-x: auto;
}

code {
  padding: 0.15rem 0.3rem;
}

body[data-page='ai-scientist'] pre,
body[data-page='ai-scientist'] code {
  background: transparent;
  border: none;
  box-shadow: none;
  color: #2a2f45;
  font-family: 'JetBrains Mono', 'Fira Code', 'SFMono-Regular', Menlo, Consolas, monospace;
}

body[data-page='ai-scientist'] pre {
  padding: 0.85rem 0;
  border: none;
}

body[data-page='ai-scientist'] pre code {
  padding: 0;
}

body[data-page='ai-scientist'] .token.keyword {
  color: #c678dd;
}

body[data-page='ai-scientist'] .token.function {
  color: #61afef;
}

body[data-page='ai-scientist'] .token.string {
  color: #98c379;
}

body[data-page='ai-scientist'] .token.variable {
  color: #e5c07b;
}

body[data-page='ai-scientist'] .token.number {
  color: #d19a66;
}

.table-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  margin-top: 1rem;
}

table th,
table td {
  border: 1px solid var(--border);
  padding: 0.65rem;
  text-align: left;
}

table th {
  background: var(--surface-muted);
}

.hero-banner {
  padding: 0;
  background: transparent;
}

.hero-figure {
  margin-top: 2.5rem;
}

.hero-figure img {
  width: 100%;
  display: block;
  border-radius: var(--radius);
}

.hero-figure figcaption {
  font-size: 1.0rem;
  color: var(--muted);
  padding: 0.75rem 0;
}

.capability-lede {
  margin: 1.8rem 0 0;
  color: var(--muted);
}

.citation-block {
  margin-top: 3rem;
  padding: 1.5rem;
  background: var(--surface-muted);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.citation-block pre,
.citation-block code {
  background: transparent;
  border: none;
  box-shadow: none;
  color: #2a2f45;
  font-family: 'JetBrains Mono', 'Fira Code', 'SFMono-Regular', Menlo, Consolas, monospace;
}

.citation-block pre {
  margin: 1rem 0 0;
  padding: 0.85rem 0;
  font-size: 0.95rem;
}

.citation-block code {
  padding: 0;
}

.citation-intro {
  margin-top: 4rem;
  font-weight: 400;
}

.resource-links {
  display: flex;
  gap: 1rem;
  margin: 0.5rem 0 1.5rem;
}

.resource-link {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
}

.overview-highlight {
  background: var(--surface-muted);
  border-left: 3px solid var(--accent);
  padding: 1.2rem 1.5rem;
  border-radius: var(--radius);
  margin-top: 1rem;
}

.detail-box {
  border: 2px solid var(--border);
  border-radius: 12px;
  margin: 1.5rem 0;
  padding: 1.2rem 1.4rem;
  background: #fffdfa;
}

.detail-box--has-divider {
  padding: 0;
}

.detail-box h4 {
  margin: 0 0 0.8rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.detail-box--has-divider h4 {
  margin: 0;
}

.detail-box--has-divider .detail-box__header {
  background: var(--surface-muted);
  border-bottom: 2px solid var(--border);
  border-top-left-radius: calc(var(--radius) - 2px);
  border-top-right-radius: calc(var(--radius) - 2px);
  padding: 0.85rem 1.4rem;
}

.detail-box--has-divider .detail-box__body {
  padding: 1.2rem 1.4rem 1.4rem;
}

.detail-box p {
  margin: 0.35rem 0;
}

.detail-divider {
  border: 0;
  border-top: 2px solid var(--border);
  margin: 1rem 0;
}

.detail-box .detail-divider {
  border-top: 2px solid var(--divider-strong);
  margin: 1.1rem 0;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
}

.section-title {
  margin: 0.2rem 0 1.6rem;
  font-size: 2.6rem;
  font-weight: 600;
}

.content-section h2.section-title {
  font-size: 2rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
  margin-bottom: 1.6rem;
}

.example-box {
  margin: 1.5rem 0;
  padding: 1.2rem 1.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.example-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: #9a9384;
  margin: 0 0 0.6rem;
}

.page-nav {
  margin-top: 3rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}

.page-nav-btn {
  font-size: 0.95rem;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text);
}

.page-nav-btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .chapter-sidebar,
  .progress-sidebar {
    position: static;
    max-height: none;
    border: none;
    padding: 0 var(--main-pad);
  }

  .main-content {
    border-left: none;
    border-right: none;
    padding: 0 var(--main-pad) 1rem;
  }
}

@media (max-width: 991.98px) {
  .site-header .inner {
    flex-wrap: wrap;
    width: min(1400px, 100% - 1.5rem);
    position: relative;
  }

  #mainNav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 10;
    background: #fff;
    padding: 0.75rem 1rem 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.1);
    will-change: height;
  }

  .primary-nav {
    padding: 0;
    background: transparent;
  }

  .primary-nav .navbar-nav {
    align-items: flex-start;
    flex-direction: column;
  }

  .primary-nav .nav-link {
    padding: 0.5rem 0;
  }

  .download-btn {
    justify-content: center;
  }

  .nav-download-btn {
    width: 100%;
    max-width: none;
  }

  .main-content {
    border-right: none;
    padding: 0 var(--main-pad) 1rem;
  }
}

@media (min-width: 1200px) {
  .chapter-sidebar,
  .progress-sidebar {
    flex: 0 0 var(--side-width);
    max-width: var(--side-width);
    width: var(--side-width);
  }

  .main-content {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: calc(100% - (2 * var(--side-width)));
  }
}
