/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --bg-dark:          #0d1a2e;
  --bg-mid:           #1e3a5f;
  --bg-light:         #0f1f38;
  --text-primary:     #e2e8f0;
  --text-secondary:   #64748b;
  --text-muted:       #475569;
  --accent-player:    #38bdf8;
  --accent-bot:       #f87171;
  --accent-green:     #4ade80;
  --accent-gold:      #fbbf24;
  --accent-red:       #f87171;
  --font-game:        'Baloo 2', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  --radius-sm:        6px;
  --radius-md:        12px;
  --radius-lg:        20px;
}

/* ============================================================
   KEYFRAME ANIMATIONS
   ============================================================ */

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

@keyframes pulse-glow-green {
  0%, 100% { box-shadow: 0 0 16px 4px rgba(74, 222, 128, 0.3); }
  50%       { box-shadow: 0 0 32px 10px rgba(74, 222, 128, 0.6); }
}

@keyframes win-glow {
  0%, 100% {
    text-shadow: 0 0 12px rgba(251, 191, 36, 0.5), 0 0 30px rgba(251, 191, 36, 0.3);
  }
  50% {
    text-shadow: 0 0 24px rgba(251, 191, 36, 0.9), 0 0 60px rgba(251, 191, 36, 0.5), 0 0 80px rgba(251, 191, 36, 0.2);
  }
}

@keyframes lose-glow {
  0%, 100% {
    text-shadow: 0 0 12px rgba(248, 113, 113, 0.4), 0 0 24px rgba(248, 113, 113, 0.2);
  }
  50% {
    text-shadow: 0 0 24px rgba(248, 113, 113, 0.8), 0 0 50px rgba(248, 113, 113, 0.4);
  }
}

@keyframes crown-bob {
  0%, 100% { transform: translateY(0px) rotate(-5deg); }
  50%       { transform: translateY(-8px) rotate(5deg); }
}

@keyframes emoji-pop {
  0%   { transform: scale(0); opacity: 0; }
  50%  { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes emoji-fade {
  0%   { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.6) translateY(-8px); }
}

@keyframes confetti-fall-1 {
  0%   { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
  100% { transform: translateY(120vh) rotate(720deg); opacity: 0; }
}

@keyframes confetti-fall-2 {
  0%   { transform: translateY(-20px) rotate(0deg) translateX(0);     opacity: 1; }
  50%  { transform: translateY(60vh)  rotate(360deg) translateX(40px); opacity: 0.8; }
  100% { transform: translateY(120vh) rotate(900deg) translateX(-20px); opacity: 0; }
}

@keyframes confetti-fall-3 {
  0%   { transform: translateY(-20px) rotate(0deg) scaleX(1);    opacity: 1; }
  40%  { transform: translateY(50vh)  rotate(270deg) scaleX(-1); opacity: 0.9; }
  100% { transform: translateY(120vh) rotate(720deg) scaleX(1);  opacity: 0; }
}

@keyframes confetti-fall-4 {
  0%   { transform: translateY(-20px) rotate(0deg);    opacity: 1; }
  30%  { transform: translateY(30vh)  rotate(200deg);  opacity: 1; }
  70%  { transform: translateY(80vh)  rotate(560deg);  opacity: 0.5; }
  100% { transform: translateY(120vh) rotate(1080deg); opacity: 0; }
}

@keyframes btn-press {
  0%   { transform: scale(1); }
  50%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* ============================================================
   BASE STYLES
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: #000;
  font-family: var(--font-game);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Portrait viewport — clamp to ~9:19.5 aspect ratio, black bars on wide screens */
#app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: calc(100dvh * (9 / 19.5));
  margin: 0 auto;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

#pixi-container {
  width: 100%;
  height: 100%;
}

#overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  font-family: var(--font-game);
}

#overlay > * {
  pointer-events: auto;
}

/* HUD elements are display-only — let input pass through to canvas */
.hud-bar,
.hud-profile-center,
.hud-score-right {
  pointer-events: none;
}

/* ============================================================
   BUBBLY BUTTON SYSTEM
   ============================================================ */

