/* ── App shell ─────────────────────────────────────────────────────────────── */

body {
  display: grid;
  /* minmax(0, 1fr) keeps a long toolbar from widening the whole grid: without
     it the implicit auto column sizes to max-content and the page scrolls
     sideways on narrow screens. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  min-height: 100dvh;
}

/* ── Top bar ───────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
  padding: var(--space-4) clamp(16px, 2.4vw, 32px) var(--space-3);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  /* Above the transport (20) and the detail rail (25): the toolbar's popovers —
     Display and the language switch — live inside this grid item, so its
     stacking context caps them. They must not open under the player. */
  z-index: 50;
}

.brand {
  min-width: 0;
}

.brand h1 {
  font-family: var(--font-display);
  font-size: var(--step-3);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--ink);
}

.brand .subtitle {
  margin-top: 6px;
  font-size: var(--step--1);
  color: var(--muted);
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
}

.credit {
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.credit a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.credit a:hover {
  color: var(--ink);
  text-decoration-color: var(--accent);
}

.finding {
  max-width: 62ch;
  margin-top: var(--space-3);
  font-size: var(--step-1);
  line-height: 1.4;
  /* Reserved at the tallest wrap any locale/year produces (3 lines below
     1024px, 2 lines above), so the year ticking over cannot reflow the header
     and nudge the donut. The 2px absorbs sub-pixel line-box rounding. Keep in
     sync with the finding template in the locale files — a longer template
     needs a bigger reservation. */
  min-height: calc(3 * 1.4em + 2px);
  color: var(--ink-soft);
  text-wrap: pretty;
}

@media (min-width: 1024px) {
  .finding {
    min-height: calc(2 * 1.4em + 2px);
  }
}

.finding em {
  font-style: normal;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink);
}

.finding .finding-year {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.finding .finding-sep {
  margin: 0 0.55em;
  color: var(--muted);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink-soft);
  font-size: var(--step--1);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.btn:hover {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--panel-2);
}

.btn:active {
  transform: translateY(1px);
}

.btn[aria-pressed="true"],
.btn.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.btn.icon {
  width: 36px;
  padding: 0;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.ghost:hover {
  background: var(--panel-2);
  border-color: var(--line);
}

.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.btn .lbl {
  display: none;
}

@media (min-width: 900px) {
  .btn .lbl {
    display: inline;
  }

  /* The Display label is the only variable-width text in the toolbar and the
     toolbar is right-aligned, so without this the language switch slides left
     and right as the label changes length ("Display" → "Visualizzazione", 44 to
     95px). Reserved at the widest locale, plus a little slack for font
     fallback, so the selector never moves. */
  #btnDisplay {
    min-width: 152px;
  }
}

/* Language switch: a dropdown, the same popover as Display. The trigger names
   the current language by its endonym, so it is a variable-width label in the
   same right-aligned toolbar — the floor width is the widest endonym, so the
   row does not shift as "English" becomes "Italiano". */
.lang-switch {
  flex: none;
}

/* With scripting off the panel cannot open, so the trigger would be a dead
   button: hide it. There is no no-JS fallback — the explorer itself needs
   JavaScript (chart, map, controls), so a lone row of language links would not
   buy a usable page. Browsers without the `scripting` feature show the trigger
   and simply ignore it. */
@media (scripting: none) {
  .lang-switch {
    display: none;
  }
}

.lang-btn {
  min-width: 124px;
}

/* The endonym is not .lbl: it stays visible below 900px, unlike the Display
   label, because "English" is the whole point of the trigger. */
.lang-name {
  font-weight: 500;
  letter-spacing: 0.01em;
}

.lang-chev {
  width: 12px;
  height: 12px;
  margin-left: -2px;
  opacity: 0.7;
  transition: transform var(--dur-fast) var(--ease-out);
}

.lang-btn[aria-expanded="true"] .lang-chev {
  transform: rotate(180deg);
}

.lang-btn[aria-expanded="true"] {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--panel-2);
}

/* Two classes so the shared .popover width/padding (declared later in this
   file) does not win: the language panel is a short list, not a form. */
.popover.lang-popover {
  width: auto;
  min-width: 190px;
  padding: var(--space-2);
  overflow-y: auto;
}

