/* ============================================================
   SFWCricket — Global Stylesheet
   Dark sports dashboard. Mobile-first. No frameworks.
   ============================================================ */

/* ── Design Tokens ── */
:root {
  /* Background */
  --color-bg:          #0a0f0d;
  --color-bg-subtle:   #0e1510;
  --color-surface:     #111a14;
  --color-surface-2:   #182418;
  --color-surface-3:   #1f3027;
  --color-border:      #1e2e22;
  --color-border-2:    #2a4030;

  /* Brand */
  --color-green:       #1a472a;
  --color-green-mid:   #2d6a4f;
  --color-primary:     #22c55e;
  --color-primary-dk:  #16a34a;
  --color-primary-glow:rgba(34,197,94,0.18);

  /* Accents */
  --color-accent:      #00e5ff;
  --color-accent-dk:   #00b8cc;
  --color-accent-glow: rgba(0,229,255,0.15);
  --color-gold:        #f0c040;
  --color-gold-dk:     #d97706;

  /* Ball result colors */
  --ball-dot:    #374151;
  --ball-one:    #374151;
  --ball-two:    #374151;
  --ball-three:  #374151;
  --ball-four:   #16a34a;
  --ball-six:    #7c3aed;
  --ball-wicket: #dc2626;
  --ball-wide:   #d97706;
  --ball-nb:     #d97706;

  /* Danger */
  --color-danger:      #ef4444;
  --color-danger-lt:   rgba(239,68,68,0.15);

  /* Text */
  --color-text:        #f0f4f2;
  --color-text-muted:  #6b8a72;
  --color-text-dim:    #3d5445;
  --color-white:       #ffffff;
  --color-overlay:     rgba(0,0,0,0.7);

  /* Radii */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --radius-xl:   22px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:   0 1px 4px rgba(0,0,0,0.4);
  --shadow-md:   0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:   0 8px 32px rgba(0,0,0,0.6);
  --glow-green:  0 0 20px rgba(34,197,94,0.25);
  --glow-accent: 0 0 20px rgba(0,229,255,0.2);

  /* Layout */
  --font-base:      'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --scorebar-h:     88px;
  --shotbar-h:      96px;
  --scorebar-h-mob: 100px;
  --shotbar-h-mob:  112px;
  --header-h:       52px;
  --max-w:          480px;
  --max-w-wide:     1200px;
}

/* ── Day Mode Token Overrides ── */
body.day-mode {
  --color-bg:           #f0faf4;
  --color-bg-subtle:    #e6f4ec;
  --color-surface:      #ffffff;
  --color-surface-2:    #f0faf4;
  --color-surface-3:    #ddf0e4;
  --color-border:       #c6e2cf;
  --color-border-2:     #a8d4b5;

  --color-green:        #bbf7d0;
  --color-green-mid:    #86efac;
  --color-primary:      #16a34a;
  --color-primary-dk:   #15803d;
  --color-primary-glow: rgba(22,163,74,0.12);

  --color-accent:       #0891b2;
  --color-accent-dk:    #0e7490;
  --color-accent-glow:  rgba(8,145,178,0.12);
  --color-gold:         #b45309;
  --color-gold-dk:      #92400e;

  --ball-dot:    #9ca3af;

  --color-danger:      #dc2626;
  --color-danger-lt:   rgba(220,38,38,0.1);

  --color-text:        #0f1f14;
  --color-text-muted:  #4b7a58;
  --color-text-dim:    #86ad8e;
  --color-overlay:     rgba(0,0,0,0.45);

  --shadow-sm:   0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg:   0 8px 24px rgba(0,0,0,0.12);
  --glow-green:  0 0 16px rgba(22,163,74,0.2);
  --glow-accent: 0 0 16px rgba(8,145,178,0.15);
}

/* Day mode: game canvas background */
body.day-mode #game-container { background: #d1fae5; }

