/* ══════════════════════════════════════════════════════════════
   reading.css — Shared stylesheet for published chapter pages
   The Agentic Programming Language
   ══════════════════════════════════════════════════════════════ */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:       #1a2744;
  --blue:       #2563eb;
  --blue-light: #dbeafe;
  --blue-mid:   #93c5fd;
  --green:      #16a34a;
  --green-light:#dcfce7;
  --gray-100:   #f9fafb;
  --gray-200:   #f3f4f6;
  --gray-300:   #e5e7eb;
  --gray-500:   #6b7280;
  --gray-700:   #374151;
  --gray-900:   #111827;
  --border:     #e5e7eb;
  --ink-light:  #6b7280;
  --mono: "Cascadia Code", "Fira Code", Consolas, "Courier New", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html { font-size: 17px; scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  color: var(--gray-900);
  background: #fff;
  line-height: 1.75;
}

/* ── Layout ── */
.page-wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 24px 80px;
}

/* ── Top Nav ── */
.top-nav {
  position: sticky;
  top: 0;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--gray-300);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
}
.top-nav .book-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  text-decoration: none;
  opacity: 0.8;
}
.top-nav .book-title:hover { opacity: 1; }
.top-nav .chapter-nav {
  display: flex;
  gap: 16px;
  font-size: 13px;
}
.top-nav a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}
.top-nav a:hover { text-decoration: underline; }

/* ── Chapter Header ── */
.chapter-header {
  padding: 56px 0 48px;
  border-bottom: 2px solid var(--gray-300);
  margin-bottom: 56px;
}
.chapter-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--blue);
  text-transform: uppercase;
  margin-bottom: 16px;
}
.chapter-title {
  font-family: var(--sans);
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.15;
  color: var(--navy);
  margin-bottom: 12px;
}
.chapter-subtitle {
  font-size: 1.15rem;
  color: var(--gray-500);
  font-weight: 400;
}
.chapter-meta {
  margin-top: 28px;
  display: flex;
  gap: 24px;
  font-size: 13px;
  color: var(--gray-500);
}
.chapter-meta a { color: var(--blue); text-decoration: none; }
.chapter-meta a:hover { text-decoration: underline; }

/* ── Prose ── */
.prose h2 {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--navy);
  margin: 56px 0 20px;
  padding-left: 16px;
  border-left: 4px solid var(--blue);
  line-height: 1.3;
}
.prose h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-900);
  margin: 36px 0 14px;
}
.prose p {
  margin-bottom: 22px;
  color: var(--gray-700);
}
.prose p:last-child { margin-bottom: 0; }
.prose strong { color: var(--gray-900); font-weight: 700; }
.prose em { font-style: italic; }

/* ── Inline code & code blocks ── */
.prose code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--gray-100);
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  padding: 1px 6px;
  color: #be185d;
}
.prose pre {
  background: var(--navy);
  border-radius: 10px;
  padding: 22px 24px;
  margin: 28px 0;
  overflow-x: auto;
}
.prose pre code {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: transparent;
  border: none;
  padding: 0;
  color: #e2e8f0;
  line-height: 1.65;
}
.code-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-500);
  margin-bottom: 6px;
}

/* ── Prompt block (natural language, visually distinct from code) ── */
.prompt-block {
  background: var(--green-light);
  border-left: 4px solid var(--green);
  border-radius: 0 8px 8px 0;
  padding: 18px 20px;
  margin: 28px 0;
  font-family: var(--mono);
  font-size: 0.84rem;
  line-height: 1.65;
  color: #14532d;
}

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  margin: 32px 0;
  border-radius: 10px;
  border: 1px solid var(--gray-300);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
thead tr {
  background: var(--navy);
  color: white;
}
thead th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
}
tbody tr { border-bottom: 1px solid var(--gray-300); }
tbody tr:last-child { border-bottom: none; }
tbody tr:nth-child(even) { background: var(--gray-100); }
tbody td {
  padding: 11px 16px;
  color: var(--gray-700);
  vertical-align: top;
}
tbody td:first-child { font-weight: 600; color: var(--navy); }

