/* ACCESCO Card Match Game - Clean & Fixed CSS */

/* =====================================================
   ROOT VARIABLES
===================================================== */
:root {
  --bg-main: radial-gradient(circle at top, #1e1b4b, #020617);
  --glass: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.18);
  
  --primary: #6366f1;
  --secondary: #a855f7;
  --accent: #22d3ee;
  
  --success: #10b981;
  --danger: #ef4444;
  --warning: #facc15;
  
  --text-main: #f8fafc;
  --muted: #94a3b8;
  
  --purple-dark: #5d034a;
  --purple-mid: #8a0e5a;
  --gold: #ffd700;
}

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

body {
  min-height: 100vh;
  background: var(--bg-main);
  font-family: 'Segoe UI', 'Inter', system-ui, sans-serif;
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 20px;
}

/* =====================================================
   MAIN CONTAINER
===================================================== */
.card-game-container {
  width: 100%;
  max-width: 1300px;
  padding: 24px;
  perspective: 2000px;
}

/* =====================================================
   HEADER
===================================================== */
.game-header {
  position: sticky;
  top: 20px;
  z-index: 50;
  background: linear-gradient(135deg, rgba(99,102,241,0.25), rgba(168,85,247,0.15));
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 20px 28px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  margin-bottom: 32px;
}

.flex {
  display: flex;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-4 {
  gap: 1rem;
}

.gap-6 {
  gap: 1.5rem;
}

.max-w-7xl {
  max-width: 80rem;
}

.mx-auto {
  margin-left: auto;
  margin-right: auto;
}

.header-logo {
  width: 48px;
  height: 48px;
}

.game-title {
  font-size: 2rem;
  font-weight: 900;
  background: linear-gradient(to right, #818cf8, #22d3ee);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-stats {
  display: flex;
  gap: 18px;
}

.score-display,
.timer-display {
  min-width: 90px;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 18px;
  text-align: center;
  box-shadow: inset 0 0 20px rgba(255,255,255,0.05);
}

.label {
  font-size: 0.7rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-main);
}

.timer-warning {
  animation: timer-pulse 1s infinite;
}

@keyframes timer-pulse {
  0%, 100% { border-color: var(--border); }
  50% { border-color: var(--danger); box-shadow: 0 0 20px rgba(239, 68, 68, 0.5); }
}

/* =====================================================
   MAIN CONTENT LAYOUT
===================================================== */
.main-content {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 28px;
}

.game-board-section {
  min-height: 600px;
}

/* =====================================================
   START SCREEN
===================================================== */
#start-screen {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 40px 50px;
  text-align: center;
  box-shadow: 
    0 30px 80px rgba(0, 0, 0, 0.7),
    inset 0 0 40px rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

#start-screen h2 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(90deg, var(--gold), #ffed4e);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0;
  text-shadow: 0 0 12px rgba(255, 215, 0, 0.35);
}

#start-screen > p {
  font-size: 1.1rem;
  color: var(--muted);
  opacity: 0.9;
  margin: 0;
}

.how-to-play {
  width: 100%;
  max-width: 500px;
  padding: 24px;
  background: rgba(255,255,255,0.05);
  backdrop-filter: blur(10px);
  border-radius: 18px;
  box-shadow:
    0 20px 40px rgba(0, 0, 0, 0.6),
    inset 0 0 30px rgba(255, 255, 255, 0.05);
  text-align: left;
  margin: 0;
}

.how-to-play h3 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold);
  margin: 0 0 1rem 0;
  text-align: center;
}

.how-to-play p {
  position: relative;
  padding-left: 1.5rem;
  margin: 0 0 0.75rem 0;
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--text-main);
}

.how-to-play p:last-child {
  margin-bottom: 0;
}

.how-to-play p::before {
  content: "✦";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--gold);
  font-size: 1rem;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.7);
}

/* =====================================================
   GAME BOARD
===================================================== */
#game-board {
  min-height: 600px;
}

.cards-grid {
  display: grid;
  /* Columns are now handled by JS: cardsGrid.style.gridTemplateColumns */
  gap: 1.5rem;
  padding: 2rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 20px;
  border: 2px solid rgba(138, 14, 90, 0.3);
  max-width: 600px; /* Reduced width to keep it compact like a square */
  margin: 0 auto;
  justify-content: center; /* Centers cards if there are fewer per row */
  align-content: center;
}

/* =====================================================
   CARD
===================================================== */
.card {
  position: relative;
  cursor: pointer;
  perspective: 1000px;
  width: 100%;
  max-width: 115px;
  margin: 0 auto;
  transform-style: preserve-3d;
  aspect-ratio: 1 / 1; 
  width: 100%;
  max-width: 120px;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 15px;
  background: linear-gradient(135deg, rgba(0,0,0,0.35), rgba(0,0,0,0.1));
  transform: translateZ(-6px);
  pointer-events: none;
}

