/* ===== CSS Variables & Design Tokens ===== */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --text-primary: #f0f0f5;
  --text-secondary: rgba(240, 240, 245, 0.5);
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Finger Colors - Vibrant Neon Palette */
  --finger-1: #FF6B6B;
  --finger-2: #4ECDC4;
  --finger-3: #45B7D1;
  --finger-4: #A8E6CF;
  --finger-5: #FFD93D;
  --finger-6: #C084FC;
  --finger-7: #F472B6;
  --finger-8: #FB923C;
  --finger-9: #34D399;
  --finger-10: #60A5FA;

  --circle-size: 90px;
  --transition-smooth: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

/* ===== App Container ===== */
#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ===== Background Canvas ===== */
#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.4;
}

/* ===== Touch Area ===== */
#touch-area {
  position: fixed;
  inset: 0;
  z-index: 10;
  touch-action: none;
}

/* ===== Finger Circle ===== */
.finger-circle {
  position: absolute;
  width: var(--circle-size);
  height: var(--circle-size);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.3s var(--transition-smooth),
              opacity 0.4s ease,
              box-shadow 0.4s ease;
  z-index: 20;
  pointer-events: none;
}

.finger-circle.active {
  transform: translate(-50%, -50%) scale(1);
}

.finger-circle .circle-inner {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  opacity: 0.85;
}

.finger-circle .circle-glow {
  position: absolute;
  inset: -15px;
  border-radius: 50%;
  opacity: 0.3;
  filter: blur(15px);
}

.finger-circle .circle-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid;
  opacity: 0.5;
}

/* Pulse animation for active fingers */
.finger-circle.active .circle-glow {
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.15); opacity: 0.5; }
}

/* Ripple effect on touch */
.finger-circle .ripple {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid;
  opacity: 0;
  animation: ripple-out 0.8s ease-out forwards;
}

@keyframes ripple-out {
  0% { transform: scale(0.8); opacity: 0.6; }
  100% { transform: scale(2); opacity: 0; }
}

/* ===== Selected State ===== */
.finger-circle.selected {
  transform: translate(-50%, -50%) scale(1.5);
  z-index: 30;
}

.finger-circle.selected .circle-inner {
  opacity: 1;
  box-shadow: 0 0 30px var(--selected-color, #fff),
              0 0 60px var(--selected-color, #fff);
}

.finger-circle.selected .circle-glow {
  animation: selected-glow 0.8s ease-in-out infinite alternate;
  opacity: 0.9;
  inset: -35px;
  filter: blur(25px);
}

@keyframes selected-glow {
  0% { transform: scale(1); opacity: 0.6; filter: blur(20px); }
  100% { transform: scale(1.5); opacity: 1; filter: blur(30px); }
}

.finger-circle.selected .circle-ring {
  animation: selected-ring-expand 1.5s ease-in-out infinite;
  opacity: 0.9;
  border-width: 3px;
}

@keyframes selected-ring-expand {
  0%, 100% { inset: -6px; opacity: 0.9; }
  50% { inset: -18px; opacity: 0.3; }
}

/* Pulse wave from selected finger */
.finger-circle.selected::before {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid var(--selected-color, #fff);
  animation: pulse-wave 1.5s ease-out infinite;
}

.finger-circle.selected::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 1px solid var(--selected-color, #fff);
  animation: pulse-wave 1.5s ease-out 0.5s infinite;
}

@keyframes pulse-wave {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(3); opacity: 0; }
}

/* Not selected - fade out */
.finger-circle.not-selected {
  transform: translate(-50%, -50%) scale(0.5);
  opacity: 0.1;
  transition: transform 0.6s ease, opacity 0.6s ease;
}

.finger-circle.not-selected .circle-glow {
  animation: none;
  opacity: 0;
}

/* ===== Light Ray effect for winner ===== */
.light-ray-container {
  position: fixed;
  pointer-events: none;
  z-index: 29;
  width: 300px;
  height: 300px;
  transform: translate(-50%, -50%);
}

.light-ray {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 150px;
  transform-origin: bottom center;
  opacity: 0;
  animation: ray-burst 2s ease-out forwards;
}

@keyframes ray-burst {
  0% { opacity: 0; height: 0; }
  20% { opacity: 0.8; height: 150px; }
  100% { opacity: 0; height: 200px; }
}

/* ===== Shockwave ===== */
.shockwave {
  position: fixed;
  pointer-events: none;
  z-index: 28;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.4);
  animation: shockwave-expand 1s ease-out forwards;
}

@keyframes shockwave-expand {
  0% { width: 20px; height: 20px; opacity: 0.8; }
  100% { width: 400px; height: 400px; opacity: 0; }
}

/* ===== Crown / Star effect for winner ===== */
.finger-circle .crown {
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%) scale(0);
  font-size: 28px;
  filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.8));
  transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  z-index: 31;
}

