/* ============================================================
 * MCB Census Compendium — Hero, Sections, Modal
 * Layered on top of styles.css. Loads after.
 * Design language: editorial/architectural with MCB brand red.
 * ============================================================ */

/* === Body / nav adjustments === */
body { background: var(--page-bg); color: var(--page-fg); transition: background 200ms ease, color 200ms ease; }

.nav {
  background: rgba(13, 14, 16, 0.85);
  border-bottom: 1px solid var(--ink-line);
  padding: 0.85rem 1.75rem;
}
.nav-brand { gap: 0.85rem; }
.nav-brand span {
  font-family: var(--font-display);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.95rem;
  color: var(--bone);
}
.nav-logo { height: 36px; width: auto; filter: brightness(1.1); }
.nav-links a {
  color: var(--bone-soft);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  font-weight: 600;
  transition: color 180ms ease;
  position: relative;
}
.nav-links a:hover { color: var(--bone); }
.nav-links a::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -6px;
  height: 2px;
  background: var(--mcb-red);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 220ms ease;
}
.nav-links a:hover::after { transform: scaleX(1); }

.progress-bar { background: var(--mcb-red); height: 2px; }

/* === Hero — Compendium === */
.hero {
  position: relative;
  min-height: 100svh;
  display: grid;
  align-items: center;
  background: var(--ink);
  color: var(--bone);
  isolation: isolate;
  overflow: hidden;
  padding: 8rem 0 6rem;
}

.hero-photo {
  position: absolute;
  inset: 0;
  z-index: -2;
}
.hero-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 60%;
  filter: saturate(0.7) brightness(0.55);
  transform: scale(1.05);
  animation: hero-pan 22s ease-out forwards;
}
@keyframes hero-pan {
  to { transform: scale(1) translateY(-1.5%); }
}
.hero-photo-overlay {
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgba(13,14,16,0.55) 0%, rgba(13,14,16,0.65) 40%, var(--ink) 100%),
    linear-gradient(90deg, rgba(13,14,16,0.7) 0%, rgba(13,14,16,0.2) 40%, rgba(13,14,16,0) 60%, rgba(13,14,16,0.4) 100%);
}

.hero-pattern {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  color: var(--bone);
  opacity: 0.18;
  pointer-events: none;
  mix-blend-mode: overlay;
}

.hero-rail {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 64px;
  background: var(--mcb-red);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.hero-rail::before {
  content: '';
  position: absolute;
  inset: 18px 14px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 60'><path d='M30 4 L36 24 L56 24 L40 36 L46 56 L30 44 L14 56 L20 36 L4 24 L24 24 Z' fill='none' stroke='%23ffffff' stroke-width='0.6' opacity='0.22'/></svg>");
  background-size: 60px 60px;
  background-repeat: repeat-y;
  background-position: center top;
  pointer-events: none;
}
.hero-rail-text {
  font-family: var(--font-display);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.42em;
  color: rgba(255,255,255,0.85);
  font-size: 0.72rem;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
}

.hero-content {
  max-width: 1120px;
  width: min(90%, 1120px);
  margin: 0 auto;
  padding-right: 64px; /* account for red rail */
  position: relative;
  z-index: 2;
  animation: hero-rise 900ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes hero-rise {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: none; }
}

.hero-eyebrow {
  display: inline-block;
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.32em;
  color: var(--bone-soft);
  font-size: 0.78rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--mcb-red);
  margin-bottom: 1.6rem;
  animation: hero-fade 1.1s 100ms ease both;
}

.hero-title {
  font-family: var(--font-display);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -0.005em;
  line-height: 0.92;
  margin: 0;
  font-size: clamp(3.2rem, 9vw, 7.5rem);
  color: var(--bone);
  animation: hero-fade 1.1s 200ms ease both;
}
.hero-title span { display: block; }
.hero-title-accent {
  color: var(--mcb-red);
  font-style: italic;
  font-weight: 800;
}

.hero-rule {
  width: 96px;
  height: 4px;
  background: var(--mcb-red);
  margin: 1.8rem 0 1.4rem;
  animation: hero-rule 900ms 500ms ease-out both;
}
@keyframes hero-rule {
  from { width: 0; }
  to   { width: 96px; }
}

