/* Layout: sidebar (filters + list) | map | legend. Road-sign green as the brand, amber route line. */
:root {
  --bg: #E9EEEF;
  --panel: #FFFFFF;
  --panel-2: #F3F6F6;
  --ink: #12202A;
  --muted: #5A6A74;
  --line: #D5DEE1;
  --sign: #0B6B4C;        /* US guide-sign green */
  --sign-ink: #FFFFFF;
  --route: #FFB020;
  --warn-bg: #FFF4D6;
  --warn-ink: #6B4A00;
  --shadow: 0 10px 30px rgba(18, 32, 42, .14);
  --font-display: "Overpass", "Segoe UI", system-ui, sans-serif;
  --font-body: "Overpass", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Overpass Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D1417; --panel: #141C20; --panel-2: #1A2429; --ink: #E4EBEE; --muted: #93A4AD; --line: #26343B;
    --sign: #1F8A64; --sign-ink: #FFFFFF; --route: #FFB020; --warn-bg: #3A2F12; --warn-ink: #FFD98A;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0D1417; --panel: #141C20; --panel-2: #1A2429; --ink: #E4EBEE; --muted: #93A4AD; --line: #26343B;
  --sign: #1F8A64; --sign-ink: #FFFFFF; --route: #FFB020; --warn-bg: #3A2F12; --warn-ink: #FFD98A;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font-body); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--sign); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---------- grid ---------- */
.app {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 400px;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
}
.brand { grid-column: 1; grid-row: 1; }
.side { grid-column: 1; grid-row: 2; }
.mapwrap { grid-column: 2; grid-row: 1 / span 2; }
.legend { grid-column: 3; grid-row: 1 / span 2; }

/* ---------- brand ---------- */
.brand {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 18px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.sign {
  align-self: flex-start;
  background: var(--sign); color: var(--sign-ink);
  border-radius: 8px;
  padding: 6px 14px 4px;
  box-shadow: inset 0 0 0 2px var(--sign), inset 0 0 0 4px rgba(255, 255, 255, .9);
  display: flex; flex-direction: column; line-height: 1.05;
}
.sign-top { font: 600 11px/1.4 var(--font-mono); letter-spacing: .18em; text-transform: uppercase; opacity: .9; }
.sign-main { font: 800 24px/1.1 var(--font-display); letter-spacing: -.01em; }
.sign-3d { color: var(--route); }
.tagline { margin: 0; color: var(--muted); font-size: 13px; }
.brand { position: relative; }
.lang { position: absolute; top: 16px; right: 18px; z-index: 1200; }
.lang-btn {
  display: flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer;
  font: 600 12px/1 var(--font-mono); padding: 6px 8px;
}
.lang-btn:hover, .lang-btn[aria-expanded="true"] { color: var(--ink); background: var(--panel-2); }
.lang-menu {
  position: absolute; top: calc(100% + 4px); right: 0; min-width: 150px; margin: 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
}
.lang-menu button {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%;
  border: 0; border-radius: 5px; background: transparent; color: var(--ink); cursor: pointer;
  font: 600 13px/1.2 var(--font-body); padding: 8px 10px; text-align: left;
}
.lang-menu button:hover, .lang-menu button:focus-visible { background: var(--panel-2); outline: none; }
.lang-menu button[aria-current] { color: var(--sign); }
.lang-name { flex: 1; }
.lang-code { font: 600 11px/1 var(--font-mono); color: var(--muted); }
/* Colonna fissa per il segno di spunta, così i codici restano allineati. */
.lang-menu button::after { content: ""; width: 12px; text-align: right; }
.lang-menu button[aria-current]::after { content: "✓"; }
/* Donazioni facoltative: piccolo pulsante sotto il motto, sempre in vista. */
.coffee {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px 4px;
  color: var(--ink); font-size: 12.5px; font-weight: 600; text-decoration: none;
}
.coffee:hover, .coffee:focus-visible { border-color: var(--route); background: var(--panel-2); }

/* ---------- sidebar ---------- */
.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.tab {
  background: none; border: 0; cursor: pointer;
  padding: 10px 6px; margin-bottom: -1px;
  font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tab + .tab { margin-left: 14px; }
.tab.is-active { color: var(--ink); border-bottom-color: var(--sign); }
.panel { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; min-height: 0; flex: 1; }
.credits { padding: 10px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.4; }
.credits p { margin: 0; }
.credits p + p { margin-top: 6px; }
/* Donazioni facoltative: un link discreto nei crediti e in fondo a Esporta. */
.support { margin: 0; color: var(--muted); font-size: 13px; }
.support a { color: var(--sign); font-weight: 600; text-decoration: none; }
.export .support a { white-space: nowrap; }
.support a:hover, .support a:focus-visible { text-decoration: underline; }
.export .support { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }

.label { font: 600 11px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.hint { margin: -4px 0 0; color: var(--muted); font-size: 13px; }
.input {
  width: 100%; padding: 9px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
}
.input:focus { border-color: var(--sign); outline: none; }
.filter-group { display: flex; flex-direction: column; gap: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink); cursor: pointer; font-weight: 600; text-decoration: none;
}
.linkbtn { background: none; border: 0; padding: 0; color: var(--sign); font-weight: 600; text-decoration: underline; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--sign); color: var(--sign-ink); border-color: var(--sign); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { padding: 12px 16px; font-size: 16px; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 8px; flex: none; }
.btn.icon.is-on { background: var(--sign); color: var(--sign-ink); border-color: var(--sign); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.type-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tchip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; font-weight: 600;
}
.tchip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--muted)); }
.tchip.is-active { border-color: var(--ink); background: var(--panel); box-shadow: inset 0 0 0 1px var(--ink); }

