/* ============================================================
   Accessibilità, preferenze utente (condiviso fra tutte le pagine)
   Gli effetti sono pilotati da attributi su <html>, impostati
   prima del paint da uno script inline e gestiti da prefs.js.
   ============================================================ */

/* ---------- RETE DI SICUREZZA TIPOGRAFICA ---------- */

/* I titoli sono in Syne 800 a corpo grande: una parola lunga ("collaborazione.",
   "l'accessibilità.") su schermo stretto non entra in una riga e, non potendo
   andare a capo, sfonderebbe la pagina in orizzontale.

   Perché entrambe le proprietà, in quest'ordine:
   - hyphens: auto sillaba all'italiana (le pagine hanno lang="it"). Misurato:
     interviene ESATTAMENTE alle stesse larghezze in cui la parola non ci sta
     comunque, mai per riempire meglio una riga. Quindi non altera la tipografia.
   - overflow-wrap: break-word resta come ultima risorsa, per le parole prive di
     punti di sillabazione validi (indirizzi email, URL).
   Senza la prima, la rottura cade in un punto qualsiasi e lascia orfano il punto
   finale; con entrambe si ottiene "l'accessibili-tà." con il trattino corretto.

   Specificità bassa di proposito: le regole di pagina restano libere di
   sovrascrivere tutto il resto. */
h1, h2, h3 {
  -webkit-hyphens: auto;
  hyphens: auto;
  overflow-wrap: break-word;
}

/* ---------- EFFETTI ---------- */

