/* ===== Design tokens — claude.com palette ===== */
:root, :root[data-theme="light"] {
  /* surfaces */
  --canvas: #faf9f5;
  --surface-soft: #f5f0e8;
  --surface-card: #efe9de;
  --surface-cream-strong: #e8e0d2;
  --surface-dark: #181715;
  --surface-dark-elevated: #252320;
  --surface-dark-soft: #1f1e1b;
  /* text */
  --ink: #141413;
  --body-strong: #252523;
  --body: #3d3d3a;
  --muted: #6c6a64;
  --muted-soft: #8e8b82;
  --on-primary: #ffffff;
  --on-dark: #faf9f5;
  --on-dark-soft: #a09d96;
  /* brand */
  --primary: #cc785c;
  --primary-active: #a9583e;
  --primary-disabled: #e6dfd8;
  --accent-teal: #5db8a6;
  --accent-amber: #e8a55a;
  --success: #5db872;
  --warning: #d4a017;
  --error: #c64545;
  /* borders */
  --hairline: #e6dfd8;
  --hairline-soft: #ebe6df;
  /* radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-pill: 9999px;
  /* spacing */
  --s-xxs: 4px;
  --s-xs: 8px;
  --s-sm: 12px;
  --s-md: 16px;
  --s-lg: 24px;
  --s-xl: 32px;
  --s-xxl: 48px;
  --s-section: 96px;
  /* fonts */
  --font-display: "Manrope", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

:root[data-theme="dark"] {
  --canvas: #181715;
  --surface-soft: #1f1e1b;
  --surface-card: #252320;
  --surface-cream-strong: #2a2825;
  --surface-dark: #0f0e0c;
  --surface-dark-elevated: #1a1815;
  --surface-dark-soft: #141311;
  --ink: #faf9f5;
  --body-strong: #ebe6df;
  --body: #a09d96;
  --muted: #8e8b82;
  --muted-soft: #6c6a64;
  --hairline: #2a2825;
  --hairline-soft: #1f1e1b;
  /* coral and accents stay same — brand signal */
}

/* ===== Reset & base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--body);
  background: var(--canvas);
  min-height: 100vh;
  transition: background 0.2s ease, color 0.2s ease;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-active); }
img, svg { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
code, pre { font-family: var(--font-mono); }

/* ===== Typography ===== */
.display-xl { font-family: var(--font-display); font-weight: 800; font-size: 64px; line-height: 1.05; letter-spacing: -1.5px; color: var(--ink); }
.display-lg { font-family: var(--font-display); font-weight: 800; font-size: 48px; line-height: 1.1; letter-spacing: -1px; color: var(--ink); }
.display-md { font-family: var(--font-display); font-weight: 700; font-size: 36px; line-height: 1.15; letter-spacing: -0.5px; color: var(--ink); }
.display-sm { font-family: var(--font-display); font-weight: 700; font-size: 28px; line-height: 1.2; letter-spacing: -0.3px; color: var(--ink); }
.title-lg { font-weight: 500; font-size: 22px; line-height: 1.3; color: var(--ink); }
.title-md { font-weight: 500; font-size: 18px; line-height: 1.4; color: var(--ink); }
.title-sm { font-weight: 500; font-size: 16px; line-height: 1.4; color: var(--ink); }
.body-md  { font-size: 16px; line-height: 1.55; color: var(--body); }
.body-sm  { font-size: 14px; line-height: 1.55; color: var(--body); }
.eyebrow  { font-size: 12px; font-weight: 500; line-height: 1.4; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.caption  { font-size: 13px; font-weight: 500; line-height: 1.4; color: var(--muted); }

h1 { font-family: var(--font-display); font-weight: 800; font-size: 48px; line-height: 1.1; letter-spacing: -1px; color: var(--ink); margin-bottom: var(--s-lg); }
h2 { font-family: var(--font-display); font-weight: 700; font-size: 32px; line-height: 1.2; letter-spacing: -0.4px; color: var(--ink); margin-top: var(--s-xxl); margin-bottom: var(--s-md); }
h3 { font-family: var(--font-display); font-weight: 700; font-size: 24px; line-height: 1.25; letter-spacing: -0.2px; color: var(--ink); margin-top: var(--s-xl); margin-bottom: var(--s-sm); }
h4 { font-family: var(--font-display); font-weight: 600; font-size: 18px; line-height: 1.4; color: var(--ink); margin-top: var(--s-lg); margin-bottom: var(--s-sm); }
p { margin-bottom: var(--s-md); color: var(--body); font-size: 17px; line-height: 1.7; }
p strong { color: var(--body-strong); font-weight: 500; }
ul, ol { margin: 0 0 var(--s-md) 1.2em; }
li { margin-bottom: var(--s-xs); color: var(--body); font-size: 17px; line-height: 1.7; }

/* ===== Layout shell ===== */
.app {
  display: grid;
  grid-template-rows: 64px 1fr auto;
  min-height: 100vh;
}

.top-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 var(--s-xl);
  background: var(--canvas);
  border-bottom: 1px solid var(--hairline);
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.top-nav > div:first-child {
  justify-self: start;
  display: flex;
  align-items: center;
}
.top-nav .brand {
  display: flex;
  align-items: center;
  gap: var(--s-xs);
  font-weight: 500;
  color: var(--ink);
  font-size: 14px;
}
.top-nav .brand .spike {
  width: 14px;
  height: 14px;
  display: inline-block;
}
.top-nav nav { display: flex; gap: var(--s-lg); align-items: center; justify-self: center; }
.top-nav nav a { color: var(--ink); font-size: 14px; font-weight: 500; }
.top-nav nav a:hover { color: var(--primary); }
.top-nav .actions { display: flex; gap: var(--s-sm); align-items: center; justify-self: end; }
.burger-toggle {
  display: none;
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: var(--surface-card);
  margin-right: var(--s-sm);
}
.burger-toggle:hover { background: var(--surface-cream-strong); }
.top-nav-progress { display: none; }
.theme-toggle {
  width: 36px; height: 36px;
  border-radius: var(--r-pill);
  background: var(--surface-card);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink);
}
.theme-toggle:hover { background: var(--surface-cream-strong); }

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  margin: 0 auto;
  width: 100%;
  gap: var(--s-xl);
  padding: var(--s-xl) max(10vw, 24px);
}

