/* ==========================================================================
   DESIGN TOKENS
   Palette: deep ink-navy + slate blue-gray background + restrained antique
   gold accent. Chosen to read as considered and institutional rather than
   trendy — a study, not a startup.
   Display face: Source Serif 4 (headings, quotes) — a book/scripture feel.
   Body face: Source Sans 3 — quiet, highly legible workhorse.
   ========================================================================== */
:root {
  --ink-navy: #17233d;
  --ink-navy-light: #22355c;
  --slate-bg: #f3f5f7;
  --panel-bg: #ffffff;
  --hairline: #dde2e8;
  --text-primary: #232a33;
  --text-muted: #5b6673;
  --gold: #b3893f;
  --gold-deep: #8f6c2f;
  --focus-ring: #2f6fb0;

  --font-display: "Source Serif 4", Georgia, serif;
  --font-body: "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius-sm: 3px;
  --radius-md: 6px;
  --max-width: 780px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink-navy);
  color: #fff;
  padding: 10px 16px;
  z-index: 100;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- Header ---------- */
.site-header {
  background: var(--ink-navy);
  color: #f2f4f7;
  border-bottom: 3px solid var(--gold);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  color: var(--gold);
  flex-shrink: 0;
}
.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  letter-spacing: 0.01em;
}
.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: #b9c2d1;
}
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid #3a4a6b;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.menu-toggle span {
  display: block;
  height: 2px;
  width: 20px;
  margin: 0 auto;
  background: #f2f4f7;
}

/* ---------- Horizontal tab navigation (was: left sidebar) ---------- */
.tabnav {
  background: var(--ink-navy-light);
  border-bottom: 1px solid #2c3f66;
  position: sticky;
  top: 0;
  z-index: 20;
}
.tabnav-scroll {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 6px 8px;
  justify-content: center;
  align-items: center;
}

.tab-btn {
  flex: 0 0 auto;
  appearance: none;
  border: none;
  background: transparent;
  color: #cfd7e4;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 9px 12px;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  line-height: 1.3;
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.tab-btn:hover {
  color: #ffffff;
  background: rgba(255,255,255,0.04);
}
.tab-btn[aria-selected="true"] {
  color: #ffffff;
  border-bottom-color: var(--gold);
}

/* "Home & Essay" link in the header of standalone essay pages
   (fine_tuning.html, history.html, my_struggle.html) — set apart from the
   category tab row below it, at roughly 2x the tab row's text size. */
.header-home-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  color: #f2f4f7;
  text-decoration: none;
  padding: 8px 18px;
  border: 1px solid var(--gold);
  border-radius: var(--radius-md);
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.header-home-link:hover {
  background: var(--gold);
  color: var(--ink-navy);
}

/* ---------- Main / panels ---------- */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}
.panel-wrap { position: relative; }
.panel.is-hidden { display: none; }