.card:hover {
  transform: rotateX(4deg) rotateY(-4deg) translateY(-3px);
  transition: transform 0.3s ease;
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform-origin: center center;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.card-face::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 15px;
  background: linear-gradient(120deg, rgba(255,255,255,0.25), rgba(255,255,255,0) 40%);
  pointer-events: none;
}

/* Card Back */
.card-back {
  background: linear-gradient(135deg, var(--purple-dark) 0%, var(--purple-mid) 100%);
  border: 3px solid var(--gold);
  overflow: hidden;
}

.card-back-pattern {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-back-pattern::before {
  content: '';
  position: absolute;
  inset: 10px;
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: 10px;
}

.card-back-pattern::after {
  content: "";
  width: 65%;
  height: 65%;
  background-image: url("../../../AI_model/templates/accesco.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.4));
}

/* Card Front */
.card-front {
  background: linear-gradient(135deg, #ffffff 0%, #f3e8ff 100%);
  border: 3px solid var(--purple-mid);
  transform: rotateY(180deg);
}

.card-icon {
  font-size: 3rem;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.2));
}

.card.flipped .card-icon {
  animation: icon-pop 0.35s ease;
}

@keyframes icon-pop {
  0% { transform: scale(0.7); opacity: 0; }
  80% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

/* Matched Cards */
.card.matched .card-inner {
  animation: matchPulse 0.5s ease;
}

.card.matched .card-front {
  border-color: var(--gold);
  background: linear-gradient(135deg, var(--gold) 0%, #ffed4e 100%);
  box-shadow: 
    0 0 30px rgba(255, 215, 0, 0.8),
    0 15px 40px rgba(0, 0, 0, 0.6);
}

.card.matched::after {
  content: "✨";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.4rem;
  animation: sparkle-float 1.2s ease-out forwards;
  pointer-events: none;
  z-index: 10;
}

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

@keyframes sparkle-float {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -90%) scale(1.4);
  }
}

/* Wrong Cards */
.card.wrong .card-inner {
  animation: wrongShake 0.5s ease;
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

/* =====================================================
   LEADERBOARD
===================================================== */
.leaderboard-section {
  background: var(--glass);
  border-radius: 26px;
  padding: 22px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 40px rgba(0,0,0,0.45);
  align-self: start;
  position: sticky;
  top: 120px;
}

.leaderboard-title {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--warning);
  background: linear-gradient(90deg, var(--gold), #ffed4e);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.leaderboard-item {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(138, 14, 90, 0.5);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s ease;
}

.leaderboard-item:hover {
  background: rgba(138, 14, 90, 0.3);
  border-color: var(--gold);
  transform: translateX(5px);
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.35);
}

.leaderboard-item.current-game {
  background: linear-gradient(90deg, rgba(138, 14, 90, 0.5) 0%, rgba(93, 3, 74, 0.5) 100%);
  border: 2px solid var(--gold);
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.leaderboard-rank {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--gold);
  min-width: 2rem;
}

.leaderboard-points {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--gold);
}

/* =====================================================
   GAME CONTROLS
===================================================== */
.game-controls {
  margin-top: 30px;
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
}

/* =====================================================
   BUTTONS
===================================================== */
.btn {
  padding: 16px 40px;
  border-radius: 999px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  border: none;
  cursor: pointer;
  transition: all 0.25s ease;
  text-transform: uppercase;
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #22c55e);
  color: white;
  box-shadow: 0 10px 30px rgba(16,185,129,0.5);
}

.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 15px 40px rgba(16,185,129,0.6);
}

.btn-secondary {
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: white;
  box-shadow: 0 10px 30px rgba(99,102,241,0.5);
}

.btn-secondary:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 40px rgba(99,102,241,0.6);
}

.btn-exit {
  background: linear-gradient(135deg, #ef4444, #f43f5e);
  color: white;
  box-shadow: 0 10px 30px rgba(239,68,68,0.5);
}

.btn-exit:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 40px rgba(239,68,68,0.6);
}

