/* ─────────────────────────────────────────────────────────────
   Birth Lottery — design tokens
   Strict three-layer color system:
     1) Structure (warm ink, bone)
     2) Cohort identity (clay vs slate)
     3) Semantic signal (deficit / mid / parity / extinguished / highlight)
   Spin-violet appears only on the entrance.
   ───────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter+Tight:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  /* Structure */
  --bg: #16130E;
  --surface: #1E1A14;
  --surface-raised: #272219;
  --border: #37312A;
  --border-strong: #4A4338;

  --text: #F1EBDF;
  --text-muted: #B4AB9C;
  --text-dim: #807769;

  /* Cohort identity */
  --cohort-draw: #B58A63;
  --cohort-baseline: #6F8CA1;

  /* Semantic signal */
  --deficit: #BC463B;
  --mid: #C9974B;
  --parity: #7C9A6A;
  --extinguished: #2f2836;
  --highlight: #E8CB76;

  /* Entrance only */
  --spin-violet: #7B5CFF;

  /* Type */
  --font-sans: 'Inter Tight', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', ui-monospace, monospace;

  /* Legacy aliases for app.js color references */
  --bg-base: var(--bg);
  --bg-surface: var(--surface);
  --bg-glass: var(--surface);
  --text-primary: var(--text);
  --text-secondary: var(--text-muted);
  --text-muted-hsl: var(--text-dim);
  --primary: var(--spin-violet);
  --accent-safe: var(--parity);
  --accent-warn: var(--mid);
  --accent-risk: var(--deficit);
  --accent-info: var(--cohort-baseline);
  --radius-sm: 3px;
  --radius-md: 4px;
  --radius-lg: 6px;
  --transition-fast: 0.2s ease;
  --transition-normal: 0.35s ease;
  --transition-slow: 0.6s ease;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font-display: var(--font-sans);
  --font-body: var(--font-sans);
}

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

html,
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-feature-settings: 'ss01', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}

body {
  padding: 0.75rem;
}

@media (min-width: 768px) {
  body {
    padding: 1.5rem;
  }
}

/* Typographic utilities */
h1,
h2,
h3,
h4,
h5 {
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: -0.025em;
}

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.source-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-transform: uppercase;
}

::selection {
  background: var(--highlight);
  color: var(--bg);
}

/* ─── Panel (replaces glassmorphism) ─────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

@media (min-width: 768px) {
  .panel {
    padding: 1.5rem;
  }
}

/* ─── Layout ─────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
  min-width: 0;
}

main {
  min-width: 0;
  max-width: 100%;
}

@media (min-width: 768px) {
  .container {
    gap: 1.5rem;
  }
}

@media (min-width: 1024px) {
  .container {
    grid-template-columns: 320px minmax(0, 1fr);
  }
}

/* ─── Header ─────────────────────────────────────────────────── */
header {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: flex-start;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

@media (min-width: 768px) {
  header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

.logo-area h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text);
}

.logo-area h1 em {
  font-style: italic;
  color: var(--cohort-draw);
}

.logo-area p {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 2px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

/* ─── Settings bar ───────────────────────────────────────────── */
.settings-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

select,
input[type="text"] {
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
}

select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='rgba(180,171,156,0.6)' d='M0 0h10L5 6z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}

select:focus,
input[type="text"]:focus {
  border-color: var(--cohort-draw);
}

/* ─── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ─── Spinner panel ──────────────────────────────────────────── */
.spinner-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1rem;
}

.spinner-wheel-container {
  width: 260px;
  height: 260px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.35s ease, height 0.35s ease;
}

.wheel-expand-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 13px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
  margin-top: -4px;
}

.wheel-expand-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* ─── Wheel overlay ──────────────────────────────────────────── */
.wheel-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wheel-overlay.hidden {
  display: none;
}

.wheel-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(3px);
}

.wheel-overlay-panel {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.wheel-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.wheel-overlay-close {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 11px;
  padding: 0;
  transition: color 0.15s, border-color 0.15s;
}

.wheel-overlay-close:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.wheel-overlay-container {
  width: 480px;
  height: 480px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 600px) {
  .wheel-overlay-container {
    width: 320px;
    height: 320px;
  }
}

.spinner-wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid var(--border);
  position: absolute;
  background: var(--surface);
  overflow: hidden;
}

.spinner-wheel svg {
  display: block;
  width: 100%;
  height: 100%;
}

.spinner-needle {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 24px;
  background: var(--spin-violet);
  z-index: 5;
  transition: background 1s;
}

.spinner-needle::after {
  content: '';
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--spin-violet);
  transition: background 1s;
}

