/* --- CSS Design System & Theme for Princess Memory --- */

:root {
  --color-pink-light: #fff0f5; /* LavenderBlush */
  --color-pink-medium: #ffb6c1; /* LightPink */
  --color-pink-dark: #ff69b4; /* HotPink */
  --color-purple-light: #e6e6fa; /* Lavender */
  --color-purple-medium: #d8bfd8; /* Thistle */
  --color-purple-dark: #ba55d3; /* MediumOrchid */
  --color-gold: #ffd700; /* Gold */
  --color-gold-light: #fff8dc; /* Cornsilk */
  --color-gold-dark: #daa520; /* Goldenrod */
  --color-white: #ffffff;
  
  --font-family: 'M PLUS Rounded 1c', 'Outfit', sans-serif;
  --transition-smooth: all 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

body {
  font-family: var(--font-family);
  background: linear-gradient(135deg, #ffeef8 0%, #f3e5f5 50%, #fff3e0 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  color: #5c3a4d;
  position: relative;
}

/* Background Stars Animation */
.bg-stars {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.bg-star {
  position: absolute;
  color: rgba(255, 215, 0, 0.6);
  font-size: 20px;
  animation: floatUp 8s linear infinite;
  user-select: none;
}

@keyframes floatUp {
  0% {
    transform: translateY(100vh) rotate(0deg) scale(0.5);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(-10vh) rotate(360deg) scale(1.2);
    opacity: 0;
  }
}

/* Main Container */
.game-container {
  width: 95%;
  max-width: 900px;
  margin: 20px auto;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Sound Button */
.sound-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(255, 255, 255, 0.7);
  border: 3px solid var(--color-pink-medium);
  border-radius: 30px;
  padding: 8px 16px;
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 700;
  color: var(--color-pink-dark);
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(255, 105, 180, 0.15);
  transition: var(--transition-smooth);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 100;
}

.sound-btn:hover {
  transform: translateY(-2px) scale(1.05);
  background: var(--color-white);
  box-shadow: 0 6px 12px rgba(255, 105, 180, 0.25);
  border-color: var(--color-pink-dark);
}

.sound-btn.muted {
  border-color: #ccc;
  color: #777;
}

/* Header */
.game-header {
  text-align: center;
  margin-bottom: 25px;
  filter: drop-shadow(0 4px 8px rgba(218, 165, 32, 0.15));
}

.game-title {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--color-pink-dark);
  background: linear-gradient(45deg, var(--color-pink-dark), var(--color-purple-dark), var(--color-gold-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 5px;
  letter-spacing: 1px;
}

.game-subtitle {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-purple-dark);
  letter-spacing: 0.5px;
}

/* Glassmorphic Panel (Common) */
.menu-box {
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 4px solid rgba(255, 255, 255, 0.8);
  border-radius: 30px;
  padding: 35px;
  box-shadow: 0 15px 35px rgba(255, 105, 180, 0.15),
              0 0 0 6px rgba(255, 182, 193, 0.25);
  width: 100%;
  text-align: center;
  transition: var(--transition-smooth);
}

.menu-box h2 {
  font-size: 1.5rem;
  margin-bottom: 25px;
  color: #6a4055;
  text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.8);
}

/* Buttons Grid */
.difficulty-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 35px;
}

.btn {
  border: none;
  border-radius: 24px;
  padding: 20px 15px;
  font-family: var(--font-family);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--color-white);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--transition-smooth);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.btn::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.3) 50%, rgba(255,255,255,0) 100%);
  transform: rotate(30deg);
  transition: 0.8s;
  pointer-events: none;
}

.btn:hover::after {
  left: 120%;
}

