:root {
  /* Dynamic & Vibrant Theme Palette */
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  --primary-glow: rgba(99, 102, 241, 0.5);
  --secondary-glow: rgba(236, 72, 153, 0.4);

  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-color: #fca5a5;
  --success-color: #34d399;
  
  --card-width: 100%;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Kanit', sans-serif;
}

body {
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Base App Layout */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 120px 20px 140px; /* Top/bottom padding mapped for fixed header/footer */
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* Glassmorphism Panels */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  box-shadow: var(--glass-shadow);
}

.glass-panel-inner {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
}

/* Main Header */
.game-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
  margin: 0;
  border-radius: 0 0 20px 20px; /* Smooth corners hanging down */
  border-top: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  flex-wrap: wrap;
  gap: 16px;
  background: rgba(15, 23, 35, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Class to hide header dynamically via JS */
.game-header.hidden-header {
  transform: translateY(-120%);
}

/* Game HUD (Fixed to Bottom) */
.game-hud {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 900;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px 24px;
  flex-wrap: nowrap;
  gap: 16px;
  overflow-x: auto;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
}

.dark-footer {
  background: rgba(15, 23, 35, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.game-title {
  font-size: 1.5rem;
  font-weight: 600;
  background: linear-gradient(to right, #a78bfa, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.5px;
}

/* Setup Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(5px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  padding: 40px;
  text-align: center;
  max-width: 500px;
  width: 90%;
}

.select-player-btn {
  background: rgba(52, 211, 153, 0.2);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.4);
  padding: 15px 25px;
  font-size: 1.1rem;
}

.select-player-btn:hover {
  background: rgba(52, 211, 153, 0.4);
  transform: translateY(-2px);
}

/* Multi-Player HUD */
.players-hud {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  flex: 1;
}

.player-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px;
  position: relative;
  overflow: hidden;
  min-width: 100px;
  opacity: 0.6;
  transition: all 0.3s ease;
}

.player-panel.active-turn {
  opacity: 1;
  transform: scale(1.1);
  box-shadow: 0 0 15px rgba(52, 211, 153, 0.4);
  border-color: rgba(52, 211, 153, 0.6);
}

.player-panel.active-turn::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, var(--success-color) 0%, transparent 60%);
  opacity: 0.2;
  pointer-events: none;
}

.player-name {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.player-score {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--success-color);
  text-shadow: 0 0 10px rgba(52, 211, 153, 0.5);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.player-score.pop {
  transform: scale(1.3);
  color: #fff;
}

/* Buttons */
.action-btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.95rem;
}

.danger-btn {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.danger-btn:hover {
  background: rgba(239, 68, 68, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.danger-btn:active {
  transform: translateY(0);
}

/* Game Board (Grid) */
.game-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 15px; /* Reduced gap based on feedback */
  justify-items: center;
  padding: 20px 0;
  position: relative;
}

/* ----- Card 3D Flip System ----- */
.card-scene {
  width: var(--card-width);
  aspect-ratio: 800 / 1433; /* Specific ratio requested: 800x1433 */
  perspective: 1000px; /* Gives 3D depth */
  cursor: pointer;
  position: relative;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform-style: preserve-3d;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
  border-radius: 12px;
}

/* Hover micro-animation for unflipped cards */
.card-scene:not(.flipped):hover .card {
  transform: translateY(-10px) rotateX(5deg) rotateY(-5deg);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.6), 0 0 20px var(--primary-glow);
}

.card-scene.flipped .card {
  transform: rotateY(180deg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px var(--secondary-glow);
}

/* Card Faces */
.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.card-number-badge {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #3b82f6, #a855f7);
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.65rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  z-index: 20;
  border: 1px solid rgba(255,255,255,0.8);
  transition: opacity 0.3s ease;
  pointer-events: none; /* Let clicks pass through to card */
}

.card-scene.flipped .card-number-badge {
  opacity: 0;
}

.card-face-back {
  background-color: #1e293b;
  background-image: url('_media/bg.webp');
  /* User requested file */
  background-size: cover;
  background-position: center;
  /* Add a stylish inner border for the back */
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.05);
}

/* Front Face */
.card-face-front {
  background: #334155;
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  font-size: 0.8rem; /* Scaled down slightly to fit new ratio */
}

.card-image {
  width: 100%;
  height: 48%; /* Adjusted for aspect ratio */
  background-color: #0f172a;
  background-size: cover;
  background-position: center;
  position: relative;
}

/* Placeholder gradient if image fails */
.card-image::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 50%, rgba(30, 41, 59, 1) 100%);
}

.card-content {
  padding: 8px; /* Adjusted padding due to size constraint */
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: center;
  background: #1e293b;
}

.card-title {
  font-size: 0.95rem; /* Downscaled for layout */
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
  letter-spacing: 0.5px;
  line-height: 1.1;
}

.card-desc {
  font-size: 0.75rem; /* Downscaled */
  color: var(--text-muted);
  line-height: 1.25;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;  
  overflow: hidden;
}

.card-value {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.3);
  display: inline-block;
  align-self: center;
  border: 1px solid;
}

.val-positive {
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.3);
}

.val-neutral {
  color: #94a3b8;
  border-color: rgba(148, 163, 184, 0.3);
}

.val-negative {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.3);
}

/* Notifications System */
.notification-container {
  position: fixed;
  bottom: 30px;
  right: 30px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}

.notification {
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  border-left: 4px solid var(--success-color);
  padding: 16px 20px;
  border-radius: 8px;
  color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: slideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  opacity: 0;
  transform: translateX(50px);
}

.notification.fade-out {
  animation: fadeOut 0.3s forwards;
}

@keyframes slideIn {
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeOut {
  to {
    transform: translateX(50px);
    opacity: 0;
  }
}

/* Dealing Animation */
.card-scene.deal {
  animation: dealAnim 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) backwards;
}

@keyframes dealAnim {
  0% {
    opacity: 0;
    transform: translate(calc(50vw - 50%), calc(50vh - 50%)) scale(2) rotateZ(180deg);
  }
  100% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotateZ(0);
  }
}

/* Responsive */
@media (max-width: 1200px) {
  .game-board { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .game-board { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .game-board { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
}
@media (max-width: 600px) {
  .game-hud {
    flex-direction: column;
    text-align: center;
  }
  
  .game-board {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  :root {
    --card-width: 100%;
  }
  
  .card-title { font-size: 0.75rem; margin-bottom: 2px;}
  .card-desc { font-size: 0.6rem; margin-bottom: 4px; line-height: 1.1; -webkit-line-clamp: 3;}
  .card-value { font-size: 0.7rem; padding: 2px 6px; }
}
@media (max-width: 400px) {
  .game-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}