/* =============================================================================
   Cosmografia — stile. Tema unico scuro (scelta deliberata: lo spazio è nero).
   Token: vuoto blu-nero, inchiostro "carta stellare", accento luce solare G2V.
   ============================================================================= */
:root {
  --void: #04050a;
  --panel: rgba(10, 12, 20, 0.8);
  --panel-solid: #0b0d16;
  --raise: rgba(236, 232, 222, 0.06);
  --ink: #ece8de;
  --ink-2: #bdb9ae;
  --muted: #8b8fa2;
  --line: rgba(236, 232, 222, 0.13);
  --accent: #f3c06b;
  --accent-ink: #1a1204;
  --c-mis: #78d2b4;
  --c-mod: #8db6f2;
  --c-sti: #e9c46a;
  --c-ipo: #d98cd9;
  --c-ill: #a8a8b4;
  --f-display: 'Spectral', 'Iowan Old Style', Georgia, serif;
  --f-body: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --f-mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --r: 10px;
  --gap: 16px;
  color-scheme: dark;
}

html, body { height: 100%; margin: 0; background: var(--void); color: var(--ink); font-family: var(--f-body); font-size: 14px; overflow: hidden; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
a { color: var(--c-mod); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#scene { position: fixed; inset: 0; display: block; touch-action: none; cursor: grab; }
#scene:active { cursor: grabbing; }

/* --- Etichette ------------------------------------------------------------- */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.lbl {
  position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 11.5px; line-height: 18px; letter-spacing: 0.01em;
  color: var(--ink-2); text-shadow: 0 0 3px #000, 0 0 8px #000; will-change: transform;
}
.lbl.r1 { color: var(--ink); font-size: 12.5px; font-weight: 500; }
.lbl.r3 { color: var(--muted); font-size: 10.5px; }
.lbl.hyp { color: var(--c-ipo); font-style: italic; }
.lbl.sel { color: var(--accent); }
#sel-ring {
  position: fixed; left: 0; top: 0; border-radius: 50%; pointer-events: none; display: none;
  border: 1px solid rgba(243, 192, 107, 0.85); box-shadow: 0 0 0 3px rgba(243, 192, 107, 0.08);
}

/* --- Barra superiore --------------------------------------------------------- */
.topbar {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 14px); left: 18px; right: 18px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--gap); pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: grid; gap: 6px; min-width: 0; }
.wordmark { font-family: var(--f-display); font-style: italic; font-weight: 500; font-size: 26px; line-height: 1; letter-spacing: -0.01em; margin: 0; }
.wordmark span { font-style: normal; font-weight: 300; color: var(--muted); font-size: 15px; margin-left: 8px; letter-spacing: 0.02em; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; font-size: 12px; color: var(--muted); }
.crumbs button { background: none; border: 0; padding: 3px 6px; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.crumbs button:hover { background: var(--raise); color: var(--ink); }
.crumbs button[aria-current="true"] { color: var(--accent); cursor: default; }
.crumbs .sep { color: var(--line); user-select: none; }

.tools { display: flex; gap: 8px; align-items: flex-start; }
.search { position: relative; }
.search input {
  width: 230px; height: 36px; padding: 0 12px 0 34px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); outline: none;
}
.search input:focus { border-color: rgba(243, 192, 107, 0.6); }
.search svg { position: absolute; left: 11px; top: 10px; width: 16px; height: 16px; stroke: var(--muted); fill: none; stroke-width: 2; pointer-events: none; }
.results {
  position: absolute; right: 0; top: 42px; width: 300px; max-height: 60vh; overflow-y: auto; padding: 6px;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.results button { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%; text-align: left; background: none; border: 0; padding: 7px 9px; border-radius: 7px; cursor: pointer; }
.results button:hover, .results button.on { background: var(--raise); }
.results .n { color: var(--ink); }
.results .t { grid-column: 1 / 2; font-size: 11.5px; color: var(--muted); }
.results .l { grid-row: 1 / 3; grid-column: 2; align-self: center; font-size: 10.5px; color: var(--muted); font-family: var(--f-mono); }
.results .empty { padding: 10px; color: var(--muted); font-size: 12px; }

.iconbtn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); cursor: pointer; color: var(--ink-2);
}
.iconbtn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.iconbtn:hover { color: var(--ink); border-color: rgba(236, 232, 222, 0.3); }
.iconbtn[aria-pressed="true"] { color: var(--accent); border-color: rgba(243, 192, 107, 0.5); }

