/* La ricchezza in scala — Le Alternative, 2026
   Basato su "Wealth, shown to scale" di Matt Korostoff (GPL v3) */

:root {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --ink: #1b1b1f;
  --muted: #5d5d66;
  --line: rgba(0, 0, 0, .12);
  --shadow: 0 6px 24px rgba(20, 20, 30, .10), 0 1px 3px rgba(20, 20, 30, .08);
  --accent: #e8590c;
  --musk: #f59f00;
  --musk-deep: #e67700;
  --four: #1c7ed6;
  --four-deep: #1864ab;
  --billion: #4dabf7;
  --obj: #2b8a3e;
  --obj-alt: #5c940d;
  --band: rgba(0, 0, 0, .22);
  --shape: rgba(255, 255, 255, .55);
  --hud-bg: rgba(255, 255, 255, .92);
  --bar-h: 560px;   /* altezza fissa delle barre: la scala dipende da questo valore, vedi main.js */
  --hud-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161a;
    --surface: #23252b;
    --ink: #ecebe8;
    --muted: #a3a3ad;
    --line: rgba(255, 255, 255, .14);
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
    --obj: #51cf66;
    --obj-alt: #94d82d;
    --hud-bg: rgba(30, 31, 36, .92);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15161a;
  --surface: #23252b;
  --ink: #ecebe8;
  --muted: #a3a3ad;
  --line: rgba(255, 255, 255, .14);
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  --obj: #51cf66;
  --obj-alt: #94d82d;
  --hud-bg: rgba(30, 31, 36, .92);
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
body {
  overflow-x: auto;
  overflow-y: hidden;          /* la pagina va solo di lato... */
  overscroll-behavior: none;
}
html.tall body { overflow-y: auto; }   /* ...tranne su schermi troppo bassi per la barra */
/* la barra di scorrimento del browser è sostituita dalla barra di avanzamento in basso */
html { scrollbar-width: none; }
html::-webkit-scrollbar, body::-webkit-scrollbar { display: none; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- binario orizzontale ---------- */
.track {
  display: flex;
  align-items: center;
  gap: 160px;
  width: max-content;
  height: calc(100vh - var(--hud-h));
  height: calc(100dvh - var(--hud-h));
  min-height: calc(var(--bar-h) + 16px);
  padding: 8px 33vw 8px max(24px, 6vw);
  margin-bottom: var(--hud-h);
}
.stop { flex: none; position: relative; }

/* ---------- intro ---------- */
.intro { width: min(560px, 88vw); }
.kicker {
  margin: 0 0 12px;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
}
.intro h1 {
  margin: 0 0 20px;
  font-size: clamp(2.6rem, 9vw, 4.6rem);
  line-height: 1.02;
  letter-spacing: -.03em;
}
.lead { font-size: 1.15rem; margin: 0 0 16px; }
.origin { font-size: .9rem; color: var(--muted); margin: 0 0 24px; padding-left: 12px; border-left: 3px solid var(--accent); }
.hint {
  display: inline-block;
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: .9rem;
  font-weight: 600;
  animation: nudge 2.4s ease-in-out infinite;
}
.hint-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .hint-desktop { display: none; }
  .hint-touch { display: inline-block; }
}
@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(8px); } }

/* ---------- oggetti in scala ---------- */
.obj { background: var(--obj); flex: none; }
.obj.alt { background: var(--obj-alt); }
.obj.ink { background: var(--ink); }
.px1 { width: 1px; height: 1px; background: var(--ink); }
.dot-wrap {
  width: 44px; height: 44px;
  border: 1.5px dashed var(--muted);
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.figure-stop { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; width: 220px; }
.cap { margin: 0; font-size: .95rem; color: var(--muted); max-width: 30ch; }
.cap strong { color: var(--ink); }
.figure-row { display: flex; align-items: flex-end; gap: 48px; }
.figure-row figure, .deaths-row figure { margin: 0; display: flex; flex-direction: column; gap: 10px; width: 150px; }
.figure-row figcaption, .deaths-row figcaption { font-size: .9rem; color: var(--muted); }
.figure-row figcaption strong { color: var(--ink); }

.rect.billion { background: var(--billion); height: var(--bar-h); position: relative; }

/* ---------- barre ---------- */
.bar {
  position: relative;
  height: var(--bar-h);   /* niente angoli arrotondati: toglierebbero pixel all'area */
}
.bar.musk { background: var(--musk); }
.bar.four { background: var(--four); }
.bar-label, .bar-title {
  position: sticky;
  left: 16px;
  display: inline-block;
  margin: 0;
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  z-index: 3;
}
.bar-title {
  top: 14px;
  margin-top: 14px;
  margin-left: 16px;
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  white-space: normal;
  max-width: calc(100vw - 32px);
}
.bar-count { font-size: .9rem; font-weight: 600; font-variant-numeric: tabular-nums; opacity: .9; }
.bar-count:empty { display: none; }
.rect.billion .bar-label { margin: 14px 0 0 14px; }

/* righello in basso: tacche ogni 100 milioni $ (calcolate in main.js) */
.bar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 14px;
  background-image: repeating-linear-gradient(90deg, rgba(0,0,0,.35) 0 1px, transparent 1px var(--tick, 178.57px));
  pointer-events: none;
}