.btn:hover {
  transform: translateY(-6px) scale(1.03);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.btn:active {
  transform: translateY(-2px);
}

/* Colors for difficulty buttons */
.btn-easy {
  background: linear-gradient(135deg, #ff9ebb 0%, #ff6fa0 100%);
  border: 4px solid #ffd1df;
}
.btn-medium {
  background: linear-gradient(135deg, #c79aff 0%, #9f5cff 100%);
  border: 4px solid #ecd8ff;
}
.btn-hard {
  background: linear-gradient(135deg, #ffb86c 0%, #ff8a3c 100%);
  border: 4px solid #ffe8d1;
}

.btn-emoji {
  font-size: 2.2rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
  animation: wiggle 2s ease-in-out infinite;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-8deg); }
  75% { transform: rotate(8deg); }
}

.btn-title {
  display: block;
  text-shadow: 1px 2px 3px rgba(0, 0, 0, 0.15);
}

.btn-desc {
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0.9;
  background: rgba(255, 255, 255, 0.25);
  padding: 3px 12px;
  border-radius: 12px;
}

/* High Score Section */
.highscore-panel {
  background: rgba(255, 255, 255, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 20px;
  padding: 20px;
}

.highscore-panel h3 {
  font-size: 1.15rem;
  color: var(--color-purple-dark);
  margin-bottom: 15px;
}

.highscore-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 15px;
}

.highscore-card {
  background: rgba(255, 255, 255, 0.8);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
  font-size: 0.9rem;
}

.highscore-card p {
  margin: 4px 0;
  font-weight: 700;
}

.highscore-card span.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  color: white;
  font-size: 0.8rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.highscore-card span.tag.easy { background-color: #ff6fa0; }
.highscore-card span.tag.medium { background-color: #9f5cff; }
.highscore-card span.tag.hard { background-color: #ff8a3c; }

/* Playing Screen Layout */
.game-play-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Info Bar */
.info-bar {
  background: rgba(255, 255, 255, 0.8);
  border: 3px solid var(--color-pink-medium);
  border-radius: 20px;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  box-shadow: 0 8px 20px rgba(255, 105, 180, 0.08);
}

.btn-small {
  border: none;
  background: var(--color-white);
  border: 2px solid var(--color-pink-medium);
  color: var(--color-pink-dark);
  border-radius: 15px;
  padding: 8px 16px;
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-small:hover {
  background: var(--color-pink-light);
  border-color: var(--color-pink-dark);
  transform: translateY(-2px);
}

.btn-small.restart:hover {
  background: #fff3e0;
  border-color: #ff8a3c;
  color: #d35400;
}

.stats {
  display: flex;
  gap: 20px;
  align-items: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #8c7380;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--color-pink-dark);
}

.stat-unit {
  font-size: 0.75rem;
  font-weight: 700;
}

/* Card Grid Layout */
.card-grid {
  display: grid;
  gap: 12px;
  margin: 0 auto;
  width: 100%;
  max-width: 720px;
  perspective: 1000px; /* 3D depth */
  justify-content: center;
}

/* Grid sizes based on difficulty */
.card-grid.easy {
  grid-template-columns: repeat(3, 1fr);
  max-width: 500px;
}

.card-grid.medium {
  grid-template-columns: repeat(4, 1fr);
  max-width: 600px;
}

.card-grid.hard {
  grid-template-columns: repeat(4, 1fr);
}

/* Card Styling */
.card {
  aspect-ratio: 1 / 1;
  position: relative;
  cursor: pointer;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.2);
  user-select: none;
}

.card.flipped {
  transform: rotateY(180deg);
}

.card.matched {
  transform: rotateY(180deg) scale(0.95);
  pointer-events: none;
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 18px;
  border: 4px solid var(--color-white);
  box-shadow: 0 6px 15px rgba(255, 105, 180, 0.12);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  transition: border-color 0.3s;
}

/* Card Back Design */
.card-back {
  background-color: var(--color-pink-light);
  background-image: url('images/card_back.png');
  background-size: cover;
  background-position: center;
  border: 4px solid rgba(255, 255, 255, 0.9);
  transform: rotateY(0deg) translateZ(1px);
}

.card:hover .card-back {
  border-color: var(--color-gold);
  transform: scale(1.02) translateZ(2px);
  box-shadow: 0 10px 20px rgba(255, 215, 0, 0.25);
}

/* Card Front Design */
.card-front {
  background-color: var(--color-white);
  transform: rotateY(180deg) translateZ(1px);
  border: 4px solid var(--color-pink-medium);
}

.card-front img {
  width: 105%;
  height: 105%;
  object-fit: cover;
}

/* Sparkle Shine animation on matched */
.card.matched .card-face {
  border-color: var(--color-gold);
  animation: matchFlash 0.6s ease-out;
  opacity: 0.65;
}

@keyframes matchFlash {
  0% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.1); filter: brightness(1.6) saturate(1.2); box-shadow: 0 0 30px rgba(255, 215, 0, 0.8); }
  100% { transform: scale(0.95); filter: brightness(1); }
}

/* Win Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(92, 58, 77, 0.5);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.modal.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--color-white);
  border: 8px solid var(--color-gold);
  border-radius: 40px;
  padding: 40px 30px;
  width: 90%;
  max-width: 480px;
  text-align: center;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
  transform: scale(0.7) translateY(50px);
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal.show .modal-content {
  transform: scale(1) translateY(0);
}

.modal-crown {
  font-size: 4rem;
  margin-top: -80px;
  background: var(--color-white);
  border: 6px solid var(--color-gold);
  width: 100px;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  margin-left: auto;
  margin-right: auto;
  box-shadow: 0 8px 20px rgba(255, 215, 0, 0.3);
  animation: bounce 2s infinite;
}

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

#winTitle {
  font-size: 2.2rem;
  color: var(--color-pink-dark);
  margin-top: 15px;
  margin-bottom: 5px;
  text-shadow: 1px 2px 3px rgba(0,0,0,0.05);
}

.modal-subtitle {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-purple-dark);
  margin-bottom: 25px;
}

.win-stats {
  display: flex;
  justify-content: space-around;
  background: var(--color-pink-light);
  border-radius: 20px;
  padding: 15px;
  margin-bottom: 25px;
}

.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.win-stat-emoji {
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.win-stat-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #8c7380;
}

.win-stat-val {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--color-pink-dark);
}

.win-stat-unit {
  font-size: 0.8rem;
  font-weight: 700;
}

/* New Record Badge */
.new-record {
  background: linear-gradient(45deg, var(--color-gold), #ff8a3c);
  color: white;
  font-size: 1.15rem;
  font-weight: 800;
  padding: 8px 20px;
  border-radius: 20px;
  display: inline-block;
  margin-bottom: 25px;
  box-shadow: 0 4px 15px rgba(255, 138, 60, 0.4);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-win {
  background: linear-gradient(135deg, #ff6fa0 0%, #ff4081 100%);
  width: 100%;
  padding: 14px;
  font-size: 1.2rem;
  border: 3px solid #ffccd9;
}

.btn-menu-back {
  background: linear-gradient(135deg, #9f5cff 0%, #7c3eff 100%);
  width: 100%;
  padding: 12px;
  font-size: 1.05rem;
  border: 3px solid #ebd6ff;
}

/* Canvas Particle overlay */
#particleCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

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

/* Responsive Scaling for grid card sizes */
@media (max-width: 600px) {
  .game-title {
    font-size: 1.8rem;
  }
  .game-subtitle {
    font-size: 0.9rem;
  }
  .menu-box {
    padding: 20px 15px;
  }
  .info-bar {
    padding: 8px 12px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .stats {
    gap: 12px;
  }
  .stat-value {
    font-size: 1.15rem;
  }
  .card-grid {
    gap: 8px;
  }
  .card-face {
    border-radius: 12px;
    border-width: 2px;
  }
  .card-front {
    border-width: 2px;
  }
  .sound-btn {
    top: auto;
    bottom: 15px;
    right: 15px;
  }
}
