/* =================================================================
   Sondaggio "attività su appuntamento" — Bergamo
   Concept: l'agenda di carta che diventa digitale.
   Niente brand: inchiostro su carta calda, verde pino, un solo
   tocco ocra (la "pennellata" che marca le parole che convertono).
   ================================================================= */

:root {
  /* — Colore — */
  --paper:      #F1EEE6;  /* carta calda (più fredda del cream-AI) */
  --paper-2:    #ECE8DD;  /* fondo header / bande */
  --card:       #FBFAF5;  /* superficie opzioni / pannelli */
  --ink:        #232826;  /* testo principale, inchiostro verde-nero */
  --ink-soft:   #555D57;  /* testo secondario / helper */
  --ink-faint:  #61675F;  /* etichette tenui (>=4.5:1 su carta, conforme AA) */
  --green:      #1F5C46;  /* accento primario: fiducia, locale */
  --green-700:  #16442F;  /* hover */
  --green-tint: #1F5C4614;/* selezione tenue (8%) */
  --ochre:      #D98A2B;  /* signature: pennarello / highlight */
  --ochre-soft: #E7B271;
  --ochre-ink:  #8A5316;  /* ocra scuro per testo: >=4.5:1 su --card (conforme AA) */
  --line:       #DDD7C7;  /* righe sottili su carta */
  --danger:     #A5402F;  /* obbligatorio / errori, parsimonioso */

  /* — Tipografia — */
  --f-display: "Bricolage Grotesque", "Trebuchet MS", system-ui, sans-serif;
  --f-body:    "Mulish", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --f-mono:    "DM Mono", ui-monospace, "Courier New", monospace;

  /* — Misure — */
  --maxw: 660px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 var(--line), 0 18px 40px -28px #2c2a2055;
  --ease: cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  overflow-x: hidden; /* niente scroll orizzontale accidentale su mobile */
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* fine texture "carta": granitura quasi impercettibile */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.035'/%3E%3C/svg%3E");
}

/* ---------- Skip link / accessibilità ---------- */
.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--green);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 50;
  text-decoration: none;
}
.skip-link:focus { left: 12px; }

:focus-visible {
  outline: 3px solid var(--green); /* contrasto >=3:1 su carta (l'ocra non lo raggiunge) */
  outline-offset: 2px;
  border-radius: 6px;
}

