:root {
  --felt: #0d1f0f;
  --felt-mid: #162b18;
  --felt-light: #1e3d21;
  --chalk: #e8f0e9;
  --chalk-dim: #8fa892;
  --gold: #c9a84c;
  --gold-light: #e2c47a;
  --pocket: #080e09;
  --rail: #2a1a08;
  --cue: #d4a96a;
  --red: #c0392b;
  --stripe: #2980b9;
  --bg: #0a1a0b;
}

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

body {
  background: var(--bg);
  color: var(--chalk);
  font-family: 'DM Sans', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Felt texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.008) 2px, rgba(255,255,255,0.008) 4px),
    repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255,255,255,0.005) 2px, rgba(255,255,255,0.005) 4px);
  pointer-events: none;
  z-index: 0;
}

/* ── SCREENS ── */
.screen { display: none; position: relative; z-index: 1; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ── SPLASH ── */
#splash {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #1a3d1e 0%, var(--bg) 70%);
}

.splash-inner { text-align: center; padding: 2rem; }

.table-graphic {
  width: 280px;
  height: 160px;
  margin: 0 auto 2.5rem;
  position: relative;
}

.table-felt {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #0f2e12, #1a4d1e, #0f2e12);
  border-radius: 12px;
  border: 8px solid var(--rail);
  position: relative;
  box-shadow: 0 0 40px rgba(26,77,30,0.5), inset 0 0 30px rgba(0,0,0,0.4);
}

.pocket {
  width: 18px; height: 18px;
  background: var(--pocket);
  border-radius: 50%;
  position: absolute;
  box-shadow: 0 0 8px rgba(0,0,0,0.8);
}
.pocket.tl { top: -4px; left: -4px; }
.pocket.tm { top: -4px; left: 50%; transform: translateX(-50%); }
.pocket.tr { top: -4px; right: -4px; }
.pocket.bl { bottom: -4px; left: -4px; }
.pocket.bm { bottom: -4px; left: 50%; transform: translateX(-50%); }
.pocket.br { bottom: -4px; right: -4px; }

.ball {
  width: 16px; height: 16px;
  border-radius: 50%;
  position: absolute;
  box-shadow: inset -3px -3px 6px rgba(0,0,0,0.4), 2px 2px 6px rgba(0,0,0,0.3);
}
.ball.b1 { background: #f5c518; top: 50%; left: 30%; transform: translateY(-50%); }
.ball.b2 { background: #1a6fc4; top: 35%; left: 40%; }
.ball.b3 { background: #c0392b; top: 55%; left: 45%; }
.ball.b8 { background: #1a1a1a; top: 45%; left: 60%; }
.ball.b9 { background: #f5c518; width: 14px; height: 14px; top: 38%; left: 55%;
  background: linear-gradient(135deg, #f5c518 50%, white 50%); }

.logo-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(3rem, 10vw, 5.5rem);
  letter-spacing: 4px;
  line-height: 0.9;
  color: var(--chalk);
  text-shadow: 0 0 40px rgba(201,168,76,0.3);
}

.logo-title span {
  color: var(--gold);
  display: block;
}

.logo-sub {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  letter-spacing: 6px;
  color: var(--chalk-dim);
  margin-top: 0.5rem;
  text-transform: uppercase;
}

.splash-buttons {
  margin-top: 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

/* ── BUTTONS ── */
.btn {
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 1px;
  padding: 14px 28px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: var(--pocket);
  box-shadow: 0 4px 20px rgba(201,168,76,0.3);
}
.btn-gold:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(201,168,76,0.4); }

.btn-outline {
  background: transparent;
  color: var(--chalk);
  border: 1.5px solid rgba(232,240,233,0.3);
}
.btn-outline:hover { border-color: var(--gold); color: var(--gold); }

.btn-felt {
  background: var(--felt-light);
  color: var(--chalk);
  border: 1px solid rgba(255,255,255,0.1);
}
.btn-felt:hover { background: var(--felt-mid); }

.btn-red {
  background: var(--red);
  color: white;
}

.btn-sm {
  font-size: 0.8rem;
  padding: 8px 16px;
}

.btn-full { width: 100%; }

/* ── NAV ── */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(10,26,11,0.9);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.4rem;
  letter-spacing: 3px;
  color: var(--gold);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--felt-light), var(--gold));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1rem;
  color: var(--chalk);
  border: 2px solid var(--gold);
  cursor: pointer;
}

/* ── BOTTOM NAV ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  display: flex;
  background: rgba(10,26,11,0.97);
  border-top: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(20px);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.bnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0 8px;
  cursor: pointer;
  transition: all 0.2s;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--chalk-dim);
  min-width: 0;
}

.bnav-item.active { color: var(--gold); }
.bnav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.bnav-item span { font-size: 0.58rem; letter-spacing: 0.3px; font-weight: 500; white-space: nowrap; }

/* ── PAGE CONTENT ── */
.page-content {
  flex: 1;
  padding: 1.5rem;
  padding-bottom: 90px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.page-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2rem;
  letter-spacing: 2px;
  color: var(--chalk);
  margin-bottom: 1.5rem;
}

/* ── CARDS ── */
.card {
  background: var(--felt-mid);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-gold {
  border-color: rgba(201,168,76,0.3);
  background: linear-gradient(135deg, rgba(201,168,76,0.08), rgba(26,61,33,0.5));
}

/* ── RATING DISPLAY ── */
.rating-big {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 4rem;
  line-height: 1;
  color: var(--gold);
  letter-spacing: 2px;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1rem;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 3px;
  border: 2px solid;
  min-width: 3.2rem;
  text-align: center;
}

/* ── FORM ELEMENTS ── */
.form-group { margin-bottom: 1.2rem; }

label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--chalk-dim);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

input, select {
  width: 100%;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 4px;
  color: var(--chalk);
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  padding: 12px 14px;
  transition: border-color 0.2s;
  outline: none;
  -webkit-appearance: none;
}

input:focus, select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,168,76,0.1);
}

