/* Design tokens */
:root {
  --bg: #0a0a0f;
  --bg2: #0f0f18;
  --glass: rgba(255,255,255,0.04);
  --glass-border: rgba(255,255,255,0.08);
  --fire: #ff6b35;
  --amber: #f4a261;
  --teal: #4ecdc4;
  --yellow: #ffe66d;
  --red: #e76f51;
  --steel: #457b9d;
  --text: #e8e8e8;
  --dim: #999;
  --muted: #444;
  --font-head: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}
* { margin:0; padding:0; box-sizing:border-box; }
html { scroll-behavior: smooth; }
body { font-family: var(--font-body); background: var(--bg); color: var(--text); overflow-x: hidden; line-height: 1.6; }

/* PROGRESS BAR */
#progress-bar { position:fixed; top:0; left:0; height:3px; width:0%; background:linear-gradient(90deg,var(--fire),var(--amber),var(--red),var(--teal),var(--steel)); background-size:200% 100%; z-index:9999; transition:width 0.1s linear; }

/* NAV */
#nav { position:fixed; top:0; left:0; width:100%; height:52px; background:rgba(10,10,15,0.85); backdrop-filter:blur(16px); -webkit-backdrop-filter:blur(16px); border-bottom:1px solid var(--glass-border); z-index:1000; transition:transform 0.4s ease; }
#nav.nav-hidden { transform:translateY(-100%); }
.nav-inner { max-width:1400px; margin:0 auto; height:100%; display:flex; align-items:center; padding:0 2rem; }
.nav-brand { font-family:var(--font-head); font-weight:700; font-size:0.9rem; color:var(--fire); letter-spacing:1px; margin-right:auto; }
.nav-links { display:flex; gap:2rem; list-style:none; }
.nav-link { font-size:0.8rem; color:var(--dim); cursor:pointer; letter-spacing:0.5px; transition:color 0.3s; font-family:var(--font-head); }
.nav-link:hover, .nav-link.active { color:var(--fire); }
.nav-home { margin-left:auto; font-size:0.8rem; color:var(--teal); cursor:pointer; font-family:var(--font-head); }

/* HERO */
.full-section { position:relative; width:100vw; height:100vh; display:flex; align-items:center; justify-content:center; overflow:hidden; }
#ember-canvas { position:absolute; inset:0; width:100%; height:100%; z-index:1; }
.hero-content { position:relative; z-index:2; text-align:center; padding:2rem; max-width:700px; }
.hero-pre { font-size:0.8rem; letter-spacing:5px; text-transform:uppercase; color:var(--teal); margin-bottom:2rem; opacity:0; animation:fadeUp 1s 0.5s forwards; }
.hero-title { font-family:var(--font-head); font-size:clamp(2.5rem,6vw,5rem); font-weight:700; line-height:1.1; margin-bottom:1.5rem; }
.title-line { display:block; background:linear-gradient(135deg,var(--fire),var(--yellow)); -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; }
.hero-tagline { font-size:1.05rem; color:var(--dim); margin:0 auto 3rem; line-height:1.7; opacity:0; animation:fadeUp 1s 2.5s forwards; }
.scroll-cue { opacity:0; animation:fadeUp 1s 3s forwards; color:var(--dim); font-size:0.8rem; letter-spacing:2px; }
.scroll-arrow { width:20px; height:20px; margin:0.8rem auto 0; border-right:2px solid var(--dim); border-bottom:2px solid var(--dim); transform:rotate(45deg); animation:bounce 2s infinite; }
@keyframes fadeUp { from{opacity:0;transform:translateY(30px)} to{opacity:1;transform:translateY(0)} }
@keyframes bounce { 0%,100%{transform:rotate(45deg) translateY(0)} 50%{transform:rotate(45deg) translateY(8px)} }

/* BRIDGE */
/* Bridge canvas centered at fixed 400 by 400, text overlays via z index 3 */
.bridge {
  position: relative;
  overflow: hidden;
  height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg2);
}