.hero-deck {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: clamp(0.85rem, 1.1vw, 1rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  line-height: 1.7;
  max-width: 36ch;
  color: var(--bone-soft);
  margin-bottom: 3rem;
  animation: hero-fade 1.1s 350ms ease both;
}

@keyframes hero-fade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* === Hero stats — chunky compendium-style === */
.hero .hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin-bottom: 3rem;
  border-top: 1px solid var(--ink-line);
  border-bottom: 1px solid var(--ink-line);
  /* No container animation — each card animates individually (see below) */
}
@keyframes hero-card-rise {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: none; }
}
.hero .stat-card:nth-child(1) {
  animation: hero-card-rise 700ms 620ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.hero .stat-card:nth-child(2) {
  animation: hero-card-rise 700ms 820ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.hero .stat-card:nth-child(3) {
  animation: hero-card-rise 700ms 1020ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.hero .stat-card {
  background: transparent;
  border: none;
  border-right: 1px solid var(--ink-line);
  padding: 1.6rem 1.4rem;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  transition: background 180ms ease;
  will-change: opacity, transform;
}
.hero .stat-card:last-child { border-right: none; }
.hero .stat-card:hover { background: rgba(200,38,46,0.06); }
.hero .stat-card .stat-icon { display: none; }
.hero .stat-card .stat-number {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(2.4rem, 5vw, 3.8rem);
  letter-spacing: -0.01em;
  background: none;
  -webkit-background-clip: initial;
  background-clip: initial;
  -webkit-text-fill-color: initial;
  color: var(--bone);
  font-feature-settings: "tnum" 1;
  line-height: 0.9;
}
.hero .stat-card .stat-label {
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--bone-soft);
  font-size: 0.78rem;
}

/* === Hero CTAs === */
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  animation: hero-fade 1.1s 600ms ease both;
}

.btn-primary {
  background: var(--mcb-red);
  color: white;
  border: none;
  padding: 0.95rem 1.6rem 0.85rem;
  font-family: var(--font-display);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.92rem;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  transition: background 160ms ease, transform 160ms ease;
  position: relative;
  overflow: hidden;
}
.btn-primary:hover { background: var(--mcb-red-deep); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary .btn-label { font-size: 1rem; line-height: 1; }
.btn-primary .btn-meta {
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  font-weight: 600;
  opacity: 0.78;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.85rem;
  color: var(--bone);
  text-decoration: none;
  border-bottom: 1px solid var(--bone-mute);
  padding: 0.5rem 0;
  transition: color 160ms ease, border-color 160ms ease;
}
.btn-ghost:hover { color: var(--mcb-red); border-bottom-color: var(--mcb-red); }
.btn-ghost svg { transition: transform 200ms ease; }
.btn-ghost:hover svg { transform: translateY(2px); }

@media (max-width: 768px) {
  .hero { padding: 6rem 0 4rem; }
  .hero-rail { width: 36px; }
  .hero-rail-text { font-size: 0.6rem; letter-spacing: 0.32em; }
  .hero-content { padding-right: 36px; }
  .hero-title { font-size: clamp(2.6rem, 14vw, 4.2rem); }
  .hero .hero-stats { grid-template-columns: 1fr; }
  .hero .stat-card { border-right: none; border-bottom: 1px solid var(--ink-line); }
  .hero .stat-card:last-child { border-bottom: none; }
}

/* === Section divider blocks (matching report Part II / III) === */
.report-divider {
  background: var(--deep-teal);
  color: var(--bone);
  padding: 5rem 1.5rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.report-divider.maroon { background: var(--maroon); }

.report-divider::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 80'><path d='M40 4 L48 32 L76 32 L52 48 L60 76 L40 60 L20 76 L28 48 L4 32 L32 32 Z' fill='none' stroke='%23ffffff' stroke-width='0.7' opacity='0.10'/></svg>");
  background-size: 80px 80px;
  pointer-events: none;
}

.report-divider-eyebrow {
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.32em;
  font-size: 0.78rem;
  opacity: 0.78;
  margin-bottom: 1rem;
  color: var(--bone-soft);
}
.report-divider-title {
  font-family: var(--font-display);
  font-weight: 900;
  text-transform: uppercase;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 0.95;
  letter-spacing: -0.005em;
}
.report-divider-rule {
  width: 64px;
  height: 3px;
  background: var(--mcb-red);
  margin: 1.4rem auto 0;
}

/* === Download / Notify section === */
.report-cta-section {
  background: var(--surface-feature-bg);
  color: var(--surface-feature-fg);
  padding: 6rem 1.5rem;
  position: relative;
  overflow: hidden;
  transition: background 200ms ease, color 200ms ease;
}
.report-cta-section::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 80'><path d='M40 4 L48 32 L76 32 L52 48 L60 76 L40 60 L20 76 L28 48 L4 32 L32 32 Z' fill='none' stroke='%23ffffff' stroke-width='0.7' opacity='0.06'/></svg>");
  background-size: 80px 80px;
  pointer-events: none;
}

.report-cta-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  gap: 3rem;
  grid-template-columns: 1fr 1fr;
  position: relative;
}
@media (max-width: 880px) { .report-cta-inner { grid-template-columns: 1fr; } }

