/* ==========================================================================
   VOXELCLICKS — Charts & dashboards

   Series palette validated with the dataviz validator against surface
   #0c141f: CVD separation ΔE 17.7 (deutan), normal-vision ΔE 21.9, chroma
   and contrast all pass. Do not substitute the brand cyan (#4dd8ff) for the
   blue slot: it sits ΔE 7.6 from the teal in normal vision and the two
   become indistinguishable as adjacent series.
   ========================================================================== */

:root {
  --c1: #5eead4; /* teal    — primary series */
  --c2: #fbbf24; /* amber   — comparison */
  --c3: #d8b4fe; /* violet  — third series */
  --c-grid: rgba(234, 240, 246, 0.09);
  --c-axis: rgba(234, 240, 246, 0.32);
}

/* --------------------------------------------------------------------------
   Figure shell
   -------------------------------------------------------------------------- */

.fig {
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: var(--bg-surface);
  padding: clamp(1.1rem, 2.4vw, 1.75rem);
  overflow: hidden;
}

.fig__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.35rem;
}

.fig__title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text-hi);
}

.fig__sub {
  font-size: 0.85rem;
  color: var(--text-lo);
  margin-bottom: 1.1rem;
  max-width: 60ch;
}

.fig__note {
  margin-top: 0.9rem;
  font-size: 0.76rem;
  color: var(--text-faint);
}

/* Direct children only. A blanket `.fig svg` also stretches nested icon
   SVGs (tick marks in a list inside a figure) to full panel width. */
.fig > svg,
.dash__panel > svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Legend: always present for two or more series */
.fig__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
  margin-bottom: 0.9rem;
}

.fig__key {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--text-lo); /* text keeps ink tokens, never the series colour */
}

.fig__swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex: none;
}

/* --------------------------------------------------------------------------
   Chart primitives
   -------------------------------------------------------------------------- */

.ch-grid line {
  stroke: var(--c-grid);
  stroke-width: 1;
}

.ch-axis {
  stroke: var(--c-axis);
  stroke-width: 1;
}

.ch-tick {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--text-faint);
}

.ch-line {
  fill: none;
  stroke-width: 2; /* thin marks */
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ch-dot {
  r: 4.5; /* >= 8px diameter */
  stroke: var(--bg-surface);
  stroke-width: 2; /* 2px surface ring on overlapping marks */
}

.ch-label {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--text);
}

.ch-bar {
  rx: 4; /* 4px rounded data-ends */
}

/* --------------------------------------------------------------------------
   Rank grid (geo-grid scan)
   -------------------------------------------------------------------------- */

.grid-scan {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  max-width: 320px;
}

.grid-scan span {
  aspect-ratio: 1;
  display: grid;
  place-content: center;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  color: #05090f;
}

/* Sequential magnitude: one hue, light to dark. Rank 1 is best. */
.r1 { background: #5eead4; }
.r2 { background: #3fcfbb; }
.r3 { background: #2bb3a2; }
.r4 { background: #1f8d84; color: #eaf0f6; }
.r5 { background: #176a66; color: #eaf0f6; }
.rx { background: #14303a; color: #55677a; }

.scan-legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-faint);
}

.scan-legend i {
  width: 15px;
  height: 15px;
  border-radius: 3px;
  display: inline-block;
}

/* --------------------------------------------------------------------------
   Stat tiles — sometimes the answer is not a chart
   -------------------------------------------------------------------------- */

.tiles {
  display: grid;
  gap: var(--sp-2);
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 780px) {
  .tiles {
    grid-template-columns: repeat(4, 1fr);
  }
}

.tile {
  padding: clamp(0.9rem, 2vw, 1.3rem);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--bg-surface);
}

.tile__n {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2.1rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--text-hi);
}

.tile__n i {
  font-style: normal;
  font-size: 0.6em;
  color: var(--c1);
}

.tile__l {
  margin-top: 0.45rem;
  font-size: 0.8rem;
  color: var(--text-lo);
}

/* --------------------------------------------------------------------------
   Dashboard frame
   -------------------------------------------------------------------------- */

.dash {
  border-radius: var(--r-lg);
  border: 1px solid var(--line-strong);
  background: linear-gradient(168deg, var(--bg-raised), var(--bg-surface) 60%);
  overflow: hidden;
  box-shadow: 0 30px 70px -44px rgba(0, 0, 0, 0.9);
}

.dash__bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--glass);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-lo);
}

.dash__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c1);
  flex: none;
}

.dash__body {
  display: grid;
  gap: 1px;
  background: var(--line);
  grid-template-columns: 1fr;
}

@media (min-width: 860px) {
  .dash__body {
    grid-template-columns: 1.35fr 0.65fr;
  }
}

.dash__panel {
  background: var(--bg-surface);
  padding: clamp(1rem, 2.2vw, 1.5rem);
}

