:root {
  --bg: #eef2ff;
  --fg: #0f172a;
  --card: #ffffff;
  --card-soft: #f8faff;
  --border: #d6def0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --muted: #475569;
  --success: #047857;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at top, #dbeafe 0%, var(--bg) 40%, #e2e8f0 100%);
  color: var(--fg);
  font: clamp(15px, 1.6vw, 18px)/1.45 Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  padding: clamp(0.5rem, 2vw, 1.5rem);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}

.card {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: clamp(0.75rem, 2vw, 1.25rem);
  box-shadow: 0 16px 36px rgba(37, 99, 235, 0.12);
}

.wizard-shell h1 {
  margin: 0 0 0.7rem;
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
  letter-spacing: 0.01em;
}

.home-view {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: clamp(0.75rem, 2vw, 1rem);
  background: linear-gradient(160deg, #f8fbff, #eef6ff);
}

.home-view h2 {
  margin: 0 0 0.35rem;
  font-size: 1.22rem;
}

.summary-grid {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  background: #fff;
}

.summary-label {
  margin: 0;
  font-size: 0.83rem;
  color: var(--muted);
}

.summary-value {
  margin: 0.2rem 0 0;
  font-size: 1.1rem;
  font-weight: 700;
}

#wizardContent {
  flex: 1;
  flex-direction: column;
}

#wizardContent:not([hidden]) {
  display: flex;
}

.wizard-progress {
  margin-bottom: 0.9rem;
}

.race-badge {
  margin: 0 0 0.4rem;
  display: inline-block;
  font-size: 0.85rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: #e0eaff;
  color: #1e3a8a;
}

.step-indicator {
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
}

.step-dots {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(40px, 1fr));
  gap: 0.5rem;
  padding: 0;
  margin: 0;
}

.step-dot {
  width: 100%;
  font-weight: 700;
  background: #fff;
  color: var(--fg);
  border: 1px solid var(--border);
}

.step-dot.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.wizard-step {
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: clamp(0.65rem, 2vw, 0.85rem);
}

.wizard-step:not([hidden]) {
  flex: 1;
}

.wizard-step h2 {
  margin: 0 0 0.7rem;
  font-size: 1.04rem;
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  align-items: center;
}

.inline, .inline-form {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  flex-wrap: wrap;
}

input, select, button {
  font: inherit;
  padding: 0.52rem 0.65rem;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
}

button {
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  transition: background-color 120ms ease;
  font-weight: 600;
}

button:hover { background: var(--accent-hover); }

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  min-width: 120px;
  font-weight: 700;
}

.btn-secondary {
  background: #fff;
  color: #1e3a8a;
  border-color: #9db5ea;
}

.btn-secondary:hover {
  background: #eff6ff;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.45rem;
  text-align: left;
}

th { background: #f8fafc; }

.winner-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.8rem;
}

.winner-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  padding: 0.35rem 0.6rem;
}

#results {
  margin-top: 0.8rem;
  border-top: 1px solid var(--border);
  padding-top: 0.7rem;
}

#results ul { padding-left: 1.2rem; }

#bettorList {
  list-style: none;
  padding-left: 0;
  margin: 0.7rem 0 0;
  display: grid;
  gap: 0.5rem;
}

.bettor-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  background: #fbfdff;
}

#betTable { min-width: min(620px, 100%); }

#betTable select {
  width: 100%;
  min-width: 70px;
  text-align: left;
  padding: 0.35rem 1.2rem 0.35rem 0.5rem;
  font-variant-numeric: tabular-nums;
  -webkit-appearance: menulist;
  appearance: auto;
}

.history-panel {
  margin-top: 0.9rem;
  border-top: 1px solid var(--border);
  padding-top: 0.8rem;
}

.history-panel h2 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

#raceHistoryList,
#dayTotalsList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.history-item {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
}

.history-item p {
  margin: 0.12rem 0;
  font-size: 0.92rem;
}

.muted { color: var(--muted); }

.wizard-nav {
  margin-top: auto;
  padding-top: 1rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.wizard-nav button { min-width: 120px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

dialog {
  border-radius: 12px;
  border: 1px solid var(--border);
  width: min(90vw, 560px);
  max-width: 560px;
  padding: clamp(0.75rem, 3vw, 1.5rem);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.4);
}

/* Small phones in landscape / large phones */
@media (min-width: 480px) {
  #betTable { min-width: 620px; }
}

/* Tablets */
@media (min-width: 760px) {
  .wizard-shell h1 { margin-bottom: 0.8rem; }
  .grid.two {
    grid-template-columns: 220px 1fr;
    gap: 0.65rem 1rem;
  }
}

/* Large tablets / small desktops */
@media (min-width: 1024px) {
  main { max-width: 1080px; }
}

/* Cap growth on very large screens */
@media (min-width: 1440px) {
  body { font-size: 18px; }
  main { max-width: 1120px; }
}