/* =========================================
   Root: Responsive Variables
   ========================================= */
:root {
  /* Fonts */
  --font-base: clamp(0.75rem, 1.2vw, 1rem);

  /* Container */
  --container-padding: clamp(0.5rem, 1.5vw, 1.5rem);
  --container-radius: clamp(0.5rem, 1vw, 1rem);

  /* Cards */
  --card-width: clamp(35px, 6vw, 75px);
  --card-height: calc(var(--card-width) * 1.3);
  --card-radius: clamp(0.4rem, 0.8vw, 0.8rem);

  /* Buttons */
  --btn-padding-v: clamp(0.3rem, 0.8vw, 0.8rem);
  --btn-padding-h: clamp(0.6rem, 1.5vw, 1.5rem);
  --btn-radius: clamp(0.5rem, 1vw, 1rem);

  /* Chips */
  --chip-size: clamp(25px, 4vw, 45px);

  /* Spacing */
  --gap-xs: clamp(0.2rem, 0.4vw, 0.5rem);
  --gap-sm: clamp(0.3rem, 0.8vw, 1rem);
  --gap-md: clamp(0.5rem, 1.5vw, 1.5rem);
  --gap-lg: clamp(1rem, 2.5vw, 2rem);
}

/* General Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  overflow-x: hidden;
  overflow-y: hidden;
  background-size: cover;
  background-position: center center;
  padding: 0.5rem;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.game-container {
  background: rgba(0, 0, 0, 0.8);
  border-radius: clamp(10px, 2vw, 20px);
  padding: var(--container-padding);
  width: 100%;
  max-width: 900px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
  display: flex;
  flex-direction: column;
  
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.6),
    0 0 0 8px rgba(255, 255, 255, 0.05) inset;
  overflow-y: hidden;
  overflow-x: hidden;
  min-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

.game-container::before {
  content: none;
}

.header {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: var(--gap-xs);
  flex-shrink: 0;
  min-height: clamp(40px, 8vh, 60px);
}

.balance-and-sound {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  flex-wrap: wrap;
  justify-content: center;
}

.balance {
  display: flex;
  align-items: center;
  gap: var(--gap-xs);
  background: linear-gradient(145deg,
      rgba(255, 255, 255, 0.15),
      rgba(255, 255, 255, 0.05));
  padding: clamp(4px, 1vw, 8px) clamp(8px, 2vw, 15px);
  border-radius: 25px;
  font-size: clamp(0.7rem, 2vw, 1.1em);
  font-weight: bold;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3),
    inset 0 2px 5px rgba(255, 255, 255, 0.2);
}

.coin-icon {
  width: clamp(12px, 3vw, 18px);
  height: clamp(12px, 3vw, 18px);
  font-size: clamp(8px, 2vw, 12px);
}

.sound-toggle,
#leaderboard-toggle,
#stats-toggle,
.btn-ad-header {
  background: linear-gradient(145deg,
      rgba(255, 255, 255, 0.15),
      rgba(255, 255, 255, 0.05));
  border: none;
  border-radius: 50%;
  width: clamp(28px, 6vw, 38px);
  height: clamp(28px, 6vw, 38px);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  font-size: clamp(12px, 3vw, 18px);
  color: white;
  transition: background 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 10;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3),
    inset 0 2px 5px rgba(255, 255, 255, 0.2);
}

.btn-ad-header {
  border-radius: 25px;
  padding: 0 clamp(6px, 2vw, 12px);
  width: auto;
  min-width: clamp(50px, 12vw, 70px);
  font-size: clamp(8px, 2vw, 12px);
  font-weight: bold;
  background: linear-gradient(145deg, #e9851e, #c7665c);
  color: white;
  gap: 4px;
}

.sound-toggle:hover,
#leaderboard-toggle:hover,
#stats-toggle:hover,
.btn-ad-header:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.4),
    inset 0 2px 5px rgba(255, 255, 255, 0.3);
}

.sound-toggle:active,
#leaderboard-toggle:active,
#stats-toggle:active,
.btn-ad-header:active {
  transform: translateY(0);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4), inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.dealer-section,
.player-section {
  margin: var(--gap-xs) 0;
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-height: clamp(120px, 20vh, 180px);
  max-height: clamp(150px, 25vh, 220px);
  transition: opacity 0.5s ease-in-out;
}

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

.section-title {
  font-size: clamp(0.8rem, 2.5vw, 1em);
  margin-bottom: var(--gap-xs);
  text-align: center;
  flex-shrink: 0;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.4);
}

#dealer-cards-and-score {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
}

.cards-container {
  display: flex;
  justify-content: center;
  gap: clamp(1px, 0.5vw, 3px);
  margin: clamp(2px, 1vw, 5px) 0 clamp(5px, 2vw, 10px);
  min-height: clamp(80px, 15vh, 130px);
  max-height: clamp(100px, 18vh, 150px);
  align-items: flex-start;
  flex-wrap: wrap;
  flex-direction: row;
  flex-grow: 1;
  align-content: center;
  min-width: 0;
  position: relative;
  overflow: visible;
}

.score-bubble {
  background: linear-gradient(145deg, #3498db, #2980b9);
  color: white;
  border-radius: 50%;
  width: clamp(24px, 5vw, 30px);
  height: clamp(24px, 5vw, 30px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: clamp(10px, 2.5vw, 14px);
  border: 2px solid #3498db;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.5),
    inset 0 0 10px rgba(255, 255, 255, 0.1);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
  transition: opacity 0.5s ease-in-out;
  z-index: 5;
}

.dealer-section .score-bubble {
  position: absolute;
  top: 5px;
  right: 5px;
  width: clamp(28px, 6vw, 35px);
  height: clamp(28px, 6vw, 35px);
  font-size: clamp(12px, 3vw, 16px);
}

.player-hands-wrapper {
  display: flex;
  justify-content: center;
  gap: var(--gap-xs);
  flex-wrap: nowrap;
  min-height: clamp(100px, 18vh, 130px);
  max-height: clamp(120px, 22vh, 160px);
  flex-grow: 1;
  flex-direction: row;
  align-content: flex-start;
  overflow: hidden;
}

.player-hand {
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  text-align: center;
  flex-grow: 1;
  flex-basis: clamp(80px, 20vw, 120px);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  position: relative;
  min-height: clamp(90px, 16vh, 120px);
  max-height: clamp(110px, 20vh, 140px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}

.player-hand .score-bubble {
  position: absolute;
  top: 2px;
  right: 2px;
}

.player-hand.active-hand {
  border-color: #2ecc71;
  box-shadow: 0 0 15px rgba(46, 204, 113, 0.8), 0 8px 25px rgba(0, 0, 0, 0.6);
}

.hand-label {
  font-size: clamp(0.6rem, 1.8vw, 0.8em);
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.hand-status {
  font-size: clamp(0.6rem, 1.8vw, 0.8em);
  font-weight: bold;
  margin-top: 3px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.6);
  padding: 1px clamp(3px, 1vw, 8px);
  border-radius: 5px;
}

.hand-status.win {
  color: #2ecc71;
  z-index: 10;
}

.hand-status.lose {
  color: #e74c3c;
  z-index: 10;
}

.hand-status.push {
  color: #f39c12;
  z-index: 10;
}

.hand-status.hidden {
  opacity: 0;
  pointer-events: none;
}

.card {
  width: var(--card-width);
  height: var(--card-height);
  background: linear-gradient(145deg, #ffffff, #f0f0f0);
  border-radius: clamp(4px, 1vw, 8px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(2px, 1vw, 5px);
  color: black;
  font-weight: bold;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(0, 0, 0, 0.1) inset;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  flex-shrink: 1;
  min-width: clamp(25px, 6vw, 35px);
  font-size: clamp(8px, 2vw, 12px);
  position: relative;
  transform-style: preserve-3d;
  z-index: 1;
}

.card:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
}

.card.red {
  color: #e74c3c;
}

.card-back {
  background: linear-gradient(45deg, #3498db, #2980b9);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(12px, 3vw, 20px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
  backface-visibility: hidden;
}

.card-value {
  font-size: clamp(8px, 2.5vw, 14px);
  line-height: 1;
  text-shadow: 0.5px 0.5px 1px rgba(0, 0, 0, 0.1);
}

.card-suit {
  font-size: clamp(10px, 3vw, 18px);
  text-align: center;
  text-shadow: 0.5px 0.5px 1px rgba(0, 0, 0, 0.1);
}

.controls {
  display: flex;
  justify-content: center;
  gap: var(--gap-sm);
  margin: var(--gap-sm) 0;
  flex-wrap: wrap;
  flex-shrink: 0;
  min-height: clamp(60px, 12vh, 80px);
  max-height: clamp(80px, 15vh, 100px);
  align-items: flex-start;
  padding: 0 clamp(5px, 2vw, 10px);
  align-content: center;
}

.btn {
  padding: var(--btn-padding-v) var(--btn-padding-h);
  border: none;
  border-radius: var(--btn-radius);
  font-size: clamp(10px, 2.5vw, 16px);
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  min-width: clamp(70px, 18vw, 120px);
  max-width: clamp(120px, 25vw, 200px);
  flex-grow: 1;
  flex-basis: auto;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3),
    inset 0 2px 5px rgba(255, 255, 255, 0.2);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  position: relative;
  transform: translateY(0);
  display: flex;
  align-items: center;
  justify-content: center;
  height: clamp(35px, 8vh, 40px);
}

.btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

.btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

.btn-hit {
  background: linear-gradient(145deg, #e74c3c, #c0392b);
  color: white;
}

.btn-stand {
  background: linear-gradient(145deg, #f39c12, #e67e22);
  color: white;
}

.btn-deal {
  background: linear-gradient(145deg, #27ae60, #229954);
  color: white;
}

.btn-split {
  background: linear-gradient(145deg, #3498db, #2980b9);
  color: white;
}

.btn-double-down {
  background: linear-gradient(145deg, #8e44ad, #9b59b6);
  color: white;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.btn.hidden {
  display: none;
}

.betting-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2vw, 15px);
  margin: var(--gap-sm) 0;
  flex-shrink: 0;
  min-height: clamp(80px, 15vh, 120px);
  max-height: clamp(120px, 20vh, 160px);
}

.bet-controls {
  display: flex;
  gap: var(--gap-sm);
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.bet-btn {
  width: clamp(28px, 6vw, 40px);
  height: clamp(28px, 6vw, 40px);
  border: none;
  border-radius: 50%;
  background: linear-gradient(145deg, #3498db, #2980b9);
  color: white;
  font-size: clamp(12px, 3vw, 18px);
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3),
    inset 0 1px 3px rgba(255, 255, 255, 0.2);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.bet-btn:hover {
  background: linear-gradient(145deg, #2980b9, #3498db);
  transform: scale(1.08);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.4);
}

.bet-btn:active {
  transform: scale(1);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

.bet-amount {
  background: linear-gradient(145deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.1));
  border: none;
  color: white;
  padding: clamp(3px, 1vw, 7px) clamp(6px, 2vw, 10px);
  border-radius: 10px;
  text-align: center;
  font-size: clamp(9px, 2.5vw, 13px);
  width: clamp(50px, 12vw, 70px);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3);
}

.bet-chips-display {
  display: flex;
  justify-content: center;
  align-items: center;
  height: clamp(40px, 8vh, 60px);
  width: 100%;
  max-width: clamp(250px, 60vw, 400px);
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  padding: clamp(2px, 1vw, 5px) 0;
}

.bet-chip {
  border-radius: 50%;
  width: var(--chip-size);
  height: var(--chip-size);
  flex-shrink: 0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.3);
  transition: all 0.2s ease-out;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.5rem, 1.5vw, 0.8em);
  font-weight: bold;
  color: white;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  position: relative;
  transform: none;
}

.chip-10 {
  background: linear-gradient(145deg, #27ae60, #229954);
}

.chip-50 {
  background: linear-gradient(145deg, #3498db, #2980b9);
}

.chip-100 {
  background: linear-gradient(145deg, #f39c12, #e67e22);
}

.chip-500 {
  background: linear-gradient(145deg, #e74c3c, #c0392b);
}

.chip-1000 {
  background: linear-gradient(145deg, #9b59b6, #8e44ad);
}

.game-status {
  text-align: center;
  font-size: clamp(0.8rem, 2.5vw, 1em);
  font-weight: bold;
  margin: var(--gap-xs) 0;
  min-height: clamp(25px, 5vh, 35px);
  max-height: clamp(35px, 7vh, 45px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
}

.game-status.win {
  color: #2ecc71;
}

.game-status.lose {
  color: #e74c3c;
}

.game-status.push {
  color: #f39c12;
}

/* Animations */
@keyframes cardDeal {
  0% {
    transform: translate(-50%, -150px) rotate(180deg) scale(0.2);
    opacity: 0;
  }

  70% {
    transform: translate(0, 0) rotate(0deg) scale(1.1);
    opacity: 1;
  }

  100% {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
  }
}

