/* host.css — stili specifici della vista docente (proiettata). */

.host-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap;
  padding: 9px clamp(12px, 2vw, 22px);
  border-bottom: 1px solid var(--border);
  background: rgba(7, 11, 34, 0.72);
  backdrop-filter: blur(12px);
}
.host-header .brand .name { font-size: 1.05rem; }
.host-header .brand .logo { width: 30px; height: 30px; border-radius: 6px; }
.host-header .brand .logo svg { width: 18px; height: 18px; }

/* Gruppo informativo: PIN, avanzamento, conteggio risposte, timer numerico. */
.hinfo { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: 4px; }
.pill.mono { font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace; letter-spacing: 0.06em; }
.pill.counter b { color: var(--text); font-size: 1rem; }
.pill.counter .slash { color: var(--muted); margin: 0 1px; }
.htimer {
  display: inline-flex; align-items: baseline; gap: 1px;
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.15rem;
  padding: 3px 10px; border: 1px solid var(--border-strong);
  min-width: 46px; justify-content: center;
}
.htimer.warn { color: var(--bad); border-color: var(--bad); }
.htimer b { font-size: 1.15rem; }

/* Gruppo comandi (a destra). */
.hctrl { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.hctrl .btn.icon { padding: 8px 10px; font-size: 1rem; line-height: 1; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.btn.danger:hover { color: var(--bad); border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
/* Piccola separazione dai comandi di avanzamento, per evitare click accidentali. */
#hbEnd { margin-left: 6px; }
.hbAdvance-pulse { }

/* Barra timer sottile sul bordo inferiore dell'header. */
.htimerbar { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: transparent; }
.htimerbar span { display: block; height: 100%; width: 100%; transform-origin: left; background: var(--brand-grad); transition: transform 0.2s linear; }
.htimerbar.warn span { background: linear-gradient(90deg, #ff5d6c, #ff9a3c); }

/* Tutti gli elementi dell'header (PIN, avanzamento, conteggio, timer, nome
   docente e tasti) alla stessa altezza, verticalmente centrati. */
.host-header .hinfo > *, .host-header .hctrl > * {
  height: 38px; min-height: 0;
  display: inline-flex; align-items: center; justify-content: center;
}

.host-main { flex: 1; display: flex; flex-direction: column; }

/* ---- Setup ---- */
.setup-card { width: min(640px, 100%); padding: clamp(24px, 4vw, 44px); }
[data-screen="setup"] .setup-card { width: min(736px, 100%); }
.setup-card h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); margin-bottom: 6px; }
.quiz-list { display: flex; flex-direction: column; gap: 10px; margin: 20px 0; max-height: 46vh; overflow-y: auto; padding: 2px; }
.quiz-opt {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 15px 18px 15px 20px; border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.22); border: 1px solid var(--border);
  cursor: pointer; transition: border 0.2s, background 0.2s, transform 0.1s;
}
/* Barra accento a sinistra: invisibile finché non selezionato. */
.quiz-opt::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--brand-grad); opacity: 0; transition: opacity 0.2s;
}
.quiz-opt:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.quiz-opt.selected {
  border-color: var(--brand-1);
  background: color-mix(in srgb, var(--brand-1) 26%, transparent);
  /* Anello INTERNO: non viene ritagliato dall'overflow della lista (era il caso
     del primo box in cima). */
  box-shadow: inset 0 0 0 2px var(--brand-1);
}
.quiz-opt.selected::before { opacity: 1; }
.quiz-opt.selected .t { color: var(--text); }
.quiz-opt.selected .s { color: color-mix(in srgb, var(--text) 78%, transparent); }
.quiz-opt.invalid { opacity: 0.55; cursor: not-allowed; }
.quiz-opt .t { font-weight: 700; font-size: 1.05rem; }
.quiz-opt .s { color: var(--muted); font-size: 0.9rem; }
.quiz-actions { display: flex; align-items: center; gap: 6px; }
.quiz-select { flex: 1; min-width: 0; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.quiz-select:disabled { cursor: not-allowed; }
.quiz-select:focus-visible, .quiz-act:focus-visible { outline: 2px solid var(--brand-1); outline-offset: 4px; }
.quiz-select .t, .quiz-select .s { overflow-wrap: anywhere; }
.quiz-actions { flex: none; }
.quiz-act svg { width: 19px; height: 19px; }
.quiz-act:disabled { opacity: 0.4; cursor: not-allowed; }
.quiz-preview { width: min(760px, calc(100vw - 32px)); }
.preview-summary { color: var(--muted); font-size: 0.9rem; margin-bottom: 12px; }
.preview-list { margin: 0; padding-left: 28px; }
.preview-list li { padding: 10px 0 10px 6px; border-bottom: 1px solid var(--border); }
.preview-list li::marker { color: #bc9fff; font-weight: 700; }
.preview-question { font-size: 0.95rem; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.preview-meta { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 4px; }
.quiz-act {
  width: 28px; height: 28px; display: grid; place-items: center;
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  cursor: pointer; text-decoration: none; font-size: 0.9rem; border-radius: var(--radius-sm);
}
.quiz-act:hover { color: var(--text); border-color: var(--border-strong); }

/* ---- Login docente ---- */
#authSub { margin-bottom: 20px; }
.auth-error { color: var(--bad); text-align: center; margin-top: 10px; min-height: 1.2em; font-weight: 600; }
#authToggle { color: var(--brand-1); font-weight: 600; }
.auth-or { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 14px 0; position: relative; }
.auth-or::before, .auth-or::after { content: ""; position: absolute; top: 50%; width: 38%; height: 1px; background: var(--border); }
.auth-or::before { left: 0; } .auth-or::after { right: 0; }

/* ---- Pannello impostazioni ---- */
.set-body { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.set-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; cursor: pointer; }
.set-row input { width: 18px; height: 18px; accent-color: var(--brand-1); flex: none; }
.set-row span { line-height: 1.3; }
.users-box { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; max-height: 34vh; overflow-y: auto; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--border); }
.user-row .ui { flex: 1; min-width: 0; }
.user-row .ue { color: var(--muted); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .roles { display: flex; gap: 6px; }
.role-btn { font-size: 0.8rem; padding: 4px 9px; border: 1px solid var(--border-strong); background: transparent; color: var(--muted); cursor: pointer; }
.role-btn.active { color: #fff; background: var(--brand-1); border-color: var(--brand-1); }
.role-badge { font-size: 0.75rem; color: var(--accent-2); font-weight: 700; }

/* ---- Storico e report (tabelle compatte) ---- */
.reports-card, .report-card { width: min(1040px, 100%); margin: 0 auto; padding: clamp(16px, 2.2vw, 26px); }
.report-card h1 { font-size: 1.4rem; }
.rsub { font-size: 0.75rem; color: var(--muted); margin: 22px 0 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.rtable-wrap { overflow-x: auto; }
.rtable { width: 100%; border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.rtable th {
  text-align: left; font-weight: 700; color: var(--muted); font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.05em; padding: 6px 8px; white-space: nowrap;
  border-bottom: 1px solid var(--border-strong);
  position: sticky; top: 0; background: rgba(7, 11, 34, 0.9); backdrop-filter: blur(6px); z-index: 1;
}
.rtable td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.rtable tbody tr { cursor: default; }
.rtable tbody tr.clickable { cursor: pointer; }
.rtable tbody tr.clickable:hover td { background: rgba(255, 255, 255, 0.05); }
.rtable .num { text-align: right; }
.rtable .qtext { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rtable .acorr { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--good); font-weight: 600; }
.rtable .who { font-weight: 600; white-space: nowrap; }

/* Distribuzione risposte per opzione (mini barre). L'opzione corretta è marcata
   da una sottolineatura verde (non da un riquadro). */
.dist { display: inline-flex; align-items: flex-end; gap: 3px; height: 20px; }
.dist .seg { position: relative; width: 9px; min-height: 2px; opacity: 0.9; }
.dist .seg.correct::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -4px; height: 2px; background: var(--good);
}
.rtable td.center, .rtable th.center { text-align: center; }

/* Percentuale corrette con barra */
.pct { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.pct .bar { width: 60px; height: 6px; background: var(--surface-strong); position: relative; }
.pct .bar > i { position: absolute; inset: 0 auto 0 0; background: var(--good); }
.pct.low .bar > i { background: var(--bad); }
.pct.mid .bar > i { background: #f4a51c; }

/* Matrice esiti per domanda: priorità alle risposte (celle compatte a larghezza
   fissa); le colonne identità restano "congelate" a sinistra durante lo scroll. */
.rtable td.mx, .rtable th.mx { width: 22px; min-width: 22px; text-align: center; padding: 5px 2px; font-weight: 800; }
.mx.ok { color: var(--good); } .mx.no { color: var(--bad); } .mx.na { color: var(--faint); }

.rtable.students th:first-child, .rtable.students td:first-child {
  position: sticky; left: 0; width: 34px; min-width: 34px; z-index: 2; background: #12132b;
}
.rtable.students th:nth-child(2), .rtable.students td:nth-child(2) {
  position: sticky; left: 34px; z-index: 2; background: #12132b;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rtable.students thead th:first-child, .rtable.students thead th:nth-child(2) { z-index: 4; }

/* Overlay dettaglio domanda (risposte incolonnate, colore+forma, corrette in verde) */
.qo-qtext { color: var(--text); font-weight: 600; margin: 8px 0 14px; line-height: 1.35; white-space: pre-wrap; }
.qo-options { display: flex; flex-direction: column; gap: 8px; }
.qo-opt {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border); overflow: hidden;
}
.qo-opt .qo-bar { position: absolute; inset: 0 auto 0 0; background: rgba(255, 255, 255, 0.06); }
.qo-opt > *:not(.qo-bar) { position: relative; z-index: 1; }
.qo-glyph { width: 26px; height: 26px; flex: none; display: grid; place-items: center; }
.qo-glyph svg { width: 16px; height: 16px; }
.qo-label { flex: 1; line-height: 1.3; }
.qo-opt .cnt { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700; white-space: nowrap; }
.qo-opt.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.qo-opt.correct .cnt { color: var(--good); }
.qo-check { color: var(--good); font-weight: 900; margin-left: 6px; }

/* ---- Lobby ---- */
.lobby { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: clamp(20px, 3vw, 40px); align-items: start; }
.join-panel { padding: clamp(20px, 3vw, 34px); text-align: center; }
.pin-display { font-size: clamp(2.6rem, 5.2vw, 4.5rem); font-weight: 900; letter-spacing: 0.05em; line-height: 1.05;
  white-space: nowrap; max-width: 100%; overflow: hidden;
  font-variant-numeric: tabular-nums; background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pin-label { color: var(--muted); text-transform: uppercase; letter-spacing: 0.2em; font-size: 0.8rem; font-weight: 700; }
.qr { margin: 18px auto 8px; width: min(260px, 68%); background: white; padding: 10px; }
.qr img { width: 100%; display: block; }
.join-url { word-break: break-all; color: var(--muted); font-size: 0.95rem; }
.players-panel { padding: clamp(18px, 2.4vw, 26px); min-height: 280px; }
.players-panel h2 { font-size: 1.2rem; margin-bottom: 4px; }
.player-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.player-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border: 1px solid var(--border); font-weight: 600; font-size: 0.95rem;
  background: var(--surface-strong);
  animation: pop 0.4s cubic-bezier(0.2,0.9,0.3,1.3) both;
}
.chip-x {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 0.85rem; line-height: 1; padding: 0 2px;
}
.chip-x:hover { color: var(--bad); }
.player-chip.off { opacity: 0.45; }
.empty-hint { color: var(--muted); margin-top: 24px; text-align: center; font-size: 1.05rem; }
/* Tasti della lobby (Ingressi / Avvia) alla stessa altezza. */
#lockBtn, #startBtn { height: 46px; min-height: 0; display: inline-flex; align-items: center; justify-content: center; }

/* ---- Question / reveal ---- */
.q-stage { flex: 1; display: flex; flex-direction: column; gap: clamp(12px, 1.8vw, 22px);
  padding: clamp(14px, 2.4vw, 30px) clamp(16px, 3vw, 44px); position: relative; }
.q-stage[data-screen="question"] {
  display: grid; grid-template-rows: auto minmax(min-content, 1fr) auto;
}
.q-tags { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
.review-badge {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--brand-1); border: 1px solid color-mix(in srgb, var(--brand-1) 45%, transparent);
  padding: 3px 10px; background: color-mix(in srgb, var(--brand-1) 12%, transparent);
}
/* Indicatore del tipo di domanda; enfatizzato per la scelta multipla. */
.q-kind {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 0.82rem; font-weight: 700; letter-spacing: 0.02em;
  padding: 4px 12px; border: 1px solid var(--border-strong); color: var(--muted);
}
.q-kind .box { width: 13px; height: 13px; border: 2px solid currentColor; flex: none; }
.q-kind.multi {
  color: var(--text);
  border-color: var(--brand-1);
  background: color-mix(in srgb, var(--brand-1) 16%, transparent);
  font-size: 0.92rem;
}
.q-kind.multi .box { position: relative; }
.q-kind.multi .box::after { content: "✓"; position: absolute; inset: -4px 0 0 1px; font-size: 12px; font-weight: 900; }
.q-text {
  font-size: clamp(1.3rem, 2.6vw, 2.1rem); font-weight: 700; line-height: 1.25; letter-spacing: -0.01em;
  /* Usa tutta la riga e centra il testo nello spazio sopra le risposte. */
  display: grid; align-content: center;
  width: 100%; min-width: 0; margin: 0;
  text-align: center; white-space: pre-wrap; text-wrap: wrap; overflow-wrap: anywhere;
}
/* Le tessere restano in basso e crescono solo quando serve al loro contenuto.
   Lo spazio libero sopra di esse viene assegnato alla domanda. */
.answers.host { align-content: start; width: 100%; }
.answers.host .answer {
  cursor: default; pointer-events: none;
  min-height: clamp(64px, 9vw, 200px);
  font-size: clamp(1.1rem, 1.7vw, 1.7rem);
}
.q-hint { text-align: center; color: var(--muted); font-size: 0.92rem; }

/* ---- Leaderboard ---- */
.board-stage { justify-content: flex-start; }
.board-title { text-align: center; font-size: clamp(1.3rem, 2.6vw, 1.9rem); font-weight: 800; margin: 4px 0 6px; }
.board { width: min(820px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 7px; }
.lb-row {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 12px;
  padding: 9px 14px; border: 1px solid var(--border);
  background: var(--surface); position: relative; overflow: hidden;
  animation: rise 0.4s cubic-bezier(0.2,0.8,0.2,1) both;
}
.lb-row .bar { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(139,92,255,0.26), rgba(255,92,168,0.08)); transform-origin: left; transform: scaleX(0); transition: transform 0.8s cubic-bezier(0.2,0.8,0.2,1); z-index: 0; }
.lb-row > * { position: relative; z-index: 1; }
.lb-row .rank { font-size: 1.15rem; font-weight: 800; text-align: center; color: var(--muted); }
.lb-row .who { font-weight: 600; font-size: 1.05rem; }
.lb-row .pts { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.lb-row.top1 .rank { color: #f4c60a; } .lb-row.top2 .rank { color: #cdd6e6; } .lb-row.top3 .rank { color: #e0985a; }

/* ---- Podio finale ---- */
.podium-wrap { width: min(900px, 100%); margin: 0 auto; padding: clamp(16px, 3vw, 32px); text-align: center; }
.podium-wrap h1 { font-size: clamp(2rem, 5vw, 3.2rem); margin-bottom: 6px; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: clamp(10px, 2vw, 24px); margin: 40px 0 24px; min-height: 260px; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 12px; width: clamp(90px, 22vw, 200px); }
.pod .avatar { width: clamp(56px, 8vw, 84px); height: clamp(56px, 8vw, 84px); border-radius: 50%; display: grid; place-items: center;
  font-size: clamp(1.4rem, 3vw, 2rem); font-weight: 900; background: var(--brand-grad); color: white; box-shadow: var(--shadow-sm); }
.pod .who { font-weight: 800; font-size: clamp(1rem, 2vw, 1.3rem); }
.pod .pts { color: var(--muted); font-variant-numeric: tabular-nums; }
.pod .stand { width: 100%; display: grid; place-items: start center; padding-top: 14px;
  font-size: clamp(2rem, 5vw, 3.4rem); font-weight: 900; color: rgba(0, 0, 0, 0.55);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  animation: standRise 0.7s cubic-bezier(0.2,0.9,0.3,1.2) both; }
@keyframes standRise { from { transform: scaleY(0.2); opacity: 0; } to { transform: scaleY(1); opacity: 1; } }
.pod.p1 .stand { height: 180px; background: linear-gradient(180deg, #f4c60a, #b8930a); }
.pod.p2 .stand { height: 130px; background: linear-gradient(180deg, #cdd6e6, #8b93a6); }
.pod.p3 .stand { height: 100px; background: linear-gradient(180deg, #e0985a, #a86a34); }
.pod.p1 { order: 2; } .pod.p2 { order: 1; } .pod.p3 { order: 3; }
.saved-note { color: var(--muted); font-size: 0.9rem; margin-top: 8px; }
.saved-note code { background: rgba(0,0,0,0.3); padding: 2px 6px; }

@media (max-width: 820px) {
  .lobby { grid-template-columns: 1fr; }
}
