/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sky:    #0d1b2a;
  --sky2:   #1a2d42;
  --neon:   #00e5ff;
  --gold:   #ffd740;
  --green:  #69f0ae;
  --red:    #ff5252;
  --text:   #e8f4fd;
  --muted:  #7fa8c4;
  --card:   rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.12);
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--sky);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Auth bar ─────────────────────────────────────────────────────────── */
#authBar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(0,0,0,0.3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 52px;
}

#userInfo { display: flex; align-items: center; gap: 8px; flex: 1; }
#userAvatar { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--neon); }
#userName { font-size: 0.9rem; font-weight: 600; }

/* ── Screens ──────────────────────────────────────────────────────────── */
.screen {
  display: none;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  animation: fadeIn 0.25s ease;
}
.screen.active { display: flex; }

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

/* ── Hero (sign-in / searching / waiting) ─────────────────────────────── */
.hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 340px;
  width: 100%;
}
.hero h1 { font-size: 2.4rem; letter-spacing: -0.5px; }
.hero h2 { font-size: 1.5rem; }
.hero p  { color: var(--text); font-size: 1rem; }
.hero-icon { font-size: 5rem; filter: drop-shadow(0 0 18px var(--neon)); }
.spin-icon { font-size: 3rem; animation: spin 2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Lobby card ───────────────────────────────────────────────────────── */
.lobby-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
}
.lobby-card h2 { font-size: 1.6rem; }

.stat-row {
  display: flex;
  justify-content: center;
  gap: 24px;
  font-size: 0.9rem;
  color: var(--muted);
}
.stat-row strong { color: var(--neon); font-size: 1.1rem; }

#walletBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  gap: 10px;
  font-size: 0.85rem;
}

#walletInfo {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  text-align: left;
}

#walletStatus { color: var(--muted); }
#walletStatus.ok  { color: var(--green); }
#walletStatus.err { color: var(--red); }
#walletStatus.low { color: var(--gold); }

.usdc-balance {
  font-size: 0.75rem;
  color: var(--neon);
  font-weight: 600;
}
.usdc-balance.low {
  color: var(--gold);
}

#walletActions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-link {
  color: var(--neon);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--neon);
  border-radius: 20px;
  transition: background 0.2s;
  white-space: nowrap;
}
.btn-link:hover {
  background: rgba(0, 229, 255, 0.1);
}

.pay-note { font-size: 0.8rem; color: var(--muted); }
.pay-note strong { color: var(--gold); }

/* ── Buttons ──────────────────────────────────────────────────────────── */
button { cursor: pointer; border: none; font-family: inherit; font-size: 0.95rem; }

.btn-primary {
  background: linear-gradient(135deg, var(--neon), #0091ea);
  color: #000;
  font-weight: 700;
  padding: 13px 28px;
  border-radius: 50px;
  transition: opacity 0.2s, transform 0.1s;
  width: 100%;
}
.btn-primary:hover:not(:disabled) { opacity: 0.88; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 50px;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--card); }

#signInBtn  { background: #fff; color: #333; font-weight: 600; padding: 8px 20px; border-radius: 50px; }
#signOutBtn { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 6px 14px; border-radius: 50px; font-size: 0.85rem; }

/* ── Waiting screen extras ────────────────────────────────────────────── */
.avatar-lg {
  width: 72px; height: 72px; border-radius: 50%;
  border: 3px solid var(--neon);
  object-fit: cover;
}
.round-dots { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }
.round-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--border);
  transition: background 0.3s;
}
.round-dot.win  { background: var(--green); }
.round-dot.loss { background: var(--red); }

/* ── Game header ──────────────────────────────────────────────────────── */
#screenGame { flex-direction: column; gap: 0; padding: 0; justify-content: flex-start; }

#gameHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(0,0,0,0.35);
  border-bottom: 1px solid var(--border);
  width: 100%;
  max-width: 400px;
  align-self: center;
}

.player-tag {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.8rem; font-weight: 600;
  max-width: 130px;
}
.player-tag.right { flex-direction: row-reverse; }
.tag-avatar { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border); }
.tag-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 65px; }

#roundBadge {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(255,215,64,0.1);
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
}

.win-pips { letter-spacing: 2px; font-size: 0.75rem; }

/* ── Canvas wrapper ───────────────────────────────────────────────────── */
#canvasWrap {
  position: relative;
  align-self: center;
  flex: 1;
  width: 100%;
  max-width: 400px;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  background: #1a3a5c;
  /* keep aspect ratio — canvas is 400×500 */
  aspect-ratio: 400 / 500;
  max-height: calc(100dvh - 52px - 48px - 2px);
  object-fit: contain;
}

/* ── Overlays ─────────────────────────────────────────────────────────── */
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  background: rgba(0,0,0,0.62);
  text-align: center;
  padding: 24px;
}
.overlay.hidden { display: none; }

.overlay h2 { font-size: 1.8rem; }
.overlay p  { font-size: 1rem; }
.big-text   { font-size: 1.3rem; font-weight: 700; color: var(--neon); }

/* ── Misc helpers ─────────────────────────────────────────────────────── */
.muted  { color: var(--muted); font-size: 0.9rem; }
.center { text-align: center; }

#lobbyStatus { min-height: 1.2em; }

.btn-training {
  background: transparent;
  border: 1px dashed var(--green);
  color: var(--green);
  font-weight: 600;
  padding: 11px 28px;
  border-radius: 50px;
  width: 100%;
  transition: background 0.2s;
}
.btn-training:hover { background: rgba(105,240,174,0.1); }

/* ── Leaderboard ──────────────────────────────────────────────────────── */
#leaderboard {
  margin-top: 4px;
  text-align: left;
}
#leaderboard h3 {
  font-size: 1rem;
  color: var(--gold);
  margin-bottom: 10px;
  text-align: center;
}
#lbList {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
}
.lb-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--neon);
  object-fit: cover; flex-shrink: 0;
}
.lb-avatar-placeholder {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--border); display: flex;
  align-items: center; justify-content: center;
  font-size: 0.8rem; flex-shrink: 0;
}
.lb-name  { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-wins  { color: var(--neon); font-weight: 700; white-space: nowrap; }
.lb-streak { color: var(--gold); font-size: 0.8rem; }

/* How-it-works card in lobby */
.how-it-works {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  text-align: left;
}
.hiw-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.3rem 0;
  font-size: 0.88rem;
  color: #c0c8d8;
  line-height: 1.4;
}
.hiw-row + .hiw-row { border-top: 1px solid rgba(255,255,255,0.05); }
.hiw-icon { font-size: 1rem; flex-shrink: 0; margin-top: 0.05rem; }
.hiw-row strong { color: #e8f0ff; }

/* Prize payout line on win screen */
.match-payout {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: #4ade80;
  text-shadow: 0 0 12px rgba(74, 222, 128, 0.7);
  animation: pulse-green 1.5s ease-in-out infinite;
}
@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}