.spinner-needle.landed {
  background: var(--border-strong);
}

.spinner-needle.landed::after {
  background: var(--border-strong);
}

.spin-btn.spinning {
  background: #3d2f8f;
  opacity: 0.85;
  cursor: wait;
}

.spinner-center {
  width: 36px;
  height: 36px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}

/* ─── Spin button: violet at entrance only ───────────────────── */
.spin-btn {
  width: 100%;
  background: var(--spin-violet);
  color: #fff;
  border: none;
  padding: 0.85rem 1.5rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, transform var(--transition-fast);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.spin-btn:hover:not(:disabled) {
  background: #6a4de8;
  transform: translateY(-1px);
}

.spin-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.spin-btn:disabled {
  background: #3d2f8f;
  cursor: wait;
  opacity: 0.8;
}

/* After landing: go sober */
.spin-btn.landed {
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
}

.spin-btn.landed:hover {
  background: var(--border);
  color: var(--text);
}

/* ─── Secondary buttons ──────────────────────────────────────── */
.secondary-actions {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.btn-secondary {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  letter-spacing: 0.04em;
}

.btn-secondary:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary.active {
  border-color: var(--cohort-draw);
  color: var(--cohort-draw);
}

.spin-btn-secondary {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.6rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: all var(--transition-fast);
}

.spin-btn-secondary:hover {
  border-color: var(--border-strong);
  color: var(--text-muted);
}

/* ─── Filters panel ──────────────────────────────────────────── */
.filters-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.filters-panel h3 {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

/* ─── Main area ──────────────────────────────────────────────── */
main {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ─── Draw card ──────────────────────────────────────────────── */
.draw-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-left: none;
  padding: 1.5rem 2rem;
}

.draw-result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.draw-result-header-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 65%;
}

.draw-result-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.hero-main-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flag-title-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.country-flag {
  font-size: 3.5rem;
  line-height: 1;
}

.country-name {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text);
}

.demographic-draw-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.stitched-persona-text {
  font-size: 18px;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.45;
  max-width: 620px;
  border-left: none;
  padding-left: 0;
  margin: 0;
}

.characteristics-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.badge {
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  padding: 0.25rem 0.6rem;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.badge.primary {
  border-color: var(--cohort-draw);
  color: var(--cohort-draw);
}

/* ─── Devastating stat ───────────────────────────────────────── */
.devastating-stat-box {
  background: var(--surface-raised);
  border: 1px solid var(--deficit);
  border-left: 3px solid var(--deficit);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.headline-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--deficit);
  font-weight: 600;
  margin-bottom: 4px;
}

.devastating-stat-headline {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
  letter-spacing: -0.02em;
}

/* ─── Luck score ─────────────────────────────────────────────── */
.luck-score-container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-start;
  text-align: right;
  padding: 0;
  border: none;
  border-radius: 0;
}

.luck-score-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.luck-score-number {
  font-family: var(--font-mono);
  font-size: 5rem;
  font-weight: 800;
  line-height: 0.9;
  color: var(--highlight);
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.luck-score-desc {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  line-height: 1.35;
  font-family: var(--font-mono);
}

/* ─── Share actions ──────────────────────────────────────────── */
.share-actions-row {
  display: flex;
  gap: 8px;
  margin-top: 0.25rem;
}

.btn-share {
  flex: 1;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-share:hover {
  border-color: var(--cohort-draw);
  color: var(--cohort-draw);
}

.btn-share-alt {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-share-alt:hover {
  border-color: var(--border-strong);
  color: var(--text-muted);
}

/* ─── Globe ──────────────────────────────────────────────────── */
.globe-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.globe-wrapper {
  position: relative;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1;
}

#globe-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.globe-ocean {
  fill: var(--surface);
}

.globe-graticule {
  fill: none;
  stroke: rgba(241, 235, 223, 0.04);
  stroke-width: 0.5px;
  pointer-events: none;
}

.globe-land {
  fill: var(--surface-raised);
  stroke: var(--border-strong);
  stroke-width: 0.5px;
  transition: fill var(--transition-fast), stroke var(--transition-fast);
  cursor: pointer;
}

.globe-land:hover {
  fill: rgba(181, 138, 99, 0.25);
  stroke: var(--cohort-draw);
}

.globe-land.globe-active {
  fill: var(--cohort-draw) !important;
  stroke: var(--cohort-draw) !important;
  stroke-width: 0.8px;
}

.globe-land.globe-active.safe-active {
  fill: var(--parity) !important;
  stroke: var(--parity) !important;
}

.globe-land.globe-active.risk-active {
  fill: var(--deficit) !important;
  stroke: var(--deficit) !important;
}

.globe-microcopy {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.globe-pin {
  fill: var(--cohort-draw);
  stroke: var(--bg);
  stroke-width: 1px;
}

.globe-pin-ring {
  fill: none;
  stroke: var(--cohort-draw);
  stroke-width: 1.5px;
  opacity: 1;
  animation: pulsate 1.8s cubic-bezier(0.215, 0.610, 0.355, 1) infinite;
}

.globe-pin-glow {
  transform-origin: center;
  opacity: 0.9;
  animation: globe-pulsate 1.8s infinite cubic-bezier(0.215, 0.610, 0.355, 1);
}

@keyframes pulsate {
  0% {
    opacity: 1;
    stroke-width: 2.5px;
  }

  100% {
    r: 18px;
    opacity: 0;
    stroke-width: 0.5px;
  }
}

@keyframes globe-pulsate {
  0% {
    r: 4px;
    opacity: 0.9;
  }

  100% {
    r: 18px;
    opacity: 0;
  }
}

/* ─── Dashboard tabs ─────────────────────────────────────────── */
.dashboard-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0;
  margin: 0;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-dim);
  padding: 0.6rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab-btn:hover {
  color: var(--text-muted);
}

.tab-btn.active {
  border-bottom-color: var(--cohort-draw);
  color: var(--cohort-draw);
}

/* ─── Metrics grid & section ─────────────────────────────────── */
#metrics-dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.dashboard-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.dashboard-section.accordion-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
}

.metrics-section-title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0;
  border: none;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 56px;
  row-gap: 22px;
}

