/* Marsala TPL — direzione "maiolica siciliana".
   Smalto bianco caldo, cobalto a scala di pagina, ocra per il prossimo bus, verde rame per i mezzi in movimento,
   terracotta per gli avvisi. Atkinson Hyperlegible: pensato per la leggibilità, anche al sole. */

@font-face { font-family: "Atkinson Hyperlegible"; src: url("../fonts/atkinson-hyperlegible-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("../fonts/atkinson-hyperlegible-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  color-scheme: light dark;
  /* chiaro: smalto */
  --glaze: oklch(97.5% 0.012 85);
  --glaze-2: oklch(94.5% 0.02 85);
  --ink: oklch(24% 0.07 262);
  --ink-2: oklch(43% 0.06 262);
  --line: oklch(86% 0.028 85);
  --edge: oklch(58% 0.05 262);
  --cobalt: oklch(37% 0.16 264);
  --cobalt-hi: oklch(48% 0.18 262);
  --on-cobalt: oklch(97% 0.012 85);
  --on-cobalt-2: oklch(86% 0.05 262);
  --ocra: oklch(83% 0.15 85);
  --ocra-soft: oklch(94% 0.06 88);
  --rame: oklch(50% 0.1 172);
  --terra: oklch(48% 0.15 38);
  --terra-soft: oklch(94% 0.04 45);
  --focus: oklch(48% 0.18 262);

  --on-ocra: oklch(24% 0.07 262); /* testo su ocra: resta indaco scuro in entrambi i temi */
  --r: 10px;
  --r-sm: 4px;
  --r-tile: 7px;
  --r-lg: 14px;
  --r-pill: 99px;
  --shadow-float: 0 2px 10px oklch(20% 0.05 262 / 0.28);
  --shadow-modal: 0 8px 28px oklch(20% 0.08 262 / 0.28);
  --shadow-sheet: 0 4px 18px oklch(20% 0.05 262 / 0.35);
  /* colori fissi della mappa e della legenda: uguali in JS (map.js) e non cambiano col tema */
  --map-ink: #14213D;
  --map-idle: #8A93A6;
  --map-glaze: #FBF7EE;
  --map-cobalt: #1B3A94;
  --map-ocra: #F2C14E;
  --tabs-h: 64px;
  --col: 560px;
  --gut: max(16px, calc((100% - var(--col)) / 2));
  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --glaze: oklch(19% 0.045 264);
    --glaze-2: oklch(25% 0.055 264);
    --ink: oklch(95% 0.012 85);
    --ink-2: oklch(77% 0.04 262);
    --line: oklch(33% 0.055 264);
    --edge: oklch(58% 0.07 264);
    --cobalt: oklch(31% 0.15 264);
    --cobalt-hi: oklch(72% 0.13 262);
    --ocra-soft: oklch(30% 0.05 85);
    --rame: oklch(70% 0.11 172);
    --terra: oklch(74% 0.13 45);
    --terra-soft: oklch(28% 0.06 40);
    --focus: oklch(80% 0.12 262);
  }
}
:root[data-theme="dark"] {
  --glaze: oklch(19% 0.045 264);
  --glaze-2: oklch(25% 0.055 264);
  --ink: oklch(95% 0.012 85);
  --ink-2: oklch(77% 0.04 262);
  --line: oklch(33% 0.055 264);
  --edge: oklch(58% 0.07 264);
  --cobalt: oklch(31% 0.15 264);
  --cobalt-hi: oklch(72% 0.13 262);
  --ocra-soft: oklch(30% 0.05 85);
  --rame: oklch(70% 0.11 172);
  --terra: oklch(74% 0.13 45);
  --terra-soft: oklch(28% 0.06 40);
  --focus: oklch(80% 0.12 262);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scrollbar-color: var(--line) transparent; }
