:root {
  --sfondo: #eef4f4;
  --superficie: #ffffff;
  --testo: #10303a;
  --testo-2: #4c666e;
  --bordo: #d5e2e4;
  --accento: #004f66;        /* petrolio: colore predefinito, sostituito dal colore dell'evento */
  --accento-scuro: #003747;
  --accento-tenue: #e2f3ee;  /* verde acqua molto chiaro */
  --stand: #dfe8ea;
  --stand-hover: #c8dadd;
  --stand-match: #a6dccd;
  --percorso: #004f66;
  --percorso-tenue: #70bfac; /* verde acqua */
  --partenza: #f08a24;
  --qui: #e0402a;
  --evidenzia: #c4e9de;
  --raggio: 14px;
  --ombra: 0 6px 24px rgba(0, 48, 62, .16), 0 1px 3px rgba(0, 48, 62, .1);
  --testata-h: 76px;
  --pannello-w: 380px;
  --tocco: 44px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  color: var(--testo);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sfondo);
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--accento);
  outline-offset: 2px;
}

svg.icona {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ------------------------------------------------------------ mappa */

#mappa-area {
  position: fixed;
  inset: 0;
}

#mappa {
  position: absolute;
  inset: 0;
  background: var(--superficie);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
#mappa:active { cursor: grabbing; }
#mappa:focus-visible { outline-offset: -3px; }

#mappa > svg {
  display: block;
  width: 100%;
  height: 100%;
}

#mappa .stand { cursor: pointer; }
#mappa .stand-shape {
  fill: var(--stand);
  stroke: var(--superficie);
  stroke-width: .15;
  transition: fill .15s, opacity .15s;
}
#mappa .stand:hover .stand-shape { fill: var(--stand-hover); }
#mappa .stand text { fill: var(--testo); stroke: none; }
#mappa .stand-num { fill: var(--testo-2); }

#mappa svg.filtrato .stand:not(.match):not(.sel) { opacity: .35; }
#mappa .stand.match .stand-shape { fill: var(--stand-match); }
#mappa .stand.sel .stand-shape { fill: var(--accento); }
#mappa .stand.sel text,
#mappa .stand.sel tspan { fill: #fff; }

#mappa .percorso-bordo,
#mappa .percorso-base,
#mappa .percorso {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
#mappa .percorso-bordo { stroke: #fff; }
#mappa .percorso-base {
  stroke: var(--percorso-tenue);
}
/* Tratto scuro che scorre dalla partenza all'arrivo */
#mappa .percorso {
  stroke: var(--percorso);
  stroke-dasharray: 14 200;
  stroke-dashoffset: 14;
  opacity: 0;
  animation: percorso-scorre 2.6s linear .9s infinite;
}
@keyframes percorso-scorre {
  0% { stroke-dashoffset: 14; opacity: 1; }
  85% { stroke-dashoffset: -86; opacity: 1; }
  100% { stroke-dashoffset: -86; opacity: 0; }
}
#mappa .marcatore { pointer-events: none; stroke: #fff; vector-effect: non-scaling-stroke; stroke-width: 3px; }
#mappa .marcatore.arrivo { fill: var(--percorso); }
#mappa .marcatore.partenza { fill: var(--partenza); }
#mappa .alone-arrivo {
  fill: var(--percorso);
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
  animation: alone 1.8s ease-out infinite;
}
@keyframes alone { from { transform: scale(.4); opacity: .45; } to { transform: scale(1); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  #mappa .percorso-base { animation: none; stroke: var(--percorso); }
  #mappa .percorso, #mappa .alone-arrivo { display: none; }
}
#mappa .marcatore.qui { fill: var(--qui); }
#mappa .etichetta-qui {
  fill: var(--qui);
  font-weight: 700;
  paint-order: stroke;
  stroke: #fff;
  vector-effect: non-scaling-stroke;
  stroke-width: 4px;
  pointer-events: none;
}

/* ------------------------------------------------------------ testata e zoom */

.testata {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--testata-h);
  padding: max(8px, env(safe-area-inset-top)) 12px 8px 16px;
  background: linear-gradient(var(--superficie) 70%, rgba(255, 255, 255, 0));
  pointer-events: none;
}
.testata > * { pointer-events: auto; }
.testata-titoli { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.testata .logo { display: block; height: 28px; width: auto; }
/* Visibile solo agli screen reader */
.solo-lettori {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.testata .evento {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--testo-2);
}
.testata h1 {
  margin: 0;
  color: var(--accento);
  font-size: 1.125rem;
  line-height: 1.25;
}

.btn-lingua {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--bordo);
  border-radius: 999px;
  background: var(--superficie);
  font-size: .875rem;
  font-weight: 600;
}

.controlli-zoom {
  position: absolute;
  z-index: 2;
  right: 12px;
  top: calc(var(--testata-h) + max(8px, env(safe-area-inset-top)) + 4px);
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  background: var(--superficie);
  box-shadow: var(--ombra);
  overflow: hidden;
}
.controlli-zoom .btn-icona { border-radius: 0; }
.controlli-zoom .btn-icona + .btn-icona { border-top: 1px solid var(--bordo); }