/* ─── Metric card — flat ContrastBar design ──────────────────── */
.metric-card {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  cursor: default;
}

.metric-card.card-state-safe .active-bar-row .metric-bar-fill {
  background: var(--parity);
}

.metric-card.card-state-warn .active-bar-row .metric-bar-fill {
  background: var(--mid);
}

.metric-card.card-state-risk .active-bar-row .metric-bar-fill {
  background: var(--deficit);
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.metric-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.metric-source {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-transform: uppercase;
  cursor: help;
  position: relative;
  overflow: visible;
}

.metric-source::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  transform: translateY(4px) scale(0.92);
  background: var(--surface-raised);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.01em;
  text-transform: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-strong);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  z-index: 9999;
  width: max-content;
  max-width: 220px;
  text-align: left;
  white-space: normal;
  line-height: 1.4;
}

.metric-source:hover::after {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Hide the legacy big-number display inside metric cards that use the dual-bar layout */
.metric-card:has(.metric-dual-bars) .metric-value-display {
  display: none;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--cohort-draw);
  letter-spacing: -0.03em;
}

.metric-value-display {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.metric-unit {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.metric-range {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

/* ─── ContrastBar: single overlaid 28px track ────────────────── */
.metric-dual-bars {
  position: relative;
  height: 28px;
  background: var(--surface);
  border-radius: 2px;
  margin-top: 0;
  overflow: hidden;
}

.dual-bar-row {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* Hide flags and inline labels — values move to cb-values row */
.dual-bar-flag,
.dual-bar-val {
  display: none !important;
}

.dual-bar-track {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  background: transparent;
  border-radius: 0;
  overflow: hidden;
}

.metric-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  height: 100%;
  width: 0%;
  border-radius: 0;
  background: var(--cohort-draw);
  transition: width 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Baseline sits behind (z-index 1), clay draw sits in front (z-index 2) */
.compare-bar-row {
  z-index: 1;
}

.active-bar-row {
  z-index: 2;
}

.compare-bar-row .metric-bar-fill,
.compare-bar-fill {
  background: var(--cohort-baseline) !important;
  opacity: 0.85;
}

.active-bar-row .metric-bar-fill {
  background: var(--cohort-draw);
}

/* Deficit hatch — z-index 3, floats above both bars */
.deficit-hatch {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 3;
  pointer-events: none;
  display: none;
  background: repeating-linear-gradient(-45deg,
      rgba(188, 70, 59, 0.55) 0px,
      rgba(188, 70, 59, 0.55) 2px,
      transparent 2px,
      transparent 6px);
  border-top: 1px solid var(--deficit);
  border-bottom: 1px solid var(--deficit);
  transition: left 0.6s, width 0.6s;
}

/* ─── ContrastBar values row ─────────────────────────────────── */
.cb-values {
  display: none;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 6px;
}

.cb-vals-left {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.cb-draw-val {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--cohort-draw);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.card-state-safe .cb-draw-val {
  color: var(--parity);
}

.card-state-warn .cb-draw-val {
  color: var(--mid);
}

.card-state-risk .cb-draw-val {
  color: var(--deficit);
}

.cb-unit {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 2px;
  font-weight: 400;
}

.cb-sep {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

.cb-base-val {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--cohort-baseline);
  font-variant-numeric: tabular-nums;
}

.cb-deficit-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--deficit);
  letter-spacing: 0.02em;
}

.cb-parity-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--parity);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cb-surplus-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--parity);
  letter-spacing: 0.02em;
}

