/* =========================================================
   The Intelligence Divide — Dark AI-aesthetic design
   ========================================================= */

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

:root {
  /* Palette */
  --bg-base:        #0d0f14;
  --bg-surface:     #12151c;
  --bg-elevated:    #1a1e28;
  --bg-hover:       #1f2433;
  --border:         #252a38;
  --border-strong:  #2e3548;

  --accent:         #6366f1;
  --accent-dim:     #4f52c9;
  --accent-glow:    rgba(99, 102, 241, 0.15);
  --accent-text:    #a5b4fc;

  --text-primary:   #e8eaf0;
  --text-secondary: #8b92a8;
  --text-muted:     #545c73;
  --text-link:      #818cf8;

  /* Typography */
  --font-body: Georgia, "Times New Roman", serif;
  --font-ui:   "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Fira Code", "Cascadia Code", "Consolas", monospace;

  /* Layout */
  --sidebar-width: 300px;
  --content-max:   720px;

  /* Transitions */
  --t-fast: 0.15s ease;
  --t-mid:  0.25s ease;
}

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

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  line-height: 1.75;
}

/* ----- Layout ----- */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ----- Sidebar ----- */
.sidebar {
  position: sticky;
  top: 0;
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 2px;
}

.sidebar-title {
  display: block;
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-title a {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-text);
  text-decoration: none;
  line-height: 1.3;
  transition: color var(--t-fast);
}
.sidebar-title a:hover { color: var(--text-primary); }

.sidebar-subtitle {
  display: block;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  line-height: 1.4;
}

.nav-section {
  border-bottom: 1px solid var(--border);
}
.nav-section:last-of-type { border-bottom: none; }

.nav-section summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem 0.6rem 1rem;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-secondary);
  user-select: none;
  transition: color var(--t-fast), background var(--t-fast);
}
.nav-section summary::-webkit-details-marker { display: none; }
.nav-section summary::after {
  content: "";
  display: block;
  width: 14px;
  height: 14px;
  margin-left: auto;
  flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b92a8' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  transition: transform var(--t-fast);
}
.nav-section[open] summary::after { transform: rotate(180deg); }
.nav-section summary:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.nav-section[open] summary { color: var(--text-primary); }

.nav-section ul {
  list-style: none;
  padding: 0.25rem 0 0.5rem;
}