/* Day mode: run popup text shadows muted */
body.day-mode .run-popup        { text-shadow: 0 2px 8px rgba(0,0,0,0.15); }
body.day-mode .run-popup--six   { color: #7c3aed; text-shadow: 0 0 12px rgba(124,58,237,0.35); }
body.day-mode .run-popup--four  { color: #15803d; text-shadow: 0 0 12px rgba(21,128,61,0.35); }
body.day-mode .run-popup--wicket{ color: #dc2626; text-shadow: 0 0 12px rgba(220,38,38,0.35); }

/* Day mode: home hero radial tint */
body.day-mode .home-hero::before {
  background: radial-gradient(ellipse 80% 60% at 50% 110%, #86efac 0%, transparent 70%);
  opacity: 0.4;
}

/* ── Theme Toggle Button ── */
#btn-theme {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--color-border-2);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: 1rem;
  transition: background 0.15s, border-color 0.15s, transform 0.2s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
#btn-theme:hover {
  background: var(--color-surface-3);
  border-color: var(--color-green-mid);
  transform: rotate(20deg);
}
#btn-theme:active { transform: scale(0.92); }

/* ── Theme transition — smooth mode switch ── */
body, body * {
  transition-property: background-color, border-color, color, box-shadow;
  transition-duration: 0.25s;
  transition-timing-function: ease;
}
/* Exclude animations from the broad transition override */
body .run-popup,
body .ball-chip,
body .over-summary,
body .tap-zone-hint,
body .score-update,
body .score-flash,
body .ball-chip-new,
body .shot-btn-ripple,
body .wicket-shake,
body .flash-four,
body .flash-six,
body .flash-wicket {
  transition: none;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-base);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  overflow-x: hidden;
}
button { cursor: pointer; border: none; background: none; font-family: inherit; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }

/* ============================================================
   HEADER (Home screen only)
   ============================================================ */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  /* Hidden during game screen — toggled by JS */
}
.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
}
.logo { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.logo-icon { font-size: 1.25rem; line-height: 1; }
.logo-text {
  font-size: 1rem;
  font-weight: 900;
  color: var(--color-primary);
  letter-spacing: -0.3px;
}

/* ── Auth area ── */
#auth-area { display: flex; align-items: center; gap: 10px; }

.btn-google {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s;
}
.btn-google:hover { background: var(--color-surface-3); border-color: var(--color-green-mid); }

.user-profile { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--color-primary);
  object-fit: cover;
}
.user-name {
  font-size: 0.8rem; font-weight: 600;
  max-width: 90px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-signout {
  font-size: 0.7rem; font-weight: 500;
  color: var(--color-text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  transition: background 0.15s;
}
.btn-signout:hover { background: var(--color-surface-2); }

/* ============================================================
   SCREENS
   ============================================================ */
#app-shell { max-width: var(--max-w); margin: 0 auto; }
.screen { display: none; }
.screen.active { display: block; }

/* App header always visible */

/* ============================================================
   HOME SCREEN
   ============================================================ */
.home-hero {
  padding: 28px 22px 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: relative;
  overflow: hidden;
}
/* subtle pitch-texture gradient overlay */
.home-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 110%, var(--color-green) 0%, transparent 70%);
  opacity: 0.25;
  pointer-events: none;
}
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--color-primary);
  border: 1px solid var(--color-primary-dk);
  background: var(--color-primary-glow);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  margin-bottom: 14px;
  position: relative;
}
.home-hero h1 {
  font-size: 2.5rem;
  font-weight: 900;
  line-height: 1.08;
  color: var(--color-text);
  letter-spacing: -1.5px;
  position: relative;
}
.hero-sub {
  margin-top: 10px;
  font-size: 0.84rem;
  color: var(--color-text-muted);
  position: relative;
}

/* ── Game List — 2-column square grid ── */
.game-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 16px;
  background: var(--color-bg-subtle);
}
.game-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  aspect-ratio: 3 / 2;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background 0.12s, border-color 0.12s, transform 0.1s, box-shadow 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.game-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 70% at 50% 110%, var(--color-green) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.game-card:hover::before, .game-card:active::before { opacity: 0.18; }
.game-card:hover  { background: var(--color-surface-2); border-color: var(--color-border-2); box-shadow: var(--shadow-md); }
.game-card:active { transform: scale(0.97); }