/* ── Inline SVG diagram ── */
.diagram {
  margin: 44px 0;
  background: var(--gray-100);
  border-radius: 12px;
  padding: 32px 24px 24px;
  border: 1px solid var(--gray-200);
}
.diagram-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 20px;
}
.diagram svg {
  display: block;
  width: 100%;
  height: auto;
}
.diagram-caption {
  margin-top: 16px;
  font-size: 0.82rem;
  color: var(--gray-500);
  line-height: 1.55;
  font-style: italic;
}

/* ── Diagram card (links to illustration page) ── */
.diagram-card {
  margin: 44px 0;
  background: var(--gray-100);
  border-radius: 12px;
  border: 1px solid var(--gray-200);
  overflow: hidden;
}
.diagram-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--navy);
}
.diagram-card-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--blue-mid);
}
.diagram-card-link {
  font-size: 12px;
  color: var(--blue-mid);
  text-decoration: none;
  font-weight: 600;
  border: 1px solid var(--blue-mid);
  border-radius: 4px;
  padding: 3px 10px;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.diagram-card-link:hover { opacity: 1; }
.diagram-card-body {
  padding: 20px 24px;
}
.diagram-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 8px;
}
.diagram-card-desc {
  font-size: 0.85rem;
  color: var(--gray-500);
  line-height: 1.6;
}

/* ── Section divider ── */
.section-divider {
  border: none;
  border-top: 1px solid var(--gray-300);
  margin: 52px 0;
}

/* ── Callout / pull-quote ── */
.callout {
  background: var(--blue-light);
  border-left: 4px solid var(--blue);
  border-radius: 0 10px 10px 0;
  padding: 20px 24px;
  margin: 36px 0;
  font-style: italic;
  color: var(--navy);
  font-size: 1rem;
  line-height: 1.65;
}
.callout strong { font-style: normal; }

/* ── Definition / key-term block ── */
.definition {
  background: #fff7ed;
  border-left: 4px solid #f97316;
  border-radius: 0 10px 10px 0;
  padding: 18px 22px;
  margin: 32px 0;
  font-size: 0.92rem;
  color: var(--gray-700);
  line-height: 1.65;
}
.definition strong { color: #9a3412; }

/* ── Core Principle block ── */
.core-principle {
  background: var(--navy);
  border-radius: 12px;
  padding: 32px 36px;
  margin: 56px 0 48px;
  color: white;
}
.core-principle-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--blue-mid);
  margin-bottom: 14px;
}
.core-principle p {
  font-size: 1.05rem;
  line-height: 1.7;
  color: #e2e8f0;
  margin: 0;
}
.core-principle strong { color: white; }

/* ── Credits / Colophon Block ── */
.credits-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin: 0 0 2.5rem;
  background: #f8fafc;
}
.credits-block-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-light);
  margin-bottom: 0.75rem;
}
.credits-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.28rem 1.2rem;
  font-size: 0.82rem;
}
.credits-role {
  color: var(--ink-light);
  white-space: nowrap;
}
.credits-name {
  color: var(--navy);
  font-weight: 600;
}

/* ── Bottom navigation ── */
.bottom-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 40px;
  border-top: 1px solid var(--gray-300);
  gap: 16px;
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  padding: 16px 20px;
  border: 1px solid var(--gray-300);
  border-radius: 10px;
  transition: border-color 0.15s, background 0.15s;
  max-width: 280px;
}
.bottom-nav a:hover {
  border-color: var(--blue);
  background: var(--blue-light);
}
.bottom-nav .nav-direction {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--blue);
}
.bottom-nav .nav-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--navy);
}
.bottom-nav .next { text-align: right; margin-left: auto; }

/* ── Copyright Footer ── */
.site-copyright {
  margin-top: 2.5rem;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--ink-light);
  text-align: center;
  letter-spacing: 0.01em;
}