body {
  margin: 0; min-height: 100dvh; background: var(--glaze); color: var(--ink);
  font: 400 17px/1.45 var(--font); font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
::selection { background: var(--ocra); color: var(--on-ocra); }
input { caret-color: var(--cobalt-hi); accent-color: var(--cobalt); }
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
.hero :focus-visible { outline-color: var(--ocra); }
.ico { flex: none; }
.tile { flex: none; display: block; border-radius: var(--r-tile); filter: drop-shadow(0 1px 1px oklch(20% 0.05 262 / 0.35)); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 10; background: var(--ocra); color: var(--on-ocra); padding: 10px 14px; border-radius: var(--r); }
.skip:focus { top: 8px; }
.boot { padding: 40px var(--gut); color: var(--ink-2); }
.muted { color: var(--ink-2); }

/* ---------- guscio ---------- */
.app { display: block; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 28px + var(--consent-h, 0px)); outline: none; }
.app > * { padding-inline: var(--gut); }
.app > .map-wrap { padding: 0; }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 5; display: grid; grid-template-columns: repeat(5, 1fr);
  min-height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  padding-inline: max(0px, calc((100% - var(--col)) / 2));
  background: var(--glaze); border-top: 1px solid var(--line);
}
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 48px; padding: 6px 0 4px; text-decoration: none; color: var(--ink-2); font-size: 13px; font-weight: 700; }
.tabs a .ico { padding: 3px 14px; box-sizing: content-box; border-radius: var(--r); transition: background-color 0.2s var(--ease); }
.tabs a { position: relative; }
.tabs a[aria-current] { color: var(--ink); }
.tab-badge { position: absolute; top: 3px; left: calc(50% + 6px); display: grid; place-items: center; min-width: 18px; height: 18px; padding-inline: 5px; border-radius: var(--r-pill); background: var(--terra); color: var(--glaze); font: 700 11px/1 var(--font); }
.tabs a[aria-current] .ico { background: var(--ocra); color: var(--on-ocra); }

/* ---------- campo cobalto ---------- */
.hero {
  position: relative; background: var(--cobalt); color: var(--on-cobalt);
  padding-top: calc(env(safe-area-inset-top) + 20px); padding-bottom: 34px; overflow: hidden;
}
/* striscia di piastrelle sul bordo inferiore del campo: il colore segue lo stato (ok / avviso / offline) */
.hero { --strip: oklch(83% 0.15 85); }
.hero[data-strip="warn"] { --strip: oklch(74% 0.15 45); }
.hero[data-strip="offline"] { --strip: oklch(80% 0.04 262); }
.hero::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 12px; background: var(--strip);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='12' viewBox='0 0 24 12'%3E%3Cpath d='M12 1.500l5 4.500-5 4.500-5-4.500z' fill='none' stroke='%23000' stroke-width='1.400'/%3E%3Ccircle cx='0' cy='6' r='1.300'/%3E%3Ccircle cx='24' cy='6' r='1.300'/%3E%3C/svg%3E") repeat-x left center / 24px 12px;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='12' viewBox='0 0 24 12'%3E%3Cpath d='M12 1.500l5 4.500-5 4.500-5-4.500z' fill='none' stroke='%23000' stroke-width='1.400'/%3E%3Ccircle cx='0' cy='6' r='1.300'/%3E%3Ccircle cx='24' cy='6' r='1.300'/%3E%3C/svg%3E") repeat-x left center / 24px 12px;
}
.hero[data-strip="offline"]::after { opacity: 0.6; }
/* campo di motivo: stesso disegno della piastrella della linea, grande e tenue */
.hero > * { position: relative; }
.hero > .field { position: absolute; right: -50px; top: -30px; width: 380px; height: 380px; color: var(--on-cobalt); opacity: 0.2; pointer-events: none; -webkit-mask-image: radial-gradient(circle at 78% 30%, black 8%, transparent 62%); mask-image: radial-gradient(circle at 78% 30%, black 8%, transparent 62%); }
/* barra di identità della Home: logo e nome dell'app sopra la fermata */
.brandbar { display: flex; align-items: center; gap: 10px; margin: -4px 0 14px; color: var(--on-cobalt-2); font-size: 15px; }
.brandbar img { border-radius: var(--r-tile); flex: none; }
.brandbar b { color: var(--on-cobalt); font-size: 17px; }
/* embed (iframe PalermoHub): niente barre di scorrimento, la barra in basso arriva a bordo display; il pulsante del wrapper in alto a sinistra non copre il titolo */
html.embed { scrollbar-width: none; }
html.embed::-webkit-scrollbar, html.embed body::-webkit-scrollbar { display: none; }
.embed .hero { padding-top: 30px; }
.embed .map-bar { left: 60px; }
.dir-origin { margin: 0 0 2px; font-weight: 700; color: var(--ocra); }
.dir-origin .ico { vertical-align: -1px; }
.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.stopname { min-width: 0; }
.stopname h1 { margin: 0; font-size: 22px; line-height: 1.15; font-weight: 700; text-wrap: balance; overflow-wrap: anywhere; }
.dir { margin: 4px 0 0; font-size: 16px; color: var(--on-cobalt-2); }
.hero-actions { display: flex; gap: 6px; flex: none; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: var(--r); cursor: pointer;
  background: oklch(100% 0 0 / 0.12); color: var(--on-cobalt); transition: background-color 0.15s;
}
.icon-btn:hover { background: oklch(100% 0 0 / 0.2); }
.icon-btn[aria-pressed="true"] { color: var(--ocra); }