.game-card-icon {
  font-size: 1.6rem;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius-md);
  flex-shrink: 0;
  margin-bottom: 2px;
}
.game-card-info {
  flex: 1;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.game-card-title {
  font-size: 0.85rem; font-weight: 800;
  color: var(--color-text);
  letter-spacing: -0.3px;
  line-height: 1.2;
  margin-bottom: 3px;
}
.game-card-desc {
  font-size: 0.68rem;
  color: var(--color-text-muted);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.game-card-badge {
  position: absolute;
  top: 12px; right: 12px;
  font-size: 0.55rem; font-weight: 700;
  padding: 3px 7px;
  border-radius: var(--radius-full);
  background: var(--color-surface-3);
  color: var(--color-primary);
  border: 1px solid var(--color-primary-dk);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.game-card-badge.daily {
  color: var(--color-gold);
  border-color: var(--color-gold-dk);
  background: rgba(240,192,64,0.08);
}
.game-card-badge--soon {
  color: var(--color-text-dim);
  border-color: var(--color-border-2);
  background: var(--color-surface-2);
  opacity: 0.85;
}
/* Coming-soon card — dimmed, non-interactive */
.game-card--coming-soon {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}
/* Remove the row-style chevron arrow */
.game-card::after { display: none; }

/* ============================================================
   GAME SCREEN — full viewport layout
   ============================================================ */
#screen-game.active {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header-h));
  overflow: hidden;
  background: var(--color-bg);
}

/* ── BROADCAST SCOREBOARD BAR ── */
.scoreboard {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 6px 14px 4px;
  position: relative;
  z-index: 10;
}
.score-top-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

/* subtle green underlighting */
.scoreboard::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--color-green-mid), transparent);
}

/* Left: team + score + last over balls */
.score-left {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.score-team-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.score-team {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.score-main {
  display: flex;
  align-items: baseline;
  gap: 1px;
}
.score-runs {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -2px;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.score-sep {
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--color-text-dim);
  margin: 0 1px;
  line-height: 1;
}
.score-wickets {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--color-text-muted);
  letter-spacing: -0.5px;
  line-height: 1;
}
.score-balls-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  width: 100%;
}
.run-history-balls {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

/* Center: overs + RR + target */
.score-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
}
.score-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.score-meta-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.score-meta-divider {
  width: 1px;
  height: 20px;
  background: var(--color-border-2);
  flex-shrink: 0;
}
.score-label {
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--color-text-dim);
}
.score-meta-val {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -0.3px;
  font-variant-numeric: tabular-nums;
}
.score-meta-val--accent { color: var(--color-accent); }

/* Game title strip (below scoreboard) */
.game-title-strip {
  display: none;
  padding: 4px 14px;
  background: var(--color-bg-subtle);
  border-bottom: 1px solid var(--color-border);
}
.game-title-bar {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--color-text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
#screen-game.active .game-title-strip {
  display: block;
}

