:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --surface3: #2d333b;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #7d8590;
  --accent: #58a6ff;
  --accent-dim: #1f3a5f;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --purple: #bc8cff;
  --radius: 8px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { background: var(--bg); color: var(--text); font-family: var(--font); min-height: 100vh; line-height: 1.5; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface3); padding: 0.15em 0.4em; border-radius: 4px; font-size: 0.875em; }

/* ─── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 54px;
  position: sticky; top: 0; z-index: 100;
}
.logo { font-size: 1.05rem; font-weight: 700; color: var(--accent); white-space: nowrap; }

nav { display: flex; gap: 0.1rem; flex: 1; }
nav a {
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
nav a:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
nav a.active { background: var(--accent-dim); color: var(--accent); }

#header-status { font-size: 0.78rem; color: var(--muted); }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.main-content { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.page { display: none; }
.page.active { display: block; }

.page-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 1rem; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 680px) { .two-col { grid-template-columns: 1fr; } }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.9rem;
}
.helper-text { font-size: 0.83rem; color: var(--muted); }

/* ─── Stats grid ─────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 0.75rem;
  text-align: center;
}
.stat-box .val { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stat-box .lbl { font-size: 0.72rem; color: var(--muted); margin-top: 0.2rem; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 600; font-family: var(--font);
  cursor: pointer; transition: opacity 0.15s, transform 0.1s;
  line-height: 1;
}
.btn:hover { opacity: 0.88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn-secondary { background: var(--surface2); color: var(--text); border-color: var(--border); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

.action-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 0.18rem 0.55rem;
  border-radius: 99px;
  font-size: 0.7rem; font-weight: 600;
  white-space: nowrap;
}
.badge-green  { background: rgba(63,185,80,0.15);  color: var(--green); }
.badge-amber  { background: rgba(210,153,34,0.15); color: var(--amber); }
.badge-red    { background: rgba(248,81,73,0.15);  color: var(--red); }
.badge-blue   { background: rgba(88,166,255,0.15); color: var(--accent); }
.badge-purple { background: rgba(188,140,255,0.15);color: var(--purple); }
.badge-muted  { background: var(--surface3); color: var(--muted); }

/* ─── Notices ────────────────────────────────────────────────────────────── */
.notice {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.85rem;
}
.notice-info   { background: rgba(88,166,255,0.08);  border: 1px solid rgba(88,166,255,0.25);  color: var(--accent); }
.notice-warn   { background: rgba(210,153,34,0.1);  border: 1px solid rgba(210,153,34,0.3);   color: var(--amber); }
.notice-err    { background: rgba(248,81,73,0.1);   border: 1px solid rgba(248,81,73,0.3);    color: var(--red); }
.notice-success{ background: rgba(63,185,80,0.1);   border: 1px solid rgba(63,185,80,0.3);    color: var(--green); }

/* ─── Meetings / Race cards ──────────────────────────────────────────────── */
.meeting-card { margin-bottom: 1.5rem; }
.meeting-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, var(--surface2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
  position: sticky; top: 54px; z-index: 5;
}
.meeting-course {
  font-size: 1.1rem; font-weight: 700; flex: 1;
  display: flex; align-items: center; gap: 0.5rem;
}
.meeting-course::before { content: '🏇'; font-size: 1.1rem; }
.meeting-races-list { display: grid; gap: 0.6rem; }

/* Each race is now a card, not a row */
.race-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
  position: relative;
  overflow: hidden;
}
.race-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.race-card.completed { border-left: 3px solid var(--green); }
.race-card.completed.top1-hit { border-color: var(--green); background: linear-gradient(180deg, rgba(63,185,80,0.06), var(--surface) 30%); }
.race-card.completed.top1-miss { border-left-color: var(--amber); }

.race-card-head {
  display: flex; align-items: baseline; gap: 0.6rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}
