/* Finestrino
   Palette presa dalla cabina di un aereo:
   notte in quota, plastica del finestrino, la luce gialla "allacciare le cinture". */
:root {
  --night: #0E1B2C;
  --night-a: rgba(14, 27, 44, 0.84);
  --ink: #F4F6F8;
  --ink-2: #AEB9C6;
  --sign: #F2A900;
  --sign-ink: #1E1600;
  --cabin: #D9DDE1;
  --cabin-2: #C3C9CF;
  --cabin-3: #A3ABB4;
  --line: rgba(244, 246, 248, 0.14);

  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-4: clamp(2.75rem, 9vw, 5rem);

  --gap: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  font-family: 'B612', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); }
button, input { font: inherit; color: inherit; }
a { color: var(--sign); }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--sign); outline-offset: 2px; }

#globe { position: fixed; inset: 0; touch-action: none; }
.cesium-widget canvas { touch-action: none; }

/* I crediti di Cesium vivono nella finestra "Fonti dei dati" */
.cesium-viewer-bottom { display: none !important; }

/* ---------- Bottoni ---------- */
.primary, .ghost, .seg {
  white-space: nowrap;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: 11px 18px;
  min-height: 44px;
  font-size: var(--step-0);
  letter-spacing: 0.01em;
}
.primary { background: var(--sign); color: var(--sign-ink); font-weight: 700; }
.primary:hover { filter: brightness(1.06); }
.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.ghost:hover { box-shadow: inset 0 0 0 1px var(--ink-2); }
.wide { width: 100%; }

/* ---------- Intro ---------- */
.intro {
  position: fixed; inset: 0; z-index: 5;
  display: flex; align-items: flex-end;
  padding: calc(24px + var(--safe-t)) calc(24px + var(--safe-r)) calc(32px + var(--safe-b)) calc(24px + var(--safe-l));
  background: linear-gradient(to top, rgba(14,27,44,0.92) 0%, rgba(14,27,44,0.55) 45%, rgba(14,27,44,0) 75%);
}
.intro-inner { max-width: 34rem; }
.intro-title {
  margin: 0 0 0.3em;
  font-size: var(--step-4);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}
.intro-lede { margin: 0 0 1.5em; font-size: var(--step-1); color: var(--ink); max-width: 30ch; }
.intro-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.intro-msg { min-height: 1.4em; margin: 1em 0 0; color: var(--ink-2); font-size: var(--step--1); }

