/* ==========================================================================
   Handbook of Well-Being — Modern Editorial Design
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=Source+Sans+3:ital,wght@0,300..900;1,300..900&display=swap');

:root {
  --bg: #fdfbf7;
  --bg-elevated: #ffffff;
  --bg-subtle: #f7f4ed;
  --fg: #1a1a1a;
  --fg-muted: #5c5c5c;
  --fg-soft: #8a8a8a;
  --accent: #2d6a4f;
  --accent-light: #40916c;
  --accent-subtle: rgba(45, 106, 79, 0.08);
  --highlight: #d4a373;
  --highlight-subtle: rgba(212, 163, 115, 0.15);
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.12);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --font-serif: 'Libre Baskerville', Georgia, serif;
  --font-sans: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition-fast: 150ms ease;
  --transition-med: 250ms ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121210;
    --bg-elevated: #1a1917;
    --bg-subtle: #1f1e1b;
    --fg: #f5f4f0;
    --fg-muted: #a8a8a5;
    --fg-soft: #727270;
    --accent: #52b788;
    --accent-light: #74c69d;
    --accent-subtle: rgba(82, 183, 136, 0.12);
    --highlight: #e9c46a;
    --highlight-subtle: rgba(233, 196, 106, 0.12);
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.12);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.7;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.02em;
  
}

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

/* Skip Link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 16px;
  z-index: 9999;
  padding: 12px 20px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-md);
}
.skip-link:focus { left: 16px; }

/* ==========================================================================
   HEADER
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 40px;
}

.brand { display: flex; flex-direction: column; gap: 2px; }
.brand a { font-family: var(--font-serif); font-size: 1.15rem; font-weight: 500; color: var(--fg); text-decoration: none;  }
.brand small { font-size: 0.75rem; color: var(--fg-soft); }

.nav { display: flex; gap: 8px; flex-wrap: wrap; }
.nav a { padding: 8px 14px; font-size: 0.9rem; color: var(--fg-muted); border-radius: var(--radius-sm); white-space: nowrap; }
.nav a:hover { background: var(--accent-subtle); color: var(--fg); text-decoration: none; }

/* ==========================================================================
   HOMEPAGE CONTAINER - FULL WIDTH
   ========================================================================== */
.home-main {
  display: block;
  padding: 0;
}

.container {
  width: 100%;
  padding: 40px;
}

/* ==========================================================================
   HERO - FULL WIDTH
   ========================================================================== */
.hero {
  position: relative;
  padding: 60px;
  margin-bottom: 40px;
  background: linear-gradient(135deg, var(--bg-elevated) 0%, var(--bg-subtle) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 50%;
  height: 200%;
  background: radial-gradient(ellipse, var(--accent-subtle) 0%, transparent 70%);
  pointer-events: none;
}

.hero-inner {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 60px;
  align-items: center;
}

.hero h1 {
  font-size: clamp(2.2rem, 4vw, 3.5rem);
  font-weight: 400;
  margin: 0 0 16px;
  
}

.hero h1::after {
  content: '';
  display: block;
  width: 80px;
  height: 4px;
  margin-top: 24px;
  background: linear-gradient(90deg, var(--accent), var(--highlight));
  border-radius: 2px;
}

.lead {
  font-size: 1.15rem;
  color: var(--fg-muted);
  margin: 24px 0;
  max-width: 600px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 24px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: white;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all var(--transition-med);
}
.btn:hover { background: var(--accent-light); transform: translateY(-2px); color: white; text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border-strong);
}
.btn-ghost:hover { background: var(--accent-subtle); border-color: var(--accent); color: var(--accent); }

.hero-meta {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.pill {
  padding: 20px 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--fg-muted);
}
.pill strong { color: var(--fg); font-weight: 600; display: block; margin-bottom: 4px; }

/* ==========================================================================
   HOME GRID - FULL WIDTH
   ========================================================================== */
.home-grid {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 40px;
  align-items: start;
}

.home-left {
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 100px;
}

.home-right {
  min-width: 0;
}

/* Cards */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.card h2 {
  font-size: 1rem;
  font-family: var(--font-sans);
  font-weight: 600;
  margin: 0 0 16px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: none;
  padding: 0;
}

.card p { margin: 0 0 12px; }
.card p:last-child { margin: 0; }

/* Editors page */
.editor-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.editor-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: var(--bg);
}

.editor-role {
  margin: 6px 0 12px;
  color: var(--fg-muted);
  font-size: 0.92rem;
  font-weight: 500;
}