.card, .figure-free, .shape, .band, .marker { position: absolute; }
.card, .figure-free { top: 50%; transform: translateY(-50%); z-index: 2; }

.card {
  width: min(360px, calc(100vw - 48px));
  max-height: calc(var(--bar-h) - 90px);
  overflow: auto;
  padding: 20px 22px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.card p { margin: 0 0 .7em; }
.card p:last-child { margin-bottom: 0; }
.card .big { font-size: 1.25rem; font-weight: 650; line-height: 1.3; letter-spacing: -.01em; }
.card.small { width: min(280px, calc(100vw - 48px)); }
.card.head { display: flex; align-items: center; gap: 18px; width: min(420px, calc(100vw - 48px)); }
.card.head h3 { margin: 0; font-size: 1.3rem; line-height: 1.25; }
.text-stop .card { position: static; transform: none; max-height: calc(100dvh - var(--hud-h) - 24px); }

.card.compare { display: flex; flex-direction: column; gap: 16px; width: min(380px, calc(100vw - 48px)); }
.cmp { display: grid; grid-template-columns: 60px 1fr; align-items: center; gap: 12px; }
.cmp p { margin: 0; font-size: .92rem; }
.cmp .obj { justify-self: center; }

.pie {
  --p: 10;
  flex: none;
  width: 72px; height: 72px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0);
}

/* sagome di confronto, alte quanto la barra */
.shape {
  top: 0;
  height: 100%;
  background: var(--shape);
  border-left: 2px solid rgba(255,255,255,.9);
  border-right: 2px solid rgba(255,255,255,.9);
  z-index: 1;
}
.shape-label, .band-label {
  position: sticky;
  left: 16px;
  display: inline-block;
  max-width: min(340px, calc(100vw - 48px));
  margin: 70px 0 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: .88rem;
  font-weight: 600;
  line-height: 1.35;
}

/* fasce dei progetti nella barra dei 400 */
.band {
  top: 0;
  height: 100%;
  background: var(--band);
  border-left: 3px solid #fff;
  z-index: 1;
}
.band-label { margin-top: 70px; font-size: .95rem; }

/* segnaposto: "fin qui ..." */
.marker {
  top: 0;
  height: 100%;
  width: 0;
  border-left: 2px dashed rgba(255, 255, 255, .9);
  z-index: 2;
}
.marker span {
  position: absolute;
  bottom: 28px;
  left: 10px;
  width: max-content;
  max-width: min(320px, 70vw);
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  line-height: 1.3;
}
.marker.tick { border-left-style: solid; border-left-color: rgba(255,255,255,.35); }
.marker.tick span { background: transparent; padding: 0; bottom: 20px; font-weight: 500; opacity: .85; }
.marker.special span { background: var(--ink); color: var(--bg); font-size: .92rem; }
.marker.strong { border-left: 4px solid #fff; }
.marker.strong span { font-size: 1rem; padding: 10px 14px; bottom: 40px; }

/* morti di malaria vs ebola */
.deaths-row { display: flex; align-items: flex-end; gap: 28px; }
.deaths-row figure { width: auto; }
.deaths-row figcaption { color: #fff; max-width: 220px; font-weight: 600; }
.obj.deaths { background: #c92a2a; border: 1px solid rgba(255,255,255,.6); }

/* ---------- omini e bambini ---------- */
.people-card, .scroller-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(640px, calc(100vw - 48px));
}
.figure-free .scroller-card { padding: 16px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 16px);
  gap: 2px;
  justify-content: start;
}
.people-grid i {
  width: 16px; height: 32px;
  background: url(img/person.svg) center / contain no-repeat;
}
.scroller {
  position: relative;
  height: min(380px, calc(var(--bar-h) - 200px));
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line), inset 0 0 16px rgba(0,0,0,.08);
}
.scroller-inner { background-repeat: repeat; }
.scroller[data-icon="person"] .scroller-inner { background-image: url(img/person.svg); }
.scroller[data-icon="baby"] .scroller-inner { background-image: url(img/baby.svg); }
.scroller-badge {
  position: sticky;
  bottom: 12px;
  width: max-content;
  margin: 0 12px 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .people-grid i,
  :root:not([data-theme="light"]) .scroller-inner { filter: invert(1); }
}
:root[data-theme="dark"] .people-grid i,
:root[data-theme="dark"] .scroller-inner { filter: invert(1); }

