@font-face {
  font-family: "Poppins";
  src: url("fonts/poppins-500.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

@font-face {
  font-family: "Poppins";
  src: url("fonts/poppins-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "Poppins";
  src: url("fonts/poppins-800.woff2") format("woff2");
  font-weight: 800;
  font-display: swap;
}

:root {
  --bg: #F6F7FB;
  --ubox-orange: #F47A20;
  --ink: #2D3848;
  --ink-soft: #6B7280;
  --accepted: #02873E;
  --duplicate: #966200;
  --error: #CF222E;
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}

/* Come nel mockup: una sola tela 402x874 con la mappa a tutto schermo e logo,
   pill di stato e card sovrapposti. Non sono blocchi che comprimono la mappa. */
.app {
  position: relative;
  height: 100dvh;
  /* La tela prende tutta la larghezza disponibile: vincolarla alle proporzioni
     del mockup (402x874) la riduceva a una colonnina su schermi tozzi (su un
     iPhone SE ~250px). La mappa non si rimpicciolisce piu' per starci dentro,
     si esplora (vedi frameMap/enablePan in app.js). */
  width: min(100%, 460px);
  margin-inline: auto;
  /* Le misure tipografiche seguono la colonna, non la finestra: con vw il logo
     si gonfierebbe appena la colonna e' piu' stretta dello schermo. */
  container-type: inline-size;
  overflow: hidden;
  background: var(--bg);
}

.map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* Un dito sulla mappa la trascina; con due dita resta lo zoom del browser. */
  touch-action: pinch-zoom;
  cursor: grab;
}

/* Lo scheletro non e' esplorabile: non deve promettere il trascinamento. */
.map--skeleton { cursor: default; touch-action: auto; }

.map.is-panning { cursor: grabbing; }
.map:focus { outline: none; }
.map:focus-visible { outline: 3px solid var(--ubox-orange); outline-offset: -3px; }

/* ---------- logo ---------- */

/* La mappa scorre sotto l'intestazione: serve una fascia piena, altrimenti il
   marchio arancione capita sopra un'area colorata e non si legge piu'. */
.village-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(2.2%, env(safe-area-inset-top)) 4% 2.4%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3cqw;
  text-align: center;
  pointer-events: none;
  background: #FFFFFF;
  box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.08);
}

/* Il marchio si misura sul blocco di testo accanto, non su un valore fisso:
   restano proporzionati a qualunque larghezza di colonna. */
.village-brand {
  flex: none;
  width: 13cqw;
  height: auto;
}

/* Colonna: il titolo sopra, il sottotitolo esattamente sotto. Ogni riga e'
   larga quanto il suo testo, quindi centrarle qui allinea i bordi. */
