:root {
  --blu-laguna: #0a3d62;
  --blu-acqua: #3c6e91;
  --sabbia: #e8dfc4;
  --rosso-alert: #d33;
  --verde: #2ecc71;
  --bg: #f4f1e8;
  --testo: #1a1a1a;
  --panel-bg: rgba(255, 255, 255, 0.96);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--testo);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* ---------- Splash ---------- */
#splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: linear-gradient(160deg, var(--blu-laguna) 0%, var(--blu-acqua) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  color: #fff;
}

.splash-card {
  max-width: 480px;
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 1.75rem 1.5rem;
}

.splash-card h1 {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.splash-card h2 {
  font-size: 1.05rem;
  font-weight: 400;
  opacity: 0.85;
  margin-bottom: 1.25rem;
}

.warning {
  background: rgba(211, 51, 51, 0.15);
  border-left: 3px solid var(--rosso-alert);
  padding: 0.85rem 0.95rem;
  font-size: 0.87rem;
  line-height: 1.5;
  margin-bottom: 1rem;
  border-radius: 4px;
}

.warning strong { color: #ffcf2e; }

.chk {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.92rem;
  margin-bottom: 1.1rem;
  cursor: pointer;
  user-select: none;
}

.chk input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--verde);
}

#btn-start {
  width: 100%;
  padding: 0.85rem;
  background: var(--verde);
  border: none;
  color: #fff;
  font-size: 1.02rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.08s;
}

#btn-start:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#btn-start:not(:disabled):active { transform: scale(0.98); }

/* ---------- HUD navigazione ---------- */
#hud {
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 0;
  right: 0;
  z-index: 10;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  padding: 0.65rem 0.95rem;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  border-bottom: 2px solid var(--blu-laguna);
}

.hud-line {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.hud-line.small {
  grid-column: 1 / -1;
  flex-direction: row;
  justify-content: center;
  font-size: 0.82rem;
  color: var(--blu-laguna);
  padding-top: 0.3rem;
  border-top: 1px dashed rgba(0, 0, 0, 0.1);
  margin-top: 0.1rem;
}

.hud-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #666;
}

#hud-speed, #hud-limit, #hud-dist {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--blu-laguna);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

#hud-speed.over {
  color: var(--rosso-alert);
  animation: pulse 0.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.hud-unit {
  font-size: 0.7rem;
  color: #888;
}

/* ---------- Sticky route pills A/B ---------- */
#sticky-routes {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0) + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  gap: 0.3rem;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  padding: 0.25rem;
  border-radius: 22px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.sticky-route-pill {
  border: none;
  background: transparent;
  color: var(--blu-laguna);
  width: 38px;
  height: 32px;
  border-radius: 18px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.sticky-route-pill.active {
  background: var(--blu-laguna);
  color: #fff;
}
.sticky-route-pill[data-variant="B"].active {
  background: #7e3ff2;
}
body.nav-active #sticky-routes {
  top: calc(env(safe-area-inset-top, 0) + 88px);
}

/* ---------- Toast non-bloccante ---------- */
.toast {
  position: fixed;
  bottom: 8rem;
  left: 50%;
  transform: translate(-50%, 20px);
  z-index: 100;
  background: rgba(0,0,0,0.88);
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: 8px;
  font-size: 0.88rem;
  max-width: 80%;
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast-error { background: rgba(192,57,43,0.95); }

/* ---------- Marea widget ---------- */
#marea-widget {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0) + 1rem);
  left: 1rem;
  z-index: 11;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  font-size: 0.83rem;
  max-width: 60%;
  border-left: 3px solid #2196f3;
  transition: top 0.2s;
}
body.nav-active #marea-widget {
  top: calc(env(safe-area-inset-top, 0) + 130px);
}
.marea-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.marea-row.small {
  font-size: 0.72rem;
  color: #666;
  margin-top: 0.15rem;
}
.marea-label {
  font-weight: 600;
  color: var(--blu-laguna);
}
.marea-value {
  font-weight: 700;
  font-size: 1rem;
  color: var(--blu-acqua);
  font-variant-numeric: tabular-nums;
}
.marea-value.high { color: var(--rosso-alert); }
.marea-value.low { color: #c0392b; }
.marea-update {
  font-style: italic;
}
.forecast {
  border-top: 1px dashed rgba(0,0,0,0.1);
  padding-top: 0.25rem;
  margin-top: 0.25rem;
  font-size: 0.72rem;
}
#meteo-widget {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0) + 1rem);
  right: 4.5rem;
  z-index: 11;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  font-size: 0.78rem;
  border-left: 3px solid #2196f3;
  transition: top 0.2s;
}
body.nav-active #meteo-widget {
  top: calc(env(safe-area-inset-top, 0) + 130px);
}
.meteo-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.meteo-row.warning {
  color: var(--rosso-alert);
  font-weight: 600;
}
#meteo-wind-arrow {
  display: inline-block;
  font-size: 0.95rem;
  font-weight: 700;
  color: #2196f3;
  transition: transform 0.3s;
}

