/* ============================================================
   MISSIONE 31 — style.css
   Tema: navy scuro + oro. Font self-hosted (Poppins/Inter).
   Nessuna libreria CSS. Mobile-first.
   ============================================================ */

/* ---------- FONT (self-hosted, funzionano offline) ---------- */
@font-face {
  font-family: "Poppins";
  src: url("assets/fonts/poppins/poppins-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Poppins";
  src: url("assets/fonts/poppins/poppins-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Poppins";
  src: url("assets/fonts/poppins/poppins-latin-800-normal.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("assets/fonts/inter/inter-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("assets/fonts/inter/inter-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("assets/fonts/inter/inter-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("assets/fonts/inter/inter-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- DESIGN TOKENS ---------- */
:root {
  --bg: #0f172a;
  --bg-deep: #0a1120;
  --card: #1e293b;
  --card-hi: #26374d;
  --gold: #fbbf24;
  --gold-dim: #a67c1f;
  --white: #ffffff;
  --muted: #94a3b8;
  --danger: #f87171;
  --success: #34d399;

  --font-display: "Poppins", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 24px;

  --ease: cubic-bezier(.22, 1, .36, 1);
  --dur-fast: 180ms;
  --dur-med: 380ms;
  --dur-slow: 700ms;

  --header-h: 128px;
  --dock-h: 84px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- RESET ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--white);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }
img { max-width: 100%; display: block; }

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

/* ---------- SFONDO PARTICELLE ---------- */
#bg-particles {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
}

/* ---------- SCREENS ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.screen--active {
  display: flex;
}

/* transizione ingresso schermata */
.screen--active > * {
  animation: screenEnter var(--dur-slow) var(--ease) both;
}

@keyframes screenEnter {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- TIPOGRAFIA COMUNE ---------- */
.eyebrow {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gold);
  text-align: center;
}

.text-gold { color: var(--gold); }

.section-label {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ---------- CARD ---------- */
.card {
  background: var(--card);
  border: 1px solid rgba(251, 191, 36, 0.12);
  border-radius: var(--radius-m);
  padding: 22px;
}

/* ---------- BOTTONI ---------- */
.btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  border-radius: var(--radius-s);
  padding: 15px 22px;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.btn--primary {
  background: linear-gradient(135deg, var(--gold), #f59e0b);
  color: #1a1305;
  box-shadow: 0 8px 24px -8px rgba(251, 191, 36, 0.55);
}
.btn--primary:hover { box-shadow: 0 10px 28px -6px rgba(251, 191, 36, 0.7); }

.btn--gold {
  background: rgba(251, 191, 36, 0.12);
  color: var(--gold);
  border: 1.5px solid var(--gold);
}
.btn--gold:hover { background: rgba(251, 191, 36, 0.2); }

.btn--ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(148, 163, 184, 0.3);
  margin: 28px auto 0;
}

.btn--large { padding: 18px 32px; font-size: 16px; width: 100%; max-width: 340px; }
.btn--full { width: 100%; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  font-size: 16px;
  flex-shrink: 0;
}

/* ============================================================
   SCHERMATA START
============================================================ */
#screen-start {
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  background:
    radial-gradient(ellipse 60% 45% at 50% 18%, rgba(251, 191, 36, 0.13), transparent 65%),
    var(--bg);
}

.start__content { display: flex; flex-direction: column; align-items: center; gap: 14px; }

.start__badge {
  width: 92px;
  height: 92px;
  border-radius: 26px;
  background: linear-gradient(145deg, var(--card-hi), var(--card));
  border: 1px solid rgba(251, 191, 36, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  box-shadow: 0 0 0 1px rgba(251,191,36,0.05), 0 20px 40px -18px rgba(251, 191, 36, 0.5);
  animation: badgeFloat 4.5s var(--ease) infinite;
}
.badge-gem { font-size: 40px; filter: drop-shadow(0 0 10px rgba(251,191,36,0.6)); }

@keyframes badgeFloat {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-8px) rotate(2deg); }
}

.start__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(38px, 11vw, 58px);
  letter-spacing: 1px;
  line-height: 1;
  margin-top: 4px;
}

.start__subtitle {
  color: var(--muted);
  font-size: 16px;
  margin-bottom: 18px;
}

/* ============================================================
   SCHERMATA BRIEFING
============================================================ */
#screen-briefing {
  align-items: center;
  justify-content: center;
  padding: 32px 22px;
  gap: 20px;
}

.briefing__content { width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 18px; }

.briefing__card { width: 100%; display: flex; flex-direction: column; gap: 14px; }

.briefing__text {
  font-size: 15.5px;
  line-height: 1.6;
  color: #e2e8f0;
}
.briefing__text--emphasis {
  color: var(--gold);
  font-weight: 600;
  border-top: 1px solid rgba(251, 191, 36, 0.15);
  padding-top: 14px;
}

/* ============================================================
   SCHERMATA MAIN
============================================================ */
#screen-main { padding: 0; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(251, 191, 36, 0.1);
}

