/**
 * Dark-mode-first design system for Poker Knights.
 * CSS custom properties → use everywhere; never hardcode colors.
 *
 * Designed for:
 * - 45+ users in dim rooms
 * - Minimum 17px base font
 * - WCAG AA+ contrast (≥4.5:1 for text, ≥3:1 for UI elements)
 * - 48×48px minimum touch targets
 */

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

/* ── TOKENS ── */
:root {
  /* Backgrounds */
  --bg:            #0d0d0d;
  --surface:       #181818;
  --surface-2:     #222222;
  --surface-3:     #2a2a2a;

  /* Borders */
  --border:        rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);

  /* Text */
  --text:          #f2f2f2;
  --text-dim:      rgba(242, 242, 242, 0.55);
  --text-faint:    rgba(242, 242, 242, 0.3);

  /* Brand colours */
  --primary:       #3b82f6;   /* blue-500 */
  --primary-dim:   rgba(59, 130, 246, 0.15);
  --success:       #22c55e;   /* green-500 */
  --success-dim:   rgba(34, 197, 94, 0.12);
  --danger:        #ef4444;   /* red-500 */
  --danger-dim:    rgba(239, 68, 68, 0.12);
  --warning:       #f59e0b;   /* amber-500 */
  --warning-dim:   rgba(245, 158, 11, 0.12);
  --night:         #a855f7;   /* purple-500 */
  --sunset:        #f97316;   /* orange-500 */

  /* Typography */
  --font:          'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-size:     17px;
  --font-size-sm:  14px;
  --font-size-xs:  12px;
  --font-size-lg:  20px;
  --font-size-xl:  24px;
  --font-size-2xl: 32px;

  /* Spacing */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  12px;
  --space-lg:  16px;
  --space-xl:  24px;
  --space-2xl: 32px;

  /* Layout */
  --touch-target:   48px;
  --radius-sm:      8px;
  --radius-md:      12px;
  --radius-lg:      16px;
  --radius-xl:      20px;
  --radius-full:    999px;

  /* Elevation */
  --shadow-sm:  0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md:  0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg:  0 8px 40px rgba(0, 0, 0, 0.5);

  /* Transitions */
  --ease:       cubic-bezier(0.4, 0, 0.2, 1);
  --duration:   0.2s;
}

/* ── RESET ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: var(--font-size);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  letter-spacing: -0.01em;
  line-height: 1.5;
}

/* ── APP SHELL ── */
.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
}

/* ── SCROLL ── */
.scroll {
  overflow-y: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.scroll::-webkit-scrollbar { display: none; }

/* ── HEADER ── */
header {
  padding: var(--space-xl) var(--space-xl) var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
}

.header-title h1 {
  font-size: var(--font-size-xl);
  font-weight: 900;
  color: var(--text);
  line-height: 1.1;
}

.header-title p {
  font-size: var(--font-size-xs);
  color: var(--text-dim);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

/* ── COUNTDOWN ── */
.countdown {
  display: flex;
  gap: var(--space-xs);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: var(--radius-full);
}

.cd-num {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--warning);
  font-size: var(--font-size-sm);
}

/* ── NAVIGATION ── */
nav {
  display: flex;
  padding: var(--space-md) var(--space-xl) calc(var(--space-xl) + env(safe-area-inset-bottom, 0px));
  gap: var(--space-sm);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.nav-btn {
  flex: 1;
  min-height: var(--touch-target);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-faint);
  transition: color var(--duration) var(--ease);
  cursor: pointer;
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-xs);
  position: relative;
}

.nav-btn.active {
  color: var(--primary);
  background: var(--primary-dim);
}

.nav-btn:active { transform: scale(0.94); }

.nav-icon { font-size: 1.6rem; }

.nav-label {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.live-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 900;
  padding: 2px 4px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 5px var(--danger)); }
  50%       { filter: drop-shadow(0 0 14px var(--danger)); transform: scale(1.1); }
}

.nav-btn.live-poker .nav-icon {
  animation: pulse-glow 2s infinite;
}

/* ── PANELS ── */
.panels {
  padding: var(--space-lg);
  overflow: hidden;
  position: relative;
}

.panel {
  display: none;
  flex-direction: column;
  gap: var(--space-lg);
  height: 100%;
  overflow-y: auto;
  scrollbar-width: none;
  padding-bottom: var(--space-sm);
}

.panel.active { display: flex; }
.panel::-webkit-scrollbar { display: none; }

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
}

.card-title {
  font-size: var(--font-size-sm);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: var(--space-lg);
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: var(--touch-target);
  padding: 0 var(--space-xl);
  border-radius: var(--radius-lg);
  border: none;
  font-family: var(--font);
  font-size: var(--font-size);
  font-weight: 800;
  cursor: pointer;
  transition: transform var(--duration) var(--ease), opacity var(--duration);
  -webkit-user-select: none;
  user-select: none;
}

.btn:active { transform: scale(0.95); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: #2563eb; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm {
  min-height: 38px;
  padding: 0 var(--space-md);
  font-size: var(--font-size-sm);
  border-radius: var(--radius-sm);
}