/* ---------- Alert velocità ---------- */
#alert-speed {
  position: fixed;
  top: 30%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--rosso-alert);
  color: #fff;
  padding: 1rem 1.4rem;
  border-radius: 8px;
  font-size: 1.15rem;
  font-weight: 700;
  box-shadow: 0 4px 20px rgba(211, 51, 51, 0.4);
  animation: shake 0.35s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(-50%); }
  25% { transform: translate(-55%, 0); }
  75% { transform: translate(-45%, 0); }
}

/* ---------- Toolbar ---------- */
#toolbar {
  position: fixed;
  bottom: env(safe-area-inset-bottom, 1rem);
  bottom: calc(env(safe-area-inset-bottom, 0) + 1rem);
  right: 1rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#toolbar button {
  width: 60px;
  min-height: 56px;
  border-radius: 14px;
  border: none;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  color: var(--blu-laguna);
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
}
#toolbar button .i { font-size: 1.15rem; line-height: 1; }
#toolbar button .l {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
}

#toolbar button.panel-active {
  background: var(--blu-laguna) !important;
  color: #fff !important;
}

#toolbar-extra {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#btn-nav {
  background: var(--verde) !important;
  color: #fff !important;
}
#btn-nav .l { font-weight: 700; }

#btn-nav.active {
  background: var(--rosso-alert) !important;
}

#toolbar button:active { transform: scale(0.94); }

/* ---------- Panel ---------- */
.panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  max-height: 65vh;
  overflow-y: auto;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
  padding-bottom: calc(env(safe-area-inset-bottom, 0) + 4rem);
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem 0.5rem;
  border-bottom: 1px solid #eee;
}

.panel-head h3 {
  font-size: 1.05rem;
  color: var(--blu-laguna);
}

.close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: #666;
  padding: 0.25rem 0.5rem;
}

.panel-body {
  padding: 0.9rem 1rem 1.2rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.panel-body p { margin-bottom: 0.6rem; }
.panel-body h4 {
  font-size: 0.95rem;
  color: var(--blu-laguna);
  margin: 0.9rem 0 0.4rem;
}
.panel-body ol, .panel-body ul {
  padding-left: 1.3rem;
  margin-bottom: 0.6rem;
}
.panel-body small { color: #666; font-size: 0.8rem; }

.fine-print {
  font-size: 0.75rem;
  color: #666;
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px solid #eee;
}

/* Legenda */
.legend {
  list-style: none;
  padding: 0;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0;
}
.sw {
  display: inline-block;
  width: 28px;
  height: 6px;
  border-radius: 3px;
}
.sw-5 { background: #c0392b; }
.sw-7 { background: #e67e22; }
.sw-11 { background: #f1c40f; }
.sw-20 { background: #27ae60; }
.sw-route { background: var(--blu-laguna); height: 5px; border: 1px solid #fff; }

/* Badges segnaletica */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-right: 0.2rem;
  color: #fff;
}
.badge.white { background: #ecf0f1; color: #333; border: 1px solid #999; }
.badge.green { background: #27ae60; }
.badge.red { background: #c0392b; }

.highlight {
  background: #fff7d1;
  border-left: 3px solid #f39c12;
  padding: 0.6rem 0.7rem;
  border-radius: 4px;
  font-size: 0.88rem;
}

/* Avvertenze */
.warn-item {
  border-left: 3px solid #e67e22;
  padding: 0.35rem 0.7rem;
  margin-bottom: 0.85rem;
  background: #fef6ef;
  border-radius: 0 4px 4px 0;
}
.warn-h {
  font-weight: 700;
  color: #c0392b;
  margin-bottom: 0.25rem;
  font-size: 0.92rem;
}
.warn-item p {
  font-size: 0.83rem;
  line-height: 1.45;
  margin: 0;
}

code {
  background: #f0f0f0;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.85em;
  font-family: Menlo, Consolas, monospace;
}

/* Route switch */
.route-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin: 0.6rem 0 0.8rem;
}
.route-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.55rem 0.7rem;
  background: #f0f0f0;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  font-size: 0.82rem;
  color: #333;
  transition: all 0.15s;
}
.route-btn strong {
  color: var(--blu-laguna);
  font-size: 0.92rem;
}
.route-btn small {
  color: #666;
  font-size: 0.72rem;
  margin-top: 0.15rem;
}
.route-btn.active {
  background: #e3f2fd;
  border-color: var(--blu-laguna);
  box-shadow: 0 1px 4px rgba(10,61,98,0.2);
}
.route-btn.active strong { color: var(--rosso-alert); }
.info-note {
  font-size: 0.82rem;
  color: #555;
  line-height: 1.4;
}

/* MILVA Gallery */
.milva-card {
  margin: 0.6rem 0;
  padding: 0.5rem;
  background: #f8f4e8;
  border-radius: 6px;
  border-left: 3px solid #b8860b;
}
.milva-title {
  font-weight: 600;
  font-size: 0.85rem;
  color: #0a3d62;
  margin-bottom: 0.4rem;
}
.milva-thumbs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
}
.milva-thumbs a {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: 4px;
  border: 1px solid #ccc;
  text-decoration: none;
  aspect-ratio: 1;
}
.milva-thumbs img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.milva-thumbs span {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(10, 61, 98, 0.85);
  color: #fff;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
}