/* Chart figures side by side */
.fig-2 {
  display: grid;
  gap: var(--sp-3);
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  .fig-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ==========================================================================
   Animated figures
   Every rule here is keyed off `.is-drawn`, which charts.js adds when the
   figure scrolls into view. Each figure is themed by its own --acc.
   ========================================================================== */

.fig[data-chart] {
  position: relative;
  border-color: color-mix(in oklab, var(--acc, var(--c1)) 22%, var(--line));
  background:
    radial-gradient(ellipse 70% 90% at 88% 4%, var(--acc-glow, transparent), transparent 62%),
    var(--bg-surface);
}

/* A thin accent rule along the top, drawn on reveal */
.fig[data-chart]::after {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  height: 2px;
  width: 100%;
  background: linear-gradient(90deg, var(--acc, var(--c1)), transparent 78%);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 1s var(--ease-out);
}

.fig[data-chart].is-drawn::after {
  transform: none;
}

/* ---- line: stroke itself on ------------------------------------------- */
.ch-draw {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: var(--len, 1000);
  stroke-dashoffset: var(--len, 1000);
}

.is-drawn .ch-draw {
  transition: stroke-dashoffset 1.6s var(--ease-out);
  stroke-dashoffset: 0;
}

/* ---- area wash under the line ----------------------------------------- */
.ch-area {
  opacity: 0;
  transform-origin: bottom;
  transform: scaleY(0.6);
}

.is-drawn .ch-area {
  transition: opacity 1s var(--ease-out) 0.45s, transform 1.1s var(--ease-out) 0.45s;
  opacity: 1;
  transform: none;
}

/* ---- dots pop in sequence --------------------------------------------- */
.ch-pop {
  opacity: 0;
  transform: scale(0);
  transform-box: fill-box;
  transform-origin: center;
}

.is-drawn .ch-pop {
  animation: ch-pop-in 0.5s var(--ease-spring) forwards;
  animation-delay: calc(0.42s + var(--i, 0) * 0.075s);
}

@keyframes ch-pop-in {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* The single most important point gets a pulsing halo */
.ch-hero-dot {
  opacity: 0;
}

.is-drawn .ch-hero-dot {
  animation: ch-pop-in 0.5s var(--ease-spring) 1.2s forwards;
}

.is-drawn .ch-halo {
  animation: ch-halo 2.4s var(--ease-out) 1.5s infinite;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes ch-halo {
  0% {
    opacity: 0.7;
    transform: scale(0.4);
  }
  100% {
    opacity: 0;
    transform: scale(2.6);
  }
}

/* ---- bars grow from the baseline -------------------------------------- */
.ch-grow {
  transform: scaleX(0);
  transform-box: fill-box;
  transform-origin: left;
}

.is-drawn .ch-grow {
  transition: transform 1s var(--ease-out);
  transition-delay: calc(0.15s + var(--i, 0) * 0.12s);
  transform: none;
}

.ch-grow-y {
  transform: scaleY(0);
  transform-box: fill-box;
  transform-origin: bottom;
}

.is-drawn .ch-grow-y {
  transition: transform 0.9s var(--ease-out);
  transition-delay: calc(0.15s + var(--i, 0) * 0.09s);
  transform: none;
}

/* Value labels fade in behind their bar */
.ch-val {
  opacity: 0;
}

.is-drawn .ch-val {
  transition: opacity 0.5s var(--ease-out);
  transition-delay: calc(0.7s + var(--i, 0) * 0.12s);
  opacity: 1;
}

/* ---- shaded danger / focus band --------------------------------------- */
.ch-band,
.ch-guide,
.ch-note {
  opacity: 0;
}

/* Dashed marker for the region that carries the argument. Replaces the old
   filled band, which read as a bar sitting inside a line chart. */
.ch-guide {
  stroke-width: 1.2;
  stroke-dasharray: 3 5;
  opacity: 0;
}
.is-drawn .ch-guide {
  transition: opacity 0.7s var(--ease-out) 1.1s;
  opacity: 0.55;
}
.is-drawn .ch-note {
  transition: opacity 0.7s var(--ease-out) 1.2s;
  opacity: 1;
}

.is-drawn .ch-band {
  transition: opacity 0.9s var(--ease-out) 0.9s;
  opacity: 1;
}

.ch-note {
  font-family: var(--font-mono);
  font-size: 9.5px;
  fill: var(--text-faint);
  letter-spacing: 0.04em;
}

/* ---- big number for the hero stat ------------------------------------- */
.fig__hero {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0.2rem 0 0.9rem;
}

.fig__hero b {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.1rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.045em;
  color: var(--acc, var(--c1));
}

.fig__hero span {
  font-size: 0.85rem;
  color: var(--text-lo);
  max-width: 24ch;
}

@media (prefers-reduced-motion: reduce) {
  .ch-draw { stroke-dashoffset: 0; }
  .ch-area, .ch-pop, .ch-val, .ch-band, .ch-guide, .ch-note, .ch-hero-dot { opacity: 1; transform: none; }
  .ch-grow, .ch-grow-y { transform: none; }
  .is-drawn .ch-halo { animation: none; }
  .fig[data-chart]::after { transform: none; }
}

/* Geo-grid cells reveal from the centre outward */
.ch-cell {
  opacity: 0;
  transform: scale(0.6);
}

.is-drawn .ch-cell {
  animation: ch-cell-in 0.42s var(--ease-spring) forwards;
  animation-delay: calc(0.2s + var(--i, 0) * 0.07s);
}

@keyframes ch-cell-in {
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ch-cell { opacity: 1; transform: none; animation: none; }
}