.btn-full { width: 100%; }

/* ── INPUTS ── */
.input {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  font-family: var(--font);
  font-size: var(--font-size);
  font-weight: 700;
  color: var(--text);
  width: 100%;
  min-height: var(--touch-target);
  text-align: center;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  transition: border-color var(--duration);
}

.input:focus { border-color: var(--primary); }
.input::placeholder { color: var(--text-faint); font-weight: 600; }
.input[readonly] { opacity: 0.4; cursor: not-allowed; }

/* ── PLAYER ROWS ── */
.player-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

/* ── AVATAR ── */
.av {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: var(--font-size-xs);
  color: #fff;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge-blue   { background: var(--primary-dim);  color: var(--primary); }
.badge-green  { background: var(--success-dim);  color: var(--success); }
.badge-red    { background: var(--danger-dim);   color: var(--danger);  }
.badge-purple { background: rgba(168,85,247,0.15); color: var(--night);  }

/* ── POT STATUS ── */
.pot-status {
  font-size: var(--font-size-sm);
  font-weight: 800;
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-lg);
}
.pot-ok  { background: var(--success-dim); color: var(--success); border: 2px solid var(--success); }
.pot-err { background: var(--danger-dim);  color: var(--danger);  border: 2px solid var(--danger);  }

/* ── TRANSACTION LOG ── */
.tx-log {
  font-size: var(--font-size-xs);
  max-height: 110px;
  overflow-y: auto;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-top: var(--space-lg);
  border: 1px dashed var(--border);
  scrollbar-width: none;
}
.tx-log::-webkit-scrollbar { display: none; }

.log-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xs);
  color: var(--text-dim);
}

/* ── SETTLE ROW ── */
.settle-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.settle-row.paid { opacity: 0.4; }

/* ── PRESENCE BAR ── */
.presence-bar {
  text-align: center;
  font-size: var(--font-size-xs);
  color: var(--text-faint);
  padding: var(--space-sm) var(--space-lg);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.presence-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

/* ── UPDATE TOAST (version banner) ── */
#update-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  width: min(90vw, 380px);
  background: var(--night);
  color: #fff;
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 9000;
}

#update-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: all;
}

/* ── HOME HERO ── */
.hero-card {
  background: linear-gradient(135deg, var(--primary) 0%, #1d4ed8 100%);
  border: none;
  padding: var(--space-2xl);
  text-align: center;
  position: relative;
  overflow: hidden;
  color: #fff;
}

.hero-card .bg-emoji {
  position: absolute;
  top: -20px;
  right: -20px;
  font-size: 7rem;
  opacity: 0.08;
  transform: rotate(15deg);
  pointer-events: none;
}

.hero-card h2 {
  font-size: var(--font-size-2xl);
  font-weight: 900;
  line-height: 1.1;
  margin-bottom: var(--space-xl);
}

.hero-stats {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: var(--space-lg);
  align-items: center;
  background: rgba(255,255,255,0.12);
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(10px);
}

.hero-stat-label {
  font-size: 10px;
  font-weight: 800;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 2px;
}

.hero-stat-value {
  font-size: var(--font-size);
  font-weight: 900;
}

.hero-divider {
  height: 24px;
  background: rgba(255,255,255,0.2);
  width: 1px;
}

/* ── CREW GRID ── */
.crew-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: var(--space-md);
}

.crew-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: var(--space-md) var(--space-sm);
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  position: relative;
  cursor: default;
}

.crew-card .crew-name {
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  color: var(--text-dim);
}

.online-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  border: 2px solid var(--surface-2);
}

/* ── LEADERBOARD ── */
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.leaderboard-row.gold {
  background: rgba(255,215,0,0.08);
  border-color: rgba(255,215,0,0.25);
}

.rank-num {
  font-weight: 900;
  color: var(--text-faint);
  width: 20px;
}

/* ── CHIP ASSIST HINT ── */
.chip-hint {
  font-size: var(--font-size-xs);
  background: var(--night);
  color: #fff;
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  margin-top: var(--space-md);
  display: flex;
  gap: var(--space-md);
  align-items: center;
}

/* ── UTILITY ── */
.text-success { color: var(--success); }
.text-danger  { color: var(--danger);  }
.text-dim     { color: var(--text-dim); }
.text-faint   { color: var(--text-faint); }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.text-sm      { font-size: var(--font-size-sm); }
.text-xs      { font-size: var(--font-size-xs); }
.text-lg      { font-size: var(--font-size-lg); }
.font-bold    { font-weight: 700; }
.font-black   { font-weight: 900; }
.strike       { text-decoration: line-through; }
.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm       { gap: var(--space-sm); }
.gap-md       { gap: var(--space-md); }
.gap-lg       { gap: var(--space-lg); }
.w-full       { width: 100%; }
.mt-sm        { margin-top: var(--space-sm); }
.mt-md        { margin-top: var(--space-md); }
.mt-lg        { margin-top: var(--space-lg); }

/* ── MODALS ── */
.modal {
  margin: auto;
  border: none;
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  max-width: 400px;
  width: calc(100% - 32px);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
}

.modal-content {
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
}