.app-header__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.app-header__logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.5px;
}

.progress-wrap { display: flex; align-items: center; gap: 12px; }

.progress-bar {
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  position: relative;
}

.progress-bar__fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
  transition: width var(--dur-slow) var(--ease);
  position: relative;
}
.progress-bar__fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.55), transparent);
  width: 40px;
  animation: shine 2.2s linear infinite;
}
@keyframes shine {
  0% { transform: translateX(-40px); }
  100% { transform: translateX(220px); }
}

.progress-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  color: var(--gold);
  white-space: nowrap;
  min-width: 44px;
  text-align: right;
}

.app-main {
  flex: 1;
  padding: 20px 20px calc(var(--dock-h) + 28px);
  display: flex;
  flex-direction: column;
  gap: 26px;
  overflow-y: auto;
}

/* --- Inventario --- */
.inventory__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.inv-item {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-s);
  padding: 12px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--dur-med) var(--ease), background var(--dur-med) var(--ease);
}

.inv-item__icon {
  font-size: 22px;
  filter: grayscale(1) opacity(0.35);
  transition: filter var(--dur-med) var(--ease);
}

.inv-item__name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  transition: color var(--dur-med) var(--ease);
}

.inv-item.is-unlocked {
  border-color: rgba(251, 191, 36, 0.4);
  background: linear-gradient(160deg, rgba(251, 191, 36, 0.14), var(--card));
}
.inv-item.is-unlocked .inv-item__icon {
  filter: grayscale(0) opacity(1) drop-shadow(0 0 6px rgba(251, 191, 36, 0.7));
}
.inv-item.is-unlocked .inv-item__name { color: var(--gold); }

.inv-item.just-unlocked { animation: unlockPop var(--dur-slow) var(--ease); }
@keyframes unlockPop {
  0% { transform: scale(1); }
  35% { transform: scale(1.08); box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.6); }
  100% { transform: scale(1); }
}
.inv-item.just-unlocked::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.5) 50%, transparent 70%);
  transform: translateX(-120%);
  animation: sweepShine 900ms ease-out;
}
@keyframes sweepShine {
  to { transform: translateX(120%); }
}

/* --- Mission card --- */
.mission-zone { flex: 1; display: flex; }
.mission-card { width: 100%; display: flex; flex-direction: column; gap: 16px; }

.mission-card__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
}

.mission-card__desc {
  color: #cbd5e1;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-line;
}

.mission-card__locked {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 18px 6px;
  color: var(--muted);
}
.mission-card__locked-icon { font-size: 30px; opacity: 0.6; }

.mission-card__hint {
  font-size: 13px;
  color: var(--gold);
  font-weight: 600;
  margin-top: 4px;
}

.mission-card__form { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }

.mission-card__input {
  background: var(--bg-deep);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-s);
  padding: 14px 16px;
  color: var(--white);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: border-color var(--dur-fast) var(--ease);
}
.mission-card__input:focus { outline: none; border-color: var(--gold); }
.mission-card__input.is-error { border-color: var(--danger); animation: shake 380ms; }
.mission-card__input::placeholder { text-transform: none; color: #64748b; font-weight: 400; }

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

.mission-card__feedback {
  font-size: 13.5px;
  font-weight: 600;
  min-height: 18px;
}
.mission-card__feedback.is-error { color: var(--danger); }

.mission-card__success {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 10px 4px 4px;
  animation: scaleIn var(--dur-med) var(--ease);
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}
.mission-card__success-check {
  font-size: 30px;
  color: var(--success);
}
.mission-card__success-obj {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}
.mission-card__success-obj strong { color: var(--gold); }

/* Dock scansione QR */
.scan-dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 14px 20px calc(14px + var(--safe-bottom));
  background: linear-gradient(0deg, var(--bg) 55%, transparent);
  z-index: 4;
}
.scan-icon { font-size: 16px; }