/* Reset */
.btn-bubbly {
  all: unset;
  display: inline-flex;
  cursor: pointer;
  border-radius: var(--radius-md);
  padding: 3px;
  /* Default: green */
  background: linear-gradient(180deg, #86efac 0%, #15803d 100%);
  drop-shadow: 0 6px 16px rgba(74, 222, 128, 0.5);
  filter: drop-shadow(0 6px 16px rgba(74, 222, 128, 0.5));
  transition: filter 0.15s ease, transform 0.1s ease;
  position: relative;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-bubbly:active {
  animation: btn-press 0.15s ease;
}

.btn-inner-stroke {
  display: flex;
  border-radius: calc(var(--radius-md) - 1px);
  padding: 2px;
  background: linear-gradient(180deg, rgba(255,255,255,0.25) 0%, rgba(0,0,0,0.15) 100%);
  width: 100%;
}

.btn-body {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius-md) - 3px);
  padding: clamp(8px, 1.5vw, 12px) clamp(18px, 3vw, 28px);
  width: 100%;
  position: relative;
  overflow: hidden;
  /* Default: green */
  background: linear-gradient(180deg, #4ade80 0%, #22c55e 50%, #16a34a 100%);
  box-shadow:
    inset 0  2px 4px  rgba(255,255,255,0.45),
    inset 0 -3px 6px  rgba(0,0,0,0.2),
    inset  2px 0 4px  rgba(255,255,255,0.1),
    inset -2px 0 4px  rgba(0,0,0,0.05);
}

/* Specular highlight */
.btn-body::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 60%;
  height: 55%;
  border-radius: calc(var(--radius-md) - 3px) 0 60% 0;
  background: radial-gradient(ellipse at 30% 30%, rgba(255,255,255,0.45) 0%, transparent 70%);
  pointer-events: none;
}

/* Ambient glow */
.btn-body::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 60%;
  height: 50%;
  border-radius: 0 0 calc(var(--radius-md) - 3px) 0;
  background: radial-gradient(ellipse at 70% 80%, rgba(74,222,128,0.25) 0%, transparent 70%);
  pointer-events: none;
}

.btn-text {
  position: relative;
  z-index: 1;
  font-family: var(--font-game);
  font-weight: 800;
  font-size: clamp(13px, 2vw, 16px);
  letter-spacing: 0.04em;
  color: #fff;
  -webkit-text-stroke: 1px rgba(0,0,0,0.3);
  paint-order: stroke fill;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4), 0 0 8px rgba(0,0,0,0.15);
  white-space: nowrap;
}

/* ---- Color Variants ---- */

