/* BENCH20 – grafica ispirata ai cartelli delle fermate: giallo palina, blu notte, numeri di linea come targhe.
   Un solo elemento forte (il cartello in cima), tutto il resto quieto: righe separate da filetti, comandi grandi.

   Carattere: Atkinson Hyperlegible, disegnato dal Braille Institute per chi vede poco (lettere ben distinte: 1 l I, 0 O).
   Si usa se è installato sul dispositivo; altrimenti il carattere del telefono. Per includerlo nel sito (licenza OFL):
   metti AtkinsonHyperlegible-Regular.woff2 e -Bold.woff2 nella cartella fonts/ e aggiungi, dopo i local(...),
   ', url("../fonts/AtkinsonHyperlegible-Regular.woff2") format("woff2")' (e lo stesso per il Bold).
   Senza i file non va aggiunto, altrimenti il browser segnala errori 404. */
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: local("Atkinson Hyperlegible"), local("AtkinsonHyperlegible-Regular");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: local("Atkinson Hyperlegible Bold"), local("AtkinsonHyperlegible-Bold");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bench20-version: "0.11"; /* deve essere uguale a quella di index.html e js/app.js */
  color-scheme: light;
  --bg: #f5f7fa;        /* bianco freddo, come la lamiera dei cartelli */
  --card: #ffffff;
  --ink: #0d1b2a;       /* blu notte */
  --muted: #3b4a5e;
  --rule: #6b7a8f;      /* filetti: almeno 3:1 sullo sfondo */
  --edge: #0d1b2a;
  --accent: #0a4aa6;    /* targhe delle linee */
  --on-accent: #ffffff;
  --mark: #ffd400;      /* giallo palina */
  --on-mark: #0d1b2a;
  --focus: #0a4aa6;
  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

/* Colori: quelli del telefono (tema chiaro o scuro). Il contrasto elevato del sistema è gestito in fondo (forced-colors). */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b1422;
    --card: #13213a;
    --ink: #f5f7fa;
    --muted: #c3cdd9;
    --rule: #5c6e88;
    --edge: #f5f7fa;
    --accent: #ffd400;
    --on-accent: #0d1b2a;
    --focus: #ffd400;
  }
}

/* Dimensione del testo scelta nelle impostazioni: tutto è in rem, quindi cresce insieme. */
:root[data-size="grande"] { font-size: 125%; }
:root[data-size="molto-grande"] { font-size: 150%; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1.125rem/1.5 var(--font);
}

.top, main, footer {
  max-width: 36rem;
  margin-inline: auto;
  padding-inline: 1rem;
}

main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; padding-bottom: 2rem; }

/* Registro di prova della voce (?debug=voce). */
.debug { max-width: 36rem; margin: 0 auto 2rem; padding: 0 1rem; display: grid; gap: 0.5rem; }
.debug pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; padding: 0.75rem; border: 2px solid var(--rule); border-radius: 0.5rem; font-size: 0.9rem; }

/* Messaggio mostrato quando i file sul server non sono tutti della stessa versione. */
.stale { max-width: 36rem; margin: 1rem auto 0; padding: 1rem; border: 3px solid var(--edge); border-radius: 0.75rem; font-weight: 700; }

/* ---------- intestazione ---------- */
.top { padding-top: 1rem; padding-bottom: 0.75rem; }
h1 { margin: 0; font-size: 1.125rem; font-weight: 700; line-height: 1.3; }
.stop { margin: 0; color: var(--muted); font-size: 1rem; overflow-wrap: break-word; }
h2 { margin: 0; font-size: 1.25rem; line-height: 1.25; }