/* utility solo-screen-reader (testo accessibile non visibile) */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Topbar + progresso ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.1) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 18px;
  justify-content: space-between;
}
.kicker {
  font-family: var(--f-mono);
  font-size: .72rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
}
.progress {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  max-width: 360px;
}
.progress__track {
  flex: 1;
  height: 7px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), #2c7a5b);
  border-radius: 99px;
  transition: width .5s var(--ease);
}
.progress__label {
  font-family: var(--f-mono);
  font-size: .72rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* ---------- Layout schermo ---------- */
.screen {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 30px 22px 64px;
  outline: none;
}

/* ---------- Signature: la pennellata ocra ---------- */
.mark {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='28' preserveAspectRatio='none'%3E%3Cpath d='M3 19 C40 11, 80 22, 120 15 S185 12, 197 17 L196 23 C150 19, 90 27, 45 23 S12 25, 4 24 Z' fill='%23D98A2B'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0 78%;
  background-size: 100% .58em;
  padding: 0 .08em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* ---------- INTRO / landing ---------- */
.intro { animation: rise .6s var(--ease) both; }

.intro__media {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  aspect-ratio: 3 / 2;
  background: var(--paper-2);
}
.intro__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.intro__media::after { /* lieve velo caldo per far respirare il testo sotto */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #00000000 55%, #1c160e3b);
}

.intro__eyebrow {
  font-family: var(--f-mono);
  font-size: .76rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--green);
  margin: 26px 0 12px;
}
.intro__title {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: clamp(2.15rem, 6.4vw, 3.5rem);
  line-height: 1.04;
  letter-spacing: -.02em;
  margin: 0 0 18px;
  text-wrap: balance;
}
.intro__lead {
  font-size: 1.12rem;
  color: var(--ink-soft);
  max-width: 52ch;
  margin: 0 0 18px;
}
.intro__lead strong { color: var(--ink); font-weight: 700; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin: 22px 0 28px;
  padding: 0;
  list-style: none;
}
.chips li {
  font-family: var(--f-mono);
  font-size: .8rem;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 7px 14px 7px 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.chips li::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 99px;
  background: var(--green);
}

/* consenso sul landing */
.consent {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 4px 0 24px;
  cursor: pointer;
}
.consent input { margin-top: 3px; width: 20px; height: 20px; accent-color: var(--green); flex: none; }
.consent span { font-size: .98rem; color: var(--ink-soft); }
.consent a { color: var(--green); }

.privacy-note {
  font-size: .85rem;
  color: var(--ink-faint);
  border-top: 1px dashed var(--line);
  padding-top: 18px;
  margin-top: 30px;
  max-width: 60ch;
}

/* ---------- Bottoni ---------- */
.btn {
  font-family: var(--f-body);
  font-weight: 700;
  font-size: 1.04rem;
  border: 1px solid transparent;
  border-radius: 99px;
  padding: 15px 28px;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: transform .12s var(--ease), background .2s, box-shadow .2s, opacity .2s;
}
.btn--primary {
  background: var(--green);
  color: #fff;
  box-shadow: 0 10px 22px -12px #1f5c4699;
}
.btn--primary:hover { background: var(--green-700); transform: translateY(-1px); }
.btn--primary:active { transform: translateY(0); }
.btn--primary:disabled { background: #b9bdb4; box-shadow: none; cursor: not-allowed; transform: none; }
.btn--ghost {
  background: transparent;
  color: var(--ink-soft);
  padding: 14px 18px;
}
.btn--ghost:hover { color: var(--ink); }
.btn__arrow { font-size: 1.1em; line-height: 1; }

/* ---------- STEP (una domanda alla volta) ---------- */
.step { animation: rise .42s var(--ease) both; }

.step__eyebrow {
  display: inline-flex;
  flex-wrap: wrap; /* sezione + chip di segmento vanno a capo su schermi stretti invece di sforare */
  align-items: center;
  gap: 9px;
  font-family: var(--f-mono);
  font-size: .74rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 16px;
}
.step__eyebrow .seg {
  color: var(--green);
  background: var(--green-tint);
  border-radius: 99px;
  padding: 3px 10px;
  letter-spacing: .08em;
}
.step__q {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: clamp(1.45rem, 3.6vw, 2.05rem);
  line-height: 1.16;
  letter-spacing: -.012em;
  margin: 0 0 10px;
  text-wrap: pretty;
}
.step__q .req { color: var(--danger); font-weight: 700; }
.step__help {
  font-size: 1rem;
  color: var(--ink-soft);
  margin: 0 0 24px;
  max-width: 56ch;
}
.step__hint {
  font-family: var(--f-mono);
  font-size: .76rem;
  color: var(--ink-faint);
  margin: -14px 0 20px;
}

/* gruppo opzioni (fieldset senza stile nativo) */
.options { border: 0; margin: 0; padding: 0; display: grid; gap: 11px; }
.options legend { padding: 0; }

.option {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 15px 17px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .08s;
  position: relative;
}
.option:hover { border-color: var(--green); background: #fff; }
.option:active { transform: scale(.992); }
/* input nativo focalizzabile ma invisibile: Tab/Spazio/frecce funzionano da tastiera */
.option input { position: absolute; width: 1px; height: 1px; margin: -1px; opacity: 0; }
/* contorno di focus SOLO per chi naviga da tastiera (:focus-visible): dopo un
   tap/clic del mouse non resta "appiccicato" sull'ultima opzione (utile sulle
   domande multi come D23, che non avanzano da sole). La selezione vera resta
   indicata dal riempimento verde + spunta (.is-selected). */
.option:has(input:focus-visible) { outline: 3px solid var(--green); outline-offset: 2px; }

.option__key {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  display: grid;
  place-items: center;
  font-family: var(--f-mono);
  font-size: .82rem;
  color: var(--ink-faint);
  background: var(--paper);
  transition: all .15s;
}
.option__text { flex: 1; font-size: 1.05rem; color: var(--ink); }
.option__tick {
  flex: none;
  width: 22px; height: 22px;
  opacity: 0;
  transform: scale(.6);
  transition: all .18s var(--ease);
  color: var(--green);
}

/* selezione */
.option.is-selected {
  border-color: var(--green);
  background: var(--green-tint);
}
.option.is-selected .option__key {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.option.is-selected .option__tick { opacity: 1; transform: scale(1); }
/* lo stato selezionato resta verde anche in hover (evita override da .option:hover) */
.option.is-selected:hover { background: var(--green-tint); border-color: var(--green); }

/* checkbox (multi) → chiave quadrata morbida, già differenziata dal radio via tick */
.options[data-multi="true"] .option__key { border-radius: 8px; }

/* campo "Altro" */
.other-wrap { margin-top: 4px; display: grid; gap: 8px; }
.other-input {
  width: 100%;
  font-family: var(--f-body);
  font-size: 1.02rem;
  padding: 13px 15px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
}
.other-input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(31,92,70,.32); }

/* ---------- testo libero (short / long) ---------- */
.field {
  width: 100%;
  font-family: var(--f-body);
  font-size: 1.06rem;
  padding: 15px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink);
  resize: vertical;
}
.field:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(31,92,70,.32); }
textarea.field { min-height: 130px; line-height: 1.5; }

/* ---------- scala 1–5 ---------- */
.scale { margin: 6px 0 4px; }
.scale__row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 9px;
}
.scale__btn {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 1.3rem;
  aspect-ratio: 1 / 1;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--ink-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .14s var(--ease);
}
.scale__btn:hover { border-color: var(--green); color: var(--ink); }
.scale__btn.is-selected {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 10px 20px -12px #1f5c46aa;
}
.scale__labels {
  display: flex;
  justify-content: space-between;
  font-size: .82rem;
  color: var(--ink-faint);
  margin-top: 10px;
}
.scale__already {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  margin-top: 20px;
  padding: 12px 16px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--ink-soft);
  font-size: .96rem;
  transition: border-color .15s, color .15s;
}
.scale__already input { width: 19px; height: 19px; accent-color: var(--green); }
.scale__already.is-on { border-color: var(--green); border-style: solid; color: var(--ink); }

