/* ==========================================================================
   Mastering AAISM — course site styles
   ========================================================================== */

:root {
  --bg: #0a1120;
  --bg-elevated: #0f1830;
  --bg-card: #121d38;
  --bg-hover: #17233f;
  --border: #223056;
  --border-soft: #1a2645;
  --text: #e7ecf7;
  --text-muted: #93a3c4;
  --text-faint: #64749a;
  --accent: #4f8cff;
  --accent-strong: #7cabff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --key: #4f8cff;
  --key-soft: rgba(79, 140, 255, 0.10);
  --thought: #b490ff;
  --thought-soft: rgba(180, 144, 255, 0.10);
  --tip: #f2b84b;
  --tip-soft: rgba(242, 184, 75, 0.10);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --domain1: #4f8cff;
  --domain2: #b490ff;
  --domain3: #f2b84b;
  --radius: 10px;
  --sidebar-w: 280px;
  --header-h: 60px;
  --font-serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f6f8fc;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef2fa;
  --border: #dde5f2;
  --border-soft: #e6ecf6;
  --text: #101832;
  --text-muted: #4a5878;
  --text-faint: #7f8caa;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.08);
  --key: #2563eb;
  --key-soft: rgba(37, 99, 235, 0.06);
  --thought: #8b5cf6;
  --thought-soft: rgba(139, 92, 246, 0.06);
  --tip: #b7791f;
  --tip-soft: rgba(183, 121, 31, 0.08);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.10);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.10);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-soft); }

/* ---------------- Header ---------------- */

.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
  z-index: 100;
}

.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
}
.nav-toggle svg { width: 18px; height: 18px; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--domain1), var(--thought) 55%, var(--domain3));
  display: flex; align-items: center; justify-content: center;
  color: #0a1120;
  font-weight: 800;
  font-size: 13px;
  flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text .b1 { font-size: 14px; }
.brand-text .b2 { font-size: 11px; font-weight: 500; color: var(--text-muted); }

.header-crumb {
  color: var(--text-muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.header-crumb strong { color: var(--text); font-weight: 600; }

.theme-toggle {
  margin-left: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  height: 36px;
  padding: 0 12px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.theme-toggle:hover { background: var(--bg-hover); }

.gh-link {
  flex: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 36px;
  width: 36px;
  display: flex; align-items: center; justify-content: center;
}
.gh-link:hover { color: var(--text); background: var(--bg-hover); text-decoration: none; }
.gh-link svg { width: 18px; height: 18px; }

/* ---------------- Layout ---------------- */

.layout {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: var(--header-h);
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  border-right: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  padding: 18px 14px 60px;
  z-index: 90;
}

.sidebar-section { margin-bottom: 22px; }
.sidebar-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 700;
  margin: 0 0 8px 10px;
}

.chapter-nav a {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
}
.chapter-nav a .num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}
.chapter-nav a:hover { background: var(--bg-hover); text-decoration: none; color: var(--text); }
.chapter-nav a.active { background: var(--accent-soft); color: var(--accent-strong); }

.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list li { margin: 0; }
.toc-list a {
  display: block;
  padding: 6px 10px 6px 10px;
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 13px;
  border-left: 2px solid transparent;
}
.toc-list a.level-3 { padding-left: 22px; font-size: 12.5px; color: var(--text-faint); }
.toc-list a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.toc-list a.active { color: var(--accent-strong); border-left-color: var(--accent); background: var(--accent-soft); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 80;
}

/* ---------------- Main content ---------------- */

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  padding: 40px 24px 90px;
}

.content {
  width: 100%;
  max-width: 800px;
}

.page-eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.domain-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.chapter-label { color: var(--text-faint); font-size: 13px; font-family: var(--font-mono); }

.content h1.page-title {
  font-family: var(--font-serif);
  font-size: 2.1rem;
  line-height: 1.2;
  margin: 6px 0 28px;
}

.content h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  margin: 44px 0 14px;
  padding-top: 6px;
  border-top: 1px solid var(--border-soft);
  scroll-margin-top: calc(var(--header-h) + 20px);
}
.content h2:first-child { border-top: none; margin-top: 0; }

.content h3 {
  font-family: var(--font-serif);
  font-size: 1.18rem;
  margin: 30px 0 10px;
  color: var(--text);
  scroll-margin-top: calc(var(--header-h) + 20px);
}
.content h4 { font-size: 1.02rem; margin: 22px 0 8px; }

.content p { margin: 0 0 16px; color: var(--text); }
.content ul, .content ol { margin: 0 0 16px; padding-left: 1.4em; }
.content li { margin-bottom: 6px; }
.content strong { color: var(--text); font-weight: 700; }

/* ---------------- Part dividers ---------------- */

.part-divider {
  margin: 52px 0 26px;
  padding: 18px 20px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-soft), transparent 70%);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
}
.part-divider .part-label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-strong);
  margin-bottom: 4px;
}
.part-divider .part-title {
  margin: 0;
  border: none;
  padding: 0;
  font-size: 1.25rem;
}

/* ---------------- Callout boxes ---------------- */

.callout {
  margin: 22px 0;
  padding: 16px 18px 16px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  background: var(--bg-card);
}
.callout ul { margin: 0; padding-left: 1.2em; }
.callout li { color: var(--text); }
.callout-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.callout-icon { font-size: 15px; }

