/* Plancia 3D del Naval Route Simulator — veste di www.fictilis.it.
   Layout: scena 3D a tutta pagina; barra compatta in alto (logo, titolo, comandi), strumenti di plancia a destra
   (foglio in basso sul telefono), linea del tempo in basso. Interfaccia con i colori del sito (bone, grafite,
   rame per il pulsante principale); i colori dei DATI (vettori, rotte, corrente) restano quelli del modello.
   «Vista notte» scurisce scena e pannelli come un ECDIS di notte. Nessuno stile in linea: CSP 'self'. */
:root {
  --bg: #F6F4F0; --panel: rgba(252, 251, 249, .93); --panel-solid: #FCFBF9; --line: #DDD7CC; --fg: #1D2026;
  --body: #333844; --muted: #6B7078; --brand-btn: #A44C24; --brand-ink: #FCFBF9; --focus: #BE5E30;
  --sea0: #E4E9EC;
  /* dati */
  --b0: #4b5563; --s3: #c2410c; --stw: #1d4ed8; --cur: #047857; --sog: #a16207; --wind: #0e7490; --swell: #b45309;
  --f-ui: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --f-display: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --f-num: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, Menlo, monospace;
  --r: 999px; --rp: 14px;
  color-scheme: light;
}
:root[data-notte="1"] {
  --bg: #0B0D11; --panel: rgba(20, 22, 27, .9); --panel-solid: #14161B; --line: #2A2E37; --fg: #F6F4F0;
  --body: #D8D6D1; --muted: #9A9893; --sea0: #0b1b26;
  --b0: #9aa7b1; --s3: #ff6a3d; --stw: #6aa2ff; --cur: #3ddc97; --sog: #ffd166; --wind: #5ed3f3; --swell: #ffa94d;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 400 14px/1.4 var(--f-ui); overflow: hidden; -webkit-font-smoothing: antialiased; }
#app { position: relative; height: 100%; width: 100%; }
.scena { position: absolute; inset: 0; }
.scena:focus { outline: none; }
#scene { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.bar { position: absolute; top: 0; left: 0; right: 0; display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center;
  padding-block: calc(10px + env(safe-area-inset-top, 0px)) 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: linear-gradient(var(--panel) 70%, transparent); pointer-events: none; z-index: 1; }
.bar > * { pointer-events: auto; }
.logo img { display: block; height: 22px; width: auto; }
:root[data-notte="1"] .logo img { filter: invert(1) hue-rotate(180deg) brightness(1.4); }
.brand { display: flex; flex-direction: column; line-height: 1.1; margin-right: 4px; min-width: 0; }
.brand h1 { margin: 0; font: 600 18px var(--f-display); letter-spacing: -.01em; }
.brand span { font-size: 11.5px; color: var(--muted); letter-spacing: .04em; }
.badge { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: #5b4428;
  background: #fffaf1; border: 1px solid #ecdcbf; border-radius: var(--r); padding: 3px 9px; }
.group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.group.end { margin-left: auto; }
.lab { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--panel-solid); }
.seg button { font: 600 12.5px var(--f-ui); color: var(--muted); background: transparent; border: 0; padding: 6px 12px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.chk { display: inline-flex; gap: 5px; align-items: center; font-size: 12.5px; color: var(--fg); padding: 4px 9px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--panel-solid); cursor: pointer; }
.chk input { accent-color: var(--brand-btn); margin: 0; }
.btn { font: 600 12.5px var(--f-ui); border: 1px solid var(--line); background: var(--panel-solid); color: var(--fg);
  border-radius: var(--r); padding: 6px 13px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand-btn); border-color: var(--brand-btn); color: var(--brand-ink); min-width: 92px; }
.btn[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }

.hud { position: absolute; right: max(12px, env(safe-area-inset-right, 0px)); top: 128px; width: 304px; max-height: calc(100% - 222px);
  overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--rp); padding: 14px 16px;
  backdrop-filter: blur(6px); display: grid; gap: 13px; box-shadow: 0 10px 32px -14px rgba(20, 22, 27, .18); }
