/* ========== Game Cào & Xì Dách ========== */
:root {
  --bg: #161b26;
  --bg-gradient: linear-gradient(145deg, #1a2030 0%, #141922 100%);
  --surface: #1e2433;
  --surface2: #262d3f;
  --surface-hover: #2d3548;
  --text: #eef0f2;
  --text-muted: #8b92a0;
  --primary: #5b9cf0;
  --primary-hover: #6ea8f5;
  --primary-soft: rgba(91, 156, 240, 0.15);
  --success: #3db85a;
  --danger: #e84c3d;
  --gold: #e8b43a;
  --card-face: #f8f8f8;
  --card-back: #262d3f;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,0.35);
  --shadow-sm: 0 2px 12px rgba(0,0,0,0.2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', 'SF Pro Display', system-ui, sans-serif;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
}

.screen {
  width: 100%;
  /* max-width: 1200px; */
}
.screen.hidden {
  display: none !important;
}

/* ========== Lobby ========== */
.header {
  text-align: center;
  margin-bottom: 2rem;
}
.header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
}
.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.04);
}

.lobby-form label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.lobby-form input[type="text"] {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--surface2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* 16px trở lên tránh zoom tự động trên iOS */
  margin-bottom: 1rem;
}
.lobby-form input::placeholder {
  color: var(--text-muted);
}
.lobby-form input:focus {
  outline: none;
  border-color: var(--primary);
}

.mode-select {
  margin-bottom: 1rem;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.mode-select label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  margin-bottom: 0;
}
.mode-select input[type="radio"] {
  accent-color: var(--primary);
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.lobby-actions .btn {
  width: 100%;
  padding: 0.85rem 1.25rem;
  font-size: 1rem;
}
.divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.btn-full {
  width: 100%;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 0.75rem;
  min-height: 1.4em;
}
.hint {
  margin-top: 1.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}
#lanHint {
  font-family: monospace;
  color: var(--primary);
  margin-left: 0.25rem;
}