@keyframes cardAppear {
  0% {
    transform: rotateY(90deg) scale(0.8);
    opacity: 0;
  }

  50% {
    transform: rotateY(0deg) scale(1.1);
    opacity: 1;
  }

  100% {
    transform: rotateY(0deg) scale(1);
    opacity: 1;
  }
}

@keyframes bustAnimation {
  0%,
  100% {
    transform: translateX(0) rotate(0);
    filter: brightness(1);
  }

  25% {
    transform: translateX(-5px) rotate(-2deg);
    filter: brightness(1.2);
  }

  75% {
    transform: translateX(5px) rotate(2deg);
    filter: brightness(1.2);
  }
}

@keyframes winLoseAnimation {
  0% {
    transform: scale(1);
    filter: brightness(1);
  }

  50% {
    transform: scale(1.05);
    filter: brightness(1.5);
  }

  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes flashGlow {
  0% {
    box-shadow: 0 0 0px rgba(46, 204, 113, 0);
  }

  50% {
    box-shadow: 0 0 20px 10px rgba(46, 204, 113, 0.8);
  }

  100% {
    box-shadow: 0 0 0px rgba(46, 204, 113, 0);
  }
}

@keyframes discardCard {
  0% {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
  }

  100% {
    transform: translate(200vw, -100vh) rotate(360deg) scale(0.2);
    opacity: 0;
  }
}

@keyframes chipFly {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.5);
  }

  20% {
    opacity: 1;
    transform: translate(0, -20px) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(calc(var(--target-x) - 50%),
        calc(var(--target-y) - 50%)) scale(0.8);
  }
}