/* ---------- Barra in alto ---------- */
.topbar {
  position: fixed; z-index: 3;
  top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r));
  display: flex; align-items: center; gap: 10px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.wordmark {
  font-weight: 700; font-size: var(--step-0);
  background: var(--night-a); padding: 8px 14px; border-radius: 999px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.place {
  background: var(--night-a); border: 0; border-radius: 999px; padding: 8px 14px; cursor: pointer;
  max-width: 40vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.place:hover { box-shadow: inset 0 0 0 1px var(--ink-2); }
.weather {
  margin-left: auto; color: var(--ink);
  background: var(--night-a); padding: 8px 14px; border-radius: 999px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.weather:empty { display: none; }
.info {
  flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--night-a); color: var(--ink); font-weight: 700; font-size: 1rem;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.info:hover { box-shadow: inset 0 0 0 1px var(--ink-2); }
.info svg { display: block; margin: auto; }
.weather + .info { margin-left: 0; }
.weather:empty + .info { margin-left: auto; }

/* ---------- Stato e avvisi ---------- */
.status, .toast {
  position: fixed; z-index: 3; margin: 0;
  left: calc(12px + var(--safe-l));
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
  max-width: min(420px, calc(100vw - 24px));
}
.status { white-space: pre-line; top: calc(60px + var(--safe-t)); color: var(--ink); text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.toast {
  top: calc(96px + var(--safe-t));
  background: var(--sign); color: var(--sign-ink); padding: 8px 14px; border-radius: 10px; font-weight: 700;
}

/* ---------- Scheda ---------- */
.card {
  position: fixed; z-index: 4;
  left: calc(12px + var(--safe-l));
  bottom: calc(var(--controls-h, 56px) + 26px + var(--safe-b));
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100dvh - var(--controls-h, 56px) - 150px);
  overflow-y: auto;
  background: var(--night-a);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-radius: 18px;
  padding: 18px 18px 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.card-close {
  position: absolute; top: 8px; right: 8px;
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: transparent; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--ink-2);
}
.card-close:hover { color: var(--ink); }
.card-title { margin: 0; font-size: var(--step-1); font-weight: 700; padding-right: 36px; }
.card-sub { margin: 2px 0 12px; color: var(--ink-2); font-size: var(--step--1); }
.card-data {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 16px;
  margin: 0 0 14px; font-size: var(--step--1); font-variant-numeric: tabular-nums;
}
.card-data dt { color: var(--ink-2); }
.card-data dd { margin: 0; text-align: right; }
.card-actions { display: flex; gap: 8px; }
.card-actions .primary { flex: 1 1 auto; }
.card-actions .ghost { flex: none; }
.card-route { margin: -4px 0 12px; font-weight: 700; font-size: var(--step-0); }
.card-route:empty { display: none; }
.card-route.is-muted { font-weight: 400; color: var(--ink-2); font-size: var(--step--1); }
.muted { color: var(--ink-2); font-weight: 400; }
.seg.overhead { color: var(--sign); }
.sheet-h2 { margin-top: 22px !important; }
.passes li { padding: 10px 2px; }
.pass-when { margin: 0 0 2px !important; color: var(--ink) !important; font-size: var(--step-0) !important; font-weight: 700; }
.pass-when::first-letter { text-transform: uppercase; }
.pass-desc { margin: 0 0 8px !important; }
.pass-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ghost.small { min-height: 36px; padding: 6px 14px; font-size: var(--step--1); }
.hint { font-size: var(--step--1); color: var(--ink-2); margin: 10px 0 0 !important; }

/* ---------- Comandi ---------- */
.controls {
  position: fixed; z-index: 3;
  left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--safe-b));
  max-width: calc(100vw - 16px);
}
.group {
  display: flex; gap: 4px; align-items: center;
  background: var(--night-a);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 999px; padding: 4px;
}
.seg { background: transparent; color: var(--ink); padding: 9px 14px; min-height: 40px; }
.seg.is-on { background: var(--ink); color: var(--night); }
.group .primary { min-height: 40px; padding: 9px 16px; margin-left: 4px; }
.seg.sound { box-shadow: inset 0 0 0 1px var(--line); margin-left: 4px; }
.seg.share { box-shadow: inset 0 0 0 1px var(--line); }
.seg.sound.is-on { background: transparent; color: var(--sign); box-shadow: inset 0 0 0 1px var(--sign); }



/* ---------- Finestrino ---------- */
.window {
  position: fixed; inset: 0; z-index: 1;
  pointer-events: none;
  display: grid; place-items: center;
}
.window::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 46%, transparent 38%, rgba(40, 48, 58, 0.38) 100%);
}
.pane {
  position: relative;
  width: min(62vmin, 420px);
  height: min(86vmin, 590px);
  border-radius: 46% / 34%;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.25),
    inset 0 0 70px rgba(0, 0, 0, 0.45),
    0 0 0 16px var(--cabin-2),
    0 0 0 19px var(--cabin-3),
    0 0 0 34px var(--cabin),
    0 0 0 36px var(--cabin-2),
    0 0 0 200vmax var(--cabin);
}
.shade {
  position: absolute; left: 0; right: 0; top: 0; height: 13%;
  background: linear-gradient(#F1F3F5, #D3D8DD);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}
.shade::after {
  content: ''; position: absolute; left: 50%; bottom: 7px;
  width: 54px; height: 6px; margin-left: -27px; border-radius: 3px;
  background: var(--cabin-3);
}
/* Oblò del satellite: metallo scuro, rotondo */
.window.is-porthole { --cabin: #3B4653; --cabin-2: #56616E; --cabin-3: #262E37; }
.window.is-porthole .pane { border-radius: 50%; width: min(82vmin, 600px); height: min(82vmin, 600px); }
.window.is-porthole .shade { display: none; }

/* Quando sei a bordo, i pannelli si appoggiano alla parete della cabina */
body.riding .status { color: var(--night); text-shadow: none; font-weight: 700; }
body.riding.porthole .status { color: var(--ink); }

/* ---------- Finestre di dialogo ---------- */
.sheet {
  border: 0; padding: 0; border-radius: 18px;
  background: var(--night); color: var(--ink);
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 48px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.sheet::backdrop { background: rgba(5, 10, 18, 0.55); }
.sheet-form { padding: 22px; }
.sheet h2 { margin: 0 0 12px; font-size: var(--step-1); }
.sheet p { margin: 0 0 12px; color: var(--ink-2); font-size: var(--step--1); max-width: 60ch; }
.sheet input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 0;
  background: rgba(244,246,248,0.08); box-shadow: inset 0 0 0 1px var(--line);
}
.sheet input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--sign); }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.results { list-style: none; margin: 10px 0 0; padding: 0; max-height: 40dvh; overflow-y: auto; }
.results li + li { border-top: 1px solid var(--line); }
.results button {
  width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 12px 6px; border-radius: 8px;
}
.results button:hover { background: rgba(244,246,248,0.06); }
.results small { display: block; color: var(--ink-2); font-size: var(--step--1); }
.credits { margin: 0; padding-left: 1.1em; font-size: var(--step--1); }
.credits li { margin-bottom: 8px; }
.note { margin-top: 12px !important; }
.lang-switch { display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px; background: rgba(244,246,248,0.06); margin-bottom: 14px; }
.lang-switch .seg { min-height: 34px; padding: 6px 14px; font-size: var(--step--1); }
.intro-lang {
  position: absolute; top: calc(16px + var(--safe-t)); right: calc(16px + var(--safe-r));
  margin: 0; background: var(--night-a); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.credits-sub { margin: 18px 0 8px; font-size: var(--step-0); }
.cesium-credits { font-size: 11px; color: var(--ink-2); line-height: 1.6; }
.cesium-credits a { color: var(--ink-2); }
.cesium-credits .cesium-credit-logoContainer { display: block; margin-bottom: 6px; }

/* ---------- Schermi piccoli (telefono) ---------- */
@media (max-width: 560px) {
  .wordmark { display: none; }
  .place { max-width: none; flex: 1 1 auto; min-width: 0; padding: 8px 12px; }
  .weather { margin-left: 0; padding: 8px 12px; }
  .status { font-size: 12px; top: calc(56px + var(--safe-t)); right: 12px; max-width: none; }
  .toast { top: calc(110px + var(--safe-t)); right: 12px; max-width: none; }
  .card { left: 50%; transform: translateX(-50%); padding: 14px 16px 14px; }
  .card-data { margin-bottom: 10px; }

  /* Comandi: tutta la larghezza; a bordo vanno su due righe */
  .controls { left: 8px; right: 8px; transform: none; max-width: none; display: flex; justify-content: center; bottom: calc(10px + var(--safe-b)); }
  .group { flex-wrap: wrap; justify-content: center; border-radius: 24px; gap: 4px; }
  .seg { padding: 8px 12px; font-size: 15px; min-height: 40px; }
  #ride-controls { width: 100%; }
  #ride-controls .seg[data-view] { flex: 1 1 28%; }
  #ride-controls .sound, #ride-controls .share, #ride-controls .primary { flex: 1 1 28%; margin-left: 0; }
  .group .primary { font-size: 15px; }

  .pane { width: min(70vw, 420px); height: min(62dvh, 560px); }
  .window.is-porthole .pane { width: min(86vw, 520px); height: min(86vw, 520px); }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
