/* ============================================================
   State of Britain — Shared Styles
   Common CSS used across all story pages.
   Page-specific accent colors and unique rules live in pages/css/.

   NAMING CONVENTIONS:
   - CSS classes: kebab-case (e.g. .scroll-section, .step-inner)
   - BEM-like: .chart-tooltip, .chart-annotation, .chart-annotation-bold
   - Layout: .scroll-section > .scroll-steps + .scroll-graphic
   - Big numbers: .big-number.[color] (red, green, amber, blue + page-specific)
   - IDs: kebab-case with prefix (bn- for big numbers, chart- for containers)
   - JS functions: sobCamelCase prefix for shared utils
   - Page JS functions: camelCase (buildGapChart, updateChart, init)
   ============================================================ */

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: #FAFAF7;
  color: #1A1A1A;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Loading / Error ---------- */
#loading-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: #FAFAF7;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  transition: opacity 0.5s;
}
#loading-screen.hidden { opacity: 0; pointer-events: none; }
#loading-screen .spinner {
  width: 40px; height: 40px;
  border: 3px solid #E0E0DB;
  /* border-top-color is set per-page via inline style or page CSS */
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-screen p { margin-top: 16px; color: #555555; font-size: 0.95rem; }
#error-screen {
  display: none; position: fixed; inset: 0; z-index: 9998;
  background: #FAFAF7;
  flex-direction: column; align-items: center; justify-content: center;
}
#error-screen h2 { font-family: 'Source Serif 4', serif; font-size: 1.8rem; margin-bottom: 8px; }
#error-screen p { color: #555555; max-width: 400px; text-align: center; }

/* ---------- Header ---------- */
.site-header {
  padding: 48px 32px 24px;
  max-width: 1200px;
  margin: 0 auto;
}
.site-header .kicker {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  /* color is set per-page */
  margin-bottom: 8px;
}
.site-header h1 {
  font-family: 'Source Serif 4', serif;
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 700;
  line-height: 1.15;
  max-width: 700px;
  color: #1A1A1A;
}
.site-header .deck {
  margin-top: 12px;
  font-size: 1.15rem;
  color: #3D3D3D;
  max-width: 600px;
  line-height: 1.55;
}

