/* ============================================================================
   InterCity-Hubs — UI di gioco · Material / Google (dark)
   Superfici piatte, spigoli netti, blu Google, Roboto + Material Symbols.
   Tutti i selettori toggle-ati dal JS sono preservati (.hidden, .active,
   .owned, .disabled, .urgent, .done, .neg-money, badge stati, ecc.).
   ========================================================================== */

:root {
  /* — Superfici (palette nautica: navy profondo + ottone) — */
  --bg:        #0c2537;
  --surface:   #123049;   /* app bar, pannelli */
  --surface-1: #1a3f5c;   /* elevato 1 */
  --surface-2: #234c6e;   /* elevato 2 */
  --surface-3: #2c5b81;   /* input / hover */
  --scrim:     rgba(0,0,0,.6);

  /* — Linee — */
  --border:        #3a6280;
  --border-subtle: #1c3a52;

  /* — Testo — */
  --text:  #f0e8d0;   /* carta/pergamena */
  --text-2:#cfdce1;
  --muted: #7f9fb2;

  /* — Accenti (ottone) — */
  --primary:        #d3a24b;   /* oro/ottone accento */
  --primary-strong: #c99a4a;   /* riempimenti (targa in ottone) */
  --primary-press:  #ddb066;
  --on-primary:     #1c1206;   /* inchiostro scuro su ottone */
  --primary-tint:   rgba(211,162,75,.14);
  --green:  #4fae7f;           /* verde-mare */
  --red:    #c1543f;           /* vino */
  --amber:  #e0b563;           /* denaro (ottone chiaro) */

  /* — Colori mezzi (coerenti con config.js) — */
  --bus:   #ffb347;
  --treno: #4ec9b0;
  --aereo: #5b9bd5;
  --nave:  #49c0e8;

  /* — Raggi (leggermente più morbidi, da gettone da tavolo) — */
  --r:   12px;  /* card / pannelli */
  --r-sm:6px;   /* controlli / chip */

  /* — Ombre — */
  --el-1: 0 1px 2px rgba(0,0,0,.5), 0 1px 3px 1px rgba(0,0,0,.3);
  --el-2: 0 1px 3px rgba(0,0,0,.5), 0 4px 8px 3px rgba(0,0,0,.3);
  --el-3: 0 4px 8px rgba(0,0,0,.5), 0 8px 24px 6px rgba(0,0,0,.34);

  /* — Font — */
  --font: 'Mulish', system-ui, "Segoe UI", Arial, sans-serif;
  --mono: 'Roboto Mono', ui-monospace, "SFMono-Regular", monospace;

  --hud-h: 60px;
}

/* Material Symbols */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal; font-style: normal; line-height: 1; letter-spacing: normal;
  text-transform: none; display: inline-block; white-space: nowrap; word-wrap: normal;
  direction: ltr; -webkit-font-feature-settings: 'liga'; -webkit-font-smoothing: antialiased;
  font-variation-settings: 'opsz' 20, 'wght' 400, 'GRAD' 0, 'FILL' 0;
}
/* Icone dei mezzi (Material) inline nei pannelli/legenda/tooltip */
.mode-ico { font-size: 1.18em; vertical-align: -.24em; }

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; font-family: var(--font); color: var(--text);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
body {
  display: flex; flex-direction: column; background: var(--bg);
  overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
::selection { background: var(--primary-tint); }

* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 99px; border: 3px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Mappa ---------- */
#map { flex: 1 1 auto; position: relative; min-height: 0; background: var(--bg); }
.leaflet-container { background: #081826; font-family: var(--font); }

/* Controlli Leaflet — stile Material */
.leaflet-bar, .leaflet-control-zoom { border: 0 !important; box-shadow: var(--el-2) !important; border-radius: var(--r-sm) !important; overflow: hidden; }
.leaflet-control-zoom a {
  background: var(--surface-1); color: var(--text-2);
  border-bottom: 1px solid var(--border-subtle) !important;
  width: 36px; height: 36px; line-height: 36px; font-size: 18px;
}
.leaflet-control-zoom a:hover { background: var(--surface-2); color: var(--primary); }
.leaflet-control-attribution {
  background: rgba(30,31,32,.9) !important; color: var(--muted) !important;
  border-radius: 4px 0 0 0; font-size: 10px;
}
.leaflet-control-attribution a { color: var(--text-2) !important; }
.leaflet-tooltip {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--r-sm); box-shadow: var(--el-2); font-family: var(--font);
  font-size: 12px; padding: 5px 9px;
}
.leaflet-tooltip-top:before { border-top-color: var(--surface-2); }

/* ============================================================================
   HUD (app bar)
   Desktop: riga unica (i wrapper usano display:contents). Mobile: drawer + dock.
   ========================================================================== */
#hud {
  flex: 0 0 auto; position: relative; z-index: 1200;
  display: flex; align-items: center; gap: 14px;
  min-height: var(--hud-h); padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: var(--el-1);
  font-feature-settings: "tnum";
}
.hud-top, .hud-controls { display: contents; }

/* Brand */
.hud-brand { display: flex; align-items: center; gap: 12px; padding-left: 4px; }
.hud-brand .logo {
  width: 36px; height: 36px; border-radius: var(--r-sm); display: grid; place-items: center;
  flex-shrink: 0; background: var(--primary-strong); color: var(--on-primary);
}
.hud-brand .logo .material-symbols-outlined { font-size: 22px; }
.hud-brand .brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.hud-brand strong { font-size: 17px; font-weight: 500; letter-spacing: .2px; }
.hud-brand strong .accent { color: var(--primary); font-weight: 700; }
.hud-brand small { font-size: 10px; color: var(--muted); letter-spacing: 1.4px; text-transform: uppercase; margin-top: 1px; }

.hud-divider { width: 1px; height: 28px; background: var(--border-subtle); flex-shrink: 0; }
.hud-spacer { margin-left: auto; }

/* Saldo */
.hud-money {
  display: flex; align-items: baseline; gap: 5px;
  padding: 5px 12px; border-radius: var(--r-sm);
  background: var(--surface-1); border: 1px solid var(--border-subtle);
}
.hud-money .coin { color: var(--amber); font-size: 14px; font-weight: 700; }
.hud-money b {
  font-family: var(--mono); font-size: 19px; font-weight: 700; color: var(--amber);
  letter-spacing: -.3px; font-variant-numeric: tabular-nums;
}
.hud-money b.neg-money { color: var(--red); animation: pulse 1.2s infinite; }
.hud-money b.unlimited-money { color: var(--green); }