/* ---------- il cartello ---------- */
.sign {
  background: var(--mark);
  color: var(--on-mark);
  border: 3px solid var(--on-mark);
  border-radius: 1rem;
  padding: 1rem 1.125rem 1.125rem;
}
.sign-body {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "plate when" "dest dest";
  align-items: center;
  column-gap: 0.875rem;
  row-gap: 0.5rem;
}
.sign-when {
  grid-area: when;
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: 700;
  line-height: 1.05;
  overflow-wrap: break-word;
}
.sign-dest { grid-area: dest; font-size: 1.25rem; font-weight: 700; overflow-wrap: break-word; }
.sign-dest:empty { display: none; }
/* Cartello stretto (telefono piccolo o testo molto grande): targa sopra, minuti sotto, così le parole non si spezzano. */
.sign { container-type: inline-size; }
@container (max-width: 18rem) {
  .sign-body { grid-template-columns: minmax(0, 1fr); grid-template-areas: "plate" "when" "dest"; justify-items: start; }
}

/* Senza targa (nessun passaggio, messaggi) il testo occupa tutta la riga. */
.sign-body:has(.plate[hidden]) .sign-when { grid-column: 1 / -1; font-size: 1.5rem; line-height: 1.3; }

/* Pullman in arrivo adesso: il cartello si inverte (blu notte e giallo), senza animazioni. */
.sign--now { background: var(--on-mark); color: var(--mark); border-color: var(--mark); }
.sign--now .plate--sign { background: var(--mark); color: var(--on-mark); }

/* ---------- targa della linea ---------- */
.plate {
  display: inline-grid;
  place-items: center;
  min-width: 3.5rem;
  min-height: 3rem;
  padding: 0.125rem 0.5rem;
  border-radius: 0.375rem;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.plate--sign {
  grid-area: plate;
  min-width: 4.25rem;
  min-height: 3.75rem;
  font-size: 2rem;
  background: var(--on-mark);
  color: var(--mark);
}

/* ---------- avviso sui dati ---------- */
.notice {
  margin: -0.5rem 0 0;
  padding-left: 0.75rem;
  border-left: 4px solid var(--rule);
  color: var(--muted);
  font-size: 1rem;
  overflow-wrap: break-word;
}

/* Messaggio se la lettura ad alta voce non parte. Vuoto = non occupa spazio. */
.speak-status { margin: -0.5rem 0 0; font-weight: 700; }
.speak-status:empty { display: none; }

/* ---------- pulsanti ---------- */
/* Affiancati se c'è spazio, uno sotto l'altro su schermi stretti o con testo molto grande. */
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr)); gap: 0.75rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3.5rem;
  padding: 0.75rem 1rem;
  border: 3px solid var(--edge);
  border-radius: 0.75rem;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  min-width: 0;
  overflow-wrap: break-word;
}
.btn svg { width: 1.5rem; height: 1.5rem; flex: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--primary.is-active { background: var(--card); color: var(--ink); border-color: var(--edge); }
.btn--quiet { justify-self: start; min-height: 3rem; border-width: 2px; font-weight: 400; }
.btn:active { transform: translateY(1px); }

/* ---------- elenco dei passaggi ---------- */
.arrivi { display: grid; gap: 0.75rem; }
.status { margin: -0.5rem 0 0; color: var(--muted); font-size: 1rem; }

.tools { display: grid; gap: 0.75rem; }

.board { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--rule); }
.board li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  column-gap: 0.875rem;
  padding: 0.875rem 0;
  border-bottom: 2px solid var(--rule);
}
.board .badge {
  display: inline-grid;
  place-items: center;
  min-width: 3.5rem;
  min-height: 3rem;
  padding: 0.125rem 0.5rem;
  border-radius: 0.375rem;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}
/* L'ordine nel codice resta quello letto ad alta voce (destinazione, minuti, orario);
   sullo schermo i minuti vanno in alto, in grande. */