/* --- Righello di scala ---------------------------------------------------------- */
.scale {
  position: fixed; left: 18px; top: 50%; transform: translateY(-50%); height: min(56vh, 460px); width: 150px;
  display: grid; grid-template-columns: 14px 1fr; gap: 10px; pointer-events: none;
}
.scale .bar { position: relative; border-left: 1px solid var(--line); }
.scale .tick { position: absolute; left: -4px; width: 7px; border-top: 1px solid var(--line); }
.scale .tick.major { width: 12px; border-color: rgba(236, 232, 222, 0.3); }
.scale .now { position: absolute; left: -6px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px rgba(243, 192, 107, 0.7); transform: translateY(-50%); transition: top 0.12s linear; }
.scale .anchors { position: relative; }
.scale .anchor {
  position: absolute; left: 0; transform: translateY(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; background: none; border: 0;
  padding: 2px 4px; border-radius: 5px; cursor: pointer; pointer-events: auto; text-align: left;
}
.scale .anchor:hover { color: var(--ink); background: var(--raise); }
.readout {
  position: fixed; left: 18px; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); display: grid; gap: 2px; pointer-events: none;
  font-family: var(--f-mono); font-size: 11.5px; color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.readout b { font-weight: 500; color: var(--ink); }
.readout .hint { font-family: var(--f-body); color: var(--muted); font-size: 11.5px; margin-top: 6px; max-width: 330px; }
.gpu { color: var(--muted); }

/* --- Pannello informativo ------------------------------------------------------- */
.info {
  position: fixed; right: 18px; top: calc(env(safe-area-inset-top, 0px) + 66px); bottom: calc(env(safe-area-inset-bottom, 0px) + 18px); width: min(390px, calc(100vw - 36px));
  background: var(--panel); backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(0); transition: transform 0.28s cubic-bezier(.2,.8,.2,1), opacity 0.2s;
}
.info[hidden] { display: flex !important; transform: translateX(calc(100% + 30px)); opacity: 0; pointer-events: none; }
.info header { padding: 18px 20px 14px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.info .eyebrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding-right: 34px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; padding: 3px 8px 3px 7px; border-radius: 999px; border: 1px solid currentColor; }
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.mis { color: var(--c-mis); } .chip.mod { color: var(--c-mod); } .chip.sti { color: var(--c-sti); } .chip.ipo { color: var(--c-ipo); } .chip.ill { color: var(--c-ill); }
.info h2 { font-family: var(--f-display); font-weight: 500; font-size: 28px; line-height: 1.1; margin: 0; text-wrap: balance; }
.info .close { position: absolute; right: 12px; top: 12px; width: 32px; height: 32px; }
.info .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { height: 32px; padding: 0 13px; border-radius: 16px; border: 1px solid var(--line); background: var(--raise); cursor: pointer; font-size: 12.5px; }
.btn:hover { border-color: rgba(236, 232, 222, 0.35); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; }
.info .body { overflow-y: auto; padding: 16px 20px 22px; display: grid; gap: 18px; align-content: start; }
.facts { display: grid; grid-template-columns: minmax(110px, 42%) 1fr; margin: 0; border-top: 1px solid var(--line); }
.facts dt, .facts dd { margin: 0; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.facts dt { color: var(--muted); padding-right: 10px; }
.facts dd { font-family: var(--f-mono); font-size: 12px; color: var(--ink); font-variant-numeric: tabular-nums; }
.facts .live { color: var(--accent); }
.prose { font-size: 13.5px; line-height: 1.62; color: var(--ink-2); margin: 0; max-width: 65ch; }
.sec h3 { margin: 0 0 6px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.claude { font-family: var(--f-display); font-style: italic; font-size: 16px; line-height: 1.5; color: var(--ink); margin: 0; }
.claude-sig { margin-top: 6px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.sources { margin: 0; padding-left: 16px; display: grid; gap: 6px; font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.sources a { color: var(--c-mod); text-decoration: none; border-bottom: 1px solid rgba(141, 182, 242, 0.3); }

/* --- Barra del tempo ------------------------------------------------------------ */
.timebar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  display: flex; align-items: center; gap: 6px; padding: 5px; border-radius: 22px; border: 1px solid var(--line);
  background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); max-width: calc(100vw - 36px); overflow-x: auto;
}
.timebar .date { font-family: var(--f-mono); font-size: 12px; padding: 0 10px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.timebar button { height: 30px; min-width: 30px; padding: 0 10px; border-radius: 15px; border: 0; background: none; cursor: pointer; color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.timebar button:hover { background: var(--raise); color: var(--ink); }
.timebar button[aria-pressed="true"] { background: var(--ink); color: var(--void); }
.timebar svg { width: 14px; height: 14px; fill: currentColor; }

/* --- Viaggio tra le scale ---------------------------------------------------------- */
.iconbtn.home { color: #8fc4ff; border-color: rgba(143, 196, 255, 0.45); }
.iconbtn.home:hover { color: #cfe4ff; border-color: rgba(143, 196, 255, 0.8); }
.inside { display: flex; flex-wrap: wrap; gap: 6px; }
.go-chip {
  height: 28px; padding: 0 11px; border-radius: 14px; border: 1px solid var(--line); background: var(--raise);
  font-size: 12px; cursor: pointer; color: var(--ink); display: inline-flex; align-items: center; gap: 6px;
}
.go-chip::after { content: '›'; color: var(--accent); }
.go-chip:hover { border-color: rgba(243, 192, 107, 0.6); }
.portal-hint {
  position: fixed; left: 0; top: 0; pointer-events: none; font-size: 11.5px; color: var(--accent);
  padding: 3px 9px; border-radius: 11px; background: rgba(10, 12, 20, 0.7); border: 1px solid rgba(243, 192, 107, 0.35); white-space: nowrap;
}
.tripbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 64px);
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; border-radius: 20px; max-width: calc(100vw - 32px);
  background: var(--panel-solid); border: 1px solid rgba(243, 192, 107, 0.4); font-size: 12.5px; color: var(--ink);
}
.tripbar #trip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tripbar button { height: 28px; padding: 0 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--raise); cursor: pointer; font-size: 12px; white-space: nowrap; }
.tripbar button:first-of-type { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tripbar .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; flex: none; }
@keyframes pulse { 50% { opacity: 0.25; } }
#scene.dip { animation: dip 0.35s ease-out; }
@keyframes dip { from { opacity: 0.35; } to { opacity: 1; } }

/* --- Dissolvenza, toast, intro --------------------------------------------------- */
#fade { position: fixed; inset: 0; background: var(--void); opacity: 0; pointer-events: none; transition: opacity 0.16s ease; display: grid; place-items: center; }
#fade.on { opacity: 1; }
#fade p { font-family: var(--f-display); font-style: italic; font-size: 20px; color: var(--ink-2); margin: 0; }
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 84px); transform: translateX(-50%); padding: 8px 16px; border-radius: 18px;
  background: var(--panel-solid); border: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); pointer-events: none; transition: opacity 0.4s; white-space: nowrap;
}
.toast b { color: var(--ink); font-weight: 500; }
.intro { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at center, rgba(4, 5, 10, 0.55), rgba(4, 5, 10, 0.92)); }
.intro .card { width: min(720px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 18px; padding: clamp(20px, 4vw, 38px); display: grid; gap: 20px; }
.intro h1 { font-family: var(--f-display); font-weight: 400; font-size: clamp(30px, 5vw, 46px); line-height: 1.05; margin: 0; text-wrap: balance; }
.intro h1 em { color: var(--accent); }
.intro .lead { font-size: 15px; line-height: 1.6; color: var(--ink-2); margin: 0; max-width: 62ch; }
.principles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px 22px; margin: 0; padding: 0; list-style: none; }
.principles li { font-size: 13px; line-height: 1.5; color: var(--ink-2); }
.principles b { display: block; color: var(--ink); font-weight: 500; margin-bottom: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; }
.intro .go { display: flex; flex-wrap: wrap; gap: 10px; }
.intro .go .btn { height: 40px; padding: 0 18px; border-radius: 20px; font-size: 14px; }
.intro .foot { font-size: 11.5px; color: var(--muted); line-height: 1.5; }

/* --- Schermi stretti ----------------------------------------------------------- */
@media (max-width: 820px) {
  .scale { display: none; }
  .wordmark { font-size: 21px; }
  .wordmark span { display: none; }
  .search input { width: 150px; }
  .results { width: min(300px, calc(100vw - 36px)); }
  .readout .hint { display: none; }
  .info { top: auto; left: 16px; right: 16px; width: auto; max-height: 58vh; bottom: calc(env(safe-area-inset-bottom, 0px) + 64px); }
  .info[hidden] { transform: translateY(calc(100% + 80px)); }
  .readout { bottom: calc(env(safe-area-inset-bottom, 0px) + 64px); }
}
@media (max-width: 520px) {
  .topbar { flex-direction: column; left: 16px; right: 16px; }
  .tools { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .crumbs { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  #scene.dip, .tripbar .pulse { animation: none; }
  .info, #fade, .toast, .scale .now { transition: none; }
}