.next { margin-top: 22px; }
.next-line { display: flex; align-items: center; gap: 12px; }
.next-head { margin: 0; font-size: 20px; line-height: 1.2; font-weight: 700; text-wrap: balance; overflow-wrap: anywhere; }
.next-when { display: flex; align-items: baseline; gap: 10px; margin: 6px 0 0; color: var(--ocra); line-height: 1; }
.next-when .num { font-size: clamp(64px, 22vw, 96px); font-weight: 700; letter-spacing: -0.03em; }
.next-when .unit { font-size: 28px; font-weight: 700; color: var(--on-cobalt); }
.next-sub { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; font-size: 16px; color: var(--on-cobalt-2); }
.next-empty { padding-top: 6px; }
.empty-title { margin: 0; font-size: 24px; line-height: 1.2; font-weight: 700; text-wrap: balance; }
.empty-sub { margin: 8px 0 0; font-size: 18px; color: var(--ocra); }
.block .empty-title { color: var(--ink); }

.hero-first h1 { margin: 0; font-size: 40px; line-height: 1.05; font-weight: 700; letter-spacing: -0.02em; }
.lead { margin: 12px 0 0; font-size: 19px; color: var(--on-cobalt-2); max-width: 32ch; }
.hero-line { padding-bottom: 30px; }
/* testata compatta delle schermate senza risposta immediata: stessa famiglia del campo cobalto */
.page-head { padding-bottom: 26px; }
.page-head h1 { margin: 0; font-size: 30px; line-height: 1.1; font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; overflow-wrap: anywhere; }
.page-head .back + h1 { margin-top: 2px; }
.page-head .lead { margin-top: 8px; font-size: 17px; max-width: 46ch; }
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin-left: -6px; padding-right: 10px; text-decoration: none; color: var(--on-cobalt-2); font-weight: 700; }
.line-head { display: flex; align-items: center; gap: 14px; margin: 6px 0 18px; }
.line-head h1 { margin: 0; font-size: 24px; line-height: 1.15; font-weight: 700; text-wrap: balance; }

/* ---------- pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 48px; padding: 0 18px;
  border: 0; border-radius: var(--r); background: var(--cobalt); color: var(--on-cobalt); font-weight: 700; font-size: 17px; text-decoration: none; cursor: pointer;
  transition: transform 0.15s var(--ease), background-color 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn-quiet { background: var(--glaze-2); color: var(--ink); }
.btn-on-field { background: var(--ocra); color: var(--on-ocra); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; padding-block: 20px 4px; }
.actions-hero { flex-direction: column; align-items: stretch; padding: 24px 0 0; }
.actions-hero .btn-quiet { background: oklch(100% 0 0 / 0.14); color: var(--on-cobalt); }
.actions-hero .btn:first-child { background: var(--ocra); color: var(--on-ocra); }
.note { margin: 10px 0 0; color: var(--ink-2); font-size: 16px; }
.note-hero { color: var(--on-cobalt-2); }

/* ---------- avvisi ---------- */
.banner { margin: 0; padding-block: 11px; background: var(--ocra-soft); color: var(--ink); font-size: 15px; font-weight: 700; }
.banner.warn { background: var(--terra-soft); color: var(--terra); }

/* ---------- liste ---------- */
.block { padding-block: 22px 6px; }
.block h2 { margin: 26px 0 6px; font-size: 15px; line-height: 1.3; font-weight: 700; color: var(--ink-2); }
.block > h2:first-child, .block > .h1 + h2 { margin-top: 0; }
.h1 { margin: 0 0 18px; font-size: 30px; line-height: 1.1; font-weight: 700; letter-spacing: -0.01em; }
.plain { list-style: none; margin: 0; padding: 0; }
.dim .row-title { color: var(--ink-2); }