.report-cta-copy h2 {
  font-family: var(--font-display);
  font-weight: 900;
  text-transform: uppercase;
  font-size: clamp(2rem, 4.5vw, 3rem);
  line-height: 0.96;
  margin-bottom: 1rem;
  color: var(--surface-feature-fg);
}
.report-cta-copy h2 em {
  color: var(--mcb-red);
  font-style: italic;
}
.report-cta-copy p {
  color: var(--surface-feature-fg-soft);
  max-width: 50ch;
  margin-bottom: 1.6rem;
  line-height: 1.7;
}
.report-cta-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--gold);
}
.report-cta-meta::before {
  content: '';
  width: 8px; height: 8px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(201,160,74,0.18);
}

.report-volumes { display: grid; gap: 1.25rem; }

.report-volume-card {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 1.4rem;
  align-items: center;
  background: var(--surface-feature-bg-soft);
  border: 1px solid var(--surface-feature-line);
  padding: 1.25rem;
  transition: border-color 200ms ease, transform 200ms ease, background 200ms ease;
}
.report-volume-card:hover {
  border-color: var(--mcb-red);
  transform: translateX(2px);
}
.report-volume-card img {
  width: 96px;
  height: 136px;
  object-fit: cover;
  display: block;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
.report-volume-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.report-volume-meta .vol-label {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-size: 0.7rem;
  color: var(--mcb-red);
  font-weight: 700;
}
.report-volume-meta .vol-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  line-height: 1.05;
  color: var(--surface-feature-fg);
}
.report-volume-meta .vol-meta {
  font-size: 0.78rem;
  color: var(--surface-feature-fg-soft);
  letter-spacing: 0.05em;
}
.report-volume-card button,
.report-volume-card .report-volume-cta {
  background: transparent;
  border: 1px solid var(--surface-feature-cta-bd);
  color: var(--surface-feature-fg);
  padding: 0.7rem 1rem 0.6rem;
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 180ms ease;
  white-space: nowrap;
  text-decoration: none;
  display: inline-block;
}
.report-volume-card button:hover,
.report-volume-card .report-volume-cta:hover {
  background: var(--mcb-red);
  border-color: var(--mcb-red);
  color: #ffffff;
}


/* === Light-background colour reset ====================================
 * body { color: var(--bone) } is correct for the dark hero/cta surfaces,
 * but white-bg step cards and the light-bg explorer must restore dark text.
 * ===================================================================== */
.step-card { color: var(--ink); }
.explorer  { color: var(--ink); }

/* === iOS Safari compositing — promote animated elements to their own layer
 * so overflow:hidden on .hero doesn't break opacity/transform animations. */
.hero-photo img,
.hero-content,
.hero-eyebrow,
.hero-title,
.hero-deck,
.hero .hero-stats,
.hero-actions {
  will-change: opacity, transform;
}

