:root {
  --felt-green: #0a5534;
  --felt-dark: #063821;
  --felt-light: #0d6b47;
  --felt-border: #052a1c;
  --card-white: #ffffff;
  --card-red: #d40000;
  --card-black: #1a1a1a;
  --gold: #ffd700;
  --silver: #c0c0c0;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  background-attachment: fixed;
  color: #fff;
  position: relative;
}

/* Animated background particles */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: 
    radial-gradient(circle at 20% 30%, rgba(255, 215, 0, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(255, 215, 0, 0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.table-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  z-index: 1;
}

.felt {
  width: min(1200px, 98vw);
  max-width: 1200px;
  border-radius: 30px;
  padding: 40px 30px;
  background: 
    repeating-linear-gradient(
      45deg,
      var(--felt-green) 0px,
      var(--felt-dark) 2px,
      var(--felt-green) 4px
    ),
    linear-gradient(135deg, var(--felt-light) 0%, var(--felt-green) 100%);
  border: 4px solid var(--felt-border);
  box-shadow: 
    0 40px 100px rgba(0, 0, 0, 0.6) inset,
    0 0 0 2px rgba(255, 255, 255, 0.1),
    0 20px 60px rgba(0, 0, 0, 0.5);
  position: relative;
  overflow: hidden;
}

.felt::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 50% 50%, transparent 60%, rgba(0, 0, 0, 0.2) 100%);
  pointer-events: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 30px;
  position: relative;
  z-index: 2;
}

.topbar h1 {
  margin: 0;
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 3px;
  text-align: center;
  flex: 1;
  color: var(--gold);
  text-shadow: 
    0 0 10px rgba(255, 215, 0, 0.5),
    0 2px 4px rgba(0, 0, 0, 0.8),
    2px 2px 0px rgba(0, 0, 0, 0.9);
  text-transform: uppercase;
  font-family: 'Georgia', serif;
}

.status {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 10px;
  min-height: 28px;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
  width: 100%;
}