/* Rail options list in panel */
.pill.rail-opt { background: var(--surface-2); border-left: 3px solid var(--primary); padding-left: 10px; cursor: pointer; }
.pill.rail-opt:hover { background: var(--surface-3); }
.small { font-size: 11px; color: var(--muted); }

/* KPI */
.hud-group { display: flex; align-items: center; gap: 0; }
.kpi { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: var(--r-sm); transition: background .15s; }
.kpi:hover { background: var(--surface-1); }
.kpi-ico { color: var(--muted); display: grid; place-items: center; }
.kpi-ico .material-symbols-outlined { font-size: 19px; }
.kpi-val { display: flex; flex-direction: column; line-height: 1; }
.kpi-val b { font-family: var(--mono); font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-val small { font-size: 10px; color: var(--muted); margin-top: 3px; letter-spacing: .2px; }
.kpi.ok .kpi-ico { color: var(--green); } .kpi.ok b { color: var(--green); }
.kpi.bad .kpi-ico { color: var(--red); }   .kpi.bad b { color: var(--red); }

/* Orologio */
.hud-clock { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.hud-clock .material-symbols-outlined { font-size: 18px; }
.hud-clock b { color: var(--text-2); font-weight: 500; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Hamburger (mobile) */
.hud-menu-btn {
  display: none; width: 44px; height: 44px; flex-shrink: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--text-2);
  cursor: pointer; position: relative; transition: background .15s;
}
.hud-menu-btn:hover { background: var(--surface-1); }
.hud-menu-btn .bars, .hud-menu-btn .bars::before, .hud-menu-btn .bars::after {
  content: ''; position: absolute; left: 50%; width: 18px; height: 2px;
  background: currentColor; transform: translateX(-50%); transition: transform .22s, opacity .22s;
}
.hud-menu-btn .bars { top: 50%; transform: translate(-50%, -50%); }
.hud-menu-btn .bars::before { top: -6px; }
.hud-menu-btn .bars::after  { top: 6px; }
.menu-open .hud-menu-btn { color: var(--primary); background: var(--surface-1); }
.menu-open .hud-menu-btn .bars { background: transparent; }
.menu-open .hud-menu-btn .bars::before { transform: translateX(-50%) translateY(6px) rotate(45deg); background: var(--primary); }
.menu-open .hud-menu-btn .bars::after  { transform: translateX(-50%) translateY(-6px) rotate(-45deg); background: var(--primary); }

/* Gruppi segmentati (Material segmented buttons) */
.seg {
  display: inline-flex; align-items: stretch;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-sm);
  overflow: hidden;
}
.seg button {
  background: transparent; color: var(--text-2); border: 0;
  border-right: 1px solid var(--border);
  padding: 8px 13px; cursor: pointer; font-family: var(--font);
  font-size: 13px; font-weight: 500; line-height: 1;
  transition: background .14s, color .14s; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.seg button:last-child { border-right: 0; }
.seg button:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.seg button:active:not(:disabled) { background: var(--surface-3); }
.seg button.active {
  background: var(--primary-strong); color: var(--on-primary); font-weight: 500;
}
.seg button.active:hover { background: var(--primary-press); color: var(--on-primary); }
.seg button:disabled { opacity: .38; cursor: not-allowed; }
.seg button.material-symbols-outlined { font-size: 20px; }
.seg-speed button { min-width: 40px; }

/* ---- Menù a tendina della top bar (Traffico/Dati/Gestione/Partita) ---- */
.hud-menu { position: relative; display: inline-flex; }
.hud-menu-trigger {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 11px;
  background: transparent; border: 0; border-radius: var(--r-sm); cursor: pointer;
  color: var(--text-2); font: 500 13px var(--font); transition: background .14s, color .14s;
}
.hud-menu-trigger:hover { background: var(--surface-1); color: var(--text); }
.hud-menu.open .hud-menu-trigger { background: var(--primary-tint); color: var(--primary); }
.hud-menu-trigger .material-symbols-outlined { font-size: 20px; }
.hud-menu-trigger .chev { font-size: 16px; transition: transform .18s; opacity: .7; }
.hud-menu.open .hud-menu-trigger .chev { transform: rotate(180deg); }
.hmt-badge {
  font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--amber);
  background: var(--surface-2); border-radius: 9px; padding: 1px 7px; line-height: 1.4;
  font-variant-numeric: tabular-nums;
}
.hmt-badge.urgent { color: #1a1400; background: var(--amber); animation: pulse 1.2s infinite; }

.hud-pop {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 1300; min-width: 188px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--el-3); padding: 6px; display: none;
}
.hud-menu.open .hud-pop { display: block; }
.hud-pop-head {
  font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
  font-weight: 500; padding: 6px 8px 4px;
}
.hud-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: 0; border-radius: var(--r-sm); padding: 9px 10px;
  color: var(--text); font: 400 14px var(--font); cursor: pointer; text-align: left;
  transition: background .12s;
}
.hud-item:hover:not(:disabled) { background: var(--surface-3); }
.hud-item:disabled { opacity: .4; cursor: not-allowed; }
.hud-item .material-symbols-outlined { font-size: 20px; color: var(--muted); flex-shrink: 0; }
.hud-item.active { color: var(--primary); }
.hud-item.active .material-symbols-outlined { color: var(--primary); }
#b-new .material-symbols-outlined { color: var(--primary); }
/* Righe KPI nel menu Traffico */
.kpi-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; font-size: 14px; }
.kpi-row .kpi-ico .material-symbols-outlined { font-size: 19px; color: var(--muted); }
.kpi-row .kpi-lbl { flex: 1; color: var(--text-2); }
.kpi-row b { font-family: var(--mono); font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-row.ok .kpi-ico .material-symbols-outlined, .kpi-row.ok b { color: var(--green); }
.kpi-row.bad .kpi-ico .material-symbols-outlined, .kpi-row.bad b { color: var(--red); }
/* Toggle lingua */
.hud-lang {
  height: 38px; padding: 0 13px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: transparent; color: var(--text-2); font: 500 13px var(--font); cursor: pointer;
  transition: background .14s, border-color .14s;
}
.hud-lang:hover { background: var(--surface-1); border-color: var(--primary); color: var(--text); }

/* Compattazione progressiva */
@media (max-width: 1280px) {
  #hud { gap: 10px; }
  .kpi-val small { display: none; }
  .kpi { gap: 6px; padding: 6px 9px; }
}
@media (max-width: 1060px) {
  #hud { gap: 7px; padding: 0 8px; }
  .hud-brand small { display: none; }
  .hud-clock { display: none; }
}

/* ============================================================================
   Pannello città
   ========================================================================== */
#panel {
  position: absolute; top: calc(var(--hud-h) + 12px); right: 12px; z-index: 1100; width: 328px;
  max-height: calc(100% - var(--hud-h) - 24px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-subtle); border-radius: var(--r);
  padding: 18px; box-shadow: var(--el-3);
}
#panel.hidden, #hint.hidden { display: none; }

