/*
 * app/assets/app.css — v2.0 (Restyle)
 * Design system in stile "Duolingo-inspired ma adulto":
 *   - Container mobile anche su desktop (max 440px centrato)
 *   - Colori vivaci ma non infantili
 *   - Bottoni con lift-shadow
 *   - Tipografia grassa/confident
 *   - Icone SVG inline (no dipendenza CDN)
 */

/* ============================================================
   1. DESIGN TOKENS
   ============================================================ */

:root {
  /* Brand SMAA */
  --teal:        #14b8a6;
  --teal-dark:   #0d9488;
  --navy:        #0f2a44;
  --navy-ink:    #08192a;

  /* Superficie "navy" (hero, badge, card scure): resta SEMPRE scura,
     anche in dark mode. Distinta da --navy, che in dark diventa un
     colore di testo chiaro. --on-navy è il testo che ci va sopra. */
  --navy-surface: #0f2a44;
  --on-navy:      #ffffff;

  /* Duolingo-inspired accents */
  --green:       #58cc02;
  --green-dark:  #4caa01;
  --green-shadow:#3a8c00;
  --coral:       #ff4b4b;
  --coral-dark:  #ea2b2b;
  --coral-shadow:#c02020;
  --yellow:      #ffc800;
  --yellow-dark: #eab700;
  --purple:      #ce82ff;

  /* Neutri */
  --bg:          #fafafa;
  --surface:     #ffffff;
  --surface-alt: #f7f7f7;
  --border:      #e5e5e5;
  --border-soft: #f0f0f0;
  --text:        #3c3c3c;
  --text-muted:  #777;
  --text-light:  #afafaf;

  /* Semantici — sfondo tenue */
  --success:     var(--green);
  --success-bg:  #e5f5d5;
  --warning:     var(--yellow);
  --warning-bg:  #fff3c4;
  --danger:      var(--coral);
  --danger-bg:   #ffdfe0;
  --info:        var(--teal);
  --info-bg:     #d1f5f0;

  /* Semantici — testo scuro leggibile SOPRA gli sfondi tenui sopra.
     In dark mode questi vengono schiariti (vedi [data-theme="dark"]). */
  --success-text: #2d5016;
  --warning-text: #78350f;
  --danger-text:  #7c1f1f;
  --info-text:    #0d4c44;

  /* Streak (KPI fuoco) */
  --streak-bg:     #fff7ed;
  --streak-border: #fed7aa;
  --streak-text:   #ea580c;
  --streak-shadow: #c94a00;

  /* Gradiente "navy" per i banner hero (es. banner iscriviti home).
     In dark mode viene scurito (vedi blocco dark). */
  --grad-navy-a: #0f2a44;
  --grad-navy-b: #1d4e7e;

  /* Trend statistiche */
  --trend-su:  #16a34a;
  --trend-giu: #dc2626;

  /* Ombra "solida" stile Duolingo: colore che sta SOTTO l'elemento
     sollevato. In dark mode diventa quasi-nero (vedi blocco dark). */
  --shadow-solid: var(--border);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Display",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font-sans);

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;

  /* Radii */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --r-pill: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(15, 42, 68, 0.06);
  --shadow-md: 0 2px 8px rgba(15, 42, 68, 0.1);
  --shadow-lg: 0 8px 24px rgba(15, 42, 68, 0.15);

  /* App container */
  --app-max-width: 440px;

  /* Z-index */
  --z-bottomnav: 50;
  --z-header:    60;
  --z-modal:     100;
}

/* ============================================================
   1b. TEMA SCURO
   Ridefinisce SOLO i token: ogni componente costruito su var()
   diventa scuro automaticamente. theme.js mette data-theme su
   <html> in base a 'auto' / 'light' / 'dark'.
   ============================================================ */