.dep-link, .row {
  display: grid; align-items: center; gap: 14px; min-height: 64px; padding-block: 10px; text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.dep-link { grid-template-columns: auto 1fr auto; }
.deps { margin-inline: calc(var(--gut) * -1); }
.deps .dep-link { margin-inline: var(--gut); }
.dep-main { display: flex; flex-direction: column; min-width: 0; }
.dep-when { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.dep-first { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.dep-second { font-size: 15px; color: var(--ink-2); }
.dep-head { font-size: 18px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }

.row { grid-template-columns: 1fr auto; }
.row:has(> .tile) { grid-template-columns: auto 1fr auto; }
.row:has(> .ico:first-child) { grid-template-columns: auto 1fr auto; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-title { font-size: 18px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.row-sub { font-size: 15px; color: var(--ink-2); }
.row-tiles { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.more { min-width: 26px; padding-left: 2px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.chev { color: var(--ink-2); display: grid; }
.row { transition: background-color 0.15s, box-shadow 0.15s; }
/* sfondo di pressione/hover che sborda di 8px ai lati senza spostare filetti e testo */
.row:active, .dep-link:active { --row-bg: color-mix(in srgb, var(--cobalt-hi) 10%, transparent); background: var(--row-bg); box-shadow: -8px 0 0 var(--row-bg), 8px 0 0 var(--row-bg); }
@media (hover: hover) { .row:hover, .dep-link:hover { --row-bg: color-mix(in srgb, var(--cobalt-hi) 7%, transparent); background: var(--row-bg); box-shadow: -8px 0 0 var(--row-bg), 8px 0 0 var(--row-bg); } }
.row:hover .row-title, .dep-link:hover .dep-head { text-decoration: underline; text-underline-offset: 3px; }

.tile-row { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 0; padding: 0; }
.tile-row a { display: block; border-radius: 8px; }

/* ---------- ricerca ---------- */
.field { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px; border: 2px solid var(--edge); border-radius: var(--r); background: var(--glaze-2); color: var(--ink-2); }
.field:focus-within { border-color: var(--cobalt-hi); color: var(--ink); }
.field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; font-size: 18px; padding: 12px 0; }
.field input::placeholder { color: var(--ink-2); opacity: 0.8; }
#results { margin-top: 10px; }

/* ---------- linea ---------- */
.seg { display: flex; gap: 0; margin-block: 18px 0; }
.seg button { flex: 1; min-height: 48px; padding: 6px 10px; border: 2px solid var(--cobalt-hi); background: transparent; color: var(--ink); font-weight: 700; font-size: 15px; line-height: 1.2; cursor: pointer; text-wrap: balance; }
.seg button:first-child { border-radius: var(--r) 0 0 var(--r); }
.seg button:last-child { border-radius: 0 var(--r) var(--r) 0; }
.seg button + button { border-left-width: 0; }
.seg button[aria-selected="true"], .seg button[aria-checked="true"] { background: var(--cobalt); border-color: var(--cobalt); color: var(--on-cobalt); }
.seg-inline { padding-inline: 0; margin-block: 6px 0; }
.app > .seg { padding-inline: var(--gut); }

.chips { list-style: none; display: flex; gap: 8px; margin: 8px calc(var(--gut) * -1) 0; padding: 4px var(--gut) 8px; overflow-x: auto; scroll-snap-type: x proximity; }
.chips { scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips li { scroll-snap-align: start; }
.chips button { min-width: 64px; min-height: 44px; padding: 0 12px; border: 2px solid var(--edge); border-radius: var(--r); background: var(--glaze); font-size: 17px; font-weight: 700; cursor: pointer; }
.chips button[aria-selected="true"] { background: var(--ocra); border-color: var(--ocra); color: var(--on-ocra); }

.route-stops { list-style: none; margin: 8px 0 0; padding: 0; }
.route-stops li { position: relative; padding-left: 30px; }
.route-stops li::before { content: ""; position: absolute; left: 7px; top: 0; bottom: 0; width: 2px; background: var(--cobalt-hi); opacity: 0.55; }
.route-stops li.first::before { top: 50%; }
.route-stops li.last::before { bottom: 50%; }
.route-stops li::after { content: ""; position: absolute; left: 2px; top: 50%; width: 12px; height: 12px; margin-top: -6px; border-radius: 50%; background: var(--glaze); border: 3px solid var(--cobalt-hi); }
.route-stops li.first::after, .route-stops li.last::after { background: var(--cobalt); }
.route-stops a { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding-block: 8px; text-decoration: none; }
.route-stops .st-time { font-weight: 700; }
.route-stops li.past a { color: var(--ink-2); }
.route-stops li.here a { font-weight: 700; background: color-mix(in srgb, var(--cobalt-hi) 14%, transparent); border-radius: 8px; padding-inline: 8px; }

/* ---------- mappa ---------- */
.map-side { display: none; }
.map-wrap { position: relative; height: calc(100dvh - var(--tabs-h) - env(safe-area-inset-bottom)); margin-bottom: calc(-1 * (var(--tabs-h) + env(safe-area-inset-bottom) + 28px + var(--consent-h, 0px))); }
#map { position: absolute; inset: 0; }
.map-bar { position: absolute; left: 12px; right: 64px; top: calc(env(safe-area-inset-top) + 12px); }
.chip { display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 9px 14px; border-radius: var(--r); background: var(--glaze); color: var(--ink); font-size: 15px; font-weight: 700; line-height: 1.25; box-shadow: var(--shadow-float); }
.chip.live::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--rame); box-shadow: 0 0 0 3px var(--glaze), 0 0 0 5px var(--rame); margin-right: 4px; }
/* Comandi mappa: colonna di pulsanti a destra, sotto il cursore di zoom. */
.map-ctrls { position: absolute; right: 10px; top: calc(env(safe-area-inset-top) + 12px); z-index: 2; display: flex; flex-direction: column; gap: 8px; }
.map-btn { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: var(--r); background: var(--glaze); color: var(--cobalt-hi); font: 800 13px/1 var(--font); box-shadow: var(--shadow-float); cursor: pointer; }
.map-btn:hover { background: var(--glaze-2); }
.map-btn[aria-busy='true'] { opacity: 0.55; }
.map-btn[aria-pressed='true'] { background: var(--cobalt); color: var(--on-cobalt); }
.map-zoom { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 40px; padding: 2px 0 12px; border-radius: var(--r-pill); background: var(--glaze); box-shadow: var(--shadow-float); }
.map-zoom-val { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--glaze-2); color: var(--ink); box-shadow: inset 0 0 0 2px var(--cobalt-hi); font: 700 11px/1 var(--font); letter-spacing: -0.02em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.map-zoom-range { appearance: none; -webkit-appearance: none; writing-mode: vertical-lr; direction: rtl; width: 24px; height: 120px; margin: 0; background: transparent; cursor: pointer; }
.map-zoom-range::-webkit-slider-runnable-track { width: 6px; border-radius: var(--r-sm); background: var(--line); }
.map-zoom-range::-moz-range-track { width: 6px; border-radius: var(--r-sm); background: var(--line); }
.map-zoom-range::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-left: -8px; border: 3px solid var(--glaze); border-radius: 50%; background: var(--cobalt); box-shadow: 0 0 0 1.5px var(--edge); }
.map-zoom-range::-moz-range-thumb { width: 16px; height: 16px; border: 3px solid var(--glaze); border-radius: 50%; background: var(--cobalt); box-shadow: 0 0 0 1.5px var(--edge); }
@media (max-height: 640px) { .map-zoom { display: none; } }
.map-wrap .maplibregl-ctrl-bottom-left { bottom: calc(76px + var(--consent-h, 0px)); }
.map-msg { position: absolute; inset: 40% 24px auto; margin: 0; padding: 16px; border-radius: var(--r); background: var(--glaze); text-align: center; font-weight: 700; box-shadow: var(--shadow-float); }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 12px); margin: 0; padding: 12px 18px; border-radius: var(--r); background: var(--ink); color: var(--glaze); font-weight: 700; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.3s var(--ease); z-index: 9; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- movimento: un solo momento, all'apertura di una schermata ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.app.enter .next-when .num, .app.enter .empty-title { animation: rise 0.55s var(--ease) both; }
.app.enter .next-head { animation: rise 0.45s var(--ease) both; }

/* Momenti in più, tutti brevi: dissolvenza tra schermate, stella che "scatta" al salvataggio, cifra che respira quando il bus è imminente. */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 0.18s; animation-timing-function: var(--ease); }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.28) rotate(-8deg); } 100% { transform: scale(1); } }
.icon-btn.pop { animation: pop 0.35s var(--ease); }
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.72; } }
.next-when.soon .num { animation: breathe 1.8s ease-in-out 3; }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 700px) {
  .next-when .num { font-size: 96px; }
  .stopname h1 { font-size: 30px; }
}
/* Schermi larghi: colonna un po' più larga (tab bar e gutter seguono `--col`); la mappa resta a tutto schermo. */
@media (min-width: 900px) { :root { --col: 680px; } .page-head h1 { font-size: 40px; } }
/* Desktop (>= 1000px): due colonne. A sinistra il campo cobalto resta fisso (fermata, linea, titolo di pagina),
   a destra scorrono le liste. La mappa resta a tutto schermo. Barra in basso e banner seguono la stessa larghezza. */
