:root {
  --bg-dark: #0a0e17;
  --bg-card: rgba(18, 24, 38, 0.85);
  --bg-card-hover: rgba(26, 35, 56, 0.95);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --accent-gold: #fbbf24;
  --accent-emerald: #10b981;
  --accent-cyan: #06b6d4;
  --accent-rose: #f43f5e;
  --accent-blue: #3b82f6;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --felt-green: #0d5c34;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
}

#game-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  position: relative;
  background: radial-gradient(circle at 50% 20%, #152238 0%, #080c14 100%);
}

/* ==================== HEADER HUD ==================== */
#hud-header {
  height: 64px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(10, 14, 23, 0.75);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 20;
}

.hud-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-ball {
  width: 38px;
  height: 38px;
  background: radial-gradient(circle at 35% 35%, #2a2a2a, #000);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: 'Outfit', sans-serif;
  font-weight: 900;
  font-size: 18px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5), inset 0 2px 3px rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.15);
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* SCOREBOARD */
#scoreboard {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  transition: all 0.25s ease;
  position: relative;
}

.player-card.active {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.4);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.2);
}

#player2-card.active {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.4);
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.2);
}

.player-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.p1-avatar {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
}

.p2-avatar {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
}

.player-info {
  display: flex;
  flex-direction: column;
}

.player-name {
  font-weight: 700;
  font-size: 13px;
  color: #fff;
}

.player-suit {
  font-size: 11px;
  color: var(--accent-gold);
  font-weight: 600;
}

.player-balls {
  display: flex;
  gap: 4px;
  margin-top: 3px;
  min-height: 16px;
}

.pocket-ball-pill {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 800;
  color: #111;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.4), 0 1px 2px rgba(0,0,0,0.6);
}

.turn-indicator {
  display: none;
  position: absolute;
  top: -8px;
  right: 10px;
  background: var(--accent-emerald);
  color: #064e3b;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.player-card.active .turn-indicator {
  display: block;
  animation: pulse 1.5s infinite;
}

#player2-card.active .turn-indicator {
  background: var(--accent-blue);
  color: #1e3a8a;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.85; }
}

.vs-badge {
  font-family: 'Outfit', sans-serif;
  font-weight: 900;
  font-size: 12px;
  color: var(--text-muted);
  padding: 3px 6px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
}

/* ACTIONS */
.hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-subtle);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  transition: all 0.2s;
}

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

.btn-icon.active {
  border-color: var(--accent-gold);
  background: rgba(251, 191, 36, 0.15);
}

/* ==================== TABLE WRAPPER ==================== */
#table-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 10px 70px 10px 10px; /* Room for power slider on right */
}

#billiard-canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  border-radius: 16px;
  cursor: crosshair;
}

/* ==================== NOTIFICATION BANNER ==================== */
#game-banner {
  position: absolute;
  top: 25px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(251, 191, 36, 0.4);
  padding: 10px 24px;
  border-radius: 30px;
  text-align: center;
  pointer-events: none;
  z-index: 15;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#game-banner.banner-hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-20px);
}

#banner-text {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.5px;
  color: var(--accent-gold);
}

#banner-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ==================== BALL IN HAND HINT ==================== */
#ball-in-hand-hint {
  position: absolute;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(16, 185, 129, 0.9);
  color: #064e3b;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 15;
  transition: all 0.3s;
}

#ball-in-hand-hint.hint-hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
}

.hint-badge {
  background: #064e3b;
  color: #10b981;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 800;
}

/* ==================== FINE AIM CONTROLS ==================== */
#fine-aim-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.fine-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  transition: all 0.15s;
}

.fine-btn:active {
  transform: scale(0.92);
  background: rgba(251, 191, 36, 0.2);
  border-color: var(--accent-gold);
}

/* ==================== POWER GAUGE ==================== */
#power-gauge-wrapper {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

.power-title {
  font-family: 'Outfit', sans-serif;
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--accent-gold);
}

#power-slider-track {
  width: 28px;
  height: 280px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 4px 10px rgba(0,0,0,0.6), 0 8px 25px rgba(0,0,0,0.5);
  cursor: pointer;
  touch-action: none;
}

#power-slider-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  background: linear-gradient(to top, #10b981 0%, #fbbf24 60%, #ef4444 100%);
  border-radius: 0 0 12px 12px;
  transition: height 0.05s ease-out;
}