.callout-key { border-left-color: var(--key); background: var(--key-soft); }
.callout-key .callout-title { color: var(--key); }

.callout-thought { border-left-color: var(--thought); background: var(--thought-soft); }
.callout-thought .callout-title { color: var(--thought); }

.callout-tip { border-left-color: var(--tip); background: var(--tip-soft); }
.callout-tip .callout-title { color: var(--tip); }

/* ---------------- Tables ---------------- */

.table-wrap {
  overflow-x: auto;
  margin: 22px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table.data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14.5px;
}
table.data-table th, table.data-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
table.data-table thead th {
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
table.data-table thead th strong { color: var(--text); }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--bg-hover); }

/* ---------------- Quiz cards ---------------- */

.quiz-card {
  margin: 24px 0;
  padding: 18px 20px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}
.quiz-question { font-weight: 600; margin-bottom: 14px; }
.quiz-num {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 8px;
  margin-right: 10px;
  vertical-align: middle;
}
.quiz-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.quiz-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  font-size: 14.5px;
}
.quiz-option:hover:not(.disabled) { background: var(--bg-hover); border-color: var(--accent); }
.opt-letter {
  flex: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.quiz-option.correct { border-color: var(--success); background: var(--success-soft); }
.quiz-option.correct .opt-letter { background: var(--success); border-color: var(--success); color: #06281c; }
.quiz-option.incorrect { border-color: var(--danger); background: var(--danger-soft); }
.quiz-option.incorrect .opt-letter { background: var(--danger); border-color: var(--danger); color: #2a0a0a; }
.quiz-option.disabled { cursor: default; }

.quiz-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent-strong);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.quiz-toggle:hover { background: var(--accent-soft); }
.quiz-card.revealed .quiz-toggle { border-color: var(--accent); }

.quiz-answer { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.quiz-answer[hidden] { display: none; }
.quiz-correct { margin: 0 0 8px; font-size: 13.5px; color: var(--success); font-weight: 700; }
.quiz-explanation { margin: 0; color: var(--text-muted); font-size: 14.5px; }

/* ---------------- Chapter summary panel ---------------- */

.content h2#chapter-summary + p,
.content h2[id*="chapter-summary"] {
  scroll-margin-top: calc(var(--header-h) + 20px);
}

/* ---------------- Prev/next + footer ---------------- */

.chapter-pager {
  display: flex;
  gap: 14px;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border-soft);
}
.pager-link {
  flex: 1;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}
.pager-link:hover { background: var(--bg-hover); text-decoration: none; border-color: var(--accent); }
.pager-link.next { text-align: right; }
.pager-dir { display: block; font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.pager-title { display: block; font-weight: 700; color: var(--text); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.site-footer {
  max-width: 800px;
  margin: 40px auto 0;
  padding: 20px 0 0;
  color: var(--text-faint);
  font-size: 12.5px;
  text-align: center;
}

/* ---------------- Landing page ---------------- */

.hero {
  padding: 10px 0 8px;
}
.hero-kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-strong);
  margin-bottom: 10px;
}
.hero h1 {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  line-height: 1.15;
  margin: 0 0 16px;
}
.hero p.lede {
  font-size: 1.05rem;
  color: var(--text-muted);
  max-width: 640px;
  margin: 0 0 26px;
}
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 36px; }
.stat-chip {
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.stat-chip strong { display: block; font-size: 1.3rem; color: var(--text); font-family: var(--font-serif); }

.chapter-grid { display: flex; flex-direction: column; gap: 14px; margin-bottom: 44px; }
.chapter-card {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
}
.chapter-card:hover { border-color: var(--accent); text-decoration: none; background: var(--bg-hover); }
.chapter-card .ch-num {
  flex: none;
  width: 46px; height: 46px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 700;
  color: #0a1120;
}
.chapter-card .ch-body { min-width: 0; }
.chapter-card h3 { margin: 0 0 4px; font-size: 1.08rem; font-family: var(--font-sans); }
.chapter-card .ch-meta { font-size: 12px; color: var(--text-faint); margin-bottom: 6px; display: flex; gap: 10px; flex-wrap: wrap; }
.chapter-card p { margin: 0; color: var(--text-muted); font-size: 13.5px; }

.about-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  padding: 22px 24px;
  margin-bottom: 24px;
}
.about-panel h2 { margin-top: 0; font-family: var(--font-serif); font-size: 1.25rem; }
.about-panel p:last-child { margin-bottom: 0; }

/* ---------------- Responsive ---------------- */

@media (max-width: 920px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 0 rgba(0,0,0,0);
    width: 84vw;
    max-width: 320px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 40px rgba(0,0,0,0.4); }
  .main { margin-left: 0; padding: 28px 16px 70px; }
  .nav-toggle { display: flex; }
  .sidebar-overlay.open { display: block; }
  .brand-text .b2 { display: none; }
  .header-crumb { display: none; }
}

@media (max-width: 520px) {
  .hero h1 { font-size: 1.8rem; }
  .content h1.page-title { font-size: 1.6rem; }
  .chapter-card { flex-direction: column; }
}

@media print {
  .site-header, .sidebar, .sidebar-overlay, .chapter-pager, .theme-toggle, .nav-toggle, .gh-link { display: none !important; }
  .main { margin-left: 0; padding: 0; }
  body { background: #fff; color: #000; }
}