.lang-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lang-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: var(--step--1);
  color: var(--ink-soft);
  text-decoration: none;
  transition: background var(--dur-fast), color var(--dur-fast);
}

.lang-list a:hover,
.lang-list a:focus-visible {
  background: var(--panel-2);
  color: var(--ink);
}

/* The current language is marked by the check glyph AND aria-current — the ink
   fill is a reinforcement, never the only encoding. */
.lang-list a[aria-current] {
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
}

.lang-check {
  width: 14px;
  height: 14px;
  flex: none;
}

/* View switch: the same chrome the language switch had when it was segmented,
   with words instead of language names. Buttons are given a floor width so the
   toolbar does not shift when a locale swaps "Bars" for "Balken". */
.view-switch {
  display: inline-flex;
  align-items: center;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  background: var(--panel);
}

.view-switch button {
  height: 34px;
  min-width: 64px;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--muted);
  transition: background var(--dur-fast), color var(--dur-fast);
}

.view-switch button + button {
  border-left: 1px solid var(--line);
}

.view-switch button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.view-switch button:hover:not([aria-pressed="true"]) {
  background: var(--panel-2);
  color: var(--ink);
}

/* ── Stage ─────────────────────────────────────────────────────────────────── */

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 0;
  min-width: 0;
  padding: 14px clamp(12px, 2.4vw, 32px);
  transition: padding-right var(--dur-slow) var(--ease-out);
  /* The charts size themselves from both axes of the stage (cqw / cqh), so the
     viewport height is used and a portrait phone still gets a square Doughnut. */
  container-type: size;
}

/* One host, two charts: the donut is square, the bar chart is wide. Only the
   active chart is laid out and only the active chart is in the tab order. */
.chart-host {
  position: relative;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
}

/* The switch sits in the stage above the chart: 50px = its 36px height plus
   the 14px gap. Both charts fill whatever height the viewport leaves them —
   measured from the stage itself, so a header that wraps in one locale and not
   another costs the chart nothing. The size control only caps that height
   (small and medium); "large" is "as tall as the window allows". */
.chart-host[data-view="donut"] {
  width: min(var(--donut-size, 100%), 100cqw, calc(100cqh - 50px));
  aspect-ratio: 1;
  max-width: 100%;
}

.chart-host[data-view="bars"] {
  width: min(100cqw, 1400px);
  height: calc(100cqh - 50px);
  max-height: var(--bars-max, 100%);
}

body[data-size="sm"] {
  --donut-size: 440px;
  --bars-max: 360px;
}
body[data-size="md"] {
  --donut-size: 600px;
  --bars-max: 460px;
}

