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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Trebuchet MS', Verdana, system-ui, sans-serif;
  background: linear-gradient(160deg, #d4f5e9 0%, #e8dff5 50%, #d4f5e9 100%);
  color: #1e293b;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* === Canvas === */
#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* === Scenes === */
.scene {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  z-index: 1;
}
.scene.active {
  opacity: 1;
  pointer-events: auto;
}

/* === Decorative Background Blobs === */
body::before, body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}
body::before {
  width: 480px; height: 480px;
  background: radial-gradient(circle, rgba(251, 191, 36, 0.10) 0%, transparent 70%);
  top: -120px; right: -120px;
}
body::after {
  width: 360px; height: 360px;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.08) 0%, transparent 70%);
  bottom: -80px; left: -80px;
}

/* === Panel === */
.game-panel {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 3px solid rgba(30, 41, 59, 0.12);
  border-radius: 28px;
  box-shadow: 0 8px 32px rgba(30, 41, 59, 0.10), 0 2px 8px rgba(30, 41, 59, 0.06);
  padding: 32px 28px;
}

/* === Title === */
.game-title {
  font-family: 'Trebuchet MS', Verdana, system-ui;
  font-size: 40px;
  font-weight: 900;
  color: #3730a3;
  text-align: center;
  letter-spacing: -0.5px;
  line-height: 1.1;
  text-shadow: 0 2px 0 rgba(55, 48, 163, 0.15);
  margin-bottom: 8px;
}

/* === START SCENE === */
.start-card {
  max-width: 380px;
  width: 88%;
  text-align: center;
}
.start-subtitle {
  color: #64748b;
  font-size: 15px;
  margin-bottom: 20px;
  line-height: 1.4;
}
.start-stats {
  margin-bottom: 24px;
}
.stat-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  color: #475569;
}

/* === Icons === */
.star-icon, .flag-icon, .heart-icon {
  display: inline-block;
  width: 20px; height: 20px;
  flex-shrink: 0;
}
.star-icon::before {
  content: '\2605';
  font-size: 20px;
  color: #f59e0b;
  line-height: 1;
}
.flag-icon::before {
  content: '\2691';
  font-size: 20px;
  color: #6366f1;
  line-height: 1;
}
.heart-icon {
  display: inline-block;
}
.heart-icon::before {
  content: '\2665';
  font-size: 22px;
  color: #e11d48;
  line-height: 1;
  transition: all 0.3s ease;
}
.heart-icon.lost::before {
  color: #cbd5e1;
  transform: scale(0.85);
}

/* === Button === */
.game-button {
  display: inline-block;
  padding: 14px 48px;
  border: 3px solid #1e293b;
  border-radius: 16px;
  background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
  color: #1e293b;
  font-family: 'Trebuchet MS', Verdana, system-ui;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 #1e293b, 0 8px 20px rgba(0,0,0,0.12);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  letter-spacing: 0.3px;
}
.game-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #1e293b, 0 4px 12px rgba(0,0,0,0.10);
}
.game-button:hover {
  background: linear-gradient(180deg, #fcd34d 0%, #f59e0b 100%);
}

/* === COUNTDOWN SCENE === */
#scene-countdown.active {
  background: rgba(55, 48, 163, 0.30);
}
.countdown-number {
  font-family: 'Trebuchet MS', Verdana, system-ui;
  font-size: 120px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 20px rgba(0,0,0,0.25);
  animation: countPop 0.7s ease-out forwards;
}
@keyframes countPop {
  0% { transform: scale(1.4); opacity: 1; }
  60% { transform: scale(1.0); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0; }
}

/* === HUD === */
.hud {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  pointer-events: none;
  gap: 8px;
}
.hud-left, .hud-right {
  pointer-events: auto;
}
.hud-center {
  display: flex;
  gap: 4px;
  pointer-events: auto;
}
.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255,255,255,0.90);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 2px solid rgba(30, 41, 59, 0.10);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  color: #475569;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.hud-chip strong {
  color: #1e293b;
}