/* Contrasto alto */
html[data-contrast="high"] {
  --muted: #2c2b27;
  --muted-light: #5f5f59;
  --line: rgba(26, 26, 26, 0.55);
  --orange-ink: #A82600;
}
html[data-contrast="high"] .rotating-word,
html[data-contrast="high"] .dot-accent,
html[data-contrast="high"] .metric-num { color: var(--orange-ink); }
html[data-contrast="high"] .card-light { border-color: var(--ink); }
html[data-contrast="high"] .field input,
html[data-contrast="high"] .field textarea { border-color: #5a5954; }

/* Spaziatura testo (logica WCAG 1.4.12) */
html[data-spacing="wide"] body { line-height: 1.75; letter-spacing: 0.045em; word-spacing: 0.14em; }
html[data-spacing="wide"] p { margin-bottom: 1.7em; }
html[data-spacing="wide"] .page-title,
html[data-spacing="wide"] .hero-title,
html[data-spacing="wide"] h1,
html[data-spacing="wide"] h2 { letter-spacing: -0.01em; word-spacing: normal; line-height: 1.06; }

/* Font ad alta leggibilità */
html[data-font="legible"] { --font-body: 'Atkinson Hyperlegible', 'Inter', sans-serif; }

/* Dimensione testo (scala dal root; richiede tipografia in rem) */
html[data-text-size="large"]  { font-size: 112.5%; }
html[data-text-size="xlarge"] { font-size: 125%; }

/* Riduci animazioni (override esplicito, oltre alla preferenza di sistema) */
html[data-reduce-motion="true"] *,
html[data-reduce-motion="true"] *::before,
html[data-reduce-motion="true"] *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

/* ---------- RISPETTO DELLE IMPOSTAZIONI DI SISTEMA ----------
   Questi blocchi si attivano da soli, senza che l'utente tocchi
   nulla nel sito: è qui che sta la vera accessibilità. */

/* L'utente ha chiesto più contrasto a livello di OS/browser */
@media (prefers-contrast: more) {
  :root {
    --muted: #2c2b27;
    --muted-light: #5f5f59;
    --line: rgba(26, 26, 26, 0.6);
    --orange-ink: #A82600;
  }
  .rotating-word, .dot-accent, .metric-num { color: var(--orange-ink); }
  .card-light { border-color: var(--ink); }
  .field input, .field textarea { border-color: #5a5954; }
}

/* Modalità a colori forzati (es. Contrasto elevato di Windows):
   non imporre colori, ma garantire che i bordi e i controlli restino visibili */
@media (forced-colors: active) {
  .card, .card-light, .card-dark, .card-orange, .next, .demo-card { border: 1px solid; }
  .pref-toggle, .btn, .pref-switch, .pref-seg { border: 1px solid; }
  .pref-switch[aria-checked="true"] { background: Highlight; }
  .cursor-ring { display: none !important; }
}

/* ---------- PILL NELLA TOPBAR ---------- */
.topbar.has-prefs { justify-content: space-between; align-items: center; }
.pref-toggle {
  font-family: var(--font-display); font-weight: 800; font-size: 0.9375rem; letter-spacing: 0.02em;
  color: var(--ink); background: transparent; border: 1.5px solid var(--line); border-radius: 999px;
  padding: 7px 15px; cursor: pointer; line-height: 1; display: inline-flex; align-items: center; gap: 8px;
  transition: border-color .2s ease;
}
.pref-toggle:hover { border-color: var(--ink); }
.pref-toggle__sub {
  font-family: var(--font-body); font-weight: 600; font-size: 0.6875rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
}

/* ---------- PANNELLO ----------
   Ordine di sovrapposizione, da tenere allineato fra questo file e la regola
   .cursor-ring che sta nello <style> di ogni pagina:
       800   #bpLayer, il livello dei raggi X
      1300   .pref-backdrop
      1310   .pref-panel
      1320   .bp-legend
      1400   .cursor-ring, il puntatore personalizzato
   Il puntatore deve stare sopra tutto: quando il pannello e' aperto il cursore
   di sistema e' nascosto (cursor: none), quindi se il pallino finisce sotto il
   pannello l'utente resta senza puntatore visibile proprio mentre sceglie le
   preferenze di lettura. Era il caso quando .cursor-ring stava a 1200. */
.pref-backdrop {
  position: fixed; inset: 0; background: rgba(26, 26, 26, 0.28); z-index: 1300;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.pref-backdrop.open { opacity: 1; pointer-events: auto; }

.pref-panel {
  position: fixed; top: 50%; left: 50%; width: 360px; max-width: calc(100vw - 32px);
  background: var(--white); color: var(--ink); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 18px 50px rgba(26, 26, 26, 0.18); z-index: 1310; padding: 24px 24px 16px;
  transform: translate(-50%, calc(-50% + 8px)); opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease, visibility 0s .2s;
}
.pref-panel.open { opacity: 1; visibility: visible; transform: translate(-50%, -50%); pointer-events: auto; transition: opacity .2s ease, transform .2s ease; }
.pref-panel h2 { font-family: var(--font-display); font-weight: 800; font-size: 1.1875rem; margin: 0 0 4px; }
.pref-intro { font-size: 0.8125rem; line-height: 1.5; color: var(--muted); margin: 0 0 14px; }

.pref-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; border-top: 1px solid var(--line); }
.pref-label { font-size: 0.875rem; font-weight: 500; color: var(--ink); }
.pref-hint { display: block; font-size: 0.75rem; font-weight: 400; color: var(--muted); margin-top: 2px; }

/* switch */
.pref-switch { position: relative; flex: none; width: 46px; height: 26px; border-radius: 999px; border: none; background: var(--muted-light); cursor: pointer; transition: background .2s ease; }
.pref-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s ease; }
.pref-switch[aria-checked="true"] { background: var(--orange); }
.pref-switch[aria-checked="true"]::after { transform: translateX(20px); }
.pref-switch:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

/* segmented (dimensione testo) */
.pref-seg { display: inline-flex; flex: none; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; }
.pref-seg button { font-family: var(--font-body); border: none; background: transparent; cursor: pointer; padding: 5px 0; width: 40px; color: var(--muted); font-weight: 700; line-height: 1; }
.pref-seg button[aria-checked="true"] { background: var(--ink); color: var(--cream); }
.pref-seg button:nth-child(1) { font-size: 0.75rem; }
.pref-seg button:nth-child(2) { font-size: 0.9375rem; }
.pref-seg button:nth-child(3) { font-size: 1.125rem; }
.pref-seg button:focus-visible { outline: 3px solid var(--orange); outline-offset: -3px; }

.pref-reset { margin-top: 14px; width: 100%; font-family: var(--font-body); font-size: 0.8125rem; font-weight: 600; color: var(--muted); background: transparent; border: none; border-top: 1px solid var(--line); padding: 12px 8px 6px; cursor: pointer; }
.pref-reset:hover { color: var(--ink); }

@media (max-width: 820px) {
  .pref-toggle__sub { display: none; }
  .pref-panel { top: auto; bottom: 0; left: 0; right: 0; width: 100%; max-width: 100%; border-radius: 18px 18px 0 0; transform: translateY(14px); }
  .pref-panel.open { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .pref-backdrop, .pref-panel, .pref-switch, .pref-switch::after, .pref-toggle { transition: none; }
}

/* ---------- RAGGI X (mostra landmark, ARIA, ordine di focus) ---------- */
#bpLayer { position: fixed; inset: 0; pointer-events: none; z-index: 800; }
.bp-box { position: absolute; border: 1.5px dashed var(--ink); border-radius: 4px; box-shadow: inset 0 0 0 9999px rgba(200, 255, 0, 0.06); }
.bp-tag { position: absolute; background: var(--acid); color: #1A1A1A; font-family: var(--font-body); font-size: 0.6875rem; font-weight: 600; line-height: 1.2; padding: 3px 7px; border-radius: 5px; white-space: nowrap; max-width: 70vw; overflow: hidden; text-overflow: ellipsis; }
.bp-num { position: absolute; width: 22px; height: 22px; border-radius: 50%; background: var(--orange); color: #fff; font-family: var(--font-body); font-size: 0.75rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.bp-legend { display: none; position: fixed; bottom: 18px; left: 18px; z-index: 1320; gap: 18px; background: var(--ink); color: var(--cream); padding: 10px 16px; border-radius: 10px; font-size: 0.75rem; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); }
body.bp-on .bp-legend { display: flex; }
.bp-legend span { display: inline-flex; align-items: center; gap: 7px; }
.bp-legend .dot { width: 11px; height: 11px; border-radius: 3px; background: var(--acid); }
.bp-legend .dot.orange { background: var(--orange); border-radius: 50%; }

html[data-reduce-motion="true"] .mark-eyes { transform: none !important; }

/* Blink del marchio (saluto a fine intro). Gli occhi si chiudono un istante. */
@keyframes eyeBlink { 0%, 100% { transform: scaleY(1); } 45%, 55% { transform: scaleY(0.08); } }
.mark-blink .mark-eyes circle { transform-box: fill-box; transform-origin: center; animation: eyeBlink .34s ease both; }
html[data-reduce-motion="true"] .mark-blink .mark-eyes circle { animation: none; }
