:root {
  --paper: #fbfaf7;
  --paper-deep: #f0ece4;
  --ink: #27231e;
  --muted: #756d62;
  --rule: #ded7cc;
  --rail: #24231f;
  --rail-soft: #34312b;
  --rail-ink: #f4eee5;
  --accent: #a4472c;
  --accent-dark: #7f3521;
  --receipt: #b86b27;
  --shadow: 0 18px 50px rgba(48, 38, 26, 0.08);
}

* { box-sizing: border-box; }

html {
  background: var(--paper-deep);
  color: var(--ink);
  font-size: 17px;
  scroll-behavior: smooth;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.72;
}

body::before {
  background: var(--accent);
  content: "";
  height: 3px;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  transform: scaleX(var(--reading-progress, 0));
  transform-origin: left;
  z-index: 1000;
}

body::after {
  background: linear-gradient(90deg, rgba(164, 71, 44, 0.035), transparent 35%, transparent 65%, rgba(164, 71, 44, 0.025));
  content: "";
  inset: 0;
  pointer-events: none;
  position: fixed;
  z-index: -1;
}

.sidebar {
  background: var(--rail);
  border-right: 1px solid #3d3932;
  color: var(--rail-ink);
  padding-top: 0;
  width: 286px;
}

.sidebar > .app-sub-sidebar,
.sidebar-nav { padding: 1.5rem 1.25rem 2rem; }

.sidebar-nav::before {
  color: #d4b39a;
  content: "THE AI AGENT HANDBOOK";
  display: block;
  font-family: Arial, sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1.5;
  margin: 0 0 1.5rem;
  max-width: 12rem;
}

.sidebar-nav > ul > li > a {
  border-bottom: 1px solid var(--rail-soft);
  color: var(--rail-ink);
  font-family: Arial, sans-serif;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  padding: 0.7rem 0;
  text-transform: uppercase;
}

