@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --table-felt: radial-gradient(circle at center, #1b4d3e 0%, #0b251d 100%);
  --table-border: linear-gradient(135deg, #4d2b18 0%, #2a1608 100%);
  --card-width: 68px;
  --card-height: 98px;
  --gold: #f59e0b;
  --gold-dark: #d97706;
  --bg-dark: #0b0f17;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --table-glow: inset 0 0 40px rgba(0, 0, 0, 0.8), inset 0 0 10px rgba(27, 77, 62, 0.5);
  --glass-bg: rgba(17, 24, 39, 0.85);
  --glass-border: rgba(255, 255, 255, 0.1);
}

body {
  background-color: var(--bg-dark);
  color: white;
  font-family: 'Inter', sans-serif;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden; /* Prevent scrolling on game view */
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* --- GAME TABLE --- */
.game-table {
  position: relative;
  width: 95%;
  max-width: 1000px;
  min-height: 520px;
  margin: 0 auto;
  background: var(--table-felt);
  border-radius: 180px / 120px;
  box-shadow: 0 0 0 16px #3b1c09, 0 0 0 20px #2a1608, 0 20px 50px rgba(0,0,0,0.8), var(--table-glow);
  border: 4px solid #1a0f06;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.table-felt-pattern {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: radial-gradient(rgba(255,255,255,0.05) 1px, transparent 1px);
  background-size: 8px 8px;
  border-radius: 180px / 120px;
  pointer-events: none;
}

/* --- PLAYER SEATS --- */
.player-seat {
  position: absolute;
  transition: all 0.3s ease;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.seat-bottom {
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 700px;
}

.seat-top {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
}

.seat-left {
  left: 20px;
  top: 45%;
  transform: translateY(-50%);
}

.seat-right {
  right: 20px;
  top: 45%;
  transform: translateY(-50%);
}

/* --- TURN ACTIVE --- */
.turn-active {
  position: relative;
}
.turn-active .avatar-ring, 
.turn-active img.avatar {
  box-shadow: 0 0 15px var(--gold), inset 0 0 10px var(--gold);
  animation: pulse-border 1.5s infinite;
  border-color: var(--gold);
}

@keyframes pulse-border {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(245, 158, 11, 0); }
  100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

/* --- HAND FAN CONTAINER --- */
.hand-container {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-top: 30px;
  min-height: calc(var(--card-height) + 50px);
  overflow: visible;
  position: relative;
  width: 100%;
}

/* --- PLAYING CARDS --- */
.playing-card {
  --fan-transform: none;
  --lift-y: 0px;
  transform: var(--fan-transform) translateY(var(--lift-y));
  width: var(--card-width);
  height: var(--card-height);
  background-color: white;
  border-radius: 6px;
  box-shadow: var(--card-shadow);
  position: relative;
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.18s ease, filter 0.18s ease;
  cursor: pointer;
  border: 1.5px solid #d1d5db;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px;
  box-sizing: border-box;
  user-select: none;
}

.hand-container .playing-card:hover {
  --lift-y: -14px;
  z-index: 60 !important;
  filter: brightness(1.08);
}

.hand-container .playing-card.selected {
  --lift-y: -28px;
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.85), 0 8px 20px rgba(0, 0, 0, 0.45);
  border-color: #f59e0b;
  z-index: 65 !important;
}

.hand-container .playing-card.selected:hover {
  --lift-y: -34px;
}

.card-red { color: #dc2626; }
.card-black { color: #111827; }

.card-corner {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: bold;
  font-size: 14px;
  line-height: 1.1;
}

.card-corner .suit {
  font-size: 16px;
}

.top-left {
  align-self: flex-start;
}

.bottom-right {
  align-self: flex-end;
  transform: rotate(180deg);
}

.card-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
}

.card-back {
  background: linear-gradient(135deg, #1e3a8a 0%, #172554 100%);
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.05) 0, rgba(255,255,255,0.05) 2px, transparent 2px, transparent 4px);
  border: 2px solid white;
}
.card-back .card-corner, .card-back .card-center {
  display: none;
}

/* --- CENTER PLAYED CARDS --- */
.center-played-cards {
  display: flex;
  justify-content: center;
  align-items: center;
  filter: drop-shadow(0 10px 15px rgba(0,0,0,0.5));
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
}

.center-played-cards .playing-card {
  margin-left: -20px;
  cursor: default;
  transition: none;
}
.center-played-cards .playing-card:first-child {
  margin-left: 0;
}
.center-played-cards .playing-card:hover, 
.center-played-cards .playing-card.selected {
  transform: none !important;
  z-index: auto !important;
  filter: none;
  box-shadow: var(--card-shadow);
  border-color: #d1d5db;
}

/* --- FLYING EMOJI --- */
.flying-emoji {
  position: absolute;
  font-size: 40px;
  z-index: 100;
  pointer-events: none;
  transition: all 1s cubic-bezier(0.25, 1, 0.5, 1);
}

/* --- CHAT DRAWER --- */
.chat-drawer {
  position: fixed;
  top: 0;
  right: -320px;
  width: 320px;
  height: 100vh;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border-left: 1px solid var(--glass-border);
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 200;
  display: flex;
  flex-direction: column;
}

.chat-drawer.open {
  right: 0;
}

/* --- SPECTATOR BADGE --- */
.spectator-badge {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #6b21a8, #9333ea);
  color: white;
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 0 0 10px rgba(147, 51, 234, 0.5);
  animation: pulse-spectator 2s infinite;
  z-index: 30;
}

@keyframes pulse-spectator {
  0% { opacity: 0.8; box-shadow: 0 0 5px rgba(147,51,234,0.3); }
  50% { opacity: 1; box-shadow: 0 0 15px rgba(147,51,234,0.8); }
  100% { opacity: 0.8; box-shadow: 0 0 5px rgba(147,51,234,0.3); }
}

/* --- TOAST --- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  z-index: 1000;
  animation: slideUp 0.3s ease-out forwards;
}

/* --- ROOM CARDS --- */
.room-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 16px;
  transition: all 0.2s ease;
  cursor: pointer;
}
.room-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.3);
  border-color: rgba(245, 158, 11, 0.5);
}