.list-head { display: flex; justify-content: space-between; color: var(--muted); font: 600 11px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .08em; padding-top: 4px; }
.road-list { list-style: none; margin: 0 -8px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.road-item {
  width: 100%; display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: 8px; border: 0; border-radius: 8px; background: none; text-align: left; cursor: pointer;
}
.road-item:hover { background: var(--panel-2); }
.road-item.is-active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--sign); }
.ri-dots { display: flex; flex-wrap: wrap; gap: 3px; }
.ri-dots i { width: 8px; height: 8px; border-radius: 50%; }
.ri-dots i.ri-flag {
  width: 10px; height: 10px; border-radius: 2px; border: 1.5px solid var(--c);
  background: repeating-conic-gradient(#111 0 25%, #fff 0 50%) 0 0 / 5px 5px;
}
.or-sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font: 11px var(--font-mono); text-transform: uppercase; letter-spacing: .08em; }
.or-sep::before, .or-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.ri-main { display: flex; flex-direction: column; min-width: 0; }
.ri-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ri-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ri-km { font: 12px var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 8px; }

/* A→B */
.ab-field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: flex; gap: 6px; }
.pin-dot {
  display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  font: 800 11px/1 var(--font-display); color: #fff;
}
.pin-dot.a { background: var(--sign); }
.pin-dot.b { background: #C2402A; }
.pin-dot.v { background: #5A6A74; }
.opt { text-transform: none; letter-spacing: 0; font-weight: 400; }
.results { display: flex; flex-direction: column; gap: 2px; }
.results button {
  text-align: left; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-size: 13px;
}
.results button:hover { border-color: var(--sign); }
.ab-actions { display: flex; gap: 8px; }
.ab-actions .primary { flex: 1; }
.ab-msg { margin: 0; color: var(--muted); font-size: 13px; min-height: 1.4em; }

/* ---------- map ---------- */
.mapwrap { position: relative; z-index: 0; min-width: 0; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--panel-2); }
.status {
  position: absolute; top: 12px; left: 12px; z-index: 1000;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  padding: 6px 12px 5px; border-radius: 999px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px;
}
.status::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--sign); border-right-color: transparent; animation: spin .8s linear infinite;
}
.pick-banner {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 1000;
  background: var(--ink); color: var(--bg); padding: 8px 14px 6px; border-radius: 999px; font-size: 13px; font-weight: 600;
  white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .status::before { animation: none; } }