.hud h2 { font: 600 10.5px var(--f-ui); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 4px; }
.clock { font: 600 20px var(--f-num); letter-spacing: .01em; }
.sub { font: 400 12px var(--f-num); color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 12px; }
.ro { display: flex; flex-direction: column; min-width: 0; }
.ro .k { font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ro .v { font: 600 15.5px var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--fg); }
.ro .v small { font-weight: 400; font-size: 11px; color: var(--muted); }
.sw { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.sw.stw { background: var(--stw); } .sw.sog { background: var(--sog); } .sw.cur { background: var(--cur); }
.sw.wind { background: var(--wind); } .sw.swell { background: var(--swell); } .sw.s3 { background: var(--s3); }
.sw.b0 { background: var(--b0); } .sw.calm { background: var(--muted); }
.sw.dash { background: repeating-linear-gradient(90deg, var(--b0) 0 4px, transparent 4px 7px); }
.bars { display: grid; gap: 5px; }
.barrow { display: grid; grid-template-columns: 78px 1fr 58px; gap: 6px; align-items: center; font-size: 12px; }
.barrow .track { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.barrow .fill { display: block; height: 100%; border-radius: 4px; }
.barrow .fill.calm { background: var(--muted); } .barrow .fill.swell { background: var(--swell); } .barrow .fill.wind { background: var(--wind); }
.barrow .num { font: 400 12px var(--f-num); text-align: right; }
.race { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 8px; font-size: 12.5px; align-items: center; }
.race .num { font: 600 13px var(--f-num); text-align: right; }
.kpi { display: grid; gap: 5px; border-top: 1px solid var(--line); padding-top: 11px; }
.kpi .big { font: 600 26px var(--f-display); color: var(--fg); line-height: 1.1; }
.kpi .big small { font: 500 13px var(--f-ui); color: var(--muted); margin-left: 6px; }
.kpi p { margin: 0; font-size: 13px; color: var(--body); }
.kpi p.note { font-size: 11.5px; color: var(--muted); line-height: 1.4; }

.timeline { position: absolute; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 10px 14px; align-items: center;
  padding-block: 10px calc(10px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: linear-gradient(transparent, var(--panel) 32%); }
input[type=range] { width: 100%; accent-color: var(--brand-btn); }
.legend { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.legend b { font-weight: 600; color: var(--fg); }
#hudToggle { display: none; }
/* strumenti e linea del tempo sopra la barra, come prima che la scena entrasse in <main> */
.hud, .timeline, .toast { z-index: 2; }
/* link di salto: sr-only come nel sito (la regola skip-link dell'audit riconosce quella classe), visibile al focus */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.salta { position: absolute; left: 12px; top: -80px; z-index: 100; background: var(--panel-solid); color: var(--fg); border: 1px solid var(--line); border-radius: var(--r); font-weight: 600; text-decoration: none; }
.salta.sr-only:focus { top: 10px; width: auto; height: auto; padding: 10px 18px; margin: 0; overflow: visible; clip: auto; white-space: nowrap; }
.toast { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: var(--rp); padding: 16px 20px; max-width: min(440px, 90vw); font-size: 14px; margin: 0; }

@media (max-width: 1100px) {
  .brand span { display: none; }
}
@media (max-width: 820px) {
  .hud { left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); width: auto;
    top: auto; bottom: 124px; max-height: 44%; }
  .hud.collapsed { display: none; }
  #hudToggle { display: inline-block; }
  .timeline { grid-template-columns: auto minmax(0, 1fr); }
  .timeline .group { display: none; }
  .bar { gap: 8px 10px; }
  .badge { display: none; }
  .chk { font-size: 12px; padding: 3px 7px; }
  .brand h1 { font-size: 16px; }
  .group.end { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