.btn-icona {
  display: inline-grid;
  place-items: center;
  width: var(--tocco);
  height: var(--tocco);
  border-radius: 10px;
  flex: none;
}
.btn-icona:hover { background: var(--sfondo); }
.btn-icona.piccolo { width: 36px; height: 36px; }

/* ------------------------------------------------------------ pannello (mobile: foglio dal basso) */

#pannello {
  position: fixed;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - var(--testata-h));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--superficie);
  border-radius: var(--raggio) var(--raggio) 0 0;
  box-shadow: var(--ombra);
}
#pannello[data-foglio="chiuso"] #contenuto { display: none; }
#pannello[data-foglio="medio"] { height: 46dvh; }
#pannello[data-foglio="pieno"] { height: calc(100dvh - var(--testata-h)); }

.maniglia {
  display: grid;
  place-items: center;
  width: 100%;
  height: 28px;
  flex: none;
  touch-action: none;
  cursor: grab;
}
#pannello[data-trascina] { transition: none; }
#pannello[data-trascina] #contenuto { display: block; }
#pannello[data-trascina] .maniglia { cursor: grabbing; }

/* Settori sempre a portata di dito con il foglio chiuso (solo telefono) */
.anteprima { display: none; }
@media (max-width: 767px) {
  #pannello[data-foglio="chiuso"] .anteprima {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    margin: -4px 0 0;
    padding: 0 12px 12px;
    scrollbar-width: none;
    flex: none;
  }
  .anteprima::-webkit-scrollbar { display: none; }
  .anteprima .chip { flex: none; }
}
.maniglia span {
  width: 40px;
  height: 5px;
  border-radius: 3px;
  background: var(--bordo);
}

.cerca {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0 12px 12px;
  flex: none;
}
.cerca-icona {
  position: absolute;
  left: 12px;
  color: var(--testo-2);
  pointer-events: none;
  display: grid;
}
.cerca input {
  width: 100%;
  min-height: 48px;
  padding: 0 44px 0 44px;
  border: 1px solid var(--bordo);
  border-radius: 12px;
  background: var(--sfondo);
  font: inherit;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.cerca input::-webkit-search-cancel-button { display: none; }
.cerca input:focus { outline: none; border-color: var(--accento); background: var(--superficie); }
.cerca .btn-icona { position: absolute; right: 6px; }

#contenuto {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 16px;
}

/* ------------------------------------------------------------ contenuti */

.sezione + .sezione { margin-top: 20px; }
.sezione h2 {
  margin: 4px 0 8px;
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--testo-2);
}

.nota { margin: 4px 0 16px; color: var(--testo-2); line-height: 1.45; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--bordo);
  border-radius: 999px;
  background: var(--superficie);
  font-size: .875rem;
  text-align: left;
}
.chip:hover { border-color: var(--accento); }
.chip .conta { color: var(--testo-2); font-variant-numeric: tabular-nums; }

.lista { list-style: none; margin: 0; padding: 0; }
.lista li + li { border-top: 1px solid var(--bordo); }
.voce {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  min-height: 56px;
  padding: 10px 4px;
  text-align: left;
}
.voce:hover { background: var(--sfondo); }
.voce:focus-visible, .chip:focus-visible { outline-offset: -2px; border-radius: 10px; }
.chip:focus-visible { border-radius: 999px; }

/* Parte del testo che corrisponde alla ricerca */
mark {
  background: var(--evidenzia);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}
.voce strong { font-weight: 600; }
.voce small { color: var(--testo-2); font-size: .875rem; }
.voce .estratto { margin-top: 2px; color: var(--testo); font-size: .875rem; line-height: 1.4; }

.intestazione {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 -8px 8px;
}
.intestazione h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.25;
  text-transform: none;
  letter-spacing: 0;
  color: var(--testo);
}

.meta { margin: 0 0 12px; color: var(--testo-2); }

.blocco-espositore { padding: 12px 0; }
.blocco-espositore + .blocco-espositore { border-top: 1px solid var(--bordo); }
.blocco-espositore h3 { margin: 0 0 2px; font-size: 1.0625rem; }
.blocco-espositore .meta { margin: 0; }
.blocco-espositore .chips { margin-top: 8px; }
.apri-scheda {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: var(--tocco);
  text-align: left;
  font-weight: 700;
}
.apri-scheda .icona { color: var(--testo-2); }
.apri-scheda:hover span { color: var(--accento); }

/* ------------------------------------------------------------ scheda catalogo */

.chips.tag { margin: -4px 0 12px; }
.chips.tag .chip { min-height: 32px; padding: 4px 10px; font-size: .8125rem; }

