/* ===== COIN SWING GAME ===== */

#coinswingGame {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a1e;
  transition: box-shadow 0.5s ease;
}

/* Danger mode: blue-purple vignette */
#coinswingGame.sw-danger-active {
  box-shadow: inset 0 0 60px rgba(100, 50, 255, 0.2), inset 0 0 120px rgba(100, 50, 255, 0.08);
  animation: sw-danger-pulse 1.5s ease-in-out infinite;
}

@keyframes sw-danger-pulse {
  0%, 100% { box-shadow: inset 0 0 60px rgba(100, 50, 255, 0.15), inset 0 0 120px rgba(100, 50, 255, 0.05); }
  50% { box-shadow: inset 0 0 80px rgba(100, 50, 255, 0.3), inset 0 0 160px rgba(100, 50, 255, 0.1); }
}

/* 3D Canvas Container */
#swThreeContainer {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

#swThreeContainer canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}

/* ===== HUD OVERLAY ===== */
.sw-hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  pointer-events: none;
  padding: env(safe-area-inset-top, 12px) 12px 0 12px;
}

.sw-hud > * { pointer-events: auto; }

/* Back Button */
.sw-back-btn {
  position: absolute;
  top: env(safe-area-inset-top, 8px);
  left: 8px;
  z-index: 20;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Turn Indicator */
.sw-turn-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  margin: 0 48px;
}

.sw-turn-avatar {
  font-size: 28px;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
  animation: sw-turn-bounce 0.6s ease;
}

.sw-turn-text {
  font-size: 16px;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 2px 8px rgba(0,0,0,0.7);
}

.sw-turn-text.my-turn {
  color: #88bbff;
  font-size: 20px;
  animation: sw-pulse 1s ease-in-out infinite;
}

/* Streak Badge */
.sw-streak-badge {
  font-size: 12px;
  font-weight: 800;
  color: #6688ff;
  background: rgba(100, 136, 255, 0.15);
  border: 1px solid rgba(100, 136, 255, 0.3);
  padding: 2px 8px;
  border-radius: 10px;
  animation: sw-streak-flash 0.8s ease;
  text-shadow: 0 0 8px rgba(100, 136, 255, 0.5);
}

@keyframes sw-streak-flash {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes sw-turn-bounce {
  0% { transform: scale(0.5) translateY(-10px); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes sw-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.05); }
}

/* Info Bar */
.sw-info-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 4px;
  padding: 0 12px;
  flex-wrap: wrap;
}

.sw-info-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.sw-info-item .sw-info-icon {
  font-size: 16px;
}

/* Stability Meter */
.sw-stability-wrap {
  width: 80px;
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  overflow: hidden;
}

.sw-stability-bar {
  height: 100%;
  background: #44ff88;
  border-radius: 3px;
  transition: width 0.5s ease, background 0.3s;
  width: 100%;
}

/* Speed Indicator */
.sw-speed-indicator {
  display: none;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: rgba(255,255,255,0.6);
}

.sw-speed-icon {
  font-size: 14px;
  color: rgba(100, 180, 255, 0.9);
}

.sw-speed-bars {
  display: flex;
  gap: 2px;
  align-items: center;
}

.sw-speed-bar {
  width: 4px;
  height: 8px;
  background: rgba(255,255,255,0.12);
  border-radius: 1px;
  transition: background 0.3s;
}

.sw-speed-bar.active {
  background: rgba(100, 180, 255, 0.7);
}

.sw-speed-bar.active:nth-child(4),
.sw-speed-bar.active:nth-child(5) {
  background: rgba(255, 100, 100, 0.8);
}

.sw-speed-label {
  font-size: 10px;
  color: rgba(255,255,255,0.4);
}

/* Score Display */
.sw-score-display {
  font-size: 13px;
  font-weight: 700;
  color: #88bbff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

/* Player Chips */
.sw-players-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.sw-player-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  border: 2px solid transparent;
  transition: all 0.3s ease;
  min-width: 48px;
}