[data-theme="dark"] {
  /* Brand — tenuti vivaci; il navy come superficie va schiarito
     perché in dark mode "navy" diventa un colore di accento, non
     più lo sfondo. */
  --teal:        #2dd4bf;
  --teal-dark:   #5eead4;   /* in dark è il colore "chiaro" del teal */
  --navy:        #e8edf2;   /* ex testo-su-navy → ora testo chiaro */
  --navy-ink:    #c2ccd6;

  /* La superficie navy resta scura: in dark la rendiamo appena più
     chiara dello sfondo per dare stacco. Il testo sopra resta chiaro. */
  --navy-surface: #232c36;
  --on-navy:      #e8edf2;

  /* Accenti: leggermente più tenui per non "bruciare" su fondo scuro */
  --green:       #6fd63a;
  --green-dark:  #8ae65c;
  --green-shadow:#2f6b00;
  --coral:       #ff6b6b;
  --coral-dark:  #ff8a8a;
  --coral-shadow:#8a1818;
  --yellow:      #ffd633;
  --yellow-dark: #e0b800;
  --purple:      #d99cff;

  /* Neutri — la base scura */
  --bg:          #0f1419;
  --surface:     #1a2129;
  --surface-alt: #232c36;
  --border:      #36404c;
  --border-soft: #2a323c;
  --text:        #e8edf2;
  --text-muted:  #9aa7b4;
  --text-light:  #6b7783;

  /* Sfondi tenui semantici — versioni desaturate e scure */
  --success-bg:  #1f3315;
  --warning-bg:  #3a2e0a;
  --danger-bg:   #3a1a1c;
  --info-bg:     #14322f;

  /* Testi semantici — schiariti per restare leggibili sui bg scuri */
  --success-text: #a3e07a;
  --warning-text: #f5c97a;
  --danger-text:  #ff9b9b;
  --info-text:    #6fd9cc;

  /* Streak */
  --streak-bg:     #3a2410;
  --streak-border: #5c3a18;
  --streak-text:   #ff9d4d;
  --streak-shadow: #7a2e00;

  /* Gradiente navy — scurito per il tema scuro */
  --grad-navy-a: #16242f;
  --grad-navy-b: #1f3a52;

  /* Trend */
  --trend-su:  #4ade80;
  --trend-giu: #f87171;

  /* Ombre morbide — su fondo scuro servono nere e più marcate,
     non blu trasparenti (invisibili). */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);

  /* Ombra solida Duolingo: in dark un quasi-nero dà profondità. */
  --shadow-solid: #0b0f14;

  color-scheme: dark;   /* form control, scrollbar nativi scuri */
}

/* ============================================================
   2. RESET & BASE
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--surface);  /* bianco anche nelle safe-area iOS */
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* iOS native polish */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overscroll-behavior-y: none; /* niente "rubber band" verticale */
}

/* ============================================================
   FONT DSA / Alta leggibilità (v1 — 2026-05-11)
   Quando body.font-dsa è attivo, usa Lexend (validato scientifically)
   al posto del font di default. Migliora la leggibilità per chi ha
   dislessia o difficoltà di lettura.
   ============================================================ */

body.font-dsa,
body.font-dsa input,
body.font-dsa textarea,
body.font-dsa button,
body.font-dsa select {
  font-family: 'Lexend', var(--font-sans);
  letter-spacing: 0.01em;        /* lieve aumento spaziatura tra lettere */
  line-height: 1.6;              /* righe più ariose */
}

/* In modalità DSA aumento spaziatura paragrafi e righe testo lungo */
body.font-dsa p,
body.font-dsa .cap-card__titolo,
body.font-dsa .ps-quiz__q {
  line-height: 1.65;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 16px;
}

a { color: var(--teal-dark); text-decoration: none; }

h1, h2, h3, h4 {
  color: var(--navy);
  margin: 0 0 var(--sp-3);
  line-height: 1.15;
  letter-spacing: -0.01em;
  font-weight: 800;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; font-weight: 700; }

