/* Derby Racing — Luxury Casino Theme */
:root {
  --bg-primary: #070a10;
  --bg-secondary: #0e1422;
  --bg-card: #141c2e;
  --bg-card-hover: #1c273e;
  --gold-primary: #f59e0b;
  --gold-light: #fbbf24;
  --gold-glow: rgba(245, 158, 11, 0.35);
  --gold-dark: #b45309;
  --emerald-primary: #10b981;
  --emerald-dark: #064e3b;
  --emerald-glow: rgba(16, 185, 129, 0.3);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border-color: #1e293b;
  --border-gold: rgba(245, 158, 11, 0.4);
  --danger-color: #ef4444;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-main: 0 10px 30px -5px rgba(0, 0, 0, 0.6);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Background Atmosphere */
.bg-mesh {
  position: fixed;
  inset: 0;
  background: 
    radial-gradient(circle at 20% 15%, rgba(16, 185, 129, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(245, 158, 11, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(14, 20, 34, 0.8) 0%, var(--bg-primary) 100%);
  pointer-events: none;
  z-index: 0;
}

.noise {
  position: fixed;
  inset: 0;
  opacity: 0.02;
  background-image: radial-gradient(#fff 1px, transparent 0);
  background-size: 24px 24px;
  pointer-events: none;
  z-index: 1;
}

/* Main Container Shell */
.derby-shell {
  position: relative;
  z-index: 2;
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Topbar */
.derby-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-main);
}

.brand-group .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-main);
}

.brand-badge {
  background: linear-gradient(135deg, var(--gold-primary), var(--gold-dark));
  color: #000;
  font-weight: 900;
  font-size: 18px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  letter-spacing: 1px;
  box-shadow: 0 0 15px var(--gold-glow);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1.5px;
  background: linear-gradient(90deg, #fff, var(--gold-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 10px;
  color: var(--gold-primary);
  letter-spacing: 2px;
  font-weight: 600;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.balance-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  padding: 6px 14px;
  border-radius: var(--radius-md);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.15);
}

.currency-icon {
  font-size: 20px;
}

.balance-details {
  display: flex;
  flex-direction: column;
}

.balance-details small {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 1px;
  font-weight: 700;
}

.balance-details strong {
  font-size: 15px;
  color: var(--gold-light);
  font-weight: 800;
}

.topup-btn {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid var(--gold-primary);
  color: var(--gold-light);
  font-size: 10px;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.topup-btn:hover {
  background: var(--gold-primary);
  color: #000;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--gold-primary);
}

/* History Ticker */
.history-section {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(14, 20, 34, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  overflow: hidden;
}

.history-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 800;
  color: var(--gold-light);
  letter-spacing: 1px;
  white-space: nowrap;
}

.pulse-icon {
  width: 8px;
  height: 8px;
  background: var(--emerald-primary);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--emerald-primary);
  animation: pulseGlow 1.5s infinite;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
}

.history-track {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.history-track::-webkit-scrollbar {
  display: none;
}

.history-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-pill:hover {
  border-color: var(--gold-primary);
  transform: translateY(-1px);
}

.history-pill .horse-badge {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 900;
  color: #fff;
}

.history-pill .horse-name {
  color: var(--text-main);
  font-weight: 700;
}

.history-pill .horse-odds {
  color: var(--gold-light);
  font-weight: 800;
  font-size: 11px;
}

/* Layout Grid */
.game-layout {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 16px;
}

@media (max-width: 1080px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
}

/* Track Container */
.track-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-main);
}

.track-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.round-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.round-badge strong {
  color: var(--gold-light);
  font-size: 16px;
}

.public-id-pill {
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-dim);
}

.phase-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 6px 16px;
  border-radius: 30px;
}

.phase-indicator.phase-betting {
  border-color: var(--emerald-primary);
  box-shadow: 0 0 15px var(--emerald-glow);
}

.phase-indicator.phase-racing {
  border-color: var(--gold-primary);
  box-shadow: 0 0 15px var(--gold-glow);
}

.phase-glow {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--emerald-primary);
  animation: pulseGlow 1s infinite;
}

.phase-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
}

.phase-timer {
  font-size: 15px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--gold-light);
}

.seed-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.seed-badge code {
  color: var(--gold-primary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Canvas Wrapper */
.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 7.6;
  background: #021a0d;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid #0f3d23;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8);
}

#raceCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.track-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Winner Ceremony Overlay */
.winner-ceremony {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(6, 78, 59, 0.95), rgba(7, 10, 16, 0.95));
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  animation: fadeIn 0.4s ease;
  z-index: 10;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.ceremony-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  max-width: 500px;
  padding: 24px;
}

.trophy-anim {
  font-size: 56px;
  animation: bounceTrophy 1s infinite alternate ease-in-out;
}

@keyframes bounceTrophy {
  from { transform: translateY(0) scale(1); }
  to { transform: translateY(-10px) scale(1.1); }
}