.sidebar-nav > ul > li:first-child > a,
.sidebar-nav > ul > li:nth-child(2) > a { color: #e6ae80; }

.sidebar-nav > h2 {
  border-top: 1px solid var(--rail-soft);
  color: #e6ae80;
  font-family: Arial, sans-serif;
  font-size: 0.74rem;
  letter-spacing: 0.09em;
  margin: 1.25rem 0 0.35rem;
  padding-top: 1rem;
  text-transform: uppercase;
}

.sidebar-nav > h2 a { color: #e6ae80; }
.sidebar-nav > h2 a:hover { color: #fff; }

.sidebar-nav li > a {
  color: #cfc7bc;
  font-family: Arial, sans-serif;
  font-size: 0.86rem;
  line-height: 1.4;
  padding: 0.28rem 0;
}

.sidebar-nav li > a:hover { color: #fff; }
.sidebar-nav li.active > a {
  background: #e8e0d5;
  border-left: 3px solid #e6ae80;
  color: var(--rail);
  padding-left: 0.55rem;
}

.sidebar-nav ul ul {
  border-left: 1px solid #4c463d;
  margin: 0.2rem 0 0.65rem 0.2rem;
  padding-left: 0.8rem;
}

.content { left: 286px; }

.markdown-section {
  background: var(--paper);
  box-shadow: var(--shadow);
  margin: 0 auto;
  max-width: 900px;
  min-height: 100vh;
  padding: 4.6rem 4.5rem 7rem;
}

.markdown-section > h1:first-child {
  border-bottom: 0;
  color: var(--ink);
  font-size: clamp(2.35rem, 5vw, 4.25rem);
  letter-spacing: -0.045em;
  line-height: 1.05;
  margin-bottom: 1.2rem;
  max-width: 13ch;
}

.markdown-section h1,
.markdown-section h2,
.markdown-section h3,
.markdown-section h4 {
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
}

.markdown-section h2 {
  border-top: 1px solid var(--rule);
  font-size: 1.55rem;
  letter-spacing: -0.02em;
  margin: 3.3rem 0 1rem;
  padding-top: 1.3rem;
}

.markdown-section h3 { font-size: 1.15rem; margin-top: 2rem; }

.markdown-section p,
.markdown-section ul,
.markdown-section ol,
.markdown-section table,
.markdown-section blockquote { max-width: 68ch; }

.markdown-section a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

.markdown-section a:hover { color: var(--accent-dark); }
.markdown-section strong { color: #1d1a17; }

.markdown-section blockquote {
  background: #f6f0e7;
  border-left: 4px solid var(--receipt);
  color: #4c433a;
  margin: 1.5rem 0;
  padding: 0.85rem 1.25rem;
}

.markdown-section blockquote p:first-child::before {
  color: var(--receipt);
  content: "RECEIPT  ";
  font-family: Arial, sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.markdown-section code {
  background: #eee8df;
  border: 1px solid #e4dbcf;
  border-radius: 3px;
  color: #633724;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.84em;
  padding: 0.1em 0.32em;
}

.markdown-section pre {
  background: #292722;
  border-radius: 5px;
  box-shadow: 0 8px 24px rgba(32, 26, 20, 0.12);
  margin: 1.4rem 0;
  padding: 1.15rem 1.3rem;
}

.markdown-section pre > code {
  background: transparent;
  border: 0;
  color: #f2e9dc;
  line-height: 1.6;
}

.markdown-section table { display: table; width: 100%; }
.markdown-section th {
  background: #eee8df;
  color: #51463c;
  font-family: Arial, sans-serif;
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.markdown-section td,
.markdown-section th { border-color: var(--rule); }
.markdown-section hr { border-color: var(--rule); }

.book-cover {
  background: linear-gradient(135deg, #2b2924 0%, #40382f 100%);
  border: 1px solid #51473b;
  border-radius: 4px;
  box-shadow: 0 22px 55px rgba(44, 34, 23, 0.18);
  color: #f8f1e8;
  margin: -1rem -1.5rem 3.5rem;
  min-height: 28rem;
  padding: 4rem 3.2rem;
  position: relative;
}

.book-cover::after {
  border: 1px solid rgba(232, 190, 150, 0.35);
  content: "";
  inset: 1.1rem;
  pointer-events: none;
  position: absolute;
}

.book-cover > * { position: relative; z-index: 1; }
.book-kicker {
  color: #e9b78e;
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.book-cover h1 {
  color: #fff8ee;
  font-size: clamp(2.8rem, 7vw, 5.7rem);
  letter-spacing: -0.06em;
  line-height: 0.95;
  margin: 3rem 0 1.4rem;
  max-width: 8ch;
}
.book-dek { color: #e6d9cb; font-size: 1.22rem; line-height: 1.45; max-width: 28rem; }
.book-note { color: #c9b9aa; font-family: Arial, sans-serif; font-size: 0.78rem; margin-top: 2.7rem; }
.book-actions { margin-top: 2rem; }
.book-actions a {
  border: 1px solid #dfaa82;
  color: #fff4e7;
  display: inline-block;
  font-family: Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin: 0.25rem 0.6rem 0.25rem 0;
  padding: 0.65rem 0.9rem;
  text-decoration: none;
  text-transform: uppercase;
}
.book-actions a:hover { background: #a4472c; color: #fff; }
.app-nav { font-family: Arial, sans-serif; }
.search .search-keyword { background: #fffaf3; border-color: var(--rule); font-family: Arial, sans-serif; }

@media (max-width: 800px) {
  html { font-size: 16px; }
  .sidebar { width: 270px; }
  .content { left: 0; }
  .markdown-section { box-shadow: none; padding: 3.6rem 1.45rem 5rem; }
  .book-cover { margin: -1rem -0.4rem 2.5rem; padding: 3rem 2rem; }
  .book-cover h1 { margin-top: 2.5rem; }
}