.finger-circle.selected .crown {
  transform: translateX(-50%) scale(1);
  animation: crown-bounce 1s ease-in-out infinite alternate;
}

@keyframes crown-bounce {
  0% { transform: translateX(-50%) scale(1) translateY(0); }
  100% { transform: translateX(-50%) scale(1.1) translateY(-5px); }
}

/* ===== Sparkle effects ===== */
.sparkle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
  pointer-events: none;
  z-index: 25;
  animation: sparkle-fly 0.8s ease-out forwards;
}

@keyframes sparkle-fly {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

/* ===== Guide Message ===== */
#guide-message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 5;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

#guide-message.hidden {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.9);
}

.guide-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 24px;
  color: var(--text-secondary);
  animation: hand-float 3s ease-in-out infinite;
}

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

#guide-message h1 {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #fff 0%, rgba(255,255,255,0.6) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#guide-message p {
  font-size: 0.9rem;
  font-weight: 300;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ===== Countdown ===== */
#countdown {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#countdown.hidden {
  opacity: 0;
}

.countdown-ring {
  width: 120px;
  height: 120px;
}

.countdown-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.06);
  stroke-width: 4;
}

.countdown-ring-progress {
  fill: none;
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 0;
  transform: rotate(-90deg);
  transform-origin: center;
  transition: stroke-dashoffset linear;
}

/* Countdown Number */
#countdown-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 3rem;
  font-weight: 800;
  color: white;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.5),
               0 0 40px rgba(255, 255, 255, 0.2);
  opacity: 0;
}

#countdown-number.show {
  animation: countdown-pop 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

@keyframes countdown-pop {
  0% { transform: translate(-50%, -50%) scale(2.5); opacity: 0; }
  30% { transform: translate(-50%, -50%) scale(0.9); opacity: 1; }
  50% { transform: translate(-50%, -50%) scale(1.05); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0.3; }
}

/* ===== Result Overlay ===== */
#result-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(255,255,255,0.03) 0%, transparent 60%);
  transition: opacity 0.5s ease;
}

#result-overlay.hidden {
  opacity: 0;
}

.result-text {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: linear-gradient(135deg, #FFD93D, #FF6B6B, #C084FC);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: result-pop 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
  opacity: 0;
}

@keyframes result-pop {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== Reset Button ===== */
#reset-btn {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50px;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: all 0.4s var(--transition-smooth);
  opacity: 0;
}

#reset-btn:not(.hidden) {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#reset-btn.hidden {
  pointer-events: none;
}

#reset-btn:active {
  transform: translateX(-50%) scale(0.95);
  background: rgba(255, 255, 255, 0.15);
}

/* ===== Settings Button ===== */
#settings-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 40;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.3s ease;
}

#settings-btn:active {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(0.92);
}

/* ===== Settings Panel ===== */
#settings-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.3s ease;
}

#settings-panel.hidden {
  opacity: 0;
  pointer-events: none;
}

#settings-panel.hidden .settings-content {
  transform: translateY(100%);
}

.settings-content {
  width: 100%;
  max-width: 420px;
  background: var(--bg-secondary);
  border-radius: 24px 24px 0 0;
  padding: 32px 24px 48px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  transition: transform 0.4s var(--transition-smooth);
}

.settings-content h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 28px;
  text-align: center;
  letter-spacing: -0.01em;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.setting-item label {
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-primary);
}

/* Stepper */
.stepper {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stepper-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  font-size: 1.2rem;
  font-family: var(--font-family);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.stepper-btn:active {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.9);
}

.stepper span {
  font-size: 1rem;
  font-weight: 600;
  min-width: 30px;
  text-align: center;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 30px;
  transition: background 0.3s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background: #4ECDC4;
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* Settings Close */
.settings-close-btn {
  display: block;
  width: 100%;
  margin-top: 24px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.settings-close-btn:active {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.98);
}

/* ===== Confetti ===== */
.confetti-piece {
  position: fixed;
  width: 8px;
  height: 8px;
  z-index: 35;
  pointer-events: none;
  animation: confetti-fall var(--duration) ease-out forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) rotate(var(--rot)) scale(0);
    opacity: 0;
  }
}

/* ===== Flash effect ===== */
.flash-overlay {
  position: fixed;
  inset: 0;
  background: white;
  z-index: 35;
  pointer-events: none;
  animation: flash 0.4s ease-out forwards;
}

@keyframes flash {
  0% { opacity: 0.3; }
  100% { opacity: 0; }
}

/* ===== Safe area for notch ===== */
@supports (padding-top: env(safe-area-inset-top)) {
  #settings-btn {
    top: calc(16px + env(safe-area-inset-top));
  }
  
  #reset-btn {
    bottom: calc(40px + env(safe-area-inset-bottom));
  }

  .settings-content {
    padding-bottom: calc(48px + env(safe-area-inset-bottom));
  }
}