/* === Reduce motion === */
@media (prefers-reduced-motion: reduce) {
  .hero-photo img { animation: none; transform: none; will-change: auto; }
  .hero-content,
  .hero-eyebrow,
  .hero-title,
  .hero-deck,
  .hero .hero-stats,
  /* animation-fill-mode:both means opacity:0 is held until animation plays —
   * must explicitly reset to visible when animations are disabled. */
  .hero-actions { animation: none; opacity: 1; transform: none; will-change: auto; }
  .hero-rule { width: 96px; animation: none; }
  /* Per-card stagger animations */
  .hero .stat-card:nth-child(1),
  .hero .stat-card:nth-child(2),
  .hero .stat-card:nth-child(3) { animation: none; opacity: 1; transform: none; will-change: auto; }
}

/* === Embed mode — hide nav + footer + progress bar when iframed or ?embed=1
 * Toggled by the inline script in index.html setting <html data-embed>. */
html[data-embed] .nav,
html[data-embed] .progress-bar,
html[data-embed] footer { display: none !important; }
html[data-embed] .hero { padding-top: 3rem; }

/* === Sponsor sticky logo (AGHOSH UK) ==================================
 * Hidden by default. Shown only in embed mode (where the MCB nav is gone),
 * floating top-left as a small "Supported by" card. */
.aghosh-sticky { display: none; }
html[data-embed] .aghosh-sticky {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 100;
  padding: 6px 10px 4px;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  text-decoration: none;
  transition: transform 200ms ease, box-shadow 200ms ease;
}
html[data-embed] .aghosh-sticky:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
}
html[data-embed] .aghosh-sticky .aghosh-caption {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.55rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 3px;
}
html[data-embed] .aghosh-sticky img {
  display: block;
  height: 56px;
  width: auto;
}
@media (max-width: 600px) {
  html[data-embed] .aghosh-sticky { top: 10px; left: 10px; padding: 4px 8px 3px; }
  html[data-embed] .aghosh-sticky img { height: 42px; }
  html[data-embed] .aghosh-sticky .aghosh-caption { font-size: 0.5rem; }
}

/* === Light theme overrides ============================================
 * Pure white everywhere. Every dark section (hero, deep-dive panels,
 * report CTA, footer) flips to white with dark text. The hero photo
 * and the deep-dive gradient are hidden — brand identity comes from
 * typography + the MCB red rail. */
html[data-theme="light"] {
  --page-bg:           #ffffff;
  --page-fg:           #1c1d22;
  --page-fg-soft:      #4a4e57;
  --surface-feature-bg:      #ffffff;
  --surface-feature-bg-soft: #f7f6f3;   /* subtle warm tint on volume cards */
  --surface-feature-fg:      var(--ink);
  --surface-feature-fg-soft: #4a4e57;
  --surface-feature-line:    #e8e6e1;
  --surface-feature-cta-bd:  rgba(13,14,16,0.32);
}