/* ========== Buttons ========== */
.btn {
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn:not(:disabled):active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 12px rgba(91, 156, 240, 0.3);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 16px rgba(91, 156, 240, 0.4);
}
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.06);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover:not(:disabled) {
  background: rgba(74, 144, 217, 0.15);
}
.btn-small {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

/* ========== Room ========== */
.room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.room-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.room-badge {
  background: var(--surface);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  border: 1px solid rgba(255,255,255,0.06);
}
.room-badge strong {
  letter-spacing: 0.12em;
  color: var(--gold);
}

.room-layout {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  gap: 1rem;
  min-height: 75vh;
}
@media (max-width: 1100px) {
  .room-layout {
    grid-template-columns: 1fr 1fr;
  }
  .room-layout .sidebar-left {
    grid-column: 1;
  }
  /* .room-layout .game-area {
    grid-column: 2;
  } */
  .room-layout .sidebar-right {
    grid-column: 1 / -1;
  }
}
@media (max-width: 700px) {
  .room-layout {
    grid-template-columns: 1fr;
  }
}

.sidebar {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.04);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-left {
  min-width: 0;
}

.chat-panel {
  min-height: 450px;
  max-height: calc(100vh - 5rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.sidebar h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.mode-badge {
  font-size: 0.85rem;
  color: var(--gold);
  margin-bottom: 0.5rem;
}

.host-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.host-actions.host-xidach,
.host-actions.host-cao {
  display: none;
}
.host-actions.host-xidach.visible,
.host-actions.host-cao.visible {
  display: flex;
}
.xidach-player-actions {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
}
.xidach-player-actions.visible {
  display: flex;
}
.xidach-player-actions-mobile {
  display: none !important;
  flex-direction: row;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1rem;
}
@media (min-width: 769px) {
  .xidach-player-actions-mobile {
    display: none !important;
  }
}
.host-actions-mobile {
  display: none;
  flex-direction: row;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
@media (min-width: 769px) {
  .host-actions-mobile {
    display: none !important;
  }
}
@media (max-width: 768px) and (orientation: portrait) {
  .host-actions-mobile.visible {
    display: flex;
  }
}

@media (max-width: 768px) and (orientation: portrait) {
  .sidebar-left .xidach-player-actions {
    display: none !important;
  }
  .sidebar-left .dealer-actions {
    display: none !important;
  }
  .sidebar-left .host-actions.host-xidach {
    display: none !important;
  }
}
.dealer-actions {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
}
.dealer-actions.visible {
  display: flex !important;
}
.dealer-actions .btn {
  width: 100%;
}
.dealer-actions-inline {
  display: none;
  gap: 0.75rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
.dealer-actions-inline.visible {
  display: flex !important;
}
.dealer-actions-inline .btn {
  min-width: 120px;
}

.player-list {
  list-style: none;
}
.player-list li {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface2);
  border: 1px solid rgba(255,255,255,0.04);
}
.player-list li.host .player-name::after {
  content: ' (Host)';
  color: var(--gold);
  font-size: 0.85rem;
}
.player-list .player-name {
  flex: 1;
}
.player-list .card-count {
  font-size: 0.75rem;
  color: #fff;
  background: linear-gradient(135deg, #4ecdc4, #44a08d);
  padding: 0.2rem 0.5rem;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(78, 205, 196, 0.3);
}

.player-list .player-points {
  font-size: 0.75rem;
  color: #e8b43a;
  font-weight: 600;
  margin-left: auto;
  margin-right: 0.5rem;
}

.player-list .btn-transfer-host {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: rgba(232, 180, 58, 0.2);
  color: var(--gold);
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
}
.player-list .btn-transfer-host:hover {
  background: rgba(232, 180, 58, 0.4);
  transform: scale(1.1);
}

/* Bet Info */
.bet-info {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  background: linear-gradient(135deg, rgba(232, 180, 58, 0.15), rgba(232, 180, 58, 0.05));
  border: 1px solid rgba(232, 180, 58, 0.3);
  border-radius: var(--radius-sm);
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.bet-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.bet-amount {
  font-size: 1rem;
  font-weight: 700;
  color: #e8b43a;
}
.bet-controls {
  display: none;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}
.bet-controls select {
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--surface2);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
}
.bet-controls .btn {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
}

.host-actions .btn {
  width: 100%;
}

.dealer-area {
  margin-bottom: 1.5rem;
  padding: 0.75rem;
  background: var(--surface2);
  border-radius: 8px;
}
.dealer-area.hidden {
  display: none !important;
}
.dealer-area h4 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.dealer-area .dealer-score {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--gold);
  word-break: break-word;
}

/* ========== Popup đến lượt (Xì Dách) ========== */
.turn-popup {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  padding: 1rem;
}
.turn-popup.hidden {
  display: none !important;
}
.turn-popup-inner {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 320px;
  text-align: center;
  box-shadow: var(--shadow);
}
.turn-popup-text {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 0.25rem;
}
.turn-popup-sub {
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.turn-popup-inner .btn {
  min-width: 100px;
}

/* ========== Chat ========== */
.chat-box {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chat-panel .chat-box {
  min-height: 350px;
  min-width: 0;
  position: relative;
}
.chat-box h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.chat-box h3 .chat-icon {
  font-size: 1.1rem;
  opacity: 0.9;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  min-height: 180px;
  margin-bottom: 0.5rem;
  border: 1px solid rgba(255,255,255,0.05);
  scrollbar-width: thin;
  scrollbar-color: var(--surface2) transparent;
}
.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--surface2);
  border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.typing-indicator {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 0.25rem 0;
  min-height: 0;
  display: none;
}
.typing-indicator.visible {
  display: block;
}
.chat-messages .msg {
  margin-bottom: 0.6rem;
  word-break: break-word;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  line-height: 1.45;
}
.chat-messages .msg.system {
  color: var(--text-muted);
  font-style: italic;
  background: rgba(255,255,255,0.03);
  padding-left: 0.5rem;
}
.chat-messages .msg:not(.system) {
  background: var(--primary-soft);
  border-left: 3px solid var(--primary);
}
.chat-messages .msg .from {
  color: var(--primary);
  font-weight: 600;
  margin-right: 0.35rem;
}
.chat-messages .msg .msg-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.chat-messages .msg .msg-top-row .from {
  flex: 1;
}
.chat-messages .msg .msg-reply-btn {
  opacity: 0.5;
  padding: 0.2rem 0.4rem;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.9rem;
  border-radius: 4px;
  transition: opacity 0.2s, background 0.2s;
}
.chat-messages .msg .msg-reply-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.1);
}
.chat-messages .msg .msg-react-btn {
  opacity: 0.5;
  padding: 0.2rem 0.35rem;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.85rem;
  border-radius: 4px;
  transition: opacity 0.2s, background 0.2s;
}
.chat-messages .msg .msg-react-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.1);
}
.chat-messages .msg .msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.35rem;
}
.chat-messages .msg .reaction-badge {
  font-size: 0.8rem;
  padding: 0.15rem 0.4rem;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
}
.reaction-picker {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  padding: 0.35rem;
  display: flex;
  gap: 0.25rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 1000;
}
.reaction-picker-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 6px;
  transition: transform 0.15s, background 0.15s;
}
.reaction-picker-btn:hover {
  background: var(--surface-hover);
  transform: scale(1.15);
}
.chat-messages .msg .msg-reply-to {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.25rem 0;
  border-left: 2px solid rgba(255,255,255,0.2);
  padding-left: 0.5rem;
  margin: 0.25rem 0;
}
.chat-messages .msg .msg-reply-to .reply-from {
  font-weight: 600;
  color: var(--primary);
}
.chat-reply-preview {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: rgba(91, 156, 240, 0.15);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  border-left: 3px solid var(--primary);
}
.chat-reply-preview.visible {
  display: flex;
}
.chat-reply-preview .reply-preview-text {
  flex: 1;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-reply-preview .reply-preview-cancel {
  padding: 0.2rem 0.5rem;
  border: none;
  background: rgba(255,255,255,0.1);
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.8rem;
  transition: background 0.2s;
}
.chat-reply-preview .reply-preview-cancel:hover {
  background: rgba(255,255,255,0.2);
}
.chat-stickers {
  display: none;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
  max-height: 160px;
  overflow-y: auto;
}
.chat-stickers.visible {
  display: flex;
}
.chat-input-wrap .btn-emoji {
  padding: 0.5rem;
  min-width: 36px;
  font-size: 1.2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface2);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s;
}
.chat-input-wrap .btn-emoji:hover {
  background: var(--surface-hover);
}
.chat-input-wrap .btn-emoji.active {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.mention-suggest {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius-sm);
  max-height: 140px;
  overflow-y: auto;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
  z-index: 50;
}
.mention-suggest.visible {
  display: block;
}
.mention-suggest .mention-item {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}
.mention-suggest .mention-item:hover {
  background: var(--surface-hover);
}
.chat-messages .msg-text .mention {
  color: var(--primary);
  font-weight: 600;
}

