/* ==========================================================================
   The Pacifica Handbook — stylesheet
   Brand colors extracted from docs.pacifica.fi (--primary: 17 120 102, etc.)
   ========================================================================== */

:root {
  /* Pacifica brand palette */
  --primary:        #117866;   /* Pacifica primary green */
  --primary-bright: #4ADE80;   /* bright emerald */
  --primary-deep:   #166534;   /* deep forest */
  --primary-soft:   rgba(74, 222, 128, 0.10);
  --primary-line:   rgba(74, 222, 128, 0.25);

  /* Neutrals */
  --bg:             #0F1117;
  --bg-elev:        #161922;
  --bg-elev-2:      #1C2030;
  --border:         rgba(255, 255, 255, 0.08);
  --border-strong:  rgba(255, 255, 255, 0.16);

  /* Text */
  --text:           #F4F4F5;
  --text-soft:      #A1A1AA;
  --text-muted:     #71717A;

  /* Accent */
  --warn:           #F0B90B;
  --danger:         #EF4444;

  /* Type */
  --font-sans:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display:   'Space Grotesk', 'Inter', sans-serif;
  --font-mono:      'JetBrains Mono', 'PaperMono', ui-monospace, monospace;

  /* Layout */
  --radius:         12px;
  --radius-sm:      8px;
  --radius-lg:      16px;
  --max-w:          1200px;
  --pad:            24px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow-x: hidden;
}

a { color: var(--primary-bright); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--text); }
code, pre { font-family: var(--font-mono); font-size: 0.9em; }
code { background: var(--bg-elev); padding: 0.15em 0.4em; border-radius: 4px; color: var(--primary-bright); }
pre { background: var(--bg-elev); padding: 16px; border-radius: var(--radius-sm); overflow-x: auto; border: 1px solid var(--border); }
pre code { background: transparent; padding: 0; color: var(--text); }

