:root {
  --bg: #03040a;
  --panel: rgba(10, 14, 28, 0.62);
  --panel-border: rgba(140, 180, 255, 0.14);
  --text: #e8ecf8;
  --muted: #8d97b5;
  --dim: #5d6683;
  --accent: #7fe3ff;
  --accent-2: #ffb35c;
  --good: #9cf2c3;
  --radius: 18px;
  --font: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
body { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; outline: none; }
#labels { position: fixed; inset: 0; pointer-events: none; }
#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .35s ease; z-index: 5; }
#fade.on { opacity: 1; }

/* ── Etichette 3D ─────────────────────────────────────────── */
.space-label {
  font-size: 11px; letter-spacing: .04em; color: rgba(220, 230, 255, .78);
  white-space: nowrap; padding: 2px 6px; margin-left: 10px;
  text-shadow: 0 0 6px #000, 0 0 2px #000; pointer-events: none; user-select: none;
}
.lbl-sun { color: #ffd59a; font-weight: 600; font-size: 12px; }
.lbl-planet { color: rgba(230, 236, 255, .85); }
.lbl-region { color: rgba(150, 175, 230, .6); font-size: 10px; text-transform: uppercase; letter-spacing: .18em; }
.lbl-arm { color: rgba(170, 190, 255, .45); font-size: 11px; text-transform: uppercase; letter-spacing: .3em; }
.lbl-grid { color: rgba(110, 140, 200, .55); font-size: 10px; font-family: var(--mono); margin-left: 4px; }
.lbl-grid.gc { color: rgba(255, 200, 140, .6); letter-spacing: .1em; }
.lbl-probe { color: #ffe9a8; font-size: 10px; }
.lbl-ghost { color: rgba(127, 190, 255, .75); font-size: 10px; font-style: italic; }
.clickable { pointer-events: auto; cursor: pointer; border-radius: 6px; transition: background .2s, color .2s; }
.clickable:hover { background: rgba(127, 227, 255, .15); color: #fff; }
.lbl-star { pointer-events: auto; cursor: pointer; border-radius: 6px; transition: background .2s, color .2s; }
.lbl-star:hover { background: rgba(127, 227, 255, .15); color: #fff; }
.lbl-star.reached { color: var(--good); }
.lbl-star.reached::before { content: '✓ '; opacity: .7; }
.lbl-star.lbl-gift { color: #ffd27a; font-weight: 700; letter-spacing: .12em; text-shadow: 0 0 10px rgba(255, 200, 100, .7); }
.lbl-star.target { color: var(--accent-2); font-weight: 600; }
.lbl-zone { color: #bff1ff; font-size: 11px; letter-spacing: .08em; border: 1px solid rgba(127, 227, 255, .45); background: rgba(8, 30, 48, .55); border-radius: 999px; padding: 3px 10px; transform: translateX(-50%); margin-left: 0; }
.traveler-label {
  color: #04121a; background: var(--accent); font-weight: 700; font-size: 11px; letter-spacing: .12em;
  border-radius: 999px; padding: 3px 9px; margin-left: 16px; box-shadow: 0 0 18px rgba(127, 227, 255, .6);
}

/* ── Barra superiore ──────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 14px 20px; background: linear-gradient(to bottom, rgba(3, 4, 10, .85), rgba(3, 4, 10, 0));
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; margin-right: auto; }
.brand-mark { width: 30px; height: 30px; border-radius: 50%; position: relative;
  background: radial-gradient(circle, #fff6d8 0 18%, #ffb347 30%, rgba(255, 106, 0, 0) 52%); }
.brand-mark::after { content: ''; position: absolute; inset: 3px -4px; border: 1.5px solid var(--accent); border-radius: 50%; transform: rotate(-25deg) scaleY(.38); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-weight: 600; font-size: 16px; letter-spacing: .01em; }
.brand-text small { color: var(--muted); font-family: var(--mono); font-size: 10px; letter-spacing: .14em; }

.views { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: rgba(10, 14, 28, .6); border: 1px solid var(--panel-border); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.views button { border: 0; background: none; padding: 7px 14px; border-radius: 999px; color: var(--muted); cursor: pointer; font-size: 13px; transition: color .2s, background .2s; }
.views button:hover { color: var(--text); }
.views button.active { background: rgba(127, 227, 255, .14); color: var(--accent); box-shadow: inset 0 0 0 1px rgba(127, 227, 255, .3); }

.ghost-btn { border: 1px solid var(--panel-border); background: rgba(10, 14, 28, .5); padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 13px; color: var(--text); transition: border-color .2s, background .2s; }
.ghost-btn:hover { border-color: rgba(127, 227, 255, .5); background: rgba(127, 227, 255, .08); }
.primary-btn { border: 0; cursor: pointer; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; color: #04121a;
  background: linear-gradient(135deg, #a5f0ff, #5fc8ff); box-shadow: 0 6px 24px rgba(95, 200, 255, .25); transition: transform .15s, box-shadow .2s; }
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 30px rgba(95, 200, 255, .4); }
.primary-btn.on { background: linear-gradient(135deg, #ffd08a, #ff9e4a); }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 4px; font-size: 14px; }
.link-btn:hover { color: var(--text); }

/* ── Pannelli ─────────────────────────────────────────────── */
.hud { position: fixed; inset: 72px 20px 44px; pointer-events: none; display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; z-index: 6; }
.panel {
  pointer-events: auto; background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .04);
  max-height: 100%; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(127, 227, 255, .2) transparent;
}
.controls { width: 330px; padding: 20px; }
.results { width: 380px; padding: 22px; }
.panel h2 { margin: 0 0 18px; font-size: 15px; font-weight: 600; letter-spacing: .02em; display: flex; align-items: center; gap: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.field { margin-bottom: 18px; }
.field > label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin-bottom: 8px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
input[type=date], input[type=time], input[type=number], select {
  width: 100%; background: rgba(255, 255, 255, .04); border: 1px solid rgba(140, 180, 255, .18); border-radius: 10px;
  padding: 9px 11px; font-size: 14px; outline: none; transition: border-color .2s, background .2s;
}
input[type=number] { font-family: var(--mono); }
input:focus, select:focus { border-color: var(--accent); background: rgba(127, 227, 255, .06); }
select option, select optgroup { background: #0b0f1e; }
input[type=time] { flex: 0 0 124px; }
::-webkit-calendar-picker-indicator { filter: invert(.8); cursor: pointer; }
.help { margin: 6px 0 0; font-size: 12px; color: var(--dim); }

input[type=range] { width: 100%; margin: 14px 0 6px; -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, #3a4a7a, #7fe3ff var(--p, 50%), rgba(255, 255, 255, .08) var(--p, 50%)); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(127, 227, 255, .3), 0 0 16px rgba(127, 227, 255, .7); cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(127, 227, 255, .3), 0 0 16px rgba(127, 227, 255, .7); cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { border: 1px solid rgba(140, 180, 255, .16); background: rgba(255, 255, 255, .03); border-radius: 999px; padding: 5px 10px; font-size: 12px; cursor: pointer; color: var(--muted); transition: all .15s; }
.chip:hover { color: var(--text); border-color: rgba(127, 227, 255, .4); }
.chip.active { color: #04121a; background: var(--accent); border-color: var(--accent); }
.speed-note { margin: 10px 0 0; font-size: 12px; color: var(--muted); min-height: 1em; line-height: 1.45; }
.speed-note .warn { color: var(--accent-2); }

.actions { display: flex; gap: 8px; }
.actions .primary-btn { flex: 1; }

/* ── Risultati ────────────────────────────────────────────── */
.kicker { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .18em; color: var(--muted); }
.big { font-size: 26px; font-weight: 600; margin-top: 8px; line-height: 1.15; white-space: nowrap;
  background: linear-gradient(90deg, #fff, #a5f0ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.unit { color: var(--muted); font-size: 13px; margin-top: 2px; }
.alt-units { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--accent); }
.alt-units span:empty { display: none; }
.where { margin: 16px 0 0; font-size: 14px; line-height: 1.55; color: #c8d0e8; }
.where b { color: #fff; font-weight: 600; }

.progress { margin-top: 14px; display: flex; align-items: center; gap: 10px; }
.progress .bar { flex: 1; height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .07); overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #5fc8ff, #ffb35c); border-radius: 6px; box-shadow: 0 0 12px rgba(255, 179, 92, .5); transition: width .4s; }
.progress span { font-size: 12px; color: var(--muted); min-width: 52px; text-align: right; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.stat { margin: 0; background: rgba(255, 255, 255, .03); border: 1px solid rgba(140, 180, 255, .1); border-radius: 12px; padding: 10px 12px; }
.stat.wide { grid-column: span 2; }
.stat dt { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--dim); }
.stat dd { margin: 5px 0 0; font-size: 14px; font-weight: 500; line-height: 1.3; }
.stat small { display: block; margin-top: 3px; color: var(--muted); font-size: 11.5px; font-weight: 400; line-height: 1.35; }

.results h3 { margin: 22px 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .18em; color: var(--muted); font-weight: 500; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; position: relative; }
.timeline::before { content: ''; position: absolute; left: 13px; top: 8px; bottom: 8px; width: 1px; background: linear-gradient(to bottom, rgba(127, 227, 255, .4), rgba(140, 180, 255, .08)); }
.timeline li { display: grid; grid-template-columns: 20px 1fr; gap: 10px; padding: 6px 0; font-size: 13px; position: relative; }
.timeline .ic { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; background: #0b1020; border: 1px solid rgba(140, 180, 255, .25); color: var(--muted); z-index: 1; }
.timeline .passed .ic { border-color: rgba(156, 242, 195, .5); color: var(--good); }
.timeline .next .ic { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 10px rgba(127, 227, 255, .5); }
.timeline .dest .ic { border-color: var(--accent-2); color: var(--accent-2); }
.timeline .name { color: #c8d0e8; }
.timeline .passed .name { color: #e8ecf8; }
.timeline .future .name { color: var(--muted); }
.timeline .when { display: block; font-family: var(--mono); font-size: 11px; color: var(--dim); margin-top: 1px; }
.timeline .next .when { color: var(--accent); }
.timeline .more { color: var(--dim); font-size: 12px; cursor: pointer; }
.timeline .more:hover { color: var(--text); }

/* ── Navigazione 3D ───────────────────────────────────────── */
.space-label.hover { background: rgba(127, 227, 255, .15); color: #fff; }
.navctl { position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%); z-index: 7; display: flex; gap: 2px; padding: 4px;
  border-radius: 999px; background: rgba(10, 14, 28, .6); border: 1px solid var(--panel-border); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.navctl button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: none; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; transition: color .2s, background .2s; }
.navctl button:hover { color: var(--text); background: rgba(127, 227, 255, .1); }
.navctl button:focus-visible, .focus-back:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.navctl #homeBtn { font-size: 17px; }
.focusbar { position: fixed; left: 50%; top: 74px; transform: translateX(-50%); z-index: 9; display: flex; align-items: center; gap: 10px;
  padding: 5px 5px 5px 14px; border-radius: 999px; font-size: 13px; color: var(--muted); white-space: nowrap;
  background: rgba(10, 14, 28, .72); border: 1px solid rgba(127, 227, 255, .3); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  animation: focusIn .3s ease; }
.focusbar[hidden] { display: none; }
.focusbar b { color: var(--text); font-weight: 600; }
.focus-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.focus-back { border: 0; border-radius: 999px; padding: 6px 12px; background: rgba(127, 227, 255, .14); color: var(--accent); cursor: pointer; font-size: 13px; }
.focus-back:hover { background: rgba(127, 227, 255, .24); }
.focus-back kbd { font-family: var(--mono); font-size: 10px; padding: 1px 5px; margin-left: 4px; border-radius: 4px; border: 1px solid rgba(127, 227, 255, .35); color: var(--muted); }
@keyframes focusIn { from { opacity: 0; transform: translate(-50%, -6px); } }
body.intro-open .navctl, body.intro-open .focusbar { opacity: 0; pointer-events: none; }

.hint { position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0; font-size: 11px; color: var(--dim); letter-spacing: .06em; z-index: 6; pointer-events: none; white-space: nowrap; }

/* ── Intro ────────────────────────────────────────────────── */
.intro { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(ellipse at center, rgba(3, 4, 10, .25), rgba(3, 4, 10, .85) 75%); transition: opacity .9s ease, visibility .9s; }
.intro.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-inner { max-width: 760px; text-align: center; }
.eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: .3em; text-transform: uppercase; color: var(--accent); margin: 0 0 18px; }
.intro h1 { font-size: clamp(32px, 5.6vw, 64px); line-height: 1.04; margin: 0; font-weight: 600; letter-spacing: -.02em; }
.intro h1 em { font-style: normal; background: linear-gradient(90deg, #ffd59a, #ff9e4a 40%, #7fe3ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { color: #b6bfdc; font-size: clamp(15px, 1.6vw, 18px); line-height: 1.55; max-width: 560px; margin: 22px auto 30px; }
.intro-form { display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.intro-form label { color: var(--muted); font-size: 15px; }
.intro-form input { width: auto; font-size: 16px; padding: 12px 14px; }
.big-btn { padding: 13px 20px; font-size: 15px; }
#skipIntro { margin-top: 22px; }

body.intro-open .hud, body.intro-open #labels, body.intro-open .views, body.intro-open .hint, body.intro-open #aboutBtn { opacity: 0; pointer-events: none; }
.hud, #labels, .views, .hint, #aboutBtn { transition: opacity .8s ease; }

/* ── Dialog ───────────────────────────────────────────────── */
dialog { border: 1px solid var(--panel-border); border-radius: var(--radius); background: rgba(8, 11, 24, .92); color: var(--text); max-width: 620px; width: calc(100% - 32px); padding: 0; backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.about-inner { padding: 26px 28px; }
.about-inner h2 { margin: 0 0 12px; }
.about-inner h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .16em; color: var(--accent); margin: 20px 0 8px; }
.about-inner p, .about-inner li { color: #c8d0e8; line-height: 1.6; font-size: 14px; }
.about-inner ul { padding-left: 18px; margin: 0; }
.about-inner li { margin-bottom: 6px; }
.about-inner .primary-btn { margin-top: 18px; }

.toast { position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 20px); background: rgba(10, 14, 28, .9); border: 1px solid var(--panel-border); padding: 10px 16px; border-radius: 999px; font-size: 13px; opacity: 0; transition: all .3s; z-index: 30; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; background: var(--bg); }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1080px) {
  .controls { width: 300px; }
  .results { width: 340px; }
  .brand-text small { display: none; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; padding: 12px 16px; gap: 10px; }
  .views { order: 3; width: 100%; justify-content: space-between; }
  .views button { flex: 1; padding: 7px 6px; font-size: 12px; }
  .hud { position: relative; inset: auto; display: block; padding: 58vh 16px 40px; pointer-events: none; }
  .panel { max-height: none; width: 100%; margin-bottom: 14px; }
  .controls, .results { width: 100%; }
  .hint { display: none; }
  .space-label { font-size: 10px; }
  .navctl { position: absolute; bottom: auto; top: calc(58vh - 62px); left: auto; right: 16px; transform: none; }
  .focusbar { top: 112px; }
  .focus-back kbd { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
@media (max-width: 560px) { .intro h1 br { display: none; } }