/* ---------- nota / box informativo (Salute, offerta pilota) ---------- */
.note {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ochre);
  border-radius: var(--radius-sm);
  padding: 20px 22px;
  margin: 4px 0 8px;
}
.note__tag {
  font-family: var(--f-mono);
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ochre-ink);
  margin: 0 0 8px;
}
.note p { margin: 0; font-size: 1.05rem; color: var(--ink); }
.note p + p { margin-top: 10px; }

/* ---------- navigazione step ---------- */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 34px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.nav__hint {
  font-family: var(--f-mono);
  font-size: .73rem;
  color: var(--ink-faint);
}
.error-msg {
  color: var(--danger);
  font-size: .92rem;
  margin-top: 14px;
  font-weight: 600;
}

/* ---------- THANK YOU ---------- */
.thankyou { animation: rise .5s var(--ease) both; text-align: left; padding-top: 10px; }
.thankyou__seal {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--green-tint);
  color: var(--green);
  display: grid; place-items: center;
  margin-bottom: 22px;
}
.thankyou__title {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: clamp(1.9rem, 5vw, 2.7rem);
  line-height: 1.08;
  margin: 0 0 14px;
}
.thankyou__body { font-size: 1.1rem; color: var(--ink-soft); max-width: 54ch; }
.thankyou__share {
  margin-top: 26px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ---------- footer sito ---------- */
.sitefoot {
  position: relative;
  z-index: 1;
  max-width: var(--maxw);
  margin: 0 auto;
  width: 100%;
  padding: 18px 22px 30px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: space-between;
  align-items: center;
  font-size: .8rem;
  color: var(--ink-faint);
  border-top: 1px solid var(--line);
}
.linkbtn {
  background: none;
  border: 0;
  color: var(--ink-faint);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 0;
}
.linkbtn:hover { color: var(--green); }

.noscript {
  max-width: var(--maxw);
  margin: 40px auto;
  padding: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* ---------- animazioni ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes markIn {
  from { background-size: 0 .58em; }
  to   { background-size: 100% .58em; }
}
.intro .mark {
  animation: markIn .75s var(--ease) .35s both;
}

/* ---------- responsive ---------- */
@media (max-width: 540px) {
  body { font-size: 16px; }
  .topbar__inner { padding: 10px 16px; gap: 10px; }
  .kicker { font-size: .64rem; letter-spacing: .1em; }
  /* durante le domande la barra di progresso ha la precedenza: il kicker si
     ritira per non comprimere la barra su schermi stretti (resta nell'intro) */
  .topbar__inner:has(.progress:not([hidden])) .kicker { display: none; }
  /* fallback per browser datati senza :has(): la classe la mette il JS (updateProgress) */
  .topbar--step .kicker { display: none; }
  .progress { max-width: none; }
  .screen { padding: 22px 16px 56px; }
  .scale__row { gap: 6px; }
  .scale__btn { font-size: 1.1rem; }
  .nav { flex-direction: row; }
  .btn { padding: 14px 22px; }
}

@media (max-width: 380px) {
  .option__key { width: 26px; height: 26px; }
}

/* ---------- riduzione movimento ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .intro .mark { background-size: 100% .58em; }
}