.donut-svg,
.bars-svg {
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

/* The inactive chart leaves the flow and the tab order. Declared here because
   `hidden` on an SVG element must not depend on the UA stylesheet. */
.chart-host > svg[hidden] {
  display: none;
}

.donut-svg {
  overflow: visible;
}

.bars-svg {
  overflow: hidden;
  font-family: var(--font-ui);
}

.donut-svg text {
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: 0.005em;
  paint-order: stroke;
}

.donut-svg .band-title {
  fill: var(--ring-ink);
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.donut-svg .banner {
  fill: var(--body-ink);
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
  opacity: 0.9;
}

.donut-svg .hole-label {
  fill: var(--ink);
  stroke: var(--label-halo);
  stroke-width: 2.4px;
  stroke-linejoin: round;
  paint-order: stroke;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.donut-svg .eco-label {
  fill: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  text-anchor: middle;
  stroke: var(--label-halo);
  stroke-width: 2.2px;
  stroke-linejoin: round;
  paint-order: stroke;
}

.donut-svg .arrow-label {
  fill: var(--paper);
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.donut-svg .layer-wash,
.donut-svg .layer-body,
.donut-svg .layer-within,
.donut-svg .layer-ticks,
.donut-svg .layer-titles,
.donut-svg .layer-labels,
.donut-svg .layer-arrows {
  pointer-events: none;
}

.donut-svg .wedge {
  transition: filter var(--dur-fast) var(--ease-out), opacity var(--dur-fast);
  cursor: pointer;
}

.donut-svg.is-hovering .wedge {
  opacity: 0.42;
}

.donut-svg.is-hovering .wedge.is-active {
  opacity: 1;
}

.donut-svg .hit {
  cursor: pointer;
}

/* Hover and selection both outline the sector; selection also dashes it. */
.donut-svg .hit.is-active {
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
}

.donut-svg .hit.is-selected {
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-dasharray: 6 4;
}

.donut-svg text {
  user-select: none;
}

/* ── Bar view ───────────────────────────────────────────────────────────────── */

.bars-svg text {
  user-select: none;
  paint-order: stroke;
}

.bars-svg .bar {
  cursor: pointer;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.bars-svg .bar.is-active {
  fill: var(--alarm-strong);
}

.bars-svg.is-hovering .bar {
  opacity: 0.4;
}

.bars-svg.is-hovering .bar.is-active {
  opacity: 1;
}

.bars-svg .hit {
  cursor: pointer;
}

.bars-svg .bar-band {
  opacity: 0.55;
}

/* The two Doughnut 3.0 band labels, styled like the donut's banners. */
.bars-svg .banner {
  fill: var(--body-ink);
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
  opacity: 0.9;
}

.bars-svg .layer-titles {
  pointer-events: none;
}

/* A baseline tick for an indicator on the safe side (ratio at or below the
   boundary). No length is drawn, so no magnitude is implied. */
.bars-svg .bar-within {
  opacity: 0.6;
  pointer-events: none;
}

.bars-svg .bar-label {
  fill: var(--ink);
  stroke: var(--label-halo);
  stroke-width: 2.2px;
  stroke-linejoin: round;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.bars-svg .bar-label.is-social {
  fill: var(--ink-soft);
}

.bars-svg .bar-value {
  fill: var(--ink-soft);
  stroke: var(--label-halo);
  stroke-width: 2px;
  stroke-linejoin: round;
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.bars-svg .bar-axis {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 8.6px;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.bars-svg .bar-tick-label {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.bars-svg .bar-rule-title {
  fill: var(--body-ink);
  opacity: 0.85;
  font-family: var(--font-mono);
  font-size: 8.6px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.toolbar-item {
  position: relative;
}

.stage-hint {
  display: flex;
  align-items: center;
  gap: 7px;
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  white-space: nowrap;
  transition: opacity var(--dur-mid) var(--ease-out);
}

.stage-hint.is-hidden,
.stage:has(.strip.is-open) .stage-hint {
  opacity: 0;
  pointer-events: none;
}

.stage-hint .hint-arrow {
  width: 14px;
  height: 14px;
  flex: none;
  color: var(--accent);
}

.stage-hint .hint-mobile {
  display: none;
}

@media (max-width: 640px) {
  .stage-hint .hint-desktop {
    display: none;
  }

  .stage-hint .hint-mobile {
    display: inline;
  }
}

/* ── Tooltip ───────────────────────────────────────────────────────────────── */

.tooltip {
  position: absolute;
  z-index: 30;
  left: 0;
  top: 0;
  min-width: 150px;
  max-width: 260px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, calc(-100% - 12px)) scale(0.98);
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.35);
}

.tooltip.is-visible {
  opacity: 1;
  transform: translate(-50%, calc(-100% - 12px)) scale(1);
}

.tooltip strong {
  font-weight: 600;
}

.tooltip .t-value {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.8;
  display: block;
  margin-top: 2px;
}

.tooltip .t-cta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
}

.tooltip .t-cta svg {
  width: 11px;
  height: 11px;
}

/* ── Transport ─────────────────────────────────────────────────────────────── */

.transport {
  display: grid;
  grid-template-columns: auto auto minmax(120px, 1fr) auto auto;
  align-items: center;
  gap: clamp(10px, 1.6vw, 22px);
  padding: 12px clamp(16px, 2.4vw, 32px) 14px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  z-index: 20;
}

.play {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  display: grid;
  place-items: center;
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast);
}

.play:hover {
  transform: scale(1.05);
}

.play:active {
  transform: scale(0.97);
}

.play svg {
  width: 17px;
  height: 17px;
}

.year-block {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 74px;
}

.year {
  font-family: var(--font-mono);
  font-size: clamp(24px, 2.4vw, 34px);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.year-block .kicker {
  font-size: 9px;
  letter-spacing: 0.12em;
}

.scrub {
  position: relative;
  display: flex;
  align-items: center;
  height: 46px;
}

.scrub input[type="range"] {
  position: relative;
  z-index: 2;
  width: calc(100% - 16px);
  margin: 0 8px;
  height: 46px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.scrub input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--line-strong);
  border-radius: 1px;
}

.scrub input[type="range"]::-moz-range-track {
  height: 2px;
  background: var(--line-strong);
  border-radius: 1px;
}

.scrub input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--ink-soft);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--line-strong);
  transition: transform var(--dur-fast) var(--ease-out);
}

.scrub input[type="range"]::-moz-range-thumb {
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink-soft);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--line-strong);
}

.scrub input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.15);
}