/* Accento colorato per tipo di pannello (#3): barra superiore + tinta del titolo
   e dell'anello icona. Colori coerenti con la palette: città=blu, costruisci=ambra,
   linee=verde, tratta=ciano, linea=teal. */
#panel { --pv: var(--primary); border-top: 3px solid var(--pv); }
#panel.pv-city    { --pv: var(--primary); }
#panel.pv-build   { --pv: var(--amber); }
#panel.pv-lines   { --pv: var(--green); }
#panel.pv-segment { --pv: var(--nave); }
#panel.pv-line    { --pv: var(--treno); }
#panel h2 .material-symbols-outlined { color: var(--pv); vertical-align: -.18em; }
#panel .panel-back { color: color-mix(in srgb, var(--pv) 70%, var(--muted)); }
#panel .panel-back:hover { color: var(--pv); }
#panel .bigbtn .material-symbols-outlined { color: var(--pv); }

#panel h2 { margin: 0 0 4px; font-size: 22px; font-weight: 400; letter-spacing: -.2px; }
#panel .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#panel .sect { border-top: 1px solid var(--border-subtle); padding-top: 14px; margin-top: 14px; }
#panel .sect h3 {
  margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); font-weight: 500;
}

.row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 7px; }
.pill {
  flex: 1 1 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; background: var(--surface-1); border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm); padding: 11px 12px; cursor: pointer; font-size: 14px; font-weight: 400;
  transition: border-color .14s, background .14s;
}
.pill:hover:not(.disabled) { border-color: var(--primary); background: var(--surface-2); }
.pill.disabled { opacity: .45; cursor: not-allowed; }
.pill .cost { color: var(--amber); font-size: 13px; font-family: var(--mono); font-weight: 500; }
.pill.owned { border-color: var(--green); background: rgba(79,174,127,.08); }

