/* styles.css — sistema di design condiviso di AulaQuiz.
   Palette centralizzate in themes.css; struttura condivisa tra tutti i temi.
   Tipografia ampia e colore + forma per distinguere 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; }

/* Colori e superfici: themes.css. Le geometrie restano comuni a tutti i temi. */
:root { --radius: 0px; --radius-lg: 0px; --radius-sm: 0px; }

.aurora {
  position: fixed; inset: 0; z-index: -2;
  background: var(--page-decoration); filter: var(--page-filter);
  animation: var(--page-animation);
}
.aurora::after { content: ""; position: absolute; inset: 0; background: var(--page-shade); }
@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; } }

/* Pulsante condiviso: stesso comando da tastiera e puntatore in tutte le viste. */
.btn.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 38px; min-width: 38px; height: 38px;
  padding: 0; font-size: 0; line-height: 0; color: var(--text);
}
.btn.theme-toggle svg { display: block; flex: none; width: 22px; height: 22px; pointer-events: none; }
.theme-toolbar { display: flex; justify-content: flex-end; padding: 12px 16px 0; }
.theme-toolbar .theme-toggle { margin-top: 0; }
/* Nei pannelli di accesso il comando occupa l'angolo del marchio, senza una riga propria. */
.join-card, .st-login { position: relative; }
.join-card .theme-toolbar, .st-login .theme-toolbar { position: absolute; top: 12px; right: 12px; padding: 0; }
.join-card .brand, .st-login > .brand { max-width: calc(100% - 44px); }
@media (pointer: coarse) {
  .btn.theme-toggle { width: 44px; min-width: 44px; height: 44px; min-height: 44px; }
}

/* ---- 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: var(--logo-shadow);
  flex: none;
}
.brand .logo svg { width: 24px; height: 24px; fill: var(--on-brand); }
.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; }

/* ---- Superfici ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: var(--card-filter);
  -webkit-backdrop-filter: var(--card-filter);
}

/* ---- 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: var(--on-brand);
}
.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: inherit;
  width: min(600px, calc(100vw - 32px)); max-width: none;
  max-height: calc(100dvh - 32px); margin: auto; padding: 0;
  color: var(--text); background: var(--modal-bg);
  border: 1px solid var(--border-strong); border-top: 3px solid var(--brand-1);
  border-radius: var(--radius-lg); box-shadow: var(--modal-shadow);
  overflow: auto; overscroll-behavior: contain;
}
.app-modal::backdrop { background: var(--modal-backdrop); }
.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: var(--modal-mark-bg); color: var(--modal-mark); font-size: 1.5rem; font-weight: 800; }
.is-danger { border-top-color: var(--bad); }
.is-danger .modal-mark { color: var(--danger-mark); background: var(--danger-mark-bg); }
.app-modal .btn.destructive { background: var(--destructive-bg); color: var(--on-destructive); }
@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: var(--input-bg);
  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: var(--placeholder); opacity: 1; }
.input:focus { border-color: var(--brand-1); box-shadow: 0 0 0 4px var(--focus-ring); }
select, select.input, select option, select optgroup {
  color: var(--select-ink); background: var(--select-bg); font-family: inherit;
}
select option:checked { color: var(--select-selected-ink); background: var(--select-selected-bg); }
.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; }
.rtable-wrap { overflow-x: auto; }

/* ---- 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) var(--answer-bottom-mix), var(--answer-shade)));
  color: var(--on-answer);
  border: 1px solid var(--answer-border);
  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: var(--glyph-shadow);
}
.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[data-c="4"] { --_c: var(--ans-4); }
.answer[data-c="5"] { --_c: var(--ans-5); }
.answer:not(:disabled):hover { transform: translateY(-3px) scale(1.01); box-shadow: var(--answer-hover-shadow); }
.answer:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }
.answer:disabled { cursor: default; }

/* Stato selezionato (player, scelta multipla) */
.answer.selected { outline: 4px solid var(--on-answer); outline-offset: -4px; }
.answer.selected::after {
  content: "✓";
  position: absolute; top: 8px; right: 12px;
  font-size: 1.4rem; font-weight: 900;
}

/* Correzione: solo le soluzioni conservano il colore originale.
   I segni hanno un disco neutro proprio, leggibile su ogni colore delle tessere. */
.answer.solution-option {
  background: var(--solution-bg); color: var(--solution-ink);
  border: 1px solid color-mix(in srgb, var(--solution-border) 40%, transparent);
  box-shadow: none; cursor: default; opacity: 1; filter: none;
  gap: clamp(12px, 1.4vw, 20px);
}
.answer.solution-option:hover { transform: none; box-shadow: none; }
.answer.solution-option.correct {
  background: linear-gradient(180deg, var(--_c), color-mix(in srgb, var(--_c) var(--answer-bottom-mix), var(--answer-shade)));
  color: var(--on-answer); border-color: var(--answer-border); box-shadow: var(--shadow-sm);
}
.answer.solution-option.dimmed.chosen { color: var(--text); }
.solution-option .glyph svg { fill: currentColor; }
.solution-option.dimmed .glyph { filter: none; }
.solution-option .label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.solution-marker {
  display: grid; place-items: center; flex: none;
  width: clamp(30px, 3vw, 40px); height: clamp(30px, 3vw, 40px);
  border-radius: 50%; border: 2px solid currentColor;
  color: var(--solution-border); background: var(--solution-marker-bg);
  box-shadow: var(--shadow-sm);
}
.solution-marker svg { display: block; width: 80%; height: 80%; stroke-width: 3.6; }
.solution-option.correct .solution-marker { color: var(--solution-positive); }
.solution-option.wrong .solution-marker {
  color: var(--solution-negative); background: var(--solution-negative-marker-bg);
}
.solution-option .count {
  flex: none; min-width: 38px; padding: 5px 10px; border-radius: var(--radius-sm);
  font-size: 0.95rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums;
  color: var(--text); background: var(--solution-count-bg); border: 1px solid var(--border);
}

/* ---- 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: var(--timer-track); 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: var(--toast-bg); 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); }

.question-progress { display: inline-flex; align-items: center; gap: 5px; background: var(--progress-bg); font-variant-numeric: tabular-nums; white-space: nowrap; }
.question-progress b, .question-progress .question-prefix { font-size: 1.35rem; font-weight: 800; line-height: 1; }
.question-progress .question-current { color: var(--progress-current); }
.question-prefix { color: var(--text); }
.question-separator { font-size: 1rem; color: var(--text); }

/* ---- Confetti canvas ---- */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; }

@media (max-width: 560px) {
  .answers { grid-template-columns: 1fr; }
}
