/* Modern Simon Game Styling - Enhanced 3D Version */

:root {
  --red: #e74c3c;
  --green: #2ecc71;
  --blue: #3498db;
  --yellow: #f1c40f;
  --background: #1a1e24;
  --text: #ecf0f1;
  --shadow: rgba(0, 0, 0, 0.3);
  --glow: rgba(255, 255, 255, 0.8);
  --button-depth: 15px;
  --accent: #9b59b6;
}

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

body {
  text-align: center;
  background: var(--background);
  background-image: radial-gradient(circle at center, #2c3e50, #1a1e24);
  color: var(--text);
  font-family: 'Press Start 2P', cursive;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
  padding-top: 60px;
}

body::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.05),
    rgba(0, 0, 0, 0.05) 10px,
    rgba(0, 0, 0, 0.08) 10px,
    rgba(0, 0, 0, 0.08) 20px
  );
  z-index: -1;
}

/* Ambient light effect */
body::after {
  content: "";
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at center, rgba(42, 82, 152, 0.1), transparent 60%);
  z-index: -2;
  animation: ambientLight 15s infinite alternate ease-in-out;
}

@keyframes ambientLight {
  0% {
    transform: translate(10%, 10%);
    opacity: 0.5;
  }
  100% {
    transform: translate(-10%, -10%);
    opacity: 0.7;
  }
}

#level-title {
  font-size: clamp(2rem, 4vw, 3.5rem);
  margin-bottom: 5%;
  margin-top: 20px;
  color: var(--text);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.3),
               0 0 20px rgba(255, 255, 255, 0.2),
               0 0 30px rgba(66, 133, 244, 0.4);
  animation: titlePulse 3s infinite alternate;
  letter-spacing: 2px;
  position: relative;
}

@keyframes titlePulse {
  0% {
    opacity: 0.8;
    transform: scale(1);
  }
  100% {
    opacity: 1;
    transform: scale(1.05);
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.5),
                 0 0 30px rgba(255, 255, 255, 0.3),
                 0 0 40px rgba(66, 133, 244, 0.5);
  }
}

/* High Score Styling */
#high-score {
  position: fixed;
  top: 15px;
  right: 20px;
  font-family: 'Press Start 2P', cursive;
  font-size: clamp(0.75rem, 2vw, 1rem);
  color: var(--text);
  background: rgba(0, 0, 0, 0.5);
  padding: 10px 15px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
  z-index: 100;
  animation: fadeIn 0.5s ease-out;
}

/* Leaderboard Button Styling */
#show-leaderboard-btn {
  font-family: 'Press Start 2P', cursive;
  font-size: clamp(0.7rem, 1.5vw, 0.9rem);
  color: var(--text);
  background: var(--accent);
  padding: 12px 20px;
  border-radius: 8px;
  border: none;
  box-shadow: 0 5px 0 #7d4497, 
              0 5px 15px rgba(0, 0, 0, 0.3);
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: all 0.2s ease;
  position: fixed;
  top: 15px;
  left: 20px;
  z-index: 100;
  letter-spacing: 1px;
  outline: none;
  transform: translateZ(0);
  margin-bottom: 15px;
}

#show-leaderboard-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 #7d4497, 
              0 8px 20px rgba(0, 0, 0, 0.4);
}

#show-leaderboard-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #7d4497, 
              0 3px 6px rgba(0, 0, 0, 0.2);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 25px;
  perspective: 1000px;
  transform-style: preserve-3d;
  transform: rotateX(15deg);
  width: min(600px, 90vw);
  margin: auto;
  animation: containerFloat 6s infinite ease-in-out;
  position: relative;
}

/* Container reflection */
.container::after {
  content: "";
  position: absolute;
  bottom: -80px;
  left: 0;
  width: 100%;
  height: 40px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.1), transparent);
  filter: blur(10px);
  transform: rotateX(80deg) scaleY(0.3);
  opacity: 0.4;
  border-radius: 50%;
}

.container > div {
  display: flex;
  gap: 25px;
  transform-style: preserve-3d;
}

@keyframes containerFloat {
  0%, 100% {
    transform: rotateX(15deg) translateY(0);
  }
  50% {
    transform: rotateX(15deg) translateY(-10px);
  }
}

