:root {
  --card-width: 200px;
  --card-height: 350px;
  --bg-dark: #050510;
  --accent-gold: #d4af37;
  --accent-glow: rgba(212, 175, 55, 0.6);
  --glass-bg: rgba(5, 5, 16, 0.6);
  --glass-border: rgba(212, 175, 55, 0.3);
}

/* Intro Animation Class - if needed, but we will use JS interpolation */

body,
html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  background: radial-gradient(circle at center, #1b1b3a 0%, var(--bg-dark) 100%);
  font-family: 'Cormorant Garamond', serif;
  color: #eee;
  user-select: none;
}

/* Background Effects */
#stars-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0.8;
}

#fog-layer {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 40%;
  background: linear-gradient(to top, rgba(10, 10, 30, 0.9), transparent);
  z-index: 1;
  pointer-events: none;
}

/* Main Game Container */
#game-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  perspective: 1200px; /* Increased perspective for deeper look */
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* 3D Scene for Cards */
#scene {
  width: 100%;
  height: 60vh;
  position: relative;
  transform-style: preserve-3d;
  /* removed transition, we handle it in JS loop */
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Card Styles */
.card-wrapper {
  position: absolute;
  width: var(--card-width);
  height: var(--card-height);
  transform-style: preserve-3d;
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 0.3s;
  cursor: pointer;
  border-radius: 15px;
}

.card-wrapper.selected {
  box-shadow: 0 0 30px var(--accent-glow);
  z-index: 100;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.8s;
  transform-style: preserve-3d;
  border-radius: 15px;
}

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

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 15px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  border: 2px solid #333;
}

.card-back {
  background: repeating-linear-gradient(45deg, #1a1a2e, #1a1a2e 10px, #16213e 10px, #16213e 20px);
  background-image: url('../img/black-thread.png'); /* Fallback or simple pattern */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Elaborate back design using CSS pseudo-elements */
.card-back::after {
  content: '✦';
  font-size: 3rem;
  color: rgba(212, 175, 55, 0.3);
  border: 2px solid rgba(212, 175, 55, 0.3);
  border-radius: 50%;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-front {
  background-color: #fff;
  transform: rotateY(180deg);
  background-size: cover;
  background-position: center;
}

/* UI Overlay */
#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 20;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  box-sizing: border-box;
}

#header {
  text-align: center;
  text-shadow: 0 0 10px var(--accent-gold);
  margin-top: 20px;
}

h1 {
  margin: 0;
  font-weight: 300;
  letter-spacing: 5px;
  color: var(--accent-gold);
  font-family: 'Cinzel Decorative', cursive;
}

h2,
h3 {
  font-family: 'Cinzel Decorative', cursive;
}

#status-text {
  text-align: center;
  font-size: 1.2rem;
  color: #aaa;
  margin-top: 10px;
  text-shadow: 0 0 5px black;
  font-family: 'Playfair Display', serif;
}

#controls {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  margin-bottom: 30px;
}

.btn {
  background: transparent;
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  padding: 10px 30px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  text-transform: uppercase;
  letter-spacing: 2px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 30px;
  font-family: 'Playfair Display', serif;
}

.btn:hover {
  background: var(--accent-gold);
  color: #000;
  box-shadow: 0 0 20px var(--accent-glow);
}

#webcam-preview {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 160px;
  height: 120px;
  border: 1px solid var(--accent-gold);
  opacity: 0.5;
  border-radius: 10px;
  transform: scaleX(-1); /* Mirror */
  z-index: 100;
}

#interpretation-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  max-width: 800px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  padding: 30px;
  border-radius: 20px;
  color: #eee;
  display: none; /* Hidden by default */
  pointer-events: auto;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(212, 175, 55, 0.1);
  z-index: 50;
}

#interpretation-content {
  line-height: 1.6;
  font-size: 1.1rem;
  height: 60vh;
  overflow-y: auto;
}

#interpretation-content h3 {
  color: var(--accent-gold);
  border-bottom: 1px solid #333;
  padding-bottom: 10px;
}

#token-input-container {
  position: absolute;
  top: 20px;
  right: 20px;
  pointer-events: auto;
  z-index: 100;
}

#api-token {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid #555;
  color: white;
  padding: 5px 10px;
  border-radius: 5px;
  width: 150px;
  transition: width 0.3s;
  font-family: 'Playfair Display', serif;
}

.card-wrapper.locked-center {
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) scale(1.5) rotateY(0deg) !important;
  z-index: 5000 !important;
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#api-token:focus {
  width: 300px;
  border-color: var(--accent-gold);
  outline: none;
}

/* Hand Gesture Guide */
#gesture-guide {
  position: absolute;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  display: none; /* Removed based on user request */
  gap: 20px;
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
  width: 100%;
  justify-content: center;
}

.guide-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: rgba(212, 175, 55, 0.5);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none; /* Ensure no blocking */
  font-family: 'Playfair Display', serif;
}