@media (max-width: 900px) {
  .editor-grid { grid-template-columns: 1fr; }
}

.muted { color: var(--fg-muted); }
.small { font-size: 0.88rem; }

.clean { margin: 16px 0 0; padding-left: 1.4em; }
.clean li { margin: 8px 0; }

/* Chapters */
.chapters-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.search input {
  width: 280px;
  padding: 12px 16px;
  font-size: 0.95rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.search input:focus { outline: none; border-color: var(--accent); }

ol.chapter-list {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: chapter;
}

/* When search filtering is active, we render stable numbers via .chapter-num spans.
   Disable CSS counters to avoid duplicate numbering (e.g., 01 01). */
ol.chapter-list.chapter-list--stable {
  counter-reset: none;
}

ol.chapter-list.chapter-list--stable li {
  counter-increment: none;
}

ol.chapter-list.chapter-list--stable li::before {
  content: none;
}

.chapter-num {
  font-family: var(--font-serif);
  font-size: 0.85rem;
  color: var(--fg-soft);
  min-width: 28px;
  flex-shrink: 0;
  
}

ol.chapter-list li {
  counter-increment: chapter;
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

ol.chapter-list li::before {
  content: counter(chapter, decimal-leading-zero);
  font-family: var(--font-serif);
  font-size: 0.85rem;
  color: var(--fg-soft);
  min-width: 28px;
  flex-shrink: 0;
  
}

.chapter-content {
  flex: 1;
  line-height: 1.5;
}

ol.chapter-list a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

ol.chapter-list a strong {
  font-weight: 600;
}

ol.chapter-list a:hover {
  text-decoration: underline;
}

.chapter-authors {
  color: var(--fg-muted);
  font-size: 0.88em;
  font-weight: 400;
}

ol.chapter-list li:hover {
  background: var(--accent-subtle);
}

/* Section headers in chapter list */
ol.chapter-list li.section-header {
  background: var(--bg-subtle);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 12px 18px;
  margin-top: 8px;
  border-bottom: 2px solid var(--accent);
  counter-increment: none;
}

ol.chapter-list li.section-header:first-child {
  margin-top: 0;
}

ol.chapter-list li.section-header::before {
  content: none;
}

ol.chapter-list li.section-header:hover {
  background: var(--bg-subtle);
}

/* Footer */
.footer {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
  color: var(--fg-muted);
  font-size: 0.9rem;
}

/* ==========================================================================
   CHAPTER PAGES
   ========================================================================== */
main {
  display: grid;
  grid-template-columns: 240px minmax(0, 800px);
  gap: 40px;
  padding: 32px 40px 80px;
  align-items: start;
  max-width: 1200px;
  margin: 0 auto;
  justify-content: center;
}

aside.card.toc {
  position: sticky;
  top: 90px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 24px;
}

aside.card.toc h2 {
  font-size: 0.85rem;
  margin: 0 0 16px;
}

.toc ol { margin: 0; padding: 0; list-style: none; }
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: 10px 14px;
  font-size: 0.9rem;
  color: var(--fg-muted);
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
}
.toc a:hover {
  color: var(--fg);
  background: var(--accent-subtle);
  border-left-color: var(--accent);
  text-decoration: none;
}

.toc hr { margin: 20px 0; border: none; border-top: 1px solid var(--border); }
.toc .nav { flex-direction: column; gap: 6px; }
.toc .nav a { padding: 10px 14px; }

article.card.content {
  padding: 48px 56px;
  max-width: 100%;
  width: 100%;
}

article.card.content header {
  margin-bottom: 32px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}

article.card.content h1 {
  font-size: clamp(1.75rem, 3vw, 2.5rem);
  font-weight: 400;
  margin: 0 0 20px;
}

/* Section headers within chapter content */
article.card.content section h3 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 500;
  color: var(--accent);
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent-subtle);
  
}

article.card.content section h3:first-child {
  margin-top: 0;
}

article.card.content section h4 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--fg);
  margin: 1.8rem 0 0.8rem;
  
}

.meta-line { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }

.badge {
  display: block;
  padding: 12px 16px;
  font-size: 0.9rem;
  color: var(--fg-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  line-height: 1.6;
}
.badge strong { color: var(--accent); font-weight: 600; }

.author-list {
  margin-top: 8px;
  padding: 0;
  list-style: none;
}

.author-list li {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.author-list li:last-child {
  border-bottom: none;
}

.author-name {
  font-weight: 600;
  color: var(--fg);
}

.author-affiliation {
  color: var(--fg-muted);
  font-size: 0.88rem;
}

blockquote.citation {
  margin: 20px 0 0;
  padding: 20px 24px;
  background: var(--highlight-subtle);
  border-left: 4px solid var(--highlight);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: 0.92rem;
}

details {
  margin: 32px 0;
  padding: 18px 22px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
details summary { cursor: pointer; font-weight: 600; font-size: 0.95rem; }
details ul { margin: 16px 0 0; padding-left: 1.4em; }

/* Chapter Sections */
article section {
  margin-top: 48px;
}

article section:first-of-type {
  margin-top: 32px;
}

article section h2 {
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin: 0 0 24px;
  padding: 0;
}

article section p {
  margin: 0 0 20px;
}

article section p:last-child {
  margin-bottom: 0;
}

.keywords {
  margin-top: 28px;
  padding: 16px 20px;
  background: var(--accent-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.keywords strong { color: var(--accent); }

figure {
  margin: 40px 0;
  padding: 24px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
figure img { max-width: 100%; height: auto; display: block; margin: 0 auto; border-radius: var(--radius-sm); }
figcaption { margin-top: 16px; font-size: 0.88rem; color: var(--fg-muted); text-align: center; }

ol.refs { margin: 0; padding-left: 1.4em; }
ol.refs li { margin: 0 0 16px; font-size: 0.95rem; line-height: 1.6; }

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

article .footer {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  font-style: italic;
  color: var(--fg-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 1100px) {
  .hero-inner {
    grid-template-columns: 1fr;
  }
  
  .hero-meta {
    flex-direction: row;
    flex-wrap: wrap;
  }
  
  .hero-meta .pill {
    flex: 1 1 200px;
  }
  
  .home-grid {
    grid-template-columns: 1fr;
  }
  
  .home-left {
    position: static;
    order: 2;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
  }
  
  .home-right {
    order: 1;
  }
}

@media (max-width: 900px) {
  .container {
    padding: 24px;
  }
  
  .header-inner {
    padding: 14px 24px;
  }
  
  .nav a { 
    padding: 8px 12px; 
    font-size: 0.85rem; 
  }
  
  .hero {
    padding: 40px 32px;
  }
  
  main {
    grid-template-columns: 1fr;
    padding: 24px;
    max-width: 800px;
  }
  
  aside.card.toc {
    position: static;
    max-height: none;
  }
  
  article.card.content {
    padding: 32px 28px;
    max-width: 100%;
  }
}

@media (max-width: 600px) {
  .container {
    padding: 16px;
  }
  
  .header-inner {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .brand small { display: none; }
  
  .nav { 
    gap: 4px;
    justify-content: flex-end;
    flex: 1;
  }
  .nav a { 
    padding: 6px 10px; 
    font-size: 0.8rem; 
  }
  
  .hero {
    padding: 28px 20px;
  }
  
  .hero h1 { font-size: 1.8rem; }
  
  .hero-meta {
    flex-direction: column;
  }
  
  .search input { width: 100%; }
  
  .home-left {
    grid-template-columns: 1fr;
  }
  
  ol.chapter-list a {
    padding: 12px 14px;
  }
}

/* Print */
@media print {
  .site-header, aside.card.toc, .hero-actions, .search, details { display: none !important; }
  body { background: white; color: black; }
  article.card.content { box-shadow: none; border: none; padding: 0; }
}

/* Figure captions */
figure.figure-caption {
  margin: 2rem 0;
  padding: 1.5rem;
  background-color: var(--card);
  border-left: 4px solid var(--accent);
  border-radius: 0.25rem;
}

figure.figure-caption figcaption {
  font-size: 0.95rem;
  color: var(--fg);
  line-height: 1.6;
}

figure.figure-caption figcaption strong {
  color: var(--accent);
}

@media (prefers-color-scheme: dark) {
  figure.figure-caption {
    background-color: var(--card);
  }
}

/* Table captions */
.table-caption {
  margin: 2rem 0;
  padding: 1.5rem;
  background-color: var(--card);
  border-left: 4px solid var(--heading);
  border-radius: 0.25rem;
  font-size: 0.95rem;
  line-height: 1.6;
}

.table-caption strong {
  color: var(--heading);
}

@media (prefers-color-scheme: dark) {
  .table-caption {
    background-color: var(--card);
  }
}