.badge { display: inline-block; font-size: 11px; padding: 3px 8px; border-radius: var(--r-sm); font-weight: 500; letter-spacing: .2px; }
.b-bloccata    { background: var(--surface-2); color: var(--muted); }
.b-disponibile { background: rgba(224,181,99,.16);  color: var(--amber); }
.b-sbloccata   { background: rgba(176,107,255,.18); color: #c79bff; }
.b-collegata   { background: rgba(79,174,127,.16); color: var(--green); }

/* Righe rotta */
.route-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-1); border: 1px solid var(--border-subtle); border-radius: var(--r-sm);
  padding: 10px; margin-bottom: 7px; transition: border-color .14s;
}
.route-row:hover { border-color: var(--border); }
.route-info { flex: 1 1 auto; min-width: 0; cursor: pointer; }
.route-title { font-size: 14px; font-weight: 500; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route-sub { font-size: 11px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.route-sub .net { color: var(--green); font-weight: 500; }
.up-chip { margin-left: 6px; padding: 1px 6px; border-radius: 9px; font-size: 10px; font-weight: 600;
  color: #f5dfb0; background: rgba(211,162,75,.18); border: 1px solid rgba(211,162,75,.5); white-space: nowrap; }
/* Flotta + acquisto modelli */
.fleet-now { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.fleet-tag { font-size: 10px; padding: 1px 7px; border-radius: 9px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); color: var(--muted); }
.veh-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; }
.veh-card { border: 1px solid rgba(255,255,255,.12); border-radius: 8px; padding: 6px; background: rgba(255,255,255,.04); display: flex; flex-direction: column; gap: 4px; }
.veh-card.disabled { opacity: .5; }
.veh-card .vc-name { font-size: 11px; font-weight: 600; }
.veh-card .vc-stats { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.veh-card .vc-buy { font-size: 11px; font-weight: 600; padding: 3px 0; border-radius: 6px; border: 1px solid rgba(79,174,127,.5);
  background: rgba(79,174,127,.15); color: #d6f0e2; cursor: pointer; }
.veh-card .vc-buy.disabled { border-color: rgba(255,255,255,.12); background: rgba(255,255,255,.04); color: var(--muted); cursor: default; }
.route-btns { display: flex; gap: 5px; flex-shrink: 0; }
.rbtn {
  width: 34px; height: 34px; border-radius: var(--r-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 18px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; transition: background .14s, border-color .14s;
}
.rbtn:hover:not(.disabled) { border-color: var(--primary); background: var(--surface-3); }
.rbtn.buy { background: rgba(79,174,127,.16); color: var(--green); border-color: transparent; }
.rbtn.buy:hover:not(.disabled) { background: rgba(79,174,127,.26); }
.rbtn.del { background: rgba(193,84,63,.14); color: var(--red); font-size: 14px; border-color: transparent; }
.rbtn.del:hover { border-color: var(--red); }
.rbtn.disabled { opacity: .35; cursor: not-allowed; }
.rbtn.wide { width: auto; min-width: 34px; padding: 0 10px; font-size: 13px; white-space: nowrap; gap: 3px; }
.thr-btn {
  height: 34px; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--amber); font-size: 12px; font-weight: 500; cursor: pointer;
  white-space: nowrap; min-width: 38px; font-family: var(--mono);
}
.thr-btn:hover { border-color: var(--primary); }

.closex {
  float: right; cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1;
  width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%;
  border: 0; background: transparent; transition: background .15s, color .15s; margin: -4px -6px 0 0;
}
.closex:hover { color: var(--text); background: var(--surface-2); }
.muted { color: var(--muted); font-size: 13px; line-height: 1.5; }
.qrow { display: flex; justify-content: space-between; align-items: center; padding: 6px 2px; font-size: 13px; border-bottom: 1px solid var(--border-subtle); }
.qrow:last-child { border-bottom: none; }
.qrow b { color: var(--amber); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.qrow b.urgent { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

.neg { color: var(--red); }
.pos { color: var(--green); }

.delx {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--red);
  border-radius: var(--r-sm); width: 26px; height: 26px; font-size: 12px; line-height: 1;
  cursor: pointer; margin-left: 6px; flex-shrink: 0; transition: all .14s;
}
.delx:hover { border-color: var(--red); background: rgba(193,84,63,.16); }
.linkrow {
  flex: 1 1 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 4px 4px 4px 10px; font-size: 12px;
}
.link-btns { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.tier-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  border-radius: var(--r-sm); padding: 2px 7px; font-size: 11px; cursor: pointer;
  transition: border-color .14s, background .14s, color .14s; line-height: 1.6;
}
.tier-btn:hover { border-color: var(--primary); color: var(--text); }
.tier-btn.active { border-color: var(--primary); background: rgba(201,154,74,.15); color: var(--primary); font-weight: 600; }
.av-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--amber);
  border-radius: var(--r-sm); padding: 2px 7px; font-size: 11px; cursor: pointer;
  transition: border-color .14s, background .14s; line-height: 1.6;
}
.av-btn:hover:not(.disabled) { border-color: var(--amber); background: rgba(242,193,78,.12); }
.av-btn.disabled { opacity: .45; cursor: not-allowed; }
.av-done { font-size: 11px; color: var(--green); font-weight: 600; padding: 0 4px; white-space: nowrap; }

/* Macchina a viste del pannello: back, big buttons, righe cliccabili, fermate */
.panel-back {
  display: inline-flex; align-items: center; gap: 4px; margin: 0 0 6px;
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  font: 500 13px var(--font); padding: 4px 2px; border-radius: var(--r-sm);
}
.panel-back:hover { color: var(--text); }
.panel-back .material-symbols-outlined { font-size: 18px; }
.big-actions { display: flex; gap: 8px; margin: 10px 0 4px; }
.bigbtn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 8px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r); color: var(--text); cursor: pointer; font: 500 14px var(--font);
  transition: background .14s, border-color .14s;
}
.bigbtn:hover { background: var(--surface-3); border-color: var(--primary); }
.bigbtn .material-symbols-outlined { font-size: 26px; color: var(--primary); }
.link-open { cursor: pointer; }
.link-open:hover { color: var(--text); }
.route-info.clickable { cursor: pointer; border-radius: var(--r-sm); }
.route-info.clickable:hover { background: var(--surface-2); }
.stops-chain { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.stop-chip { background: var(--surface-2); border: 1px solid var(--border-subtle); border-radius: var(--r-sm); padding: 2px 7px; font-size: 12px; }
.stop-arrow { color: var(--muted); font-size: 11px; }

/* Nomi-città cliccabili dentro i pannelli (header tratta/linea, catena fermate) */
.city-link { cursor: pointer; color: var(--primary, #d3a24b); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; }
.city-link:hover { text-decoration-style: solid; filter: brightness(1.15); }
.stop-chip.city-link { color: inherit; text-decoration: none; }
.stop-chip.city-link:hover { background: var(--surface-3, rgba(255,255,255,.12)); border-color: var(--primary, #d3a24b); }

/* Sprite mezzi nei pannelli flotta */
.veh-card .vc-img { width: 100%; height: 46px; object-fit: contain; align-self: center; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.veh-row-img { height: 24px; width: 30px; object-fit: contain; vertical-align: -7px; margin-right: 2px; }
.fleet-tag-img { height: 16px; width: 20px; object-fit: contain; vertical-align: -3px; margin-right: 2px; }

/* Riga "Terminal & capienza" nel pannello città */
.termrow {
  flex: 1 1 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 4px 4px 4px 10px; font-size: 12px;
}
.termrow b { color: var(--text); }
.pill.upg { padding: 3px 9px; font-size: 12px; white-space: nowrap; }

/* Merci / rotte commerciali 📦 */
.pill.cargo { border-color: #c8924a; }
.pill.cargo.owned { border-color: #c8924a; background: rgba(200,146,74,.12); }
.route-row.cargo .route-title { color: #e3b173; }
/* NB: niente position:relative su .veh-icon — sovrascriverebbe l'absolute che Leaflet
   mette su .leaflet-marker-icon → i marker driftano (deriva incrementale). Il badge
   merci si ancora invece all'elemento interno .vi (vedi sotto). */
.veh-icon .vcargo { font-size: 10px; position: absolute; top: -7px; left: -7px; line-height: 1; filter: drop-shadow(0 0 1px #000); }

/* ============================================================================
   Hint + Toast (Material snackbar)
   ========================================================================== */
#hint {
  position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 1000; max-width: min(520px, calc(100vw - 32px));
  background: #f0e8d0; color: #1c1206; font-weight: 500; font-size: 13px;
  padding: 11px 18px; border-radius: var(--r-sm); box-shadow: var(--el-2);
  text-align: center;
}
#toast {
  position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%);
  z-index: 1500; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: calc(100vw - 24px);
}
.toast-item {
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  padding: 11px 16px; border-radius: var(--r-sm); font-size: 13px; font-weight: 400;
  box-shadow: var(--el-2); animation: fade 3s forwards; text-align: center;
}
.toast-item.err { border-color: var(--red); color: #f3d3cb; }
@keyframes fade { 0%{opacity:0;transform:translateY(10px);} 10%{opacity:1;transform:none;} 82%{opacity:1;} 100%{opacity:0;transform:translateY(-4px);} }

/* ============================================================================
   Modale
   ========================================================================== */
#modal {
  position: fixed; inset: 0; z-index: 2000;
  background: var(--scrim); display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: overlay-in .15s ease;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
#modal.hidden { display: none; }
.modal-card {
  width: 440px; max-width: 100%; max-height: calc(100vh - 80px); overflow-y: auto;
  background: var(--surface-1); border: 1px solid var(--border-subtle); border-radius: var(--r);
  padding: 24px; box-shadow: var(--el-3); position: relative;
  animation: card-in .2s cubic-bezier(.2,.9,.3,1);
}
@keyframes card-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.modal-card h2 { margin: 0 0 16px; font-size: 22px; font-weight: 400; letter-spacing: -.2px; }
.modal-body { min-height: 60px; }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; justify-content: flex-end; }
.btn-primary {
  background: var(--primary-strong); color: var(--on-primary); border: 0; border-radius: var(--r-sm);
  padding: 0 24px; height: 40px; font-size: 14px; font-weight: 500; cursor: pointer; font-family: var(--font);
  transition: background .15s, box-shadow .15s; box-shadow: var(--el-1);
}
.btn-primary:hover { background: var(--primary-press); box-shadow: var(--el-2); }
.btn-ghost {
  background: transparent; color: var(--primary); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 0 22px; height: 40px; cursor: pointer; font-size: 14px; font-weight: 500;
  font-family: var(--font); transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--primary-tint); border-color: var(--primary); }
/* le modali "a tutta riga" (classifica/nuova partita) mantengono i bottoni espansi */
.modal-actions .btn-primary[data-act="submit"],
.modal-actions .btn-primary[data-act="start"],
.modal-actions .btn-primary[data-act="new"] { flex: 1; }

table.lb { width: 100%; border-collapse: collapse; font-size: 13px; }
table.lb th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: .6px; padding: 8px; border-bottom: 1px solid var(--border);
}
table.lb td { padding: 10px 8px; border-bottom: 1px solid var(--border-subtle); font-variant-numeric: tabular-nums; }
table.lb td b { font-family: var(--mono); }
table.lb tr.top3 td, table.lb tr.top3 td b { color: var(--amber); font-weight: 700; }
table.lb tbody tr { transition: background .12s; }
table.lb tbody tr:hover { background: var(--surface-2); }
.modal-card code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; font-family: var(--mono); }

/* ============================================================================
   Eventi dinamici (card)
   ========================================================================== */
#events {
  position: absolute; left: 12px; bottom: 14px; z-index: 1000; width: 300px;
  background: var(--surface); border: 1px solid var(--border-subtle); border-radius: var(--r);
  padding: 12px 14px; box-shadow: var(--el-2);
}
#events.hidden { display: none; }
.ev-head { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.ev-item { display: flex; align-items: center; gap: 9px; padding: 5px 0; font-size: 12px; }
.ev-ico { font-size: 16px; }
.ev-lbl { flex: 1 1 auto; }
.ev-time { color: var(--amber); font-weight: 700; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.ev-fix {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--amber);
  border-radius: var(--r-sm); padding: 5px 10px; font-size: 11px; font-weight: 500;
  cursor: pointer; white-space: nowrap; flex-shrink: 0; transition: border-color .14s;
}
.ev-fix:hover { border-color: var(--amber); }
.ev-bankrupt {
  color: #f3d3cb; font-weight: 500; border: 1px solid var(--red);
  border-radius: var(--r-sm); padding: 8px 10px !important; margin-bottom: 8px;
  background: rgba(193,84,63,.12); animation: pulse 1.2s infinite;
}

/* Marker eventi sulla mappa */
.event-icon { text-align: center; }
.ev-emoji { display: inline-block; font-size: 20px; filter: drop-shadow(0 1px 3px #000); animation: evpulse 1.4s infinite; }
@keyframes evpulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }
.weather-haze { filter: blur(12px); animation: hazedrift 6s ease-in-out infinite alternate; }
@keyframes hazedrift { from { opacity: .85; } to { opacity: 1; } }

/* Icone città (immagine isometrica + anello-stato alla base) */
.city-ico-wrap { background: none; border: none; }
.city-ico { position: relative; width: 100%; height: 100%; }
.city-ico img { display: block; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 2px 3px rgba(0,0,0,.55)); }
.city-ico .cic-ring {
  position: absolute; left: 50%; bottom: 1px; transform: translateX(-50%);
  width: 56%; height: 12px; border: 2px solid var(--ring, #4fae7f); border-radius: 50%;
  box-shadow: 0 0 6px var(--ring, #4fae7f); pointer-events: none;
}
.city-ico.sel .cic-ring { border-color: #fff; box-shadow: 0 0 9px #fff; width: 64%; height: 14px; }

/* Etichette città */
.city-label {
  font-size: 11px; color: #e8eaed; font-weight: 500; letter-spacing: .2px;
  text-shadow: 0 0 3px #000, 0 1px 3px #000, 0 0 8px rgba(0,0,0,.7);
}

/* Icone-stato infrastruttura sopra le città (riga di chip modo+livello) */
.city-infra { pointer-events: none; }
.city-infra .ci-row {
  position: absolute; left: 0; bottom: 0; transform: translate(-50%, -2px);
  display: flex; gap: 2px; white-space: nowrap;
}
.ci-chip {
  display: inline-flex; align-items: center; gap: 1px;
  background: rgba(20,21,22,.82); border: 1px solid var(--c, #888);
  border-radius: 5px; padding: 0 2px 0 1px; line-height: 1;
  box-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.ci-chip .material-symbols-outlined { font-size: 13px; color: var(--c, #ccc); line-height: 1; }
.ci-chip i { font-style: normal; font-size: 9px; font-weight: 700; color: #e8eaed; font-family: var(--mono); }

/* Veicoli */
.veh-icon { font-size: 15px; line-height: 15px; text-align: center; filter: drop-shadow(0 1px 2px rgba(0,0,0,.55)); pointer-events: auto; }
.veh-icon .vi { display: inline-block; position: relative; transition: transform .25s linear; }
.veh-icon .vimg { display: block; }
.veh-icon .mode-ico { font-size: 18px; vertical-align: 0; line-height: 1; }

.flow-anim { animation: flowdash 1.2s linear infinite; }
@keyframes flowdash { to { stroke-dashoffset: -17; } }

.fx { pointer-events: none; }
/* L'animazione (transform) sta sull'inner span, così il transform di posizionamento
   di Leaflet sull'elemento radice del marker resta intatto. */
.fxi { display: block; font-size: 12px; font-weight: 700; white-space: nowrap; font-family: var(--mono);
  text-shadow: 0 0 3px #000, 0 0 3px #000; animation: fxfloat 1.3s ease-out forwards;
  margin-left: 8px; margin-top: 14px; }
.fx-up .fxi { color: #4fae7f; }
.fx-down .fxi { color: #c1543f; }
@keyframes fxfloat { 0% { opacity: 0; transform: translateY(4px); } 15% { opacity: 1; } 100% { opacity: 0; transform: translateY(-22px); } }

.qbadge {
  background: var(--amber); color: #1a1400; font-size: 10px; font-weight: 700; font-family: var(--mono);
  border-radius: var(--r-sm); text-align: center; line-height: 15px; min-width: 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,.6); pointer-events: none; padding: 0 3px;
}
.qbadge.urgent { background: var(--red); color: #fff; animation: pulse 1s infinite; }

/* ============================================================================
   Filtri mappa (pannello floating bottom-right)
   ========================================================================== */
#map-filter-panel {
  position: fixed;
  bottom: 28px;
  right: 12px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
#map-filter-toggle {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--el-2);
  transition: background .14s, color .14s;
}
#map-filter-toggle:hover,
#map-filter-toggle.active { background: var(--primary-tint); color: var(--primary); border-color: var(--primary); }
#map-filter-pop {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--el-3);
  padding: 10px;
  min-width: 200px;
}
#map-filter-pop.hidden { display: none; }
.mf-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .06em;
  text-transform: uppercase;
  margin: 6px 0 4px;
}
.mf-section-label:first-child { margin-top: 0; }
.mf-row { display: flex; flex-wrap: wrap; gap: 5px; }
.mf-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font: 500 12px var(--font);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.mf-chip.active { background: var(--primary-tint); color: var(--primary); border-color: rgba(211,162,75,.35); }

/* ============================================================================
   Tutorial / Obiettivi / Legenda (card)
   ========================================================================== */
#tutorial {
  position: absolute; left: 12px; top: calc(var(--hud-h) + 12px); z-index: 1000; width: 280px;
  background: var(--surface); border: 1px solid var(--border-subtle); border-radius: var(--r);
  padding: 14px; box-shadow: var(--el-2); font-size: 12px;
}
#tutorial.hidden { display: none; }
.tut-head { font-size: 13px; font-weight: 500; margin-bottom: 10px; }
.tut-head .closex { float: right; width: 28px; height: 28px; font-size: 16px; margin: -4px -6px 0 0; }
.tut-step { padding: 5px 0; color: var(--text-2); line-height: 1.4; }
.tut-step.done { color: var(--green); text-decoration: line-through; opacity: .7; }

#objectives {
  position: absolute; left: 12px; top: calc(var(--hud-h) + 12px); z-index: 1000; width: 272px;
  background: var(--surface); border: 1px solid var(--border-subtle); border-radius: var(--r);
  padding: 14px; box-shadow: var(--el-2); font-size: 13px;
}
#objectives.hidden { display: none; }
.obj-head { font-weight: 500; margin-bottom: 10px; font-size: 14px; }
.obj-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; color: var(--text-2); }
.obj-row.done { color: var(--green); }
.obj-row .obj-lbl { flex: 1; }
.obj-row .obj-prog { font-variant-numeric: tabular-nums; font-weight: 500; font-family: var(--mono); }
.obj-foot { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border-subtle); color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

#legend {
  position: absolute; right: 12px; bottom: 28px; z-index: 1000;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.lg-toggle {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border-subtle);
  background: var(--surface); color: var(--text-2); cursor: pointer; font-size: 18px;
  box-shadow: var(--el-2); transition: background .15s, color .15s;
}
.lg-toggle:hover { background: var(--surface-1); color: var(--primary); }
#legend .lg-body { display: none; }
#legend.open .lg-body {
  display: flex; gap: 20px; background: var(--surface); border: 1px solid var(--border-subtle);
  border-radius: var(--r); padding: 14px 16px; box-shadow: var(--el-2);
}
.lg-h { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.lg-row { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 3px 0; white-space: nowrap; }
.lg-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ============================================================================
   Modali: bilancio / economia / nuova partita
   ========================================================================== */
.modal-h3 { margin: 18px 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 500; }
.bal-grid .qrow b { color: var(--text); }
.bal-grid .qrow b.pos { color: var(--green); }
.bal-grid .qrow b.neg { color: var(--red); }
.bal-net { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px !important; font-weight: 500; font-size: 14px; }
.spark { width: 100%; height: 68px; background: var(--bg); border: 1px solid var(--border-subtle); border-radius: var(--r-sm); }

.eco-row { display: grid; grid-template-columns: 120px 1fr 56px; align-items: center; gap: 12px; padding: 9px 0; }
.eco-row label { font-size: 13px; }
.eco-row b { font-variant-numeric: tabular-nums; text-align: right; color: var(--amber); font-family: var(--mono); font-weight: 500; }
.eco-row input[type="range"] { width: 100%; accent-color: var(--primary); height: 22px; }

.ng-field { margin-bottom: 16px; }
.ng-field > label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.ng-field select, .ng-field input[type="text"] {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 11px 12px; font-size: 14px; font-family: var(--font);
}
.ng-field select:focus, .ng-field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.ng-opts { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.ng-opts label { font-size: 13px; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.ng-opts input { accent-color: var(--primary); width: 16px; height: 16px; }
.ng-evs { font-size: 12px; }

/* Stelle */
.stars .star { color: #3d6076; }
.stars .star.on { color: var(--amber); }
.stars-big { font-size: 46px; letter-spacing: 8px; margin: 14px 0; }
.stars-big .star { color: #3d6076; }
.stars-big .star.on { color: var(--amber); text-shadow: 0 0 14px rgba(224,181,99,.4); animation: star-pop .45s cubic-bezier(.2,1.4,.4,1) both; }
.stars-big .star.on:nth-child(2) { animation-delay: .1s; }
.stars-big .star.on:nth-child(3) { animation-delay: .2s; }
@keyframes star-pop { from { transform: scale(0); opacity: 0; } to { transform: none; opacity: 1; } }

/* ============================================================================
   MOBILE
   ========================================================================== */
@media (max-width: 760px) {
  :root { --hud-h: 56px; }

  #hud { flex-direction: column; align-items: stretch; gap: 0; padding: 0; min-height: 0; }
  .hud-top {
    display: flex; align-items: center; gap: 8px;
    height: var(--hud-h); padding: env(safe-area-inset-top) 6px 0 10px;
  }
  .hud-top .hud-divider { display: none; }
  .hud-brand .brand-text { display: none; }
  .hud-brand { padding-left: 0; }
  .hud-clock { display: none; }
  .hud-money { padding: 4px 10px; }
  .hud-money b { font-size: 17px; }
  .hud-group { gap: 0; margin-left: auto; }
  .kpi { padding: 4px 5px; gap: 4px; }
  .kpi-ico .material-symbols-outlined { font-size: 17px; }
  .kpi-val b { font-size: 13px; }
  .hud-spacer { display: none; }
  .hud-menu-btn { display: block; }

  /* Drawer */
  .hud-controls {
    display: block; position: absolute; top: 100%; right: 8px; left: 8px;
    background: var(--surface-1); border: 1px solid var(--border-subtle);
    border-radius: var(--r); box-shadow: var(--el-3); padding: 12px;
    transform-origin: top right; transform: translateY(-8px) scale(.98); opacity: 0; pointer-events: none;
    transition: transform .2s cubic-bezier(.2,.9,.3,1), opacity .16s; z-index: 1300;
  }
  .menu-open .hud-controls { transform: none; opacity: 1; pointer-events: auto; max-height: 78vh; overflow-y: auto; }

  /* I menù diventano sezioni accordion a tutta larghezza dentro il drawer */
  .hud-controls .hud-menu { display: block; width: 100%; margin-bottom: 6px; }
  .hud-controls .hud-menu-trigger {
    width: 100%; height: 48px; justify-content: flex-start;
    background: var(--surface); border: 1px solid var(--border-subtle);
  }
  .hud-controls .hud-menu-trigger .hmt-label { flex: 1; text-align: left; }
  .hud-controls .hud-pop {
    position: static; box-shadow: none; border-color: var(--border-subtle);
    margin: 6px 0 0; min-width: 0; width: 100%;
  }
  .hud-controls .hud-pop-head { display: none; }
  .hud-controls .hud-item { height: 46px; }
  .hud-controls .hud-lang { width: 100%; height: 46px; margin-top: 4px; }

  /* Dock velocità in basso */
  #seg-speed {
    position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom));
    transform: translateX(-50%); z-index: 1050;
    box-shadow: var(--el-3); background: var(--surface-1); border: 1px solid var(--border);
  }
  #seg-speed button { min-width: 52px; min-height: 46px; font-size: 14px; }
  body:has(#panel:not(.hidden)) #seg-speed,
  body:has(#modal:not(.hidden)) #seg-speed { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(20px); transition: .2s; }

  /* Bottom sheet */
  #panel {
    top: auto; bottom: 0; left: 0; right: 0; width: auto;
    max-height: 64vh; border-radius: 12px 12px 0 0; border-bottom: 0;
    padding: 20px 16px max(18px, env(safe-area-inset-bottom));
  }
  #panel::before {
    content: ''; position: sticky; top: -4px; display: block;
    width: 32px; height: 4px; border-radius: 99px; background: var(--surface-3);
    margin: -10px auto 14px;
  }
  #panel h2 { font-size: 24px; }
  .pill { padding: 13px; }
  .rbtn, .thr-btn { min-width: 44px; min-height: 44px; }
  .delx { width: 32px; height: 32px; }
  .route-row { padding: 11px; }

  #tutorial { width: auto; left: 8px; right: 8px; top: calc(var(--hud-h) + env(safe-area-inset-top) + 8px); }
  #events { width: auto; left: 8px; right: 64px; bottom: calc(74px + env(safe-area-inset-bottom)); }
  #legend { bottom: calc(74px + env(safe-area-inset-bottom)); right: 10px; }
  #hint { bottom: calc(136px + env(safe-area-inset-bottom)); left: 8px; right: 8px; transform: none; max-width: none; }
  #toast { bottom: calc(190px + env(safe-area-inset-bottom)); width: calc(100vw - 24px); }
  #objectives { left: 8px; right: 64px; top: calc(var(--hud-h) + env(safe-area-inset-top) + 8px); width: auto; }
  .modal-card { padding: 20px 18px; border-radius: 12px 12px 0 0; align-self: flex-end; width: 100%; max-height: 88vh; }
  #modal { align-items: flex-end; padding: 0; }
  .modal-actions { gap: 8px; }
}

@media (max-width: 760px) and (min-height: 560px) {
  #objectives, #tutorial { max-height: 40vh; overflow-y: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- Mini-player musicale (YouTube) ---------- */
.music-panel {
  position: fixed; right: 16px; bottom: 16px; z-index: 1400;
  width: 320px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: 0 8px 24px rgba(0,0,0,.5);
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.music-panel.hidden { display: none; }
.music-panel .mp-head { display: flex; align-items: center; justify-content: space-between; }
.music-panel .mp-title { font-size: 14px; color: var(--text); }
.music-panel .mp-close {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 2px 4px; border-radius: var(--r-sm);
}
.music-panel .mp-close:hover { background: var(--surface-2); color: var(--text); }
.music-panel .mp-row { display: flex; gap: 6px; }
.music-panel .mp-input {
  flex: 1; min-width: 0; background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 6px 8px; font-size: 13px;
}
.music-panel .mp-input:focus { outline: none; border-color: var(--primary); }
.music-panel .mp-load {
  background: var(--primary-strong); color: var(--on-primary); border: none;
  border-radius: var(--r-sm); padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.music-panel .mp-load:hover { background: var(--primary-press); }

/* ---------- Pubblicità / bonus (Fase 4) ---------- */
/* Banner fisso: in basso al centro su desktop, sotto l'HUD su mobile (per non
   coprire il dock velocità in basso). Placeholder testabile col provider stub. */
#ad-banner {
  position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%);
  z-index: 1050; display: flex; align-items: center; gap: 8px;
  width: min(728px, calc(100vw - 24px)); height: 64px; padding: 0 10px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--el-1); overflow: hidden;
}
#ad-banner.hidden { display: none; }
#ad-banner .ad-ph {
  flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  border: 1px dashed var(--border); border-radius: var(--r-sm);
  background: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,.02) 10px, rgba(255,255,255,.02) 20px);
}
#ad-banner .ad-ph-tag { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
#ad-banner .ad-ph-note { font-size: 12px; color: var(--text-2); }
#ad-banner .ad-remove {
  flex: 0 0 auto; align-self: flex-start; margin-top: 4px;
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: var(--r-sm); padding: 3px 8px; font-size: 11px; cursor: pointer;
}
#ad-banner .ad-remove:hover { background: var(--surface-2); color: var(--text); }

/* Overlay condiviso (video rewarded + acquisto rimuovi-ads): sopra le modali. */
.ad-overlay {
  position: fixed; inset: 0; z-index: 2100; display: flex;
  align-items: center; justify-content: center; padding: 16px;
  background: var(--scrim);
}
.ad-video, .ad-buy {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--el-3);
  width: min(420px, 100%); padding: 16px; text-align: center; color: var(--text);
}
.ad-video-tag, .ad-buy h3 { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.ad-buy h3 { font-size: 18px; letter-spacing: 0; text-transform: none; color: var(--text); margin-bottom: 8px; }
.ad-video-body {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: #000; border-radius: var(--r-sm); padding: 28px 16px; margin-bottom: 12px;
}
.ad-video-spark { font-size: 34px; color: var(--primary); }
.ad-video-msg { font-size: 13px; color: var(--text-2); }
.ad-video-count { font-size: 13px; color: var(--muted); }
.ad-video-count b { color: var(--text); }
.ad-video-skip {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--r-sm); padding: 8px 14px; font-size: 13px; cursor: pointer;
}
.ad-video-skip:disabled { opacity: .45; cursor: default; }
.ad-buy { position: relative; }
.ad-buy-x {
  position: absolute; top: 8px; right: 10px; background: transparent; border: none;
  color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer;
}
.ad-buy p { font-size: 13px; color: var(--text-2); margin: 0 0 12px; }
.ad-buy-price { font-size: 26px; font-weight: 700; color: var(--amber); margin-bottom: 12px; }
.ad-buy-cta {
  width: 100%; background: var(--primary-strong); color: var(--on-primary); border: none;
  border-radius: var(--r-sm); padding: 11px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.ad-buy-cta:hover { background: var(--primary-press); }
.ad-buy-stub { font-size: 11px !important; color: var(--muted) !important; margin: 10px 0 0 !important; }

@media (max-width: 760px) {
  #ad-banner {
    top: calc(var(--hud-h) + 8px); bottom: auto; height: 52px;
    width: calc(100vw - 16px);
  }
}
.music-panel .mp-msg { color: var(--muted); font-size: 12px; min-height: 0; }
.music-panel .mp-msg:empty { display: none; }
.music-panel .mp-frame {
  width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: var(--r-sm);
  background: #000; display: none;
}
.music-panel .mp-hint { color: var(--muted); font-size: 11px; line-height: 1.4; }

@media (max-width: 760px) {
  .music-panel { right: 8px; bottom: 72px; width: calc(100vw - 16px); }
}

/* ============================================================================
   Demo guidata (index, iframe ?demo=1) — nasconde il chrome superfluo e mostra
   il box dialoghi del team esecutivo al posto di tutorial/obiettivi.
   ========================================================================== */
body.demo-mode .hud-menu,
body.demo-mode .hud-clock,
body.demo-mode #map-filter-panel,
body.demo-mode #ad-banner,
body.demo-mode #seg-speed,
body.demo-mode #legend,
body.demo-mode #tutorial,
body.demo-mode #objectives,
body.demo-mode .music-panel { display: none !important; }

#demo-dialog {
  position: absolute; left: 12px; right: 12px; bottom: 14px; z-index: 1600;
  max-width: 460px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-1); border: 2px solid var(--primary);
  border-radius: var(--r); padding: 12px 16px; box-shadow: var(--el-3);
  animation: card-in .25s cubic-bezier(.2,.9,.3,1);
}
#demo-dialog .dd-portrait {
  width: 56px; height: 56px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  border: 2px solid var(--primary); background: var(--surface-2);
}
#demo-dialog .dd-body { min-width: 0; }
#demo-dialog .dd-name { font-weight: 700; font-size: 14px; color: var(--text); }
#demo-dialog .dd-role { font-weight: 400; font-size: 11px; color: var(--muted); margin-left: 6px; }
#demo-dialog .dd-line { font-size: 13px; color: var(--text-2); line-height: 1.35; margin-top: 2px; }
#demo-dialog.done { justify-content: center; text-align: center; border-color: var(--green); }
#demo-dialog .dd-cta-title { font-weight: 700; font-size: 15px; color: var(--text); margin-bottom: 8px; }
#demo-dialog .dd-cta-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 20px;
  border-radius: var(--r-sm); font-weight: 700; font-size: 14px;
  background: var(--primary-strong); color: var(--on-primary);
}
#demo-dialog .dd-cta-btn:hover { background: var(--primary-press); }

@media (max-width: 480px) {
  #demo-dialog { left: 8px; right: 8px; bottom: 8px; padding: 10px 12px; gap: 8px; }
  #demo-dialog .dd-portrait { width: 44px; height: 44px; }
  #demo-dialog .dd-line { font-size: 12px; }
}

/* "Clicca qui" — evidenzia il bottone/pill da cliccare nello step corrente della demo. */
@keyframes demo-pulse-anim {
  0%, 100% { box-shadow: 0 0 0 0 rgba(211,162,75,.75); }
  50%      { box-shadow: 0 0 0 9px rgba(211,162,75,0); }
}
.demo-pulse {
  position: relative; z-index: 5;
  outline: 2px solid var(--primary); outline-offset: 2px;
  border-radius: var(--r-sm);
  animation: demo-pulse-anim 1.1s ease-in-out infinite;
}
/* Variante per i marker sulla mappa (icona o pallino SVG): box-shadow non è
   affidabile sugli elementi SVG, quindi qui pulsa con drop-shadow + scala. */
@keyframes demo-pulse-map-anim {
  0%, 100% { filter: drop-shadow(0 0 2px var(--primary)); transform: scale(1); }
  50%      { filter: drop-shadow(0 0 12px var(--primary)) drop-shadow(0 0 4px #fff); transform: scale(1.3); }
}
.demo-pulse-map {
  animation: demo-pulse-map-anim 1s ease-in-out infinite;
  transform-box: fill-box; transform-origin: center;
}