/* ============================================================
   3. APP CONTAINER (il segreto per farla bene anche su desktop)
   ============================================================ */

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: var(--app-max-width);
  margin: 0 auto;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  position: relative;
  box-shadow: 0 0 80px rgba(15, 42, 68, 0.08);  /* solo visibile su desktop */
}

@media (max-width: 440px) {
  .app-shell { box-shadow: none; }
}

/* ============================================================
   4. HEADER
   ============================================================ */

.app-header {
  position: sticky; top: 0;
  z-index: var(--z-header);
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  padding: var(--sp-3) var(--sp-4);
  /* iOS: spinge l'header sotto la status bar (Dynamic Island / notch) */
  padding-top: calc(var(--sp-3) + env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between;
  min-height: 60px;
}

/* Estensione visiva: copre la status bar iOS con lo stesso bianco dell'header */
.app-header::before {
  content: "";
  position: absolute;
  top: calc(-1 * env(safe-area-inset-top));
  left: 0; right: 0;
  height: env(safe-area-inset-top);
  background: var(--surface);
  pointer-events: none;
}

.app-header__brand {
  display: flex; align-items: center; gap: var(--sp-2);
  font-weight: 800;
  color: var(--navy);
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.app-header__brand-mark {
  width: 36px; height: 36px;
  background: var(--navy-surface);
  border-radius: 10px;
  display: grid; place-items: center;
  color: var(--on-navy); font-weight: 900;
  font-size: 0.95rem;
  letter-spacing: -0.05em;
}

.app-main {
  flex: 1;
  padding: var(--sp-4);
}

/* ============================================================
   5. BOTTOM NAV
   ============================================================ */

.bottom-nav {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-max-width);
  z-index: var(--z-bottomnav);
  background: var(--surface);
  border-top: 1px solid var(--border-soft);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Estensione visiva: copre la safe-area sotto la tab bar 
   con lo stesso bianco della tab bar (look iOS native) */
.bottom-nav::after {
  content: "";
  position: absolute;
  bottom: calc(-1 * env(safe-area-inset-bottom));
  left: 0; right: 0;
  height: env(safe-area-inset-bottom);
  background: var(--surface);
  pointer-events: none;
}

.bottom-nav__item {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 10px 4px;
  gap: 3px;
  color: var(--text-light);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  border-top: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.bottom-nav__item svg {
  width: 26px; height: 26px;
  stroke-width: 2;
}

.bottom-nav__item.is-active {
  color: var(--teal-dark);
  border-top-color: var(--teal);
}

/* ============================================================
   6. BOTTONI (Duolingo-style con "lift shadow")
   ============================================================ */

.btn-smaa {
  display: inline-flex;
  align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 0.9rem 1.4rem;
  border-radius: var(--r-md);
  font-weight: 800;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: none;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.08s;
  min-height: 52px;
  text-decoration: none;
  position: relative;
  will-change: transform;
}

/* Shadow "solida" tipo Duolingo: un secondo colore scuro sotto */
.btn-smaa-primary {
  background: var(--teal);
  color: #fff;
  box-shadow: 0 4px 0 var(--teal-dark);
}
.btn-smaa-primary:hover { filter: brightness(1.05); }
.btn-smaa-primary:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--teal-dark);
}

.btn-smaa-accent {
  background: var(--green);
  color: #fff;
  box-shadow: 0 4px 0 var(--green-shadow);
}
.btn-smaa-accent:hover { filter: brightness(1.05); }
.btn-smaa-accent:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--green-shadow);
}

.btn-smaa-dark {
  background: var(--navy-surface);
  color: var(--on-navy);
  box-shadow: 0 4px 0 var(--navy-ink);
}
.btn-smaa-dark:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--navy-ink);
}

.btn-smaa-outline {
  background: var(--surface);
  color: var(--navy);
  border: 2px solid var(--border);
  box-shadow: 0 4px 0 var(--shadow-solid);
}
.btn-smaa-outline:hover { border-color: var(--text-muted); }
.btn-smaa-outline:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--shadow-solid);
}