/* ─── Legend row (draw vs baseline key) ─────────────────────── */
.cb-legend {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 14px 0 20px;
}

.cb-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.cb-legend-swatch {
  width: 22px;
  height: 4px;
  border-radius: 1px;
  flex-shrink: 0;
}

.cb-legend-swatch.swatch-draw {
  background: var(--cohort-draw);
}

.cb-legend-swatch.swatch-baseline {
  background: var(--cohort-baseline);
}

.cb-legend-swatch.swatch-deficit {
  background: repeating-linear-gradient(-45deg,
      rgba(188, 70, 59, 0.8) 0px, rgba(188, 70, 59, 0.8) 2px,
      transparent 2px, transparent 5px);
  border-top: 1px solid var(--deficit);
  border-bottom: 1px solid var(--deficit);
  height: 10px;
  margin: -3px 0;
}

/* ─── Single-bar (no compare) ────────────────────────────────── */
.metric-bar-container {
  height: 8px;
  background: var(--surface);
  border-radius: 1px;
  position: relative;
  overflow: hidden;
  margin-top: 8px;
}

/* ─── Safe/risk/warn bar modifiers ──────────────────────────── */
.safe-bar {
  background: var(--parity) !important;
}

.risk-bar {
  background: var(--deficit) !important;
}

/* ─── 1,000-dot survival grid ────────────────────────────────── */
.dot-grid-section {
  border-top: 1px solid var(--border);
  padding-top: 28px;
  margin-top: 24px;
}

.dot-grid-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  gap: 24px;
}

.dot-grid-header-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 60%;
}

.dot-grid-headline {
  font-family: var(--font-sans);
  font-size: 44px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  margin: 0;
}

.dot-grid-desc {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0;
  max-width: 500px;
}

.dot-grid-counters {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}

.dot-counter {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 110px;
}

.dot-counter-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.dot-counter-num {
  font-family: var(--font-mono);
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.dot-counter-total {
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--text-dim);
  font-weight: 500;
}

.dot-grid-scrubber-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 4px;
  margin-bottom: 12px;
}

.dot-grid-age-label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-shrink: 0;
}

.dot-grid-age-num {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 48px;
}

.dot-grid-progress-wrap {
  flex: 1;
  position: relative;
  height: 2px;
  background: var(--border);
}

.dot-grid-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: var(--text-muted);
  transition: width 0.05s linear;
}

.dot-grid-milestone {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 1px;
  background: var(--border-strong);
}

.dot-grid-milestone-label {
  position: absolute;
  top: -16px;
  left: -6px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  white-space: nowrap;
}

.dot-grid-replay-btn {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.dot-grid-replay-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.dot-grid {
  display: grid;
  grid-template-columns: repeat(50, 1fr);
  gap: 3px;
  padding: 8px 0;
}

.dot-item {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--cohort-draw);
  opacity: 0.95;
  box-shadow: 0 0 0 0.5px rgba(181, 138, 99, 0.45);
  transition: background 0.4s ease, box-shadow 0.4s ease, opacity 0.4s ease;
}

.dot-item.dot-dead {
  background: var(--extinguished);
  opacity: 1;
  box-shadow: none;
}

.dot-grid-milestone-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.dot-milestone-item {
  border-left: 2px solid var(--border);
  padding-left: 10px;
  opacity: 0.45;
  transition: opacity 0.4s, border-color 0.4s;
}

.dot-milestone-item.passed {
  opacity: 1;
  border-left-color: var(--cohort-draw);
}

.dot-milestone-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.dot-milestone-age {
  color: var(--text-dim);
}

.dot-milestone-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.4;
}

/* ─── Expand tray ────────────────────────────────────────────── */
.card-details-tray {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--border);
}

.card-details-text {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.45;
  margin: 0;
}

/* ─── Comparison mode ────────────────────────────────────────── */
.comparison-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 768px) {
  .comparison-container {
    grid-template-columns: 1fr 1fr;
  }
}

.comparison-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.comparison-tag-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  gap: 1rem;
}

.comparison-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ─── Aggregate dashboard ────────────────────────────────────── */
.aggregate-dashboard {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  height: fit-content;
}

.aggregate-header-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.25rem;
}

.aggregate-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text);
}

