:root {
  --bg: #0e141b;
  --panel: #161f2b;
  --panel2: #1d2937;
  --line: #2a3a4d;
  --text: #e6edf3;
  --muted: #8aa0b5;
  --accent: #4ec9b0;
  --gold: #e0c060;
  --bad: #e06060;
  --ok: #6fcf6f;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, "Segoe UI", Inter, sans-serif; color: var(--text); }
/* Layout a colonna: header in alto (flusso normale), mappa sotto → niente sovrapposizioni */
body { display: flex; flex-direction: column; background: var(--bg); }
#map { flex: 1 1 auto; position: relative; min-height: 0; background: #0a0f15; }

/* Leaflet dark-ish tweak */
.leaflet-container { background: #0a0f15; }
.leaflet-control-zoom a { background: var(--panel2); color: var(--text); border-color: var(--line); }
.leaflet-control-zoom a:hover { background: var(--panel); color: var(--accent); }

/* ---------- HUD (header) ---------- */
#hud {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 16px;
  background: linear-gradient(180deg, #131b25 0%, #0f161e 100%);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
  font-feature-settings: "tnum"; /* cifre tabulari: numeri che non "ballano" */
}

/* Brand */
.hud-brand { display: flex; align-items: center; gap: 10px; }
.hud-brand .logo {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  font-size: 18px; background: linear-gradient(135deg, var(--accent), #2f8f7d);
  box-shadow: 0 2px 8px rgba(78,201,176,.35); flex-shrink: 0;
}
.hud-brand .brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.hud-brand strong { font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.hud-brand strong .accent { color: var(--accent); }
.hud-brand small { font-size: 10px; color: var(--muted); letter-spacing: 1.5px; text-transform: uppercase; }

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

/* Saldo */
.hud-money { display: flex; align-items: baseline; gap: 5px; }
.hud-money .coin { color: var(--gold); font-size: 15px; font-weight: 700; }
.hud-money b { font-size: 22px; font-weight: 700; color: var(--gold); letter-spacing: .3px; }

/* KPI chips */
.hud-group { display: flex; align-items: center; gap: 4px; }
.kpi { display: flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 8px; }
.kpi:hover { background: rgba(255,255,255,.03); }
.kpi-ico { font-size: 14px; opacity: .9; }
.kpi-val { display: flex; flex-direction: column; line-height: 1; }
.kpi-val b { font-size: 15px; font-weight: 700; }
.kpi-val small { font-size: 10px; color: var(--muted); margin-top: 2px; }
.kpi.ok b { color: var(--ok); }
.kpi.bad b { color: var(--bad); }

/* Orologio */
.hud-clock { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.hud-clock b { color: var(--text); font-weight: 600; }

/* Gruppi di bottoni segmentati */
.seg { display: inline-flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button {
  background: transparent; color: var(--text); border: 0; border-right: 1px solid var(--line);
  padding: 7px 11px; cursor: pointer; font-size: 13px; line-height: 1; transition: background .12s, color .12s;
}
.seg button:last-child { border-right: 0; }
.seg button:hover:not(:disabled) { background: rgba(78,201,176,.12); color: var(--accent); }
.seg button.active { background: var(--accent); color: #06201a; font-weight: 700; }
.seg button:disabled { opacity: .35; cursor: not-allowed; }
.seg.actions button { font-size: 12px; color: var(--muted); }
.seg.actions button:hover { color: var(--text); }

/* Compattazione elegante su schermi più stretti (no overflow/taglio) */
@media (max-width: 1200px) {
  #hud { gap: 12px; }
  .kpi-val small { display: none; }
  .kpi { gap: 5px; padding: 5px 7px; }
}
@media (max-width: 980px) {
  #hud { gap: 9px; padding: 0 10px; }
  .hud-brand small { display: none; }
  .hud-clock { display: none; }
}

/* ---------- Panel ---------- */
#panel {
  position: absolute; top: 70px; right: 14px; z-index: 1000; width: 300px;
  max-height: calc(100% - 90px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
#panel.hidden, #hint.hidden { display: none; }
#panel h2 { margin: 0 0 2px; font-size: 18px; }
#panel .sub { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
#panel .sect { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
#panel .sect h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.pill {
  flex: 1 1 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 6px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; cursor: pointer; font-size: 13px;
}
.pill:hover:not(.disabled) { border-color: var(--accent); }
.pill.disabled { opacity: .45; cursor: not-allowed; }
.pill .cost { color: var(--gold); font-size: 12px; }
.pill.owned { border-color: var(--ok); }
.badge { display: inline-block; font-size: 10px; padding: 2px 7px; border-radius: 20px; font-weight: 700; }
.b-bloccata { background: #33414f; color: #9fb3c7; }
.b-disponibile { background: #4a4320; color: var(--gold); }
.b-sbloccata { background: #1d3a52; color: #6db4f0; }
.b-collegata { background: #1c4030; color: var(--ok); }
/* Righe rotta: info a sinistra, pulsanti − / + a destra sulla stessa riga */
.route-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 9px; margin-bottom: 6px;
}
.route-info { flex: 1 1 auto; min-width: 0; }
.route-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.route-sub .net { color: var(--ok); }
.route-btns { display: flex; gap: 5px; flex-shrink: 0; }
.rbtn {
  width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--line);
  background: #233141; color: var(--text); font-size: 18px; line-height: 1; cursor: pointer;
  display: grid; place-items: center; transition: background .12s, border-color .12s;
}
.rbtn:hover:not(.disabled) { border-color: var(--accent); }
.thr-btn {
  height: 30px; padding: 0 8px; border-radius: 7px; border: 1px solid var(--line);
  background: #233141; color: var(--gold); font-size: 12px; font-weight: 600; cursor: pointer;
  white-space: nowrap; min-width: 34px;
}
.thr-btn:hover { border-color: var(--accent); }
.rbtn.buy { background: #1c3b32; color: var(--ok); }
.rbtn.buy:hover:not(.disabled) { background: #234a3e; }
.rbtn.disabled { opacity: .35; cursor: not-allowed; }

.closex { float: right; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; }
.closex:hover { color: var(--text); }
.muted { color: var(--muted); font-size: 12px; }
.qrow { display: flex; justify-content: space-between; align-items: center; padding: 3px 2px; font-size: 13px; border-bottom: 1px dashed var(--line); }
.qrow:last-child { border-bottom: none; }
.qrow b { color: var(--gold); }
.qrow b.urgent { color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* Icone veicoli in movimento (bus/treno/aereo) */
.veh-icon {
  font-size: 15px; line-height: 15px; text-align: center;
  filter: drop-shadow(0 0 2px #000) drop-shadow(0 0 2px #000);
  pointer-events: auto;
}

/* ---------- Hint + Toast ---------- */
#hint {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 1000; background: var(--gold); color: #1a1400; font-weight: 600;
  padding: 8px 16px; border-radius: 20px; font-size: 13px; box-shadow: 0 6px 18px rgba(0,0,0,.4);
}
#toast {
  position: absolute; bottom: 56px; left: 50%; transform: translateX(-50%);
  z-index: 1001; display: flex; flex-direction: column; gap: 6px; align-items: center;
  pointer-events: none;
}
.toast-item {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.4);
  animation: fade 3s forwards;
}
.toast-item.err { border-color: var(--bad); color: #ffc9c9; }
@keyframes fade { 0%{opacity:0;transform:translateY(8px);} 10%{opacity:1;transform:none;} 80%{opacity:1;} 100%{opacity:0;} }

/* ---------- Modale (classifica) ---------- */
#modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(6, 10, 14, .66); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
#modal.hidden { display: none; }
.modal-card {
  width: 420px; max-width: calc(100vw - 32px); max-height: calc(100vh - 80px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.6); position: relative;
}
.modal-card h2 { margin: 0 0 12px; font-size: 20px; }
.modal-body { min-height: 60px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.btn-primary {
  flex: 1; background: var(--accent); color: #06201a; border: 0; border-radius: 9px;
  padding: 10px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 16px; cursor: pointer; font-size: 14px;
}
.btn-ghost:hover { border-color: var(--accent); }
table.lb { width: 100%; border-collapse: collapse; font-size: 13px; }
table.lb th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .5px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.lb td { padding: 7px 8px; border-bottom: 1px solid rgba(42,58,77,.5); }
table.lb tr.top3 td { color: var(--gold); }
table.lb tr.top3 td b { color: var(--gold); }
table.lb tbody tr:hover { background: rgba(255,255,255,.03); }
.modal-card code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* City labels on map */
.city-label { font-size: 11px; color: #cfe; text-shadow: 0 0 3px #000, 0 0 3px #000; font-weight: 600; }