/* Green (default already above) */
.btn-green {
  background: linear-gradient(180deg, #86efac 0%, #15803d 100%);
  filter: drop-shadow(0 6px 16px rgba(74,222,128,0.5));
}
.btn-green .btn-body {
  background: linear-gradient(180deg, #4ade80 0%, #22c55e 50%, #16a34a 100%);
}
.btn-green .btn-body::after {
  background: radial-gradient(ellipse at 70% 80%, rgba(74,222,128,0.25) 0%, transparent 70%);
}

/* Gold */
.btn-gold {
  background: linear-gradient(180deg, #fde68a 0%, #b45309 100%);
  filter: drop-shadow(0 6px 16px rgba(251,191,36,0.5));
}
.btn-gold .btn-body {
  background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 50%, #d97706 100%);
}
.btn-gold .btn-body::after {
  background: radial-gradient(ellipse at 70% 80%, rgba(251,191,36,0.25) 0%, transparent 70%);
}

/* Red */
.btn-red {
  background: linear-gradient(180deg, #fca5a5 0%, #991b1b 100%);
  filter: drop-shadow(0 6px 16px rgba(248,113,113,0.5));
}
.btn-red .btn-body {
  background: linear-gradient(180deg, #f87171 0%, #ef4444 50%, #dc2626 100%);
}
.btn-red .btn-body::after {
  background: radial-gradient(ellipse at 70% 80%, rgba(248,113,113,0.25) 0%, transparent 70%);
}

/* Blue */
.btn-blue {
  background: linear-gradient(180deg, #7dd3fc 0%, #0369a1 100%);
  filter: drop-shadow(0 6px 16px rgba(56,189,248,0.5));
}
.btn-blue .btn-body {
  background: linear-gradient(180deg, #38bdf8 0%, #0ea5e9 50%, #0284c7 100%);
}
.btn-blue .btn-body::after {
  background: radial-gradient(ellipse at 70% 80%, rgba(56,189,248,0.25) 0%, transparent 70%);
}

/* ---- CTA pulse ---- */
.btn-cta {
  animation: pulse-glow-green 2.4s ease-in-out infinite;
}
.btn-gold.btn-cta {
  animation: none;
}

/* ---- Compact ---- */
.btn-compact .btn-body {
  padding: clamp(6px, 1vw, 8px) clamp(12px, 2vw, 18px);
}
.btn-compact .btn-text {
  font-size: clamp(11px, 1.5vw, 13px);
}

/* ---- Full width ---- */
.btn-full {
  width: 100%;
}
.btn-full .btn-inner-stroke,
.btn-full .btn-body {
  width: 100%;
}

/* ---- Ghost ---- */
.btn-ghost {
  background: transparent;
  filter: none;
  border: 2px solid rgba(255,255,255,0.2);
  padding: 0;
}
.btn-ghost .btn-inner-stroke {
  background: transparent;
  padding: 0;
}
.btn-ghost .btn-body {
  background: rgba(255,255,255,0.06);
  box-shadow: none;
  padding: 10px 24px;
}
.btn-ghost .btn-body::before,
.btn-ghost .btn-body::after {
  display: none;
}
.btn-ghost:hover .btn-body {
  background: rgba(255,255,255,0.12);
}
.btn-ghost .btn-text {
  color: var(--text-primary);
  -webkit-text-stroke: 0;
  text-shadow: none;
}

/* ============================================================
   AVATAR CLASSES
   ============================================================ */

.avatar {
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 2px solid rgba(255,255,255,0.15);
}

.avatar-sm {
  width: clamp(48px, 12vmin, 96px);
  height: clamp(48px, 12vmin, 96px);
}

.avatar-lg {
  width: 80px;
  height: 80px;
}

.avatar-winner {
  width: 72px;
  height: 72px;
  border: 3px solid var(--accent-gold);
  box-shadow: 0 0 0 2px rgba(251,191,36,0.3), 0 0 20px rgba(251,191,36,0.4);
}

/* ============================================================
   MENU SCREEN
   ============================================================ */

.menu-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: linear-gradient(160deg, var(--bg-light) 0%, var(--bg-mid) 50%, var(--bg-dark) 100%);
  transition: opacity 0.4s ease;
  overflow: hidden;
}

/* Decorative background blurs */
.menu-glow-1 {
  position: absolute;
  top: -120px;
  left: -100px;
  width: 480px;
  height: 480px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56,189,248,0.18) 0%, transparent 70%);
  pointer-events: none;
  animation: float 6s ease-in-out infinite;
}

.menu-glow-2 {
  position: absolute;
  bottom: -100px;
  right: -80px;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(251,191,36,0.14) 0%, transparent 70%);
  pointer-events: none;
  animation: float 8s ease-in-out infinite reverse;
}

.game-title {
  font-family: var(--font-game);
  font-size: 52px;
  font-weight: 900;
  color: var(--text-primary);
  margin: 0 0 8px;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-shadow: 0 2px 16px rgba(56,189,248,0.35), 0 1px 0 rgba(0,0,0,0.5);
  position: relative;
  z-index: 1;
}

.game-subtitle {
  font-family: var(--font-game);
  font-size: 16px;
  color: var(--text-secondary);
  margin: 0 0 48px;
  letter-spacing: 2px;
  position: relative;
  z-index: 1;
}

.settings-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
}

/* ============================================================
   HUD
   ============================================================ */

/* Pause button — top-left with comfortable margin */
.hud-pause-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 25;
}

.hud-bar {
  position: absolute;
  left: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 16px;
  z-index: 20;
  /* relative so children can be absolutely centered */
  display: block;
}

.hud-bar-top {
  top: 0;
}

.hud-bar-bottom {
  bottom: 0;
}

/* Profile: absolutely centered horizontally within the bar */
.hud-profile-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.hud-name {
  font-family: var(--font-game);
  font-size: clamp(12px, 2vw, 18px);
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.hud-avatar-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Score: right-aligned within the bar */
.hud-score-right {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-game);
}

.score-num {
  font-size: clamp(22px, 4.5vw, 40px);
  font-weight: 900;
  color: var(--text-primary);
  line-height: 1;
}

.score-den {
  font-size: clamp(12px, 2.5vw, 20px);
  color: var(--text-muted);
}

.piece-dot {
  width: clamp(8px, 1.5vw, 14px);
  height: clamp(8px, 1.5vw, 14px);
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.25);
  display: inline-block;
  margin-left: 4px;
}


/* ============================================================
   EMOJI BUBBLE
   ============================================================ */

