/* styles.css — sistema di design condiviso di AulaQuiz.
   Estetica "game show": sfondo profondo con aurora animata, superfici in vetro,
   tipografia ampia, colori vividi e accessibili (colore + forma per le risposte).
   Nessuna dipendenza esterna: tutto funziona offline in LAN. */

/* ---- Reset leggero ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Segoe UI Variable', 'Segoe UI', system-ui, -apple-system, 'Inter',
    'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
button { font-family: inherit; }
h1, h2, h3, p { margin: 0; }
img { max-width: 100%; }
/* L'attributo hidden deve sempre vincere sulle regole di display delle classi. */
[hidden] { display: none !important; }

/* ---- Design tokens ---- */
:root {
  --bg: #070b22;
  --text: #f4f6ff;
  --muted: #a6add6;

  --brand-1: #8b5cff;
  --brand-2: #ff5ca8;
  --brand-grad: linear-gradient(120deg, var(--brand-1), var(--brand-2));

  --surface: rgba(255, 255, 255, 0.06);
  --surface-strong: rgba(255, 255, 255, 0.11);
  --border: rgba(255, 255, 255, 0.16);
  --border-strong: rgba(255, 255, 255, 0.30);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.30);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);

  /* Colori delle risposte (colore + forma per accessibilità) */
  --ans-0: #e94b5a; /* triangolo */
  --ans-1: #2f6bff; /* rombo */
  --ans-2: #f4a51c; /* cerchio */
  --ans-3: #22a06b; /* quadrato */
  --ans-0-d: #c53545;
  --ans-1-d: #1f4fd0;
  --ans-2-d: #cc850a;
  --ans-3-d: #17805a;

  --good: #22c98b;
  --bad: #ff5d6c;

  /* Design "strumento didattico": niente rounding, bordi sottili. */
  --radius: 0px;
  --radius-lg: 0px;
  --radius-sm: 0px;
}

/* ---- Sfondo animato (aurora) ---- */
.aurora {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(60vmax 60vmax at 12% 8%, rgba(139, 92, 255, 0.35), transparent 60%),
    radial-gradient(55vmax 55vmax at 88% 18%, rgba(255, 92, 168, 0.28), transparent 60%),
    radial-gradient(65vmax 65vmax at 70% 92%, rgba(47, 107, 255, 0.30), transparent 62%),
    radial-gradient(50vmax 50vmax at 20% 88%, rgba(34, 160, 107, 0.22), transparent 60%);
  filter: saturate(1.1);
  animation: auroraDrift 26s ease-in-out infinite alternate;
}
.aurora::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120vmax 120vmax at 50% -10%, transparent 40%, rgba(0, 0, 0, 0.55));
}
@keyframes auroraDrift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(-3%, 2%, 0) scale(1.06); }
  100% { transform: translate3d(2%, -2%, 0) scale(1.03); }
}
@media (prefers-reduced-motion: reduce) {
  .aurora { animation: none; }
}

/* ---- Layout di base ---- */
.app {
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.wrap {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 32px);
}
.center-screen {
  flex: 1;
  display: grid;
  place-items: center;
  padding: clamp(16px, 4vw, 40px);
}

/* ---- Marchio ---- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand .logo {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--brand-grad);
  display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(139, 92, 255, 0.5);
  flex: none;
}
.brand .logo svg { width: 24px; height: 24px; }
.brand .name { font-size: clamp(20px, 2.4vw, 26px); }
.brand .name b { background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---- Card in vetro ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
}

/* ---- Pulsanti ---- */
.btn {
  --_bg: var(--surface-strong);
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--_bg);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}
.btn:hover { border-color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  border: 1px solid transparent;
  background: var(--brand-grad);
  color: white;
}
.btn.primary:hover { filter: brightness(1.08); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1.05rem; padding: 11px 20px; }
.btn.block { width: 100%; }
.btn:focus-visible { outline: 2px solid var(--brand-1); outline-offset: 2px; }