.sezione .descrizione { margin: 0; }
.descrizione {
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  overflow: hidden;
}
.descrizione.aperta { display: block; -webkit-line-clamp: unset; line-clamp: none; }
.descrizione.breve {
  margin: 6px 0 0;
  font-size: .9375rem;
  line-height: 1.45;
  color: var(--testo-2);
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.leggi-tutto {
  min-height: var(--tocco);
  padding: 0 2px;
  color: var(--accento);
  font-weight: 600;
}
.leggi-tutto:hover { text-decoration: underline; }

.contatti {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--bordo);
  border-radius: 12px;
  overflow: hidden;
}
.contatti li + li { border-top: 1px solid var(--bordo); }
.contatto {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 10px 14px;
  color: inherit;
  text-decoration: none;
  line-height: 1.35;
}
a.contatto:hover { background: var(--sfondo); }
a.contatto:focus-visible { outline-offset: -3px; border-radius: 12px; }
.contatto > .icona:first-child { color: var(--accento); }
.contatto .valore { flex: 1; min-width: 0; overflow-wrap: anywhere; }
a.contatto > .icona:last-child { width: 18px; height: 18px; color: var(--testo-2); }

.social { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.social a {
  display: inline-grid;
  place-items: center;
  width: var(--tocco);
  height: var(--tocco);
  border: 1px solid var(--bordo);
  border-radius: 50%;
  color: var(--testo);
}
.social a:hover { border-color: var(--accento); color: var(--accento); }
.social a:focus-visible { border-radius: 50%; }

.azioni { display: flex; gap: 8px; margin: 4px 0 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  font-weight: 600;
  border: 1px solid var(--bordo);
  background: var(--superficie);
}
.btn.primario { background: var(--accento); border-color: var(--accento); color: #fff; }
.btn.primario:hover { background: var(--accento-scuro); }
.btn:not(.primario):hover { border-color: var(--accento); }

/* indicazioni */
.tappe {
  display: grid;
  /* minmax(0, …): senza, i nomi lunghi allargano la colonna e spingono fuori il pulsante Inverti */
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.tappa-elenco { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tappa {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 6px 12px;
  border: 1px solid var(--bordo);
  border-radius: 12px;
  text-align: left;
}
.tappa.attiva { border-color: var(--accento); box-shadow: 0 0 0 2px var(--accento-tenue); }
.tappa .etichetta { font-size: .75rem; font-weight: 700; color: var(--testo-2); text-transform: uppercase; width: 3.4em; flex: none; }
.tappa .valore { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tappa .valore.vuoto { color: var(--testo-2); }
.pallino { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--bordo); }
.pallino.partenza { background: var(--partenza); }
.pallino.arrivo { background: var(--percorso); }

.riepilogo {
  margin: 16px 0 0;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--accento-tenue);
}
.riepilogo strong { display: block; font-size: 1.125rem; }
.riepilogo span { color: var(--testo-2); }

/* ------------------------------------------------------------ schermi larghi e totem */

@media (min-width: 768px) {
  :root { --testata-h: 92px; }
  .testata .logo { height: 36px; }

  /* z-index: la testata (fissa, figlia di #mappa-area) deve stare sopra il pannello */
  #mappa-area { left: var(--pannello-w); z-index: 4; }

  #pannello,
  #pannello[data-foglio] {
    top: 0;
    right: auto;
    width: var(--pannello-w);
    height: auto;
    max-height: none;
    border-radius: 0;
    padding-top: var(--testata-h);
    box-shadow: inset -1px 0 0 var(--bordo);
  }
  #pannello[data-foglio] #contenuto { display: block; }
  .maniglia { display: none; }

  /* Su desktop titolo e lingua stanno in cima al pannello: la mappa resta tutta libera */
  .testata {
    position: fixed;
    right: auto;
    width: var(--pannello-w);
    height: var(--testata-h);
    min-height: 0;
    z-index: 4;
    padding: 16px 12px 8px 16px;
    align-items: flex-start;
    background: var(--superficie);
    box-shadow: inset -1px 0 0 var(--bordo);
  }
  .controlli-zoom { top: 12px; }
}

/* ------------------------------------------------------------ etichetta sugli stand (desktop) */

.fumetto {
  position: absolute;
  z-index: 3;
  left: 0;
  top: 0;
  max-width: 280px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--testo);
  color: #fff;
  font-size: .875rem;
  line-height: 1.35;
  box-shadow: var(--ombra);
  pointer-events: none;
}
.fumetto strong { display: block; }
.fumetto span { display: block; color: #cfe0e3; }

/* Stand raggiungibili da tastiera: anello di focus sulla forma dello stand */
#mappa .stand:focus { outline: none; }
#mappa .stand:focus-visible .stand-shape {
  stroke: var(--accento);
  stroke-width: 3px;
  vector-effect: non-scaling-stroke;
}

html.totem {
  font-size: 19px;
  --pannello-w: 460px;
  --tocco: 56px;
}
html.totem { --testata-h: 104px; }
html.totem .testata h1 { font-size: 1.375rem; }
html.totem .testata .logo { height: 40px; }

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