/* Background */
.bg-grid {
  position: fixed; inset: 0; z-index: -2;
  background-image:
    linear-gradient(rgba(74, 222, 128, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(74, 222, 128, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at top, black 30%, transparent 80%);
}
.bg-glow {
  position: fixed; top: -300px; right: -300px; width: 800px; height: 800px;
  background: radial-gradient(circle, var(--primary-soft), transparent 60%);
  z-index: -1;
  pointer-events: none;
}

.container { max-width: var(--max-w); margin: 0 auto; padding: 0 var(--pad); }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(15, 17, 23, 0.7);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; font-size: 1.05rem; }
.brand-text { font-family: var(--font-display); letter-spacing: -0.02em; }
.header-nav { display: flex; gap: 28px; align-items: center; }
.header-nav a { color: var(--text-soft); font-size: 0.9rem; font-weight: 500; }
.header-nav a:hover { color: var(--text); }
.header-nav .cta {
  background: var(--primary-bright); color: #0F1117;
  padding: 8px 16px; border-radius: 8px; font-weight: 600;
}
.header-nav .cta:hover { background: var(--primary); color: white; }

/* Hero */
.hero {
  padding: 100px 0 80px;
  position: relative;
}
.hero-eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--primary-soft); color: var(--primary-bright);
  padding: 6px 14px; border-radius: 999px; font-size: 0.85rem; font-weight: 500;
  border: 1px solid var(--primary-line); margin-bottom: 24px;
}
.hero-eyebrow .dot {
  width: 6px; height: 6px; background: var(--primary-bright);
  border-radius: 50%; box-shadow: 0 0 8px var(--primary-bright);
}
.hero-title {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 700; line-height: 1.05;
  letter-spacing: -0.03em;
  max-width: 18ch;
  margin-bottom: 28px;
}
.hero-title .grad {
  background: linear-gradient(135deg, var(--primary-bright), #22d3ee);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub {
  font-size: 1.15rem; color: var(--text-soft); max-width: 65ch; margin-bottom: 40px;
  line-height: 1.7;
}
.hero-sub a { color: var(--primary-bright); text-decoration: underline; text-underline-offset: 3px; }
.hero-cta { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 64px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 24px; border-radius: 10px; font-weight: 600; font-size: 0.95rem;
  transition: all 0.15s; border: 1px solid transparent;
}
.btn-primary { background: var(--primary-bright); color: #0F1117; }
.btn-primary:hover { background: var(--primary); color: white; transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--bg-elev); border-color: var(--primary-bright); }

.hero-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px;
  padding: 24px; background: var(--bg-elev); border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.stat-value { font-family: var(--font-display); font-size: 1.8rem; font-weight: 700; color: var(--primary-bright); letter-spacing: -0.02em; }
.stat-label { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }

/* Section heads */
.section-head { text-align: center; margin-bottom: 64px; }
.section-head h2 {
  font-family: var(--font-display); font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 700; letter-spacing: -0.02em; margin-bottom: 16px;
}
.section-head p { color: var(--text-soft); font-size: 1.05rem; max-width: 60ch; margin: 0 auto; }

/* Catalog */
.catalog { padding: 80px 0; }
.part { margin-bottom: 80px; }
.part-header {
  display: flex; align-items: baseline; gap: 16px;
  padding-bottom: 16px; border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}
.part-num { font-family: var(--font-mono); color: var(--primary-bright); font-size: 0.85rem; font-weight: 500; }
.part-title { font-family: var(--font-display); font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
.part-count { color: var(--text-muted); font-size: 0.85rem; margin-left: auto; }
.chapter-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.chapter-card {
  display: block; padding: 20px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); transition: all 0.2s;
  color: var(--text); position: relative; overflow: hidden;
}
.chapter-card::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--primary-soft), transparent 50%);
  opacity: 0; transition: opacity 0.2s;
}
.chapter-card:hover { border-color: var(--primary-bright); transform: translateY(-2px); }
.chapter-card:hover::before { opacity: 1; }
.chapter-card .num { font-family: var(--font-mono); color: var(--primary-bright); font-size: 0.78rem; font-weight: 500; }
.chapter-card h3 {
  font-family: var(--font-display); font-size: 1.1rem; font-weight: 600;
  margin: 8px 0 8px; line-height: 1.3; letter-spacing: -0.01em;
  position: relative;
}
.chapter-card .desc { color: var(--text-soft); font-size: 0.88rem; line-height: 1.5; position: relative; }
.chapter-card .meta {
  display: flex; gap: 12px; margin-top: 14px; font-size: 0.75rem;
  color: var(--text-muted); position: relative;
}
.chapter-card .meta .dot { width: 3px; height: 3px; background: var(--text-muted); border-radius: 50%; align-self: center; }