.village-lockup {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* I due blocchi sono inline-block e ognuno annulla col margine destro la
   spaziatura che segue l'ultima lettera: quello spazio non e' inchiostro, e
   centrando la riga senza toglierlo i due bordi non combacerebbero.
   line-height stretto perche' sono tutte maiuscole, senza discendenti. */
.village-title {
  display: inline-block;
  margin: 0 0.03em 0 0;
  font-size: 13.5cqw;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 0.74;
  color: var(--ubox-orange);
}

/* Il corpo qui e' solo il punto di partenza: fitLockup lo riscrive misurando,
   perche' la larghezza di "STUDENT VILLAGE" deve combaciare con "UBOX". */
.village-subtitle {
  display: inline-block;
  margin: 0.16em -0.16em 0 0;
  font-size: 5cqw;
  font-weight: 600;
  letter-spacing: 0.16em;
  line-height: 1;
  color: var(--ubox-orange);
}

.bottom-stack {
  position: absolute;
  right: 3.5%;
  bottom: max(1.6%, env(safe-area-inset-bottom));
  width: 42%;
  min-width: 148px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* Il testo sta su una riga sola: la pill si dimensiona sul contenuto e sborda
   verso la mappa a sinistra, restando allineata al bordo destro della card. */
.status-pill {
  align-self: flex-end;
  width: max-content;
  max-width: none;
  white-space: nowrap;
  margin: 0;
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  background: #ECFDF3;
  color: var(--accepted);
  box-shadow: 0 2px 8px rgba(45, 56, 72, 0.12);
}

.status-pill--duplicate { background: #FEF6E7; color: var(--duplicate); }
.status-pill--rejected { background: #FDECEC; color: var(--error); }

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

.area-label {
  font-weight: 800;
  letter-spacing: 0.005em;
}

.cp-halo { fill: #fff; }
.cp-icon-lock { fill: #9AA1AC; }
.cp-icon-stroke { stroke: var(--ink); fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* Pulsa solo mentre si carica davvero: in errore il movimento suggerirebbe
   un caricamento ancora in corso. */
.app:has(.notice--loading) .village-skeleton {
  animation: skeletonPulse 1.6s ease-in-out infinite alternate;
}

.village-skeleton { opacity: 0.7; }

@keyframes skeletonPulse {
  from { opacity: 0.5; }
  to   { opacity: 0.85; }
}

.notice {
  position: absolute;
  left: 50%;
  bottom: 16%;
  translate: -50% 0;
  margin: 0;
  padding: 9px 16px;
  max-width: 78%;
  border-radius: 12px;
  background: #fff;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  line-height: 1.45;
  box-shadow: 0 4px 14px rgba(45, 56, 72, 0.14);
}

.notice--error {
  color: var(--error);
  font-weight: 600;
}

/* ---------- card progresso (in basso a destra, come nel mockup) ---------- */

.card {
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 4px 14px rgba(45, 56, 72, 0.14);
}

.card-line {
  margin: 0;
  font-size: clamp(10px, 3.2cqw, 13px);
  color: var(--ink-soft);
  text-align: center;
  white-space: nowrap;
}

.card-line strong { color: var(--ink); font-weight: 700; }

.bar {
  position: relative;
  height: 11px;
  margin: 7px 0 6px;
  border-radius: 999px;
  background: #FFE2C6;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--ubox-orange);
  transition: width 600ms cubic-bezier(0.22, 1, 0.36, 1);
}

.bar-gift {
  position: absolute;
  top: 50%;
  translate: -50% -50%;
  font-size: 15px;
  line-height: 1;
}

.card-sub {
  margin: 0;
  text-align: center;
  font-size: clamp(9px, 2.9cqw, 12px);
  color: var(--ink-soft);
  white-space: nowrap;
}

.card-sub strong { color: var(--ink); }

.claim-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  border: none;
  border-radius: 9px;
  background: var(--accepted);
  color: #fff;
  font-size: clamp(10px, 3.2cqw, 13px);
  font-weight: 700;
  cursor: pointer;
}

.claim-btn:disabled { opacity: 0.6; cursor: default; }

.card-suspended {
  margin: 8px 0 0;
  text-align: center;
  font-size: clamp(9px, 2.9cqw, 12px);
  color: var(--ink-soft);
}

/* ---------- animazioni: il villaggio "vivo" ---------- */

.village,
.tree,
.cp {
  transform-box: fill-box;
  transform-origin: center;
}

.tree { transform-origin: bottom center; }

/* Il villaggio respira come blocco unico: scalare le singole aree romperebbe
   l'incastro fra i confini condivisi. */
@keyframes breathe {
  from { transform: scale(1); }
  to   { transform: scale(1.008); }
}

@keyframes sway {
  from { transform: rotate(-2.2deg); }
  to   { transform: rotate(2.2deg); }
}

@keyframes bob {
  from { transform: translateY(0); }
  to   { transform: translateY(-2px); }
}

@keyframes pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.28); }
  60%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}

@keyframes haloPulse {
  0%   { transform: scale(1); opacity: 0.9; }
  70%  { transform: scale(2.1); opacity: 0; }
  100% { transform: scale(2.1); opacity: 0; }
}

@keyframes giftBounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

.village { animation: breathe 9s ease-in-out infinite alternate; }
.tree { animation: sway 4.5s ease-in-out infinite alternate; }
.cp--locked { animation: bob 3.6s ease-in-out infinite alternate; }
.cp--current { animation: pop 900ms cubic-bezier(0.22, 1, 0.36, 1) 1; }
.cp--current .cp-pulse { animation: haloPulse 1.9s ease-out infinite; }
.cp-pulse {
  transform-box: fill-box;
  transform-origin: center;
  opacity: 0;
  fill: none;
  stroke: #fff;
  stroke-width: 2.6;
}

/* Il completato pesa piu' del bloccato anche a colpo d'occhio */
.cp--done .cp-halo { fill: #fff; }
.cp--locked { opacity: 0.92; }
.bar-gift { animation: giftBounce 2.6s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  .map--skeleton .village-skeleton,
  .village, .tree, .cp--locked, .cp--current, .cp--current .cp-pulse, .bar-gift {
    animation: none;
  }
  .bar-fill { transition: none; }
}

/* ---------- pannello dell'attività ---------- */

/* Foglio dal basso: e' il gesto che il pollice si aspetta su mobile, e coprire
   la card del progresso mentre e' aperto e' voluto (e' modale). */
.sheet-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  background: rgba(35, 43, 63, 0.42);
  animation: fade 180ms ease-out;
}

.sheet {
  position: relative;
  width: 100%;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(35, 43, 63, 0.18);
  animation: sheetUp 240ms cubic-bezier(0.22, 1, 0.36, 1);
  max-height: min(88dvh, 760px);
  overflow-y: auto;
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 11px;
}

.sheet-icon {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
}

.sheet-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sheet-titles { min-width: 0; }

.sheet-kicker {
  margin: 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
}

.sheet-title {
  margin: 2px 0 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
}

.sheet-desc {
  margin: 11px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-soft);
}

/* L'avviso e' uno stato, non altra descrizione: se ha lo stesso aspetto del
   testo sopra si legge come una frase in piu' e non come il motivo per cui non
   c'e' un pulsante. */
.sheet-hint {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #F6F7FB;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-soft);
}

.sheet-done .sheet-hint { margin: 0; padding: 0; background: none; }

/* Il risultato e' un rimando, non un contenuto: il Tour non lo conserva. */
.sheet-done {
  margin-top: 12px;
  padding: 11px 12px;
  border-radius: 12px;
  background: #F6F7FB;
}

.sheet-done-line {
  margin: 0 0 9px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

.sheet-cta {
  display: block;
  margin-top: 12px;
  padding: 12px;
  border: none;
  border-radius: 12px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.sheet-cta--button {
  width: 100%;
  background: var(--ubox-orange);
  color: var(--ink);
}

.sheet-cta--button:disabled { opacity: 0.5; cursor: default; }

/* ---------- quiz nativo Risparmia ---------- */
.quiz-form { margin-top: 14px; }
.quiz-category-grid,
.quiz-answer-list {
  display: grid;
  gap: 8px;
}
.quiz-category-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.quiz-choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1.5px solid #DDE1EA;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.quiz-choice:has(input:checked) {
  border-color: var(--ubox-orange);
  background: #FFF8D8;
}
.quiz-choice:has(input:disabled) { opacity: 0.46; cursor: default; }
.quiz-choice input { accent-color: var(--ubox-orange); }
.quiz-counter {
  margin: 9px 2px 0;
  text-align: right;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
}
.quiz-question {
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}
.quiz-question legend {
  width: 100%;
  margin-bottom: 9px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}
.quiz-question legend span {
  display: block;
  margin-bottom: 3px;
  color: var(--ink-soft);
  font-size: 10px;
  letter-spacing: 0.08em;
}
.quiz-error {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #FFF0F0;
  color: #9B1C1C;
  font-size: 12px;
}
.quiz-reveal { text-align: center; }
.quiz-score {
  margin: 10px 0 -5px;
  color: var(--ink);
  font-size: clamp(48px, 18vw, 76px);
  font-weight: 800;
  line-height: 1;
}
.quiz-unit {
  margin: 0 0 14px;
  color: #966200;
  font-size: 18px;
  font-weight: 800;
}
.quiz-disclaimer {
  margin: 10px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.4;
}
.quiz-reveal-compact .sheet-cta { margin-top: 8px; }

@media (max-width: 360px) {
  .quiz-category-grid { grid-template-columns: 1fr; }
}

/* Il rimando al risultato e' una pill che si dimensiona sul testo: peso
   diverso dal pulsante che AVVIA l'attivita', che resta un blocco pieno.
   Azioni diverse, forme diverse. */
.sheet-done .sheet-cta {
  margin: 0;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13px;
}

.sheet-dismiss {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

/* Il badge che apre qualcosa lo dichiara col cursore. */
.cp--opens { cursor: pointer; }
[data-activity]:focus { outline: none; }
[data-activity]:focus-visible { outline: 3px solid var(--ubox-orange); }

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-backdrop { animation: none; }
}