/* ============================================================
   OVERLAY QR
============================================================ */
.qr-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
  display: none;
  flex-direction: column;
}
.qr-overlay.is-open { display: flex; }

.qr-overlay__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 18px 14px;
  color: var(--white);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  background: rgba(0,0,0,0.4);
  position: relative;
  z-index: 2;
}

.qr-overlay__viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
}

#qr-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.qr-canvas-hidden { display: none; }

.qr-frame {
  position: absolute;
  top: 50%; left: 50%;
  width: min(68vw, 300px);
  height: min(68vw, 300px);
  transform: translate(-50%, -50%);
  border-radius: 20px;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.5);
}
.qr-frame::before, .qr-frame::after {
  content: "";
  position: absolute;
  width: 34px; height: 34px;
  border: 3px solid var(--gold);
}
.qr-frame::before {
  top: -3px; left: -3px;
  border-right: none; border-bottom: none;
  border-radius: 14px 0 0 0;
}
.qr-frame::after {
  bottom: -3px; right: -3px;
  border-left: none; border-top: none;
  border-radius: 0 0 14px 0;
}

.qr-overlay__hint {
  text-align: center;
  padding: 16px 20px calc(20px + var(--safe-bottom));
  color: var(--muted);
  font-size: 13.5px;
  background: rgba(0,0,0,0.4);
}

/* ============================================================
   SCHERMATA FINALE
============================================================ */
#screen-final {
  background: #000;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  position: relative;
  overflow: hidden;
}
#screen-final > * { animation: none !important; }

#confetti-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.final__content {
  width: 100%;
  max-width: 440px;
  text-align: center;
  position: relative;
  z-index: 2;
}

.final__typewriter {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(17px, 5.2vw, 22px);
  line-height: 1.7;
  color: var(--white);
  min-height: 160px;
}
.final__typewriter .line { display: block; opacity: 0; }
.final__typewriter .line.shown { opacity: 1; }
.final__typewriter .cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--gold);
  margin-left: 3px;
  vertical-align: -0.15em;
  animation: blink 900ms step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.final__reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  animation: scaleIn 600ms var(--ease);
}
.final__reveal-icon {
  font-size: 54px;
  margin-bottom: 6px;
  filter: drop-shadow(0 0 18px rgba(251, 191, 36, 0.7));
}
.final__reveal-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
}
.final__reveal-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(24px, 7vw, 32px);
  color: var(--white);
  line-height: 1.3;
}
.final__reveal-sub {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 14px;
}

/* ============================================================
   SCHERMATA STATISTICHE
============================================================ */
#screen-stats {
  align-items: center;
  justify-content: center;
  padding: 32px 22px;
}
.stats__content { width: 100%; max-width: 420px; text-align: center; }
.stats__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  margin: 8px 0 22px;
}
.stats__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.stat-card { display: flex; flex-direction: column; gap: 4px; align-items: center; padding: 20px 12px; }
.stat-card__value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  color: var(--gold);
}
.stat-card__label {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ============================================================
   TOAST
============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translate(-50%, 16px);
  background: var(--card-hi);
  border: 1px solid rgba(251, 191, 36, 0.3);
  color: var(--white);
  padding: 12px 18px;
  border-radius: 99px;
  font-size: 13.5px;
  font-weight: 600;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-med) var(--ease), transform var(--dur-med) var(--ease);
  max-width: 88vw;
  text-align: center;
  box-shadow: 0 12px 30px -10px rgba(0,0,0,0.6);
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}
.toast.is-error { border-color: rgba(248, 113, 113, 0.4); }

/* ---------- Utility anim ---------- */
.anim-fade-in { animation: screenEnter var(--dur-slow) var(--ease) both; }

/* ---------- Responsive: schermi più larghi (tablet/desktop) ---------- */
@media (min-width: 640px) {
  .app-main { max-width: 480px; margin: 0 auto; width: 100%; }
  .scan-dock { display: flex; justify-content: center; }
  .scan-dock .btn { max-width: 480px; }
  .app-header__top, .progress-wrap { max-width: 480px; margin: 0 auto; }
}