.bridge-canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px !important;
  height: 400px !important;
  z-index: 2;
  pointer-events: none;
}

.bridge-text {
  position: absolute;
  z-index: 3;
  text-align: center;
  max-width: 700px;
  pointer-events: none;
  font-family: var(--font-head);
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  color: var(--dim);
  line-height: 1.8;
}
.bridge-text strong { color: var(--text); }
.bridge-q { color: var(--fire); font-style: italic; }

/* CHAPTER */
.chapter { padding:5rem 2rem 4rem; max-width:1400px; margin:0 auto; }
.chapter-header { display:flex; align-items:baseline; gap:1rem; margin-bottom:1rem; justify-content:center; }
.ch-num { font-family:var(--font-mono); font-size:3rem; font-weight:700; color:var(--fire); opacity:0.3; line-height:1; }
.chapter-header h2 { font-family:var(--font-head); font-size:2.2rem; font-weight:700; line-height:1.2; }
.ch-context { font-size:0.9rem; color:#bbb; line-height:1.7; margin-bottom:2.5rem; max-width:100%; }
.ch-section {
  margin: 3.5rem 0;
  padding: 2.5rem 2rem;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
}
.ch-section + .ch-section { margin-top: 2.5rem; }
.ch-section::before {
  content: "";
  display: block;
  width: 48px;
  height: 3px;
  background: linear-gradient(90deg, var(--fire), transparent);
  margin: 0 auto 1.2rem;
  border-radius: 2px;
}
.ch-subtitle {
  font-family: var(--font-head);
  font-size: 1.3rem;
  margin-bottom: 1.2rem;
  text-align: center;
  letter-spacing: 0.5px;
}

/* KPI */
.kpi-row { display:grid; grid-template-columns:repeat(4,1fr); gap:1rem; margin-bottom:2rem; }
.kpi-card { background:var(--glass); border:1px solid var(--glass-border); border-radius:12px; padding:1.2rem; text-align:center; backdrop-filter:blur(8px); }
.kpi-val { display:block; font-family:var(--font-mono); font-size:1.8rem; font-weight:700; color:var(--fire); margin-bottom:0.3rem; }
.kpi-lbl { font-size:0.72rem; color:var(--dim); letter-spacing:1px; text-transform:uppercase; }

/* CHART CONTAINERS */
.chart-box { background:var(--glass); border:1px solid var(--glass-border); border-radius:12px; padding:1.5rem; position:relative; }
.chart-wide { height:380px; }
.chart-scatter { height:auto; min-height:420px; }

/* TABS */
.traj-tabs { display:flex; gap:0.8rem; margin-bottom:1.5rem; flex-wrap:wrap; }
.traj-tab { flex:1; min-width:180px; background:var(--glass); border:1px solid var(--glass-border); border-radius:12px; padding:0.8rem 1rem; cursor:pointer; transition:all 0.3s; display:flex; align-items:center; gap:0.6rem; }
.traj-tab:hover, .traj-tab.active { border-color:var(--fire); }
.traj-tab.active { background:rgba(255,107,53,0.08); }
.tt-dot { display:inline-block; width:10px; height:10px; border-radius:50%; }
.dot-gray { background:var(--dim); }
.dot-fire { background:var(--fire); }
.dot-teal { background:var(--teal); }
.lbl-dot { display:inline-block; width:8px; height:8px; border-radius:50%; vertical-align:middle; margin-right:4px; }
.tt-name { font-family:var(--font-head); font-weight:600; font-size:0.9rem; color:var(--text); }
.traj-panel { display:none; }
.traj-panel.active { display:flex; gap:2rem; align-items:flex-start; animation:fadeIn 0.4s ease; }
@keyframes fadeIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }
.tp-text { flex:0 0 30%; }
.tp-text h4 { font-family:var(--font-head); font-size:1.2rem; margin-bottom:0.6rem; }
.tp-text p { color:var(--dim); margin-bottom:0.5rem; font-size:0.9rem; }
.tp-text strong { color:var(--text); }
.tp-text em { color:var(--fire); font-style:normal; font-weight:600; }
.big-n { font-family:var(--font-mono); font-size:1.2rem; color:var(--fire); }
.tp-chart { flex:1; background:var(--glass); border:1px solid var(--glass-border); border-radius:12px; padding:1rem; min-height:240px; position:relative; }
.tp-chart canvas, .tp-chart svg { width:100%; height:100%; }

