:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --panel: #1c2330;
  --border: #2d3645;
  --text: #e6edf3;
  --muted: #8b949e;
  --gold: #c9a84c;
  --accent: #4c9bd2;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 50% 0%, #1b2433 0%, var(--bg) 60%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: min(720px, 100%);
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

#loading {
  text-align: center;
  color: var(--muted);
  font-size: 18px;
  padding: 60px 20px;
}

/* ---- Schermate ---- */
.screen { display: none; animation: fade 0.25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- Titolo ---- */
#title { text-align: center; }
.logo {
  font-size: 64px;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 2px 12px rgba(201, 168, 76, 0.4);
  margin-bottom: 4px;
}
.tagline { color: var(--muted); margin-bottom: 18px; font-size: 16px; }
.highscore { color: var(--gold); font-weight: 600; margin: 10px 0; }
.rules {
  margin-top: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  text-align: left;
}
.rules p { margin: 8px 0; color: var(--muted); font-size: 14px; }
.rules b { color: var(--text); }

/* ---- Pulsanti ---- */
.btn-primary, .btn-secondary {
  font-size: 18px;
  font-weight: 600;
  padding: 14px 36px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}
.btn-primary { background: var(--gold); color: #1a1300; margin-top: 22px; }
.btn-secondary { background: var(--panel); color: var(--text); border: 1px solid var(--border); }
.btn-primary:active, .btn-secondary:active { transform: scale(0.97); filter: brightness(1.1); }
.btn-row { display: flex; gap: 14px; justify-content: center; margin-top: 24px; flex-wrap: wrap; }
@media (hover: hover) {
  .btn-primary:hover, .btn-secondary:hover { filter: brightness(1.1); transform: translateY(-2px); }
}

/* ---- HUD ---- */
.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 12px;
}
#hud-score { color: var(--gold); font-weight: 700; font-size: 18px; }
.bonus-tag { color: var(--gold); font-size: 14px; }
.reward { color: var(--gold); font-weight: 700; }
.hud-right { display: flex; align-items: center; gap: 12px; }

/* ---- Pulsante audio ---- */
.mute-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}
.mute-btn:active { transform: scale(0.92); }
.title-mute { margin: 16px auto 0; display: flex; }

/* ---- Barra timer ---- */
.timerbar-track {
  width: 100%;
  height: 8px;
  background: var(--bg2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 18px;
}
.timerbar { height: 100%; width: 100%; background: #3fb950; transition: background 0.3s; }

/* ---- Meta domanda ---- */
.qmeta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.topic {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 12px;
}
.diff {
  color: #fff;
  border-radius: 20px;
  padding: 3px 12px;
  font-weight: 700;
}

/* ---- Domanda ---- */
.question {
  font-size: 23px;
  line-height: 1.4;
  margin-bottom: 22px;
  min-height: 64px;
}

/* ---- Risposte ---- */
.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.answers-2 { grid-template-columns: 1fr; }
.answer {
  position: relative;
  display: flex;
  align-items: center;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  padding: 16px 18px;
  min-height: 56px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  -webkit-user-select: none;
  user-select: none;
}
.answer .key {
  display: inline-block;
  width: 22px; height: 22px;
  line-height: 22px;
  text-align: center;
  background: var(--bg2);
  border-radius: 5px;
  font-size: 12px;
  color: var(--muted);
  margin-right: 10px;
}
@media (hover: hover) {
  .answer:not(:disabled):hover { background: #232c3b; border-color: var(--accent); transform: translateY(-1px); }
}
.answer:not(:disabled):active { background: #232c3b; border-color: var(--accent); transform: scale(0.99); }
.answer:disabled { cursor: default; }
.answer.correct { background: rgba(63, 185, 80, 0.22); border-color: #3fb950; }
.answer.wrong { background: rgba(248, 81, 73, 0.18); border-color: #f85149; opacity: 0.8; }

/* ---- Feedback ---- */
.feedback {
  margin-top: 18px;
  min-height: 24px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}
.feedback.ok { color: #3fb950; }
.feedback.ko { color: #f85149; }
.feedback.retry { color: #d29922; }

/* ---- Fine livello / bonus ---- */
#levelend, #bonusend, #result { text-align: center; padding-top: 30px; }
#levelend h2, #bonusend h2 { font-size: 30px; color: var(--gold); margin-bottom: 18px; }
.stats { font-size: 18px; line-height: 1.8; color: var(--muted); margin-bottom: 10px; }
.stats b { color: var(--text); }

/* ---- Risultato ---- */
#result h2 { font-size: 30px; margin-bottom: 10px; }
.record { color: var(--gold); font-size: 22px; font-weight: 700; margin: 10px 0; }
.final-score { color: var(--muted); margin-top: 18px; }
.big-score { font-size: 72px; font-weight: 800; color: var(--gold); margin: 6px 0; }

@media (max-width: 560px) {
  .logo { font-size: 46px; }
  .tagline { font-size: 14px; }
  .rules { padding: 14px 16px; }
  .rules p { font-size: 13px; }
  .question { font-size: 19px; min-height: 0; margin-bottom: 18px; }
  .answers { grid-template-columns: 1fr; gap: 10px; }
  .answer { font-size: 15.5px; padding: 14px 16px; min-height: 52px; }
  .btn-primary, .btn-secondary { font-size: 17px; padding: 14px 30px; width: 100%; max-width: 320px; }
  .btn-row { width: 100%; }
  .btn-row .btn-primary, .btn-row .btn-secondary { width: auto; flex: 1; min-width: 130px; }
  .hud { font-size: 14px; }
  .bonus-tag { font-size: 12.5px; }
  .big-score { font-size: 60px; }
  #levelend, #bonusend, #result { padding-top: 16px; }
  #levelend h2, #bonusend h2, #result h2 { font-size: 26px; }
  .feedback { font-size: 15px; }
}

@media (max-width: 360px) {
  .logo { font-size: 40px; }
  .question { font-size: 17.5px; }
  .answer { font-size: 15px; }
}

/* In orizzontale su telefoni bassi: comprimi gli spazi verticali */
@media (max-height: 480px) and (orientation: landscape) {
  body { align-items: flex-start; }
  .question { min-height: 0; margin-bottom: 14px; }
  .answers { grid-template-columns: 1fr 1fr; }
  .rules { display: none; }
}