/* --- ANIMATIONS --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.animate-fade-in { animation: fadeIn 0.3s ease forwards; }
.animate-slide-up { animation: slideUp 0.3s ease forwards; }
.animate-scale-in { animation: scaleIn 0.3s ease forwards; }

/* --- RESPONSIVE: MOBILE PORTRAIT & GENERAL MOBILE --- */
@media (max-width: 640px) {
  :root {
    --card-width: 46px;
    --card-height: 68px;
  }

  .game-table, .poker-table {
    border-radius: 120px / 80px;
    box-shadow: 0 0 0 8px #3b1c09, 0 0 0 12px #2a1608, 0 10px 25px rgba(0,0,0,0.8);
    width: 96%;
  }

  .seat-left { left: -10px; }
  .seat-right { right: -10px; }
  .seat-top { top: -25px; }
  
  .card-corner { font-size: 10px; }
  .card-corner .suit { font-size: 11px; }
  .card-center { font-size: 16px; }
  
  .chat-drawer { width: 100%; right: -100%; }
}

/* --- RESPONSIVE: MOBILE LANDSCAPE (Màn hình ngang điện thoại) --- */
@media (orientation: landscape) and (max-height: 540px), (max-height: 480px) {
  :root {
    --card-width: 38px;
    --card-height: 56px;
  }

  /* Thu nhỏ thanh Header toàn cục */
  header {
    height: 36px !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
  header .text-3xl { font-size: 18px !important; }
  header h1 { font-size: 13px !important; }
  #user-info-header {
    padding: 1px 6px !important;
    font-size: 11px !important;
  }
  #btn-fullscreen, #btn-toggle-sound {
    padding: 3px 6px !important;
    font-size: 12px !important;
  }

  /* Game Screen chiếm trọn phần còn lại mà không scroll */
  #game-screen {
    height: calc(100vh - 36px) !important;
    overflow: hidden !important;
  }

  .poker-table-container {
    height: 100% !important;
    width: 100% !important;
    padding: 2px !important;
  }

  .poker-table {
    width: 94% !important;
    height: 84% !important;
    max-height: none !important;
    border-width: 8px !important;
    border-radius: 200px / 110px !important;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5), 0 8px 24px rgba(0,0,0,0.7) !important;
  }

  /* Các ghế người chơi thu nhỏ gọn gàng quanh bàn */
  .seat {
    width: 80px !important;
  }
  #seat-top {
    top: -28px !important;
    transform: translateX(-50%) scale(0.8) !important;
  }
  #seat-left {
    left: -20px !important;
    transform: translateY(-50%) scale(0.8) !important;
  }
  #seat-right {
    right: -20px !important;
    transform: translateY(-50%) scale(0.8) !important;
  }
  #seat-bottom {
    bottom: -6px !important;
    width: 95% !important;
  }

  /* Rút gọn thông tin người chơi ở ghế */
  .seat .w-12 {
    width: 34px !important;
    height: 34px !important;
  }
  .seat .w-12 .text-base, .seat .w-12 .text-lg {
    font-size: 13px !important;
  }
  .seat .bg-gray-900\/90 {
    padding: 2px 4px !important;
    font-size: 9px !important;
  }

  /* Thẻ bài trên tay trong màn hình ngang */
  .hand-container {
    min-height: 65px !important;
    padding-top: 4px !important;
  }
  .playing-card {
    border-radius: 4px !important;
    border-width: 1px !important;
    padding: 2px !important;
  }
  .hand-container .playing-card:hover {
    --lift-y: -8px !important;
  }
  .hand-container .playing-card.selected {
    --lift-y: -18px !important;
  }
  .card-corner { font-size: 9px !important; }
  .card-corner .suit { font-size: 9px !important; }
  .card-center { font-size: 12px !important; }

  /* Nút thao tác (Đánh bài, Bỏ lượt, Gợi ý, Xếp bài) */
  #table-actions-container {
    margin-bottom: 2px !important;
    gap: 3px !important;
    z-index: 50;
  }
  #table-actions-container button {
    padding: 3px 8px !important;
    font-size: 11px !important;
    border-radius: 6px !important;
  }

  /* Bài đánh ra giữa bàn */
  .center-played-cards {
    transform: translate(-50%, -50%) scale(0.82) !important;
  }
  #table-center-content .text-xs {
    font-size: 10px !important;
  }
  #turn-timer-display {
    font-size: 14px !important;
  }

  /* Game Info overlay (Góc trên trái) */
  .absolute.top-4.left-4 {
    top: 4px !important;
    left: 6px !important;
    padding: 2px 6px !important;
    font-size: 10px !important;
  }
  #table-title { font-size: 10px !important; }
  #table-bet-display { font-size: 10px !important; }
  #btn-leave-room {
    margin-top: 1px !important;
    padding: 1px 5px !important;
    font-size: 9px !important;
  }

  /* Nút mở chat (Góc trên phải) */
  #btn-toggle-chat {
    top: 4px !important;
    right: 6px !important;
    padding: 3px 7px !important;
    font-size: 12px !important;
  }

  /* Drawer Chat / Log */
  #game-right-panel {
    width: 250px !important;
    max-width: 75vw !important;
  }
  #game-right-panel .p-3 {
    padding: 6px !important;
  }
}