.btn-smaa-ghost {
  background: transparent;
  color: var(--text-muted);
  border: none;
  box-shadow: none;
  text-transform: none;
  font-weight: 600;
  letter-spacing: 0;
}
.btn-smaa-ghost:hover { background: var(--surface-alt); color: var(--navy); }

.btn-smaa-block { width: 100%; }

.btn-smaa[disabled],
.btn-smaa.is-loading {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Bottone "Continua" colorato della home */
.btn-continua {
  display: block; width: 100%;
  padding: var(--sp-5);
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: var(--r-lg);
  text-align: left;
  box-shadow: 0 6px 0 var(--teal-dark);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn-continua:active {
  transform: translateY(6px);
  box-shadow: 0 0 0 var(--teal-dark);
}
.btn-continua__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.85;
  margin-bottom: 6px;
  font-weight: 700;
}
.btn-continua__title {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: var(--sp-2);
  letter-spacing: -0.01em;
}
.btn-continua__meta {
  font-size: 0.88rem;
  opacity: 0.9;
  font-weight: 600;
}

/* ============================================================
   7. CARD E KPI
   ============================================================ */

.card-smaa {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.kpi {
  background: var(--surface);
  border: 1.5px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
}
.kpi__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: var(--sp-1);
}
.kpi__value {
  font-size: 1.75rem;
  font-weight: 900;
  color: var(--navy);
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.kpi__value-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-left: 4px;
  font-weight: 600;
}
.kpi__hint {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 500;
}
.kpi--accent { background: var(--info-bg); border-color: var(--info-bg); }
.kpi--danger .kpi__value { color: var(--danger); }
.kpi--success .kpi__value { color: var(--green-dark); }
.kpi--streak { background: var(--streak-bg); border-color: var(--streak-border); }
.kpi--streak .kpi__value { color: var(--streak-text); }
.kpi__trend {
  font-size: 0.9rem;
  font-weight: 800;
  margin-left: 6px;
  letter-spacing: -0.05em;
  vertical-align: 0.05em;
}
.kpi__trend.trend--su     { color: var(--trend-su); }
.kpi__trend.trend--giu    { color: var(--trend-giu); }
.kpi__trend.trend--piatto { color: var(--text-muted); }
.kpi__fuoco {
  font-size: 1.1rem;
  margin-right: 3px;
  vertical-align: -0.05em;
}

/* ============================================================
   7b. DAILY GOAL
   Card "obiettivo di oggi": titolo + contatore + barra progresso.
   Tre stati (gestiti dal JS con --state):
     in-corso   → barra teal
     completato → barra verde + bordo verde + emoji ✨
     superato   → barra verde + glow leggero + emoji 🚀
   Tutto su variabili: regge bene chiaro/scuro.
   ============================================================ */

.daily-goal {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: 0 3px 0 var(--shadow-solid);
  display: flex; flex-direction: column; gap: 8px;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.daily-goal__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-2);
}
.daily-goal__title {
  font-weight: 800;
  color: var(--navy);
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 8px;
}
.daily-goal__count {
  font-weight: 900;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}
.daily-goal__count strong { font-size: 1.05rem; }
.daily-goal__bar {
  height: 10px;
  background: var(--border-soft);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}