.sidebar {
  position: sticky;
  top: 88px;
  align-self: flex-start;
  height: calc(100vh - 88px - var(--s-xl));
  overflow-y: auto;
  padding-right: var(--s-md);
  border-right: 1px solid var(--hairline);
}
.sidebar h4 { font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: var(--s-lg) 0 var(--s-sm); }
.sidebar ol { list-style: none; margin: 0; padding: 0; counter-reset: chapter; }
.sidebar li { margin: 0; padding: 0; counter-increment: chapter; font-size: 14px; }
.sidebar li a {
  display: flex;
  align-items: baseline;
  gap: var(--s-xs);
  padding: var(--s-xs) var(--s-sm);
  color: var(--body);
  border-radius: var(--r-md);
}
.sidebar li a::before { content: counter(chapter, decimal-leading-zero); color: var(--muted-soft); font-family: var(--font-mono); font-size: 12px; min-width: 22px; }
.sidebar li a:hover { background: var(--surface-card); color: var(--ink); }
.sidebar li a.current { background: var(--surface-card); color: var(--ink); font-weight: 500; }
.sidebar .progress {
  margin-top: var(--s-lg);
  padding-top: var(--s-md);
  border-top: 1px solid var(--hairline);
}
.sidebar .progress-bar {
  height: 4px;
  background: var(--hairline);
  border-radius: var(--r-pill);
  overflow: hidden;
  margin-top: var(--s-xs);
}
.sidebar .progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s ease;
}

.chapter {
  min-width: 0;
  padding-bottom: var(--s-section);
  word-wrap: break-word;
}
.chapter .breadcrumb {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: var(--s-md);
}
.chapter .breadcrumb a { color: var(--muted); }
.chapter .breadcrumb a:hover { color: var(--primary); }
.chapter .lead {
  font-family: var(--font-body);
  font-size: 19px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--body-strong);
  margin: var(--s-lg) 0 var(--s-xl);
}

/* ===== Components ===== */
.button {
  display: inline-flex;
  align-items: center;
  gap: var(--s-xs);
  padding: 10px 20px;
  border-radius: var(--r-md);
  font-weight: 500;
  font-size: 14px;
  transition: background 0.15s ease, color 0.15s ease;
}
.button-primary {
  background: var(--primary);
  color: var(--on-primary);
}
.button-primary:hover, .button-primary:active { background: var(--primary-active); color: var(--on-primary); }
.button-secondary {
  background: var(--canvas);
  color: var(--ink);
  border: 1px solid var(--hairline);
}
.button-secondary:hover { background: var(--surface-card); }

.feature-card {
  background: var(--surface-card);
  border-radius: var(--r-lg);
  padding: var(--s-xl);
  color: var(--ink);
}

