/* ===== HALLOWEEN MEMORY MATCH GAME - 960x540 ARTICULATE STORYLINE ===== */

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Arial', sans-serif;
  background: #000;
  color: #fff;
  overflow: hidden;
  user-select: none;
}

/* Main Game Container - Fixed 960x540 for Storyline */
#game-container {
  width: 960px;
  height: 540px;
  position: relative;
  background-image: url('images/haunted_mansion.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(255, 153, 0, 0.3);
}

/* Dark overlay for better contrast */
#game-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1;
}

/* Screen System */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  z-index: 10;
  align-items: center;
  justify-content: center;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* START SCREEN */
#start-screen {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
}

.start-content {
  text-align: center;
  padding: 40px;
  background: rgba(40, 40, 40, 0.95);
  border-radius: 15px;
  border: 2px solid #ffa500;
  box-shadow: 0 0 30px rgba(255, 165, 0, 0.4);
}

.start-content h1 {
  font-size: 2.5em;
  margin-bottom: 20px;
  color: #ffcc00;
  text-shadow: 0 0 8px rgba(255, 204, 0, 0.8);
  animation: glow 3s ease-in-out infinite alternate;
  font-weight: bold;
}

@keyframes glow {
  from { text-shadow: 0 0 8px rgba(255, 204, 0, 0.8); }
  to { text-shadow: 0 0 12px rgba(255, 204, 0, 1), 0 0 20px rgba(255, 165, 0, 0.6); }
}

.start-content p {
  font-size: 1.2em;
  margin-bottom: 30px;
  color: #ffffff;
  font-weight: 500;
}

.difficulty-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

/* Button Styles */
.btn {
  background: #2a2a2a;
  color: #ffffff;
  border: 2px solid #ffa500;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1em;
  font-weight: bold;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
  min-height: 44px; /* Accessibility: minimum touch target */
}

.btn:hover, .btn:focus {
  background: #ffa500;
  color: #000000;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(255, 165, 0, 0.4);
  outline: 2px solid #ffcc00;
  outline-offset: 2px;
}

.btn.active {
  background: #ffa500;
  color: #000000;
  box-shadow: 0 0 15px rgba(255, 165, 0, 0.6);
}

.start-btn {
  font-size: 1.3em;
  padding: 15px 30px;
  background: #ff8c00;
  border-color: #ff8c00;
  color: #000000;
  font-weight: 900;
}

.start-btn:hover, .start-btn:focus {
  background: #ffcc00;
  border-color: #ffcc00;
  color: #000000;
}

/* GAME SCREEN */
#game-screen {
  display: none;
  flex-direction: column;
  padding: 20px;
  position: relative;
}

#game-screen.active {
  display: flex;
}

/* Game Stats Bar */
#game-stats {
  position: absolute;
  top: 15px;
  left: 15px;
  right: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.8);
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid #ff9900;
  z-index: 15;
}

.stat {
  color: #fff;
  font-weight: bold;
  font-size: 1.1em;
}

.stat-label {
  color: #ff9900;
  margin-right: 5px;
}

.reset-btn {
  padding: 8px 16px;
  font-size: 0.9em;
}

/* Memory Grid */
#memory-grid {
  display: grid;
  gap: 12px;
  justify-content: center;
  align-items: center;
  margin: 80px auto 20px;
  padding: 20px;
}

/* Memory Cards */
.memory-card {
  width: 80px;
  height: 80px;
  position: relative;
  cursor: pointer;
  perspective: 1000px;
  transition: transform 0.1s ease;
}

.memory-card:hover {
  transform: scale(1.05);
}

.memory-card.matched {
  pointer-events: none;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.8);
}

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

.card-front, .card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5em;
  border: 2px solid #ff9900;
}

.card-front {
  background: linear-gradient(145deg, #2a2a2a, #404040);
  color: #ff9900;
  box-shadow: inset 0 2px 4px rgba(255, 153, 0, 0.2);
}

.card-front::before {
  content: '👻';
  opacity: 0.3;
}

.card-back {
  background: linear-gradient(145deg, #404040, #2a2a2a);
  transform: rotateY(180deg);
  color: #fff;
  text-shadow: 0 0 10px currentColor;
}

.memory-card.matched .card-back {
  background: linear-gradient(145deg, #2d5a2d, #4a8f4a);
  border-color: #00ff00;
  box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
  animation: matchGlow 1s ease-in-out;
}

@keyframes matchGlow {
  0%, 100% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.1); }
}

/* Game Message */
#game-message {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: #ff9900;
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid #ff9900;
  font-weight: bold;
  text-align: center;
  z-index: 15;
}

/* COMPLETION SCREEN */
#complete-screen {
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
}

.complete-content {
  text-align: center;
  padding: 40px;
  background: rgba(20, 20, 20, 0.9);
  border-radius: 15px;
  border: 2px solid #00ff00;
  box-shadow: 0 0 30px rgba(0, 255, 0, 0.5);
}

.complete-content h2 {
  font-size: 2.2em;
  margin-bottom: 20px;
  color: #00ff00;
  text-shadow: 0 0 15px #00ff00;
  animation: successGlow 2s ease-in-out infinite alternate;
}

@keyframes successGlow {
  from { text-shadow: 0 0 15px #00ff00, 0 0 25px #00ff00; }
  to { text-shadow: 0 0 20px #00ff00, 0 0 35px #00ff00, 0 0 45px #00ff00; }
}

#final-stats {
  margin-bottom: 30px;
}

#final-stats p {
  font-size: 1.3em;
  margin: 10px 0;
  color: #fff;
}

/* Responsive Grid Layouts */
.grid-3x4 { grid-template-columns: repeat(3, 80px); }
.grid-4x4 { grid-template-columns: repeat(4, 80px); }
.grid-4x6 { grid-template-columns: repeat(4, 80px); }

/* Success and Error Animations */
.card-success {
  animation: cardSuccess 0.6s ease-in-out;
}

.card-error {
  animation: cardError 0.6s ease-in-out;
}

@keyframes cardSuccess {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

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

/* Storyline Optimization */
@media (max-width: 960px) {
  #game-container {
    width: 100vw;
    height: 56.25vw; /* Maintains 16:9 aspect ratio */
    max-width: 960px;
    max-height: 540px;
  }
}