.speed {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.speed button {
  padding: 0 9px;
  height: 30px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

.speed button + button {
  border-left: 1px solid var(--line);
}

.speed button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.loop {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--muted);
}

.loop[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.loop svg {
  width: 15px;
  height: 15px;
}

/* ── Detail rail ───────────────────────────────────────────────────────────── */

.detail {
  visibility: hidden;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(var(--rail-w), 92vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  clip-path: inset(0 0 0 100%);
  transition: clip-path var(--dur-slow) var(--ease-out),
    visibility 0s linear var(--dur-slow);
  z-index: 25;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.detail.is-open {
  visibility: visible;
  clip-path: inset(0 0 0 0);
  transition: clip-path var(--dur-slow) var(--ease-out), visibility 0s;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-3);
  border-bottom: 1px solid var(--line);
}

.detail-body {
  padding: var(--space-5);
  overflow-y: auto;
  flex: 1;
}

.detail h2 {
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin-top: 4px;
}

.detail .dim {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: var(--step--1);
  color: var(--muted);
  margin-top: 4px;
}

.rel-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1.6;
}

.rel-chip.is-direct {
  color: var(--ring);
  border-color: currentColor;
}

.rel-chip.is-proxy {
  color: var(--accent);
  border-color: currentColor;
}

.rel-note {
  margin-top: 10px;
  font-size: var(--step--1);
  line-height: 1.5;
  color: var(--muted);
  text-wrap: pretty;
}

.data-table .rel-chip {
  font-size: 8.5px;
  margin-top: 3px;
}

.detail-intro p {
  font-size: var(--step-0);
  line-height: 1.5;
  color: var(--ink-soft);
  text-wrap: pretty;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  margin-top: var(--space-4);
}

.stat {
  background: var(--panel);
  padding: 12px 14px;
}

.stat .kicker {
  font-size: 9px;
  letter-spacing: 0.1em;
}

.stat .v {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 500;
  margin-top: 3px;
  letter-spacing: -0.02em;
}

.stat .u {
  font-size: 10px;
  color: var(--muted);
  margin-top: 1px;
  display: block;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--space-4);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: var(--step--1);
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status-pill.is-over .dot {
  background: var(--alarm);
}

.status-pill.is-under .dot {
  background: var(--accent);
}

.status-pill.is-good .dot {
  background: var(--ring);
}

.spark {
  margin-top: var(--space-5);
  width: 100%;
  height: 96px;
}

.spark.is-live {
  position: relative;
  cursor: crosshair;
  outline: none;
}

.spark.is-live:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 4px;
  border-radius: 6px;
}

.spark-label {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
}

.spark-label > span:last-child {
  text-align: right;
}

.spark-readout {
  text-align: center;
  color: var(--ink);
  white-space: nowrap;
}

.spark-readout strong {
  font-weight: 600;
}

.detail-note {
  margin-top: var(--space-4);
  padding: 10px 12px;
  border-left: 2px solid var(--line-strong);
  font-size: var(--step--1);
  color: var(--muted);
  line-height: 1.45;
}

/* Doughnut 3.0 mapping — deliberately the quietest block in the rail */

.dim-block {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.dim-head {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.dim-head svg {
  width: 12px;
  height: 12px;
  flex: none;
  opacity: 0.8;
}

.version-note {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
  text-wrap: pretty;
}

.dim-block .dim {
  margin-top: 8px;
  font-size: 11px;
  opacity: 0.85;
}

.dim-block .rel-note {
  margin-top: 6px;
  font-size: 11px;
}

/* ── Popover ───────────────────────────────────────────────────────────────── */

.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 320px;
  padding: var(--space-4);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  /* Hidden panels are not tabbable and not readable: the fade still runs, the
     visibility step only lands at the end of the close. */
  visibility: hidden;
  transform: translateY(-6px) scale(0.99);
  transform-origin: top right;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out),
    visibility 0s linear var(--dur-fast);
}

.popover.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out),
    visibility 0s linear 0s;
}