#zone-left {
  left: 0;
  justify-content: flex-start;
  padding-left: 50px;
}
#zone-right {
  right: 0;
  justify-content: flex-end;
  padding-right: 50px;
}
#zone-center {
  left: 30%;
  width: 40%;
  align-items: flex-end;
  padding-bottom: 180px;
}

.guide-zone.active {
  opacity: 1;
  text-shadow: 0 0 20px var(--accent-gold);
}

/* New Pulse Animation */
@keyframes pulseRing {
  0% {
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 1;
    border-width: 5px;
  }
  100% {
    transform: translate(-50%, -50%) scale(2);
    opacity: 0;
    border-width: 0px;
  }
}

.guide-icon {
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border: 1px solid transparent;
}

.guide-icon.active {
  border-color: var(--accent-gold);
  background: rgba(212, 175, 55, 0.2);
  box-shadow: 0 0 15px var(--accent-glow);
  transform: scale(1.2);
}

/* Cursor & Particles */
#hand-cursor {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid var(--accent-gold);
  border-radius: 50%;
  pointer-events: none;
  z-index: 1000;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 15px var(--accent-glow);
  transition: width 0.2s, height 0.2s, background-color 0.2s;
  display: none; /* Hidden until hand detected */
}

/* Removed grabbing state as requested */
/* #hand-cursor.grabbing { ... } */

.cursor-trail {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--accent-glow);
  border-radius: 50%;
  pointer-events: none;
  z-index: 999;
  opacity: 0.8;
  animation: fadeTrail 0.5s forwards;
}

@keyframes fadeTrail {
  to {
    opacity: 0;
    transform: scale(0.2);
  }
}

.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #ffffff;
  border-radius: 50%;
  pointer-events: none;
  z-index: 2001;
  animation: riseAndFade 0.8s ease-out forwards;
  box-shadow: 0 0 10px #ffffff, 0 0 20px #ffffff;
}

@keyframes riseAndFade {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -150px) scale(0.2);
    opacity: 0;
  }
}

/* Charge Progress Bar */
#charge-progress-container {
  width: 200px;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  margin: 10px auto;
  overflow: hidden;
  display: none; /* Hidden by default */
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

#charge-progress-bar {
  width: 0%;
  height: 100%;
  background: #fff;
  box-shadow: 0 0 10px #fff;
  transition: width 0.1s linear;
}

/* Charge Ring */
#charge-ring {
  position: absolute;
  width: 60px;
  height: 60px;
  border: 4px solid var(--accent-gold);
  border-radius: 50%;
  pointer-events: none;
  z-index: 1001;
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  transition: transform 0.1s linear;
}

/* Picked Card Zone */
#picked-zone {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  display: none; /* Hidden initially */
  gap: 20px;
  z-index: 50;
  pointer-events: none;
}

.picked-slot {
  width: 100px;
  height: 175px;
  border: 2px dashed rgba(212, 175, 55, 0.3);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  transition: all 0.5s;
}

.picked-slot.filled {
  border-style: solid;
  border-color: var(--accent-gold);
  background: rgba(0, 0, 0, 0.6);
}

.mini-card {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  animation: flyIn 0.5s ease-out;
}

@keyframes flyIn {
  from {
    transform: translateY(-300px) scale(1.5);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* Loading Spinner */
.spinner {
  border: 4px solid rgba(255, 255, 255, 0.1);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border-left-color: var(--accent-gold);
  animation: spin 1s linear infinite;
  display: none;
  margin: 20px auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Status Text Animation */
.text-enter-active {
  animation: textEnter 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes textEnter {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    text-shadow: 0 0 0 rgba(212, 175, 55, 0);
    filter: blur(4px);
  }
  60% {
    opacity: 0.8;
    text-shadow: 0 0 20px rgba(212, 175, 55, 0.8);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    text-shadow: 0 0 5px black;
  }
}

/* Settings Icon */
#settings-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  color: var(--accent-gold);
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.5s;
  pointer-events: auto; /* Enable clicks */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  border: 1px solid transparent;
  font-family: 'Playfair Display', serif;
}
#settings-btn:hover {
  transform: rotate(90deg);
  border-color: var(--accent-gold);
  background: rgba(212, 175, 55, 0.1);
}

/* Settings Modal */
#settings-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 3000;
  backdrop-filter: blur(5px);
}
.settings-content {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(212, 175, 55, 0.1);
  width: 90%;
  max-width: 400px;
  margin: 15vh auto;
  padding: 30px;
  border-radius: 10px;
  text-align: center;
  color: #eee;
}
.settings-content input {
  width: 80%;
  padding: 10px;
  margin: 20px 0;
  background: #222;
  border: 1px solid #444;
  color: white;
  border-radius: 5px;
  font-size: 1rem;
  font-family: 'Playfair Display', serif;
}
.settings-content a {
  color: var(--accent-gold);
  text-decoration: underline;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: #111;
}
::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #555;
}