@media (min-width: 1000px) {
  :root { --col: 1080px; --gut: 24px; }
  .app:not(:has(> .map-wrap)) { display: grid; grid-template-columns: 440px minmax(0, 640px); justify-content: center; align-items: start; }
  .app:not(:has(> .map-wrap)) > * { grid-column: 2; }
  .app:not(:has(> .map-wrap)) > .hero { grid-column: 1; grid-row: 1 / span 40; position: sticky; top: 0; align-self: start; min-height: calc(100dvh - var(--tabs-h) - env(safe-area-inset-bottom)); }
  /* schermate con testata di pagina (Linee, Cerca, Altro, Avvisi, Guida, Info): testata a tutta larghezza, contenuto in una colonna centrata */
  .app:has(> .page-head) { display: block; }
  .app:has(> .page-head) > :not(.page-head):not(.banner) { max-width: 688px; margin-inline: auto; }
  .app:has(> .page-head) > .page-head, .app:has(> .page-head) > .banner { padding-inline: max(24px, calc((100% - 640px) / 2)); }
  .app:has(> .page-head) > .page-head { position: static; min-height: 0; }
  /* mappa: stessa larghezza delle altre pagine (440 + 640px, centrata): colonna laterale a sinistra, mappa a destra a tutta altezza; legenda sempre aperta, quindi niente pulsante */
  .app:has(> .map-wrap) { display: grid; grid-template-columns: 440px minmax(0, 640px); justify-content: center; align-items: start; }
  .app > .map-wrap { grid-column: 2; grid-row: 1; }
  .app > .map-side { display: block; grid-column: 1; grid-row: 1; padding-inline: 0; height: calc(100dvh - var(--tabs-h) - env(safe-area-inset-bottom)); overflow-y: auto; background: var(--glaze); }
  .map-side > * { padding-inline: var(--gut); }
  .map-side > .hero { padding-bottom: 26px; }
  .map-side .legend-list { margin-top: 4px; }
  .map-wrap .legend-btn, .map-wrap .legend { display: none; }
  .consent { max-width: 640px; }
}