.winner-title {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(90deg, #fff, var(--gold-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.winner-horse-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-card);
  border: 2px solid var(--gold-primary);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  box-shadow: 0 0 30px var(--gold-glow);
}

.winner-num {
  font-size: 28px;
  font-weight: 900;
  color: var(--gold-light);
}

.winner-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.winner-meta strong {
  font-size: 20px;
  color: #fff;
}

.winner-meta span {
  font-size: 14px;
  color: var(--gold-primary);
  font-weight: 700;
}

.user-payout-banner {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(16, 185, 129, 0.4));
  border: 1px solid var(--emerald-primary);
  padding: 10px 24px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: pulseGlow 1s infinite;
}

.payout-title {
  font-size: 12px;
  font-weight: 800;
  color: #a7f3d0;
  letter-spacing: 1px;
}

.payout-val {
  font-size: 26px;
  color: #34d399;
  font-weight: 900;
}

.ranking-podium {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.ranking-podium-item {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Starting Gate Overlay */
.starting-gate-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.gate-countdown-box {
  background: var(--bg-card);
  border: 2px solid var(--gold-primary);
  padding: 20px 40px;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 0 40px var(--gold-glow);
  animation: popIn 0.3s ease;
}

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

.gate-sub {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 2px;
}

.gate-count {
  font-size: 64px;
  font-weight: 900;
  color: var(--gold-light);
  line-height: 1;
}

/* Betting Panel */
.betting-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-main);
}

.betting-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.bet-title-group h3 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 1px;
}

.bet-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.bet-status-pill {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--emerald-primary);
  color: var(--emerald-primary);
  font-size: 11px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

.bet-status-pill.closed {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--danger-color);
  color: var(--danger-color);
}

/* Stake Control */
.stake-control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.stake-control-group label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.input-with-addons {
  display: flex;
  align-items: center;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0 12px;
}

.input-prefix {
  color: var(--gold-light);
  font-weight: 800;
  font-size: 16px;
}

.input-suffix {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
}

.input-with-addons input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  padding: 8px 10px;
  outline: none;
  font-family: inherit;
}

.quick-chip-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip-btn {
  flex: 1;
  min-width: 38px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 700;
  padding: 6px 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--gold-primary);
  color: var(--gold-light);
}

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

/* Horse Bet Cards Grid */
.horses-bet-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.horses-bet-list::-webkit-scrollbar {
  width: 4px;
}
.horses-bet-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.horse-bet-card {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.horse-bet-card:hover {
  border-color: var(--border-gold);
  background: var(--bg-card-hover);
}

.horse-bet-card.selected {
  border-color: var(--gold-primary);
  background: rgba(245, 158, 11, 0.08);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.15);
}

.horse-silk-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.horse-info-col {
  display: flex;
  flex-direction: column;
}

.horse-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.horse-name-row strong {
  font-size: 13px;
  color: #fff;
}

.horse-jockey-form {
  font-size: 10px;
  color: var(--text-dim);
}

.horse-odds-badge {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid var(--border-gold);
  color: var(--gold-light);
  font-size: 13px;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.5px;
}

.horse-bet-input-box {
  width: 70px;
}

.horse-bet-input-box input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 4px;
  text-align: center;
  outline: none;
}

.horse-bet-input-box input:focus {
  border-color: var(--gold-primary);
}

/* Action Footer */
.bet-action-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
}

.total-bet-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.summary-line {
  display: flex;
  flex-direction: column;
}

.summary-line span {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 700;
}

.summary-line strong {
  font-size: 15px;
  color: var(--gold-light);
  font-weight: 800;
}

.submit-bet-btn {
  background: linear-gradient(135deg, var(--gold-primary), var(--gold-dark));
  border: none;
  color: #000;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 1.5px;
  padding: 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: 0 0 20px var(--gold-glow);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.submit-bet-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 30px rgba(245, 158, 11, 0.6);
}

.submit-bet-btn:disabled {
  background: #273349;
  color: #64748b;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.security-footer-note {
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-main);
  overflow: hidden;
}

.modal-wide {
  max-width: 780px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-title-group h3 {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-intro {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.fair-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fair-field label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
}

.fair-field input {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: #fff;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  outline: none;
  font-family: monospace;
}

.fair-dual-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.verify-action-btn {
  background: var(--bg-card);
  border: 1px solid var(--gold-primary);
  color: var(--gold-light);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.2s ease;
}

.verify-action-btn:hover {
  background: var(--gold-primary);
  color: #000;
}

.verify-results {
  background: var(--bg-card);
  border: 1px solid var(--emerald-primary);
  padding: 12px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.verify-status-badge {
  font-size: 12px;
  font-weight: 900;
  color: var(--emerald-primary);
}

.verify-details {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
}

/* History Table */
.history-table-container {
  max-height: 400px;
  overflow-y: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.history-table th {
  text-align: left;
  padding: 10px;
  background: var(--bg-card);
  color: var(--text-dim);
  font-weight: 700;
}

.history-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

.history-table code {
  color: var(--gold-primary);
  font-size: 11px;
}

/* Rules content */
.rules-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

.rules-content h4 {
  color: var(--gold-light);
  font-size: 14px;
}