.flying-chip {
  position: absolute;
  border-radius: 50%;
  width: clamp(30px, 6vw, 40px);
  height: clamp(30px, 6vw, 40px);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(0.5rem, 1.5vw, 0.7em);
  font-weight: bold;
  color: white;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
  animation: chipFly 1s ease-out forwards;
  z-index: 100;
  border: 2px solid rgba(255, 255, 255, 0.3);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.flying-chip.chip-10 {
  background: linear-gradient(145deg, #27ae60, #229954);
}

.flying-chip.chip-50 {
  background: linear-gradient(145deg, #3498db, #2980b9);
}

.flying-chip.chip-100 {
  background: linear-gradient(145deg, #f39c12, #e67e22);
}

.flying-chip.chip-500 {
  background: linear-gradient(145deg, #e74c3c, #c0392b);
}

.flying-chip.chip-1000 {
  background: linear-gradient(145deg, #9b59b6, #8e44ad);
}

.card.new-card {
  animation: cardDeal 0.6s cubic-bezier(0.68, -0.55, 0.27, 1.55) forwards;
}

.card.card-appear {
  animation: cardAppear 0.5s ease-out forwards;
}

.player-hand .cards-container .card.bust-animation,
.dealer-section .cards-container .card.bust-animation {
  animation: bustAnimation 0.6s ease-in-out 3;
  border-color: #e74c3c;
  box-shadow: 0 0 15px #e74c3c;
}

.player-hand .cards-container .card.blackjack-animation,
.player-hand .cards-container .card.score-21-animation {
  animation: winLoseAnimation 0.8s ease-in-out, flashGlow 1s infinite;
  box-shadow: 0 0 20px #2ecc71;
}

.player-hand .cards-container .card.win-animation {
  animation: winLoseAnimation 0.8s ease-in-out, flashGlow 1s infinite;
  box-shadow: 0 0 20px #2ecc71;
}

.player-hand .cards-container .card.lose-animation {
  animation: winLoseAnimation 0.8s ease-in-out;
  box-shadow: 0 0 20px #e74c3c;
}

.card.discarding-card {
  animation: discardCard 0.8s ease-in forwards;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  backdrop-filter: blur(5px);
  padding: 1rem;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: linear-gradient(145deg, #34495e, #2c3e50);
  padding: clamp(15px, 4vw, 25px);
  border-radius: 15px;
  text-align: center;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.6), inset 0 0 0 3px rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  max-width: none;
  width: clamp(280px, 70vw, 350px);
  max-height: 80vh;
  overflow-y: hidden;
  transform: translateY(-20px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.modal-overlay.show .modal-content {
  transform: translateY(0);
  opacity: 1;
}

.modal-content h2 {
  margin-bottom: clamp(15px, 3vw, 20px);
  font-size: clamp(1rem, 3vw, 1.4em);
  color: #ecf0f1;
  text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.6);
}

.modal-buttons {
  display: flex;
  justify-content: center;
  gap: clamp(10px, 3vw, 15px);
  flex-wrap: wrap;
}

.modal-btn {
  padding: clamp(8px, 2vw, 10px) clamp(15px, 4vw, 25px);
  border: none;
  border-radius: 10px;
  font-size: clamp(0.8rem, 2.5vw, 1em);
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3), inset 0 2px 5px rgba(255, 255, 255, 0.2);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  min-width: clamp(80px, 20vw, 120px);
}

.modal-btn-yes {
  background: linear-gradient(145deg, #2ecc71, #27ae60);
  color: white;
}

.modal-btn-no {
  background: linear-gradient(145deg, #e74c3c, #c0392b);
  color: white;
}

.modal-btn-close {
  background: linear-gradient(145deg, #34495e, #2c3e50);
  color: white;
}

.modal-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4), inset 0 2px 5px rgba(255, 255, 255, 0.3);
}

.modal-btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4), inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Stats Section Styles */
.stats-data {
  text-align: left;
  margin-bottom: clamp(15px, 3vw, 20px);
  font-size: clamp(0.9rem, 2.5vw, 1.1em);
  color: #ecf0f1;
  line-height: 1.6;
}

.stats-data p {
  display: flex;
  justify-content: space-between;
  margin-bottom: clamp(6px, 1.5vw, 8px);
}

.stats-data span:first-child {
  font-weight: normal;
  color: rgba(255, 255, 255, 0.8);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.stats-data span:last-child {
  font-weight: bold;
  color: #ecf0f1;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

/* Leaderboard Styles */
.icon-btn {
  width: clamp(32px, 6vw, 38px);
  height: clamp(32px, 6vw, 38px);
  background: var(--btn-bg);
  border-radius: 12px;
  font-size: clamp(16px, 3vw, 20px);
  line-height: clamp(32px, 6vw, 38px);
  text-align: center;
  cursor: pointer;
}

#lb-box {
  width: 90vw;
  max-width: clamp(350px, 80vw, 420px);
  max-height: 80vh;
  overflow-y: auto;
  padding: clamp(15px, 4vw, 20px) clamp(20px, 5vw, 24px);
  box-sizing: border-box;
  background: linear-gradient(145deg, #34495e, #2c3e50);
  border-radius: 14px;
  text-align: center;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.6), inset 0 0 0 3px rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

#lb-list {
  margin: clamp(10px, 2vw, 12px) 0;
  padding: 0;
  list-style: none;
  counter-reset: lb;
}

#lb-list li {
  counter-increment: lb;
  margin: clamp(3px, 1vw, 4px) 0;
  display: flex;
  justify-content: center;
  gap: 0.3em;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  font-size: clamp(0.8rem, 2vw, 1rem);
}

#lb-list li::before {
  content: counter(lb) '.';
  font-weight: 600;
}

.input {
  justify-content: center;
}

.bet-chips-display {
  overflow-x: hidden;
  padding: 0 clamp(3px, 1vw, 5px);
}

/* Very small screens */
@media (max-width: 320px) and (orientation: portrait) {
  .game-container {
    padding: 0.25rem;
    min-height: 99vh;
    max-height: 99vh;
  }

  .header {
    min-height: 30px;
    margin-bottom: 0.2rem;
  }

  .balance-and-sound {
    gap: 0.3rem;
  }

  .dealer-section,
  .player-section {
    margin: 0.2rem 0;
    min-height: 80px;
    max-height: 100px;
  }

  .cards-container {
    min-height: 60px;
    max-height: 75px;
    gap: 1px;
  }

  .player-hands-wrapper {
    min-height: 70px;
    max-height: 85px;
  }

  .player-hand {
    min-height: 65px;
    max-height: 80px;
    padding: 2px;
  }

  .controls {
    min-height: 40px;
    max-height: 55px;
    margin: 0.3rem 0;
    gap: 0.2rem;
    align-content: flex-end;
  }

  .betting-section {
    min-height: 60px;
    max-height: 75px;
    gap: 0.3rem;
  }

  .game-status {
    min-height: 18px;
    max-height: 25px;
    margin: 0.2rem 0;
  }
}

/* Mobile portrait adjustments */
@media (max-width: 480px) and (orientation: portrait) {
  :root {
    --card-width: clamp(26px, 14vw, 60px);
    --gap-xs: 1.5px;
    --gap-sm: 3px;
  }

  .cards-container {
    flex-wrap: wrap;
    overflow: visible;
    gap: var(--gap-xs);
    padding-bottom: 0;
  }

  .player-hands-wrapper:has(.player-hand:nth-child(2)) {
    --card-width: clamp(24px, 11vw, 55px);
    --card-height: calc(var(--card-width) * 1.25);
    --gap-xs: 1.5px;
  }
}

.game-status.error {
  color: #e54343;
}

/* Loading overlay */
#loading-screen {
  position: fixed;
  inset: 0;
  background: black;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  transition: opacity .4s ease;
}

.loading-bar {
  width: 70%;
  max-width: 400px;
  height: 22px;
  background: rgba(255,255,255,.24);
  border-radius: 12px;
  overflow: hidden;
}

#loading-progress {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg,#27ae60,#2ecc71);
  transition: width .25s ease;
}

#loading-text {
  margin-top: 12px;
  font-size: 1rem;
  color: #fff;
}

#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
/* ――― Модальное окно ――― */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0 0 0 / .65);
    z-index: 9999;
    overflow: hidden;          /* перестраховка: скролл внутри оверлея невозможен */
    overscroll-behavior: contain;
}