.info {
  display: grid;
  grid-template-areas: "when" "dest" "at" "note";
  min-width: 0;
  overflow-wrap: break-word;
}
.when { grid-area: when; font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.dest { grid-area: dest; font-weight: 700; }
.at { grid-area: at; color: var(--muted); font-variant-numeric: tabular-nums; }
.note { grid-area: note; color: var(--muted); font-size: 1rem; }

/* ---------- campi ---------- */
.field { display: grid; gap: 0.375rem; }
.field label { font-weight: 700; }
.field select {
  width: 100%;
  min-width: 0;
  min-height: 3.25rem;
  padding: 0.5rem 0.75rem;
  border: 3px solid var(--edge);
  border-radius: 0.75rem;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}
.hint { margin: 0; color: var(--muted); font-size: 1rem; }
.field textarea {
  width: 100%;
  min-width: 0;
  padding: 0.625rem 0.75rem;
  border: 3px solid var(--edge);
  border-radius: 0.75rem;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  resize: vertical;
}
/* Errore: testo in grassetto con una barra a sinistra, non solo un colore. */
.error { margin: 0; padding-left: 0.75rem; border-left: 4px solid currentColor; font-weight: 700; }
.field textarea[aria-invalid="true"] { border-width: 4px; border-style: double; }
.preview { margin: 0.5rem 0 0; padding-left: 1.25rem; display: grid; gap: 0.25rem; color: var(--muted); font-size: 1rem; overflow-wrap: anywhere; }

/* Scelta "Per orario / Per linea": due metà di un solo blocco. I pulsanti radio veri restano (tastiera e lettori). */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0;
  padding: 0;
  border: 3px solid var(--edge);
  border-radius: 0.75rem;
  overflow: hidden;
  min-width: 0;
  position: relative;
}
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented label {
  display: grid;
  place-items: center;
  min-height: 3rem;
  padding: 0.5rem;
  text-align: center;
  font-weight: 700;
  cursor: pointer;
}
.segmented label + input + label { border-left: 3px solid var(--edge); }
.segmented input:checked + label { background: var(--ink); color: var(--bg); }
.segmented input:focus-visible + label { outline: 4px solid var(--focus); outline-offset: -7px; }
.segmented:disabled { opacity: 0.55; }
.segmented:disabled label { cursor: not-allowed; }

/* Interruttori (suono, vibrazione): una casella vera con l'aspetto di un interruttore. */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3rem; font-weight: 700; }
.switch span { order: -1; min-width: 0; overflow-wrap: break-word; }
.switch input {
  appearance: none;
  flex: none;
  width: 3.5rem;
  height: 2rem;
  margin: 0;
  border: 3px solid var(--edge);
  border-radius: 1rem;
  background: var(--card);
  position: relative;
  cursor: pointer;
}
.switch input::before {
  content: "";
  position: absolute;
  top: 0.1875rem;
  left: 0.1875rem;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.15s;
}
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::before { background: var(--on-accent); transform: translateX(1.5rem); }
.switch input:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- sezioni che si aprono ---------- */
.more { border-top: 2px solid var(--rule); }
.more:last-of-type { border-bottom: 2px solid var(--rule); }
.more summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 3.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::after {
  content: "";
  width: 0.75rem;
  height: 0.75rem;
  margin-right: 0.375rem;
  border-right: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s;
}
.more[open] summary::after { transform: rotate(-135deg); }
.stack { display: grid; gap: 1rem; padding-bottom: 1.25rem; }
.where { margin: 0; padding: 0 0 1.25rem 1.25rem; display: grid; gap: 0.5rem; }

/* ---------- piè di pagina ---------- */
footer { padding-bottom: 2rem; color: var(--muted); font-size: 0.9375rem; }

/* ---------- accessibilità ---------- */
a:focus-visible, button:focus-visible, select:focus-visible, summary:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -5rem;
  z-index: 10;
  padding: 0.75rem 1rem;
  background: var(--mark);
  color: var(--on-mark);
  font-weight: 700;
}
.skip:focus { top: 1rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (forced-colors: active) {
  .sign, .btn, .board .badge, .plate, .field select, .field textarea, .segmented, .switch input { border: 2px solid CanvasText; }
  .segmented input:checked + label { outline: 3px solid Highlight; outline-offset: -6px; }
}