.race-card-time {
  font-size: 1rem; font-weight: 800; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.race-card-name {
  font-weight: 600; font-size: 0.95rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.race-card-meta {
  font-size: 0.75rem; color: var(--muted);
  display: flex; gap: 0.5rem; flex-wrap: wrap;
}
.race-card-meta span:not(:last-child)::after { content: '·'; margin-left: 0.5rem; color: var(--border); }

/* Hero pick block — the big "Best Pick" inside each race card */
.race-hero {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.7rem 0.85rem;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  position: relative;
}
.race-hero.is-best { border-color: rgba(255,215,0,0.4); background: linear-gradient(135deg, rgba(255,215,0,0.06), var(--surface2)); }
.race-hero-rank {
  font-size: 1.4rem; font-weight: 800;
  color: #ffd700;
  min-width: 28px; text-align: center;
  line-height: 1;
}
.race-hero-body { flex: 1; min-width: 0; }
.race-hero-name {
  font-weight: 700; font-size: 0.98rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.race-hero-sub {
  font-size: 0.75rem; color: var(--muted);
  margin-top: 0.15rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.market-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.35rem;
}
.market-tag,
.value-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 99px;
  padding: 0.12rem 0.45rem;
  font-size: 0.65rem;
  font-weight: 700;
  white-space: nowrap;
}
.market-shortening { background: rgba(63,185,80,0.16); color: var(--green); }
.market-drifting { background: rgba(210,153,34,0.16); color: var(--amber); }
.market-stable { background: var(--surface3); color: var(--muted); }
.value-positive { background: rgba(88,166,255,0.16); color: var(--accent); }
.value-watch { background: rgba(248,81,73,0.14); color: var(--red); }
.race-hero-pct {
  font-size: 1.05rem; font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 56px;
}
.race-hero-pct small { display: block; font-size: 0.62rem; color: var(--muted); font-weight: 500; margin-top: 0.1rem; letter-spacing: 0.04em; }

/* Other-runners preview line under the hero */
.race-others {
  display: flex; align-items: center; gap: 0.5rem;
  margin-top: 0.55rem;
  padding: 0 0.2rem;
  font-size: 0.74rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.race-others .chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  white-space: nowrap;
}

/* Result strip at top of completed cards */
.result-strip {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.7rem;
  margin: -0.9rem -1rem 0.75rem;
  font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.result-strip.win { background: rgba(63,185,80,0.15); color: var(--green); }
.result-strip.miss { background: rgba(210,153,34,0.15); color: var(--amber); }
.result-strip .actual-winner { font-weight: 500; text-transform: none; color: var(--muted); letter-spacing: 0; margin-left: auto; }

/* Outcome pip next to a runner showing where they actually finished */
.outcome-pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  font-size: 0.7rem; font-weight: 700;
  margin-left: 0.4rem;
  font-variant-numeric: tabular-nums;
}
.outcome-pill.correct { background: rgba(63,185,80,0.18); color: var(--green); }
.outcome-pill.close   { background: rgba(210,153,34,0.18); color: var(--amber); }
.outcome-pill.wrong   { background: rgba(248,81,73,0.15); color: var(--red); }
.outcome-pill.non-runner { background: var(--surface3); color: var(--muted); }

/* Bigger best-pick badge in hero, like a ribbon */
.best-pick-ribbon {
  position: absolute; top: 0; right: 0;
  background: linear-gradient(135deg, #ffd700, #d4a017);
  color: #000;
  font-size: 0.6rem; font-weight: 800;
  letter-spacing: 0.08em;
  padding: 0.15rem 0.55rem;
  border-radius: 0 var(--radius) 0 var(--radius);
}

/* ─── Prediction table ───────────────────────────────────────────────────── */
.pred-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
.pred-table th {
  text-align: left; padding: 0.5rem 0.6rem;
  font-size: 0.7rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.pred-table td {
  padding: 0.6rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.pred-table tbody tr:last-child td { border-bottom: none; }
.pred-table tbody tr:hover td { background: var(--surface2); }

.rank-cell { font-size: 1rem; font-weight: 800; min-width: 28px; text-align: center; }
.rank-1 { color: #ffd700; }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }

.horse-cell .horse-name { font-weight: 700; }
.horse-cell .horse-explain { font-size: 0.73rem; color: var(--muted); margin-top: 0.2rem; max-width: 280px; }
.horse-cell .warn-tags { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.25rem; }

.prob-bar-wrap { background: var(--surface3); border-radius: 99px; height: 5px; width: 56px; margin-bottom: 2px; }
.prob-bar { border-radius: 99px; height: 5px; transition: width 0.3s; }

/* ─── Info rows ──────────────────────────────────────────────────────────── */
.info-row { display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: 0.83rem; color: var(--muted); }
.info-row b { color: var(--text); }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 2rem 1rem;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%; max-width: 800px;
  padding: 1.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex; align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.2rem; }

/* ─── Loading ────────────────────────────────────────────────────────────── */
.loading-row { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.85rem; padding: 0.5rem 0; }
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Results pre ────────────────────────────────────────────────────────── */
.result-pre {
  font-size: 0.76rem; color: var(--muted);
  white-space: pre-wrap; margin-top: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  max-height: 240px; overflow-y: auto;
  display: none;
}
.result-pre.visible { display: block; }

/* ─── Confidence ─────────────────────────────────────────────────────────── */
.conf-low  { color: var(--red); }
.conf-mid  { color: var(--amber); }
.conf-high { color: var(--green); }

/* ─── Footer ─────────────────────────────────────────────────────────────── */
footer {
  display: flex; align-items: center; justify-content: center; gap: 1.5rem;
  padding: 1.5rem 1rem;
  font-size: 0.78rem; color: var(--muted);
  border-top: 1px solid var(--border); margin-top: 2rem;
}

/* ─── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  /* Hide less-important table columns on mobile */
  .pred-table .col-trainer,
  .pred-table .col-weight { display: none; }
  .app-header { gap: 0.75rem; }
  nav a { padding: 0.3rem 0.55rem; font-size: 0.8rem; }
}
