/* =============================================================
   DeFi Protocol Engineering — Custom mdBook Theme
   ============================================================= */

/* --- Web Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- Typography & Base --- */
:root {
  --content-max-width: 920px;
  --font-heading: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-code: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

.content main {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.8;
  max-width: var(--content-max-width);
  letter-spacing: -0.01em;
}

/* Headings — distinct visual hierarchy per level */

/* H1 — Module title: largest, boldest, full underline */
.content main h1 {
  font-family: var(--font-heading);
  font-size: 2.1rem;
  font-weight: 700;
  border-bottom: 2px solid var(--sidebar-bg);
  padding-bottom: 0.4em;
  margin-top: 1.5em;
  letter-spacing: -0.025em;
}

/* H2 — Major sections: uppercase, white, top bar only, larger, centered */
.content main h2 {
  font-family: var(--font-heading);
  font-size: 1.9rem;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  margin-top: 3.2em;
  padding-top: 0.5em;
  padding-bottom: 0.3em;
  border-bottom: none;
  border-top: 3px solid;
  letter-spacing: 0.03em;
}

/* H2 colors per theme — white for dark themes, dark for light */
.light .content main h2 {
  border-top-color: #0f172a;
  color: #0f172a;
}
.navy .content main h2 {
  border-top-color: #ffffff;
  color: #ffffff;
}
.coal .content main h2 {
  border-top-color: #ffffff;
  color: #ffffff;
}
.ayu .content main h2 {
  border-top-color: #ffffff;
  color: #ffffff;
}

/* H2 section keyword — inherits H2 color (no per-section coloring) */
.section-keyword {
  font-weight: 700;
  color: inherit;
}

/* Summary & Exercise H2s — subsection style (keyword left, title centered) */
.content main h2.section-summary,
.content main h2.section-exercise {
  font-size: 1.55rem;
  text-transform: none;
  text-align: center;
  border-bottom: 2px solid;
  letter-spacing: -0.02em;
  position: relative;
}

/* Keyword pinned to the left edge */
.content main h2.section-summary .section-keyword,
.content main h2.section-exercise .section-keyword {
  position: absolute;
  left: 0;
}

/* Title text centered naturally by parent text-align */
.content main h2.section-summary .section-rest,
.content main h2.section-exercise .section-rest {
  font-weight: 600;
}

.content main h2.section-summary {
  border-top-color: #6366f1;
  border-bottom-color: #6366f1;
}
.content main h2.section-summary .section-keyword { color: #6366f1; }

.content main h2.section-exercise {
  border-top-color: #22c55e;
  border-bottom-color: #22c55e;
}
.content main h2.section-exercise .section-keyword { color: #22c55e; }

/* Override theme colors for subsection H2s */
.light .content main h2.section-summary,
.light .content main h2.section-exercise {
  color: var(--fg);
}
.navy .content main h2.section-summary,
.navy .content main h2.section-exercise,
.coal .content main h2.section-summary,
.coal .content main h2.section-exercise,
.ayu .content main h2.section-summary,
.ayu .content main h2.section-exercise {
  color: var(--fg);
}

/* H3 — Concepts/sub-sections: medium weight, muted color, accent bar */
.content main h3 {
  font-family: var(--font-heading);
  font-size: 1.28rem;
  font-weight: 600;
  margin-top: 2.4em;
  padding-bottom: 0.25em;
  position: relative;
}

.light .content main h3 { color: #1e3a5f; }
.navy .content main h3 { color: #93c5fd; }
.coal .content main h3 { color: #93c5fd; }
.ayu .content main h3 { color: #ffd599; }

.content main h3::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 60px;
  height: 3px;
  border-radius: 2px;
}

/* H3 accent colors per theme */
.light .content main h3::after {
  background: #1e40af;
}

.navy .content main h3::after {
  background: #3b82f6;
}

.coal .content main h3::after {
  background: #3b82f6;
}

.ayu .content main h3::after {
  background: #3b82f6;
}

/* "Concept:" keyword coloring in H3 headings */
.concept-keyword {
  font-weight: 800;
  font-size: 1.15em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 0;
}
.light .concept-keyword { color: #1e40af; }
.navy .concept-keyword  { color: #60a5fa; }
.coal .concept-keyword  { color: #60a5fa; }
.ayu .concept-keyword   { color: #60a5fa; }

/* Topic text after "CORE" keyword — uppercase */
.concept-topic {
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* H4 — Deep dives, patterns: body font (Inter), lighter weight, italic feel */
.content main h4 {
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 2em;
  letter-spacing: 0;
}

.light .content main h4 { color: #475569; }
.navy .content main h4 { color: #94a3b8; }
.coal .content main h4 { color: #94a3b8; }
.ayu .content main h4 { color: #c8a67a; }

/* Content indentation — all body elements indented under headings */
.content main p,
.content main pre,
.content main ul,
.content main ol,
.content main blockquote,
.content main table,
.content main .callout {
  margin-left: 1.2em;
}

/* Paragraphs — breathing room */
.content main p {
  margin-bottom: 1em;
}

/* Bold text — slightly heavier */
.content main strong {
  font-weight: 600;
}

/* Links — vibrant, distinct from body text */
.light .content main a {
  color: #2563eb;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.navy .content main a {
  color: #60a5fa;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.coal .content main a {
  color: #60a5fa;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.ayu .content main a {
  color: #ffb454;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.content main a:hover {
  text-decoration-thickness: 2px;
}

/* Lists */
.content main ul,
.content main ol {
  margin-bottom: 1em;
  padding-left: 1.5em;
}

.content main li {
  margin-bottom: 0.35em;
  line-height: 1.7;
}

.content main li p {
  margin-bottom: 0.5em;
}

/* --- Code blocks --- */
.content main pre {
  font-family: var(--font-code);
  border-radius: 8px;
  padding: 1.1em 1.3em;
  margin: 1.6em 0;
  font-size: 0.88rem;
  line-height: 1.65;
  border: 1px solid var(--table-border-color);
  overflow-x: auto;
}

.content main code {
  font-family: var(--font-code);
  font-size: 0.88em;
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

/* Inline code — visible tint with subtle border */
.navy .content main :not(pre) > code,
.coal .content main :not(pre) > code,
.ayu .content main :not(pre) > code {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.light .content main :not(pre) > code {
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.04);
}

/* --- Tables --- */
.content main table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.8em 0;
  font-size: 0.93rem;
  border-radius: 8px;
  overflow: hidden;
}

.content main table th {
  font-family: var(--font-heading);
  background: var(--table-header-bg);
  font-weight: 600;
  text-align: left;
  padding: 0.7em 0.9em;
  border-bottom: 2px solid var(--table-border-color);
  font-size: 0.9rem;
  text-transform: none;
  letter-spacing: 0;
}

.content main table td {
  padding: 0.55em 0.9em;
  border-bottom: 1px solid var(--table-border-color);
  vertical-align: top;
}

.content main table tr:hover {
  background: rgba(128, 128, 128, 0.06);
}

/* Alternating row colors for readability */
.content main table tbody tr:nth-child(even) {
  background: rgba(128, 128, 128, 0.03);
}

/* --- Blockquotes --- */
.content main blockquote {
  border-left: 4px solid #4a9eff;
  background: rgba(74, 158, 255, 0.06);
  padding: 0.8em 1.2em;
  margin: 1.6em 0;
  border-radius: 0 8px 8px 0;
  font-size: 0.97rem;
}

.content main blockquote p {
  margin-bottom: 0.5em;
}

.content main blockquote p:last-child {
  margin-bottom: 0;
}

/* Light theme blockquotes */
.light .content main blockquote {
  background: rgba(74, 158, 255, 0.06);
  border-left-color: #3b82f6;
}

/* Dark theme blockquotes */
.navy .content main blockquote,
.coal .content main blockquote,
.ayu .content main blockquote {
  background: rgba(74, 158, 255, 0.08);
  border-left-color: #60a5fa;
}

/* --- Horizontal rules as section dividers --- */
.content main hr {
  border: none;
  border-top: 2px solid var(--table-border-color);
  margin: 4em 0;
}

/* --- Checklist styling --- */
.content main li input[type="checkbox"] {
  margin-right: 0.5em;
  transform: scale(1.2);
  vertical-align: middle;
}

/* --- In-page Table of Contents --- */
/* Style the TOC that appears at the top of modules (📚 Table of Contents) */
.content main h2 + ul,
.content main h2 + p + ul {
  /* TOC lists following a heading */
}

/* Nested TOC items */
.content main ul ul {
  margin-top: 0.2em;
  margin-bottom: 0.2em;
}

/* --- Callout boxes (injected by callouts.js) --- */
.callout {
  border-left: 4px solid;
  border-radius: 0 8px 8px 0;
  padding: 1.2em 1.4em;
  margin: 2em 0;
  position: relative;
}

.callout-label {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.6em;
  display: flex;
  align-items: center;
  gap: 0.4em;
}

.callout-label::before {
  font-size: 1.1em;
}

/* Callout headings */
.callout h4 {
  margin-top: 0 !important;
  padding-top: 0;
}

.callout p:last-child {
  margin-bottom: 0;
}

.callout pre {
  margin-top: 0.8em;
}

/* Callout code blocks — slightly subdued border */
.callout pre {
  border-color: rgba(128, 128, 128, 0.15);
}

/* --- Callout colors per type --- */

/* Quick Try — blue */
.callout-try { border-left-color: #3b82f6; }
.light .callout-try { background: rgba(59, 130, 246, 0.05); }
.navy .callout-try, .coal .callout-try, .ayu .callout-try { background: rgba(59, 130, 246, 0.08); }
.callout-try .callout-label { color: #3b82f6; }

/* Real Usage — emerald */
.callout-build { border-left-color: #10b981; }
.light .callout-build { background: rgba(16, 185, 129, 0.05); }
.navy .callout-build, .coal .callout-build, .ayu .callout-build { background: rgba(16, 185, 129, 0.08); }
.callout-build .callout-label { color: #10b981; }

/* Deep Dive — purple */
.callout-deep { border-left-color: #8b5cf6; }
.light .callout-deep { background: rgba(139, 92, 246, 0.05); }
.navy .callout-deep, .coal .callout-deep, .ayu .callout-deep { background: rgba(139, 92, 246, 0.08); }
.callout-deep .callout-label { color: #8b5cf6; }

/* DeFi Pattern — amber */
.callout-pattern { border-left-color: #f59e0b; }
.light .callout-pattern { background: rgba(245, 158, 11, 0.05); }
.navy .callout-pattern, .coal .callout-pattern, .ayu .callout-pattern { background: rgba(245, 158, 11, 0.08); }
.callout-pattern .callout-label { color: #f59e0b; }

/* Job Market — red */
.callout-job { border-left-color: #ef4444; }
.light .callout-job { background: rgba(239, 68, 68, 0.05); }
.navy .callout-job, .coal .callout-job, .ayu .callout-job { background: rgba(239, 68, 68, 0.08); }
.callout-job .callout-label { color: #ef4444; }

/* Example — cyan */
.callout-example { border-left-color: #06b6d4; }
.light .callout-example { background: rgba(6, 182, 212, 0.05); }
.navy .callout-example, .coal .callout-example, .ayu .callout-example { background: rgba(6, 182, 212, 0.08); }
.callout-example .callout-label { color: #06b6d4; }

/* Summary — indigo */
.callout-summary { border-left-color: #6366f1; }
.light .callout-summary { background: rgba(99, 102, 241, 0.05); }
.navy .callout-summary, .coal .callout-summary, .ayu .callout-summary { background: rgba(99, 102, 241, 0.08); }
.callout-summary .callout-label { color: #6366f1; }

/* Study Guide — teal */
.callout-study { border-left-color: #14b8a6; }
.light .callout-study { background: rgba(20, 184, 166, 0.05); }
.navy .callout-study, .coal .callout-study, .ayu .callout-study { background: rgba(20, 184, 166, 0.08); }
.callout-study .callout-label { color: #14b8a6; }

/* Warning — orange */
.callout-warning { border-left-color: #f97316; }
.light .callout-warning { background: rgba(249, 115, 22, 0.05); }
.navy .callout-warning, .coal .callout-warning, .ayu .callout-warning { background: rgba(249, 115, 22, 0.08); }
.callout-warning .callout-label { color: #f97316; }

/* Exercise — green */
.callout-exercise { border-left-color: #22c55e; }
.light .callout-exercise { background: rgba(34, 197, 94, 0.05); }
.navy .callout-exercise, .coal .callout-exercise, .ayu .callout-exercise { background: rgba(34, 197, 94, 0.08); }
.callout-exercise .callout-label { color: #22c55e; }

/* H2 section classes kept for JS compatibility — no bottom borders */

/* --- Code Block Language Labels --- */
.code-lang-label {
  position: absolute;
  top: 0;
  right: 0;
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2em 0.7em;
  border-radius: 0 8px 0 6px;
  pointer-events: none;
  z-index: 1;
}

.light .code-lang-label {
  background: rgba(0, 0, 0, 0.06);
  color: rgba(0, 0, 0, 0.45);
}

.navy .code-lang-label,
.coal .code-lang-label {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.4);
}

.ayu .code-lang-label {
  background: rgba(255, 180, 84, 0.08);
  color: rgba(255, 180, 84, 0.5);
}

/* --- Sidebar tweaks --- */
.sidebar .sidebar-scrollbox {
  font-family: var(--font-body);
  font-size: 0.88rem;
}

/* Part separators in sidebar */
.sidebar .chapter li.part-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.92rem;
  margin-top: 1.4em;
  color: var(--sidebar-active);
  letter-spacing: 0.02em;
}

/* Active sidebar item — colored left accent */
.sidebar .chapter li.chapter-item a.active {
  font-weight: 600;
  border-left: 3px solid;
  padding-left: 8px;
  margin-left: -3px;
}

.light .sidebar .chapter li.chapter-item a.active {
  border-left-color: #3b82f6;
}

.navy .sidebar .chapter li.chapter-item a.active {
  border-left-color: #60a5fa;
}

.coal .sidebar .chapter li.chapter-item a.active {
  border-left-color: #60a5fa;
}

.ayu .sidebar .chapter li.chapter-item a.active {
  border-left-color: #ffb454;
}

/* Hide in-page headings from sidebar — show only Parts and Module names */
.sidebar .on-this-page {
  display: none;
}

/* --- Navigation footer --- */
.nav-chapters {
  font-family: var(--font-body);
  font-size: 0.95rem;
}

/* --- Print styles --- */
@media print {
  .callout {
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .content main {
    font-size: 1rem;
    line-height: 1.7;
  }

  .content main h1 {
    font-size: 1.6rem;
  }

  .content main h2 {
    font-size: 1.45rem;
  }

  .content main pre {
    font-size: 0.82rem;
    padding: 0.8em 1em;
  }

  .callout {
    padding: 0.8em 1em;
  }
}