/* Hero — drop the photo + dark overlay in light mode, restyle text dark. */
html[data-theme="light"] .hero { background: var(--page-bg); color: var(--page-fg); }
html[data-theme="light"] .hero-photo,
html[data-theme="light"] .hero-photo-overlay,
html[data-theme="light"] .hero-pattern { display: none; }
html[data-theme="light"] .hero-eyebrow,
html[data-theme="light"] .hero-deck { color: #4a4e57; }
html[data-theme="light"] .hero-title { color: var(--ink); }
html[data-theme="light"] .hero .hero-stats {
  border-top-color: rgba(13, 14, 16, 0.12);
  border-bottom-color: rgba(13, 14, 16, 0.12);
}
html[data-theme="light"] .hero .stat-card { border-right-color: rgba(13, 14, 16, 0.12); }
html[data-theme="light"] .hero .stat-card .stat-number { color: var(--ink); }
html[data-theme="light"] .hero .stat-card .stat-label { color: #4a4e57; }
html[data-theme="light"] .hero .stat-card:hover { background: rgba(200, 38, 46, 0.08); }
/* Hero CTA buttons */
html[data-theme="light"] .btn-ghost { color: var(--ink); border-color: rgba(13, 14, 16, 0.4); }
html[data-theme="light"] .btn-ghost:hover { background: rgba(13, 14, 16, 0.06); }
/* Nav (standalone view, embed has it hidden anyway) */
html[data-theme="light"] .nav {
  background: rgba(255, 255, 255, 0.94);
  border-bottom-color: rgba(13, 14, 16, 0.08);
}
html[data-theme="light"] .nav-brand span,
html[data-theme="light"] .nav-links a { color: var(--ink); }
html[data-theme="light"] .nav-links a:hover { color: var(--mcb-red); }
html[data-theme="light"] .nav-logo { filter: brightness(0.4); }
/* Footer (standalone view) */
html[data-theme="light"] footer { background: var(--page-bg); color: var(--page-fg); border-top: 1px solid rgba(13, 14, 16, 0.08); }
html[data-theme="light"] .footer-bottom p { color: rgba(13, 14, 16, 0.62); }
html[data-theme="light"] .footer-brand p { color: rgba(13, 14, 16, 0.72); }
html[data-theme="light"] .footer-links a { color: var(--ink); }

/* Deep-dive section (gradient panel with prison stats, LAD comparison,
 * gap analysis, etc.) — flip to white with dark text. */
html[data-theme="light"] .deep-dive {
  background: var(--page-bg);
  color: var(--page-fg);
}
html[data-theme="light"] .deep-dive .section-header h2 { color: var(--ink); }
html[data-theme="light"] .deep-dive .section-header p { color: var(--page-fg-soft); }
html[data-theme="light"] .deep-dive-card {
  background: #ffffff;
  border-color: rgba(13, 14, 16, 0.1);
  box-shadow: 0 1px 3px rgba(13, 14, 16, 0.06);
}
html[data-theme="light"] .deep-dive-card.alert-card {
  background: rgba(239, 68, 68, 0.04);
  border-color: rgba(239, 68, 68, 0.25);
}
html[data-theme="light"] .card-header h3 { color: var(--ink); }
html[data-theme="light"] .card-content { color: var(--page-fg); }
html[data-theme="light"] .card-insight {
  background: rgba(15, 61, 68, 0.06);
  border-left-color: var(--deep-teal);
  color: var(--ink);
}
html[data-theme="light"] .card-insight p,
html[data-theme="light"] .card-insight strong { color: var(--ink); }
html[data-theme="light"] .insight-highlight .big-number { color: var(--deep-teal); }
html[data-theme="light"] .insight-highlight .insight-label { color: var(--page-fg); }

/* Gap analysis panel (Persisting Inequalities — maroon-themed) */
html[data-theme="light"] .gap-grid { background: transparent; }
html[data-theme="light"] .gap-item {
  background: #ffffff;
  border-color: rgba(13, 14, 16, 0.1);
}
html[data-theme="light"] .gap-item-title { color: var(--ink); }
html[data-theme="light"] .gap-bar-label,
html[data-theme="light"] .gap-bar-value { color: var(--page-fg); }
html[data-theme="light"] .gap-badge.negative {
  background: rgba(239, 68, 68, 0.12);
  color: #991b1b;
}
html[data-theme="light"] .gap-badge.neutral {
  background: rgba(202, 138, 4, 0.14);
  color: #854d0e;
}

/* Prison overrepresentation panel */
html[data-theme="light"] .prison-viz { background: transparent; }
html[data-theme="light"] .prison-stat,
html[data-theme="light"] .prison-comparison { color: var(--page-fg); }
html[data-theme="light"] .prison-bar { background: rgba(13, 14, 16, 0.06); }
html[data-theme="light"] .prison-bar .bar-label { color: var(--ink); font-weight: 700; }
html[data-theme="light"] .prison-stat .stat-desc,
html[data-theme="light"] .prison-details .detail-label,
html[data-theme="light"] .prison-note { color: var(--page-fg); }

/* LAD comparison panel */
html[data-theme="light"] .lad-selectors,
html[data-theme="light"] .lad-select { color: var(--ink); }
html[data-theme="light"] .lad-select {
  background: #ffffff;
  border: 1px solid rgba(13, 14, 16, 0.16);
}
html[data-theme="light"] #lad-comparison-grid .placeholder-text { color: rgba(13, 14, 16, 0.6); }
html[data-theme="light"] .vs-badge { color: var(--mcb-red); }
/* LAD comparison cards (injected on dropdown change). Originally
 * bg: rgba(255,255,255,0.05) + white text — invisible on the white
 * page. Flip to a visible card with dark text. */
html[data-theme="light"] .lad-card {
  background: #f7f6f3;
  border: 1px solid rgba(13, 14, 16, 0.1);
  color: var(--ink);
}
html[data-theme="light"] .lad-card h4 { color: var(--mcb-red); }
html[data-theme="light"] .lad-card .lad-metric-label { color: var(--page-fg-soft); }
html[data-theme="light"] .lad-card .lad-metric-value { color: var(--ink); }

/* Compare cards (median age etc.) */
html[data-theme="light"] .compare-item { background: #f7f6f3; border-color: rgba(13, 14, 16, 0.08); }
html[data-theme="light"] .compare-item .compare-label { color: #334155; }

/* Explorer insights box */
html[data-theme="light"] #explorer-insights {
  background: #ffffff;
  border-color: rgba(13, 14, 16, 0.1);
}
html[data-theme="light"] #explorer-insights h4,
html[data-theme="light"] #insight-text { color: var(--ink); }

/* Section dividers — those dark "Part II / Part III" header blocks */
html[data-theme="light"] .section-divider,
html[data-theme="light"] .section-divider-block {
  background: var(--page-bg);
  color: var(--page-fg);
  border-top: 1px solid rgba(13, 14, 16, 0.08);
  border-bottom: 1px solid rgba(13, 14, 16, 0.08);
}

/* Scrollytelling section — was background: var(--dark) in styles.css.
 * Flip to white and recolor every white-text label inside the sticky viz. */
html[data-theme="light"] .scrolly { background: var(--page-bg); color: var(--page-fg); }
html[data-theme="light"] .viz-title { color: var(--ink); }
html[data-theme="light"] .viz-legend { color: var(--page-fg-soft); }
html[data-theme="light"] .viz-header,
html[data-theme="light"] .viz-wrapper { background: transparent; }
/* viz-container was --dark-soft — flip to white card with hairline border */
html[data-theme="light"] .viz-container {
  background: #ffffff;
  border-color: rgba(13, 14, 16, 0.08);
}
html[data-theme="light"] .viz-header { border-bottom-color: rgba(13, 14, 16, 0.08); }
/* D3 axis text + grid — were rgba(255,...) for the dark canvas.
 *
 *   Why !important here (it's a smell, but justified):
 *   ---------------------------------------------------
 *   The D3 chart code in app.js sets fills via inline SVG attributes,
 *   e.g. `.attr('fill', 'rgba(255,255,255,0.7)')`. Inline presentation
 *   attributes beat CSS without !important. Selector specificity alone
 *   cannot override them.
 *
 *   Scope is intentionally narrow (.chart-container/.viz-container text +
 *   tspan only) so this can't bleed into unrelated SVGs. Re-evaluate this
 *   rule if/when app.js ever sets fills via CSS classes instead of inline
 *   attrs — at that point these !importants become dead weight. */
html[data-theme="light"] .axis text,
html[data-theme="light"] .grid text,
html[data-theme="light"] .chart-container text,
html[data-theme="light"] .chart-container tspan,
html[data-theme="light"] .viz-container text,
html[data-theme="light"] .viz-container tspan,
html[data-theme="light"] svg text { fill: rgba(13, 14, 16, 0.85) !important; }
html[data-theme="light"] .axis path,
html[data-theme="light"] .axis line,
html[data-theme="light"] .grid line,
html[data-theme="light"] .chart-container .domain,
html[data-theme="light"] .viz-container .domain { stroke: rgba(13, 14, 16, 0.2) !important; }
/* Step indicators (right-edge dots) — dark dots on white */
html[data-theme="light"] .step-dot { background: rgba(13, 14, 16, 0.25); }
html[data-theme="light"] .step-dot.active { background: var(--mcb-red); }
html[data-theme="light"] .step-dot:hover { background: rgba(13, 14, 16, 0.5); }

/* Explore-the-data section — has its own viz canvas */
html[data-theme="light"] .explorer { background: var(--page-bg); color: var(--page-fg); }
html[data-theme="light"] .explorer-insights {
  background: #f7f6f3;
  color: var(--ink);
  border: 1px solid rgba(13, 14, 16, 0.08);
}
html[data-theme="light"] .explorer-insights h4,
html[data-theme="light"] .explorer-insights p { color: var(--ink); }
html[data-theme="light"] .tab-btn { color: var(--ink); border-color: rgba(13, 14, 16, 0.2); }
html[data-theme="light"] .tab-btn.active { background: var(--mcb-red); border-color: var(--mcb-red); color: #ffffff; }

/* Download CSV section — was dark with white text */
html[data-theme="light"] .download-section { background: var(--page-bg); color: var(--page-fg); }
html[data-theme="light"] .download-section h2 { color: var(--ink); }
html[data-theme="light"] .download-section p { color: var(--page-fg-soft); }
html[data-theme="light"] .download-card {
  background: #f7f6f3;
  border: 1px solid rgba(13, 14, 16, 0.1);
  color: var(--ink);
}
html[data-theme="light"] .download-card:hover {
  background: #ffffff;
  border-color: rgba(13, 14, 16, 0.3);
}
html[data-theme="light"] .download-card .dl-name { color: var(--ink); }
html[data-theme="light"] .download-card .dl-size { color: var(--page-fg-soft); }

/* === Theme toggle button — fixed top-right, both modes ================
 * Mirrors the AGHOSH sticky logo on the opposite corner. */
.theme-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 1001;            /* must beat .nav (z=999) on the standalone view */
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(13, 14, 16, 0.08);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  transition: transform 180ms ease, box-shadow 180ms ease, background 200ms ease;
  color: var(--ink);
  padding: 0;
}
.theme-toggle:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); }
.theme-toggle svg { width: 18px; height: 18px; display: block; }
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
html[data-theme="light"] .theme-toggle .icon-sun  { display: block; }
html[data-theme="light"] .theme-toggle .icon-moon { display: none; }
html[data-theme="light"] .theme-toggle {
  background: rgba(13, 14, 16, 0.92);
  border-color: rgba(13, 14, 16, 0.6);
  color: var(--bone);
}

/* When embedded next to the AGHOSH logo at top-left, just keep the right side
 * unobstructed — no special tweak needed for the toggle itself. */
@media (max-width: 600px) {
  .theme-toggle { top: 10px; right: 10px; width: 34px; height: 34px; }
  .theme-toggle svg { width: 16px; height: 16px; }
}

/* === AA-contrast fixes uncovered by scripts/test-readability.js =========
 * Each rule cites the failing pair it resolves. */

/* 1. Deep-dive section keeps cream text in both themes — without this,
 *    icons + secondary text inherit --page-fg (dark in light theme) and
 *    become invisible against the section's permanent dark gradient. */
.deep-dive { color: var(--bone); }

/* 2. AVAILABLE NOW gold tag — 2.44:1 on white in light theme.
 *    Switch to a darker mustard for legibility on cream/white. */
html[data-theme="light"] #report-status-tag { color: #7a5a18; }

/* 3. .compare-label was slate-500 #64748b — 4.23:1 on light cards.
 *    Move to slate-700 for AA. */
.deep-dive-card .compare-label,
.compare-item .compare-label { color: #334155; }

/* 4. Footer copyright + LAD placeholder were slate-500 on dark — 3.82/3.81:1.
 *    Use semi-transparent bone for proper AA on dark gradients. */
.footer-bottom p,
.lad-comparison-grid .placeholder-text { color: rgba(245, 239, 230, 0.78); }

/* 5. .hero-rail-text was alpha-cream on MCB red — 4.38:1.
 *    Bump to near-white for AA against the red rail. */
.hero-rail-text { color: rgba(255, 255, 255, 0.96); }

/* 6. Volume One/Two red label — needs different shades per theme because the
 *    surrounding card bg flips. Dark theme: brighter red on ink-soft. Light
 *    theme: deeper red on warm cream card. */
.report-volume-meta .vol-label { color: #ff5a63; } /* dark theme: 4.95:1 on ink-soft */
html[data-theme="light"] .report-volume-meta .vol-label { color: #8e1a20; } /* light: ~7.6:1 on cream */

/* 7. .gap-badge.negative — bright red on dark-red panel was 3.29:1. The bg
 *    is the inequality-card's maroon design accent (intentional). Switch the
 *    badge text to near-white so the metric reads clearly. */
.gap-badge.negative { color: #ffe4e6; }