/* ---------- E voi? ---------- */
.card.you { display: flex; flex-direction: column; gap: 10px; width: min(420px, calc(100vw - 48px)); }
.card.you label { font-weight: 600; }
.card.you input {
  font: inherit;
  font-size: 1.2rem;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  width: 100%;
}
.card.you input:focus { border-color: var(--accent); outline: none; }
.you-out { display: grid; grid-template-columns: 70px 1fr; gap: 14px; align-items: center; }
.you-out[hidden] { display: none; }
.you-sq-wrap { display: grid; place-items: center; min-height: 40px; }
.you-sq { background: var(--accent); }
.you-out p { margin: 0; }
.fine { font-size: .8rem; color: var(--muted); margin: 0; }
.live strong { font-variant-numeric: tabular-nums; color: var(--accent); }

/* ---------- fonti ---------- */
.sources-inner {
  width: min(760px, calc(100vw - 48px));
  max-height: calc(100dvh - var(--hud-h) - 48px);
  overflow: auto;
  padding: 28px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: .9rem;
}
.sources-inner h2 { margin: 0 0 8px; font-size: 1.6rem; }
.sources-inner ul { padding-left: 1.1em; }
.sources-inner li { margin-bottom: .5em; }
.credits { color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; margin-bottom: 0; }

/* ---------- barra di navigazione in basso ---------- */
.hud {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  height: var(--hud-h);
  padding: 8px max(16px, 2vw) 0;
  background: var(--hud-bg);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.hud-row { display: flex; align-items: center; gap: 10px; height: 32px; }
.step {
  flex: none;
  height: 32px;
  min-width: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
}
.step.next { background: var(--accent); border-color: var(--accent); color: #fff; }
.step:active { transform: scale(.96); }
.hud-chapters { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 0; }
.hud-chapters::-webkit-scrollbar { display: none; }
.hud-chapters button {
  flex: none;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
}
.hud-chapters button:hover { border-color: var(--ink); }
.hud-chapters button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.progress {
  position: relative;
  height: 22px;
  margin-top: 2px;
  cursor: pointer;
  touch-action: none;
}
.progress::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 9px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}
.progress-fill {
  position: absolute;
  left: 0; top: 9px;
  height: 4px;
  width: 0;
  border-radius: 2px;
  background: var(--accent);
}
.progress-thumb {
  position: absolute;
  top: 3px;
  left: 0;
  width: 16px; height: 16px;
  margin-left: -8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--hud-bg);
}
.progress-tick {
  position: absolute;
  top: 6px;
  width: 2px; height: 10px;
  background: var(--muted);
  opacity: .6;
}

/* ---------- telefono ---------- */
@media (max-width: 600px) {
  html, body { font-size: 16px; }
  .track { gap: 96px; padding-right: 20vw; padding-left: 16px; }
  .hud { padding: 6px 10px 0; }
  .hud-row { gap: 6px; }
  .hud-chapters button { padding: 4px 10px; }
  .bar-title { font-size: .92rem; padding: 6px 10px; margin-left: 8px; left: 8px; }
  .figure-row { gap: 24px; }
  .figure-row figure { width: 110px; }
  .card { padding: 16px 18px; }
  .card .big { font-size: 1.1rem; }
  .pie { width: 56px; height: 56px; }
  .card.head h3 { font-size: 1.1rem; }
}

/* telefono in orizzontale: la barra alta 560 px non ci sta */
.rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .rotate {
    display: block;
    position: fixed;
    top: 8px; left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--ink);
    color: var(--bg);
    font-size: .85rem;
    font-weight: 600;
    pointer-events: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hint { animation: none; }
}