.modal-content {
    box-sizing: border-box;
    width: 340px;
    max-width: 92vw;
    padding: 24px 20px;
    background: #20232a;
    border-radius: 12px;
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    overflow: hidden;          /* исключаем внутренний скролл */
}

/* ――― Текстовые блоки ――― */
#fortune-wheel-title {
    margin: 0;
    font: 600 22px/1.3 Arial, sans-serif;
    text-align: center;
}

.fortune-wheel-info,
.fortune-wheel-result {
    min-height: 24px;
    margin: 0;
    font: 16px/1.4 Arial, sans-serif;
    text-align: center;
    width: 100%;
}

/* ――― Канвас ――― */
#fortune-wheel-canvas {
    width: 300px;
    height: 300px;
    display: block;
}

/* ――― Кнопки: ВСЕГДА в столбик ――― */
.modal-buttons {
    display: flex;
    flex-direction: column;    /* главное изменение: вертикальный стек */
    gap: 10px;
    width: 100%;
    min-height: 144px;         /* фикс. высота = 3 кнопки по ~44 px + зазоры
                                  → состав кнопок не влияет на размеры модалки */
}

.modal-btn,
.modal-btn-close {
    flex: 0 0 auto;
    width: 100%;
    padding: 10px 6px;
    font: 600 14px/1 Arial, sans-serif;
    color: #fff;
    background: #04a96d;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: transform .12s ease-in-out;
}
.modal-btn:hover     { transform: translateY(-2px); }
.modal-btn:disabled  { background: #555; cursor: default; transform: none; }

/* Альтернативные цвета */
.modal-btn-no       { background: #c0392b; }
.modal-btn-close    { background: #555; }

/* ――― Управление видимостью без изменения лэй‑аута ――― */
.hidden, .hidden-visibility {
    visibility: hidden;        /* место остаётся, ничего не скачет */
}
.collapse {                   /* если нужно полностью убрать элемент из потока */
    display: none !important;
}
/* ――― Мобильные экраны ≤ 420 px ――― */
@media (max-width:420px) {
    #fortune-wheel-canvas { width:240px; height:240px; }   /* меньше канвас */
    .modal-content { gap:12px; padding:20px 14px; }        /* экономим место */
}
/* уже существующие стили … */

/* ───────── 4. Адаптация: ≤ 420 px ───────── */
@media (max-width:420px) {
    .modal-content {
        width: 300px;
        padding: 20px 16px;
        gap: 12px;
    }
    #fortune-wheel-canvas {          /* меньше сам холст */
        width: 240px;
        height: 240px;
    }
    #fortune-wheel-title   { font-size: 20px; }
    .fortune-wheel-info,
    .fortune-wheel-result { font-size: 15px; min-height:20px; }
    .modal-buttons         { min-height: 128px; gap: 8px; }
    .modal-btn,
    .modal-btn-close       { padding: 8px 4px; font-size: 13px; }
}

/* ───────── 5. Крошечные экраны: ≤ 360 px ───────── */
@media (max-width:360px) {
    .modal-content { width: 280px; padding: 18px 12px; }
    #fortune-wheel-canvas { width: 200px; height: 200px; }
    #fortune-wheel-title  { font-size: 18px; }
}
/* ───────── Базовый центр ───────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;          /* центр по вертикали */
    justify-content: center;      /* центр по горизонтали */
    background: rgba(0 0 0 / .65);
    z-index: 9999;
    overflow: hidden;
    overscroll-behavior: contain;
}

/* ───────── Контент ───────── */
.modal-content {
    box-sizing: border-box;
    width: 340px;
    max-width: 92vw;
    max-height: calc(100vh - 32px); /* запас сверху/снизу, чтобы не упираться */
    padding: 24px 20px;
    background: #20232a;
    border-radius: 12px;
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    overflow-y: auto;            /* появится ТОЛЬКО если реально не хватает высоты */
    overscroll-behavior: contain;
}

/* ───────── Канвас и кнопки (как раньше) ───────── */
#fortune-wheel-canvas { width: 300px; height: 300px; }

/* … кнопки в столбик, стили modal‑btn и т.д. … */

/* ───────── Адаптация: ≤ 420 px ───────── */
@media (max-width: 420px) {
    .modal-content {
        width: 300px;
        padding: 20px 16px;
        gap: 12px;
    }
    #fortune-wheel-canvas { width: 240px; height: 240px; }
    .modal-buttons       { min-height: 128px; gap: 8px; }
}

/* ───────── Адаптация по НИЗКОЙ высоте ───────── */
@media (max-height: 650px) {
    .modal-content {
        width: 300px;
        padding: 18px 14px;
        gap: 10px;
    }
    #fortune-wheel-canvas { width: 220px; height: 220px; }
}

/* ───────── Мини‑экраны ≤ 360 px ───────── */
@media (max-width: 360px) {
    .modal-content { width: 280px; }
    #fortune-wheel-canvas { width: 200px; height: 200px; }
}
/* ────────────────────────────────────────────────
   Экран по высоте ≤ 500 px  (пример: 344 × 450)
   ──────────────────────────────────────────────── */
@media (max-height: 500px) {

    /* 1.  Контент начинается сверху, скролл разрешён */
    body {
        align-items: flex-start;      /* больше не центрируем */
        overflow-y: auto;             /* даём прокрутиться вниз */
        padding-top: 0.25rem;         /* лёгкий отступ, чтобы не упиралось */
    }

    /* 2.  Контейнер растягивается по содержимому, а не держит 95 vh */
    .game-container {
        min-height: auto;
        max-height: none;
        height: auto;                 /* снимаем 95 vh */
    }

    /* 4.  Управляем нижними кнопками, чтобы они не «уехали» */
    .controls {
        margin-bottom: 0.25rem;
        min-height: 50px;             /* немного меньше */
        max-height: 60px;
    }
}

/* Anti-select & anti-contextmenu */
html,
body,
.game-container,
.game-container * {
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -moz-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;

}

.disable-select,
.game-container,
.player-section,
.dealer-section,
.cards-container,
.player-hand,
.bet-chip,
.modal-content {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;

}