.area {
  padding: 25px 20px;
  border-radius: 20px;
  margin: 20px 0;
  text-align: center;
  position: relative;
  background: rgba(0, 0, 0, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(5px);
}

.area h2 {
  text-align: center;
  margin: 0 0 20px 0;
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
  letter-spacing: 1px;
}

.dealer {
  min-height: 200px;
  margin-bottom: 30px;
}

.player {
  min-height: 240px;
  margin-top: 20px;
}

.cards {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  min-height: 150px;
  position: relative;
  padding: 10px;
}

/* Deck Cards on Sides */
.deck-left, .deck-right {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 1;
  pointer-events: none;
}

.deck-left {
  left: -130px;
  align-items: flex-end;
}

.deck-right {
  right: -130px;
  align-items: flex-start;
}

@media (min-width: 1400px) {
  .deck-left {
    left: -150px;
  }
  .deck-right {
    right: -150px;
  }
}

.deck-card {
  width: 75px;
  height: 105px;
  background: repeating-linear-gradient(
    45deg,
    #1a237e 0px,
    #1a237e 8px,
    #283593 8px,
    #283593 16px
  );
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 
    0 6px 12px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  position: relative;
  opacity: 0.9;
}

.deck-card::before {
  content: '♠♥';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 4px;
}

.deck-left .deck-card:nth-child(1) {
  transform: translateX(-8px) rotate(-3deg);
  z-index: 3;
}

.deck-left .deck-card:nth-child(2) {
  transform: translateX(-4px) rotate(-1deg);
  z-index: 2;
}

.deck-left .deck-card:nth-child(3) {
  transform: translateX(0) rotate(0deg);
  z-index: 1;
}

.deck-right .deck-card:nth-child(1) {
  transform: translateX(8px) rotate(3deg);
  z-index: 3;
}

.deck-right .deck-card:nth-child(2) {
  transform: translateX(4px) rotate(1deg);
  z-index: 2;
}

.deck-right .deck-card:nth-child(3) {
  transform: translateX(0) rotate(0deg);
  z-index: 1;
}

.card {
  width: 90px;
  height: 126px;
  background: var(--card-white);
  color: var(--card-black);
  border-radius: 12px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  box-shadow: 
    0 8px 16px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset,
    0 2px 4px rgba(0, 0, 0, 0.3) inset;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  z-index: 1;
  transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
  font-weight: 700;
  will-change: transform, opacity;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.card:hover {
  transform: translateY(-5px) scale(1.05);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.2) inset;
  z-index: 10;
}

.card.deal {
  animation: dealFromDeck 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@keyframes dealFromDeck {
  0% {
    transform: translateX(-250px) translateY(-50px) rotate(-120deg) scale(0.4);
    opacity: 0;
  }
  60% {
    transform: translateX(-50px) translateY(-5px) rotate(-10deg) scale(0.95);
    opacity: 0.9;
  }
  100% {
    transform: translateX(0) translateY(0) rotate(0deg) scale(1);
    opacity: 1;
  }
}

.card.back {
  background: repeating-linear-gradient(
    45deg,
    #1a237e 0px,
    #1a237e 10px,
    #283593 10px,
    #283593 20px
  );
  border-color: #1a237e;
  position: relative;
}

.card.back::before {
  content: '♠♥';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 32px;
  color: rgba(255, 255, 255, 0.3);
  letter-spacing: 8px;
}

.card .rank {
  font-weight: 900;
  font-size: 22px;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.card .suit {
  font-size: 32px;
  line-height: 1;
  text-align: center;
  margin: auto 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.card.red {
  color: var(--card-red);
}

.points {
  margin-top: 15px;
  color: rgba(255, 255, 255, 0.95);
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
  letter-spacing: 1px;
}

.controls {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 30px;
  flex-wrap: wrap;
}

button {
  appearance: none;
  border: none;
  padding: 14px 28px;
  border-radius: 12px;
  background: linear-gradient(145deg, #1a73e8, #1557b0);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.4),
    0 2px 4px rgba(255, 255, 255, 0.1) inset;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
  will-change: transform, filter;
  transform: translateZ(0);
}

button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  transition: left 0.5s;
}

button:hover:not(:disabled)::before {
  left: 100%;
}

button:hover:not(:disabled) {
  filter: brightness(1.15);
  transform: translateY(-2px);
  box-shadow: 
    0 6px 16px rgba(0, 0, 0, 0.5),
    0 2px 4px rgba(255, 255, 255, 0.2) inset;
}

button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 
    0 2px 8px rgba(0, 0, 0, 0.4),
    0 1px 2px rgba(255, 255, 255, 0.1) inset;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  filter: grayscale(0.5);
}

button.secondary {
  background: linear-gradient(145deg, #4a5568, #2d3748);
}

button.play-again {
  background: linear-gradient(145deg, #ffd700, #ffb700);
  color: #000;
  font-weight: 900;
  font-size: 18px;
  padding: 16px 32px;
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 
    0 6px 20px rgba(255, 215, 0, 0.5),
    0 2px 4px rgba(255, 255, 255, 0.2) inset;
}

button.play-again:hover:not(:disabled) {
  filter: brightness(1.2);
  transform: translateY(-3px) scale(1.05);
  box-shadow: 
    0 8px 24px rgba(255, 215, 0, 0.7),
    0 2px 4px rgba(255, 255, 255, 0.3) inset;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 
      0 6px 20px rgba(255, 215, 0, 0.5),
      0 2px 4px rgba(255, 255, 255, 0.2) inset;
  }
  50% {
    transform: scale(1.05);
    box-shadow: 
      0 8px 24px rgba(255, 215, 0, 0.7),
      0 2px 4px rgba(255, 255, 255, 0.3) inset;
  }
}

.footer-note {
  opacity: 0.7;
  text-align: center;
  margin-top: 20px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Win/Lose/Bust Animations */
body[data-outcome="win"] .felt {
  animation: winPulse 1s ease-out;
  box-shadow: 
    0 40px 100px rgba(0, 0, 0, 0.6) inset,
    0 0 0 2px rgba(255, 255, 255, 0.1),
    0 20px 60px rgba(0, 0, 0, 0.5),
    0 0 100px rgba(76, 175, 80, 0.8),
    0 0 150px rgba(76, 175, 80, 0.4);
}

body[data-outcome="lose"] .felt {
  animation: loseShake 0.8s ease-out;
  box-shadow: 
    0 40px 100px rgba(0, 0, 0, 0.6) inset,
    0 0 0 2px rgba(255, 255, 255, 0.1),
    0 20px 60px rgba(0, 0, 0, 0.5),
    0 0 100px rgba(239, 71, 111, 0.8),
    0 0 150px rgba(239, 71, 111, 0.4);
}

body[data-outcome="blackjack_win"] .felt {
  animation: blackjackWin 1.2s ease-out;
  box-shadow: 
    0 40px 100px rgba(0, 0, 0, 0.6) inset,
    0 0 0 2px rgba(255, 255, 255, 0.1),
    0 20px 60px rgba(0, 0, 0, 0.5),
    0 0 120px rgba(255, 215, 0, 1),
    0 0 200px rgba(255, 215, 0, 0.6);
}

@keyframes winPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}

@keyframes loseShake {
  0%, 100% {
    transform: translateX(0);
  }
  10%, 30%, 50%, 70%, 90% {
    transform: translateX(-5px);
  }
  20%, 40%, 60%, 80% {
    transform: translateX(5px);
  }
}

@keyframes blackjackWin {
  0%, 100% {
    transform: scale(1) rotate(0deg);
    filter: brightness(1);
  }
  25% {
    transform: scale(1.03) rotate(0.5deg);
    filter: brightness(1.2);
  }
  50% {
    transform: scale(1.05) rotate(-0.5deg);
    filter: brightness(1.4);
  }
  75% {
    transform: scale(1.03) rotate(0.5deg);
    filter: brightness(1.2);
  }
}


/* Card flip animation */
.card.flip {
  animation: cardFlip 0.3s ease-in-out both;
  will-change: transform;
}

@keyframes cardFlip {
  0% {
    transform: perspective(1000px) rotateY(0deg);
  }
  50% {
    transform: perspective(1000px) rotateY(90deg);
  }
  100% {
    transform: perspective(1000px) rotateY(0deg);
  }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .felt {
    padding: 25px 15px;
    border-radius: 20px;
  }
  
  .topbar h1 {
    font-size: 32px;
  }
  
  .card {
    width: 75px;
    height: 105px;
    padding: 8px 6px;
  }
  
  .card .rank {
    font-size: 18px;
  }
  
  .card .suit {
    font-size: 24px;
  }
  
  .deck-left, .deck-right {
    display: none; /* Hide deck on mobile */
  }
}
