body:has([data-explorer-root]) {
  background: var(--surface);
  background-image: radial-gradient(70rem 28rem at 75% -8%, rgba(var(--accent-rgb), .09), transparent 68%);
  color: var(--ink);
}

.explorer {
  /* The chart canvas matches the fixed light export, while controls follow the reader theme. */
  --explore-paper: #F7F5F1;
  --explore-paper-ink: #18212b;
  --explore-muted: #5d6876;
  --explore-control: var(--panel);
  --explore-soft: var(--panel-2);
  --explore-tint: var(--accent-tint);
  --explore-success: var(--status-success);
  --explore-warning: var(--status-warning);
  --explore-danger: var(--status-danger);
  color: var(--ink);
}

.explorer-intro { margin-bottom: 1.5rem; }
.explorer-intro p:last-child { color: var(--ink-2); }
.eyebrow,
.step-label {
  margin: 0 0 .2rem;
  color: var(--accent-ink);
  font-size: .72rem;
  font-weight: 750;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.explorer-workflow { margin: 0 0 1.25rem; }
.explorer-workflow ol {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .65rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.explorer-workflow li { min-width: 0; margin: 0; }
.explorer-workflow a {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: .65rem;
  min-height: 4.6rem;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(var(--shadow-rgb), .08);
}
.explorer-workflow a:hover {
  border-color: var(--accent-dim);
  background: var(--explore-tint);
  color: var(--ink);
}
.explorer-workflow a:focus-visible {
  outline: 3px solid var(--accent-dim);
  outline-offset: 2px;
}
.explorer-workflow a > span {
  display: inline-flex;
  grid-row: 1 / 3;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--explore-tint);
  color: var(--accent-ink);
  font-weight: 800;
}
.explorer-workflow strong { align-self: end; font-size: .88rem; line-height: 1.2; }
.explorer-workflow small {
  align-self: start;
  margin: .15rem 0 0;
  color: var(--ink-3);
  font-size: .72rem;
  line-height: 1.3;
}

.explorer-status,
.explorer-error {
  margin: 1rem 0;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent-dim);
  border-radius: 8px;
  padding: .7rem .9rem;
  color: var(--ink-2);
  background: var(--panel);
  font-size: .88rem;
}
.explorer-status[data-state="ready"] { border-left-color: var(--explore-success); }
.explorer-status[data-state="error"],
.explorer-error { border-left-color: var(--explore-danger); color: var(--ink); }

.explorer-panel {
  scroll-margin-top: 1rem;
  margin: 1rem 0 1.5rem;
  padding: clamp(1rem, 2.2vw, 1.6rem);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(var(--shadow-rgb), .12);
}
.explorer-panel h2 { margin: 0; color: var(--ink); }
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}
.section-title { display: flex; align-items: flex-start; gap: .75rem; min-width: 0; }
.step-number {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 50%;
  background: var(--explore-tint);
  color: var(--accent-ink);
  font-weight: 800;
}
.section-summary {
  max-width: 29rem;
  margin: .2rem 0 0;
  color: var(--ink-2);
  font-size: .88rem;
  text-align: right;
}

.selection-grid {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(18rem, 2fr) minmax(18rem, 2fr);
  gap: 1rem;
  align-items: stretch;
}
.branding-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: .9rem;
}
.control-wide { grid-column: 1 / -1; }

.explorer label,
.explorer fieldset legend {
  color: var(--ink-2);
  font-size: .84rem;
  font-weight: 650;
}
.explorer label > span,
.control-label { display: block; margin-bottom: .35rem; }
.explorer select,
.explorer input[type="text"],
.explorer input[type="file"] {
  width: 100%;
  min-height: 2.9rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--explore-control);
  color: var(--ink);
  padding: .58rem .75rem;
  font: inherit;
}
.explorer select:hover:not(:disabled),
.explorer input[type="text"]:hover,
.explorer input[type="file"]:hover { border-color: var(--accent-dim); }
.explorer select:disabled { background: var(--explore-soft); color: var(--ink-3); }
.explorer input[type="color"] {
  width: 100%;
  min-height: 2.9rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--explore-control);
  padding: .25rem;
}
.explorer select:focus-visible,
.explorer input:focus-visible,
.explorer button:focus-visible,
.chart-mount:focus-visible,
.pivot-table-wrap:focus-visible,
.explorer summary:focus-visible {
  outline: 3px solid var(--accent-dim);
  outline-offset: 2px;
}
.explorer small { display: block; margin-top: .3rem; color: var(--ink-3); font-weight: 400; }

.period-fieldset,
.jurisdiction-fieldset {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: .75rem .9rem .9rem;
  background: var(--explore-soft);
}
.period-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
.quick-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .55rem; }
.quick-actions button,
.fieldset-actions button { min-height: 44px; }
.jurisdiction-fieldset { margin-top: 1rem; background: var(--panel); }
.fieldset-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin: -.15rem 0 .55rem;
}
.fieldset-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.selection-count { color: var(--ink-3); font-size: .78rem; font-weight: 600; }
.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: .45rem;
}
.check-grid label {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-height: 2.75rem;
  margin: 0;
  padding: .4rem .55rem;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--explore-soft);
  color: var(--ink);
  font-weight: 550;
  cursor: pointer;
}
.check-grid label:hover { border-color: var(--accent-dim); background: var(--explore-tint); }
.check-grid input { flex: 0 0 auto; width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }

.explorer button {
  min-height: 2.75rem;
  border: 1px solid var(--accent);
  border-radius: 9px;
  padding: .55rem .85rem;
  background: var(--accent);
  color: var(--on-accent);
  font: 700 .84rem/1.2 inherit;
  cursor: pointer;
}
.explorer button:hover:not(:disabled) { border-color: var(--accent-ink); background: var(--accent-ink); }
.explorer button:disabled { cursor: not-allowed; opacity: .48; }
.explorer .secondary-button {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}
.explorer .secondary-button:hover:not(:disabled) {
  border-color: var(--accent-dim);
  background: var(--explore-tint);
  color: var(--ink);
}
.explorer .text-button {
  min-height: 2.75rem;
  padding: .35rem .55rem;
  border-color: transparent;
  background: transparent;
  color: var(--accent-ink);
  font-size: .78rem;
}
.explorer .text-button:hover:not(:disabled) {
  border-color: var(--accent-dim);
  background: var(--explore-tint);
  color: var(--accent-ink);
}
.button-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
.current-selection {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: .75rem;
  margin-top: 1rem;
  padding: .8rem .95rem;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--explore-tint);
}
.current-selection > span {
  color: var(--accent-ink);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.current-selection p { margin: 0; color: var(--ink); font-size: .88rem; }

.chart-figure { margin: 0; }
.chart-mount {
  min-height: 24rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--explore-paper);
}
.chart-mount svg { display: block; width: 100%; min-width: 42rem; height: auto; }
.chart-mount .axis-line,
.chart-mount .tick-line { stroke: #a8adb4; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-mount .grid-line { stroke: #d9d9d6; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-mount text { fill: var(--explore-paper-ink); font-family: system-ui, "Segoe UI", sans-serif; }
.chart-mount .axis-label { fill: #4c5563; font-size: 12px; }
.chart-mount .chart-title { font-size: 18px; font-weight: 700; }
.chart-mount .series-line { fill: none; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.chart-mount .series-point { stroke: var(--explore-paper); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.chart-mount .break-line { stroke: #7f253d; stroke-width: 1.5; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
.chart-mount .break-mark { fill: #7f253d; font-size: 17px; font-weight: 800; }
.chart-mount .absence-mark { fill: none; stroke: #343b47; stroke-width: 1.8; vector-effect: non-scaling-stroke; }
.chart-mount .legend-label { font-size: 11px; }
.chart-figure figcaption { margin-top: .55rem; color: var(--ink-2); font-size: .85rem; }
.chart-notes { margin-top: .8rem; }
.chart-notes ul { margin: .4rem 0; color: var(--ink-2); font-size: .86rem; }
.chart-notes .warning { color: var(--explore-danger); }
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 10rem;
  margin: 0;
  padding: 1.5rem;
  color: var(--ink-3);
  text-align: center;
}

.download-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  padding: .85rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--explore-soft);
}
.download-bar strong,
.download-bar span { display: block; }
.download-bar strong { color: var(--ink); font-size: .9rem; }
.download-bar span { margin-top: .1rem; color: var(--ink-3); font-size: .78rem; }

.provenance-panel,
.branding-details,
.analysis-notes,
.calculation-details {
  margin-top: .8rem;
  border-top: 1px solid var(--line);
  padding-top: .8rem;
}
.provenance-panel summary,
.branding-details summary,
.analysis-notes summary,
.calculation-details summary {
  min-height: 2.75rem;
  padding: .55rem .25rem;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
.provenance-list { display: grid; gap: .65rem; margin: .8rem 0; padding: 0; list-style: none; }
.provenance-list li {
  padding-left: .8rem;
  border-left: 2px solid var(--line);
  color: var(--ink-2);
  font-size: .86rem;
}
.local-note { color: var(--ink-2); }
.branding-preview {
  display: flex;
  align-items: center;
  gap: .8rem;
  min-height: 3rem;
  margin: .9rem 0;
  color: var(--ink);
  font-weight: 700;
}
.branding-preview img { display: block; max-width: 10rem; max-height: 3.5rem; object-fit: contain; }
.field-status { min-height: 1.25rem; color: var(--ink-2); font-size: .84rem; }
.field-status[data-state="error"] { color: var(--explore-danger); }

.pivot-builder {
  display: grid;
  grid-template-columns: minmax(11rem, 1fr) auto minmax(11rem, 1fr) minmax(11rem, 1fr);
  gap: .75rem;
  align-items: end;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--explore-soft);
}
.swap-button { min-width: 5.5rem; }
.swap-button span { margin-right: .15rem; font-size: 1.05rem; }
.pivot-table-wrap {
  max-height: 42rem;
  overflow: auto;
  margin-top: .8rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
}
.pivot-table-wrap table { margin: 0; }
.pivot-table-wrap caption { padding: .8rem 1rem; color: var(--ink-2); }
.pivot-table-wrap th { background: var(--panel-2); color: var(--ink-2); }
.pivot-table-wrap thead th { position: sticky; top: 0; z-index: 2; }
.pivot-table-wrap tbody th { position: sticky; left: 0; z-index: 1; border-right: 1px solid var(--line); }
.pivot-table-wrap td { color: var(--ink); font-variant-numeric: tabular-nums; }
.pivot-table-wrap .pivot-absence { background: repeating-linear-gradient(135deg, transparent 0 5px, rgba(var(--ink-rgb), .08) 5px 7px); }
.pivot-table-wrap .pivot-refused { color: var(--explore-danger); }
.pivot-table-wrap .pivot-mixed { box-shadow: inset 3px 0 #c4872d; }

.statistics-controls {
  display: grid;
  grid-template-columns: minmax(16rem, 2fr) minmax(10rem, 1fr) minmax(8rem, .7fr) auto;
  gap: .75rem;
  align-items: end;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--explore-soft);
}
.statistics-controls button { min-width: 7.5rem; min-height: 2.9rem; }
.assumption-note {
  margin-top: .35rem;
  padding: .75rem .9rem;
  border-left: 3px solid var(--accent-dim);
  background: var(--explore-soft);
  color: var(--ink-2);
  font-size: .86rem;
}
.test-result { margin-top: 1rem; }
.test-result[data-state="ok"],
.test-result[data-state="refused"] {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: .95rem 1rem;
  background: var(--panel);
}
.test-result[data-state="ok"] { border-left: 4px solid var(--explore-success); }
.test-result[data-state="refused"] { border-left: 4px solid var(--explore-warning); }
.test-result h3 { margin-top: 0; color: var(--ink); }
.result-label { color: var(--ink-3); font-size: .7rem; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; }
.calculation-details pre {
  max-height: 28rem;
  overflow: auto;
  padding: .8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink-2);
  white-space: pre-wrap;
  font: .78rem/1.5 ui-monospace, Consolas, monospace;
}

@media (max-width: 960px) {
  .explorer-workflow ol { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .selection-grid { grid-template-columns: 1fr; }
  .pivot-builder { grid-template-columns: 1fr auto 1fr; }
  .pivot-builder label:last-child { grid-column: 1 / -1; }
  .statistics-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .test-control { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .section-heading { display: block; }
  .section-summary { margin-top: .5rem; text-align: left; }
  .download-bar { display: block; }
  .download-bar .button-row { justify-content: flex-start; margin-top: .75rem; }
  .branding-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .branding-grid > label:first-child,
  .branding-grid > .control-wide { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .explorer-workflow ol { grid-template-columns: 1fr; }
  .explorer-workflow a { min-height: 4.1rem; }
  .explorer-panel { margin-right: -.35rem; margin-left: -.35rem; border-radius: 12px; }
  .period-grid,
  .pivot-builder,
  .statistics-controls,
  .branding-grid { grid-template-columns: 1fr; }
  .pivot-builder label:last-child,
  .test-control,
  .branding-grid > label:first-child,
  .branding-grid > .control-wide { grid-column: auto; }
  .swap-button { width: 100%; }
  .fieldset-toolbar { align-items: flex-start; }
  .check-grid { grid-template-columns: 1fr; }
  .current-selection { grid-template-columns: 1fr; gap: .2rem; }
  .button-row { display: grid; grid-template-columns: 1fr; width: 100%; }
  .button-row button { width: 100%; }
  .quick-actions { display: grid; grid-template-columns: 1fr; }
  .quick-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .explorer * { scroll-behavior: auto !important; }
}

@media print {
  body:has([data-explorer-root]) { background: #ffffff; }
  .site-header,
  .site-footer,
  .explorer-intro,
  .explorer-workflow,
  .explorer-status,
  .explorer-panel:not(.chart-panel),
  .chart-panel .download-bar,
  .chart-panel details { display: none !important; }
  .explorer-panel.chart-panel { border: 0; padding: 0; background: #fff; box-shadow: none; }
  .chart-mount { border: 0; }
  .chart-mount svg { min-width: 0; }
}

/* Sensitive slices in the explorer use the same veil vocabulary as the
   jurisdiction pages; the wrapper itself carries the blur here because the
   chart is mounted directly inside it. */
/* No transition when the veil is APPLIED: the explorer applies it the moment a
   sensitive measure is selected, and animating from clear to blurred would show
   the chart for a quarter second before hiding it. Revealing is the reader's
   deliberate choice, so that direction may ease. */
#chart-veil-wrap.sensitive-veil {
  filter: blur(14px); pointer-events: none; user-select: none;
}
#chart-veil-wrap.sensitive-veil.revealed {
  filter: none; pointer-events: auto; user-select: auto;
  transition: filter .25s ease;
}
.chart-sensitivity[hidden] { display: none; }