/* ── Side Navigation ── */
.side-nav {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: 240px;
  background: var(--gray-100);
  border-right: 1px solid var(--gray-300);
  overflow-y: auto;
  z-index: 90;
  padding-top: 0;
  transition: transform 0.25s ease;
}
.side-nav-inner {
  padding: 16px 0 40px;
}
.side-nav-book {
  display: block;
  padding: 14px 18px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--navy);
  text-decoration: none;
  border-bottom: 1px solid var(--gray-300);
  margin-bottom: 8px;
  line-height: 1.4;
}
.side-nav-book:hover { background: var(--blue-light); color: var(--blue); }
.side-nav-part {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gray-500);
  padding: 14px 18px 4px;
}
.side-nav-link {
  display: block;
  padding: 5px 18px;
  font-size: 0.8rem;
  color: var(--gray-700);
  text-decoration: none;
  line-height: 1.45;
  transition: background 0.12s, color 0.12s;
}
.side-nav-link:hover { background: var(--blue-light); color: var(--blue); }
.side-nav-link.active {
  color: var(--blue);
  font-weight: 700;
  background: var(--blue-light);
}
.side-nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 8px;
  color: var(--navy);
  font-size: 20px;
  line-height: 1;
}
.side-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 89;
}
.side-nav-overlay.open { display: block; }

/* Wide screens: shift content right of sidebar */
@media (min-width: 860px) {
  body { padding-left: 240px; }
}

/* Narrow screens: sidebar overlays, toggle button visible */
@media (max-width: 859px) {
  .side-nav { transform: translateX(-100%); }
  .side-nav.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.15); }
  .side-nav-toggle { display: block; }
}

/* ── Responsive ── */
@media (max-width: 600px) {
  html { font-size: 16px; }
  .chapter-title { font-size: 1.9rem; }
  .top-nav .chapter-nav { gap: 10px; }
  .diagram { padding: 20px 14px 16px; }
  .core-principle { padding: 24px 20px; }
}

/* ══════════════════════════════════════════════════════════════
   Dark Theme
   ══════════════════════════════════════════════════════════════ */

[data-theme="dark"] {
  --blue:        #60a5fa;
  --blue-light:  #1e3358;
  --green:       #34d399;
  --green-light: #022c22;
  --gray-100:    #161b22;
  --gray-200:    #21262d;
  --gray-300:    #30363d;
  --gray-500:    #8b949e;
  --gray-700:    #c9d1d9;
  --gray-900:    #f0f6fc;
  --border:      #30363d;
  --ink-light:   #8b949e;
}

[data-theme="dark"] body {
  background: #0d1117;
  color: #c9d1d9;
}