.control-group + .control-group {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.control-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.segmented {
  display: flex;
  gap: 4px;
}

.segmented button {
  flex: 1;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 11px;
  color: var(--muted);
  transition: all var(--dur-fast);
}

.segmented button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.swatches {
  display: flex;
  gap: 8px;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  position: relative;
  transition: transform var(--dur-fast) var(--ease-out);
}

.swatch::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: linear-gradient(
    90deg,
    var(--ring) 0 33%,
    var(--body) 33% 66%,
    var(--alarm) 66%
  );
}

.swatch:hover {
  transform: scale(1.08);
}

.swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 5px 0;
  font-size: var(--step--1);
  color: var(--ink-soft);
}

.switch {
  position: relative;
  width: 34px;
  height: 20px;
  flex: none;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background var(--dur-fast);
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform var(--dur-fast) var(--ease-out);
}

.switch input:checked ~ .knob {
  transform: translateX(14px);
}

.switch input:checked {
  background: transparent;
}

.switch:has(input:checked) {
  background: var(--ink);
}

.switch input:focus-visible ~ .knob {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Drawer ────────────────────────────────────────────────────────────────── */

.scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-mid) var(--ease-out);
  z-index: 55;
}

.scrim.is-on {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  visibility: hidden;
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(620px, 94vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  clip-path: inset(0 0 0 100%);
  transition: clip-path var(--dur-slow) var(--ease-out),
    visibility 0s linear var(--dur-slow);
  z-index: 60;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.drawer.is-open {
  visibility: visible;
  clip-path: inset(0 0 0 0);
  transition: clip-path var(--dur-slow) var(--ease-out), visibility 0s;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line);
}

.drawer-head h2 {
  font-family: var(--font-display);
  font-size: var(--step-2);
  letter-spacing: -0.03em;
}

.drawer-body {
  overflow-y: auto;
  padding: var(--space-5);
  font-size: var(--step-0);
  color: var(--ink-soft);
}

.drawer-body h3 {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: var(--space-5) 0 6px;
}

.drawer-body h3:first-child {
  margin-top: 0;
}

.drawer-body p {
  line-height: 1.6;
  max-width: 62ch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--space-3);
  font-size: 12px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.data-table th {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

.data-table td.num {
  font-family: var(--font-mono);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table tr.is-eco td:first-child {
  box-shadow: inset 3px 0 0 var(--alarm);
}

.data-table tr.is-social td:first-child {
  box-shadow: inset 3px 0 0 var(--ring);
}

.term-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  font-size: 12px;
  margin-top: 8px;
}

.term-list dt {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.term-list dd {
  margin: 0;
}

.link {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
}

.link:hover {
  text-decoration-color: var(--accent);
}

/* ── Trend strip ───────────────────────────────────────────────────────────── */

.strip {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 8px;
  width: auto;
  max-width: 920px;
  margin-inline: auto;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 14px 12px;
  z-index: 15;
  opacity: 0;
  translate: 0 12px;
  pointer-events: none;
  transition: opacity var(--dur-mid) var(--ease-out), translate var(--dur-mid) var(--ease-out);
}

.strip.is-open {
  opacity: 1;
  translate: 0 0;
  pointer-events: auto;
}

.strip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.strip-head .kicker {
  font-size: 9px;
}

.strip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 4px 10px;
}

.mini {
  display: block;
  text-align: left;
  padding: 3px 0;
  border-radius: 4px;
}

.mini svg {
  width: 100%;
  height: 22px;
  overflow: visible;
}

.mini .mini-label {
  display: block;
  font-size: 9.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.mini:hover .mini-label,
.mini[aria-pressed="true"] .mini-label {
  color: var(--ink);
}

.strip-caption {
  margin-top: 6px;
  font-size: 10px;
  color: var(--muted);
}

/* ── Tour ──────────────────────────────────────────────────────────────────── */

.tour-scrim {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-mid);
}

.tour-scrim.is-on {
  opacity: 1;
  pointer-events: auto;
}

.tour-card {
  position: fixed;
  z-index: 71;
  left: 50%;
  bottom: 116px;
  transform: translate(-50%, 12px);
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: var(--space-5);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-mid) var(--ease-out), transform var(--dur-mid) var(--ease-out);
}

.tour-card.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.tour-card h3 {
  font-family: var(--font-display);
  font-size: var(--step-2);
  letter-spacing: -0.03em;
  margin: 6px 0 6px;
}

.tour-card p {
  font-size: var(--step-0);
  color: var(--ink-soft);
  line-height: 1.55;
}

.tour-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.tour-dots {
  display: flex;
  gap: 5px;
}

.tour-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
}

