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

:root {
  --gold: #f59e0b;
  --gold-light: #fbbf24;
  --gold-dark: #d97706;
  --red: #ef4444;
  --green: #10b981;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-light: #818cf8;

  /* Ball palette */
  --ball-white-bg: #f1f5f9;
  --ball-white-text: #0f172a;
  --ball-red-bg: #ef4444;
  --ball-red-text: #fff;
  --ball-gold-bg: #f59e0b;
  --ball-gold-text: #fff;
  --ball-star-bg: #8b5cf6;
  --ball-star-text: #fff;
  --ball-orange-bg: #f97316;
  --ball-orange-text: #fff;
  --ball-blue-bg: #3b82f6;
  --ball-blue-text: #fff;
  /* Per-grid dynamic vars (set by JS) */
  --ball-a-bg: #f1f5f9;
  --ball-a-text: #0f172a;
  --ball-b-bg: #ef4444;
  --ball-b-text: #fff;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Back link ── */
.back-bar {
  padding: 0.6rem 1.5rem;
  background: #0f172a;
  border-bottom: 1px solid #334155;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: #94a3b8;
  text-decoration: none;
  transition: color 0.2s;
}
.back-link:hover { color: #f8fafc; }

/* ── Lottery Selector Bar ── */
.lottery-selector-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.lottery-selector-bar::-webkit-scrollbar { display: none; }

.lottery-selector-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: max-content;
}

.lottery-selector-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
}

.lottery-selector {
  display: flex;
  gap: 0.5rem;
}

.lottery-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.5rem 0.9rem;
  border-radius: 0.625rem;
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.lottery-tab:hover {
  border-color: var(--primary-light);
  color: var(--text);
  background: var(--surface);
}

.lottery-tab.active {
  border-color: var(--gold);
  background: rgba(245, 158, 11, 0.1);
  color: var(--gold-light);
}

.lottery-tab-flag { font-size: 1.2rem; line-height: 1; }
.lottery-tab-name { font-size: 0.78rem; font-weight: 700; line-height: 1; }
.lottery-tab-region { font-size: 0.62rem; color: var(--text-muted); }
.lottery-tab.active .lottery-tab-region { color: var(--gold); opacity: 0.8; }

/* ── Header ── */
.game-header {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.jackpot-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.jackpot-icon { font-size: 2.2rem; line-height: 1; }
.jackpot-title { font-size: 1.1rem; font-weight: 700; color: var(--gold-light); }
.jackpot-subtitle { font-size: 0.72rem; color: var(--text-muted); }

.jackpot-display { flex: 1; text-align: center; }
.jackpot-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.jackpot-amount { font-size: 1.8rem; font-weight: 800; color: var(--gold-light); line-height: 1.1; }
.jackpot-odds { font-size: 0.68rem; color: var(--text-muted); margin-top: 0.1rem; }

.reset-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  white-space: nowrap;
}
.reset-btn:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--primary-light);
}

/* ── Main Layout ── */
.game-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 840px) {
  .game-main { grid-template-columns: 1fr; }
  .header-inner { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .jackpot-display { text-align: left; }
}

/* ── Panel Card ── */
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.panel-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Number Section ── */
.number-section { margin-bottom: 0; }
.number-section-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.35em;
  flex-wrap: wrap;
}
.number-section-note { font-weight: 400; opacity: 0.75; }

.white-ball-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
}

/* ── Ball buttons ── */
.ball-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.13s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.ball-btn:hover { border-color: var(--text-muted); color: var(--text); background: var(--surface); }

/* Selected states — use per-grid CSS vars injected by JS */
.ball-btn.selected-a {
  background: var(--ball-a-bg);
  border-color: var(--ball-a-bg);
  color: var(--ball-a-text);
}

/* B ball colors by lottery */
.ball-btn.selected-b {
  background: var(--ball-b-bg);
  border-color: var(--ball-b-bg);
  color: var(--ball-b-text);
}

/* Hint color on unselected B balls */
.ball-red-pick-btn    { border-color: rgba(239,68,68,.4);   color: rgba(239,68,68,.7); }
.ball-gold-pick-btn   { border-color: rgba(245,158,11,.4);  color: rgba(245,158,11,.7); }
.ball-star-pick-btn   { border-color: rgba(139,92,246,.4);  color: rgba(139,92,246,.7); }
.ball-orange-pick-btn { border-color: rgba(249,115,22,.4);  color: rgba(249,115,22,.7); }
.ball-blue-pick-btn   { border-color: rgba(59,130,246,.4);  color: rgba(59,130,246,.7); }

.ball-btn.disabled-ball { opacity: 0.28; cursor: not-allowed; pointer-events: none; }