#power-slider-handle {
  position: absolute;
  bottom: 0%;
  left: -2px;
  width: 28px;
  height: 6px;
  background: #fff;
  border-radius: 3px;
  box-shadow: 0 0 8px #fff;
  pointer-events: none;
}

.shoot-btn {
  padding: 8px 12px;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  border-radius: 10px;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  transition: all 0.15s;
}

.shoot-btn:active {
  transform: scale(0.95);
  background: #059669;
}

/* ==================== SPIN CONTROLLER WIDGET ==================== */
#spin-widget {
  position: absolute;
  bottom: 20px;
  right: 65px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.5);
  z-index: 10;
}

.spin-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text-muted);
}

#cueball-spin-pad {
  width: 54px;
  height: 54px;
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #cbd5e1 75%, #94a3b8 100%);
  border-radius: 50%;
  position: relative;
  cursor: crosshair;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4), inset 0 2px 4px rgba(255,255,255,0.8);
  border: 1px solid rgba(0,0,0,0.2);
  touch-action: none;
}

#spin-crosshair-x {
  position: absolute;
  top: 50%;
  left: 4px;
  right: 4px;
  height: 1px;
  background: rgba(0,0,0,0.15);
  pointer-events: none;
}

#spin-crosshair-y {
  position: absolute;
  left: 50%;
  top: 4px;
  bottom: 4px;
  width: 1px;
  background: rgba(0,0,0,0.15);
  pointer-events: none;
}

#spin-marker {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #ef4444;
  border: 2px solid #fff;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  pointer-events: none;
}

.spin-reset-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  padding: 2px 6px;
}

.spin-reset-btn:hover {
  color: #fff;
}

/* ==================== MODAL OVERLAYS ==================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 16px;
}

.modal.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  width: 100%;
  max-width: 480px;
  padding: 28px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.8);
  transform: scale(0.95);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal.active .modal-card {
  transform: scale(1);
}

.modal-header {
  text-align: center;
  margin-bottom: 22px;
}

.modal-logo {
  font-size: 44px;
  margin-bottom: 8px;
}

.modal-header h2 {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 24px;
  background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.mode-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}

.mode-card:hover, .mode-card.selected {
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.4);
  transform: translateY(-2px);
}

.mode-icon {
  font-size: 26px;
}

.mode-details h3 {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

.mode-details p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.mode-badge {
  position: absolute;
  top: 10px;
  right: 12px;
  background: var(--accent-gold);
  color: #78350f;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 10px;
}

#ai-difficulty-selector {
  margin-bottom: 20px;
  background: rgba(255,255,255,0.03);
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
}

#ai-difficulty-selector label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.diff-btn-group {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.diff-btn {
  padding: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.diff-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.modal-footer {
  display: flex;
  gap: 10px;
}

.btn-primary {
  flex: 1;
  padding: 14px;
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: #451a03;
  border: none;
  border-radius: 12px;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.35);
  transition: all 0.2s;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(245, 158, 11, 0.45);
}

.btn-secondary {
  flex: 1;
  padding: 14px;
  background: rgba(255,255,255,0.06);
  color: #fff;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

/* RULES MODAL */
.rules-card {
  max-width: 540px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.rules-body {
  overflow-y: auto;
  padding-right: 8px;
  margin-bottom: 20px;
}

.rules-body h4 {
  color: var(--accent-gold);
  font-size: 14px;
  margin-top: 14px;
  margin-bottom: 4px;
}

.rules-body h4:first-child {
  margin-top: 0;
}

.rules-body p {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

/* STATS */
.match-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 22px;
}

.stat-box {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}

.stat-num {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: var(--accent-gold);
}

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* RESPONSIVE */
@media (max-width: 768px) {
  #hud-header {
    height: 56px;
    padding: 0 10px;
  }
  .brand-sub, .logo-text {
    display: none;
  }
  .player-suit {
    display: none;
  }
  .player-card {
    padding: 4px 8px;
  }
  #table-wrapper {
    padding: 6px 54px 6px 6px;
  }
  #power-slider-track {
    width: 22px;
    height: 200px;
  }
  #spin-widget {
    bottom: 12px;
    right: 52px;
    transform: scale(0.85);
    transform-origin: bottom right;
  }
}