select option { background: var(--felt); }

/* ── GAME TYPE TABS ── */
.game-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.game-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.1rem;
  letter-spacing: 2px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.1);
  background: transparent;
  color: var(--chalk-dim);
  transition: all 0.2s;
}

.game-tab.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201,168,76,0.08);
}

/* ── MATCH HISTORY ── */
.match-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  margin-bottom: 0.6rem;
  border-left: 3px solid transparent;
  transition: all 0.2s;
}

.match-item.win { border-left-color: #2ecc71; }
.match-item.loss { border-left-color: var(--red); }
.match-item.pending { border-left-color: var(--gold); opacity: 0.8; }

.match-result-pill {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 0.9rem;
  letter-spacing: 1px;
  padding: 3px 10px;
  border-radius: 3px;
  min-width: 50px;
  text-align: center;
}

.win .match-result-pill { background: rgba(46,204,113,0.2); color: #2ecc71; }
.loss .match-result-pill { background: rgba(192,57,43,0.2); color: #e74c3c; }
.pending .match-result-pill { background: rgba(201,168,76,0.2); color: var(--gold); }

/* ── LEADERBOARD ── */
.lb-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  background: rgba(0,0,0,0.15);
  transition: background 0.2s;
}

.lb-item.you {
  background: rgba(201,168,76,0.1);
  border: 1px solid rgba(201,168,76,0.2);
}

.lb-rank-num {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.3rem;
  color: var(--chalk-dim);
  min-width: 28px;
  text-align: center;
}

.lb-rank-num.top3 { color: var(--gold); }

/* ── NOTIFICATION BADGE ── */
.notif-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--red);
  color: white;
  border-radius: 50%;
  width: 18px; height: 18px;
  font-size: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.notif-badge.hidden { display: none; }

/* ── STAT ROW ── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.stat-box {
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  padding: 0.9rem;
  text-align: center;
}

.stat-val {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.8rem;
  color: var(--chalk);
  line-height: 1;
}

.stat-lbl {
  font-size: 0.65rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--chalk-dim);
  margin-top: 4px;
}

/* ── STREAK ── */
.streak-flame {
  font-size: 1.4rem;
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--felt-mid);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px 16px 0 0;
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-handle {
  width: 36px; height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 0 auto 1.5rem;
}

.modal-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.6rem;
  letter-spacing: 2px;
  margin-bottom: 1.5rem;
}

/* ── SIGN IN FORM ── */
#auth-screen {
  justify-content: center;
  align-items: center;
  background: radial-gradient(ellipse at 30% 70%, #0d2a10 0%, var(--bg) 60%);
  padding: 2rem;
}

.auth-box {
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.5rem;
  letter-spacing: 4px;
  color: var(--gold);
  text-align: center;
  margin-bottom: 0.5rem;
}

.auth-sub {
  font-size: 0.8rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--chalk-dim);
  text-align: center;
  margin-bottom: 2.5rem;
}

/* ── CONFIRM MATCH BANNER ── */
.confirm-banner {
  background: linear-gradient(135deg, rgba(201,168,76,0.15), rgba(201,168,76,0.05));
  border: 1px solid rgba(201,168,76,0.4);
  border-radius: 8px;
  padding: 1.2rem;
  margin-bottom: 1rem;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(201,168,76,0.2); }
  50% { box-shadow: 0 0 0 8px rgba(201,168,76,0); }
}

/* ── RATING CHANGE ANIM ── */
.rating-change {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.1rem;
  letter-spacing: 1px;
}

.rating-change.pos { color: #2ecc71; }
.rating-change.neg { color: var(--red); }

/* ── DIVIDER ── */
.divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 1.5rem 0;
}

/* ── SECTION LABEL ── */
.section-label {
  font-size: 0.7rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--chalk-dim);
  margin-bottom: 0.8rem;
  font-weight: 600;
}

/* ── LOCATION SCOPE ── */
.scope-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.2rem;
}