/* Doughnut chart sizing */
#chart-fa-wrap {
  height: 300px;
  max-width: 700px;
  width: 100%;
  padding: 0.5rem !important;
}
#chart-fa-wrap canvas {
  width: 100%;
  height: 100%;
}

/* TIME SLIDER */
.time-ctrl {
  display:flex; align-items:center; gap:1rem; margin-bottom:1rem;
  padding:0.7rem 1rem; background:var(--glass); border:1px solid var(--glass-border); border-radius:8px;
}
.time-btn { padding:0.35rem 0.8rem; font-size:0.75rem; font-family:var(--font-head); background:var(--fire); color:#fff; border:none; border-radius:4px; cursor:pointer; white-space:nowrap; }
.time-btn:hover { opacity:0.85; }
.time-btn-sec { background:var(--glass-border); color:var(--dim); }
.time-btn-sec.active { background:var(--teal); color:#fff; }
#time-slider { flex:1; height:4px; -webkit-appearance:none; appearance:none; background:var(--glass-border); border-radius:2px; outline:none; }
#time-slider::-webkit-slider-thumb { -webkit-appearance:none; width:14px; height:14px; background:var(--fire); border-radius:50%; cursor:pointer; }
.time-label { font-family:var(--font-mono); font-size:0.8rem; color:var(--fire); min-width:80px; text-align:center; }

/* SUB CATEGORY PILLS */
.sub-pills { display:flex; gap:0.3rem; margin-top:0.4rem; flex-wrap:wrap; justify-content:center; }
.pill {
  padding:0.2rem 0.5rem; font-size:0.65rem; font-family:var(--font-head);
  background:var(--glass); border:1px solid var(--glass-border); color:var(--dim);
  border-radius:20px; cursor:pointer; transition:all 0.2s;
}
.pill:hover { border-color:var(--pill-c, var(--fire)); color:var(--pill-c, var(--fire)); }
.pill.active { background:var(--pill-c, var(--fire)); color:#000; border-color:var(--pill-c, var(--fire)); }

/* TRIPLE MAP */
.triple-maps { display:flex; gap:0.8rem; height:400px; }
.map-third { flex:1; display:flex; flex-direction:column; }
.map-lbl {
  font-family: var(--font-head);
  font-size: 1rem;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 0.6rem;
  text-align: center;
  letter-spacing: 0.5px;
}
.map-box { flex:1; border-radius:12px; overflow:hidden; border:1px solid var(--glass-border); }
.map-large { height:450px; border-radius:12px; overflow:hidden; border:1px solid var(--glass-border); }
.single-map-wrap { margin-bottom:1rem; }
.map-ctrl-row { display:flex; gap:0.5rem; align-items:center; margin-top:0.6rem; }
.hover-info { margin-top:0.6rem; padding:0.6rem 1rem; background:var(--glass); border:1px solid var(--glass-border); border-radius:8px; text-align:center; font-size:0.85rem; min-height:36px; }
.hover-hint { color:var(--muted); }
.hover-info strong { color:var(--text); }
.hover-info em { color:var(--fire); font-style:normal; }

/* SPLIT ROW */
.inout-tabs { display:flex; gap:0.4rem; margin-bottom:1rem; }
.split-row { display:flex; gap:2rem; align-items:center; }
.split-text { flex:0 0 38%; }
.split-text p { color:var(--dim); margin-bottom:0.6rem; font-size:0.9rem; line-height:1.7; }
.split-text strong { color:var(--text); }
.split-text em { color:var(--teal); font-style:normal; font-weight:600; }
.split-chart { flex:1; height:300px; }
.stat-note { font-family:var(--font-mono); font-size:0.8rem; color:var(--teal); margin-top:0.5rem; }
.stat-cite { font-size:0.75rem; color:var(--muted); margin-top:0.3rem; }

/* SCROLLYTELLING Ch3 */
/* scrolly graphic 60 percent and scrolly steps 40 percent */
.scrolly { position:relative; display:flex; margin:2rem 0; }
.scrolly-graphic { position:sticky; top:60px; width:60%; height:calc(100vh - 80px); flex-shrink:0; background:var(--glass); border:1px solid var(--glass-border); border-radius:12px; padding:1.5rem; }
.scrolly-graphic canvas { width:100%; height:100%; }
.scrolly-steps { width:40%; padding:0 2rem; }
.step { padding:3rem 0; opacity:0.15; transition:opacity 0.6s ease; }
.step:first-child { padding-top:20vh; }
.step:last-child { padding-bottom:40vh; }
.step.is-active { opacity:1; }
.step-card { background:var(--glass); border:1px solid var(--glass-border); border-radius:12px; padding:1rem 1.2rem; backdrop-filter:blur(8px); }
.step-card h3 { font-family:var(--font-head); font-size:1.1rem; margin-bottom:0.5rem; }
.step-card p { color:var(--dim); margin-bottom:0.3rem; font-size:0.85rem; line-height:1.5; }
.step-card strong { color:var(--text); }
.sc-fire { border-left:3px solid var(--fire); }
.sc-teal { border-left:3px solid var(--teal); }
.sc-yellow { border-left:3px solid var(--yellow); }
.sc-contrast { border-left:3px solid var(--steel); }

/* CONCLUSION */
.ch5-section { display:flex; align-items:center; justify-content:center; min-height:80vh; text-align:center; }
.ch5-body { max-width:900px; margin:0 auto; }
.conclusion-title { font-family:var(--font-head); font-size:2rem; margin-bottom:1.5rem; }
.conclusion-lead { font-family:var(--font-head); font-size:1.4rem; line-height:1.8; margin-bottom:1rem; }
.conclusion-lead strong { color:var(--fire); }
.conclusion-text { font-size:1rem; color:var(--dim); line-height:1.8; margin-bottom:0.8rem; }
.conclusion-text em { color:var(--teal); font-style:italic; }
.methodology { text-align:left; margin-top:3rem; padding:2rem; background:var(--glass); border:1px solid var(--glass-border); border-radius:12px; }
.methodology h4 { font-family:var(--font-head); font-size:1rem; color:var(--teal); margin-bottom:0.5rem; margin-top:1rem; }
.methodology h4:first-child { margin-top:0; }
.methodology p { font-size:0.85rem; color:var(--dim); line-height:1.7; }
.methodology a { color:var(--teal); }
.methodology ul { padding-left:1.2rem; margin-top:0.5rem; }
.methodology li { font-size:0.8rem; color:var(--dim); margin-bottom:0.3rem; line-height:1.5; }
.credits { margin-top:2rem; color:var(--muted); font-size:0.8rem; }

/* RESPONSIVE */
@media (max-width:900px) {
  .kpi-row { grid-template-columns:repeat(2,1fr); }
  .traj-panel.active { flex-direction:column; }
  .triple-maps { flex-direction:column; height:auto; }
  .map-third { height:280px; }
  .split-row { flex-direction:column; }
  .split-chart { width:100%; flex:none; }
  .scrolly { flex-direction:column; }
  .scrolly-graphic { position:relative; width:100%; height:50vh; top:0; }
  .scrolly-steps { width:100%; }
  .stat-badge:hover {
    background: rgba(255,255,255,0.07) !important;
    border-color: rgba(255,255,255,0.25) !important;
    transform: translateY(-1px);
    transition: background 0.25s, border-color 0.25s, transform 0.2s;
  }
}

/* Additional components */

/* Signal Panel */
.signal-panel {
  position: sticky;
  top: 10vh;
  padding: 1.6rem 1.4rem;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  transition: background 0.6s ease, border-color 0.6s ease;
}
.signal-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 0.4rem;
}
.signal-subtitle {
  font-size: 0.78rem;
  color: #666;
  margin-bottom: 1.4rem;
  line-height: 1.5;
}
.signal-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.signal-item {
  display: grid;
  grid-template-columns: 14px 2px 1fr;
  grid-template-rows: auto 1fr;
  column-gap: 12px;
  padding: 10px 0;
  transition: opacity 0.4s ease;
}
.signal-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-top: 3px;
  grid-column: 1;
  grid-row: 1;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  flex-shrink: 0;
}
.signal-line {
  width: 2px;
  grid-column: 2;
  grid-row: 1 / 3;
  margin-left: 0;
  border-radius: 1px;
  min-height: 100%;
  transition: background 0.4s ease;
}
.signal-content {
  grid-column: 3;
  grid-row: 1 / 3;
}
.signal-name {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
  transition: opacity 0.4s ease;
}
.signal-desc {
  font-size: 0.76rem;
  color: #888;
  line-height: 1.6;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.4s ease, opacity 0.4s ease;
}
.signal-item.is-active .signal-dot { transform: scale(1.3); }
.signal-item.is-active .signal-desc { max-height: 120px; opacity: 1; }
.signal-item.is-active .signal-name { opacity: 1; }
.signal-item.is-dimmed .signal-dot { box-shadow: none; }
.signal-item.is-dimmed .signal-name { opacity: 0.3; }
.signal-item.is-dimmed .signal-line { background: rgba(255,255,255,0.05) !important; }

/* Ch5 Findings */
.findings-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.2rem;
  margin-bottom: 1rem;
}
.finding-card {
  border: 1px solid;
  border-radius: 12px;
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.finding-icon { font-size: 1.6rem; }
.finding-label {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.finding-stats { display: flex; flex-direction: column; gap: 4px; }
.finding-stat { font-size: 0.78rem; color: #ccc; }
.finding-desc {
  font-size: 0.78rem;
  color: #aaa;
  line-height: 1.6;
  margin: 0;
  border-top: 1px solid rgba(255,255,255,0.05);
  padding-top: 0.8rem;
}

/* Resilience Grid */
.resilience-grid {
  display: grid;
  grid-template-columns: 1fr 2fr 0.6fr;
  gap: 1px;
  background: rgba(255,255,255,0.06);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.06);
}
.res-cell { background: rgba(15,15,20,0.9); padding: 1rem 1.2rem; }
.res-header-col { background: rgba(255,255,255,0.03); }
.res-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.res-dim { font-size: 0.95rem; font-weight: 700; margin-bottom: 4px; }
.res-subdim { font-size: 0.72rem; color: #555; line-height: 1.4; }
.res-evidence { font-size: 0.78rem; color: #888; line-height: 1.6; }
.res-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  margin-top: 4px;
}
.res-amber { background: rgba(255,200,80,0.12); color: #ffc850; }
.res-red { background: rgba(255,80,80,0.1); color: #ff6b6b; }

/* Season Toggle */
.season-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.season-btn {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.15);
  background: transparent;
  color: #888;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}
.season-btn:hover { border-color: rgba(255,255,255,0.3); color: #ccc; }
.season-btn.active {
  background: rgba(255,107,53,0.15);
  border-color: rgba(255,107,53,0.5);
  color: #ff6b35;
}
.season-btn.active.winter {
  background: rgba(78,205,196,0.15);
  border-color: rgba(78,205,196,0.5);
  color: #4ecdc4;
}
.season-btn.active.entry {
  background: rgba(69,123,157,0.15);
  border-color: rgba(69,123,157,0.5);
  color: #457b9d;
}

/* Ward Popup Mapbox */
.ward-popup .mapboxgl-popup-content {
  background: rgba(10,10,15,0.92);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.ward-popup .mapboxgl-popup-tip {
  border-top-color: rgba(10,10,15,0.92);
}