.aggregate-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.stepper-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.stepper-nav-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.45rem 1rem;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.stepper-nav-btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--text);
}

.stepper-nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.stepper-pills {
  display: flex;
  gap: 0.4rem;
  flex-grow: 1;
  overflow-x: auto;
  padding: 2px 0;
  scrollbar-width: none;
}

.stepper-pills::-webkit-scrollbar {
  display: none;
}

.step-pill {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.4rem 0.9rem;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 50px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.step-pill:hover {
  border-color: var(--border-strong);
  color: var(--text-muted);
}

.step-pill.active {
  border-color: var(--cohort-draw);
  color: var(--cohort-draw);
}

/* ─── Narrative banner ───────────────────────────────────────── */
.narrative-banner-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-raised);
  border-left: 3px solid var(--cohort-draw);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 1rem 1.25rem;
  gap: 1.5rem;
}

.narrative-takeaway-text {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-muted);
  flex-grow: 1;
}

.narrative-takeaway-text strong {
  color: var(--text);
  font-weight: 600;
}

.btn-share-step {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.btn-share-step:hover {
  border-color: var(--cohort-draw);
  color: var(--cohort-draw);
}

.btn-share-step .icon {
  font-size: 0.9rem;
}

/* ─── Opportunity sub-toggles ────────────────────────────────── */
.aggregate-workspace {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.opportunity-subtoggles {
  display: flex;
  gap: 4px;
  background: var(--surface-raised);
  padding: 3px;
  border-radius: var(--radius-sm);
  align-self: flex-start;
  border: 1px solid var(--border);
}

.opt-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 0.35rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 2px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.opt-toggle-btn:hover {
  color: var(--text-muted);
}

.opt-toggle-btn.active {
  background: var(--border);
  color: var(--text);
}

/* ─── Chart containers ───────────────────────────────────────── */
.story-chart-container {
  width: 100%;
  min-height: 600px;
  background: var(--surface-raised);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  position: relative;
  overflow: visible;
}

@media (min-width: 768px) {
  .story-chart-container {
    min-height: 680px;
  }
}

@media (min-width: 1200px) {
  .story-chart-container {
    min-height: 740px;
  }
}

.chart-placeholder-message {
  text-align: center;
  padding: 2rem;
  max-width: 380px;
  margin: auto;
  align-self: center;
}

.chart-placeholder-message h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.chart-placeholder-message p {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.chart-container {
  width: 100%;
  height: 220px;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.chart-container svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* ─── Survival dot animation (Step 1) ───────────────────────── */
.survival-canvas {
  width: 100%;
  padding: 28px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 480px;
  background: var(--bg);
  border-radius: var(--radius-md);
}

.survival-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  flex-shrink: 0;
}

.survival-copy {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 55%;
}

.survival-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--text);
}

.survival-desc {
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-muted);
  max-width: 520px;
  margin-top: 4px;
}

.survival-counters {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  flex-shrink: 0;
}

.survival-counter {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 110px;
}

.survival-counter-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  text-align: right;
}

.survival-counter-value {
  font-family: var(--font-mono);
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.survival-scrubber {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding: 0 2px;
}

.survival-age-display {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-shrink: 0;
}

.survival-age-track {
  flex: 1;
  height: 2px;
  background: var(--border);
  position: relative;
}

.survival-age-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: var(--text-dim);
  transition: width 0.05s linear;
}

.survival-age-tick {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 1px;
  background: var(--border-strong);
}

.survival-age-tick-label {
  position: absolute;
  top: -18px;
  left: -6px;
  font-size: 9px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  white-space: nowrap;
}

.survival-replay-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.survival-replay-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.survival-dot-grid {
  display: grid;
  grid-template-columns: repeat(50, 1fr);
  gap: 3px;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  min-height: 380px;
}

@media (max-width: 640px) {
  .survival-dot-grid {
    grid-template-columns: repeat(25, 1fr);
  }
}

.survival-dot {
  aspect-ratio: 1;
  border-radius: 50%;
  transition: background-color 0.4s ease, box-shadow 0.4s ease;
}

.survival-dot.alive {
  background: var(--cohort-draw);
  box-shadow: 0 0 0 0.5px rgba(181, 138, 99, 0.4);
}

.survival-dot.dead {
  background: var(--extinguished);
  box-shadow: none;
}