.tour-dots span.is-on {
  background: var(--accent);
}

.tour-progress {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}

/* ── Toast ─────────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 108px;
  transform: translate(-50%, 8px);
  background: var(--ink);
  color: var(--paper);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 12px;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast), transform var(--dur-fast);
}

.toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ── Breakpoints ───────────────────────────────────────────────────────────── */

@media (min-width: 1024px) {
  body.detail-open .stage {
    padding-right: calc(min(var(--rail-w), 92vw) + 8px);
  }

  body.detail-open .strip {
    right: calc(min(var(--rail-w), 92vw) + 16px);
  }
}

@media (max-width: 1023px) {
  .detail {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: min(72vh, 620px);
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    clip-path: inset(100% 0 0 0);
  }

  .detail.is-open {
    clip-path: inset(0 0 0 0);
  }

  .detail-body {
    padding-bottom: 28px;
  }
}

@media (max-width: 767px) {
  .topbar {
    flex-wrap: wrap;
    gap: var(--space-3);
    padding: 12px 16px 10px;
  }

  .brand h1 {
    font-size: clamp(1.5rem, 7vw, 2rem);
  }

  .finding {
    font-size: var(--step-0);
    margin-top: 8px;
  }

  .toolbar {
    order: 3;
    width: 100%;
    min-width: 0;
    flex-shrink: 1;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .toolbar::-webkit-scrollbar {
    display: none;
  }

  .transport {
    grid-template-columns: auto auto 1fr auto;
    grid-template-areas:
      "play year speed loop"
      "scrub scrub scrub scrub";
    gap: 6px 10px;
    padding: 10px 16px 12px;
  }

  .play {
    grid-area: play;
    width: 42px;
    height: 42px;
  }

  .year-block {
    grid-area: year;
    flex-direction: row;
    align-items: baseline;
    gap: 8px;
  }

  .loop {
    grid-area: loop;
  }

  .scrub {
    grid-area: scrub;
  }

  .speed {
    grid-area: speed;
    justify-self: end;
  }

  .speed button {
    padding: 0 7px;
  }

  .strip {
    bottom: 6px;
    left: 10px;
    right: 10px;
    max-height: 34vh;
    overflow-y: auto;
  }

  .popover {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 12px;
    width: auto;
    max-height: 80vh;
    overflow-y: auto;
    transform-origin: bottom center;
    transform: translateY(10px) scale(0.99);
  }

  /* The language panel is four short rows: a compact panel, and popover.js
     anchors it under its trigger (the mobile toolbar scrolls and would clip an
     absolutely positioned child). */
  .popover.lang-popover {
    left: auto;
    right: 12px;
    width: min(240px, calc(100vw - 24px));
  }

  .popover.is-open {
    transform: none;
  }
}

@media (max-width: 700px) {
  .donut-svg .layer-arrows {
    display: none !important;
  }
}

@media (max-height: 700px) and (min-width: 768px) {
  .strip {
    display: none;
  }
}

/* ── Country page: back to the world map ──────────────────────────────────── */

.back-link {
  display: inline-block;
  margin-bottom: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
}
.back-link:hover { color: var(--ink); }

/* Server-rendered values table for visitors without JavaScript. */
.nojs { max-width: 900px; margin: var(--space-6) auto; padding: 0 var(--space-4); }
.nojs h2 { font-family: var(--font-display); font-size: var(--step-2); }
.nojs p { color: var(--muted); }
.nojs .data-table { width: 100%; border-collapse: collapse; font-size: var(--step-0); }
.nojs .data-table th, .nojs .data-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