.mockup-card {
  background: var(--surface-dark);
  color: var(--on-dark);
  border-radius: var(--r-lg);
  padding: var(--s-xl);
  margin: var(--s-xl) 0;
  position: relative;
  overflow: hidden;
}
.mockup-card h4 { color: var(--on-dark); margin-top: 0; }
.mockup-card .mockup-label {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--on-dark-soft);
  margin-bottom: var(--s-md);
}

.callout-coral {
  background: var(--primary);
  color: var(--on-primary);
  border-radius: var(--r-lg);
  padding: var(--s-xxl);
  margin: var(--s-xl) 0;
}
.callout-coral .quote-mark {
  font-family: var(--font-display);
  font-size: 72px;
  line-height: 1;
  display: block;
  margin-bottom: var(--s-sm);
  opacity: 0.5;
}
.callout-coral p { color: var(--on-primary); font-size: 20px; line-height: 1.5; font-family: var(--font-body); font-weight: 500; margin: 0; }
.callout-coral cite { display: block; margin-top: var(--s-md); font-size: 14px; font-family: var(--font-body); font-style: normal; opacity: 0.85; }

.badge-pill {
  display: inline-block;
  background: var(--surface-card);
  color: var(--ink);
  border-radius: var(--r-pill);
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 500;
}
.badge-coral {
  display: inline-block;
  background: var(--primary);
  color: var(--on-primary);
  border-radius: var(--r-pill);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

code:not(pre code) {
  background: var(--surface-card);
  border-radius: var(--r-xs);
  padding: 2px 6px;
  font-size: 0.92em;
  color: var(--ink);
}
:root[data-theme="dark"] code:not(pre code) { background: var(--surface-card); color: var(--ink); }

pre {
  background: var(--surface-dark);
  color: var(--on-dark);
  border-radius: var(--r-lg);
  padding: var(--s-lg);
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.6;
  margin: var(--s-md) 0;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}
pre code { color: var(--on-dark); }

.sources {
  margin-top: var(--s-xxl);
  padding: var(--s-lg);
  background: var(--surface-soft);
  border-radius: var(--r-lg);
  border-left: 3px solid var(--primary);
}
.sources h4 { font-family: var(--font-body); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 0 0 var(--s-sm); }
.sources ul { list-style: none; margin: 0; padding: 0; }
.sources li { margin: var(--s-xs) 0; font-size: 14px; line-height: 1.5; }
.sources li a { color: var(--ink); border-bottom: 1px solid var(--hairline); }
.sources li a:hover { color: var(--primary); border-color: var(--primary); }
.sources .src-kind { color: var(--muted-soft); font-family: var(--font-mono); font-size: 12px; margin-right: var(--s-xs); }

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--s-md);
  margin-top: var(--s-xxl);
  padding-top: var(--s-xl);
  border-top: 1px solid var(--hairline);
}
.chapter-nav a {
  display: flex; flex-direction: column;
  padding: var(--s-md) var(--s-lg);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  color: var(--ink);
  flex: 1;
  max-width: 280px;
  transition: border-color 0.15s ease;
}
.chapter-nav a:hover { border-color: var(--primary); color: var(--ink); }
.chapter-nav .nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin-bottom: var(--s-xxs); }
.chapter-nav .nav-title { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--ink); }
.chapter-nav .next { text-align: right; align-items: flex-end; margin-left: auto; }

.footer {
  background: var(--surface-dark);
  color: var(--on-dark-soft);
  padding: var(--s-xxl) var(--s-xl);
  font-size: 14px;
  margin-top: var(--s-section);
}
.footer .footer-grid {
  max-width: 1280px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: var(--s-xl);
}
.footer h5 { color: var(--on-dark); font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: var(--s-md); }
.footer a { color: var(--on-dark-soft); display: block; padding: 4px 0; }
.footer a:hover { color: var(--on-dark); }
.footer .brand-block p { color: var(--on-dark-soft); font-size: 14px; line-height: 1.6; }

/* ===== TOC landing ===== */
.hero {
  text-align: left;
  padding: var(--s-section) 0 var(--s-xxl);
  border-bottom: 1px solid var(--hairline);
  margin-bottom: var(--s-xxl);
}
.hero .eyebrow { margin-bottom: var(--s-md); }
.hero h1 { font-size: 64px; letter-spacing: -1.5px; line-height: 1.05; max-width: 800px; }
.hero p.lead { font-family: var(--font-body); font-size: 20px; line-height: 1.6; color: var(--body); max-width: 680px; margin-top: var(--s-lg); }
.hero .hero-actions { margin-top: var(--s-xl); display: flex; gap: var(--s-sm); }

