@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

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

:root {
  --bg-primary: #0f0c29;
  --bg-secondary: #1a1640;
  --bg-card: #242050;
  --accent-purple: #7c3aed;
  --accent-pink: #ec4899;
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --accent-red: #ef4444;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --board-size: min(90vw, 420px);
  --cell-size: calc(var(--board-size) / 8);
}

body {
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(135deg, var(--bg-primary) 0%, #1e1b4b 50%, #0f172a 100%);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  user-select: none;
}

#app { width: 100vw; height: 100vh; position: relative; overflow: hidden; }

.screen {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  z-index: 1; opacity: 0; transition: opacity 0.3s ease;
}
.screen.active { display: flex; opacity: 1; z-index: 10; }

/* MENU */
.menu-container { text-align: center; padding: 20px; width: 100%; max-width: 400px; }
.logo { margin-bottom: 40px; }
.logo-icon { font-size: 80px; animation: float 3s ease-in-out infinite; filter: drop-shadow(0 0 30px rgba(124,58,237,0.5)); }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

.logo h1 {
  font-size: 48px; font-weight: 900; letter-spacing: -2px;
  background: linear-gradient(135deg, #a78bfa, #7c3aed, #ec4899);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; margin-top: 10px;
}
.logo h1 span {
  background: linear-gradient(135deg, #f59e0b, #f97316);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.subtitle { color: var(--text-secondary); font-size: 18px; font-weight: 600; margin-top: 5px; letter-spacing: 4px; text-transform: uppercase; }
.menu-buttons { display: flex; flex-direction: column; gap: 12px; margin-bottom: 30px; }

.btn {
  padding: 16px 32px; border: none; border-radius: 16px;
  font-family: 'Nunito', sans-serif; font-size: 18px; font-weight: 800;
  cursor: pointer; transition: all 0.2s ease; text-transform: uppercase; letter-spacing: 1px;
}
.btn:active { transform: scale(0.95); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
  color: white; box-shadow: 0 4px 20px rgba(124,58,237,0.4);
}
.btn-primary:hover { box-shadow: 0 6px 30px rgba(124,58,237,0.6); transform: translateY(-2px); }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 2px solid rgba(124,58,237,0.3); }
.btn-secondary:hover { border-color: var(--accent-purple); background: rgba(124,58,237,0.1); }
.btn-danger { background: linear-gradient(135deg, var(--accent-red), #dc2626); color: white; box-shadow: 0 4px 20px rgba(239,68,68,0.3); }
.menu-footer { color: var(--text-muted); font-size: 14px; }

/* TUTORIAL */
.tutorial-container { padding: 20px; width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; text-align: center; }
.tutorial-container h2 { font-size: 28px; margin-bottom: 20px; }
.tutorial-steps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.tutorial-step { background: var(--bg-card); border-radius: 16px; padding: 16px; text-align: left; border: 1px solid rgba(124,58,237,0.2); }
.step-icon { font-size: 32px; margin-bottom: 8px; }
.tutorial-step h3 { font-size: 14px; margin-bottom: 4px; color: var(--accent-purple); }
.tutorial-step p { font-size: 12px; color: var(--text-secondary); line-height: 1.4; }
.tutorial-subjects { margin-bottom: 20px; }
.tutorial-subjects h3 { margin-bottom: 12px; font-size: 16px; }
.subject-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.subject-badge { padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 700; }
.subject-badge.math { background: rgba(239,68,68,0.2); color: #fca5a5; border: 1px solid rgba(239,68,68,0.4); }
.subject-badge.port { background: rgba(59,130,246,0.2); color: #93c5fd; border: 1px solid rgba(59,130,246,0.4); }
.subject-badge.sci { background: rgba(16,185,129,0.2); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.4); }
.subject-badge.hist { background: rgba(245,158,11,0.2); color: #fcd34d; border: 1px solid rgba(245,158,11,0.4); }
.subject-badge.geo { background: rgba(139,92,246,0.2); color: #c4b5fd; border: 1px solid rgba(139,92,246,0.4); }

/* RANKING */
.ranking-container { padding: 20px; width: 100%; max-width: 400px; max-height: 90vh; overflow-y: auto; text-align: center; }
.ranking-container h2 { font-size: 28px; margin-bottom: 20px; }
.ranking-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.ranking-item { display: flex; align-items: center; gap: 12px; background: var(--bg-card); padding: 12px 16px; border-radius: 12px; border: 1px solid rgba(124,58,237,0.2); }
.ranking-pos { font-size: 20px; font-weight: 900; width: 30px; }
.ranking-name { flex: 1; text-align: left; font-weight: 700; }
.ranking-score { font-weight: 800; color: var(--accent-yellow); }

/* GAME HEADER */
.game-header {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; max-width: 460px; padding: 8px 16px;
}
.level-info { display: flex; flex-direction: column; }
.level-label { font-weight: 800; font-size: 16px; }
.level-title { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; }
.score-display { text-align: center; }
.score-value { font-size: 32px; font-weight: 900; background: linear-gradient(135deg, #f59e0b, #f97316); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.score-label { font-size: 10px; color: var(--text-muted); letter-spacing: 2px; text-transform: uppercase; }
.btn-icon { background: var(--bg-card); border: 2px solid rgba(124,58,237,0.3); color: white; width: 40px; height: 40px; border-radius: 12px; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.btn-icon:hover { border-color: var(--accent-purple); }

/* PROGRESS */
.game-progress { width: 100%; max-width: 460px; padding: 0 16px 4px; }
.progress-bar { width: 100%; height: 10px; background: var(--bg-card); border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent-purple), var(--accent-pink)); border-radius: 5px; transition: width 0.5s ease; width: 0%; }
.progress-text { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* SUBJECTS BAR */
.game-subjects { display: flex; gap: 8px; padding: 4px 16px; width: 100%; max-width: 460px; justify-content: center; }
.subject-stat { font-size: 13px; font-weight: 700; padding: 4px 10px; background: var(--bg-card); border-radius: 20px; }

/* BOARD */
.board-container { display: flex; justify-content: center; align-items: center; padding: 8px 0; }
.board {
  display: grid; grid-template-columns: repeat(8, var(--cell-size)); grid-template-rows: repeat(8, var(--cell-size));
  background: var(--bg-card); border-radius: 16px; padding: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.05);
  border: 2px solid rgba(124,58,237,0.3);
  position: relative;
  touch-action: none;
}

.cell {
  width: var(--cell-size); height: var(--cell-size);
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px; cursor: pointer; position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cell:hover { transform: scale(1.05); z-index: 2; }
.cell.selected { transform: scale(1.15); z-index: 3; box-shadow: 0 0 0 3px white, 0 0 20px rgba(255,255,255,0.3); }
.cell.hint { animation: hintPulse 0.8s ease-in-out infinite; }

@keyframes hintPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); box-shadow: 0 0 15px rgba(255,255,255,0.3); }
}

.piece {
  width: 85%; height: 85%; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cell-size) * 0.5);
  font-weight: 900; color: white; text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  position: relative; transition: all 0.2s ease;
}

.piece.math { background: linear-gradient(135deg, #ef4444, #dc2626); box-shadow: 0 3px 10px rgba(239,68,68,0.4); }
.piece.port { background: linear-gradient(135deg, #3b82f6, #2563eb); box-shadow: 0 3px 10px rgba(59,130,246,0.4); }
.piece.sci { background: linear-gradient(135deg, #10b981, #059669); box-shadow: 0 3px 10px rgba(16,185,129,0.4); }
.piece.hist { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 3px 10px rgba(245,158,11,0.4); }
.piece.geo { background: linear-gradient(135deg, #8b5cf6, #7c3aed); box-shadow: 0 3px 10px rgba(139,92,246,0.4); }

/* BOOSTERS */
.piece.booster-line-h { background: linear-gradient(90deg, #fbbf24, #f59e0b, #fbbf24) !important; box-shadow: 0 0 15px rgba(251,191,36,0.6) !important; animation: boostGlow 1s ease-in-out infinite; }
.piece.booster-line-v { background: linear-gradient(180deg, #fbbf24, #f59e0b, #fbbf24) !important; box-shadow: 0 0 15px rgba(251,191,36,0.6) !important; animation: boostGlow 1s ease-in-out infinite; }
.piece.booster-bomb { background: linear-gradient(135deg, #ef4444, #fbbf24, #3b82f6) !important; box-shadow: 0 0 20px rgba(239,68,68,0.6) !important; animation: boostGlow 1s ease-in-out infinite; }
.piece.booster-color { background: conic-gradient(#ef4444, #f59e0b, #10b981, #3b82f6, #8b5cf6, #ef4444) !important; box-shadow: 0 0 20px rgba(139,92,246,0.6) !important; animation: boostGlow 1s ease-in-out infinite; }

@keyframes boostGlow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.3); }
}

/* ANIMATIONS */
@keyframes matchPop {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.8; }
  100% { transform: scale(0); opacity: 0; }
}

@keyframes dropIn {
  0% { transform: translateY(calc(-1 * var(--cell-size) * 3)); opacity: 0; }
  60% { transform: translateY(5px); opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes scorePopup {
  0% { transform: translateY(0) scale(0.5); opacity: 1; }
  100% { transform: translateY(-60px) scale(1.2); opacity: 0; }
}

.cell.removing .piece { animation: matchPop 0.3s ease forwards; }
.cell.dropping { animation: dropIn 0.4s ease; }

.score-popup {
  position: absolute; font-size: 20px; font-weight: 900;
  color: var(--accent-yellow); pointer-events: none;
  animation: scorePopup 0.8s ease forwards; z-index: 100;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* GAME FOOTER */
.game-footer { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 460px; padding: 4px 16px; }
.moves-display, .streak-display { text-align: center; }
.moves-label, .streak-label { display: block; font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.moves-value { font-size: 28px; font-weight: 900; color: var(--accent-cyan); }
.streak-value { font-size: 28px; font-weight: 900; color: var(--accent-yellow); }

.combo-display { text-align: center; min-width: 80px; }
.combo-text { font-size: 18px; font-weight: 900; color: var(--accent-pink); text-shadow: 0 0 10px rgba(236,72,153,0.5); }

/* MODALS */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal.active { display: flex; }

.modal-content {
  background: var(--bg-secondary); border-radius: 24px; padding: 28px;
  max-width: 420px; width: 90%; border: 2px solid rgba(124,58,237,0.3);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { transform: scale(0.8) translateY(30px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

/* QUESTION MODAL */
.question-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.question-subject { font-weight: 800; font-size: 16px; padding: 6px 14px; border-radius: 20px; }
.question-subject.math { background: rgba(239,68,68,0.2); color: #fca5a5; }
.question-subject.port { background: rgba(59,130,246,0.2); color: #93c5fd; }
.question-subject.sci { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.question-subject.hist { background: rgba(245,158,11,0.2); color: #fcd34d; }
.question-subject.geo { background: rgba(139,92,246,0.2); color: #c4b5fd; }
.question-points { font-weight: 800; color: var(--accent-yellow); font-size: 18px; }
.question-text { font-size: 18px; font-weight: 700; line-height: 1.5; margin-bottom: 20px; text-align: center; }
.question-options { display: flex; flex-direction: column; gap: 10px; }
.option-btn {
  padding: 14px 20px; border: 2px solid rgba(124,58,237,0.3); border-radius: 14px;
  background: var(--bg-card); color: var(--text-primary);
  font-family: 'Nunito', sans-serif; font-size: 16px; font-weight: 700;
  cursor: pointer; transition: all 0.2s ease; text-align: left;
}
.option-btn:hover { border-color: var(--accent-purple); background: rgba(124,58,237,0.15); transform: translateX(5px); }
.option-btn.correct { border-color: var(--accent-green); background: rgba(16,185,129,0.2); color: #6ee7b7; animation: correctPop 0.5s ease; }
.option-btn.wrong { border-color: var(--accent-red); background: rgba(239,68,68,0.2); color: #fca5a5; animation: wrongShake 0.5s ease; }
.option-btn:disabled { cursor: default; opacity: 0.7; }

@keyframes correctPop { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes wrongShake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

.question-feedback {
  margin-top: 16px; text-align: center; font-size: 16px; font-weight: 800;
  min-height: 24px; transition: all 0.3s ease;
}
.question-feedback.correct { color: var(--accent-green); }
.question-feedback.wrong { color: var(--accent-red); }

/* PAUSE MODAL */
.pause-modal { text-align: center; }
.pause-modal h2 { margin-bottom: 20px; font-size: 24px; }
.pause-stats { display: flex; gap: 16px; justify-content: center; margin-bottom: 24px; flex-wrap: wrap; }
.stat-item { background: var(--bg-card); padding: 12px 20px; border-radius: 12px; min-width: 80px; }
.stat-label { display: block; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.stat-value { display: block; font-size: 24px; font-weight: 900; margin-top: 4px; }
.pause-buttons { display: flex; gap: 12px; justify-content: center; }
.pause-buttons .btn { flex: 1; padding: 14px 20px; font-size: 15px; }

/* LEVEL COMPLETE */
.level-complete-container, .game-over-container { text-align: center; padding: 30px; max-width: 400px; }
.level-complete-icon, .game-over-icon { font-size: 80px; animation: float 2s ease-in-out infinite; }
.level-complete-container h2, .game-over-container h2 { font-size: 28px; margin: 16px 0; }
.game-over-container p { color: var(--text-secondary); margin-bottom: 20px; }
.level-complete-stats, .game-over-stats { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; align-items: center; }
.level-complete-stats .stat-item, .game-over-stats .stat-item { display: flex; justify-content: space-between; width: 100%; max-width: 280px; padding: 12px 20px; background: var(--bg-card); border-radius: 12px; }
.level-complete-stats .stat-label, .game-over-stats .stat-label { font-size: 14px; color: var(--text-secondary); }
.level-complete-stats .stat-value, .game-over-stats .stat-value { font-size: 20px; font-weight: 900; }
.stars-display { justify-content: center !important; }
.stars-display .star { font-size: 36px; opacity: 0.3; transition: all 0.3s ease; }
.stars-display .star.earned { opacity: 1; animation: starPop 0.5s ease; filter: drop-shadow(0 0 10px rgba(251,191,36,0.5)); }

@keyframes starPop { 0% { transform: scale(0); } 50% { transform: scale(1.3); } 100% { transform: scale(1); } }

.level-complete-buttons, .game-over-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.level-complete-buttons .btn, .game-over-buttons .btn { flex: 1; min-width: 140px; }

/* RESPONSIVE */
@media (max-height: 700px) {
  .logo-icon { font-size: 50px; }
  .logo h1 { font-size: 36px; }
  .subtitle { font-size: 14px; }
  .game-header { padding: 4px 16px; }
  .score-value { font-size: 24px; }
  .moves-value, .streak-value { font-size: 22px; }
}

@media (max-height: 600px) {
  :root { --board-size: min(90vw, 320px); }
  .logo { margin-bottom: 20px; }
  .logo-icon { font-size: 40px; }
  .logo h1 { font-size: 28px; }
  .menu-buttons .btn { padding: 12px 24px; font-size: 15px; }
}
