/* =====================================================
   BASE.CSS — Variables, Reset, Typography, Layout
   AlphaFold Guide
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;0,900;1,400;1,700&family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;1,8..60,300;1,8..60,400&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ─── Custom Properties ─── */
:root {
  /* Backgrounds */
  --bg:            #fdfaf5;
  --bg-secondary:  #f5f0e8;
  --bg-card:       #ffffff;
  --bg-code:       #f0ebe0;
  --bg-highlight:  #fffbeb;

  /* Text */
  --text-primary:  #1c1917;
  --text-secondary:#44403c;
  --text-muted:    #78716c;
  --text-faint:    #a8a29e;

  /* Accents — main blue */
  --blue:          #1d4ed8;
  --blue-mid:      #3b82f6;
  --blue-light:    #dbeafe;
  --blue-pale:     #eff6ff;

  /* Accents — teal */
  --teal:          #0f766e;
  --teal-light:    #ccfbf1;
  --teal-pale:     #f0fdfa;

  /* Accents — amber */
  --amber:         #b45309;
  --amber-light:   #fde68a;
  --amber-pale:    #fffbeb;

  /* Accents — red */
  --red:           #b91c1c;
  --red-light:     #fecaca;
  --red-pale:      #fef2f2;

  /* Accents — green */
  --green:         #15803d;
  --green-light:   #bbf7d0;
  --green-pale:    #f0fdf4;

  /* Accents — purple */
  --purple:        #7e22ce;
  --purple-light:  #e9d5ff;
  --purple-pale:   #faf5ff;

  /* Structure */
  --border:        #e7e5e4;
  --border-mid:    #d6d3d1;
  --shadow-sm:     0 1px 2px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.08);
  --shadow:        0 2px 8px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.05);
  --shadow-md:     0 4px 16px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.06);
  --shadow-lg:     0 10px 30px rgba(0,0,0,.12), 0 4px 10px rgba(0,0,0,.06);

  /* Geometry */
  --radius-sm:     4px;
  --radius:        8px;
  --radius-lg:     14px;
  --radius-xl:     20px;

  /* Layout */
  --nav-height:    62px;
  --max-width:     1180px;
  --content-width: 700px;
  --sidebar-width: 230px;
}

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

html {
  font-size: 17px;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + 28px);
}

body {
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  line-height: 1.78;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-top: var(--nav-height);
}

img, video, svg { max-width: 100%; display: block; }
a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: #1e40af; }

/* ─── Typography ─── */
h1, h2, h3, h4, h5 {
  font-family: 'Playfair Display', Georgia, serif;
  line-height: 1.22;
  color: var(--text-primary);
  font-weight: 700;
}

h1 { font-size: clamp(2rem, 5vw, 3.2rem); }
h2 { font-size: clamp(1.5rem, 3.5vw, 2.1rem); margin-top: 2.4rem; margin-bottom: 0.8rem; }
h3 { font-size: 1.25rem; font-weight: 600; margin-top: 1.8rem; margin-bottom: 0.5rem; }
h4 { font-size: 1.05rem; font-weight: 600; margin-top: 1.4rem; margin-bottom: 0.4rem; font-family: 'Source Serif 4', serif; }

p { margin-bottom: 1.2rem; }
p:last-child { margin-bottom: 0; }

ul, ol { padding-left: 1.5rem; margin-bottom: 1.2rem; }
li { margin-bottom: 0.35rem; }

strong { font-weight: 600; color: var(--text-primary); }
em { font-style: italic; }

code, kbd {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.85em;
  background: var(--bg-code);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--teal);
  white-space: nowrap;
}

pre {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.83rem;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  overflow-x: auto;
  margin-bottom: 1.4rem;
  line-height: 1.7;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 1em;
  white-space: pre;
  color: var(--text-primary);
}

blockquote {
  border-left: 3px solid var(--blue-mid);
  padding: 0.6rem 1.2rem;
  margin: 1.4rem 0;
  background: var(--blue-pale);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--text-secondary);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.4rem;
  font-size: 0.92rem;
}
th {
  background: var(--bg-secondary);
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 2px solid var(--border-mid);
}
td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-secondary); }

/* ─── Layout ─── */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Content page layout: sidebar + main */
.content-layout {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: 3rem;
  align-items: start;
}

.main-content {
  min-width: 0;
  max-width: var(--content-width);
}

/* ─── Page Hero ─── */
.page-hero {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, #ede8de 100%);
  border-bottom: 1px solid var(--border);
  padding: 3.5rem 0 3rem;
  margin-bottom: 3.5rem;
}

.part-badge {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue);
  background: var(--blue-light);
  padding: 0.25rem 0.7rem;
  border-radius: 99px;
  margin-bottom: 0.9rem;
}

.page-hero h1 {
  margin-bottom: 0.8rem;
  max-width: 700px;
}

.lead {
  font-size: 1.12rem;
  color: var(--text-secondary);
  max-width: 600px;
  line-height: 1.65;
  margin-bottom: 0;
}

/* ─── Section spacing ─── */
.section {
  margin-bottom: 3.5rem;
  padding-top: 0.5rem;
  scroll-margin-top: calc(var(--nav-height) + 28px);
}

.section-label {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

/* ─── Reading progress bar ─── */
.reading-progress-bar {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--blue), var(--teal));
  width: 0%;
  z-index: 999;
  transition: width 0.1s linear;
}

/* ─── TOC Sidebar ─── */
.toc-sidebar {
  position: sticky;
  top: calc(var(--nav-height) + 24px);
  max-height: calc(100vh - var(--nav-height) - 48px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.toc-inner {
  padding: 1.2rem 1rem 1.2rem 0;
  border-right: 1px solid var(--border);
}

.toc-inner h4 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.7rem;
  margin-top: 0;
}

.toc-inner nav a {
  display: block;
  font-family: 'Source Serif 4', serif;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.28rem 0.5rem;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  margin-left: -2px;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  line-height: 1.35;
}

.toc-inner nav a:hover {
  color: var(--blue);
  background: var(--blue-pale);
}

.toc-inner nav a.active {
  color: var(--blue);
  border-left-color: var(--blue);
  background: var(--blue-pale);
  font-weight: 600;
}

.toc-inner nav .toc-sub {
  padding-left: 1rem;
  font-size: 0.82rem;
}

/* ─── Chapter Navigation ─── */
.chapter-nav {
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  margin: 3rem 0 0;
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  padding: 1rem 1.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
  max-width: 280px;
  min-width: 180px;
}

.chapter-nav a:hover {
  border-color: var(--blue-mid);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.chapter-nav .nav-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.chapter-nav .nav-title {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--blue);
  line-height: 1.3;
}

.chapter-nav-next { align-items: flex-end; text-align: right; margin-left: auto; }
.chapter-nav-prev { align-items: flex-start; }

/* ─── Footer ─── */
footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 2.5rem 0;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
}

footer a { color: var(--text-muted); }
footer a:hover { color: var(--blue); }

/* ─── Scroll reveal ─── */
.reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.reveal.visible {
  opacity: 1;
  transform: none;
}

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .content-layout {
    grid-template-columns: 1fr;
    padding: 0 1.2rem 3rem;
  }
  .toc-sidebar { display: none; }
  .main-content { max-width: 100%; }
  .chapter-nav { flex-direction: column; }
  .chapter-nav a { max-width: 100%; }
  .chapter-nav-next { align-items: flex-start; text-align: left; margin-left: 0; }
}

@media (max-width: 600px) {
  html { font-size: 16px; }
  h2 { font-size: 1.45rem; }
  .page-hero { padding: 2.5rem 0 2rem; }
}