.btn {
  position: relative;
  height: min(200px, 30vw);
  width: min(200px, 30vw);
  border-radius: 20%;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.68, -0.55, 0.265, 1.55), 
              box-shadow 0.2s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  transform-style: preserve-3d;
  transform: translateZ(var(--button-depth));
  box-shadow: 0 var(--button-depth) 35px var(--shadow), 
              0 5px 15px rgba(0, 0, 0, 0.5),
              inset 0 1px 0 rgba(255, 255, 255, 0.3);
  overflow: hidden;
  /* Add this to ensure opacity transitions work properly for the jQuery fadeIn/fadeOut */
  transition-property: transform, box-shadow, opacity;
  transition-duration: 0.2s, 0.2s, 0.1s;
}

/* Button base/shadow effect to create 3D look */
.btn::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  bottom: calc(var(--button-depth) * -1);
  left: 0;
  background-color: rgba(0, 0, 0, 0.4);
  border-radius: 20%;
  transform: translateZ(calc(var(--button-depth) * -1)) rotateX(90deg);
  transform-origin: bottom;
  z-index: -1;
  filter: blur(4px);
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 30% 30%, 
              rgba(255, 255, 255, 0.3) 0%, 
              rgba(255, 255, 255, 0.1) 20%, 
              transparent 60%);
  pointer-events: none;
  border-radius: 20%;
}

.btn:hover {
  transform: translateY(-5px) translateZ(var(--button-depth));
  box-shadow: 0 calc(var(--button-depth) + 5px) 40px var(--shadow),
              0 10px 20px rgba(0, 0, 0, 0.3),
              inset 0 2px 0 rgba(255, 255, 255, 0.4);
}

/* Game Flash Effect Animations - critical for gameplay */
@keyframes gameFlash {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}

/* This is for the jQuery fadeOut(100).fadeIn(100) sequence indicator */
.btn.flash-animation {
  animation: gameFlash 0.2s ease-out;
}

.game-over {
  background-color: red !important;
  opacity: 0.8;
  animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

.red {
  background: var(--red);
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  border: 10px solid #c0392b;
}

.green {
  background: var(--green);
  background: linear-gradient(135deg, #2ecc71, #27ae60);
  border: 10px solid #27ae60;
}

.blue {
  background: var(--blue);
  background: linear-gradient(135deg, #3498db, #2980b9);
  border: 10px solid #2980b9;
}

.yellow {
  background: var(--yellow);
  background: linear-gradient(135deg, #f1c40f, #f39c12);
  border: 10px solid #f39c12;
}

.pressed {
  transform: translateY(10px) translateZ(calc(var(--button-depth) - 10px)) scale(0.95);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4),
              inset 0 -2px 5px rgba(0, 0, 0, 0.4);
  filter: brightness(1.5);
  animation: press 0.2s ease-out;
}

@keyframes press {
  0% { 
    transform: translateY(-5px) translateZ(var(--button-depth)); 
    box-shadow: 0 calc(var(--button-depth) + 5px) 40px var(--shadow);
  }
  100% { 
    transform: translateY(10px) translateZ(calc(var(--button-depth) - 10px)) scale(0.95); 
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
  }
}

/* Enhanced button glow effects when active */
.btn.red.pressed::before {
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.8) 0%, rgba(255, 255, 255, 0) 70%);
  animation: glow 0.3s ease-out;
}

.btn.green.pressed::before {
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.8) 0%, rgba(255, 255, 255, 0) 70%);
  animation: glow 0.3s ease-out;
}

.btn.blue.pressed::before {
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.8) 0%, rgba(255, 255, 255, 0) 70%);
  animation: glow 0.3s ease-out;
}

.btn.yellow.pressed::before {
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.8) 0%, rgba(255, 255, 255, 0) 70%);
  animation: glow 0.3s ease-out;
}

@keyframes glow {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* Color-specific light effects */
.red::after {
  background-color: rgba(231, 76, 60, 0.4);
}

.green::after {
  background-color: rgba(46, 204, 113, 0.4);
}

.blue::after {
  background-color: rgba(52, 152, 219, 0.4);
}

.yellow::after {
  background-color: rgba(241, 196, 15, 0.4);
}

/* Responsive design */
@media (max-width: 768px) {
  .container {
    width: 90%;
    gap: 15px;
    transform: rotateX(10deg) scale(0.9);
    margin-top: 20px;
  }
  
  .container > div {
    gap: 15px;
  }
  
  .btn {
    height: min(150px, 28vw);
    width: min(150px, 28vw);
    --button-depth: 10px;
  }
  
  #level-title {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    margin-bottom: 10px;
  }
  
  #show-leaderboard-btn {
    position: fixed;
    top: 15px;
    left: 15px;
    font-size: 0.6rem;
    padding: 8px 12px;
  }
}