.daily-goal__bar-fill {
  height: 100%;
  width: 0;
  background: var(--teal);
  border-radius: 5px;
  transition: width 0.9s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
.daily-goal__bar-fill::after {
  content: "";
  position: absolute;
  top: 2px; left: 4px; right: 4px; height: 3px;
  background: rgba(255,255,255,0.4);
  border-radius: 2px;
}
.daily-goal__hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Stato: completato */
.daily-goal.is-completato {
  border-color: var(--green);
  box-shadow: 0 3px 0 var(--green-shadow);
}
.daily-goal.is-completato .daily-goal__bar-fill {
  background: var(--green);
}
.daily-goal.is-completato .daily-goal__title { color: var(--green-dark); }

/* Stato: superato (oltre il 100%) */
.daily-goal.is-superato {
  border-color: var(--green);
  box-shadow: 0 3px 0 var(--green-shadow),
              0 0 0 4px var(--success-bg);
}
.daily-goal.is-superato .daily-goal__bar-fill {
  background: linear-gradient(90deg, var(--green) 0%, var(--teal) 100%);
}
.daily-goal.is-superato .daily-goal__title { color: var(--green-dark); }

/* Animazione di "raggiunto" — scatta una sola volta (controllata da JS) */
@keyframes daily-goal-reach {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.025); }
  100% { transform: scale(1); }
}
.daily-goal.is-reaching {
  animation: daily-goal-reach 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ============================================================
   7c. LIVELLO / GAMIFICATION
   Card compatta: badge numerico livello + nome + barra mini
   verso il prossimo + mini-collezione di badge sbloccati.
   Calcolata client-side da gamification.js (SmaaGami).
   ============================================================ */

.livello-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: 0 3px 0 var(--shadow-solid);
  display: flex; flex-direction: column; gap: 10px;
}
.livello-card__main {
  display: flex; align-items: center; gap: 12px;
}
.livello-card__num {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 14px;
  background: var(--teal);
  color: var(--on-navy);
  display: grid; place-items: center;
  font-weight: 900;
  font-size: 1.05rem;
  letter-spacing: -0.04em;
  box-shadow: 0 3px 0 var(--teal-dark);
}
.livello-card__num small {
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
  display: block;
  line-height: 1;
  margin-bottom: 1px;
}
.livello-card__num strong { font-size: 1.15rem; line-height: 1; }

.livello-card__info {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.livello-card__nome {
  font-weight: 800;
  color: var(--navy);
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.livello-card__progresso {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 600;
}
.livello-card__bar {
  height: 6px;
  background: var(--border-soft);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 2px;
}
.livello-card__bar-fill {
  height: 100%;
  background: var(--teal);
  border-radius: 3px;
  width: 0;
  transition: width 0.9s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mini-collezione badge sbloccati (max 5 visibili + counter "+N") */
.livello-card__badges {
  display: flex; align-items: center; gap: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border-soft);
}
.livello-card__badges-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-right: 4px;
}
.livello-badge {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: var(--surface-alt);
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  flex: 0 0 auto;
}
.livello-badge.is-locked {
  filter: grayscale(1);
  opacity: 0.35;
}
.livello-card__badges-more {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 800;
  margin-left: 2px;
}

/* La card livello è cliccabile (apre modal traguardi) */
.livello-card {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s, box-shadow 0.15s;
}
.livello-card:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--shadow-solid);
}

/* ============================================================
   7d. MODAL TRAGUARDI (full-screen)
   Aperta dal tap sulla card livello. Mostra i 5 livelli con
   il proprio evidenziato + griglia 8 badge (sbloccati e non).
   ============================================================ */

.modal-traguardi {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: var(--z-modal);
  display: none;
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.modal-traguardi.is-open {
  display: flex;
  animation: modal-fade-in 0.2s ease-out;
}
@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-traguardi__top {
  position: sticky; top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  padding: var(--sp-3) var(--sp-4);
  padding-top: calc(var(--sp-3) + env(safe-area-inset-top));
  display: flex; align-items: center; gap: var(--sp-3);
  z-index: 1;
}
.modal-traguardi__title {
  flex: 1;
  font-weight: 900;
  font-size: 1.05rem;
  color: var(--navy);
  letter-spacing: -0.01em;
}
.modal-traguardi__close {
  background: var(--surface-alt);
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.modal-traguardi__body {
  max-width: var(--app-max-width);
  width: 100%;
  margin: 0 auto;
  padding: var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-5);
}

.modal-traguardi__section-title {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
}

/* Scala dei 5 livelli */
.livelli-scala {
  display: flex; flex-direction: column; gap: 10px;
}
.livello-row {
  display: flex; align-items: center; gap: 12px;
  padding: var(--sp-3);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
}
.livello-row.is-current {
  border-color: var(--teal);
  background: var(--info-bg);
  box-shadow: 0 2px 0 var(--teal-dark);
}
.livello-row.is-done {
  opacity: 0.7;
}
.livello-row__num {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--border);
  color: var(--text-muted);
  display: grid; place-items: center;
  font-weight: 900;
  font-size: 0.95rem;
}
.livello-row.is-current .livello-row__num {
  background: var(--teal);
  color: var(--on-navy);
}
.livello-row.is-done .livello-row__num {
  background: var(--green);
  color: var(--on-navy);
}
.livello-row__info { flex: 1; min-width: 0; }
.livello-row__nome {
  font-weight: 800;
  color: var(--navy);
  font-size: 0.98rem;
}
.livello-row__range {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 2px;
}
.livello-row.is-current .livello-row__range {
  color: var(--teal-dark);
  font-weight: 700;
}