/* ── Pick Actions ── */
.pick-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.btn-secondary {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-secondary:hover { background: var(--surface); color: var(--text); border-color: var(--primary-light); }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Speed Options ── */
.speed-options { display: flex; gap: 0.5rem; }
.speed-btn {
  flex: 1;
  background: var(--surface-2);
  border: 2px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 0.25rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  transition: all 0.18s;
  text-align: center;
}
.speed-btn.active {
  border-color: var(--primary-light);
  color: var(--primary-light);
  background: rgba(99, 102, 241, 0.1);
}
.speed-btn:hover:not(.active) { border-color: var(--text-muted); color: var(--text); }

/* ── Start Button ── */
.start-btn {
  width: 100%;
  padding: 0.875rem;
  border-radius: 0.75rem;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  margin-bottom: 1rem;
}
.start-btn:disabled { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; opacity: 0.6; }
.start-btn.running { background: linear-gradient(135deg, var(--red), #f87171); }
.start-btn:not(:disabled):not(.running):hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

/* ── Prize Table ── */
.prize-table-card { padding-bottom: 0.75rem; }
.prize-table { font-size: 0.75rem; }
.prize-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.28rem 0;
  border-bottom: 1px solid var(--surface-2);
  color: var(--text-muted);
}
.prize-row:last-child { border-bottom: none; }
.prize-row .prize-amount { font-weight: 700; color: var(--gold-light); }
.prize-row.jackpot-row { color: var(--gold-light); }
.prize-row.jackpot-row .prize-amount { color: var(--gold-light); font-size: 0.85rem; }

/* ── Draw Card ── */
.draw-card { text-align: center; }
.draw-display { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }

.draw-balls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.draw-ball {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 800;
  transition: all 0.15s;
  line-height: 1;
}

/* Draw A balls — default white, override with color modifier */
.draw-a {
  background: var(--ball-white-bg);
  color: var(--ball-white-text);
  border: 2px solid #e2e8f0;
}
.draw-a-red {
  background: var(--ball-red-bg);
  color: var(--ball-red-text);
  border: 2px solid #f87171;
}
.draw-a.match, .draw-a-red.match {
  background: var(--green);
  border-color: var(--green);
  color: white;
  animation: ballPop 0.3s ease;
}

/* Draw B balls by color */
.draw-b-red    { background: var(--ball-red-bg);    color: var(--ball-red-text);    border: 2px solid #f87171; }
.draw-b-gold   { background: var(--ball-gold-bg);   color: var(--ball-gold-text);   border: 2px solid #fcd34d; }
.draw-b-star   { background: var(--ball-star-bg);   color: var(--ball-star-text);   border: 2px solid #a78bfa; }
.draw-b-orange { background: var(--ball-orange-bg); color: var(--ball-orange-text); border: 2px solid #fb923c; }
.draw-b-blue   { background: var(--ball-blue-bg);   color: var(--ball-blue-text);   border: 2px solid #93c5fd; }

.draw-b.match { filter: brightness(1.25); animation: ballPop 0.3s ease; }

.draw-separator { font-size: 1rem; color: var(--text-muted); font-weight: 700; }

@keyframes ballPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ── Your pick row ── */
.your-pick-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.your-pick-label { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; }
.your-balls { display: flex; gap: 0.25rem; flex-wrap: wrap; justify-content: center; align-items: center; }

.mini-ball {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1;
}

.mini-a {
  background: rgba(241,245,249,.15);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.mini-a.picked             { background: var(--ball-white-bg); color: var(--ball-white-text); border-color: var(--ball-white-bg); }
.mini-a-red                { background: rgba(239,68,68,.15); color: #f87171; border: 1px solid rgba(239,68,68,.35); }
.mini-a-red.picked         { background: var(--ball-red-bg);  color: var(--ball-red-text);   border-color: var(--ball-red-bg); }

.mini-b-red    { background: rgba(239,68,68,.2);    color: #f87171; border: 1px solid rgba(239,68,68,.4); }
.mini-b-gold   { background: rgba(245,158,11,.2);   color: #fcd34d; border: 1px solid rgba(245,158,11,.4); }
.mini-b-star   { background: rgba(139,92,246,.2);   color: #a78bfa; border: 1px solid rgba(139,92,246,.4); }
.mini-b-orange { background: rgba(249,115,22,.2);   color: #fb923c; border: 1px solid rgba(249,115,22,.4); }
.mini-b-blue   { background: rgba(59,130,246,.2);   color: #93c5fd; border: 1px solid rgba(59,130,246,.4); }

.mini-b-red.picked    { background: var(--ball-red-bg);    color: var(--ball-red-text);    border-color: var(--ball-red-bg); }
.mini-b-gold.picked   { background: var(--ball-gold-bg);   color: var(--ball-gold-text);   border-color: var(--ball-gold-bg); }
.mini-b-star.picked   { background: var(--ball-star-bg);   color: var(--ball-star-text);   border-color: var(--ball-star-bg); }
.mini-b-orange.picked { background: var(--ball-orange-bg); color: var(--ball-orange-text); border-color: var(--ball-orange-bg); }
.mini-b-blue.picked   { background: var(--ball-blue-bg);   color: var(--ball-blue-text);   border-color: var(--ball-blue-bg); }

.mini-sep { font-size: 0.75rem; color: var(--text-muted); font-weight: 700; }

/* ── Match result ── */
.match-result { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); min-height: 1.4em; }
.match-result.has-match { color: var(--green); }
.match-result.jackpot { color: var(--gold-light); font-size: 1.05rem; animation: pulse 0.5s ease; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  padding: 1rem;
  text-align: center;
}
.stat-icon { font-size: 1.3rem; margin-bottom: 0.25rem; }
.stat-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--gold-light);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin-bottom: 0.2rem;
}
.stat-value.loss { color: var(--red); }
.stat-value.gain { color: var(--green); }
.stat-label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }

/* ── Best Match ── */
.best-match { font-size: 0.85rem; }
.best-match-none { color: var(--text-muted); font-style: italic; }
.best-match-entry { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.best-match-balls { display: flex; gap: 0.2rem; flex-wrap: wrap; }
.best-match-info { font-size: 0.78rem; color: var(--text-muted); }
.best-match-prize { color: var(--gold-light); font-weight: 700; }

/* ── Reality Grid ── */
.reality-grid { display: flex; flex-direction: column; gap: 0.4rem; }
.reality-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--surface-2);
}
.reality-row:last-child { border-bottom: none; }
.reality-label { color: var(--text-muted); }
.reality-value { font-weight: 700; color: var(--text); }

/* ── Win Log ── */
.win-log-count { font-size: 0.7rem; font-weight: 400; color: var(--text-muted); text-transform: none; letter-spacing: 0; }
.win-log { max-height: 190px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.win-log-empty { color: var(--text-muted); font-size: 0.8rem; font-style: italic; }

.win-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--surface-2);
  font-size: 0.75rem;
  animation: slideIn 0.2s ease;
}
.win-entry:last-child { border-bottom: none; }
.win-entry-label { color: var(--text-muted); }
.win-entry-prize { font-weight: 700; color: var(--gold-light); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Jackpot Banner ── */
.jackpot-banner {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
}
.jackpot-banner.active { display: flex; }

.jackpot-card {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border: 2px solid var(--gold);
  border-radius: 1.5rem;
  padding: 2.5rem 2rem;
  max-width: 420px;
  width: 90%;
  text-align: center;
  animation: popIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  box-shadow: 0 0 60px rgba(245,158,11,0.3);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

.jackpot-fireworks { font-size: 2.5rem; margin-bottom: 0.5rem; animation: bounce 0.6s ease infinite alternate; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-8px); } }

.jackpot-winner-label {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.15em; color: var(--gold); margin-bottom: 0.2rem;
}
.jackpot-winner-lottery { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.jackpot-winner-title { font-size: 1.6rem; font-weight: 800; color: var(--gold-light); margin-bottom: 0.75rem; }
.jackpot-winner-desc { font-size: 0.88rem; color: var(--text-muted); line-height: 1.7; margin-bottom: 1rem; }

.jackpot-reality {
  background: rgba(245,158,11,.1);
  border: 1px solid rgba(245,158,11,.25);
  border-radius: 0.625rem;
  padding: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}
.jackpot-reality-val { font-weight: 700; color: var(--text); }

.jackpot-continue-btn {
  display: block; width: 100%;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted); padding: 0.7rem; border-radius: 0.625rem;
  cursor: pointer; font-size: 0.9rem; font-weight: 600;
  margin-bottom: 0.5rem; transition: all 0.2s;
}
.jackpot-continue-btn:hover { background: var(--surface); color: var(--text); border-color: var(--text-muted); }

.jackpot-reset-btn {
  display: block; width: 100%;
  background: linear-gradient(135deg, var(--gold-dark), var(--gold-light));
  border: none; color: white; padding: 0.7rem; border-radius: 0.625rem;
  cursor: pointer; font-size: 0.9rem; font-weight: 700; transition: all 0.2s;
}
.jackpot-reset-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(245,158,11,.4); }