/* ---------- Essay (home) ---------- */
.essay {
  max-width: var(--max-width);
  margin: 0 auto;
  background: var(--panel-bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 40px clamp(20px, 5vw, 56px) 56px;
}
.essay-header { margin-bottom: 8px; }
.essay h1 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2rem);
  line-height: 1.25;
  margin: 0 0 10px;
  color: var(--ink-navy);
}
.essay-subtitle {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--text-muted);
  font-size: 1.05rem;
  margin: 0 0 6px;
}
.essay-byline {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 24px;
}
.pull-quote {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--gold-deep);
  border-left: 3px solid var(--gold);
  padding-left: 16px;
  margin: 24px 0;
}
.essay p { margin: 0 0 18px; }
.essay h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--ink-navy);
  margin: 44px 0 16px;
  padding-top: 8px;
  border-top: 1px solid var(--hairline);
}
.essay section:first-of-type h2 { border-top: none; }
.essay figure {
  margin: 24px 0;
}
.essay figure img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  display: block;
  margin: 0 auto;
  border: 1px solid var(--hairline);
}
.figure-row {
  display: flex;
  gap: 16px;
  margin: 24px 0;
}
.figure-row figure {
  flex: 1 1 0;
  margin: 0;
  min-width: 0;
  display: flex;
  align-items: flex-end;
}
.figure-row figure img {
  width: 100%;
}
@media (max-width: 560px) {
  .figure-row {
    flex-direction: column;
  }
}
.essay blockquote {
  font-family: var(--font-display);
  font-size: 1.02rem;
  color: var(--text-primary);
  background: #f8f6f0;
  border-left: 3px solid var(--gold);
  margin: 20px 0;
  padding: 16px 20px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.essay blockquote cite {
  display: block;
  margin-top: 10px;
  font-family: var(--font-body);
  font-style: normal;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.numbered-points { padding-left: 22px; }
.numbered-points li { margin-bottom: 16px; }
.return-toc { font-size: 0.88rem; }
.return-toc a { color: var(--gold-deep); }

.toc {
  background: var(--slate-bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin: 24px 0 32px;
}
.toc-title {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 10px;
  color: var(--ink-navy);
}
.toc ol { margin: 0; padding-left: 20px; }
.toc li { margin-bottom: 6px; font-size: 0.94rem; }

.placeholder-note {
  font-size: 0.88rem;
  color: var(--text-muted);
  background: #fbf7ec;
  border: 1px dashed #d9c48b;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
}

.essay-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--hairline);
  scroll-margin-top: 16px;
}
.essay-section h2 {
  margin-top: 0;
  scroll-margin-top: 140px;
}
.section-nav {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px dashed var(--hairline);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.next-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  color: #ffffff;
  background: var(--ink-navy);
  padding: 11px 20px;
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.next-link:hover {
  background: var(--ink-navy-light);
  color: #ffffff;
}
.next-link .next-label {
  color: #cfd7e4;
  font-weight: 400;
  font-size: 0.82rem;
}
.next-link.back-link {
  background: transparent;
  color: var(--ink-navy);
  border: 1px solid var(--hairline);
  order: -1;
}
.next-link.back-link:hover {
  background: var(--slate-bg);
  border-color: var(--gold);
  color: var(--ink-navy);
}
.next-link.back-link .next-label {
  color: var(--text-muted);
}
.toc li.is-current > a {
  color: var(--gold-deep);
  font-weight: 700;
}

.essay-contact {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
  font-size: 0.9rem;
  color: var(--text-muted);
}

a { color: var(--ink-navy-light); }
a:hover { color: var(--gold-deep); }

.tab-link {
  color: var(--gold-deep);
  border-bottom: 1px dotted var(--gold-deep);
  text-decoration: none;
}
.tab-link:hover {
  color: var(--ink-navy);
  border-bottom-color: var(--ink-navy);
}

/* ---------- Category panels ---------- */
.category-panel {
  max-width: 960px;
  margin: 0 auto;
}
.category-head {
  margin-bottom: 20px;
}
.category-head h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--ink-navy);
  margin: 0 0 6px;
}
.category-head p {
  color: var(--text-muted);
  margin: 0;
}
.link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.link-card {
  display: block;
  background: var(--panel-bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text-primary);
  font-size: 0.94rem;
  line-height: 1.4;
  transition: border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.link-card:hover {
  border-color: var(--gold);
  box-shadow: 0 2px 10px rgba(23,35,61,0.08);
  color: var(--text-primary);
}
.link-card::before {
  content: "";
  display: inline-block;
}

.book-card {
  background: var(--panel-bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.book-card .book-title {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--ink-navy);
}
.book-card .book-by {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.book-card .book-extra a {
  font-size: 0.84rem;
  margin-right: 12px;
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  padding: 28px 24px 40px;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.footer-quote {
  font-family: var(--font-display);
  font-style: italic;
  margin-top: 6px;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .menu-toggle { display: flex; }
  .tabnav-scroll {
    display: none;
    flex-direction: column;
    padding: 8px;
  }
  .tabnav.is-open .tabnav-scroll {
    display: flex;
  }
  .tab-btn {
    text-align: left;
    border-bottom: none;
    border-left: 3px solid transparent;
    padding: 12px 14px;
  }
  .tab-btn[aria-selected="true"] {
    border-left-color: var(--gold);
    background: rgba(255,255,255,0.04);
  }
  .header-home-link {
    font-size: 1.2rem;
    padding: 7px 14px;
  }
  .essay { padding: 28px 18px 36px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