/* Griglia 8 badge */
.badges-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}
.badge-cell {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  min-height: 70px;
}
.badge-cell.is-locked {
  background: var(--surface-alt);
  border-style: dashed;
}
.badge-cell__emoji {
  font-size: 1.8rem;
  line-height: 1;
  flex: 0 0 auto;
}
.badge-cell.is-locked .badge-cell__emoji {
  filter: grayscale(1);
  opacity: 0.4;
}
.badge-cell__text { flex: 1; min-width: 0; }
.badge-cell__nome {
  font-weight: 800;
  font-size: 0.88rem;
  color: var(--navy);
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin-bottom: 3px;
}
.badge-cell.is-locked .badge-cell__nome {
  color: var(--text-muted);
}
.badge-cell__hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.3;
  font-weight: 500;
}

/* ============================================================
   7e. TOAST SBLOCCO BADGE
   Notifica scenica che appare in alto quando un badge passa da
   bloccato a sbloccato. Auto-dismiss dopo 3s. Stack verticale se
   se ne sbloccano più contemporaneamente.
   ============================================================ */

.unlock-stack {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;            /* sopra header e modal */
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 380px;
}

.unlock-toast {
  background: var(--surface);
  border: 2px solid var(--green);
  border-radius: var(--r-md);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18),
              0 2px 0 var(--green-shadow);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
  pointer-events: auto;
  animation: unlock-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.unlock-toast.is-leaving {
  animation: unlock-out 0.3s cubic-bezier(0.4, 0, 1, 1) both;
}
@keyframes unlock-in {
  from { opacity: 0; transform: translateY(-30px) scale(0.92); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
@keyframes unlock-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-20px); }
}

.unlock-toast__emoji {
  font-size: 2rem;
  line-height: 1;
  flex: 0 0 auto;
  animation: unlock-emoji 0.7s ease-out both;
}
@keyframes unlock-emoji {
  0%   { transform: scale(0) rotate(-30deg); }
  60%  { transform: scale(1.2) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}

.unlock-toast__text { flex: 1; min-width: 0; }
.unlock-toast__label {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--green-dark);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 2px;
}
.unlock-toast__nome {
  font-weight: 900;
  color: var(--navy);
  font-size: 1rem;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

/* ============================================================
   8. FORM
   ============================================================ */

.form-smaa .form-label {
  display: block;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--navy);
  margin-bottom: var(--sp-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.form-smaa .form-control {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  font-size: 1rem;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 52px;
  color: var(--text);
}
.form-smaa .form-control:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.15);
}
.form-smaa .form-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: var(--sp-2);
}

