/**
 * style.css - Main Visual Design System, Reset, Typography & Shared Components
 */

:root {
  --bg-dark: #090d16;
  --bg-card: rgba(18, 24, 38, 0.85);
  --bg-card-hover: rgba(28, 38, 58, 0.95);
  --border-color: rgba(255, 255, 255, 0.12);
  --border-gold: rgba(245, 158, 11, 0.4);
  
  --gold-primary: #f59e0b;
  --gold-hover: #fbbf24;
  --gold-gradient: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
  
  --emerald-primary: #10b981;
  --emerald-dark: #064e3b;
  --emerald-felt: #0d4a2f;
  
  --blue-primary: #3b82f6;
  --red-primary: #ef4444;
  --red-hover: #dc2626;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --shadow-lg: 0 10px 30px -5px rgba(0, 0, 0, 0.6);
  --shadow-gold: 0 0 20px rgba(245, 158, 11, 0.35);
  
  --font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  line-height: 1.5;
}

/* App Container */
#app-root {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Glassmorphism Panel */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

/* Common Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
  background: var(--gold-gradient);
  color: #0f172a;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.45);
}

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

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  font-weight: 600;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* ========================================================
   VIEW 1: TRANG ĐĂNG NHẬP (LOGIN SCREEN)
   ======================================================== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  background: radial-gradient(circle at 50% 20%, #1e1b4b 0%, #090d16 80%);
}

.login-bg-overlay {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(245, 158, 11, 0.08) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}

.login-card {
  width: 100%;
  max-width: 520px;
  padding: 36px 32px;
  z-index: 2;
  border: 1px solid rgba(245, 158, 11, 0.25);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), var(--shadow-gold);
}

.brand-header {
  text-align: center;
  margin-bottom: 28px;
}

.brand-badge {
  display: inline-block;
  background: rgba(245, 158, 11, 0.15);
  color: var(--gold-primary);
  border: 1px solid var(--border-gold);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
}

.brand-title {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #fff 30%, var(--gold-primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.brand-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 6px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  font-size: 1.1rem;
}

.input-wrapper input {
  width: 100%;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #fff;
  padding: 12px 14px 12px 42px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.input-wrapper input:focus {
  border-color: var(--gold-primary);
  outline: none;
}

/* Avatar Selector */
.avatar-selector-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.avatar-opt-btn {
  min-width: 0;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.avatar-opt-btn .opt-emoji {
  font-size: 1.8rem;
}

.avatar-opt-btn .opt-name {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  padding: 0 4px;
}

.avatar-opt-btn:hover {
  background: rgba(245, 158, 11, 0.1);
  border-color: var(--gold-primary);
  transform: translateY(-2px);
}

.avatar-opt-btn.selected {
  background: rgba(245, 158, 11, 0.2);
  border-color: var(--gold-primary);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
}

.starting-chips-badge {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #a7f3d0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  margin-bottom: 24px;
}

.login-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-actions .btn-login-submit {
  width: 100%;
  font-size: 1.05rem;
  padding: 14px;
}

.login-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ========================================================
   VIEW 2: SẢNH CHỜ (LOBBY VIEW)
   ======================================================== */
.lobby-screen {
  background: radial-gradient(circle at 50% 0%, #172554 0%, #090d16 65%);
  padding-bottom: 40px;
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 36px;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
}

.brand-zone {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  font-size: 2.2rem;
  color: var(--gold-primary);
}

.brand-zone .brand-title {
  font-size: 1.4rem;
  line-height: 1.2;
}

.brand-tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.user-profile-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border-radius: var(--radius-full);
}

.user-avatar-badge {
  font-size: 1.8rem;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--gold-primary);
}

.user-meta {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.user-chips-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-chips {
  color: var(--gold-primary);
  font-weight: 800;
  font-size: 1.05rem;
}

.btn-bonus {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-bonus:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.45);
}

.btn-logout {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
}

.btn-logout:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}