/* Right: nav buttons */
.score-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.score-topbar-btns {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* ── Ball Chips (used in scoreboard row) ── */
.ball-chip {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6rem; font-weight: 800;
  flex-shrink: 0;
  border: 1.5px solid transparent;
}
.ball-chip.dot    { background: var(--color-surface-3); color: var(--color-text-dim); border-color: var(--color-border-2); }
.ball-chip.run-1,
.ball-chip.run-2,
.ball-chip.run-3  { background: rgba(34,197,94,0.12); color: #4ade80; border-color: rgba(34,197,94,0.25); }
.ball-chip.run-4  { background: rgba(22,163,74,0.2);  color: #22c55e; border-color: rgba(22,163,74,0.4); }
.ball-chip.run-6  { background: rgba(124,58,237,0.2); color: #a78bfa; border-color: rgba(124,58,237,0.4); }
.ball-chip.wicket { background: rgba(220,38,38,0.2);  color: #f87171; border-color: rgba(220,38,38,0.4); }
.ball-chip.wide   { background: rgba(217,119,6,0.15); color: #fbbf24; border-color: rgba(217,119,6,0.3); }
.ball-chip.no-ball{ background: rgba(217,119,6,0.15); color: #fbbf24; border-color: rgba(217,119,6,0.3); }
.ball-chip-sep    { background: transparent; border-color: transparent; color: var(--color-text-muted); font-size: 0.75rem; font-weight: 400; width: 12px; }

/* ── GAMEPLAY AREA ── */
#game-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0d1f14;
  min-height: 0;
}
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
#game-ui {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  overflow: hidden;
}

/* ── Result Overlay ── */
.game-result {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 13, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.game-result.hidden { display: none; }
.result-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  text-align: center;
  width: 88%;
  max-width: 320px;
  box-shadow: var(--shadow-lg), var(--glow-green);
}
.result-icon  { font-size: 3rem; margin-bottom: 10px; line-height: 1; }
.result-title { font-size: 1.5rem; font-weight: 900; color: var(--color-text); letter-spacing: -0.5px; }
.result-message {
  font-size: 0.84rem; color: var(--color-text-muted);
  margin: 8px 0 16px; line-height: 1.5;
}
.result-score {
  font-size: 3rem; font-weight: 900;
  color: var(--color-primary);
  margin-bottom: 24px;
  letter-spacing: -3px; line-height: 1;
  text-shadow: var(--glow-green);
}
.result-actions { display: flex; gap: 10px; justify-content: center; }

/* ── BOTTOM SHOT CONTROLS ── */
.game-actions {
  flex-shrink: 0;
  min-height: var(--shotbar-h);
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

/* ============================================================
   SHARED BUTTONS
   ============================================================ */
.btn-icon {
  font-size: 0.8rem; font-weight: 600;
  color: var(--color-text-muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn-icon:hover {
  background: var(--color-surface-2);
  border-color: var(--color-border-2);
  color: var(--color-text);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 22px;
  border-radius: var(--radius-full);
  font-size: 0.88rem; font-weight: 700;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-width: 110px;
  letter-spacing: -0.1px;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--color-primary);
  color: #000;
  box-shadow: 0 2px 12px rgba(34,197,94,0.3);
}
.btn-primary:hover { background: #4ade80; }

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

.btn-accent {
  background: var(--color-accent);
  color: #000;
  box-shadow: 0 2px 12px rgba(0,229,255,0.25);
}
.btn-accent:hover { background: #67f0ff; }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  box-shadow: 0 2px 8px rgba(239,68,68,0.3);
}

/* ── Shot Selector buttons (injected by game modules) ── */
.shot-selector {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 10px 14px 4px;
  width: 100%;
}
.shot-btn {
  flex: 1;
  max-width: 110px;
  padding: 10px 6px;
  border-radius: var(--radius-md);
  font-size: 0.72rem; font-weight: 700;
  border: 1.5px solid var(--color-border-2);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  transition: all 0.15s;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.shot-btn:active { transform: scale(0.96); }
.shot-btn:hover  { background: var(--color-surface-3); border-color: var(--color-green-mid); color: var(--color-text); }
.shot-btn.active {
  border-color: var(--color-primary);
  background: var(--color-primary-glow);
  color: var(--color-primary);
}
.shot-btn[data-shot="safe"].active    { border-color: #22c55e; color: #4ade80; background: rgba(34,197,94,0.1); }
.shot-btn[data-shot="natural"].active { border-color: var(--color-accent); color: var(--color-accent); background: var(--color-accent-glow); }
.shot-btn[data-shot="power"].active   { border-color: #f97316; color: #fb923c; background: rgba(249,115,22,0.1); }
.shot-btn-icon  { font-size: 1.3rem; display: block; margin-bottom: 2px; }
.shot-btn-label { font-size: 0.68rem; }

/* Large tap button */
.btn-tap {
  width: 100%; max-width: 300px;
  padding: 16px;
  font-size: 1rem;
  border-radius: var(--radius-lg);
  background: var(--color-primary);
  color: #000;
  font-weight: 800;
  letter-spacing: -0.2px;
  box-shadow: 0 4px 20px rgba(34,197,94,0.25);
  transition: background 0.12s, transform 0.1s, box-shadow 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.btn-tap:hover  { background: #4ade80; box-shadow: 0 4px 28px rgba(34,197,94,0.4); }
.btn-tap:active { transform: scale(0.98); }

/* ============================================================
   MODAL
   ============================================================ */
.modal {
  position: fixed; inset: 0;
  z-index: 200;
  display: flex; align-items: flex-end;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: var(--color-overlay);
  backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  width: 100%; max-width: var(--max-w);
  margin: 0 auto;
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border: 1px solid var(--color-border-2);
  border-bottom: none;
  max-height: 80dvh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0;
  background: var(--color-surface);
  z-index: 1;
}
.modal-header h2 { font-size: 1rem; font-weight: 800; letter-spacing: -0.2px; }
.btn-close {
  font-size: 1rem; color: var(--color-text-muted);
  padding: 4px 8px; border-radius: var(--radius-sm);
  transition: background 0.12s;
}
.btn-close:hover { background: var(--color-surface-2); color: var(--color-text); }
.modal-tabs {
  display: flex; border-bottom: 1px solid var(--color-border);
  padding: 0 16px;
}
.tab-btn {
  flex: 1; padding: 12px 0;
  font-size: 0.8rem; font-weight: 600;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn.active { color: var(--color-primary); border-color: var(--color-primary); }
.leaderboard-content { padding: 0 0 16px; }
.lb-loading {
  text-align: center; color: var(--color-text-muted);
  padding: 36px 0; font-size: 0.84rem;
}
.lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--color-border);
  transition: background 0.1s;
}
.lb-row:last-child { border-bottom: none; }
.lb-row:hover { background: var(--color-surface-2); }
.lb-rank {
  width: 26px; text-align: center;
  font-size: 0.78rem; font-weight: 700;
  color: var(--color-text-muted); flex-shrink: 0;
}
.lb-rank.gold   { color: var(--color-gold); font-size: 1rem; }
.lb-rank.silver { color: #94a3b8; font-size: 0.95rem; }
.lb-rank.bronze { color: #a16207; font-size: 0.9rem; }
.lb-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-2);
}
.lb-name  { flex: 1; font-size: 0.84rem; font-weight: 600; }
.lb-score { font-size: 0.92rem; font-weight: 800; color: var(--color-primary); letter-spacing: -0.3px; }

/* ── How to Play Modal ── */
.how-to-play-content { padding-bottom: 16px; }
.htp-body { padding: 0 20px 8px; }
.htp-game-name {
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--color-primary); margin: 14px 0 12px;
}
.htp-steps { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-direction: column; gap: 14px; }
.htp-step {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 12px 14px;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: 10px;
}
.htp-step-icon { font-size: 1.4rem; flex-shrink: 0; line-height: 1.2; }
.htp-step-heading { display: block; font-size: 0.88rem; font-weight: 700; margin-bottom: 2px; }
.htp-step-text { font-size: 0.8rem; color: var(--color-text-muted); margin: 0; line-height: 1.45; }
.htp-shots { background: var(--color-bg-subtle); border: 1px solid var(--color-border); border-radius: 10px; overflow: hidden; }
.htp-shots-heading {
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--color-text-muted);
  padding: 10px 14px 6px; margin: 0;
}
.htp-shot-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid var(--color-border);
  gap: 10px;
}
.htp-shot-name { font-size: 0.84rem; font-weight: 700; }
.htp-shot-desc { font-size: 0.75rem; color: var(--color-text-muted); }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface-3);
  color: var(--color-text);
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius-full);
  padding: 10px 20px;
  font-size: 0.8rem; font-weight: 600;
  z-index: 300;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.3s;
}
.toast.hidden { display: none; }

/* ============================================================
   ENGINE ANIMATIONS
   ============================================================ */

/* ── Run Popup ── */
.run-popup {
  position: absolute;
  left: 50%; top: 40%;
  transform: translateX(-50%) translateY(0);
  font-size: 2.4rem; font-weight: 900;
  color: var(--color-primary);
  pointer-events: none; opacity: 1;
  white-space: nowrap;
  text-shadow: 0 0 20px rgba(34,197,94,0.6);
  z-index: 50;
  letter-spacing: -1px;
}
.run-popup--animate {
  animation: runPopupFloat 0.9s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.run-popup--edge    { color: #fbbf24; font-size: 1.4rem; }
.run-popup--streak  { color: #fb923c; font-size: 1.7rem; top: 28%; }
.run-popup--freehit { color: var(--color-accent); font-size: 1.7rem; top: 28%; }
.run-popup--wicket  { color: var(--color-danger); text-shadow: 0 0 20px rgba(239,68,68,0.6); }
.run-popup--six     { color: #a78bfa; text-shadow: 0 0 24px rgba(124,58,237,0.7); }
.run-popup--four    { color: #4ade80; text-shadow: 0 0 20px rgba(34,197,94,0.6); }

@keyframes runPopupFloat {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0)    scale(0.7); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(-10px) scale(1.15); }
  65%  { opacity: 1; transform: translateX(-50%) translateY(-50px) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-80px) scale(0.9); }
}

/* ── Score Flash ── */
.score-flash { animation: scoreFlash 0.38s ease-out; }
@keyframes scoreFlash {
  0%   { color: var(--color-text);    transform: scale(1); }
  40%  { color: var(--color-primary); transform: scale(1.22); }
  100% { color: var(--color-text);    transform: scale(1); }
}

/* ── Score Count-Up ── */
.score-update { animation: scoreCountUp 0.2s cubic-bezier(0.22,1,0.36,1); }
@keyframes scoreCountUp {
  0%   { transform: translateY(6px); opacity: 0; }
  100% { transform: translateY(0);   opacity: 1; }
}

/* ── Screen Edge Flash (canvas border glow) ── */
.flash-four {
  animation: edgeFlashFour 0.5s ease-out forwards;
}
.flash-six {
  animation: edgeFlashSix 0.7s ease-out forwards;
}
.flash-wicket {
  animation: edgeFlashWicket 0.6s ease-out forwards;
}
@keyframes edgeFlashFour {
  0%   { box-shadow: inset 0 0 0px   0px rgba(34,197,94,0); }
  25%  { box-shadow: inset 0 0 50px 10px rgba(34,197,94,0.55); }
  100% { box-shadow: inset 0 0 0px   0px rgba(34,197,94,0); }
}
@keyframes edgeFlashSix {
  0%   { box-shadow: inset 0 0 0px   0px rgba(124,58,237,0); }
  20%  { box-shadow: inset 0 0 80px 16px rgba(124,58,237,0.65); }
  55%  { box-shadow: inset 0 0 60px 10px rgba(167,139,250,0.45); }
  100% { box-shadow: inset 0 0 0px   0px rgba(124,58,237,0); }
}
@keyframes edgeFlashWicket {
  0%   { box-shadow: inset 0 0 0px   0px rgba(239,68,68,0); }
  15%  { box-shadow: inset 0 0 80px 20px rgba(239,68,68,0.7); }
  100% { box-shadow: inset 0 0 0px   0px rgba(239,68,68,0); }
}

/* ── Ball Chip Slide-In ── */
.ball-chip-new {
  animation: chipIn 0.25s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes chipIn {
  0%   { transform: scale(0) rotate(-15deg); opacity: 0; }
  70%  { transform: scale(1.18) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0);       opacity: 1; }
}

/* ── Shot Button Ripple ── */
.shot-btn-ripple {
  animation: shotRipple 0.35s ease-out forwards;
}
@keyframes shotRipple {
  0%   { box-shadow: 0 0 0 0   rgba(34,197,94,0.45); }
  100% { box-shadow: 0 0 0 14px rgba(34,197,94,0); }
}

/* ── Wicket Shake (applied to scoreboard wicket value) ── */
.wicket-shake {
  animation: wicketShake 0.45s ease-out;
}
@keyframes wicketShake {
  0%,100% { transform: translateX(0); }
  15%     { transform: translateX(-7px); }
  30%     { transform: translateX( 7px); }
  45%     { transform: translateX(-4px); }
  60%     { transform: translateX( 4px); }
  80%     { transform: translateX(-2px); }
}

/* ── RRR Urgency colors ── */
.rrr-safe   { color: var(--color-primary) !important; }
.rrr-warn   { color: var(--color-gold) !important; }
.rrr-danger {
  color: var(--color-danger) !important;
  animation: rrrPulse 0.8s ease-in-out infinite alternate;
}
@keyframes rrrPulse {
  from { opacity: 1; }
  to   { opacity: 0.55; }
}

/* ── Over Summary Banner ── */
.over-summary {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  background: var(--color-surface);
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius-lg);
  padding: 14px 24px;
  text-align: center;
  pointer-events: none;
  z-index: 40;
  box-shadow: var(--shadow-lg), var(--glow-green);
  opacity: 0;
  animation: overSummaryIn 0.3s cubic-bezier(0.34,1.56,0.64,1) 0.1s forwards,
             overSummaryOut 0.25s ease-in 1.6s forwards;
  min-width: 200px;
}
.over-summary-label {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}
.over-summary-runs {
  font-size: 2rem;
  font-weight: 900;
  color: var(--color-primary);
  letter-spacing: -2px;
  line-height: 1;
}
.over-summary-runs span {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: 0;
  margin-left: 4px;
}
.over-summary-balls {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 8px;
}
@keyframes overSummaryIn {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.82); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes overSummaryOut {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}

/* ── Canvas Tap Zone Hints (visible on first play) ── */
.tap-zone-hint {
  position: absolute;
  top: 0; bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 18px;
  pointer-events: none;
  opacity: 0;
  animation: tapHintFade 2.5s ease-out 0.5s forwards;
}
.tap-zone-hint--left  { left: 0;        width: 33.33%; }
.tap-zone-hint--mid   { left: 33.33%;   width: 33.33%; }
.tap-zone-hint--right { left: 66.66%;   width: 33.34%; }
.tap-zone-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.3);
  padding: 3px 10px;
  border-radius: var(--radius-full);
}
@keyframes tapHintFade {
  0%,30% { opacity: 1; }
  100%   { opacity: 0; }
}

/* ── Hot Streak Banner ── */
.hot-streak-banner {
  position: absolute; top: 10px; left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #ea580c, #f97316);
  color: #fff;
  font-size: 0.68rem; font-weight: 800;
  letter-spacing: 1px; padding: 5px 16px;
  border-radius: var(--radius-full);
  pointer-events: none; z-index: 30;
  text-transform: uppercase;
  animation: streakPulse 0.9s ease-in-out infinite alternate;
  box-shadow: 0 2px 12px rgba(234,88,12,0.5);
}
@keyframes streakPulse {
  from { box-shadow: 0 2px 8px  rgba(234,88,12,0.4); }
  to   { box-shadow: 0 2px 24px rgba(234,88,12,0.8); }
}

/* ── Free Hit Banner ── */
.freehit-banner {
  position: absolute; top: 10px; left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #0284c7, #00e5ff);
  color: #000;
  font-size: 0.68rem; font-weight: 800;
  letter-spacing: 1px; padding: 5px 16px;
  border-radius: var(--radius-full);
  pointer-events: none; z-index: 30;
  text-transform: uppercase;
  animation: freehitPulse 0.55s ease-in-out infinite alternate;
  box-shadow: var(--glow-accent);
}
@keyframes freehitPulse {
  from { opacity: 0.85; transform: translateX(-50%) scale(1); }
  to   { opacity: 1;    transform: translateX(-50%) scale(1.04); }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden { display: none !important; }
.text-muted  { color: var(--color-text-muted); }
.text-accent { color: var(--color-accent); }
.text-center { text-align: center; }

/* ── Sidebar elements (hidden on mobile) ── */
.sidebar-header,
.sidebar-game-nav { display: none; }

/* Button labels hidden on mobile, shown on desktop sidebar */
.btn-label { display: none; }

/* ============================================================
   RESPONSIVE — DESKTOP (≥900px)
   ============================================================ */
@media (min-width: 900px) {

  /* Header full-width */
  #app-header {
    position: fixed; width: 100%; left: 0;
  }
  .header-inner { max-width: 100%; padding: 0 40px; }

  /* Shell fills viewport */
  #app-shell {
    max-width: 100%;
    margin: 0;
    padding-top: var(--header-h);
    min-height: calc(100dvh - var(--header-h));
    background: transparent;
  }

  /* Home: full-width hero + grid */
  #screen-home.active {
    display: flex; flex-direction: column;
    min-height: calc(100dvh - var(--header-h));
  }
  .home-hero {
    padding: 64px 56px 48px;
    text-align: left;
  }
  .home-hero h1 { font-size: 3.6rem; max-width: 600px; }
  .hero-sub { font-size: 0.96rem; max-width: 480px; }
  .game-list {
    flex: 1;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    padding: 24px;
    background: var(--color-bg-subtle);
    align-content: start;
  }
  .game-card { padding: 20px; }

  /* Game screen: sidebar left, play area right */
  #screen-game.active {
    padding-top: var(--header-h);
    height: 100dvh;
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: 1fr auto;
    overflow: hidden;
  }

  /* ── Left sidebar ── */
  .scoreboard {
    grid-column: 1;
    grid-row: 1 / -1;
    height: auto;
    flex-direction: column;
    justify-content: flex-start;
    padding: 0;
    border-bottom: none;
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
  }
  .scoreboard::after { display: none; }

  /* Sidebar active game title header */
  .sidebar-header {
    display: flex;
    align-items: center;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--color-border);
  }
  .sidebar-game-title {
    font-size: 1rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text);
  }

  /* Score block */
  .score-top-row {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 18px 20px 16px;
    border-bottom: 1px solid var(--color-border);
  }
  .score-team-row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .score-runs    { font-size: 3.2rem; letter-spacing: -3px; }
  .score-sep     { font-size: 1.8rem; }
  .score-wickets { font-size: 1.6rem; }

  .score-balls-row {
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 14px 20px 14px;
    border-bottom: 1px solid var(--color-border);
    margin: 0;
  }
  .ball-chip { width: 28px; height: 28px; font-size: 0.65rem; }

  .score-center {
    align-items: flex-start;
    padding: 14px 20px 14px;
    border-bottom: 1px solid var(--color-border);
  }
  .score-meta-row { flex-wrap: wrap; gap: 12px; }
  .score-meta-item { align-items: flex-start; }
  .score-meta-divider { display: none; }
  .score-meta-val { font-size: 1.1rem; }

  /* Nav buttons */
  .score-right {
    align-items: flex-start;
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
  }
  .score-topbar-btns {
    flex-direction: column;
    gap: 6px;
    width: 100%;
  }
  .score-topbar-btns .btn-icon {
    width: 100%;
    text-align: left;
    padding: 9px 14px;
    border: 1px solid var(--color-border-2);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .score-topbar-btns .btn-label {
    display: inline;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-muted);
  }
  .score-topbar-btns .btn-icon:hover .btn-label {
    color: var(--color-text);
  }

  /* Game switcher nav */
  .sidebar-game-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 12px;
  }
  .sidebar-game-nav::before {
    content: 'Games';
    display: block;
    font-size: 0.58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-dim);
    padding: 0 8px 8px;
  }
  .sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: none;
    color: var(--color-text-muted);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    width: 100%;
  }
  .sidebar-nav-item:hover {
    background: var(--color-surface-2);
    border-color: var(--color-border-2);
    color: var(--color-text);
  }
  .sidebar-nav-item--active {
    background: var(--color-primary-glow);
    border-color: var(--color-primary-dk);
    color: var(--color-primary);
  }
  .sidebar-nav-icon { font-size: 1.1rem; flex-shrink: 0; width: 22px; text-align: center; }
  .sidebar-nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar-nav-badge {
    font-size: 0.52rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    background: var(--color-surface-3);
    color: var(--color-text-dim);
    border: 1px solid var(--color-border-2);
    flex-shrink: 0;
  }
  .sidebar-nav-item--active .sidebar-nav-badge {
    background: var(--color-primary-glow);
    color: var(--color-primary);
    border-color: var(--color-primary-dk);
  }
  .sidebar-nav-item--soon {
    opacity: 0.45;
    cursor: default;
    pointer-events: none;
  }
  .sidebar-nav-badge--soon {
    color: var(--color-text-dim);
    background: var(--color-surface-2);
    border-color: var(--color-border-2);
  }

  /* ── Right: play area — 60% width centered ── */
  #game-container {
    grid-column: 2;
    grid-row: 1;
    height: auto;
    display: flex;
    align-items: stretch;
    justify-content: center;
  }
  /* Inner wrapper constrains game-ui + canvas to 60% */
  #game-canvas { display: none; } /* canvas unused by all current games */
  #game-ui {
    position: relative;
    width: 60%;
    max-width: 560px;
    min-width: 320px;
    inset: unset;
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
  }

  .game-actions {
    grid-column: 2;
    grid-row: 2;
    min-height: var(--shotbar-h);
    border-left: 1px solid var(--color-border);
    justify-content: center;
  }

  /* Game title strip hidden on desktop (sidebar has it) */
  #game-title-strip { display: none !important; }

  .modal-panel { max-width: 560px; border-radius: var(--radius-xl); margin-bottom: 48px; }
  .modal { align-items: center; }
}

/* ── Tablet mid-range ── */
@media (min-width: 600px) and (max-width: 899px) {
  .scoreboard {
    --scorebar-h: 80px;
  }
  .score-runs { font-size: 1.8rem; }
}
