/* ===================== RESET & BASE ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0e17;
  --surface: #1a1932;
  --surface2: #232145;
  --accent: #ff6a3d;
  --accent2: #ffd166;
  --accent3: #06d6a0;
  --accent4: #118ab2;
  --accent5: #ef476f;
  --text: #fffffe;
  --text2: #a7a9be;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --font: 'Nunito', 'Segoe UI', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(106,61,226,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(255,106,61,0.10) 0%, transparent 50%);
}

/* ===================== SCREENS ===================== */
.screen {
  display: none;
  min-height: 100vh;
  flex-direction: column;
  align-items: center;
}
.screen.active {
  display: flex;
}

/* ===================== WELCOME ===================== */
#screen-welcome {
  justify-content: center;
  padding: 2rem 1.5rem;
  text-align: center;
  gap: 1rem;
}
.welcome-brain {
  font-size: 5rem;
  animation: float 2.5s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(255,209,102,0.5));
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}
.welcome-title {
  font-size: clamp(2rem, 6vw, 3.2rem);
  font-weight: 900;
  line-height: 1.15;
  background: linear-gradient(135deg, var(--accent2), var(--accent), var(--accent5));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.welcome-sub {
  font-size: 1.1rem;
  color: var(--text2);
  max-width: 400px;
  line-height: 1.5;
}
.welcome-features {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
}
.feature-chip {
  background: var(--surface2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 100px;
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.feature-chip span { font-size: 1.1rem; }

/* ===================== BUTTONS ===================== */
.btn-primary {
  font-family: var(--font);
  font-weight: 800;
  border: none;
  border-radius: 100px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent5));
  color: white;
  transition: transform 0.15s, box-shadow 0.2s;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.btn-primary:hover { transform: scale(1.05); }
.btn-primary:active { transform: scale(0.97); }

.btn-huge {
  font-size: 1.25rem;
  padding: 1rem 3rem;
  margin-top: 0.5rem;
}

.btn-secondary {
  font-family: var(--font);
  font-weight: 800;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 100px;
  cursor: pointer;
  background: var(--surface2);
  color: var(--text);
  font-size: 1rem;
  padding: 0.75rem 2rem;
  transition: transform 0.15s, border-color 0.2s;
}
.btn-secondary:hover { transform: scale(1.04); border-color: var(--accent2); }

/* ===================== HUD ===================== */
.game-hud {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: rgba(26,25,50,0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}
.hud-left { display: flex; flex-direction: column; gap: 0.15rem; }
.hud-round { font-size: 0.85rem; color: var(--text2); font-weight: 700; }
.hud-game-name { font-size: 1.1rem; font-weight: 900; }
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; flex: 1; max-width: 250px; margin: 0 1rem; }
.hud-score-bar {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,0.08);
  border-radius: 100px;
  overflow: hidden;
}
.hud-score-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent3), var(--accent2));
  border-radius: 100px;
  transition: width 0.5s ease;
}
.hud-score-text { font-size: 0.8rem; color: var(--text2); font-weight: 700; }
.hud-timer { font-size: 1rem; font-weight: 800; color: var(--accent2); font-variant-numeric: tabular-nums; }
.hud-timer.danger { color: var(--accent5); animation: pulse 0.5s ease infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }

/* ===================== GAME AREA ===================== */
#screen-game {
  padding-top: 0;
}
.game-area {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  gap: 1rem;
}
.game-controls {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.5rem 2rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===================== GAME: REACTION ===================== */
.reaction-zone {
  width: 100%;
  max-width: 500px;
  aspect-ratio: 16/10;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
  border: 3px solid transparent;
}
.reaction-zone.waiting {
  background: #1e1c3a;
  border-color: rgba(255,255,255,0.08);
}
.reaction-zone.ready {
  background: #c0392b;
  border-color: var(--accent5);
}
.reaction-zone.go {
  background: #27ae60;
  border-color: var(--accent3);
  color: white;
  text-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.reaction-zone.too-early {
  background: var(--accent5);
  border-color: #fff;
}
.reaction-result {
  font-size: 3rem;
  font-weight: 900;
  color: var(--accent2);
  text-shadow: 0 0 20px rgba(255,209,102,0.5);
}

/* ===================== GAME: MATH ===================== */
.math-container {
  width: 100%;
  max-width: 500px;
  text-align: center;
}
.math-progress {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 1.5rem;
}
.math-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  transition: background 0.3s;
}
.math-dot.correct { background: var(--accent3); }
.math-dot.wrong { background: var(--accent5); }
.math-dot.current { background: var(--accent2); box-shadow: 0 0 10px rgba(255,209,102,0.6); }

.math-question {
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 900;
  margin-bottom: 1.5rem;
  text-shadow: 0 0 30px rgba(255,209,102,0.3);
}
.math-answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.math-btn {
  font-family: var(--font);
  font-size: 1.4rem;
  font-weight: 800;
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255,255,255,0.1);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s, background 0.15s;
}
.math-btn:hover { transform: scale(1.04); border-color: var(--accent4); }
.math-btn:active { transform: scale(0.96); }
.math-btn.correct { background: var(--accent3); border-color: var(--accent3); color: #fff; }
.math-btn.wrong { background: var(--accent5); border-color: var(--accent5); color: #fff; }

/* ===================== GAME: MEMORY ===================== */
.memory-container {
  width: 100%;
  max-width: 420px;
  text-align: center;
}
.memory-info {
  font-size: 1rem;
  color: var(--text2);
  margin-bottom: 1rem;
  font-weight: 700;
}
.memory-sequence {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.memory-cube {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 900;
  background: var(--surface2);
  border: 2px solid rgba(255,255,255,0.08);
  transition: transform 0.3s, background 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.memory-cube.highlight {
  background: var(--accent2);
  border-color: var(--accent2);
  transform: scale(1.15);
  box-shadow: 0 0 25px rgba(255,209,102,0.5);
  color: #1a1932;
}
.memory-input-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}
.memory-choice-btn {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255,255,255,0.12);
  background: var(--surface);
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 900;
  font-family: var(--font);
  cursor: pointer;
  transition: transform 0.12s, background 0.15s;
}
.memory-choice-btn:hover { transform: scale(1.08); background: var(--surface2); }
.memory-choice-btn.chosen {
  background: var(--accent4);
  border-color: var(--accent4);
  transform: scale(0.92);
  opacity: 0.5;
  pointer-events: none;
}
.memory-answer {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 1rem;
}
.memory-answer-slot {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  border: 2px dashed rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--accent2);
}

/* ===================== GAME: LOGIC ===================== */
.logic-container {
  width: 100%;
  max-width: 500px;
  text-align: center;
}
.logic-question {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}
.logic-sequence {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.logic-seq-item {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 900;
  background: var(--surface2);
  border: 2px solid rgba(255,255,255,0.08);
}
.logic-seq-item.mystery {
  background: linear-gradient(135deg, var(--accent), var(--accent5));
  border-color: transparent;
  font-size: 1.8rem;
}
.logic-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.logic-opt {
  font-family: var(--font);
  font-size: 1.3rem;
  font-weight: 800;
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255,255,255,0.1);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s;
}
.logic-opt:hover { transform: scale(1.05); border-color: var(--accent4); }
.logic-opt.correct { background: var(--accent3); border-color: var(--accent3); color: #fff; }
.logic-opt.wrong { background: var(--accent5); border-color: var(--accent5); color: #fff; }

/* ===================== GAME: CODE ===================== */
.code-container {
  width: 100%;
  max-width: 550px;
  text-align: center;
}
.code-question {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text2);
  margin-bottom: 1rem;
}
.code-block {
  background: #12111e;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  text-align: left;
  overflow-x: auto;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.95rem;
  line-height: 1.7;
}
.code-line {
  display: flex;
  gap: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.code-line:hover { background: rgba(255,255,255,0.05); }
.code-line.highlight { background: rgba(255,106,61,0.2); border: 1px solid var(--accent); }
.code-line-num {
  color: var(--text2);
  opacity: 0.5;
  min-width: 1.5em;
  user-select: none;
}
.code-line-text { color: #e8eaf0; white-space: pre; }
.code-keyword { color: #c792ea; }
.code-string { color: #c3e88d; }
.code-number { color: #f78c6c; }
.code-comment { color: #546e7a; font-style: italic; }
.code-func { color: #82aaff; }

.code-hint {
  font-size: 0.9rem;
  color: var(--text2);
  margin-bottom: 1rem;
}

/* ===================== GAME: BATTLE (FINALE) ===================== */
.battle-container {
  width: 100%;
  max-width: 500px;
  text-align: center;
}
.battle-badge {
  display: inline-block;
  padding: 0.4rem 1.2rem;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 800;
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.battle-badge.reaction { background: var(--accent5); }
.battle-badge.logic { background: var(--accent4); }
.battle-badge.math { background: var(--accent2); color: #1a1932; }
.battle-badge.memory { background: #8F79C9; }
.battle-badge.code { background: var(--accent3); color: #1a1932; }

.battle-question {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 1.5rem;
  line-height: 1.4;
}
.battle-options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.battle-opt {
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.9rem 1.2rem;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255,255,255,0.1);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s, border-color 0.15s, background 0.15s;
}
.battle-opt:hover { transform: scale(1.02); border-color: var(--accent4); }
.battle-opt.correct { background: var(--accent3); border-color: var(--accent3); color: #fff; }
.battle-opt.wrong { background: var(--accent5); border-color: var(--accent5); color: #fff; }

/* ===================== RESULT ===================== */
#screen-result {
  justify-content: center;
  padding: 2rem 1.5rem;
  text-align: center;
}
.result-container {
  max-width: 500px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
}
.result-crown {
  font-size: 4rem;
  animation: float 2s ease-in-out infinite;
}
.result-title {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.result-total {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 1.5rem 3rem;
  box-shadow: var(--shadow);
}
.result-total-label { font-size: 0.9rem; color: var(--text2); font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; }
.result-total-score {
  font-size: 3.5rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent2), var(--accent3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.result-total-sub { font-size: 1rem; color: var(--text2); }

.result-skills {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.result-skill-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.04);
}
.result-skill-icon { font-size: 1.5rem; }
.result-skill-name { flex: 1; text-align: left; font-weight: 700; font-size: 0.95rem; }
.result-skill-bar {
  width: 100px;
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 100px;
  overflow: hidden;
}
.result-skill-fill {
  height: 100%;
  border-radius: 100px;
  transition: width 1s ease;
}
.result-skill-score { font-weight: 900; font-size: 0.95rem; min-width: 40px; text-align: right; }

.result-best {
  background: linear-gradient(135deg, rgba(255,106,61,0.15), rgba(239,71,111,0.15));
  border: 1px solid rgba(255,106,61,0.3);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  font-weight: 800;
  font-size: 1.1rem;
  line-height: 1.4;
}
.result-best-emoji { font-size: 1.8rem; display: block; margin-bottom: 0.3rem; }

/* ===================== FEEDBACK OVERLAY ===================== */
.feedback-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  pointer-events: none;
}
.feedback-text {
  font-size: 3rem;
  font-weight: 900;
  animation: feedbackPop 0.6s ease forwards;
}
@keyframes feedbackPop {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}

/* ===================== TRANSITION ===================== */
.game-transition {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.game-transition-emoji { font-size: 4rem; animation: float 1.5s ease-in-out infinite; }
.game-transition-title { font-size: 1.8rem; font-weight: 900; }
.game-transition-sub { font-size: 1rem; color: var(--text2); }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 480px) {
  .game-hud { padding: 0.75rem 1rem; }
  .hud-center { max-width: 140px; margin: 0 0.5rem; }
  .math-question { font-size: 2.2rem; }
  .math-btn { font-size: 1.1rem; padding: 0.8rem; }
  .memory-cube { width: 56px; height: 56px; font-size: 1.3rem; }
  .memory-choice-btn { width: 48px; height: 48px; font-size: 1.1rem; }
  .memory-answer-slot { width: 48px; height: 48px; font-size: 1.1rem; }
  .code-block { font-size: 0.82rem; padding: 0.75rem; }
}
