* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', sans-serif;
  background: #0f0f23;
  color: #fff;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.wrapper {
  text-align: center;
  padding: 1.5rem;
  position: relative;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.back-btn {
  color: #888;
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.back-btn:hover { color: #f0c040; }
.back-btn { background: #2a2a5e; padding: 0.3rem 0.7rem; border-radius: 6px; }
.pause-btn { background: #2a2a5e; color: #fff; border: none; padding: 0.3rem 0.7rem; border-radius: 6px; font-size: 1rem; cursor: pointer; margin-left: 0.4rem; transition: background 0.2s; }
.pause-btn:hover { background: #3a3a7e; }

.top-bar h1 { font-size: 1.4rem; }

.score-board {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  color: #aaa;
}

.score-board strong { color: #4cff72; }

/* Board */
#board {
  display: grid;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
  perspective: 800px;
}

/* Card 3D flip */
.card {
  width: 80px;
  height: 80px;
  position: relative;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.5s;
  -webkit-tap-highlight-color: transparent;
}

.card.flipped { transform: rotateY(180deg); }
.card.matched { transform: rotateY(180deg) scale(0.95); }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  border: 2px solid #2a2a5e;
  font-weight: 700;
  user-select: none;
}

.card-front {
  background: #1a1a3e;
  color: #555;
  font-size: 2rem;
}

.card-back {
  background: #2a2a5e;
  border-color: #f0c040;
  color: #f0c040;
  font-size: 1.6rem;
  transform: rotateY(180deg);
}

.card.matched .card-back {
  background: #1a3e1a;
  border-color: #4cff72;
  color: #4cff72;
}

/* Match glow animation */
.card.match-glow .card-back {
  animation: glowPulse 0.6s ease;
}

@keyframes glowPulse {
  0% { box-shadow: 0 0 0 rgba(76,255,114,0); }
  50% { box-shadow: 0 0 20px rgba(76,255,114,0.6); }
  100% { box-shadow: 0 0 0 rgba(76,255,114,0); }
}

/* Shake animation for mismatch */
.card.shake {
  animation: cardShake 0.4s ease;
}

@keyframes cardShake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  25% { transform: rotateY(180deg) translateX(-6px); }
  75% { transform: rotateY(180deg) translateX(6px); }
}

/* Bounce for already flipped card */
.card.bounce {
  animation: cardBounce 0.3s ease;
}

@keyframes cardBounce {
  0%, 100% { transform: rotateY(180deg) scale(0.95); }
  50% { transform: rotateY(180deg) scale(1.05); }
}

/* Combo popup */
.combo-popup {
  position: absolute;
  font-size: 1.2rem;
  font-weight: 700;
  color: #ffd700;
  pointer-events: none;
  animation: comboFloat 1s ease forwards;
  z-index: 10;
}

@keyframes comboFloat {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-40px) scale(1.3); }
}

/* Overlays */
#overlay, #confirm-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 35, 0.92);
  border-radius: 12px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  z-index: 20;
}

#overlay.show, #confirm-overlay.show { display: flex; }

/* Report Card */
.report-card {
  background: #1a1a3e;
  border: 2px solid #2a2a5e;
  border-radius: 16px;
  padding: 1.5rem;
  width: 90%;
  max-width: 360px;
  animation: reportSlideIn 0.4s ease;
}

@keyframes reportSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.report-header {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.report-stars {
  font-size: 1.8rem;
  letter-spacing: 0.3rem;
  margin-bottom: 0.8rem;
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.report-item {
  background: #0f0f23;
  border-radius: 10px;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.report-label {
  font-size: 0.7rem;
  color: #888;
}

.report-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f0c040;
}

.report-bar-wrap {
  margin-bottom: 0.8rem;
}

.report-bar-label {
  font-size: 0.75rem;
  color: #888;
  margin-bottom: 0.3rem;
  text-align: left;
}

.report-bar {
  height: 8px;
  background: #0f0f23;
  border-radius: 4px;
  overflow: hidden;
}

.report-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #ff4c6a, #f0c040, #4cff72);
  transition: width 1s ease;
  width: 0%;
}

.report-best {
  font-size: 0.8rem;
  color: #f0c040;
  margin-bottom: 0.8rem;
}

.report-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}

#restart-btn, #menu-btn {
  padding: 0.6rem 1.8rem;
  font-size: 1rem;
  background: #f0c040;
  color: #0f0f23;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
  min-width: 180px;
  text-align: center;
}

#restart-btn:hover, #menu-btn:hover { background: #ffd866; }

#menu-btn {
  background: #2a2a5e;
  color: #fff;
}

#menu-btn:hover { background: #3a3a7e; }

.confirm-btns { display: flex; gap: 0.8rem; }

.confirm-btns button {
  padding: 0.5rem 1.5rem;
  font-size: 0.9rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

#confirm-yes { background: #f0c040; color: #0f0f23; }
#confirm-no { background: #2a2a5e; color: #fff; }

.how-to {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: #888;
  line-height: 1.6;
  text-align: center;
}

.how-to p:first-child { color: #f0c040; margin-bottom: 0.3rem; }

@media (max-width: 500px) {
  .card { width: 60px; height: 60px; }
  .card-front { font-size: 1.5rem; }
  .card-back { font-size: 1.2rem; }
  #board { gap: 6px; }
}

/* Level Modal */
#level-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 15, 35, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.3s ease;
}

#level-modal.hidden { display: none; }

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.level-modal-content {
  text-align: center;
  max-width: 400px;
  width: 90%;
}

.level-modal-content h2 {
  font-size: 1.6rem;
  margin-bottom: 0.3rem;
}

.level-modal-content > p {
  color: #888;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.level-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.level-btn {
  background: #1a1a3e;
  border: 2px solid #2a2a5e;
  border-radius: 12px;
  padding: 1.2rem 0.8rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  color: #fff;
  font-family: inherit;
}

.level-btn:hover {
  transform: translateY(-3px);
  border-color: #f0c040;
  box-shadow: 0 0 15px rgba(240, 192, 64, 0.2);
}

.level-icon { font-size: 1.8rem; }
.level-name { font-size: 1rem; font-weight: 700; }
.level-desc { font-size: 0.75rem; color: #888; }

@media (max-width: 599px) { .hamburger-btn { display: none !important; } }