.emoji-bubble {
  position: absolute;
  top: -8px;
  right: -8px;
  font-size: clamp(16px, 3vw, 24px);
  pointer-events: none;
  z-index: 30;
  background: rgba(0,0,0,0.6);
  border-radius: 12px;
  padding: 2px 6px;
  border: 1px solid rgba(255,255,255,0.15);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: emoji-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.emoji-bubble.fading {
  animation: emoji-fade 0.5s ease forwards;
}

/* ============================================================
   TURN BANNER
   ============================================================ */

.turn-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 70%;
  transform: translate(-50%, -50%);
  font-family: var(--font-game);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 3px;
  text-align: center;
  background: linear-gradient(90deg, transparent 0%, rgba(13, 26, 46, 0.6) 15%, rgba(13, 26, 46, 0.6) 85%, transparent 100%);
  border-top: 2px solid rgba(255,255,255,0.15);
  border-bottom: 2px solid rgba(255,255,255,0.15);
  border-left: none;
  border-right: none;
  padding: 14px 0;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 25;
}

.turn-banner.visible {
  opacity: 1;
}


.toast.visible {
  opacity: 1;
}

/* ============================================================
   SKILL TOAST
   ============================================================ */

.skill-toast {
  position: absolute;
  bottom: 24px;
  right: 24px;
  font-family: var(--font-game);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(13, 26, 46, 0.85);
  border: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 25;
}

.skill-toast.visible {
  opacity: 1;
}

/* ============================================================
   PAUSE MODAL
   ============================================================ */

.pause-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 40;
}

.pause-modal {
  background: linear-gradient(160deg, var(--bg-light) 0%, var(--bg-mid) 100%);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.05);
}

.pause-modal h2 {
  font-family: var(--font-game);
  font-size: 28px;
  font-weight: 900;
  color: var(--text-primary);
  margin: 0 0 8px;
  letter-spacing: 2px;
}

/* ============================================================
   GAME OVER SCREEN
   ============================================================ */

.gameover-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: linear-gradient(160deg, var(--bg-dark) 0%, var(--bg-mid) 60%, var(--bg-dark) 100%);
  transition: opacity 0.4s ease;
  overflow: hidden;
  z-index: 35;
}

.result-text {
  font-family: var(--font-game);
  font-size: 56px;
  font-weight: 900;
  letter-spacing: 3px;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.result-text.win {
  color: var(--accent-gold);
  animation: win-glow 2s ease-in-out infinite;
}

.result-text.lose {
  color: var(--accent-bot);
  animation: lose-glow 2s ease-in-out infinite;
}

.winner-avatar-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.crown {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 28px;
  animation: crown-bob 1.8s ease-in-out infinite;
  filter: drop-shadow(0 2px 8px rgba(251,191,36,0.7));
}

.score-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  padding: 16px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.score-card .final-score {
  font-family: var(--font-game);
  font-size: 22px;
  color: var(--text-secondary);
}

.queen-bonus {
  font-family: var(--font-game);
  font-size: 15px;
  color: var(--accent-gold);
  letter-spacing: 1px;
  opacity: 0.85;
}

/* Confetti particles */
.confetti {
  position: absolute;
  top: 0;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  pointer-events: none;
  opacity: 0;
}

.confetti:nth-child(4n+1) {
  animation: confetti-fall-1 2.5s ease-in forwards;
}
.confetti:nth-child(4n+2) {
  animation: confetti-fall-2 3s ease-in forwards;
}
.confetti:nth-child(4n+3) {
  animation: confetti-fall-3 2.8s ease-in forwards;
}
.confetti:nth-child(4n+4) {
  animation: confetti-fall-4 3.2s ease-in forwards;
}

/* ============================================================
   DEBUG PANEL  (preserved exactly)
   ============================================================ */

.debug-panel {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: rgba(20, 20, 30, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 180px;
    font-size: 13px;
    color: #ccc;
}

.debug-panel .debug-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
    margin-bottom: 4px;
}

.debug-panel label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.debug-panel input[type="number"] {
    width: 64px;
    padding: 4px 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: #eee;
    font-size: 13px;
    text-align: right;
}

.debug-panel button {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: #ddd;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}

.debug-panel button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.debug-panel #dbg-fire {
    background: rgba(68, 136, 204, 0.3);
    border-color: rgba(68, 136, 204, 0.5);
    color: #88bbee;
}

.debug-panel #dbg-fire:hover {
    background: rgba(68, 136, 204, 0.5);
}

.debug-panel hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 4px 0;
}