/* Lobby Invite Banner */
.lobby-invite-banner {
  max-width: 1440px;
  margin: 16px 36px 0 36px;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.banner-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.banner-icon {
  font-size: 1.8rem;
}

.banner-desc {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.banner-desc strong {
  color: #fbbf24;
  font-size: 0.92rem;
}

.banner-desc span {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.banner-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.invite-url-code {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #38bdf8;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-family: monospace;
  font-size: 0.92rem;
  font-weight: 700;
}

.btn-copy-small {
  padding: 8px 16px;
  font-size: 0.85rem;
}

/* Lobby Content Grid */
.lobby-main-content {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 28px;
  padding: 32px 36px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

.rooms-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.section-title {
  font-size: 1.5rem;
  font-weight: 800;
}

.section-subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.rooms-actions {
  display: flex;
  gap: 12px;
}

.btn-action-primary {
  background: var(--gold-gradient);
  color: #0f172a;
  font-weight: 800;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-gold);
}

.btn-action-primary:hover {
  transform: translateY(-2px);
}

.btn-action-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.btn-action-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 20px;
}

.room-card {
  padding: 24px;
  position: relative;
  overflow: hidden;
  border-top: 3px solid var(--accent, var(--gold-primary));
  transition: all 0.25s ease;
}

.room-card:hover {
  transform: translateY(-4px);
  background: var(--bg-card-hover);
  border-color: var(--accent);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.room-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.room-top {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.room-icon {
  font-size: 2.2rem;
}

.room-name {
  font-size: 1.15rem;
  font-weight: 700;
}

.room-blinds {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.room-blinds strong {
  color: var(--gold-primary);
}

.room-stats {
  display: flex;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.3);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.stat-val {
  font-size: 0.95rem;
  font-weight: 700;
}

.btn-join-room {
  width: 100%;
  padding: 12px;
  background: var(--gold-gradient);
  color: #0f172a;
  font-weight: 700;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.btn-join-room:hover:not(.disabled) {
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4);
}

.btn-join-room.disabled {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-dim);
  cursor: not-allowed;
}

/* Right Column: User Stats & Leaderboard */
.lobby-right-col {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.stats-card, .leaderboard-card {
  padding: 22px;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.stat-box {
  background: rgba(0, 0, 0, 0.25);
  padding: 12px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.stat-number {
  display: block;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--gold-primary);
}

.stat-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.best-hand-badge {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--border-gold);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: #fde68a;
}

/* Leaderboard */
.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.leader-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
}

.leader-rank {
  font-size: 0.82rem;
  font-weight: 800;
  width: 26px;
  color: var(--text-muted);
}

.leader-rank.rank-1 { color: #fbbf24; }
.leader-rank.rank-2 { color: #94a3b8; }
.leader-rank.rank-3 { color: #b45309; }

.leader-avatar { font-size: 1.2rem; }
.leader-name {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leader-chips {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--gold-primary);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  padding: 28px;
  position: relative;
  border: 1px solid var(--border-gold);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.btn-close-modal {
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.btn-close-modal:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.modal-body .form-group input,
.modal-body .form-group select {
  width: 100%;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: #fff;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-family: inherit;
}

.modal-footer {
  margin-top: 24px;
}

.modal-footer .btn-primary {
  width: 100%;
}

/* ========================================================
   TOAST NOTIFICATIONS (Non-blocking mobile-friendly alerts)
   ======================================================== */
#toast-host {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(92vw, 420px);
}

.toast {
  background: rgba(15, 23, 42, 0.96);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(12px);
  opacity: 0;
  transform: translateY(-10px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
  text-align: center;
  max-width: 100%;
}

.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast-ok {
  border-color: rgba(16, 185, 129, 0.55);
  color: #a7f3d0;
}

.toast-warn {
  border-color: rgba(245, 158, 11, 0.6);
  color: #fde68a;
}

/* ========================================================
   MOBILE & TABLET RESPONSIVENESS (Login & Lobby)
   ======================================================== */
@media (max-width: 1024px) {
  .lobby-header {
    padding: 14px 20px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .lobby-invite-banner {
    margin: 14px 20px 0 20px;
    padding: 12px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .banner-right {
    justify-content: space-between;
  }

  .invite-url-code {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .lobby-main-content {
    grid-template-columns: 1fr;
    padding: 20px;
    gap: 20px;
  }
}

@media (max-width: 640px) {
  /* Login Screen */
  .login-screen {
    padding: 16px 12px calc(16px + env(safe-area-inset-bottom, 0px));
    min-height: 100dvh;
  }

  .login-card {
    padding: 24px 18px;
    border-radius: var(--radius-md);
  }

  .brand-header {
    margin-bottom: 20px;
  }

  .brand-title {
    font-size: 1.75rem;
  }

  .brand-subtitle {
    font-size: 0.85rem;
  }

  /* Prevent iOS Safari zoom on input focus (>= 16px) */
  .input-wrapper input,
  .modal-body .form-group input,
  .modal-body .form-group select {
    font-size: 16px;
  }

  .avatar-selector-grid {
    gap: 8px;
  }

  .avatar-opt-btn {
    padding: 8px 2px;
    min-height: 62px;
  }

  .avatar-opt-btn .opt-emoji {
    font-size: 1.55rem;
  }

  .avatar-opt-btn .opt-name {
    font-size: 0.62rem;
  }

  .starting-chips-badge {
    font-size: 0.82rem;
    padding: 8px 12px;
    margin-bottom: 18px;
  }

  .btn-primary,
  .btn-secondary,
  .btn-join-room,
  .btn-action-primary,
  .btn-action-secondary {
    min-height: 44px;
  }

  /* Lobby Header & User Profile */
  .lobby-header {
    padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 12px;
    flex-direction: column;
    align-items: stretch;
  }

  .brand-zone {
    gap: 10px;
  }

  .brand-icon {
    font-size: 1.75rem;
  }

  .brand-zone .brand-title {
    font-size: 1.2rem;
  }

  .brand-tagline {
    font-size: 0.66rem;
  }

  .user-profile-bar {
    border-radius: var(--radius-md);
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
  }

  .user-avatar-badge {
    width: 38px;
    height: 38px;
    font-size: 1.45rem;
  }

  .user-name {
    font-size: 0.88rem;
  }

  .user-chips {
    font-size: 0.95rem;
  }

  .btn-bonus {
    padding: 7px 12px;
    font-size: 0.78rem;
  }

  .btn-logout {
    padding: 7px 10px;
    font-size: 0.74rem;
  }

  /* Invite Banner */
  .lobby-invite-banner {
    margin: 12px 14px 0 14px;
    padding: 12px;
  }

  .banner-icon {
    font-size: 1.4rem;
  }

  .banner-desc strong {
    font-size: 0.84rem;
  }

  .banner-desc span {
    font-size: 0.74rem;
  }

  .invite-url-code {
    font-size: 0.78rem;
    padding: 6px 10px;
  }

  .btn-copy-small {
    padding: 8px 12px;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  /* Lobby Main Content */
  .lobby-main-content {
    padding: 16px 14px calc(24px + env(safe-area-inset-bottom, 0px));
    gap: 16px;
  }

  .rooms-header-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
  }

  .section-title {
    font-size: 1.22rem;
  }

  .section-subtitle {
    font-size: 0.8rem;
  }

  .rooms-actions {
    width: 100%;
    gap: 8px;
  }

  .rooms-actions button {
    flex: 1;
    padding: 10px 12px;
    font-size: 0.86rem;
  }

  .rooms-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .room-card {
    padding: 16px;
  }

  .room-badge {
    position: static;
    display: inline-block;
    margin-bottom: 10px;
  }

  .room-top {
    margin-bottom: 14px;
    padding-right: 0;
  }

  .room-name {
    font-size: 1.02rem;
  }

  .room-stats {
    padding: 10px 12px;
    margin-bottom: 14px;
    gap: 8px;
  }

  .stat-val {
    font-size: 0.84rem;
  }

  .stats-card,
  .leaderboard-card {
    padding: 16px;
  }

  /* Modals */
  .modal-overlay {
    padding: 12px;
    align-items: flex-end;
  }

  .modal-card {
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    max-height: 90dvh;
    overflow-y: auto;
  }
}