.input-pin {
  text-align: center;
  letter-spacing: 0.4em;
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   9. ALERT
   ============================================================ */

.alert-smaa {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: 0.95rem;
  margin-bottom: var(--sp-3);
  font-weight: 500;
}
.alert-smaa--danger  { background: var(--danger-bg);  color: var(--danger-text); }
.alert-smaa--warning { background: var(--warning-bg); color: var(--warning-text); }
.alert-smaa--success { background: var(--success-bg); color: var(--success-text); }
.alert-smaa--info    { background: var(--info-bg);    color: var(--info-text); }

/* ============================================================
   10. LANDING / LOGIN
   ============================================================ */

.landing {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: var(--app-max-width);
  margin: 0 auto;
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  padding: var(--sp-5) var(--sp-4);
  position: relative;
  box-shadow: 0 0 80px rgba(15, 42, 68, 0.08);
}

.landing__hero {
  background: var(--navy-surface);
  color: var(--on-navy);
  margin: calc(var(--sp-5) * -1) calc(var(--sp-4) * -1) var(--sp-6);
  padding: var(--sp-7) var(--sp-4) var(--sp-6);
  border-radius: 0 0 40px 40px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.landing__hero::before {
  content: "";
  position: absolute;
  top: -20%; right: -30%;
  width: 80%; height: 80%;
  background: radial-gradient(circle, var(--teal) 0%, transparent 60%);
  opacity: 0.35;
  pointer-events: none;
}
.landing__hero::after {
  content: "";
  position: absolute;
  bottom: -30%; left: -20%;
  width: 70%; height: 70%;
  background: radial-gradient(circle, var(--yellow) 0%, transparent 60%);
  opacity: 0.15;
  pointer-events: none;
}

.landing__brand-mark-big {
  width: 72px; height: 72px;
  background: var(--on-navy);
  color: var(--navy-surface);
  border-radius: 18px;
  display: grid; place-items: center;
  font-weight: 900;
  font-size: 1.6rem;
  letter-spacing: -0.05em;
  margin: 0 auto var(--sp-4);
  position: relative;
  z-index: 1;
  box-shadow: 0 8px 0 rgba(0,0,0,0.25);
}

.landing__title {
  color: var(--on-navy);
  font-size: 1.75rem;
  font-weight: 900;
  margin-bottom: var(--sp-2);
  letter-spacing: -0.02em;
  position: relative;
  z-index: 1;
}

.landing__subtitle {
  color: rgba(255,255,255,0.85);
  font-size: 0.95rem;
  position: relative;
  z-index: 1;
}

.landing__footer {
  margin-top: auto;
  padding-top: var(--sp-5);
  font-size: 0.85rem;
  text-align: center;
  color: var(--text-muted);
}

/* ============================================================
   11. UTILITY
   ============================================================ */

.text-muted-smaa { color: var(--text-muted); }

.hidden { display: none !important; }

.pill {
  display: inline-block;
  padding: 4px 12px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-radius: var(--r-pill);
}
.pill--nuovo       { background: var(--surface-alt); color: var(--text-muted); }
.pill--buono       { background: var(--success-bg); color: var(--success-text); }
.pill--medio       { background: var(--warning-bg); color: var(--warning-text); }
.pill--da_rivedere { background: var(--danger-bg); color: var(--danger-text); }

.divider {
  height: 1px;
  background: var(--border-soft);
  margin: var(--sp-4) 0;
}

.section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-weight: 800;
  margin: var(--sp-5) 0 var(--sp-3);
}

/* Skeleton loading */
@keyframes skeleton-pulse {
  0%   { opacity: 0.7; }
  50%  { opacity: 0.35; }
  100% { opacity: 0.7; }
}
.skeleton {
  background: var(--surface-alt);
  border-radius: var(--r-sm);
  animation: skeleton-pulse 1.2s ease-in-out infinite;
  display: inline-block;
}
.skeleton-line { height: 1rem; width: 100%; margin: 0.35rem 0; }
.skeleton-line--short { width: 50%; }
.skeleton-line--tall  { height: 2.2rem; }

/* Animazioni entrata */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up          { animation: fade-up 0.35s ease-out both; }
.fade-up-delay-1  { animation: fade-up 0.35s 0.05s ease-out both; }
.fade-up-delay-2  { animation: fade-up 0.35s 0.1s ease-out both; }
.fade-up-delay-3  { animation: fade-up 0.35s 0.15s ease-out both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