/* Accessibility improvements */
@media (prefers-reduced-motion) {
  .container, #level-title, .btn, .pressed, body::after {
    animation: none;
    transition: none;
  }
  
  .game-over {
    animation: none;
  }
  
  .btn:hover, .pressed {
    transform: none;
  }
}

/* Leaderboard Styles */
#leaderboard {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: scale(1.1);
  transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  padding: 20px;
}

#leaderboard.show {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
}

#leaderboard h2 {
  color: var(--text);
  font-size: clamp(1.5rem, 3vw, 2.5rem);
  margin-bottom: 30px;
  text-shadow: 0 0 10px var(--glow);
  letter-spacing: 2px;
  position: relative;
  animation: titleGlow 2s infinite alternate;
}

@keyframes titleGlow {
  from { text-shadow: 0 0 10px var(--glow); }
  to { text-shadow: 0 0 20px var(--accent), 0 0 30px var(--accent); }
}

.leaderboard-list {
  width: 90%;
  max-width: 500px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 15px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.leaderboard-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  animation: slideIn 0.5s forwards;
  transform: translateX(-100%);
  opacity: 0;
}

.leaderboard-entry:last-child {
  border-bottom: none;
}

.leaderboard-entry:nth-child(1) { animation-delay: 0.1s; }
.leaderboard-entry:nth-child(2) { animation-delay: 0.2s; }
.leaderboard-entry:nth-child(3) { animation-delay: 0.3s; }
.leaderboard-entry:nth-child(4) { animation-delay: 0.4s; }
.leaderboard-entry:nth-child(5) { animation-delay: 0.5s; }

@keyframes slideIn {
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.rank {
  font-size: 1.2rem;
  color: var(--accent);
  min-width: 40px;
  text-align: left;
}

.name {
  flex-grow: 1;
  text-align: left;
  font-size: 0.9rem;
  padding: 0 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score {
  font-size: 1.2rem;
  color: var(--green);
  font-weight: bold;
  min-width: 50px;
  text-align: right;
}

/* Name Dialog Styles */
#name-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.8);
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

#name-dialog.show {
  opacity: 1;
  visibility: visible;
}

.dialog-content {
  background: linear-gradient(to bottom right, #2c3e50, #1a1e24);
  padding: 30px;
  border-radius: 15px;
  width: 90%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.1);
  transform: translateY(-20px);
  transition: transform 0.3s ease;
  animation: dialogAppear 0.5s forwards;
}

@keyframes dialogAppear {
  from { transform: translateY(-50px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

#name-dialog.show .dialog-content {
  transform: translateY(0);
}

.dialog-content h3 {
  margin-bottom: 20px;
  color: var(--text);
  font-size: 1.5rem;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

#player-name {
  width: 100%;
  padding: 12px 15px;
  margin-bottom: 20px;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Press Start 2P', cursive;
  font-size: 1rem;
  text-align: center;
  outline: none;
  transition: all 0.3s ease;
}

#player-name:focus {
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

#start-game {
  padding: 12px 30px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-family: 'Press Start 2P', cursive;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  transform: translateZ(5px);
}

#start-game:hover {
  background: #8e44ad;
  transform: translateY(-3px) translateZ(5px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

#start-game:active {
  transform: translateY(1px) translateZ(2px);
}

/* Make sure leaderboard and dialog work on mobile too */
@media (max-width: 768px) {
  .leaderboard-list {
    width: 95%;
    padding: 15px;
  }
  
  .leaderboard-entry {
    padding: 10px;
  }
  
  .rank, .score {
    font-size: 1rem;
  }
  
  .name {
    font-size: 0.8rem;
  }
  
  #player-name, #start-game {
    font-size: 0.9rem;
  }
  
  .dialog-content {
    padding: 20px;
  }
  
  .dialog-content h3 {
    font-size: 1.2rem;
  }
}