/* ---------- home ---------- */
.howto { display: grid; gap: 14px; }
.how-row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 14px; }
.how-row p, .howto > p { margin: 0; font-size: 16px; }
.how-row .tile { justify-self: center; }
.sample { display: block; }

/* ---------- pianificatore ---------- */
.plan-h1 { margin: 6px 0 0; font-size: 30px; line-height: 1.1; font-weight: 700; letter-spacing: -0.01em; }
.hero-plan .lead { max-width: 40ch; font-size: 17px; }
.plan-form { padding-top: 20px; }
.pf-label { display: block; margin-bottom: 6px; font-size: 15px; font-weight: 700; color: var(--ink-2); }
.pf-list { margin-top: 2px; }
.pf-list:empty { display: none; }
.row-btn { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; color: inherit; font: inherit; }
.row-btn .row-title { display: inline-flex; align-items: center; gap: 8px; }
.swap-row { display: flex; justify-content: flex-end; margin: 2px 0; }
.icon-btn-quiet { background: var(--glaze-2); color: var(--ink); font-size: 24px; line-height: 1; }
.icon-btn-quiet:hover { background: var(--line); }
.pf-time { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 14px; }
.pf-time .seg { margin: 0; }
.time-in { min-height: 48px; padding: 0 12px; border: 2px solid var(--edge); border-radius: var(--r); background: var(--glaze-2); color: var(--ink); font: inherit; font-size: 18px; font-weight: 700; }
.time-in[hidden] { display: none; }
.plan-out { padding-top: 8px; }
.opts { display: grid; gap: 12px; }
.opt { border: 2px solid var(--line); border-radius: var(--r); background: var(--glaze); }
.opt[open] { border-color: var(--cobalt-hi); }
.opt summary { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; min-height: 64px; padding: 12px 14px; cursor: pointer; list-style: none; }
.opt summary::-webkit-details-marker { display: none; }
.opt-head { display: flex; flex-direction: column; line-height: 1.2; }
.opt-time { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.opt-meta { font-size: 15px; color: var(--ink-2); }
.opt-tiles { display: flex; align-items: center; gap: 4px; }
.plus { color: var(--ink-2); font-weight: 700; }
.steps { list-style: none; margin: 0; padding: 4px 14px 16px; }
.step { position: relative; display: grid; grid-template-columns: 34px 1fr; gap: 10px; padding-block: 8px; font-size: 16px; }
.step::before { content: ""; position: absolute; left: 16px; top: 0; bottom: 0; width: 2px; background: var(--cobalt-hi); opacity: 0.4; }
.step:first-child::before { top: 20px; }
.step-end::before { bottom: calc(100% - 20px); }
.step-dot { justify-self: center; align-self: start; margin-top: 7px; width: 10px; height: 10px; border-radius: 50%; background: var(--glaze); border: 3px solid var(--cobalt-hi); position: relative; z-index: 1; }
.step-tile { position: relative; z-index: 1; }
.step-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.step-sub { font-size: 15px; color: var(--ink-2); }
.step-walk .step-body { color: var(--ink-2); }

/* ---------- mappa: legenda e logo ---------- */
.legend-btn {
  position: absolute; left: 12px; bottom: calc(28px + var(--consent-h, 0px)); display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
  border: 0; border-radius: var(--r); background: var(--glaze); color: var(--ink); font-weight: 700; font-size: 15px; cursor: pointer;
  box-shadow: var(--shadow-float);
}
.legend {
  position: absolute; left: 12px; right: 12px; bottom: calc(82px + var(--consent-h, 0px)); max-width: 420px; padding: 14px 16px 16px; border-radius: var(--r);
  background: var(--glaze); color: var(--ink); box-shadow: var(--shadow-sheet); max-height: calc(100% - 160px); overflow: auto;
}
.legend[hidden] { display: none; }
.legend-top { display: flex; align-items: center; justify-content: space-between; }
.legend-top h2 { margin: 0; font-size: 18px; }
.legend-list { list-style: none; margin: 10px 0 8px; padding: 0; display: grid; gap: 8px; }
.legend-list li { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 12px; font-size: 16px; }
.legend .muted { margin: 0; font-size: 14px; }
.dot { display: block; justify-self: center; border-radius: 50%; }
/* Sagome bus della legenda: stessi colori della mappa (senza linea: inchiostro; in scuro ocra con muso chiaro). */
.bus-unk { fill: var(--map-ink); }
.bus-idle { fill: var(--map-idle); fill-opacity: 0.6; }
.bus-nose { fill: var(--map-ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bus-unk { fill: var(--map-ocra); } :root:not([data-theme="light"]) .bus-nose { fill: var(--map-glaze); } }
:root[data-theme="dark"] .bus-unk { fill: var(--map-ocra); }
:root[data-theme="dark"] .bus-nose { fill: var(--map-glaze); }
.dot-stop { width: 10px; height: 10px; background: var(--map-glaze); box-shadow: 0 0 0 2px var(--map-cobalt); }
.dot-me { width: 14px; height: 14px; background: var(--map-cobalt); box-shadow: 0 0 0 3px oklch(100% 0 0), 0 0 0 10px color-mix(in srgb, var(--map-cobalt) 22%, transparent); }
.osd { position: absolute; right: 10px; bottom: calc(36px + var(--consent-h, 0px)); display: block; padding: 5px; border-radius: var(--r); background: oklch(100% 0 0 / 0.92); box-shadow: var(--shadow-float); line-height: 0; }
.osd img { display: block; width: 36px; height: auto; }
.pf-time .seg button { white-space: nowrap; padding-inline: 18px; }

/* Mezzo sulla linea */
.bus-track p { margin: 0 0 6px; }
.bus-track { position: sticky; top: 0; z-index: 5; background: var(--glaze); border-bottom: 2px solid var(--line); }
.bus-where { display: flex; align-items: center; gap: 10px; font-size: 1.25rem; font-weight: 700; color: var(--ink); }
.bus-meta { color: var(--ink-2); font-size: 0.875rem; }
.route-stops li.here::after { background: var(--ocra); border-color: var(--cobalt); box-shadow: 0 0 0 4px color-mix(in srgb, var(--map-ocra) 45%, transparent); }
.route-stops li.bus-between { padding-block: 6px; min-height: 36px; display: flex; align-items: center; font-weight: 700; }
.route-stops li.bus-between::after { display: none; }
.route-stops li.bus-between span { display: inline-flex; align-items: center; gap: 6px; background: var(--ocra); color: var(--on-ocra); padding: 4px 10px; border-radius: var(--r-pill); }

.bus-alt { margin: 4px 0 8px; }

/* ---------- home: avviso community ---------- */
.community { display: flex; align-items: center; gap: 12px; padding-top: calc(env(safe-area-inset-top) + 12px); padding-bottom: 0; background: var(--cobalt); color: var(--on-cobalt-2); font-size: 14px; line-height: 1.35; }
.community p { margin: 0; max-width: 46ch; }
.osd-chip { flex: none; display: block; padding: 6px; border-radius: var(--r); background: oklch(100% 0 0); box-shadow: 0 1px 6px oklch(20% 0.05 262 / 0.2); line-height: 0; }
.osd-chip img { display: block; width: 32px; height: auto; }

.community-foot { margin-top: 18px; padding-block: 18px 6px; background: transparent; color: var(--ink-2); border-top: 1px solid var(--line); }

/* Riepilogo linea: giorno e statistiche */
.line-stats { padding-top: 14px; }
.day-pick { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink-2); }
.day-pick input { min-height: 44px; padding: 6px 10px; border: 2px solid var(--cobalt-hi); border-radius: var(--r); background: transparent; color: var(--ink); font: inherit; }
.stats { margin: 12px 0 0; display: grid; }
.stats .stat { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; }
.stats .stat:nth-child(odd) { background: color-mix(in srgb, var(--ink) 6%, transparent); border-radius: var(--r); }
.stats dt { color: var(--ink-2); }
.stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- consenso e informativa privacy ---------- */
.consent { position: fixed; inset-inline: 12px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 10px); max-width: var(--col); margin-inline: auto; padding: 12px 14px; border: 2px solid var(--cobalt-hi); border-radius: var(--r); background: var(--glaze); color: var(--ink); box-shadow: var(--shadow-modal); z-index: 8; }
.consent p { margin: 0 0 10px; font-size: 15px; line-height: 1.4; }
.consent a { font-weight: 700; }
.consent-btns { display: flex; gap: 10px; }
.btn-choice { flex: 1; min-height: 44px; background: var(--glaze); color: var(--ink); border: 2px solid var(--cobalt-hi); }
.h3 { margin: 18px 0 8px; font-size: 16px; font-weight: 700; }
.prose p { line-height: 1.5; overflow-wrap: anywhere; }