/* ---- Modali ---- */
html.modal-open { overflow: hidden; }
.app-modal {
  color-scheme: dark;
  width: min(600px, calc(100vw - 32px)); max-width: none;
  max-height: calc(100dvh - 32px); margin: auto; padding: 0;
  color: var(--text); background: linear-gradient(145deg, #20203e, #10152e);
  border: 1px solid var(--border-strong); border-top: 3px solid var(--brand-1);
  border-radius: var(--radius-lg); box-shadow: 0 28px 90px rgba(0, 0, 0, 0.55);
  overflow: auto; overscroll-behavior: contain;
}
.app-modal::backdrop { background: rgba(3, 6, 22, 0.78); }
.app-modal[open] { animation: modalIn 0.18s ease-out; }
.modal-panel { padding: clamp(20px, 4vw, 30px); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.modal-header h2, .confirm-modal h2 { font-size: clamp(1.2rem, 3vw, 1.5rem); line-height: 1.25; }
.modal-close { flex: none; width: 38px; height: 38px; padding: 0; }
.modal-message { color: var(--muted); line-height: 1.6; margin-top: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.app-modal .btn { min-height: 42px; }
.confirm-modal { width: min(480px, calc(100vw - 32px)); }
.modal-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--brand-1) 18%, transparent); color: #c6b4ff; font-size: 1.5rem; font-weight: 800; }
.is-danger { border-top-color: var(--bad); }
.is-danger .modal-mark { color: #ffb1b9; background: color-mix(in srgb, var(--bad) 16%, transparent); }
.app-modal .btn.destructive { background: linear-gradient(120deg, #b82c49, #b62d64); }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 480px) { .modal-actions .btn { flex: 1 1 auto; } }
@media (prefers-reduced-motion: reduce) { .app-modal[open] { animation: none; } }

/* ---- Campi ---- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-weight: 600; color: var(--muted); font-size: 0.95rem; }
.input {
  width: 100%;
  padding: 11px 14px;
  font-size: 1.05rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}
.input::placeholder { color: rgba(255, 255, 255, 0.4); }
.input:focus { border-color: var(--brand-1); box-shadow: 0 0 0 4px rgba(139, 92, 255, 0.25); }
.input.pin {
  text-align: center;
  letter-spacing: 0.35em;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
}

/* ---- Utilità ---- */
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.wrap-gap { flex-wrap: wrap; gap: 12px; }
.hidden { display: none !important; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 10px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  font-weight: 600; font-size: 0.82rem;
}
.tabular { font-variant-numeric: tabular-nums; }

/* ---- Forme delle risposte ---- */
.shape { width: 1em; height: 1em; display: inline-block; flex: none; }

/* ---- Griglia risposte (condivisa host/player) ---- */
.answers {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(8px, 1vw, 12px);
}
.answers.tf { grid-template-columns: repeat(2, 1fr); }
.answer {
  --_c: var(--ans-0);
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: clamp(10px, 1.3vw, 16px) clamp(12px, 1.5vw, 18px);
  min-height: clamp(52px, 7vw, 84px);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--_c), color-mix(in srgb, var(--_c) 82%, black));
  color: white;
  border: none;
  text-align: left;
  font-size: clamp(0.95rem, 1.4vw, 1.25rem);
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.2s ease, opacity 0.25s ease, filter 0.25s ease;
  overflow: hidden;
}
.answer .glyph {
  width: clamp(24px, 2.6vw, 34px);
  height: clamp(24px, 2.6vw, 34px);
  flex: none;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.35));
}
.answer .label { line-height: 1.3; }
.answer[data-c="0"] { --_c: var(--ans-0); }
.answer[data-c="1"] { --_c: var(--ans-1); }
.answer[data-c="2"] { --_c: var(--ans-2); }
.answer[data-c="3"] { --_c: var(--ans-3); }
.answer:not(:disabled):hover { transform: translateY(-3px) scale(1.01); box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45); }
.answer:disabled { cursor: default; }

/* Stato selezionato (player, scelta multipla) */
.answer.selected { outline: 4px solid white; outline-offset: -4px; }
.answer.selected::after {
  content: "✓";
  position: absolute; top: 8px; right: 12px;
  font-size: 1.4rem; font-weight: 900;
}

/* Stati di rivelazione */
.answer.correct { box-shadow: 0 0 0 4px var(--good), 0 20px 40px rgba(0,0,0,0.45); }
.answer.correct::after {
  content: "✓"; position: absolute; top: 8px; right: 14px; font-size: 1.5rem; font-weight: 900;
}
.answer.dimmed { opacity: 0.4; filter: grayscale(0.4); }

/* Conteggio a barra (host, reveal) */
.answer .count {
  position: absolute; right: 14px; bottom: 10px;
  font-size: 0.95rem; font-weight: 800;
  background: rgba(0, 0, 0, 0.35); padding: 3px 10px; border-radius: var(--radius-sm);
}

/* ---- Timer circolare ---- */
.timer-ring { position: relative; width: clamp(84px, 12vw, 132px); aspect-ratio: 1; }
.timer-ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.timer-ring .track { fill: none; stroke: rgba(255,255,255,0.14); stroke-width: 10; }
.timer-ring .fill {
  fill: none; stroke: url(#timerGrad); stroke-width: 10; stroke-linecap: round;
  transition: stroke-dashoffset 0.2s linear;
}
.timer-ring .num {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: clamp(1.6rem, 3vw, 2.4rem); font-weight: 800; font-variant-numeric: tabular-nums;
}
.timer-ring.warn .num { color: var(--bad); }

/* ---- Animazioni d'ingresso ---- */
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(0.8); opacity: 0; } 60% { transform: scale(1.05); } 100% { transform: scale(1); opacity: 1; } }
.rise { animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.pop { animation: pop 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
.stagger > * { animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.stagger > *:nth-child(1) { animation-delay: 0.04s; }
.stagger > *:nth-child(2) { animation-delay: 0.10s; }
.stagger > *:nth-child(3) { animation-delay: 0.16s; }
.stagger > *:nth-child(4) { animation-delay: 0.22s; }

/* ---- Toast ---- */
.toast {
  /* Centrato senza transform (l'animazione "rise" usa transform e lo
     sovrascriverebbe): centriamo con left/right + margin auto. */
  position: fixed; left: 0; right: 0; bottom: 24px;
  margin-inline: auto; width: fit-content; max-width: 90vw; text-align: center;
  background: rgba(20, 10, 40, 0.92); border: 1px solid var(--border-strong);
  padding: 14px 20px; border-radius: var(--radius-sm); font-weight: 600;
  box-shadow: var(--shadow); z-index: 50;
  animation: rise 0.3s ease both;
}
.toast.err { border-color: var(--bad); }

/* ---- Confetti canvas ---- */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; }

@media (max-width: 560px) {
  .answers { grid-template-columns: 1fr; }
}
