* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --felt: #0d5c2e;
  --felt-dark: #084422;
  --gold: #d4af37;
  --gold-light: #f4e4a6;
  --card-white: #fefefe;
  --card-red: #c41e3a;
  --shadow: rgba(0, 0, 0, 0.4);
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Source Sans 3', sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  color: #fff;
  padding: 1rem;
}

.table {
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  border: 8px solid var(--gold);
  border-radius: 24px;
  padding: 1.5rem;
  max-width: 680px;
  width: 100%;
  box-shadow: 0 0 0 4px var(--felt-dark), 0 20px 60px var(--shadow), inset 0 0 80px rgba(0, 0, 0, 0.3);
}

.header {
  text-align: center;
  margin-bottom: 1.5rem;
  position: relative;
}

.header h1 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  color: var(--gold-light);
  text-shadow: 2px 2px 4px var(--shadow);
  letter-spacing: 0.1em;
}

.subtitle {
  font-size: clamp(0.8rem, 2.5vw, 0.95rem);
  opacity: 0.9;
  margin-top: 0.25rem;
}

.header-actions {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.deck-count {
  font-size: 0.75rem;
  opacity: 0.7;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.setting label {
  margin-right: 0.35rem;
}

.setting select {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background: rgba(255,255,255,0.1);
  color: var(--gold-light);
  border: 1px solid var(--gold);
}

.table-limits {
  font-size: 0.85rem;
  opacity: 0.8;
}

.side-bets {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.side-bet {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.side-bet input[type="number"] {
  width: 50px;
  padding: 0.2rem;
  border-radius: 4px;
  background: rgba(255,255,255,0.1);
  color: var(--gold-light);
  border: 1px solid var(--gold);
}

.chip-stack {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chip-stack-visual {
  display: flex;
  gap: -2px;
}

.chip-piece {
  width: 24px;
  height: 20px;
  border-radius: 2px;
  margin-left: -8px;
  border: 1px solid rgba(0,0,0,0.3);
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.chip-piece:first-child {
  margin-left: 0;
}

.chip-piece.red { background: #c41e3a; }
.chip-piece.blue { background: #2563eb; }
.chip-piece.green { background: #16a34a; }
.chip-piece.black { background: #1a1a1a; }
.chip-piece.gold { background: #d4af37; }

#confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
}

.confetti {
  position: absolute;
  top: 0;
  width: 10px;
  height: 10px;
  animation: confettiFall 2s ease-out forwards;
}

@keyframes confettiFall {
  to {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

body.light-theme {
  background: linear-gradient(135deg, #e8f4f8 0%, #d0e8f0 50%, #b8dce8 100%);
}

body.light-theme .table {
  background: radial-gradient(ellipse at center, #1a7d4a 0%, #0d5c2e 100%);
}

body.light-theme .chip-piece.red { background: #c41e3a; }
body.light-theme .chip-piece.blue { background: #2563eb; }
body.light-theme .chip-piece.green { background: #16a34a; }
body.light-theme .chip-piece.black { background: #1a1a1a; }
body.light-theme .chip-piece.gold { background: #d4af37; }

.panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
}

.panel-backdrop.open {
  display: block;
}

.rules-panel,
.stats-panel {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--felt-dark);
  border: 3px solid var(--gold);
  border-radius: 12px;
  padding: 1.5rem;
  z-index: 100;
  max-width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.rules-panel.open,
.stats-panel.open,
.history-panel.open,
.achievements-panel.open,
.cashout-panel.open {
  display: block;
}

.cashout-panel {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--felt-dark);
  border: 3px solid var(--gold);
  border-radius: 12px;
  padding: 1.5rem;
  z-index: 100;
  max-width: 90%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.cashout-panel h3 {
  margin-bottom: 1rem;
  color: var(--gold-light);
}

.cashout-summary {
  margin-bottom: 1.5rem;
  line-height: 1.8;
}

.cashout-summary p {
  margin: 0.25rem 0;
}

.cashout-result.profit {
  color: #4ade80;
}

.cashout-result.loss {
  color: #f87171;
}

.cashout-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.history-panel,
.achievements-panel {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--felt-dark);
  border: 3px solid var(--gold);
  border-radius: 12px;
  padding: 1.5rem;
  z-index: 100;
  max-width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.history-panel h3,
.achievements-panel h3 {
  margin-bottom: 1rem;
  color: var(--gold-light);
}

#history-list {
  list-style: none;
  margin-bottom: 1rem;
  max-height: 200px;
  overflow-y: auto;
}

#history-list li {
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 0.9rem;
}

.achievement {
  padding: 0.5rem;
  border-radius: 8px;
  text-align: center;
  background: rgba(0,0,0,0.2);
  font-size: 0.8rem;
}

.achievement.unlocked {
  border: 2px solid var(--gold);
  color: var(--gold-light);
}

.achievement.locked {
  opacity: 0.5;
}

.rules-panel h3,
.stats-panel h3 {
  margin-bottom: 1rem;
  color: var(--gold-light);
}

.rules-panel ul {
  margin: 0.5rem 0 1rem 1.25rem;
  line-height: 1.5;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

#achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.btn-ghost {
  background: transparent;
  color: var(--gold-light);
  border: 1px solid var(--gold);
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.hand {
  min-height: 100px;
}

.hand h2 {
  font-size: clamp(0.9rem, 2.5vw, 1rem);
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--gold-light);
}

.score {
  font-weight: 400;
  opacity: 0.9;
  margin-left: 0.5rem;
}

.cards {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  min-height: 80px;
}

.player-hands {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.player-hand-slot {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.player-hand-slot.active {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
  border-radius: 8px;
  padding: 4px;
}

.hand-bet {
  font-size: 0.75rem;
  opacity: 0.8;
}

.card {
  width: clamp(56px, 12vw, 72px);
  height: clamp(78px, 16vw, 100px);
  background: var(--card-white);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  box-shadow: 0 4px 12px var(--shadow);
  transition: transform 0.2s ease;
  position: relative;
  animation: cardDeal 0.3s ease-out;
}

@keyframes cardDeal {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.card.flip {
  animation: cardFlip 0.4s ease-out;
}

@keyframes cardFlip {
  0% { transform: rotateY(0deg); }
  50% { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}

.card:hover {
  transform: translateY(-2px);
}

.card.red {
  color: var(--card-red);
}

.card.black {
  color: #1a1a1a;
}

.card-back {
  background: linear-gradient(135deg, #1e3a5f 0%, #2d5a87 100%);
  color: transparent;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.card-back::before {
  content: '♠';
  position: absolute;
  font-size: 1.5rem;
  opacity: 0.3;
  color: white;
}

.strategy-hint {
  font-size: 0.85rem;
  text-align: center;
  margin-bottom: 0.5rem;
  color: rgba(255, 255, 255, 0.7);
  font-style: italic;
  min-height: 1.25rem;
}

.message {
  text-align: center;
  font-size: clamp(1rem, 3vw, 1.25rem);
  font-weight: 600;
  min-height: 1.5rem;
  margin-bottom: 0.25rem;
  color: var(--gold-light);
}

.message.win {
  color: #4ade80;
  animation: pulse 0.5s ease;
}

.message.lose {
  color: #f87171;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.win-amount {
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: #4ade80;
  margin-bottom: 1rem;
  min-height: 1.25rem;
}

.win-amount.lose {
  color: #f87171;
}

.betting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.bet-label {
  font-weight: 600;
  opacity: 0.9;
}

.bet-buttons {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.btn-bet {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.15);
  color: var(--gold-light);
  border: 2px solid var(--gold);
}

.btn-bet:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.25);
}

.btn-bet.selected {
  background: var(--gold);
  color: #1a1a1a;
}

.current-bet {
  font-weight: 600;
  color: var(--gold-light);
  min-width: 2.5rem;
}

.controls {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  padding: 0.5rem 1rem;
  font-size: clamp(0.85rem, 2vw, 1rem);
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--gold);
  color: #1a1a1a;
}

.btn-primary:not(:disabled):hover {
  background: var(--gold-light);
}

#hit-btn, #stand-btn, #double-btn, #split-btn, #insurance-btn, #surrender-btn {
  background: #fff;
  color: #1a1a1a;
}

#hit-btn:not(:disabled):hover,
#stand-btn:not(:disabled):hover,
#double-btn:not(:disabled):hover,
#split-btn:not(:disabled):hover,
#insurance-btn:not(:disabled):hover,
#surrender-btn:not(:disabled):hover {
  background: #f0f0f0;
}

.footer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.chips {
  font-size: 1rem;
}

.chip-label {
  opacity: 0.8;
}

.chip-count {
  font-weight: 600;
  color: var(--gold-light);
  margin-left: 0.5rem;
}

.chip-count.animate-up {
  animation: chipUp 0.5s ease;
}

.chip-count.animate-down {
  animation: chipDown 0.5s ease;
}

@keyframes chipUp {
  0% { color: #4ade80; transform: scale(1.2); }
  100% { color: var(--gold-light); transform: scale(1); }
}

@keyframes chipDown {
  0% { color: #f87171; transform: scale(1.2); }
  100% { color: var(--gold-light); transform: scale(1); }
}

@media (max-width: 480px) {
  .table {
    padding: 1rem;
  }

  .controls {
    gap: 0.35rem;
  }

  .btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
  }

  .card {
    width: 52px;
    height: 72px;
    font-size: 0.95rem;
  }
}