.scope-tab {
  font-size: 0.75rem;
  letter-spacing: 1px;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.12);
  background: transparent;
  color: var(--chalk-dim);
  transition: all 0.2s;
  font-family: 'DM Sans', sans-serif;
}

.scope-tab.active {
  background: var(--gold);
  color: var(--pocket);
  border-color: var(--gold);
  font-weight: 600;
}

/* ── PROVISIONAL BADGE ── */
.prov-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  letter-spacing: 1px;
  color: var(--gold);
  background: rgba(201,168,76,0.1);
  border: 1px solid rgba(201,168,76,0.3);
  padding: 3px 10px;
  border-radius: 20px;
  margin-left: 8px;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--felt-light);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--chalk);
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 0.9rem;
  z-index: 300;
  animation: toastIn 0.3s ease;
  white-space: nowrap;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.text-gold { color: var(--gold); }
.text-dim { color: var(--chalk-dim); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.mono { font-family: 'DM Mono', monospace; }
.bold { font-weight: 600; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-center { text-align: center; }
.bebas { font-family: 'Bebas Neue', sans-serif; letter-spacing: 2px; }
.relative { position: relative; }

/* ── RULES PAGE ── */
.rule-item {
  display: flex;
  gap: 0.8rem;
  align-items: flex-start;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.rule-icon {
  font-size: 1.1rem;
  width: 24px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ── POOL BALL ICONS ── */
.ball-icon { display:inline-block; vertical-align:middle; margin-right:4px; }

/* ── SCOREKEEPER ── */
.frame-dot {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
  transition: background 0.3s;
}
.frame-dot.won { background: var(--gold); }
.frame-dot.lost { background: var(--red); }

.frame-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  margin-bottom: 0.4rem;
  background: rgba(0,0,0,0.15);
  font-size: 0.85rem;
}
.frame-item.frame-won { border-left: 3px solid var(--gold); }
.frame-item.frame-lost { border-left: 3px solid var(--red); }

/* ── FIND PLAYER ── */
.find-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.2rem;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
  padding: 4px;
}
.find-tab {
  flex: 1;
  font-size: 0.75rem;
  padding: 8px 4px;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--chalk-dim);
  transition: all 0.2s;
  font-family: 'DM Sans', sans-serif;
  font-weight: 500;
  text-align: center;
}
.find-tab.active {
  background: var(--felt-light);
  color: var(--chalk);
  border: 1px solid rgba(255,255,255,0.1);
}
.search-box { position: relative; margin-bottom: 0.8rem; }
.search-box input { padding-left: 40px; }
.search-icon {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--chalk-dim); width: 18px; height: 18px;
}
.player-result {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.8rem; border-radius: 6px; cursor: pointer;
  transition: background 0.15s; border: 1px solid transparent;
  margin-bottom: 0.4rem;
}
.player-result:hover {
  background: rgba(201,168,76,0.08);
  border-color: rgba(201,168,76,0.2);
}
.qr-wrapper {
  display: flex; flex-direction: column;
  align-items: center; padding: 1rem;
}
.qr-box {
  width: 160px; height: 160px;
  background: white; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 1rem;
  box-shadow: 0 0 30px rgba(201,168,76,0.2);
  overflow: hidden;
}
.online-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #2ecc71; box-shadow: 0 0 6px #2ecc71;
  display: inline-block; margin-right: 4px;
  animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.4} }
.nearby-venue-label {
  font-size: 0.65rem; letter-spacing: 2px; text-transform: uppercase;
  color: var(--chalk-dim); padding: 0.6rem 0 0.4rem;
  border-top: 1px solid rgba(255,255,255,0.05); margin-top: 0.4rem;
}
.selected-opponent-card {
  background: rgba(201,168,76,0.08);
  border: 1px solid rgba(201,168,76,0.3);
  border-radius: 8px; padding: 0.9rem 1rem;
  display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1.2rem;
}
.distance-badge {
  font-size: 0.65rem; color: #2ecc71;
  background: rgba(46,204,113,0.1);
  border: 1px solid rgba(46,204,113,0.2);
  border-radius: 10px; padding: 2px 8px;
  font-family: 'DM Mono', monospace;
}

/* ── RACE SELECTOR ── */
.race-opts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}

.race-opt {
  background: rgba(0,0,0,0.3);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.3rem;
  color: var(--chalk-dim);
  letter-spacing: 1px;
}

.race-opt.selected {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201,168,76,0.1);
}

.race-opt .race-k {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0px;
  color: var(--chalk-dim);
  margin-top: 2px;
}

/* ── PROFILE ── */
.profile-header {
  background: linear-gradient(135deg, var(--felt-light), var(--felt-mid));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  position: relative;
  overflow: hidden;
}

.profile-header::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201,168,76,0.15), transparent);
}

.profile-avatar-lg {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--felt-light), var(--gold));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.8rem;
  color: var(--chalk);
  border: 3px solid var(--gold);
  margin-bottom: 1rem;
  box-shadow: 0 0 20px rgba(201,168,76,0.3);
}