/* About */
.about { padding: 80px 0; background: linear-gradient(180deg, transparent, var(--bg-elev) 30%, var(--bg-elev) 70%, transparent); }
.about-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px; margin-bottom: 64px;
}
.about-card {
  padding: 28px; background: var(--bg-elev-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.about-icon { font-size: 2rem; margin-bottom: 12px; }
.about-card h3 { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; margin-bottom: 8px; }
.about-card p { color: var(--text-soft); font-size: 0.95rem; }
.sources {
  padding: 32px; background: var(--bg-elev-2);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.sources h3 { font-family: var(--font-display); margin-bottom: 16px; }
.sources ul { list-style: none; columns: 2; column-gap: 32px; }
.sources li { padding: 6px 0; color: var(--text-soft); }
.sources li a { color: var(--primary-bright); }
@media (max-width: 600px) { .sources ul { columns: 1; } }

/* Footer */
.site-footer { padding: 64px 0; border-top: 1px solid var(--border); }
.footer-inner { display: flex; justify-content: space-between; gap: 32px; flex-wrap: wrap; }
.footer-inner strong { font-family: var(--font-display); }
.muted { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }
.site-footer a { color: var(--primary-bright); }

/* ====== Chapter page ====== */
.chapter-page { display: flex; min-height: calc(100vh - 64px); }
.chapter-sidebar {
  width: 320px; flex-shrink: 0; padding: 32px 24px;
  background: var(--bg-elev); border-right: 1px solid var(--border);
  position: sticky; top: 64px; align-self: flex-start;
  height: calc(100vh - 64px); overflow-y: auto;
}
.chapter-sidebar .back {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-muted); font-size: 0.85rem; margin-bottom: 24px;
}
.chapter-sidebar .part-label {
  font-family: var(--font-mono); color: var(--primary-bright);
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.chapter-sidebar h2 {
  font-family: var(--font-display); font-size: 1.25rem; font-weight: 700;
  letter-spacing: -0.02em; margin-bottom: 24px; line-height: 1.3;
}
.chapter-toc { list-style: none; }
.chapter-toc li { margin-bottom: 2px; }
.chapter-toc a {
  display: block; padding: 6px 10px; color: var(--text-soft);
  font-size: 0.85rem; border-radius: 6px;
  border-left: 2px solid transparent;
}
.chapter-toc a:hover { background: var(--bg-elev-2); color: var(--text); }
.chapter-toc a.active { color: var(--primary-bright); border-left-color: var(--primary-bright); background: var(--primary-soft); }

.chapter-content { flex: 1; padding: 48px 64px; max-width: 920px; margin: 0 auto; }
.chapter-content h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 2.75rem); font-weight: 700;
  letter-spacing: -0.02em; margin-bottom: 8px; line-height: 1.15;
}
.chapter-content .lead { color: var(--text-soft); font-size: 1.05rem; margin-bottom: 32px; }
.chapter-content h2 {
  font-family: var(--font-display);
  font-size: 1.6rem; font-weight: 700; margin: 48px 0 16px;
  letter-spacing: -0.01em; color: var(--text);
  border-top: 1px solid var(--border); padding-top: 32px;
}
.chapter-content h2:first-of-type { border-top: 0; padding-top: 0; margin-top: 24px; }
.chapter-content h3 {
  font-family: var(--font-display);
  font-size: 1.2rem; font-weight: 600; margin: 32px 0 12px;
  color: var(--text);
}
.chapter-content p { margin-bottom: 16px; color: var(--text-soft); }
.chapter-content p strong, .chapter-content li strong { color: var(--text); font-weight: 600; }
.chapter-content ul, .chapter-content ol { margin: 16px 0 16px 24px; color: var(--text-soft); }
.chapter-content li { margin-bottom: 6px; }
.chapter-content a { color: var(--primary-bright); text-decoration: underline; text-underline-offset: 3px; }
.chapter-content img { max-width: 100%; height: auto; border-radius: var(--radius); margin: 24px 0; border: 1px solid var(--border); display: block; }
.chapter-content table { width: 100%; border-collapse: collapse; margin: 24px 0; font-size: 0.9rem; }
.chapter-content th {
  text-align: left; padding: 12px; background: var(--bg-elev-2);
  font-weight: 600; color: var(--text); border-bottom: 1px solid var(--border-strong);
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
}
.chapter-content td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-soft); }
.chapter-content td code { font-size: 0.8em; }
.chapter-content tr:hover td { background: var(--bg-elev); }
.chapter-content blockquote {
  margin: 24px 0; padding: 16px 20px;
  background: var(--bg-elev); border-left: 3px solid var(--primary-bright);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-soft); font-style: italic;
}

.chapter-nav {
  display: flex; justify-content: space-between; gap: 16px;
  margin-top: 80px; padding-top: 32px; border-top: 1px solid var(--border);
}
.chapter-nav .nav-card {
  display: block; flex: 1; padding: 16px 20px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); transition: all 0.15s;
}
.chapter-nav .nav-card.next { text-align: right; }
.chapter-nav .nav-card:hover { border-color: var(--primary-bright); }
.chapter-nav .nav-label { font-family: var(--font-mono); color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.chapter-nav .nav-title { font-weight: 600; margin-top: 4px; }
.chapter-nav .nav-card.disabled { opacity: 0.4; pointer-events: none; }

/* Mobile */
@media (max-width: 900px) {
  .hero-stats { grid-template-columns: repeat(2, 1fr); }
  .header-nav a:not(.cta) { display: none; }
  .chapter-page { flex-direction: column; }
  .chapter-sidebar { width: 100%; position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .chapter-content { padding: 32px 24px; }
  .chapter-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .hero { padding: 60px 0 40px; }
  .hero-stats { grid-template-columns: 1fr 1fr; }
  .catalog, .about { padding: 48px 0; }
}