.survival-milestones {
  display: flex;
  flex-wrap: nowrap;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.survival-milestone {
  flex: 1 1 auto;
  min-width: 130px;
  border-left: 2px solid var(--border);
  padding-left: 10px;
  opacity: 0.4;
  transition: opacity 0.4s ease, border-color 0.4s ease;
}

.survival-milestone.reached {
  border-left-color: var(--cohort-draw);
  opacity: 1;
}

.survival-milestone-label {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.survival-milestone-age {
  color: var(--text-dim);
}

.survival-milestone-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
}

/* ─── D3 chart styling ───────────────────────────────────────── */
.chart-svg-bar {
  cursor: pointer;
  transition: opacity var(--transition-fast);
  opacity: 0.85;
}

.chart-svg-bar:hover {
  opacity: 1 !important;
}

.chart-group text {
  font-family: var(--font-mono);
}

.chart-group text.bar-value {
  fill: var(--text);
  font-weight: 600;
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}

.chart-group text.bar-label {
  fill: var(--text-muted);
}

.chart-group:hover text.bar-value {
  opacity: 1;
}

.donut-label-group text {
  font-family: var(--font-mono);
}

.donut-label-group text:first-child {
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.story-dot {
  cursor: pointer;
  transition: stroke 0.2s, stroke-width 0.2s;
}

.story-dot:hover {
  stroke: var(--text);
  stroke-width: 1.5px;
}

.waffle-dot {
  cursor: pointer;
  transition: opacity 0.2s;
}

.waffle-dot:hover {
  opacity: 1 !important;
  stroke: var(--text);
  stroke-width: 1px;
}

.scatter-dot {
  cursor: pointer;
  transition: opacity 0.2s;
}

.scatter-dot:hover {
  opacity: 1 !important;
  stroke: var(--text);
  stroke-width: 1.5px;
}

.scatter-star {
  cursor: pointer;
}

/* D3 axes */
.domain,
.tick line {
  stroke: rgba(241, 235, 223, 0.1);
}

.tick text {
  fill: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 9px;
}

/* D3 tooltip */
.d3-tooltip {
  position: absolute;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  color: var(--text);
  font-size: 11px;
  pointer-events: none;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  font-family: var(--font-mono);
  max-width: 220px;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.15s;
}

.d3-tooltip-title {
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 0.25rem;
  color: var(--cohort-draw);
}

.d3-tooltip-stat {
  font-weight: 600;
  color: var(--text);
  margin-top: 0.1rem;
}

/* chart ref lines */
.chart-ref-line {
  stroke-dasharray: 4, 4;
  stroke-width: 1.5px;
  opacity: 0.6;
}

.chart-ref-line-comparison {
  stroke: var(--cohort-baseline);
}

.chart-ref-line-poverty {
  stroke: var(--deficit);
}

.chart-ref-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.chart-ref-label-comparison {
  fill: var(--cohort-baseline);
}

.chart-ref-label-poverty {
  fill: var(--deficit);
}

/* ─── Chart loader ───────────────────────────────────────────── */
.chart-loader {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(22, 19, 14, 0.7);
  gap: 1rem;
  z-index: 10;
}

.loader-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(181, 138, 99, 0.2);
  border-top-color: var(--cohort-draw);
  border-radius: 50%;
  animation: spinner-rotate 0.8s infinite linear;
}

@keyframes spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

.loader-text {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ─── CTA panel ──────────────────────────────────────────────── */
.cta-panel {
  border-color: var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cta-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.cta-button {
  background: var(--parity);
  color: var(--bg);
  border: none;
  padding: 0.65rem 1.25rem;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: fit-content;
  margin-top: 0.25rem;
}

.cta-button:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

/* ─── Modals ─────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.modal-body ul {
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.modal-close-btn:hover {
  color: var(--text);
}

/* ─── Data gap items ─────────────────────────────────────────── */
.gap-item {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.gap-label {
  font-weight: 500;
  color: var(--text-muted);
}

.gap-status {
  color: var(--deficit);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}

/* ─── Footer ─────────────────────────────────────────────────── */
footer {
  grid-column: 1 / -1;
  text-align: center;
  padding: 1.5rem 0;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
}

.footer-links a {
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 1px dashed rgba(128, 119, 105, 0.4);
  transition: color var(--transition-fast);
}

.footer-links a:hover {
  color: var(--text-muted);
}

/* ─── Accordion ──────────────────────────────────────────────── */
.accordion-header {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 10px;
}

.accordion-header .accordion-trigger {
  flex: 1;
  min-width: 0;
}

.accordion-trigger {
  width: 100%;
  background: none;
  border: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  cursor: pointer;
  padding: 4px 0;
  color: var(--text);
  outline: none;
}

.accordion-icon {
  font-size: 10px;
  color: var(--text-dim);
  transition: transform 0.25s ease-out;
  padding: 0 10px;
  flex-shrink: 0;
}

.accordion-section[data-collapsed="true"] .accordion-icon {
  transform: rotate(-90deg);
}

.accordion-section[data-collapsed="true"] .accordion-content {
  display: none !important;
}

/* ─── Section expand button ──────────────────────────────────── */
.section-expand-btn {
  margin-left: 0;
  margin-right: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text-dim);
  font-size: 9px;
  width: 15px;
  height: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
  line-height: 1;
  padding: 0;
}

.accordion-header:hover .section-expand-btn,
.section-expand-btn:focus {
  opacity: 1;
}

.section-expand-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* ─── Section fullscreen overlay ────────────────────────────── */
.section-fullscreen-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.section-fullscreen-overlay.hidden {
  display: none;
}

.section-fullscreen-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(22, 19, 14, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.section-fullscreen-panel {
  position: relative;
  z-index: 1;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  width: min(900px, 94vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.section-fullscreen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.section-fullscreen-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}

.section-fullscreen-close:hover {
  color: var(--text);
  background: var(--surface-raised);
}

.section-fullscreen-body {
  overflow-y: auto;
  padding: 28px;
  flex: 1;
}

.section-fullscreen-body .metrics-grid {
  grid-template-columns: 1fr 1fr;
  gap: 32px 56px;
}

.section-fullscreen-body .metric-card {
  padding: 0;
  background: transparent;
  border: none;
}

.section-fullscreen-body .cb-values {
  display: flex !important;
}

/* ─── Pulse animation ────────────────────────────────────────── */
@keyframes personaPulse {
  0% {
    transform: scale(0.98);
    opacity: 0.75;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.pulse-highlight {
  animation: personaPulse 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Info icon hint ─────────────────────────────────────────── */
.info-icon-hint {
  position: relative;
  cursor: help;
  font-size: 0.75rem;
  margin-left: 4px;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
}

.info-icon-hint::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translate(-50%, 6px) scale(0.9);
  background: var(--surface-raised);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 400;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-strong);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  z-index: 1000;
  width: 250px;
  text-align: center;
  white-space: normal;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: 0;
}

.info-icon-hint:hover::after {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.draw-explanation-hint {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
  margin-top: 0.25rem;
  border-left: 2px solid var(--border);
  padding-left: 8px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.draw-explanation-hint strong {
  color: var(--text-muted);
  font-weight: 600;
}

/* ─── Flag images ────────────────────────────────────────────── */
.flag-img {
  width: 38px;
  height: 26px;
  object-fit: cover;
  border-radius: 2px;
  border: 1px solid var(--border-strong);
  display: inline-block;
  vertical-align: middle;
}

.flag-title-row .flag-img {
  width: 48px;
  height: 32px;
}

/* ─── Utility ────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

.nav-locked {
  opacity: 0.4;
  cursor: not-allowed !important;
  pointer-events: none !important;
}

/* ─── RTL ────────────────────────────────────────────────────── */
[dir="rtl"] {
  text-align: right;
}

[dir="rtl"] .metric-card {
  border-left: none !important;
  border-right: 3px solid var(--cohort-draw) !important;
}

[dir="rtl"] .metric-card.card-state-safe {
  border-right: 3px solid var(--parity) !important;
}

[dir="rtl"] .metric-card.card-state-warn {
  border-right: 3px solid var(--mid) !important;
}

[dir="rtl"] .metric-card.card-state-risk {
  border-right: 3px solid var(--deficit) !important;
}

/* ─── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .globe-container {
    display: none !important;
  }

  .draw-card {
    grid-template-columns: 1fr !important;
    gap: 1rem;
    padding: 1rem;
  }

  .draw-result-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
  }

  .draw-result-header-left {
    max-width: 100%;
  }

  .draw-result-header-right {
    align-items: stretch;
    width: 100%;
  }

  .country-name {
    font-size: 2.2rem;
  }

  .country-flag {
    font-size: 2.2rem;
  }

  .luck-score-container.hero-luck-score {
    align-items: center;
    text-align: center;
    margin-top: 0;
    padding: 1rem 0 0;
    border-top: 1px solid var(--border);
  }

  .luck-score-number {
    font-size: 2.75rem;
  }

  .share-actions-row {
    flex-wrap: wrap;
    width: 100%;
    gap: 8px;
    margin-top: 0.5rem;
  }

  .btn-share, .btn-share-alt {
    flex: 1 1 140px;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
    column-gap: 0;
    row-gap: 1.25rem;
  }

  .section-fullscreen-body .metrics-grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  .dot-grid-headline {
    font-size: 1.8rem;
  }

  .dot-grid-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .dot-grid-header-left {
    max-width: 100%;
  }

  .dot-grid-counters {
    justify-content: flex-start;
    gap: 1.5rem;
  }

  .dot-grid {
    grid-template-columns: repeat(25, 1fr);
  }

  .dot-grid-milestone-strip {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .survival-top {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .survival-copy {
    max-width: 100%;
  }

  .survival-counters {
    justify-content: flex-start;
    gap: 1.5rem;
  }

  .survival-dot-grid {
    grid-template-columns: repeat(25, 1fr);
  }

  .sidebar {
    position: static !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
    width: 100% !important;
    background: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 0 1.25rem 0 !important;
  }

  .sidebar .spinner-panel {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    text-align: center !important;
    gap: 1rem !important;
    width: 100% !important;
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    padding: 1.25rem !important;
    border-radius: var(--radius-md) !important;
  }

  .sidebar .spinner-wheel-container,
  .sidebar .secondary-actions,
  .sidebar .filters-panel,
  .sidebar #disability-toggle-container,
  .sidebar .spin-btn-secondary {
    display: flex !important;
  }

  .sidebar .filters-panel,
  .sidebar #disability-toggle-container {
    flex-direction: column !important;
  }

  #spin-btn {
    position: fixed !important;
    bottom: 12px !important;
    left: 12px !important;
    right: 12px !important;
    width: calc(100% - 24px) !important;
    z-index: 1000 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6) !important;
    height: 48px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin: 0 !important;
  }

  .accordion-trigger {
    padding: 8px 0;
  }

  .accordion-content {
    margin-top: 8px;
  }

  main {
    margin-bottom: 80px !important;
  }

  .stepper-controls {
    flex-direction: row;
    width: 100%;
  }

  .stepper-pills {
    order: -1;
    width: 100%;
    margin-bottom: 0.5rem;
  }

  .stepper-nav-btn {
    flex-grow: 1;
    text-align: center;
  }

  .narrative-banner-container {
    flex-direction: column;
    align-items: stretch;
    padding: 0.85rem;
    gap: 0.65rem;
  }

  .btn-share-step {
    justify-content: center;
    width: 100%;
  }

  .opportunity-subtoggles {
    width: 100%;
    overflow-x: auto;
  }

  .opt-toggle-btn {
    flex-grow: 1;
    text-align: center;
    white-space: nowrap;
  }

  /* 1,000 Spins Mobile Responsiveness overrides */
  .aggregate-dashboard {
    padding: 0.75rem !important;
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: hidden !important;
    min-width: 0 !important;
  }

  .aggregate-dashboard > * {
    max-width: 100%;
    min-width: 0;
  }

  .aggregate-header-nav,
  .aggregate-workspace {
    min-width: 0;
    max-width: 100%;
  }

  .story-chart-container {
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
  }

  .narrative-takeaway-text {
    word-wrap: break-word;
    overflow-wrap: anywhere;
    min-width: 0;
  }

  .dashboard-tabs {
    overflow-x: auto;
    scrollbar-width: none;
    max-width: 100%;
  }

  .dashboard-tabs::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }

  .survival-canvas {
    padding: 16px 12px 12px !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  .survival-canvas > * {
    min-width: 0;
    max-width: 100%;
  }

  .survival-copy,
  .survival-title,
  .survival-desc {
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-width: 0;
  }

  .survival-dot-grid {
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .survival-scrubber {
    display: grid !important;
    grid-template-areas:
      "age . replay"
      "track track track" !important;
    gap: 16px 12px !important;
    align-items: center !important;
  }

  .survival-age-display {
    grid-area: age !important;
  }

  .survival-replay-btn {
    grid-area: replay !important;
    justify-self: end;
  }

  .survival-age-track {
    grid-area: track !important;
    margin-top: 16px !important;
    width: 100% !important;
  }

  .survival-milestones {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .survival-milestones::-webkit-scrollbar {
    display: none;
  }

  .survival-counters,
  .dot-grid-counters {
    flex-wrap: wrap !important;
  }

  .survival-counter,
  .dot-counter {
    align-items: flex-start !important;
  }

  .survival-counter .survival-counter-label,
  .dot-counter .dot-counter-label {
    text-align: left !important;
  }
}

/* ─── Increased tap targets ──────────────────────────────────── */
select,
input[type="checkbox"],
button,
.tab-btn {
  min-height: 36px;
}

/* ─── Persona sentence styles ────────────────────────────────── */
.persona-sentence {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0.25rem 0 0.75rem 0;
  font-style: italic;
}

/* ─── Comparison line (D3) ───────────────────────────────────── */
.comparison-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--cohort-baseline);
  z-index: 2;
}

.comparison-label {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  letter-spacing: 0.04em;
}