.chat-stickers .sticker-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}
.chat-stickers .sticker-btn:hover {
  background: var(--surface-hover);
  transform: scale(1.12);
}
.chat-stickers .sticker-btn:active {
  transform: scale(0.98);
}
.chat-input-wrap {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  min-width: 0;
  position: relative;
}
.chat-input-wrap input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--surface2);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
.chat-input-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.chat-input-wrap .btn-emoji,
.chat-input-wrap .btn-send {
  flex-shrink: 0;
}
.chat-input-wrap .btn-send {
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.85rem;
}
.chat-input-wrap .btn-send .send-icon {
  font-size: 1rem;
}

/* ========== Game area ========== */
.game-area {
  min-width: 0;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.04);
}

.spectator-banner {
  text-align: center;
  color: var(--gold);
  font-weight: 600;
  margin-bottom: 1rem;
  font-size: 0.95rem;
  padding: 0.5rem 1rem;
  background: rgba(255, 193, 7, 0.15);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 193, 7, 0.4);
}
.spectator-banner.hidden {
  display: none;
}

.spectator-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  background: rgba(255, 193, 7, 0.2);
  color: var(--gold);
  border-radius: 4px;
  margin-left: 0.4rem;
}

.phase-message {
  text-align: center;
  color: white;
  font-weight: bold;
  margin-bottom: 1.5rem;
  font-size: 1rem;
  padding: 0.6rem 1rem;
  background: rgba(4, 0, 233, 0.822);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}