/* ---------- Scroll sections ---------- */
.scroll-section {
  position: relative;
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 32px;
}
.scroll-steps {
  flex: 0 0 40%;
  position: relative;
  z-index: 2;
}
.scroll-graphic {
  flex: 0 0 58%;
  margin-left: 2%;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scroll-graphic .chart-container {
  width: 100%;
  position: relative;
}
.step {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px 0;
}
.step-inner {
  max-width: 420px;
  opacity: 0.15;
  transition: opacity 0.5s;
}
.step-inner.active {
  opacity: 1;
}
.step-inner h2 {
  font-family: 'Source Serif 4', serif;
  font-size: clamp(1.6rem, 3vw, 2.8rem);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 16px;
  color: #1A1A1A;
}
.step-inner p {
  font-size: 1.15rem;
  color: #3D3D3D;
  line-height: 1.6;
  margin-bottom: 12px;
}
.big-number {
  font-family: 'Source Serif 4', serif;
  font-size: clamp(3rem, 6vw, 5rem);
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 8px;
}
/* Common big-number colors — pages may add their own accent variants */
.big-number.red { color: #C53030; }
.big-number.green { color: #2E7D32; }
.big-number.amber { color: #A16B00; }
.big-number.blue { color: #2563A0; }

/* ---------- Tooltip ---------- */
.chart-tooltip {
  position: fixed;
  pointer-events: none;
  background: #fff;
  border: 1px solid #E0E0DB;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  color: #1A1A1A;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.15s;
  max-width: 280px;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-label { font-weight: 600; margin-bottom: 2px; }
.chart-tooltip .tt-value { color: #333333; }

/* ---------- Chart annotation ---------- */
.chart-annotation {
  font-size: 13px;
  fill: #555555;
  font-family: 'Inter', sans-serif;
}
.chart-annotation-bold {
  font-size: 13px;
  font-weight: 600;
  fill: #1A1A1A;
  font-family: 'Inter', sans-serif;
}

/* ---------- Section divider ---------- */
.section-divider {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 32px;
  height: 1px;
  background: transparent;
}

/* ---------- Footer ---------- */
.site-footer {
  max-width: 1200px;
  margin: 80px auto 0;
  padding: 32px 32px 48px;
  border-top: 1px solid #E0E0DB;
  font-size: 0.9rem;
  color: #555555;
  line-height: 1.7;
}
.site-footer a { color: #2563A0; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* ---------- SVG common ---------- */
.axis text {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  fill: #555555;
}
.axis path, .axis line { stroke: none; }
.grid line { stroke: #F0F0EB; stroke-width: 1; }
.grid path { stroke: none; }
.chart-container svg { overflow: visible; max-width: 100%; height: auto; }

/* ---------- Story nav ---------- */
.story-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 999;
  background: rgba(250,250,247,0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #E0E0DB;
  padding: 10px 24px;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
}
.story-nav a {
  color: #2563A0;
  text-decoration: none;
  font-weight: 500;
}
.story-nav .nav-separator {
  margin: 0 12px;
  color: #8A8A82;
}
.story-nav .nav-title {
  color: #555555;
  font-weight: 600;
}

/* ---------- Hidden until loaded ---------- */
.hidden-until-loaded {
  display: none;
}
.site-header.hidden-until-loaded { padding-top: 72px; }

/* ---------- Skip link (a11y) ---------- */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: #2563A0;
  color: #fff;
  padding: 8px 16px;
  z-index: 10000;
  font-size: 14px;
  text-decoration: none;
  border-radius: 0 0 4px 0;
}
.skip-link:focus {
  top: 0;
}

/* ---------- Focus indicators (a11y) ---------- */
*:focus-visible {
  outline: 3px solid #2563A0;
  outline-offset: 2px;
}

a:focus-visible {
  outline: 3px solid #2563A0;
  outline-offset: 2px;
  border-radius: 2px;
}

/* Ensure interactive SVG elements have visible focus */
.chart-container svg:focus-visible {
  outline: 3px solid #2563A0;
  outline-offset: 2px;
}

/* Visually hidden text for screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .step-inner { transition: none; }
  #loading-screen { transition: none; }
}

/* ---------- Responsive: tablet ---------- */
@media (max-width: 1024px) {
  .scroll-steps { flex: 0 0 45%; }
  .scroll-graphic { flex: 0 0 53%; margin-left: 2%; }
  .site-header { padding: 40px 24px 20px; }
  .scroll-section { padding: 0 24px; }
}

/* ---------- Responsive: mobile ---------- */
@media (max-width: 768px) {
  html, body { overflow-x: hidden; }
  .scroll-section {
    display: block;
    position: relative;
    padding: 0 16px;
  }
  .scroll-steps {
    position: relative;
    z-index: 2;
    width: 100%;
  }
  .scroll-graphic {
    position: sticky;
    top: 0;
    width: 100%;
    height: 45vh;
    margin-left: 0;
    z-index: 1;
  }
  .step {
    min-height: 80vh;
  }
  .step-inner {
    max-width: 100%;
    background: rgba(250,250,247,0.92);
    padding: 16px;
    border-radius: 8px;
  }
  .big-number {
    font-size: clamp(2.2rem, 8vw, 3.2rem);
    word-break: break-word;
  }
  .site-header {
    padding: 32px 16px 20px;
  }
  .site-header h1 { font-size: 2rem; }
  .site-header .deck { font-size: 1rem; }
  .site-footer { padding: 24px 16px 32px; margin-top: 40px; }
  .chart-tooltip { max-width: 200px; font-size: 12px; }
  .story-nav { padding: 12px 16px !important; font-size: 13px !important; }
  .story-nav a { min-height: 44px; display: inline-flex; align-items: center; }
  .scroll-graphic { top: 44px !important; }
  .site-header { padding-top: 60px !important; }
  .story-pagination { flex-direction: column; padding: 0 16px; margin-top: 40px; }
  .story-pagination a { max-width: 100%; }
}

/* ---------- Story Pagination ---------- */
.story-pagination {
  max-width: 1200px;
  margin: 64px auto 0;
  padding: 0 32px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
}
.story-pagination a {
  display: block;
  flex: 1;
  max-width: 48%;
  padding: 20px 24px;
  background: #fff;
  border: 1px solid #E5E5E0;
  border-radius: 10px;
  text-decoration: none;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.story-pagination a:hover {
  border-color: #C8C8C0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  transform: translateY(-1px);
}
.story-pagination .page-dir {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8A8A82;
  margin-bottom: 6px;
}
.story-pagination .page-title {
  display: block;
  font-family: 'Source Serif 4', serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: #1A1A1A;
  line-height: 1.3;
}
.story-pagination .next-link { text-align: right; margin-left: auto; }

/* ---------- Reading Progress Bar ---------- */
.progress-bar {
  position: fixed; top: 0; left: 0;
  height: 3px; width: 0%;
  background: var(--accent, #2563A0);
  z-index: 1001;
  pointer-events: none;
}

/* ---------- Responsive: small mobile ---------- */
@media (max-width: 375px) {
  .site-header h1 { font-size: 1.7rem; }
  .step-inner h2 { font-size: 1.4rem; }
  .step-inner p { font-size: 1rem; }
  .big-number { font-size: clamp(1.8rem, 10vw, 2.8rem); }
}

/* ---------- Touch-friendly ---------- */
@media (pointer: coarse) {
  .chart-tooltip { font-size: 13px; padding: 12px 16px; }
  a, button, .story-nav a { min-height: 44px; }
}

/* ---------- Print ---------- */
@media print {
  .story-nav, .skip-link, #loading-screen, #error-screen { display: none !important; }
  .scroll-section { display: block; }
  .scroll-graphic { position: static; height: auto; }
  .step { min-height: auto; break-inside: avoid; }
  .step-inner { opacity: 1 !important; }
}