.sw-player-chip.active {
  border-color: #88bbff;
  background: rgba(136,187,255,0.15);
  transform: scale(1.1);
  box-shadow: 0 0 12px rgba(136,187,255,0.3);
}

.sw-player-chip.team-a { background: rgba(255,100,50,0.12); }
.sw-player-chip.team-a.active { border-color: #ff6432; box-shadow: 0 0 12px rgba(255,100,50,0.3); }
.sw-player-chip.team-b { background: rgba(0,180,255,0.12); }
.sw-player-chip.team-b.active { border-color: #00b4ff; box-shadow: 0 0 12px rgba(0,180,255,0.3); }

.sw-chip-avatar { font-size: 22px; }
.sw-chip-score {
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  font-weight: 600;
}

/* ===== SCORE POPUP ===== */
.sw-score-popup {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  font-size: 22px;
  font-weight: 800;
  color: #88bbff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7), 0 0 16px rgba(136,187,255,0.3);
  pointer-events: none;
  animation: sw-score-float 1.3s ease-out forwards;
  white-space: nowrap;
}

.sw-score-popup.sw-score-perfect {
  color: #44ff88;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7), 0 0 16px rgba(68,255,136,0.4);
  font-size: 26px;
}

.sw-score-popup.sw-score-risky {
  color: #ff6644;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7), 0 0 16px rgba(255,102,68,0.4);
  font-size: 24px;
}

.sw-score-popup.sw-score-multi {
  font-size: 28px;
}

@keyframes sw-score-float {
  0% { opacity: 0; transform: translateX(-50%) scale(0.5) translateY(10px); }
  15% { opacity: 1; transform: translateX(-50%) scale(1.2) translateY(0); }
  30% { transform: translateX(-50%) scale(1) translateY(-5px); }
  100% { opacity: 0; transform: translateX(-50%) scale(0.9) translateY(-60px); }
}

/* ===== BOTTOM CONTROLS ===== */
.sw-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  padding: 0 12px env(safe-area-inset-bottom, 16px) 12px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.sw-bottom > * { pointer-events: auto; }

/* Drop Button - large for easy tapping */
.sw-drop-btn {
  display: none;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4488ff, #6644ff);
  border: 3px solid rgba(255,255,255,0.3);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(68,136,255,0.4), inset 0 2px 4px rgba(255,255,255,0.2);
  transition: transform 0.15s, box-shadow 0.15s;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.sw-drop-btn.sw-drop-ready {
  display: flex;
  animation: sw-drop-btn-glow 1.2s ease-in-out infinite;
}

.sw-drop-btn:active {
  transform: scale(0.9);
  box-shadow: 0 2px 10px rgba(68,136,255,0.3);
}

@keyframes sw-drop-btn-glow {
  0%, 100% { box-shadow: 0 4px 20px rgba(68,136,255,0.4), inset 0 2px 4px rgba(255,255,255,0.2); }
  50% { box-shadow: 0 4px 30px rgba(68,136,255,0.7), inset 0 2px 4px rgba(255,255,255,0.2), 0 0 40px rgba(68,136,255,0.2); }
}

/* Emoji Bar */
.sw-emoji-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease, padding 0.3s;
  padding: 0 8px;
}

.sw-emoji-bar.sw-emoji-open {
  max-height: 50px;
  padding: 6px 8px;
}

.sw-emoji-btn {
  font-size: 24px;
  cursor: pointer;
  transition: transform 0.15s;
  padding: 2px 4px;
  border-radius: 8px;
  user-select: none;
  -webkit-user-select: none;
}

.sw-emoji-btn:active {
  transform: scale(1.3);
}

.sw-emoji-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #fff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  flex-shrink: 0;
}

/* ===== FLOATING EMOJI ===== */
.sw-floating-emoji {
  position: absolute;
  font-size: 48px;
  pointer-events: none;
  z-index: 15;
  animation: sw-emoji-float 1.5s ease-out forwards;
}

@keyframes sw-emoji-float {
  0% { transform: scale(0.3) translateY(0); opacity: 0; }
  15% { transform: scale(1.2) translateY(-10px); opacity: 1; }
  30% { transform: scale(1) translateY(-20px); opacity: 1; }
  100% { transform: scale(0.8) translateY(-120px); opacity: 0; }
}

/* ===== RESULT OVERLAY ===== */
.sw-result-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 20px;
}