.leaflet-container { font-family: var(--font-body); }
.leaflet-control-layers, .leaflet-bar a, .leaflet-control-scale-line {
  background: var(--panel) !important; color: var(--ink) !important; border-color: var(--line) !important;
}
.leaflet-control-layers { border-radius: 8px !important; box-shadow: var(--shadow) !important; border: 1px solid var(--line) !important; }
.leaflet-tooltip.road-tip {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-weight: 600; padding: 4px 8px 2px;
}
.leaflet-tooltip.road-tip::before { display: none; }
.ab-pin {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.ab-pin span { transform: rotate(45deg); color: #fff; font: 800 12px/1 var(--font-display); }
.ab-pin.a { background: #0B6B4C; }
.ab-pin.b { background: #C2402A; }
.ab-pin.v { background: #5A6A74; }
/* Gare: bandierina a scacchi con bordo del colore della categoria. */
.flag-pin {
  width: 100%; height: 100%; border-radius: 4px; box-sizing: border-box;
  border: 2px solid var(--c); box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
  background: repeating-conic-gradient(#111 0 25%, #fff 0 50%) 0 0 / 8px 8px;
}
.flag-pin.is-active { border-width: 3px; box-shadow: 0 0 0 3px rgba(255, 176, 32, .8), 0 2px 6px rgba(0, 0, 0, .5); }

/* ---------- legend ---------- */
.legend {
  position: relative; z-index: 1;
  background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; min-height: 0;
  scroll-padding-top: 52px; /* spazio per la barra delle schede incollata: il controllo col focus non ci finisce sotto */
}
.hero { margin: 0; position: relative; aspect-ratio: 16 / 9; max-width: 100%; background: var(--panel-2); overflow: hidden; }
/* Segnaposto prima che arrivi il tracciato: cartello col nome breve. */
.hero-ph {
  position: absolute; inset: 0; display: grid; place-items: center;
  background:
    repeating-linear-gradient(90deg, transparent 0 46%, rgba(255, 255, 255, .55) 46% 54%, transparent 54% 100%) center / 80px 6px no-repeat,
    linear-gradient(160deg, var(--c), color-mix(in srgb, var(--c) 55%, #000));
}
.hero-ph span {
  font: 800 28px/1 var(--font-display); color: #fff; padding: 10px 16px 6px;
  border: 3px solid #fff; border-radius: 10px; background: rgba(0, 0, 0, .15);
  max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Sagoma del tracciato (SVG dalle coordinate) sul colore della categoria o del tipo. */
.sil {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .16) 1px, transparent 1.5px) 0 0 / 18px 18px,
    linear-gradient(160deg, var(--c), color-mix(in srgb, var(--c) 50%, #000));
}
.sil-svg { display: block; width: 100%; height: 100%; }
.sil-case, .sil-line { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.sil-case { stroke: rgba(0, 0, 0, .38); stroke-width: 8; }
.sil-line { stroke: #FFFFFF; stroke-width: 3.5; }
.sil-start { fill: var(--route); stroke: #FFFFFF; stroke-width: 2.5; }
.sil-tag {
  position: absolute; left: 12px; top: 10px; max-width: calc(100% - 84px);
  font: 800 13px/1 var(--font-display); color: #fff; padding: 5px 8px 3px;
  border: 2px solid #fff; border-radius: 6px; background: rgba(0, 0, 0, .2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.lg-head { padding: 16px 20px 14px; display: flex; flex-direction: column; gap: 12px; }
.eyebrow { margin: 0; font: 600 11px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--sign); }
.lg-head h2 { margin: -6px 0 0; font: 800 26px/1.15 var(--font-display); letter-spacing: -.01em; text-wrap: balance; overflow-wrap: anywhere; }

/* Schede della legenda: barra compatta che resta in alto mentre si scorre. */
.lg-tabs {
  position: sticky; top: 0; z-index: 2;
  display: flex; gap: 2px; padding: 0 12px;
  background: var(--panel); box-shadow: inset 0 -1px 0 var(--line);
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none; overscroll-behavior-x: contain;
}
.lg-tabs::-webkit-scrollbar { display: none; }
.lg-tab {
  flex: 1 0 auto; background: none; border: 0; border-bottom: 3px solid transparent; cursor: pointer;
  padding: 10px 6px 7px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.lg-tab:hover { color: var(--ink); }
.lg-tab.is-active { color: var(--ink); border-bottom-color: var(--sign); }
.lg-tab:focus-visible { outline-offset: -3px; border-radius: 6px 6px 0 0; }
.lg-body { padding: 16px 20px 28px; }
.lg-panel { display: flex; flex-direction: column; gap: 12px; }
.lg-panel:focus-visible { outline-offset: 6px; border-radius: 4px; }
.lg-note { margin: 0; color: var(--muted); font-size: 13px; }
.lg-note b { color: var(--ink); font-weight: 600; }
.place { margin: -8px 0 0; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 3px 10px 1px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.chip-race::before { border-radius: 1px; width: 8px; height: 8px; background: repeating-conic-gradient(#111 0 25%, #fff 0 50%) 0 0 / 4px 4px; box-shadow: 0 0 0 1px var(--c); }

/* Curve */
.sub-wrap { display: flex; flex-direction: column; gap: 12px; }
.corners { max-height: min(60vh, 480px); overflow: auto; border: 1px solid var(--line); border-radius: 10px; scroll-padding-top: 32px; }
.corners table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.corners th {
  position: sticky; top: 0; background: var(--panel-2); text-align: left; padding: 6px 10px;
  font: 600 10px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.corners td { padding: 5px 10px; border-top: 1px solid var(--line); }
.corners td:first-child, .corners td:nth-child(3), .corners td:nth-child(4) { font-family: var(--font-mono); font-size: 12px; }
.corners tr[data-corner] { cursor: pointer; }
/* Anello del focus dentro la riga: il riquadro che scorre non lo taglia e l'intestazione incollata non lo copre. */
.corners tr[data-corner]:hover, .corners tr[data-corner]:focus-visible, .corners tr.is-on { background: color-mix(in srgb, var(--route) 18%, transparent); }
.corners tr[data-corner]:focus-visible { outline-offset: -2px; }

/* Coordinate */
.coords { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.coord-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "k btn" "v btn"; column-gap: 8px; padding: 6px 6px 6px 10px; align-items: center; }
.coord-row + .coord-row { border-top: 1px solid var(--line); }
.coord-row .k { grid-area: k; font: 600 10px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.coord-row code { grid-area: v; font: 12px/1.4 var(--font-mono); overflow-wrap: anywhere; user-select: all; }
.coord-row .copy { grid-area: btn; padding: 6px; background: transparent; }
.coord-row .copy.done, .linkbtn.done { color: var(--sign); border-color: var(--sign); }
.linkbtn.small { font: 600 11px var(--font-body); text-transform: none; letter-spacing: 0; }
.facts { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.facts > div { background: var(--panel); padding: 8px 10px; min-width: 0; }
.facts > div.wide { grid-column: 1 / -1; }
.facts dt { font: 600 10px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.facts dd em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 12px; }
.curv-bar { display: block; height: 4px; border-radius: 2px; background: var(--panel-2); margin-top: 5px; overflow: hidden; }
.curv-bar b { display: block; height: 100%; background: var(--route); }
.warn { margin: 0; background: var(--warn-bg); color: var(--warn-ink); padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.desc { margin: 0; max-width: 65ch; }
.lg-body h3 { margin: 6px 0 -4px; font: 600 11px/1.4 var(--font-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.lg-body h3 .src { font-weight: 400; letter-spacing: .04em; text-transform: none; }
.hl { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 2px; }
.hl li::marker { color: var(--sign); }
.hl a { color: var(--ink); text-decoration-color: var(--line); text-underline-offset: 2px; }
.hl a:hover { text-decoration-color: var(--sign); }
.hl .dist { color: var(--muted); font: 11px var(--font-mono); margin-left: 4px; }
.near-wrap { display: flex; flex-direction: column; gap: 12px; }
/* Riga di elenco con la stella "salva" a destra. */
.star-row { display: flex; align-items: center; gap: 2px; }
.star-row .road-item { flex: 1; min-width: 0; }
.star { flex: none; width: 40px; height: 40px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer; }
.star svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.star:hover { color: var(--ink); background: var(--panel-2); }
.star[aria-pressed="true"] { color: var(--route); }
.star[aria-pressed="true"] svg { fill: currentColor; }
.star:focus-visible { outline-offset: -2px; }

.profile { min-height: 150px; }
.prof-svg { width: 100%; height: auto; display: block; touch-action: none; }
.prof-svg .grid { stroke: var(--line); stroke-width: 1; }
.prof-svg .ylab, .prof-svg .xlab { fill: var(--muted); font: 10px var(--font-mono); }
.prof-svg .area { fill: color-mix(in srgb, var(--sign) 22%, transparent); }
.prof-svg .line { fill: none; stroke: var(--sign); stroke-width: 2; stroke-linejoin: round; }
.prof-svg .cursor { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; }
.prof-svg .dot { fill: var(--route); stroke: var(--ink); stroke-width: 1.5; }
.prof-read { font: 12px var(--font-mono); color: var(--muted); min-height: 1.5em; font-variant-numeric: tabular-nums; }

.skeleton { background: linear-gradient(90deg, var(--panel-2), var(--line), var(--panel-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; height: 140px; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* Esporta */
.export { display: flex; flex-direction: column; gap: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions .btn { font-size: 13px; padding: 7px 11px; }
.actions .sep { flex-basis: 100%; height: 0; }
.actions .btn.done { color: var(--sign); border-color: var(--sign); }
.actions .btn.done::after { content: "✓"; font-weight: 800; }
/* Pulsanti al lavoro (export, vista 3D che si carica): rotellina accanto al testo. */
.btn[aria-busy="true"]::after {
  content: ""; width: 10px; height: 10px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
.btn[aria-disabled="true"] { opacity: .6; cursor: progress; }
@media (prefers-reduced-motion: reduce) { .btn[aria-busy="true"]::after { animation: none; } }

/* Invito alla vista 3D sotto il titolo: largo quanto la legenda, sempre visibile. */
.cta-3d { width: 100%; justify-content: flex-start; gap: 12px; padding: 12px 16px; border-radius: 10px; text-align: left; box-shadow: 0 4px 14px color-mix(in srgb, var(--sign) 35%, transparent); }
.cta-3d svg { flex: none; width: 30px; height: 30px; }
.cta-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cta-txt b { font: 800 18px/1.15 var(--font-display); }
.cta-txt small { font-size: 12.5px; font-weight: 400; opacity: .9; }
.cta-go { margin-left: auto; font-size: 22px; line-height: 1; transition: transform .15s; }
.cta-3d:hover:not([disabled]) .cta-go { transform: translateX(3px); }
.cta-3d[disabled] { box-shadow: none; }
.cta-3d[aria-busy="true"] .cta-go { display: none; }
@media (prefers-reduced-motion: reduce) { .cta-go { transition: none; } }

/* Heightmap per giochi */
.hm { display: flex; flex-direction: column; gap: 8px; }
.hm-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 14px; }
.hm-field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 200px; min-width: 0; }
.hm-field .input { padding: 7px 10px; font-size: 13px; }
.hm-check { display: flex; align-items: center; gap: 8px; flex: 1 1 200px; min-width: 0; font-size: 13px; cursor: pointer; padding-bottom: 6px; }
.hm-check input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--sign); }
.hm-check:has(input[disabled]) { opacity: .5; cursor: not-allowed; }
.hm-tex { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.hm-tex legend { padding: 0; margin-bottom: 2px; }
.hm-tex .hm-check { flex: 0 1 auto; padding-bottom: 0; }
.hm-tex .hm-field { flex: none; max-width: 260px; }
.hm-tex .hm-photo { max-width: 400px; }   /* «Automatica: ortofoto dove c'è, altrimenti Sentinel-2» per intero */
.hm-status { font-weight: 600; color: var(--ink); }
.hm-status:empty { margin: 0; }
.hm-status.is-err { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 10px; border-radius: 8px; font-weight: 400; }

/* ---------- responsive ---------- */
@media (max-width: 1250px) {
  .app { grid-template-columns: 320px minmax(0, 1fr); }
  .legend {
    grid-column: 2; grid-row: 1 / span 2;
    justify-self: end; align-self: start;
    width: min(380px, calc(100% - 24px)); max-height: calc(100% - 24px); margin: 12px;
    border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  }
  .hero { border-radius: 12px 12px 0 0; }
}
@media (max-width: 820px) {
  html, body { height: auto; }
  html { scroll-padding-top: 52px; } /* qui scorre la pagina: spazio per la barra delle schede incollata */
  .app { display: flex; flex-direction: column; height: auto; }
  .brand { border-right: 0; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .mapwrap { order: 1; height: 56vh; min-height: 320px; }
  .legend { order: 2; width: auto; max-height: none; margin: 0; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; box-shadow: none; overflow: visible; }
  .hero { border-radius: 0; }
  .side { order: 3; border-right: 0; }
  .panel { overflow: visible; }
  .panel, .tabs, .credits, .lg-head, .lg-body { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  /* La barra delle schede resta in cima allo schermo mentre si scorre la legenda. */
  .lg-tabs { padding-left: max(8px, env(safe-area-inset-left, 0px)); padding-right: max(8px, env(safe-area-inset-right, 0px)); box-shadow: inset 0 -1px 0 var(--line), 0 1px 0 var(--line); }
  .lg-tab { padding: 11px 6px 8px; }
  .corners { max-height: 55vh; }
  .status { left: max(12px, env(safe-area-inset-left, 0px)); }
}

/* Telefoni stretti: le cinque schede della legenda stanno in riga senza tagliare Esporta. */
@media (max-width: 360px) {
  .lg-tabs { gap: 0; }
  .lg-tab { padding-inline: 3px; font-size: 12px; }
}

/* ---------- vista 3D (src/view3d.js) ---------- */
/* Finestra a tutto schermo: scena sopra, comandi sotto. La scena ha il suo cielo diurno in entrambi i temi;
   pannello dei comandi, errori e crediti seguono il tema come il resto del sito. */
html.v3d-open, html.v3d-open body { overflow: hidden; }
.v3d { position: fixed; inset: 0; z-index: 5000; background: var(--bg); color: var(--ink); }
.v3d-dialog { position: absolute; inset: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.v3d-view { position: relative; min-height: 0; overflow: hidden; background: linear-gradient(#2f6db5, #8dbbe2 55%, #d8e3ea); }
.v3d-stage { position: absolute; inset: 0; }
.v3d-stage:focus-visible { outline: 3px solid var(--route); outline-offset: -3px; }
.v3d-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* Sopra la scena: titolo a sinistra, chiudi a destra, testi chiari su vetro scuro (leggibili sul cielo e sul terreno). */
.v3d-top {
  position: absolute; top: 0; left: 0; right: 0; pointer-events: none;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: max(12px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
}
.v3d-top > * { pointer-events: auto; }
.v3d-head {
  min-width: 0; max-width: min(560px, 100%); padding: 8px 14px 7px; border-radius: 10px;
  background: rgba(10, 18, 24, .62); color: #fff; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.v3d-eyebrow { margin: 0; font: 600 10px/1.4 var(--font-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--route); }
.v3d-title { margin: 0; font: 800 20px/1.15 var(--font-display); letter-spacing: -.01em; overflow-wrap: anywhere; }
.v3d-sect { margin: 3px 0 0; font: 600 12px/1.3 var(--font-mono); color: rgba(255, 255, 255, .82); font-variant-numeric: tabular-nums; }
.v3d-close {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: rgba(10, 18, 24, .62); color: #fff;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.v3d-close:hover { background: rgba(10, 18, 24, .85); }
.v3d-close:focus-visible { outline: 3px solid var(--route); outline-offset: 2px; }

/* HUD in basso a sinistra, come un cruscotto. */
.v3d-hud {
  position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); bottom: 12px; margin: 0;
  display: grid; grid-template-columns: repeat(4, auto); gap: 2px 20px; max-width: calc(100% - 32px);
  padding: 8px 14px; border-radius: 10px; background: rgba(10, 18, 24, .66); color: #fff;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); font-variant-numeric: tabular-nums; pointer-events: none;
}
.v3d-hud > div { min-width: 0; }
.v3d-hud dt { font: 600 10px/1.4 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: rgba(255, 255, 255, .7); }
.v3d-hud dd { margin: 0; font: 600 16px/1.3 var(--font-mono); white-space: nowrap; }
.v3d-hud .v3d-next { grid-column: 1 / -1; border-top: 1px solid rgba(255, 255, 255, .18); padding-top: 4px; margin-top: 2px; }
.v3d-hud .v3d-next dd { color: var(--route); overflow: hidden; text-overflow: ellipsis; }

/* Caricamento, avvisi ed errori */
/* width: max-content: con un solo lato fissato (left: 50%) la larghezza "shrink-to-fit" avrebbe solo metà
   dello spazio e il testo andrebbe a capo a metà schermo; il limite resta max-width. Raggio di 20px:
   su una riga è una pillola, su due un rettangolo arrotondato (il testo non esce dagli angoli). */
.v3d-load {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: max-content; max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 10px; padding: 10px 18px 8px; border-radius: 20px;
  background: rgba(10, 18, 24, .74); color: #fff; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums;
}
.v3d-spinner, .v3d-pill::before {
  flex: none; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--route); border-right-color: transparent; animation: spin .8s linear infinite;
}
.v3d-pill {
  position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); bottom: 12px; margin: 0; width: max-content; max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 8px; padding: 6px 12px 5px; border-radius: 15px;
  background: rgba(10, 18, 24, .66); color: #fff; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; pointer-events: none;
}
.v3d-pill::before { content: ""; width: 10px; height: 10px; }
.v3d-err {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(460px, calc(100% - 32px));
  display: flex; flex-direction: column; gap: 12px; padding: 16px 18px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.v3d-err p { margin: 0; }
.v3d-err-act { display: flex; flex-wrap: wrap; gap: 8px; }
@media (prefers-reduced-motion: reduce) { .v3d-spinner, .v3d-pill::before { animation: none; } }

/* Barra dei comandi: va a capo, mai più larga dello schermo. */
.v3d-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 20px; min-width: 0;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) max(8px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: var(--panel); border-top: 1px solid var(--line);
}
.v3d-cams { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.v3d-cam {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px 6px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--ink); font-size: 13px; font-weight: 600;
}
.v3d-cam:hover { border-color: var(--muted); }
.v3d-cam[aria-pressed="true"] { background: var(--sign); color: var(--sign-ink); border-color: var(--sign); }
.v3d-cam kbd { font: 600 10px/1 var(--font-mono); padding: 2px 4px 1px; border: 1px solid currentColor; border-radius: 4px; opacity: .7; }
.v3d-cam.v3d-spin { margin-left: 4px; }
.v3d-play, .v3d-opts { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; min-width: 0; }
.v3d-play { flex: 1 1 380px; }
.v3d-playbtn { min-width: 104px; }
.v3d-range, .v3d-select { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 0 1 170px; }
.v3d-range.v3d-grow { flex: 1 1 200px; }
.v3d-range input { width: 100%; margin: 4px 0; accent-color: var(--sign); }
.v3d-select { flex: 0 1 auto; }
.v3d-select .input { padding: 6px 10px; font-size: 13px; width: auto; max-width: 100%; }
.v3d-lab {
  display: flex; justify-content: space-between; gap: 8px;
  font: 600 10px/1.4 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.v3d-lab output { color: var(--ink); letter-spacing: 0; text-transform: none; font-variant-numeric: tabular-nums; }
.v3d-secnav { display: flex; flex-wrap: wrap; gap: 6px; }
.v3d-secnav .btn { font-size: 13px; padding: 7px 11px; }
.v3d-credits { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.35; }

/* Telefoni e finestre strette: titolo e HUD più compatti, etichette dei tasti nascoste. */
@media (max-width: 820px) {
  .v3d-title { font-size: 16px; }
  .v3d-head { padding: 6px 10px 5px; }
  .v3d-hud { grid-template-columns: repeat(2, auto); gap: 0 14px; padding: 6px 10px; bottom: 8px; }
  .v3d-hud dd { font-size: 13px; }
  .v3d-pill { top: 76px; bottom: auto; right: 50%; transform: translateX(50%); }
  .v3d-bar { gap: 8px 12px; padding-top: 8px; }
  .v3d-cam { padding: 6px 8px 5px; font-size: 12px; }
  .v3d-cam kbd { display: none; }
  .v3d-play { flex-basis: 100%; }
  .v3d-range { flex: 1 1 130px; }
  .v3d-opts { flex: 1 1 100%; }
}
/* Schermi bassi (telefono in orizzontale): meno spazio ai comandi, più alla scena. */
@media (max-height: 520px) {
  .v3d-hud .v3d-next { display: none; }
  .v3d-credits { font-size: 10px; }
  .v3d-bar { padding-top: 6px; gap: 6px 12px; }
}

/* ---------- benvenuto (prima visita) ---------- */
/* Durante il benvenuto la legenda è vuota: si nasconde e la mappa prende il suo posto. */
body.intro-on .app { grid-template-columns: 340px minmax(0, 1fr); }
body.intro-on .legend { display: none; }
/* Vignetta sopra i tile e sotto tracciati e marker (overlayPane di Leaflet = 400). */
.mapwrap::after {
  content: ""; position: absolute; inset: 0; z-index: 350; pointer-events: none; opacity: 0; transition: opacity .6s;
  background: radial-gradient(ellipse 85% 75% at 60% 42%, transparent 35%, rgba(5, 10, 14, .55));
}
body.intro-on .mapwrap::after { opacity: 1; }
/* Strade e gare pulsano sfasate (ritardo in --pulse-delay, da mapview). */
body.intro-on .road-dot { animation: dot-pulse 2.4s ease-in-out var(--pulse-delay, 0s) infinite; transform-box: fill-box; transform-origin: center; }
body.intro-on .flag-pin { animation: flag-pulse 2.4s ease-in-out infinite; }
@keyframes dot-pulse { 50% { transform: scale(1.6); stroke-opacity: .5; } }
/* Durante il volo e sul tracciato del giorno spariscono (da vicino coprirebbero la strada). */
.road-dot, .flag-pin { transition: opacity .5s; }
body.intro-fly .road-dot, body.intro-fly .flag-pin:not(.is-active) { opacity: 0; pointer-events: none; }
@keyframes flag-pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 176, 32, .35), 0 2px 6px rgba(0, 0, 0, .5); } }

.intro {
  position: absolute; z-index: 1000; left: 24px; bottom: 28px; width: min(480px, calc(100% - 48px));
  padding: 22px 22px 16px; border-radius: 16px; border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(1.2); backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: var(--shadow);
  animation: intro-in .6s cubic-bezier(.2, .8, .2, 1) .25s both;
}
@keyframes intro-in { from { opacity: 0; transform: translateY(16px); } }
.intro-kicker {
  margin: 0; padding-right: 36px; display: flex; align-items: center; gap: 8px;
  font: 600 12px var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--sign);
}
.intro-live { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--route); animation: live 1.8s ease-out infinite; }
@keyframes live { from { box-shadow: 0 0 0 0 rgba(255, 176, 32, .7); } to { box-shadow: 0 0 0 9px rgba(255, 176, 32, 0); } }
.intro h1 { margin: 8px 0 10px; font: 800 30px/1.1 var(--font-display); letter-spacing: -.01em; text-wrap: balance; }
.intro-sub { margin: 0 0 14px; color: var(--muted); font-size: 14.5px; line-height: 1.45; }
.intro-road {
  display: flex; flex-direction: column; gap: 1px; margin-bottom: 14px; padding: 10px 12px;
  border-radius: 10px; background: var(--panel-2); border-left: 3px solid var(--route);
}
.intro-road b { font: 800 17px/1.2 var(--font-display); }
.intro-road span { font-size: 13px; color: var(--muted); }
.intro-main { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.intro-3d { gap: 8px; }
.intro-3d svg { width: 20px; height: 20px; }
.intro-more { display: flex; flex-wrap: wrap; gap: 0 16px; margin-top: 8px; }
.intro-more button {
  padding: 8px 0; border: 0; background: none; cursor: pointer; color: var(--ink);
  font: 600 13.5px var(--font-body); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 4px;
}
.intro-more button:hover { text-decoration-color: var(--sign); }
.intro-x {
  position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer;
}
.intro-x:hover { background: var(--panel-2); color: var(--ink); }
.sign[role="button"] { cursor: pointer; }

@media (max-width: 820px) {
  /* Telefono: la mappa si allunga per il benvenuto e il riquadro sta in basso, largo quanto lo schermo. */
  body.intro-on .mapwrap { height: 82vh; height: 82svh; }
  .intro {
    left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); bottom: 12px;
    width: auto; padding: 16px 16px 10px;
  }
  .intro h1 { font-size: 23px; }
  .intro-main .btn { padding: 12px; font-size: 15px; white-space: nowrap; }
  .intro-sub { display: none; }
  .intro-road { margin-bottom: 12px; }
}
@media (max-width: 360px) {
  .intro-main { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .intro, .intro-live, body.intro-on .road-dot, body.intro-on .flag-pin { animation: none; }
  .mapwrap::after { transition: none; }
}