.nav-section li a {
  display: block;
  padding: 0.35rem 1.25rem 0.35rem 2rem;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  line-height: 1.4;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.nav-section li a:hover,
.nav-section li.active a {
  color: var(--text-primary);
  background: var(--accent-glow);
  border-left-color: var(--accent);
}
.nav-section li.active a { color: var(--accent-text); }

.nav-subsection-label {
  padding: 0.55rem 1.25rem 0.1rem 1.6rem;
  font-family: var(--font-ui);
  font-size: 0.67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
  list-style: none;
  margin-top: 0.4rem;
}
.nav-subsection-label:first-child { margin-top: 0; }

/* ----- Main content area ----- */
.content {
  flex: 1;
  min-width: 0;
  padding: 3.5rem 2rem 5rem;
}

/* ----- Index page ----- */
.book-header {
  max-width: var(--content-max);
  margin: 0 auto 4rem;
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.book-header h1 {
  font-family: var(--font-ui);
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, var(--text-primary) 50%, var(--accent-text));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.book-subtitle {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.book-description {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-family: var(--font-ui);
  max-width: 520px;
  margin: 0 auto;
  line-height: 1.6;
}

.book-section {
  max-width: var(--content-max);
  margin: 0 auto 1.5rem;
}

.section-details {
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}
.section-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 0.6rem 0 0.6rem 0;
  user-select: none;
  transition: color var(--t-fast);
}
.section-summary::-webkit-details-marker { display: none; }
.section-summary::after {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-left: auto;
  flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b92a8' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  transition: transform var(--t-fast);
}
.section-details[open] .section-summary::after { transform: rotate(180deg); }
.section-summary:hover { color: var(--text-primary); }
.section-details[open] .section-summary { color: var(--text-primary); }

.subsection-details {
  margin: 0.75rem 0 0.5rem;
}
.subsection-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.3rem 0 0.3rem 0.75rem;
  border-left: 2px solid var(--accent-dim);
  letter-spacing: 0.01em;
  user-select: none;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.subsection-summary::-webkit-details-marker { display: none; }
.subsection-summary::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: auto;
  flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b92a8' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  transition: transform var(--t-fast);
}
.subsection-details[open] .subsection-summary::after { transform: rotate(180deg); }
.subsection-summary:hover { color: var(--text-primary); border-left-color: var(--accent); }
.subsection-details[open] .subsection-summary { color: var(--text-primary); border-left-color: var(--accent); }

.chapter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.chapter-card {
  display: block;
  text-decoration: none;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.5rem;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.chapter-card:hover {
  border-color: var(--accent);
  background: var(--bg-elevated);
}

.chapter-card h3 {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 0.6rem;
  color: var(--text-primary);
  transition: color var(--t-fast);
}
.chapter-card:hover h3 { color: var(--accent-text); }

.takeaways {
  list-style: none;
  padding: 0;
  margin: 0;
}
.takeaways li {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 0.2rem 0 0.2rem 1rem;
  position: relative;
  line-height: 1.5;
}
.takeaways li::before {
  content: "›";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}

/* ----- Chapter article ----- */
.chapter {
  max-width: var(--content-max);
  margin: 0 auto;
}

.chapter h1 {
  font-family: var(--font-ui);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
}
.chapter h2 {
  font-family: var(--font-ui);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}
.chapter h3 {
  font-family: var(--font-ui);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent-text);
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
}
.chapter h4 {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-top: 1.5rem;
  margin-bottom: 0.4rem;
}
.chapter p { margin-bottom: 1.1rem; color: var(--text-primary); hyphens: auto; }
.chapter ul, .chapter ol { margin: 0.5rem 0 1rem 1.5rem; }
.chapter li { margin-bottom: 0.35rem; }

.chapter blockquote {
  border-left: 3px solid var(--accent);
  background: var(--bg-elevated);
  margin: 1.5rem 0;
  padding: 0.9rem 1.2rem;
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--text-secondary);
}
.chapter blockquote p { margin-bottom: 0; color: inherit; }

.chapter code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  color: var(--accent-text);
}
.chapter pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1.25rem 0;
}
.chapter pre code { background: none; border: none; padding: 0; font-size: 0.84rem; color: var(--text-primary); }

.chapter table { width: 100%; border-collapse: collapse; margin: 1.25rem 0; font-family: var(--font-ui); font-size: 0.88rem; }
.chapter thead { background: var(--bg-elevated); }
.chapter th { padding: 0.6rem 0.85rem; text-align: left; font-weight: 600; color: var(--text-secondary); border-bottom: 1px solid var(--border-strong); letter-spacing: 0.03em; font-size: 0.8rem; text-transform: uppercase; }
.chapter td { padding: 0.55rem 0.85rem; border-bottom: 1px solid var(--border); color: var(--text-primary); vertical-align: top; }
.chapter tr:last-child td { border-bottom: none; }
.chapter tr:hover td { background: var(--bg-elevated); }

.chapter hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

.chapter a { color: var(--text-link); text-decoration: underline; text-decoration-color: rgba(129,140,248,0.35); text-underline-offset: 2px; transition: color var(--t-fast), text-decoration-color var(--t-fast); }
.chapter a:hover { color: var(--accent-text); text-decoration-color: var(--accent-text); }
.chapter strong { font-weight: 700; color: var(--text-primary); }
.chapter em { font-style: italic; color: var(--text-secondary); }

.last-updated {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ----- Scrollbar ----- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ----- Responsive ----- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .content { padding: 2rem 1.25rem 3rem; }
  .chapter-grid { grid-template-columns: 1fr; }
  .book-header h1 { font-size: 1.9rem; }
}

@media (max-width: 500px) {
  .content { padding: 1.5rem 1rem 2.5rem; }
}