.sw-result-overlay.sw-result-show {
  animation: sw-result-fade 0.5s ease;
}

@keyframes sw-result-fade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.sw-result-card {
  text-align: center;
  max-width: 320px;
  width: 100%;
}

.sw-result-emoji {
  font-size: 72px;
  margin-bottom: 12px;
  animation: sw-result-emoji-bounce 0.8s ease;
}

@keyframes sw-result-emoji-bounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.3); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

.sw-result-title {
  font-size: 32px;
  font-weight: 900;
  color: #fff;
  margin-bottom: 8px;
  text-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

.sw-result-score {
  font-size: 20px;
  font-weight: 700;
  color: #88bbff;
  margin-bottom: 4px;
}

.sw-result-subtitle {
  font-size: 14px;
  color: rgba(255,255,255,0.6);
  margin-bottom: 16px;
}

/* Result Stats */
.sw-result-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 20px;
}

.sw-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.sw-stat-label {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  font-weight: 600;
  text-transform: uppercase;
}

.sw-stat-val {
  font-size: 20px;
  font-weight: 800;
  color: #88bbff;
}

/* Scoreboard */
.sw-scoreboard {
  background: rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 20px;
}

.sw-score-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
}

.sw-score-row.loser {
  background: rgba(255,0,0,0.1);
  border: 1px solid rgba(255,0,0,0.2);
}

.sw-score-rank { font-size: 16px; }
.sw-score-avatar { font-size: 20px; }
.sw-score-name {
  flex: 1;
  font-size: 14px;
  color: rgba(255,255,255,0.85);
  text-align: left;
  font-weight: 600;
}
.sw-score-detail {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
}
.sw-score-val {
  font-size: 14px;
  color: #88bbff;
  font-weight: 700;
  min-width: 50px;
  text-align: right;
}

/* Buttons */
.sw-result-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.sw-btn {
  padding: 12px 24px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  min-height: 44px;
}

.sw-btn:active { transform: scale(0.95); }

.sw-btn-primary {
  background: linear-gradient(135deg, #4488ff, #6644ff);
  color: #fff;
  box-shadow: 0 4px 15px rgba(68,136,255,0.3);
}

.sw-btn-secondary {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
}

/* ===== GUIDE TEXT ===== */
.sw-guide {
  position: absolute;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-size: 14px;
  color: rgba(255,255,255,0.5);
  text-align: center;
  pointer-events: none;
  text-shadow: 0 1px 6px rgba(0,0,0,0.8);
  animation: sw-guide-fade 2s ease-in-out infinite;
  white-space: nowrap;
}

@keyframes sw-guide-fade {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.9; }
}

/* ===== PEEK BUTTON (Team Mode) ===== */
.sw-peek-btn {
  position: absolute;
  top: env(safe-area-inset-top, 8px);
  right: 8px;
  z-index: 20;
  padding: 8px 14px;
  border-radius: 20px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.2s, transform 0.15s;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.sw-peek-btn:active {
  transform: scale(0.95);
  background: rgba(100,136,255,0.3);
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 430px) {
  .sw-drop-btn { width: 80px; height: 80px; font-size: 14px; }
  .sw-turn-text { font-size: 14px; }
  .sw-turn-text.my-turn { font-size: 18px; }
  .sw-player-chip { padding: 3px 6px; min-width: 42px; }
  .sw-chip-avatar { font-size: 20px; }
  .sw-result-emoji { font-size: 56px; }
  .sw-result-title { font-size: 26px; }
  .sw-score-popup { font-size: 18px; }
  .sw-score-popup.sw-score-perfect,
  .sw-score-popup.sw-score-multi { font-size: 22px; }
}

@media (max-height: 600px) {
  .sw-info-bar { margin-top: 0; }
  .sw-players-bar { margin-top: 4px; }
  .sw-drop-btn { width: 70px; height: 70px; font-size: 13px; }
}
