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

:root {
  --primary: #6c5ce7;
  --primary-light: #a29bfe;
  --secondary: #00cec9;
  --accent: #fd79a8;
  --success: #00b894;
  --danger: #e17055;
  --warning: #fdcb6e;
  --dark: #2d3436;
  --dark-light: #3d3d3d;
  --text: #ffffff;
  --text-muted: #b2bec3;
  --card-bg: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.15);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --radius: 16px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family:
    "Poppins",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
  min-height: 100vh;
  color: var(--text);
  overflow-x: hidden;
  position: relative;
}

/* Animated background blobs */
body::before,
body::after {
  content: "";
  position: fixed;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.3;
  z-index: -1;
  animation: float 20s ease-in-out infinite;
}

body::before {
  background: var(--primary);
  top: -150px;
  left: -150px;
}

body::after {
  background: var(--secondary);
  bottom: -150px;
  right: -150px;
  animation-delay: -10s;
}

@keyframes float {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }
  33% {
    transform: translate(30px, -30px) scale(1.1);
  }
  66% {
    transform: translate(-20px, 20px) scale(0.9);
  }
}

.game-wrapper {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top Bar */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  animation: slideDown 0.5s ease;
}

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

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.logo span {
  background: linear-gradient(135deg, var(--primary-light), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stats {
  display: flex;
  gap: 20px;
}

.stat-item {
  text-align: center;
  padding: 4px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  transition: var(--transition);
}

.stat-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.stat-value.pop {
  animation: pop 0.3s ease;
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

/* Game Card */
.game-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  padding: 32px;
  flex: 1;
  animation: fadeIn 0.6s ease;
}

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

/* Title Section */
.title-section {
  text-align: center;
  margin-bottom: 24px;
}

.title-section h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(
    135deg,
    var(--primary-light),
    var(--secondary),
    var(--accent)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.rgb-display {
  font-size: 2.2rem;
  font-weight: 700;
  font-family: "Courier New", monospace;
  color: var(--text);
  text-shadow: 0 0 20px rgba(108, 92, 231, 0.5);
  letter-spacing: 2px;
  margin: 12px 0;
  transition: var(--transition);
}

.rgb-display.shake {
  animation: shake 0.4s ease;
}

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

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 300;
}

/* Timer */
.timer-section {
  margin-bottom: 24px;
}

.timer-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(
    90deg,
    var(--success),
    var(--warning),
    var(--danger)
  );
  border-radius: 4px;
  transition: width 0.1s linear;
}

.timer-text {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.timer-text.warning {
  color: var(--danger);
  font-weight: 700;
  animation: pulse 0.5s ease infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Controls */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.mode-buttons {
  display: flex;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px;
  border-radius: 12px;
}

.mode-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  transition: var(--transition);
}

.mode-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

.mode-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  box-shadow: 0 4px 15px rgba(108, 92, 231, 0.4);
}

.reset-btn {
  padding: 10px 24px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--secondary), #00b894);
  color: white;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 15px rgba(0, 206, 201, 0.3);
}

.reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 206, 201, 0.4);
}

.reset-btn:active {
  transform: translateY(0);
}

/* Message */
.message {
  text-align: center;
  min-height: 30px;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  transition: var(--transition);
}

.message.correct {
  color: var(--success);
  animation: pop 0.4s ease;
}

.message.wrong {
  color: var(--danger);
  animation: shake 0.4s ease;
}

.message.timeout {
  color: var(--warning);
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.square {
  aspect-ratio: 1;
  border-radius: 16px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.square::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), transparent);
  opacity: 0;
  transition: var(--transition);
}

.square:hover {
  transform: scale(1.05) translateY(-4px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.3);
}

.square:hover::before {
  opacity: 1;
}

.square:active {
  transform: scale(0.95);
}

.square.fade-out {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

.square.correct {
  animation: correctPulse 0.5s ease;
  border-color: var(--success);
  box-shadow: 0 0 30px rgba(0, 184, 148, 0.5);
}

@keyframes correctPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

.square.wrong {
  animation: wrongShake 0.4s ease;
}

@keyframes wrongShake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-10px);
  }
  40% {
    transform: translateX(10px);
  }
  60% {
    transform: translateX(-10px);
  }
  80% {
    transform: translateX(10px);
  }
}

/* Hint Button */
.hint-btn {
  display: block;
  margin: 0 auto;
  padding: 10px 24px;
  border: 2px solid var(--warning);
  border-radius: 12px;
  background: transparent;
  color: var(--warning);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.hint-btn:hover:not(:disabled) {
  background: var(--warning);
  color: var(--dark);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(253, 203, 110, 0.3);
}

.hint-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Footer */
footer {
  text-align: center;
  padding: 24px 0 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

footer a {
  color: var(--primary-light);
  text-decoration: none;
  font-weight: 600;
  transition: var(--transition);
}

footer a:hover {
  color: var(--secondary);
  text-decoration: underline;
}

/* Start Screen */
.start-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
  z-index: 2000;
  padding: 20px;
  overflow-y: auto;
  transition:
    opacity 0.5s ease,
    visibility 0.5s ease;
}

.start-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  padding: 40px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  animation: fadeIn 0.6s ease;
}

.start-logo {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: float 3s ease-in-out infinite;
}

.start-title {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.start-title span {
  background: linear-gradient(135deg, var(--primary-light), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.start-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 300;
  margin-bottom: 24px;
}

.instructions {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 24px;
  text-align: left;
}

.instructions h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-light);
  text-align: center;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.instruction-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.instruction-item:last-child {
  border-bottom: none;
}

.instruction-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.instruction-item p {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 400;
}

.start-btn {
  display: block;
  width: 100%;
  padding: 16px 32px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  font-family: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 8px 25px rgba(108, 92, 231, 0.4);
  margin-bottom: 16px;
}

.start-btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 35px rgba(108, 92, 231, 0.5);
}

.start-btn:active {
  transform: translateY(0) scale(0.98);
}

.start-tip {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 300;
}

.start-tip kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: inherit;
  font-size: 0.75rem;
  color: var(--text);
}

/* Confetti Canvas */
#confettiCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
}

/* Responsive */
@media (max-width: 600px) {
  .game-wrapper {
    padding: 12px;
  }

  .top-bar {
    padding: 12px 16px;
    flex-direction: column;
    gap: 12px;
  }

  .stats {
    gap: 12px;
  }

  .game-card {
    padding: 20px;
  }

  .title-section h1 {
    font-size: 1.5rem;
  }

  .rgb-display {
    font-size: 1.6rem;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .mode-buttons {
    justify-content: center;
  }

  .reset-btn {
    width: 100%;
  }

  .grid {
    gap: 10px;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