/* ---------- avvisi ---------- */
.news { display: grid; gap: 10px; }
.news-item a {
  display: grid; gap: 4px; padding: 14px 16px; min-height: 64px; border-radius: var(--r);
  background: var(--glaze-2); color: var(--ink); text-decoration: none;
}
.news-item a:hover { filter: brightness(0.97); }
.news-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 15px; color: var(--ink-2); }
.news-tag { padding: 1px 8px; border-radius: var(--r-pill); background: var(--ocra); color: var(--on-ocra); font-size: 14px; font-weight: 700; }
.news-title { font-size: 18px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.news-sum { font-size: 16px; line-height: 1.4; color: var(--ink-2); }
.news-more { margin-top: 20px; }
.news-more summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 10px 16px;
  border-radius: var(--r); border: 2px solid var(--glaze-2); color: var(--ink); font-size: 18px; font-weight: 700; cursor: pointer; list-style: none;
}
.news-more summary::-webkit-details-marker { display: none; }
.news-more summary svg { transform: rotate(90deg); transition: transform 0.15s var(--ease); }
.news-more[open] summary svg { transform: rotate(-90deg); }
.news-more[open] summary { margin-bottom: 12px; }

/* Info: schede a fisarmonica */
.acc-list { display: grid; gap: 10px; margin-top: 16px; }
.acc { border: 2px solid var(--line); border-radius: var(--r-lg); background: var(--glaze); }
.acc summary { display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 10px 16px; cursor: pointer; list-style: none; }
.acc summary::-webkit-details-marker { display: none; }
.acc-ico { display: grid; place-items: center; flex: none; width: 28px; height: 28px; color: var(--ink-2); }
.acc-t { flex: 1; font-size: 18px; font-weight: 700; line-height: 1.2; }
.acc-pm { position: relative; flex: none; width: 20px; height: 20px; color: var(--ink-2); }
.acc-pm::before, .acc-pm::after { content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 2.5px; margin: -1.25px 0 0 -7px; background: currentColor; border-radius: var(--r-sm); transition: transform 0.15s var(--ease); }
.acc-pm::after { transform: rotate(90deg); }
.acc[open] .acc-pm::after { transform: rotate(0); }
.acc-body { padding: 0 16px 16px; }
.acc-body > :first-child { margin-top: 0; }
.acc-body .h3 { margin-top: 16px; }
.guide-body p { margin: 0 0 12px; line-height: 1.5; }
.guide-steps { margin: 0 0 14px; padding-left: 1.5em; display: grid; gap: 10px; line-height: 1.5; }
.guide-steps li::marker { font-weight: 700; color: var(--ink-2); }
.guide-tip { padding: 10px 12px; border-left: 4px solid var(--ocra); background: color-mix(in srgb, var(--ink) 6%, transparent); border-radius: var(--r-sm); }
.guide-shot { margin: 14px 0 0; text-align: center; }
.guide-shot img { width: min(100%, 280px); height: auto; border: 2px solid var(--line); border-radius: var(--r-lg); }
.info-links { display: grid; gap: 8px; }
.info-link { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 14px; border: 2px solid var(--line); border-radius: var(--r); color: var(--ink); font-weight: 700; text-decoration: none; }
.info-link span { flex: 1; }
.info-link:hover { background: var(--glaze-2); }
.row .news-tag { margin-left: 6px; vertical-align: 2px; background: var(--terra); color: var(--glaze); }
