:root {
  --bg-dark: #070a14;
  --bg-panel: rgba(13, 19, 36, 0.82);
  --cyan: #00f0ff;
  --magenta: #ff0055;
  --yellow: #ffb703;
  --green: #00ff88;
  --purple: #8b5cf6;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-line: rgba(0, 240, 255, 0.22);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Kanit', sans-serif;
  user-select: none;
}

body {
  background: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ================= HEADER ================= */
.app-header {
  height: 64px;
  background: rgba(7, 10, 20, 0.92);
  border-bottom: 1px solid var(--border-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 50;
  backdrop-filter: blur(12px);
}

.brand .kicker {
  font-size: 0.72rem;
  color: var(--purple);
  text-transform: uppercase;
  letter-spacing: 1px;
  display: block;
}

.header-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.3);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff3366;
  box-shadow: 0 0 8px #ff3366;
  transition: all 0.3s;
}

.status-dot.active {
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
}

.header-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: translateY(-1px);
}

.btn-mode {
  border-color: rgba(139, 92, 246, 0.4);
  color: var(--purple);
  background: rgba(139, 92, 246, 0.12);
}

.btn-mode.mouse-mode {
  border-color: rgba(255, 183, 3, 0.4);
  color: var(--yellow);
  background: rgba(255, 183, 3, 0.12);
}

/* ================= GAME STAGE ================= */
.game-stage {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
}

/* Background AR Webcam & Canvas */
.camera-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  background: #050811;
}

#webcam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0.24;
  filter: contrast(1.1) brightness(0.9);
}

#handCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.ar-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 30%, rgba(5, 8, 17, 0.88) 90%);
  pointer-events: none;
  z-index: 3;
}

.ar-grid {
  position: absolute;
  inset: 0;
  background-image: 
    linear-gradient(rgba(139, 92, 246, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(139, 92, 246, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 3;
}

/* ================= STAGE CONTAINER ================= */
.stage-container {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 1080px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  justify-content: space-around;
}

/* Top Stats Bar */
.top-stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-panel);
  border: 1px solid var(--border-line);
  border-radius: 18px;
  padding: 10px 24px;
  backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chip-label {
  font-size: 0.70rem;
  letter-spacing: 1px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.chip-num {
  font-family: 'Outfit', sans-serif;
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.1;
}

.score-chip .chip-num { color: var(--green); text-shadow: 0 0 12px rgba(0, 255, 136, 0.5); }
.timer-chip .chip-num { color: var(--cyan); text-shadow: 0 0 12px rgba(0, 240, 255, 0.5); }
.streak-chip .chip-num { color: var(--yellow); text-shadow: 0 0 12px rgba(255, 183, 3, 0.5); }
.correct-chip .chip-num { color: var(--purple); text-shadow: 0 0 12px rgba(139, 92, 246, 0.5); }

/* ================= CHALLENGE ARENA ================= */
.challenge-arena {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 10px 0;
}

.target-card, .player-detected-card {
  flex: 1;
  height: 270px;
  background: var(--bg-panel);
  border: 2px solid var(--border-line);
  border-radius: 24px;
  backdrop-filter: blur(16px);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  transition: all 0.3s;
}

.target-card {
  border-color: rgba(139, 92, 246, 0.5);
  box-shadow: 0 0 30px rgba(139, 92, 246, 0.2);
}

.player-detected-card {
  border-color: rgba(0, 240, 255, 0.4);
}

.player-detected-card.matched {
  border-color: var(--green);
  box-shadow: 0 0 36px rgba(0, 255, 136, 0.6);
}

.card-badge {
  position: absolute;
  top: 14px;
  left: 20px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.target-emoji, .detected-emoji {
  font-size: 5.5rem;
  line-height: 1;
  filter: drop-shadow(0 0 18px rgba(139, 92, 246, 0.4));
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.target-emoji.pop, .detected-emoji.pop {
  transform: scale(1.15);
}

.target-name, .detected-name {
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  margin-top: 6px;
}

.target-hint {
  font-size: 0.82rem;
  color: var(--yellow);
  font-weight: 600;
}

.accuracy-bar-box {
  position: absolute;
  bottom: 14px;
  left: 20px;
  right: 20px;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
}

.accuracy-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--green));
  transition: width 0.15s ease;
}

/* Bridge Zone (Progress Hold Circle) */
.bridge-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 5;
}

.hold-circle {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-ring {
  transform: rotate(-90deg);
}

.progress-ring-fill {
  transition: stroke-dashoffset 0.05s linear;
}

.hold-text {
  position: absolute;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.hold-text span {
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--green);
}

.match-indicator {
  font-size: 0.90rem;
  font-weight: 700;
  color: var(--yellow);
}

/* ================= MOUSE PANEL ================= */
.mouse-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-line);
  border-radius: 18px;
  padding: 10px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(12px);
}

.panel-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.emoji-grid-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.emoji-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 1.5rem;
  padding: 6px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.emoji-btn:hover {
  background: rgba(139, 92, 246, 0.25);
  border-color: var(--purple);
  transform: scale(1.1);
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.4);
}

/* ================= MODAL OVERLAY ================= */
.overlay-screen {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 17, 0.88);
  backdrop-filter: blur(16px);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 1;
  transition: opacity 0.3s;
}

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

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--purple);
  border-radius: 28px;
  padding: 36px 44px;
  text-align: center;
  max-width: 540px;
  width: 100%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.85), 0 0 40px rgba(139, 92, 246, 0.25);
}

.kicker-banner {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--purple);
  letter-spacing: 1.5px;
  margin-bottom: 6px;
}

.modal-title {
  font-family: 'Outfit', sans-serif;
  font-size: 2.2rem;
  font-weight: 900;
  color: #fff;
  margin-bottom: 12px;
  letter-spacing: 1px;
}

.modal-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 18px;
}

.emoji-preview-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  font-size: 2rem;
  margin-bottom: 20px;
  background: rgba(0, 0, 0, 0.3);
  padding: 10px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.rules-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  margin-bottom: 28px;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.rule-item.good { border-color: rgba(139, 92, 246, 0.35); background: rgba(139, 92, 246, 0.08); }
.rule-item.target { border-color: rgba(0, 255, 136, 0.35); background: rgba(0, 255, 136, 0.08); }

.rule-icon { font-size: 1.8rem; }
.rule-text { font-size: 0.88rem; color: #cbd5e1; }
.rule-text strong { color: #fff; }

.btn-start {
  background: linear-gradient(135deg, var(--purple), #6366f1);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 800;
  border: none;
  padding: 16px 36px;
  border-radius: 16px;
  width: 100%;
  cursor: pointer;
  box-shadow: 0 0 28px rgba(139, 92, 246, 0.45);
  transition: all 0.2s ease;
}

.btn-start:hover {
  transform: scale(1.03);
  box-shadow: 0 0 40px rgba(139, 92, 246, 0.7);
}

/* Stat Summary */
.stat-summary {
  display: flex;
  justify-content: space-around;
  margin-bottom: 28px;
  background: rgba(0, 0, 0, 0.3);
  padding: 16px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-num {
  font-family: 'Outfit', sans-serif;
  font-size: 2rem;
  font-weight: 800;
  color: var(--purple);
}

.stat-lbl {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}