/* Nav */
[data-theme="dark"] .top-nav {
  background: rgba(13,17,23,0.97);
  border-color: #30363d;
}
[data-theme="dark"] .top-nav .book-title { color: #c9d1d9; }

/* Side nav */
[data-theme="dark"] .side-nav { background: #161b22; border-color: #30363d; }
[data-theme="dark"] .side-nav-book { color: #c9d1d9; border-color: #30363d; }
[data-theme="dark"] .side-nav-book:hover { background: #1e3358; color: var(--blue); }
[data-theme="dark"] .side-nav-link { color: #c9d1d9; }
[data-theme="dark"] .side-nav-link:hover { background: #1e3358; color: var(--blue); }
[data-theme="dark"] .side-nav-link.active { background: #1e3358; color: var(--blue); }
[data-theme="dark"] .side-nav-toggle { color: #c9d1d9; }
[data-theme="dark"] .side-nav-part { color: #8b949e; }

/* Chapter header */
[data-theme="dark"] .chapter-header { border-color: #30363d; }
[data-theme="dark"] .chapter-title { color: #c9d1d9; }
[data-theme="dark"] .chapter-subtitle { color: #8b949e; }
[data-theme="dark"] .chapter-meta { color: #8b949e; }

/* Prose */
[data-theme="dark"] .prose h2 { color: #c9d1d9; }
[data-theme="dark"] .prose h3 { color: #e2e8f0; }
[data-theme="dark"] .prose strong { color: #f0f6fc; }
[data-theme="dark"] .prose code {
  background: #21262d;
  border-color: #30363d;
  color: #f472b6;
}
[data-theme="dark"] .code-label { color: #8b949e; }

/* Blocks */
[data-theme="dark"] .callout {
  background: #1e3358;
  border-color: var(--blue);
  color: #bfdbfe;
}
[data-theme="dark"] .definition {
  background: #1c1208;
  border-color: #f97316;
  color: #c9d1d9;
}
[data-theme="dark"] .definition strong { color: #fb923c; }
[data-theme="dark"] .prompt-block {
  background: #022c22;
  border-color: #34d399;
  color: #bbf7d0;
}
[data-theme="dark"] .core-principle { background: #161b22; border: 1px solid #30363d; }

/* Tables */
[data-theme="dark"] .table-wrap { border-color: #30363d; }
[data-theme="dark"] tbody tr { border-color: #30363d; }
[data-theme="dark"] tbody tr:nth-child(even) { background: #161b22; }
[data-theme="dark"] tbody td { color: #c9d1d9; }
[data-theme="dark"] tbody td:first-child { color: #e2e8f0; }

/* Diagram */
[data-theme="dark"] .diagram { background: #161b22; border-color: #30363d; }
[data-theme="dark"] .diagram-caption { color: #8b949e; }
[data-theme="dark"] .diagram-card-title { color: #c9d1d9; }
[data-theme="dark"] .diagram-card-desc { color: #8b949e; }

/* Credits */
[data-theme="dark"] .credits-block { background: #161b22; border-color: #30363d; }
[data-theme="dark"] .credits-name { color: #c9d1d9; }

/* Bottom nav */
[data-theme="dark"] .bottom-nav a { border-color: #30363d; }
[data-theme="dark"] .bottom-nav a:hover { border-color: var(--blue); background: #1e3358; }
[data-theme="dark"] .bottom-nav .nav-direction { color: var(--blue); }
[data-theme="dark"] .bottom-nav .nav-title { color: #c9d1d9; }

/* Dividers & footer */
[data-theme="dark"] .section-divider { border-color: #30363d; }
[data-theme="dark"] .site-copyright { border-color: #30363d; color: #8b949e; }

/* Index-page overrides */
[data-theme="dark"] .book-hero-title { color: #c9d1d9; }
[data-theme="dark"] .book-hero-subtitle { color: #8b949e; }
[data-theme="dark"] .part-name { color: #c9d1d9; }
[data-theme="dark"] .part-header { border-color: #60a5fa; }
[data-theme="dark"] .ch-title,
[data-theme="dark"] .ch-title a { color: #c9d1d9; }
[data-theme="dark"] .ch-subtitle { color: #8b949e; }
[data-theme="dark"] .ch-abstract { color: #8b949e; }
[data-theme="dark"] .chapter-row { border-color: #30363d; }
[data-theme="dark"] .chapter-row:hover { background: #1e3358; }
[data-theme="dark"] .index-footer { border-color: #30363d; color: #8b949e; }

/* ── Theme toggle button (appended inside side-nav by theme.js) ── */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  width: calc(100% - 36px);
  margin: 16px 18px 8px;
  padding: 7px 12px;
  background: none;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gray-700);
  font-family: var(--sans);
  text-align: left;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.theme-toggle:hover {
  background: var(--blue-light);
  color: var(--blue);
  border-color: var(--blue);
}
.theme-toggle-icon { font-style: normal; }
[data-theme="dark"] .theme-toggle { color: #c9d1d9; border-color: #30363d; }
[data-theme="dark"] .theme-toggle:hover { background: #1e3358; color: var(--blue); border-color: var(--blue); }