/* =====================================================
   COUNTDOWN OVERLAY
===================================================== */
.countdown-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.countdown-number {
  font-size: 10rem;
  font-weight: bold;
  background: linear-gradient(135deg, var(--gold) 0%, #ffed4e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: countdownPulse 1s ease-in-out;
  text-shadow: 0 0 50px rgba(255, 215, 0, 0.8);
}

@keyframes countdownPulse {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* =====================================================
   GAME OVER MODAL
===================================================== */
.game-over-modal {
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.game-over-content {
  position: relative;
  background: var(--glass);
  border-radius: 30px;
  padding: 40px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: 
    0 0 60px rgba(255, 215, 0, 0.3),
    0 0 120px rgba(138, 14, 90, 0.4);
  max-width: 500px;
  width: 90%;
}

.game-over-title {
  position: relative;
  font-size: 2.5rem;
  font-weight: 900;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.game-over-title::before,
.game-over-title::after {
  content: "🎉";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 2rem;
}

.game-over-title::before {
  left: -3rem;
}

.game-over-title::after {
  right: -3rem;
}

.game-over-score {
  font-size: 2.2rem;
  font-weight: bold;
  color: var(--gold);
  margin-bottom: 2rem;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

.game-over-content .btn {
  min-width: 200px;
  font-size: 1.15rem;
}

.game-over-content .btn:hover {
  transform: translateY(-3px) scale(1.05);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-item {
  background: rgba(138, 14, 90, 0.3);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 215, 0, 0.5);
  border-radius: 10px;
  padding: 1rem;
  box-shadow:
    0 10px 25px rgba(0, 0, 0, 0.5),
    inset 0 0 20px rgba(255, 255, 255, 0.04);
  transition: all 0.3s ease;
}

.stat-item:hover {
  transform: translateY(-5px) scale(1.03);
  box-shadow: 0 15px 40px rgba(255, 215, 0, 0.4);
}

.stat-label {
  font-size: 0.875rem;
  color: #d8b4fe;
  margin-bottom: 0.25rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--gold);
}

/* =====================================================
   COMBO INDICATOR
===================================================== */
#combo-indicator {
  position: fixed;
  top: 90px;
  right: 40px;
  background: linear-gradient(135deg, var(--gold), #ffed4e);
  color: #1a0033;
  font-weight: 900;
  padding: 0.6rem 1.2rem;
  border-radius: 14px;
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.6);
  z-index: 999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* =====================================================
   TIME POPUP
===================================================== */
.time-popup {
  position: fixed;
  font-size: 1.6rem;
  font-weight: bold;
  pointer-events: none;
  z-index: 999;
  animation: time-float-up 1s ease-out forwards;
}

.time-plus {
  color: #00ff9c;
  text-shadow: 0 0 12px rgba(0, 255, 156, 0.8);
}

.time-minus {
  color: #ff4d4d;
  text-shadow: 0 0 12px rgba(255, 77, 77, 0.8);
}

@keyframes time-float-up {
  0% {
    transform: translateY(0) scale(0.8);
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
  100% {
    transform: translateY(-40px) scale(1.2);
    opacity: 0;
  }
}

/* =====================================================
   SCORE POPUP
===================================================== */
.score-popup {
  position: fixed;
  font-size: 2rem;
  font-weight: bold;
  color: var(--gold);
  pointer-events: none;
  animation: scoreIncrement 1s ease-out forwards;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
  z-index: 999;
}

@keyframes scoreIncrement {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(-50px) scale(1.5);
    opacity: 0;
  }
}

/* =====================================================
   RESPONSIVE DESIGN
===================================================== */
@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .leaderboard-section {
    position: static;
    max-width: 800px;
    margin: 0 auto;
  }
}

@media (max-width: 900px) {
  .game-header {
    padding: 1rem;
  }

  .game-title {
    font-size: 1.5rem;
  }

  .header-stats {
    gap: 12px;
  }

  .score-display,
  .timer-display {
    min-width: 70px;
    padding: 0.5rem 1rem;
  }

  .value {
    font-size: 1.25rem;
  }

  .cards-grid {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 1rem;
    padding: 1.5rem;
  }

  .card {
    max-width: 90px;
  }

  .card-icon {
    font-size: 2.2rem;
  }

  .countdown-number {
    font-size: 6rem;
  }

  .game-over-content {
    padding: 2rem;
    margin: 1rem;
  }

  .game-over-title {
    font-size: 2rem;
  }

  .game-over-title::before,
  .game-over-title::after {
    display: none;
  }

  #combo-indicator {
    top: 80px;
    right: 20px;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
  }

  #start-screen {
    padding: 2rem;
  }

  #start-screen h2 {
    font-size: 2rem;
  }

  .how-to-play h3 {
    font-size: 1.2rem;
  }
}

@media (max-width: 768px) {
  #start-screen {
    padding: 1.5rem;
  }

  #start-screen h2 {
    font-size: 1.8rem;
  }

  .how-to-play {
    padding: 1rem;
  }

  .how-to-play p {
    font-size: 0.9rem;
  }

  .cards-grid {
    gap: 0.75rem;
    padding: 1rem;
  }

  .card {
    max-width: 75px;
  }

  .card-icon {
    font-size: 1.8rem;
  }

  .btn {
    padding: 12px 28px;
    font-size: 0.95rem;
  }
}

@media (max-width: 480px) {
  .header-stats {
    flex-direction: column;
    gap: 8px;
  }

  .score-display,
  .timer-display {
    min-width: 100%;
  }

  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(6, 1fr);
  }
}