.cards-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.my-cards h4 {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.cards-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}
.score-label {
  margin-top: 0.5rem;
  font-weight: 600;
  color: var(--gold);
  font-size: 1rem;
}

/* Lá bài */
.card-slot {
  width: 72px;
  height: 100px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: transform 0.2s;
  border: 1px solid;
  border-image: linear-gradient(135deg, #ffd700aa, #ff990020) 1;
}
/* Hiệu ứng chia bài: lá bay vào từng lá */
.card-slot.deal-anim {
  opacity: 0;
  animation: cardDealIn 0.4s ease-out forwards;
}
.card-slot.deal-anim.hidden {
  animation-name: cardDealInHidden;
}
@keyframes cardDealIn {
  from {
    opacity: 0;
    transform: translateY(-50px) translateX(-80px) scale(0.6);
  }
  to {
    opacity: 1;
    transform: translateY(0) translateX(0) scale(1);
  }
}
@keyframes cardDealInHidden {
  from {
    opacity: 0;
    transform: translateY(-30px) scale(0.85);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.card-slot.red {
  color: var(--danger);
  background: var(--card-face);
}
.card-slot.black {
  color: #1a1a1a;
  background: var(--card-face);
}
.card-slot.hidden {
  background: linear-gradient(135deg, var(--surface2) 0%, var(--card-back) 100%);
  color: var(--text-muted);
  font-size: 0.75rem;
  /* border: 1px solid var(--surface2); */
  border: 1px solid;
  border-image: linear-gradient(135deg, #ffd700aa, #ff990020) 1;
  border-radius: 8px;
}
.card-slot.hidden::after {
  content: '?';
}

.other-players-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
@media (max-width: 900px) {
  .other-players-cards {
    grid-template-columns: 1fr;
  }
}
.other-player-row {
  padding: 0.75rem;
  background: var(--surface2);
  border-radius: 8px;
  transition: box-shadow 0.25s, border-color 0.25s, transform 0.2s;
}
.other-player-row.current-turn {
  box-shadow: 0 0 0 3px var(--primary);
  border: 2px solid var(--primary);
  transform: scale(1.02);
  animation: turn-pulse 1.5s ease-in-out infinite;
}
.my-cards.current-turn,
.dealer-area.current-turn {
  box-shadow: 0 0 0 3px var(--primary);
  border: 2px solid var(--primary);
  animation: turn-pulse 1.5s ease-in-out infinite;
}
@keyframes turn-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--primary); }
  50% { box-shadow: 0 0 12px 4px rgba(91, 156, 240, 0.5); }
}
.other-player-row h4 {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}
.other-player-row .cards-row {
  justify-content: flex-start;
}

.result-area {
  margin-top: 1.5rem;
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
}
.result-area.winner {
  background: rgba(52, 168, 83, 0.2);
  color: var(--success);
}
.result-area.tie {
  background: rgba(240, 180, 41, 0.15);
  color: var(--gold);
}
.result-area .my-result {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.result-area .hand-type {
  color: var(--primary);
  font-weight: 700;
  font-size: 1.2rem;
}
.result-area .result-win {
  color: #3db85a;
  font-weight: 700;
}
.result-area .result-lose {
  color: #e84c3d;
  font-weight: 700;
}
.result-area .result-tie {
  color: #e8b43a;
  font-weight: 700;
}
.result-area .point-change {
  font-size: 1rem;
}
.result-area .point-change.positive {
  color: #3db85a;
}
.result-area .point-change.negative {
  color: #e84c3d;
}

/* ========== Result Popup ========== */
.result-popup {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.result-popup.hidden {
  display: none;
}
.result-popup-inner {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  max-width: 450px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.result-popup-inner h3 {
  text-align: center;
  margin-bottom: 1rem;
  color: var(--primary);
  font-size: 1.3rem;
}
.result-popup .result-bet {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.result-popup .result-bet strong {
  color: #e8b43a;
}
.result-popup .result-dealer {
  text-align: center;
  padding: 0.75rem;
  background: rgba(232, 180, 58, 0.1);
  border-radius: 8px;
  margin-bottom: 1rem;
}
.result-popup .dealer-label {
  color: var(--text-muted);
}
.result-popup .hand-type {
  color: var(--primary);
  font-weight: 600;
}
.result-popup .point-change {
  font-weight: 600;
}
.result-popup .point-change.positive {
  color: #3db85a;
}
.result-popup .point-change.negative {
  color: #e84c3d;
}
.result-popup .result-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 1rem 0;
}
.result-popup .result-players {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.result-popup .result-group {
  border-radius: 8px;
  padding: 0.75rem;
}
.result-popup .win-group {
  background: rgba(61, 184, 90, 0.1);
  border: 1px solid rgba(61, 184, 90, 0.3);
}
.result-popup .tie-group {
  background: rgba(232, 180, 58, 0.1);
  border: 1px solid rgba(232, 180, 58, 0.3);
}
.result-popup .lose-group {
  background: rgba(232, 76, 61, 0.1);
  border: 1px solid rgba(232, 76, 61, 0.3);
}
.result-popup .group-title {
  font-weight: 700;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}
.result-popup .win-group .group-title {
  color: #3db85a;
}
.result-popup .tie-group .group-title {
  color: #e8b43a;
}
.result-popup .lose-group .group-title {
  color: #e84c3d;
}
.result-popup .result-player {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  font-size: 0.9rem;
}
.result-popup .result-player .player-name {
  flex: 1;
  color: var(--text);
}
.result-popup .result-player .hand-type {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.result-popup .result-player .point-change {
  min-width: 80px;
  text-align: right;
}
.result-popup .btn {
  display: block;
  width: 100%;
  margin-top: 0.5rem;
}

/* ========== Animated Gradient Border ========== */
@keyframes gradient-rotate {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@keyframes border-spin {
  0% {
    --angle: 0deg;
  }
  100% {
    --angle: 360deg;
  }
}

@property --angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

.gradient-border {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
}

.gradient-border::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: calc(var(--radius) + 3px);
  background: linear-gradient(
    var(--angle, 0deg),
    #ff6b6b,
    #4ecdc4,
    #ffe66d,
    #a29bfe,
    #fd79a8,
    #00b894,
    #ff6b6b
  );
  background-size: 300% 300%;
  animation: border-spin 3s linear infinite, gradient-rotate 3s ease infinite;
  z-index: -1;
}

/* Áp dụng cho lá bài đang chơi */
.card-slot:not(.hidden) {
  position: relative;
}

.my-cards .card-slot:not(.hidden)::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 10px;
  background: linear-gradient(
    var(--angle, 0deg),
    #ff6b6b,
    #4ecdc4,
    #ffe66d,
    #a29bfe,
    #fd79a8,
    #00b894,
    #ff6b6b
  );
  background-size: 300% 300%;
  animation: border-spin 2s linear infinite, gradient-rotate 2s ease infinite;
  z-index: -1;
  opacity: 0.8;
}

/* Viền gradient cho khu vực bài của bạn */
.my-cards {
  position: relative;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--surface);
}

.my-cards::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(
    var(--angle, 0deg),
    #5b9cf0,
    #4ecdc4,
    #a29bfe,
    #fd79a8,
    #5b9cf0
  );
  background-size: 400% 400%;
  animation: border-spin 4s linear infinite, gradient-rotate 3s ease infinite;
  z-index: -1;
  opacity: 0.6;
}

/* Viền gradient cho dealer area */
.dealer-area {
  position: relative;
}

.dealer-area::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(
    var(--angle, 0deg),
    #e8b43a,
    #ff6b6b,
    #e8b43a,
    #ffeaa7,
    #e8b43a
  );
  background-size: 400% 400%;
  animation: border-spin 4s linear infinite, gradient-rotate 3s ease infinite;
  z-index: -1;
  opacity: 0.5;
}

/* Viền gradient cho người chơi đang đến lượt */
.player-list li.current-turn {
  position: relative;
}

.player-list li.current-turn::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: calc(var(--radius-sm) + 2px);
  background: linear-gradient(
    var(--angle, 0deg),
    #00b894,
    #4ecdc4,
    #81ecec,
    #00b894
  );
  background-size: 300% 300%;
  animation: border-spin 2s linear infinite, gradient-rotate 2s ease infinite;
  z-index: -1;
}

/* ========== Mobile Tab Bar (màn dọc) ========== */
.mobile-tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 500;
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 0.5rem 0;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
  flex-direction: row;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
}