.toc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--s-md);
  margin: var(--s-xl) 0;
}
.toc-card {
  background: var(--surface-card);
  border-radius: var(--r-lg);
  padding: var(--s-xl);
  color: var(--ink);
  display: block;
  transition: transform 0.15s ease;
}
.toc-card:hover { transform: translateY(-2px); color: var(--ink); }
.toc-card .toc-num { font-family: var(--font-mono); font-size: 13px; color: var(--muted); margin-bottom: var(--s-sm); }
.toc-card h3 { font-size: 22px; margin: 0 0 var(--s-xs); }
.toc-card p { font-size: 14px; line-height: 1.5; color: var(--body); margin: 0; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    max-width: 100%;
  }
  .burger-toggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: min(320px, 85vw);
    background: var(--canvas);
    border-right: 1px solid var(--hairline);
    border-bottom: none;
    z-index: 200;
    padding: var(--s-xl) var(--s-md);
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.2);
    align-self: stretch;
    padding-bottom: var(--s-xl);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }
  .top-nav {
    position: sticky;
  }
  .top-nav-progress {
    display: block;
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--hairline);
  }
  .top-nav-progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
  }
  .hero h1 { font-size: 48px; letter-spacing: -1px; }
}
@media (max-width: 900px) {
  .toc-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .top-nav { padding: 0 var(--s-md); }
  .top-nav nav { display: none; }
  .top-nav { grid-template-columns: auto 1fr auto; }
  .shell { padding: var(--s-md); gap: var(--s-md); }
  .hero { padding: var(--s-xxl) 0; }
  .hero h1 { font-size: 36px; letter-spacing: -0.5px; }
  h1 { font-size: 32px; }
  h2 { font-size: 28px; }
  h3 { font-size: 22px; }
  p, li { font-size: 16px; }
  .callout-coral { padding: var(--s-xl); }
  .callout-coral p { font-size: 18px; }
  .footer .footer-grid { grid-template-columns: 1fr; }
  pre { padding: var(--s-md); font-size: 12px; }
}

/* ===== Reduced motion (accessibility) ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== Archive viewer ===== */
.archive-doc h1 { margin-top: 0; }
.archive-doc h2 {
  font-size: 32px;
  margin-top: var(--s-xl);
  margin-bottom: var(--s-md);
}
.archive-doc h3 {
  font-size: 22px;
  margin-top: var(--s-lg);
  margin-bottom: var(--s-sm);
}
.archive-doc h4 {
  font-size: 18px;
  margin-top: var(--s-md);
  margin-bottom: var(--s-xs);
}
.archive-doc p,
.archive-doc li {
  font-size: 16px;
  line-height: 1.65;
}
.archive-doc ul,
.archive-doc ol {
  margin: var(--s-sm) 0 var(--s-md) var(--s-lg);
}
.archive-doc li { margin-bottom: var(--s-xxs); }
.archive-doc table {
  border-collapse: collapse;
  margin: var(--s-md) 0;
  width: 100%;
  font-size: 14px;
  display: block;
  overflow-x: auto;
}
.archive-doc th,
.archive-doc td {
  border: 1px solid var(--hairline);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.archive-doc th {
  background: var(--surface-card);
  color: var(--ink);
  font-weight: 500;
}
.archive-doc blockquote {
  margin: var(--s-md) 0;
  padding-left: var(--s-md);
  border-left: 3px solid var(--primary);
  color: var(--muted);
  font-style: italic;
}
.archive-doc pre {
  font-size: 13px;
  background: var(--surface-dark);
  color: var(--on-dark);
  padding: var(--s-md);
  border-radius: var(--r-md);
  overflow-x: auto;
  margin: var(--s-md) 0;
}
.archive-doc :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface-card);
  color: var(--ink);
  padding: 1px 6px;
  border-radius: var(--r-xs);
}
.archive-doc a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.archive-doc a:hover { color: var(--primary-active); }
.archive-doc hr {
  border: none;
  border-top: 1px solid var(--hairline);
  margin: var(--s-xl) 0;
}

.archive-sidebar h4 { color: var(--primary); }
.archive-sidebar li a.current {
  background: var(--surface-card);
  color: var(--ink);
  font-weight: 500;
}
.archive-sidebar ol { counter-reset: none; }
.archive-sidebar li { counter-increment: none; }
.archive-sidebar li a::before { content: none; }
.archive-sidebar li a {
  padding-left: var(--s-sm);
}