/* === Reveal Area === */
.reveal-area {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.number-card {
  background: rgba(255,255,255,0.95);
  border: 3px solid rgba(55, 48, 163, 0.15);
  border-radius: 24px;
  padding: 28px 40px;
  box-shadow: 0 4px 24px rgba(55, 48, 163, 0.08);
  min-width: 200px;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.number-card.correct {
  border-color: #22c55e;
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.25);
}
.number-card.wrong {
  border-color: #ef4444;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.25);
}
.number-digits {
  font-family: 'Trebuchet MS', Verdana, system-ui;
  font-size: 52px;
  font-weight: 900;
  color: #3730a3;
  letter-spacing: 4px;
  line-height: 1.2;
  text-align: center;
}
.reveal-timer {
  width: 100%;
  max-width: 240px;
  height: 6px;
  background: #e2e8f0;
  border-radius: 99px;
  margin-top: 16px;
  overflow: hidden;
}
.reveal-timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #22c55e, #eab308, #ef4444);
  transition: width 0.05s linear;
}
.reveal-hint {
  color: #64748b;
  font-size: 14px;
  font-weight: 600;
}

/* === Recall Area === */
.recall-area {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 420px;
  padding: 0 12px;
}
.recall-area.hidden {
  display: none;
}
.recall-prompt {
  font-size: 18px;
  font-weight: 700;
  color: #475569;
  margin-bottom: 4px;
}
.input-display {
  background: #f1f5f9;
  border: 3px solid #cbd5e1;
  border-radius: 16px;
  padding: 16px 24px;
  min-height: 64px;
  width: 100%;
  text-align: center;
  font-size: 36px;
  font-weight: 900;
  color: #1e293b;
  letter-spacing: 6px;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.input-display.shake {
  animation: shake 0.3s ease;
}
.input-display.correct-flash {
  border-color: #22c55e;
  background: #f0fdf4;
}
.input-display.wrong-flash {
  border-color: #ef4444;
  background: #fef2f2;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.input-cursor {
  display: inline-block;
  animation: blink 0.8s step-end infinite;
  color: #94a3b8;
  font-weight: 400;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* === Numpad === */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 360px;
  margin-top: 8px;
}
.numpad-btn {
  height: 56px;
  border: 2px solid #cbd5e1;
  border-radius: 14px;
  background: #f8fafc;
  color: #1e293b;
  font-family: Verdana, system-ui;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 #cbd5e1, 0 4px 10px rgba(0,0,0,0.04);
  transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.1s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.numpad-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #cbd5e1;
  background: #e2e8f0;
}
.numpad-btn-wide {
  font-size: 20px;
}
.numpad-btn-submit {
  background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
  color: #fff;
  border-color: #16a34a;
  box-shadow: 0 3px 0 #15803d, 0 4px 10px rgba(0,0,0,0.08);
  font-size: 22px;
}
.numpad-btn-submit:active {
  box-shadow: 0 1px 0 #15803d;
  background: linear-gradient(180deg, #16a34a 0%, #15803d 100%);
}

/* === Result Scene === */
#scene-result.active {
  background: rgba(30, 41, 59, 0.35);
}
.result-card {
  max-width: 380px;
  width: 88%;
  text-align: center;
}
.result-title {
  font-family: 'Trebuchet MS', Verdana, system-ui;
  font-size: 32px;
  font-weight: 900;
  color: #1e293b;
  margin-bottom: 20px;
}
.result-stats {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #f8fafc;
  border-radius: 12px;
  font-size: 16px;
  color: #475569;
}
.result-row strong {
  color: #1e293b;
  font-size: 20px;
}
.result-lives {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 24px;
}

/* === Hidden === */
.hidden {
  display: none !important;
}

/* === Audio overlay === */
.audio-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(30, 41, 59, 0.50);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.audio-overlay.hidden {
  display: none;
}

/* === Responsive === */
@media (max-width: 500px) {
  .game-title { font-size: 32px; }
  .number-digits { font-size: 40px; letter-spacing: 3px; }
  .numpad-btn { height: 50px; font-size: 22px; }
  .input-display { font-size: 30px; letter-spacing: 4px; padding: 12px 16px; }
  .number-card { padding: 20px 24px; min-width: 160px; }
  .game-panel { padding: 24px 20px; }
  .hud-chip { font-size: 12px; padding: 4px 10px; }
  .hud { top: 8px; left: 8px; right: 8px; }
}
@media (max-width: 380px) {
  .numpad { gap: 6px; }
  .numpad-btn { height: 44px; font-size: 18px; border-radius: 10px; }
  .number-digits { font-size: 32px; }
}

/* === Level up animation === */
@keyframes levelPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); }
}
.level-pop {
  animation: levelPop 0.4s ease;
}

/* === Dimension container === */
.game-container {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