@media (max-width: 768px) and (orientation: portrait) {
  .mobile-tab-bar {
    display: flex;
  }
  .room-layout {
    padding-bottom: 72px;
    min-height: calc(100vh - 140px);
  }
  .room-layout .mobile-panel {
    display: none !important;
  }
  .room-layout .mobile-panel.active {
    display: flex !important;
    flex-direction: column;
    min-height: calc(100vh - 180px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .room-layout .game-area.mobile-panel.active {
    display: flex !important;
    flex-direction: column;
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }
  .room-layout .game-area.mobile-panel.active .xidach-player-actions-mobile.visible {
    display: flex !important;
    position: fixed;
    bottom: calc(68px + env(safe-area-inset-bottom));
    left: max(0.25rem, env(safe-area-inset-left));
    right: max(0.25rem, env(safe-area-inset-right));
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius);
    z-index: 400;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    margin: 0;
  }
  .room-layout .game-area.mobile-panel.active .xidach-player-actions-mobile.visible .btn {
    flex: 1;
    min-height: 38px;
    padding: 0.45rem 0.6rem;
    font-size: 0.88rem;
  }
  .room-layout .game-area.has-mobile-actions #cardsContainer {
    padding-bottom: 90px;
  }
  .room-layout .chat-panel.mobile-panel.active {
    max-height: calc(100vh - 150px);
    min-height: calc(100vh - 150px);;
    overflow: hidden;
    padding-bottom: calc(68px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
  }
  .room-layout .chat-panel.mobile-panel.active .chat-box {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .room-layout .chat-panel.mobile-panel.active .chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .room-layout .chat-panel.mobile-panel.active .chat-input-wrap {
    flex-shrink: 0;
    margin-top: auto;
    padding: 0.5rem 0;
    background: var(--surface);
    border-top: 1px solid rgba(255,255,255,0.06);
  }
}

.mobile-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  flex: 1;
  max-width: 120px;
  padding: 0.5rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
  border-radius: 8px;
}
.mobile-tab:active {
  background: rgba(255,255,255,0.05);
}
.mobile-tab.active {
  color: var(--primary);
  font-weight: 600;
}
.mobile-tab-icon-wrap {
  position: relative;
  display: inline-flex;
}
.mobile-tab-icon {
  font-size: 1.4rem;
  line-height: 1;
}
.mobile-tab-badge {
  position: absolute;
  top: -2px;
  right: -6px;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
  display: none;
  border: 2px solid var(--surface);
}
.mobile-tab-badge.visible {
  display: block;
}
.mobile-tab-label {
  font-size: 0.7rem;
  white-space: nowrap;
}

/* Nút nhỏ hơn trên mobile */
.btn-mobile {
  padding: 0.4rem 0.7rem !important;
  font-size: 0.85rem !important;
  min-height: 36px !important;
}

/* ========== Mobile / Responsive ========== */
@media (max-width: 768px) {
  html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }
  body {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  #app {
    width: 100%;
    max-width: 100%;
    align-items: stretch;
    padding: 0.5rem 0.5rem env(safe-area-inset-bottom, 0.5rem) 0.5rem;
    padding-left: max(0.5rem, env(safe-area-inset-left));
    padding-right: max(0.5rem, env(safe-area-inset-right));
  }
  #app .screen {
    width: 100%;
    max-width: 100%;
  }
  #room {
    width: 100%;
    max-width: 100%;
  }
  .room-header {
    width: 100%;
  }
  .header h1 {
    font-size: 1.5rem;
  }
  .subtitle {
    font-size: 0.85rem;
  }
  .lobby-form .card {
    padding: 1rem;
  }
  .btn {
    min-height: 36px;
    padding: 0.45rem 0.75rem;
    font-size: 0.88rem;
  }
  .btn-small {
    min-height: 34px;
    padding: 0.35rem 0.6rem;
    font-size: 0.82rem;
  }
  .room-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .room-info {
    flex-wrap: wrap;
  }
  .room-badge {
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
  }
  .room-layout {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    min-height: auto;
    width: 100%;
    min-width: 0;
  }
  .room-layout .sidebar-left {
    order: 1;
  }
  .room-layout .game-area {
    order: 2;
  }
  .room-layout .sidebar-right {
    order: 3;
    min-height: 280px;
  }
  .sidebar {
    padding: 0.75rem;
    width: 100%;
    min-width: 0;
  }
  .game-area {
    padding: 0.75rem;
    width: 100%;
    min-width: 0;
  }
  .cards-container {
    width: 100%;
    min-width: 0;
  }
  .phase-message {
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
  }
  .spectator-banner {
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
  }
  .card-slot {
    width: 56px;
    height: 78px;
    font-size: 1.15rem;
  }
  .cards-row {
    gap: 0.5rem;
  }
  .dealer-area {
    padding: 0.6rem;
    margin-bottom: 1rem;
  }
  .dealer-area h4 {
    font-size: 0.85rem;
  }
  .my-cards h4,
  .other-player-row h4 {
    font-size: 0.85rem;
  }
  .other-player-row {
    padding: 0.5rem;
  }
  .other-player-row .card-slot {
    width: 48px;
    height: 66px;
    font-size: 1rem;
  }
  .host-actions .btn,
  .host-actions-mobile .btn,
  .xidach-player-actions .btn,
  .dealer-actions .btn,
  .dealer-actions-inline .btn {
    min-height: 36px;
    font-size: 0.88rem;
    padding: 0.45rem 0.7rem;
  }
  .player-list li {
    padding: 0.6rem 0.75rem;
    min-height: 44px;
  }
  .player-list .btn-transfer-host {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }
  .chat-panel .chat-box {
    min-height: 220px;
  }
  .chat-messages {
    min-height: 140px;
    font-size: 0.85rem;
  }
  .chat-input-wrap input {
    font-size: 16px; /* Ngăn zoom iOS khi focus */
  }
  .turn-popup-inner {
    margin: 1rem;
    padding: 1.25rem;
  }
  .result-popup-inner {
    padding: 1rem 1.25rem;
    max-height: 85vh;
  }
  .reaction-picker-btn {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 480px) {
  #app {
    padding-left: max(0.35rem, env(safe-area-inset-left));
    padding-right: max(0.35rem, env(safe-area-inset-right));
  }
  .header h1 {
    font-size: 1.35rem;
  }
  .room-badge {
    width: 100%;
    text-align: center;
  }
  .card-slot {
    width: 50px;
    height: 70px;
    font-size: 1rem;
  }
  .other-player-row .card-slot {
    width: 42px;
    height: 58px;
  }
  .other-players-cards {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  .bet-info {
    flex-direction: column;
    align-items: flex-start;
  }
  .bet-controls {
    width: 100%;
    margin-left: 0;
  }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .room-layout .sidebar-right {
    min-height: 180px;
  }
  .chat-panel .chat-box {
    min-height: 160px;
  }
  .chat-messages {
    min-height: 100px;
  }
}
