:root {
  /* Dazzling purple design system - vivid violet → magenta accents on a soft
     lavender-white canvas. (--blue is repurposed as the purple primary so every
     existing accent picks it up.) */
  --bg: #f5f3fc;
  --panel: #ffffff;
  --panel-2: #f4eefe;
  --border: #e8dffa;
  --text: #271a3d;
  --muted: #7b7090;
  --purple: #4c1d95;
  --purple-2: #6b21a8;
  --magenta: #86198f;
  --blue: #4c1d95; /* primary (links, active, value highlights) */
  --blue-soft: #e7ddf6;
  --green: #0f9d6b; /* profit */
  --green-soft: #e2f6ef;
  --red: #c61f5f; /* loss */
  --red-soft: #fbe2ec;
  --amber: #a86c00;
  --gold: #b07d1f;
  --grad: linear-gradient(120deg, #2e1065, #581c87 50%, #6b1f6b);
  --shadow: 0 1px 2px rgba(40, 12, 80, 0.08), 0 10px 28px rgba(40, 12, 80, 0.14);
  --glow: 0 6px 22px rgba(46, 16, 101, 0.4);
}

* { box-sizing: border-box; }
/* The `hidden` attribute must always win over component display rules
   (e.g. .auth-overlay/.user-menu set display:flex, which otherwise overrides
   the UA [hidden]{display:none} and leaves elements stuck visible). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--grad);
  color: #fff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
  gap: 12px;
  box-shadow: 0 2px 10px rgba(27, 39, 51, 0.12);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 34px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.5px; }
.tagline { margin: 0; color: rgba(255, 255, 255, 0.85); font-size: 14px; }

/* desktop: a polished segmented control */
.tabs { display: flex; gap: 4px; background: rgba(255, 255, 255, 0.16); padding: 4px; border-radius: 13px; }
.tab {
  display: flex; align-items: center; gap: 7px;
  background: transparent;
  border: none;
  color: #fff;
  padding: 8px 15px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 15px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tab .tab-ico { font-size: 16px; line-height: 1; }
.tab:hover { background: rgba(255, 255, 255, 0.16); }
.tab.active { background: #fff; color: var(--purple); font-weight: 700; box-shadow: 0 2px 6px rgba(76, 29, 149, 0.22); }

main { padding: 22px; max-width: 1180px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.howto { background: var(--blue-soft); border-left: 4px solid var(--blue); font-size: 16px; }
.howto strong { color: var(--purple); }

/* summary strip */
.summary {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: space-between;
}
.summary .metrics { display: flex; gap: 16px 30px; flex-wrap: wrap; }
/* each metric stacks its label over its value (they were running together) */
.summary .metric { display: flex; flex-direction: column; gap: 2px; }
.summary .metric .k { font-size: 13px; color: var(--muted); line-height: 1.2; }
.summary .metric .v { font-size: 24px; font-weight: 800; line-height: 1.15; }
.summary .budget { display: flex; align-items: center; gap: 8px; font-weight: 600; }
@media (max-width: 620px) {
  .summary .metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; width: 100%; }
  .summary .budget { width: 100%; justify-content: space-between; }
}

.layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
/* Let grid children shrink so wide tables scroll inside their own wrapper
   instead of forcing the whole page wider than the screen. */
.content, .sidebar { min-width: 0; }
.content { overflow-x: hidden; }

.sidebar { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px; height: fit-content; position: sticky; top: 86px; }
.sidebar h2 { margin: 0 0 8px; font-size: 16px; }
.race-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 72vh; overflow-y: auto; }
.race-list li {
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--border);
  margin-bottom: 7px;
  background: var(--panel-2);
}
.race-list li:hover { border-color: var(--blue); }
.race-list li.selected { border-color: var(--blue); background: var(--blue-soft); }
.race-list .rl-top { display: flex; justify-content: space-between; font-weight: 700; font-size: 14px; align-items: center; }
.race-list .rl-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; background: var(--green-soft); color: var(--green); }
.pill.none { background: var(--panel); color: var(--muted); border: 1px solid var(--border); }

/* Mobile: drop to one column and STOP the sidebar / race-list from creating a
   nested scroll area - that nested scroll is what makes the page feel stuck on
   phones. Let the whole page scroll naturally instead. */
@media (max-width: 860px) {
  main { padding: 14px; }
  .layout { grid-template-columns: 1fr; }
  /* Show the actual tips/race detail FIRST; push the options + race list
     below so a tapped race isn't buried under the whole list. */
  .content { order: -1; }
  .sidebar { order: 1; position: static; top: auto; }
  /* The board already lists the races as cards on mobile, so the full
     280-race sidebar list is redundant clutter that made the page scroll
     forever - hide it and keep just the option/filter controls. */
  .sidebar .race-list, .sidebar .races-heading { display: none; }
  .summary { position: static; }
  /* A more compact header so it doesn't eat half the screen on a phone. */
  .topbar { padding: 10px 16px; }
  .brand .logo { font-size: 26px; }
  .brand h1 { font-size: 18px; }
  .tagline { font-size: 12px; }
  .tab { padding: 7px 12px; font-size: 14px; }
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.checkrow { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; cursor: pointer; }
.checkrow input { width: 16px; height: 16px; }

/* top bets */
.topbets-card { background: linear-gradient(180deg, #fffdf5, #ffffff); border-color: #ecd9a0; }
.tb-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.tb-head h3 { margin: 0; font-size: 18px; }
.tb-head .star { font-size: 20px; }
.top-bet { display: flex; align-items: center; gap: 14px; padding: 10px 8px; border-top: 1px solid var(--border); cursor: pointer; }
.top-bet:hover { background: #fffdf2; }
.tb-rank { font-size: 11px; font-weight: 800; padding: 4px 9px; border-radius: 20px; min-width: 58px; text-align: center; }
.c-strong { background: #d6f0dd; color: #14532d; }
.c-solid { background: #e3eefb; color: #0a3d7a; }
.c-slight { background: #f0f2f5; color: #4a5563; }
.tb-main { flex: 1 1 180px; }
.tb-horse { font-weight: 700; font-size: 16px; }
.tb-horse .tb-odds { color: var(--muted); font-weight: 600; font-size: 13px; margin-left: 6px; }
.tb-race { color: var(--muted); font-size: 13px; }
.tb-num { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.tb-num .k { font-size: 11px; color: var(--muted); }
.tb-num .v { font-size: 17px; font-weight: 800; }
.tb-go { color: var(--blue); font-weight: 600; font-size: 14px; }
@media (max-width: 620px) { .tb-num { display: none; } }

/* confidence badge on bet cards */
.conf { font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 20px; vertical-align: middle; }

/* inputs - smaller, modern, consistent across the app */
input[type='number'], input[type='text'], input[type='email'], input[type='password'], input:not([type]), select, textarea {
  font-family: inherit;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 11px;
  border-radius: 9px;
  font-size: 14px;
  line-height: 1.3;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type='number']:focus, input[type='text']:focus, input[type='email']:focus, input[type='password']:focus, input:not([type]):focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.14);
}
input::placeholder { color: #b3aac6; }
/* every dropdown gets a clean custom chevron */
select {
  appearance: none; -webkit-appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8" viewBox="0 0 12 8"><path d="M1 1l5 5 5-5" fill="none" stroke="%237b7090" stroke-width="2"/></svg>');
  background-repeat: no-repeat; background-position: right 11px center; padding-right: 30px;
}
input[type='number'] { width: 100px; }
select { width: 100%; max-width: 460px; }
.control { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.control label { font-size: 13px; color: var(--muted); font-weight: 600; }
/* modern checkboxes */
input[type='checkbox'] { accent-color: var(--purple); width: 15px; height: 15px; cursor: pointer; }
.advanced { margin-top: 8px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.advanced summary:hover { color: var(--text); }

button.primary {
  background: var(--grad);
  border: none;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--glow);
  transition: transform 0.1s, filter 0.15s;
}
button.primary:hover { filter: brightness(1.07); transform: translateY(-1px); }
button.primary:active { transform: translateY(0); }
button.primary.big { font-size: 18px; padding: 14px 26px; }
/* Keep CTA buttons off the content above them (cramped on mobile otherwise). */
button.primary.big { margin: 20px 0 6px; }

/* default text shown when a list has no entries */
.empty-list { color: var(--muted); padding: 14px 4px; font-size: 14px; }

/* race cards (board + detail) */
.race-card { margin-bottom: 16px; }
.race-card .head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.race-card .head h3 { margin: 0; font-size: 19px; }
.race-card .head .when { color: var(--muted); font-size: 14px; }
.race-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }

.verdict {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 10px; font-size: 15px; font-weight: 600; margin: 12px 0;
}
.verdict .big-ico { font-size: 22px; }
.verdict.good { background: var(--green-soft); border: 1px solid #b7e0c2; color: #14532d; }
.verdict.bad { background: var(--red-soft); border: 1px solid #f3c0bd; color: #8a1c16; }
.verdict.neutral { background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.verdict.gold { background: #fbf3da; border: 1px solid #ecd9a0; color: #6b4e00; }

.bet-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--green-soft);
  border: 1px solid #c4e3cd;
  border-left: 4px solid var(--green);
  border-radius: 12px; padding: 12px 16px; margin-bottom: 9px; flex-wrap: wrap;
}
.bet-card .horse { font-size: 16px; font-weight: 700; flex: 1 1 150px; color: #14532d; }
.bet-card .horse small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.bet-card .stake { display: flex; flex-direction: column; align-items: center; min-width: 92px; gap: 1px; }
.bet-card .stake .k { font-size: 11px; color: var(--muted); }
.bet-card .stake .v { font-size: 19px; font-weight: 800; line-height: 1.1; }
.bet-card .arrow { color: var(--muted); font-size: 20px; }
.bet-card .win .v { color: var(--green); }
.bet-card .bet-why { flex: 1 0 100%; font-size: 13px; color: #2f6b41; background: rgba(255,255,255,0.6); border-radius: 8px; padding: 6px 10px; }

/* prediction reasoning */
.tb-why { color: #6b4e00; font-size: 12px; margin-top: 2px; }
.form-figs { font-variant-numeric: tabular-nums; letter-spacing: 0.5px; color: var(--muted); }
.why-btn { background: none; border: 1px solid var(--border); color: var(--blue); cursor: pointer; font-size: 12px; font-weight: 600; border-radius: 8px; padding: 3px 9px; white-space: nowrap; }
.why-btn:hover { border-color: var(--blue); background: var(--blue-soft); }
.why-btn.open { background: var(--blue); color: #fff; border-color: var(--blue); }
.why-row > td { background: var(--panel-2); padding: 12px 14px; }
.factors { display: flex; flex-direction: column; gap: 6px; max-width: 520px; }
.fbar { display: grid; grid-template-columns: 92px 1fr 52px; align-items: center; gap: 10px; font-size: 13px; }
.fb-label { color: var(--text); }
.fb-track { position: relative; height: 10px; background: #e3e9f0; border-radius: 6px; overflow: hidden; }
.fb-fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 6px; }
.fb-fill.pos { background: var(--green); }
.fb-fill.neg { background: var(--red); }
.fb-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.fb-val.pos { color: var(--green); }
.fb-val.neg { color: var(--red); }

.proj-line { display: flex; gap: 18px; flex-wrap: wrap; padding: 10px 14px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; margin-top: 6px; }
.proj-line .pl { font-size: 13px; }
.proj-line .pl b { display: block; font-size: 17px; }

/* full field table */
.field-toggle { background: none; border: none; color: var(--blue); cursor: pointer; font-size: 14px; padding: 6px 0; font-weight: 600; }
.table-wrap { overflow-x: auto; margin-top: 6px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.is-bet { background: var(--green-soft); }
tr.is-winner td { font-weight: 700; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 10px; margin-left: 6px; font-weight: 700; }
.tag.bet { background: var(--green); color: #fff; }
.tag.won { background: var(--gold); color: #fff; }
.val-up { color: var(--green); font-weight: 700; }
.val-down { color: var(--muted); }

.reveal-box { margin-top: 12px; }
.reveal-btn { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 9px 16px; border-radius: 10px; cursor: pointer; font-size: 15px; }
.reveal-btn:hover { border-color: var(--blue); }
.outcome { margin-top: 10px; padding: 12px 16px; border-radius: 10px; font-size: 15px; font-weight: 600; }
.outcome.win { background: var(--green-soft); border: 1px solid #b7e0c2; color: #14532d; }
.outcome.lose { background: var(--red-soft); border: 1px solid #f3c0bd; color: #8a1c16; }

.back-link { background: none; border: none; color: var(--blue); cursor: pointer; font-size: 14px; padding: 4px 0 12px; font-weight: 600; }

.pos { color: var(--green); }
.neg { color: var(--red); }

/* simulation */
.test-setup { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.set-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 16px; }
.set-row label { font-weight: 600; }
.hero { text-align: center; padding: 30px 20px; border-radius: 16px; margin-bottom: 16px; }
.hero.up { background: var(--green-soft); border: 1px solid #b7e0c2; }
.hero.down { background: var(--red-soft); border: 1px solid #f3c0bd; }
.hero .emoji { font-size: 46px; }
.hero .headline { font-size: 30px; font-weight: 800; margin: 8px 0 4px; }
.hero .sub { font-size: 17px; }
.plain-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 16px; }
.pstat { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 15px; box-shadow: var(--shadow); }
.pstat b { display: block; font-size: 18px; margin-top: 2px; }

canvas { width: 100%; height: auto; background: var(--panel-2); border-radius: 10px; }
.spinner { color: var(--muted); padding: 30px; text-align: center; font-size: 16px; }

.prose { max-width: 760px; }
.prose h3 { margin-top: 22px; }
.steps li { margin-bottom: 8px; }
.prose .warn { color: var(--amber); background: #fbf3da; border: 1px solid #ecd9a0; border-radius: 10px; padding: 12px 16px; }

/* strategy line inside the test-mode hero */
.hero-style { font-size: 14px; color: var(--muted); margin-top: 8px; }
.hero.up .hero-style { color: #2f6b41; }
.hero.down .hero-style { color: #8a4a45; }

/* test-mode "every bet placed" table */
.simbets-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.simbets-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.bet-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.bet-filter { background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 13px; font-weight: 600; }
.bet-filter:hover { border-color: var(--blue); color: var(--text); }
.bet-filter.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.csv-btn { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 6px 12px; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 600; }
.csv-btn:hover { border-color: var(--green); color: var(--green); }
.simbets-wrap { max-height: 460px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.simbets { width: 100%; border-collapse: collapse; font-size: 14px; }
.simbets thead th { position: sticky; top: 0; background: var(--panel-2); z-index: 1; }
.simbets td, .simbets th { white-space: nowrap; }
.simbets tbody tr:hover { background: var(--panel-2); }
.bet-won { color: var(--green); font-weight: 700; }
.bet-placed { color: var(--blue); font-weight: 700; }
.bet-lost { color: var(--muted); }
.ew-tag { font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 10px; background: var(--blue-soft); color: var(--blue); vertical-align: middle; }

/* model accuracy / calibration panel */
.cal-headline { display: flex; gap: 28px; flex-wrap: wrap; align-items: baseline; }
.cal-vs { display: flex; flex-direction: column; }
.cal-vs b { font-size: 26px; font-weight: 800; line-height: 1.1; }
.cal-vs i { font-size: 12px; color: var(--muted); font-style: normal; }
.cal-table { display: flex; flex-direction: column; gap: 10px; }
.cal-row { display: grid; grid-template-columns: 70px 1fr 92px; align-items: center; gap: 12px; }
.cal-band { font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.cal-bars { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-bar { position: relative; height: 18px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.cal-fill { position: absolute; inset: 0 auto 0 0; border-radius: 5px; opacity: 0.9; }
.cal-fill.pred { background: var(--blue); }
.cal-fill.act { background: var(--green); }
.cal-bar em { position: absolute; left: 8px; top: 0; line-height: 18px; font-style: normal; font-size: 11px; font-weight: 700; color: #fff; white-space: nowrap; }
.cal-n { font-size: 12px; color: var(--muted); text-align: right; }
@media (max-width: 620px) { .cal-row { grid-template-columns: 54px 1fr; } .cal-n { display: none; } }

/* On phones, wide tables reflow into stacked, labelled cards instead of
   scrolling sideways - no more dragging tables left/right to read them. */
@media (max-width: 620px) {
  .table-wrap { overflow: visible; }
  .table-wrap table, .simbets { display: block; width: 100%; }
  .table-wrap thead, .simbets thead { display: none; }
  .table-wrap tbody, .simbets tbody { display: block; }
  .table-wrap tr:not(.why-row), .simbets tbody tr {
    display: block; border: 1px solid var(--border); border-radius: 10px;
    padding: 6px 12px; margin-bottom: 8px; background: var(--panel);
  }
  .table-wrap td, .simbets td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 3px 0; border: none; text-align: right; white-space: normal; font-size: 14px;
  }
  /* secondary rows in lighter type so the card scans quickly */
  .table-wrap td[data-label]::before, .simbets td[data-label]::before { font-weight: 600; }
  .table-wrap td.muted { color: var(--muted); }
  .table-wrap td::before, .simbets td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600;
    text-align: left; flex: 0 0 auto;
  }
  /* horse name acts as the card title */
  .cell-horse { font-weight: 700; font-size: 16px; justify-content: flex-start !important;
    border-bottom: 1px solid var(--border); padding-bottom: 6px !important; margin-bottom: 4px; }
  .cell-horse::before { content: none; }
  .cell-race { font-weight: 700; }
  /* the Why? button becomes a full-width action at the foot of the card */
  .cell-why { padding-top: 6px !important; }
  .cell-why::before { content: none; }
  .cell-why .why-btn { width: 100%; padding: 8px; }
  /* keep the bet/winner tints on the card */
  .table-wrap tr.is-bet:not(.why-row) { background: var(--green-soft); }
  .table-wrap tr.is-winner:not(.why-row) { border-color: var(--gold); }
  /* the factor breakdown row spans the full card width (only when expanded -
     must not override the [hidden] attribute, or every row shows at once) */
  .table-wrap tr[hidden] { display: none; }
  .why-row:not([hidden]) { display: block; padding: 0; }
  .why-row:not([hidden]) > td { display: block; background: var(--panel-2); border-radius: 10px; padding: 12px; margin-bottom: 8px; }
  .why-row > td::before { content: none; }
  .fbar { grid-template-columns: 76px 1fr 48px; }
}

/* strategy comparison */
.cmp-table { display: flex; flex-direction: column; gap: 8px; }
.cmp-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); }
.cmp-row.cmp-best { border-color: var(--green); background: var(--green-soft); }
.cmp-name { font-weight: 600; }
.cmp-tag { font-size: 10px; font-weight: 800; background: var(--green); color: #fff; padding: 1px 7px; border-radius: 10px; vertical-align: middle; }
.cmp-final { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.cmp-yield { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) {
  .cmp-row { grid-template-columns: 1fr auto; }
  .cmp-yield { grid-column: 2; text-align: right; }
}

/* course breakdown */
.course-table { display: flex; flex-direction: column; gap: 8px; }
.course-row { display: grid; grid-template-columns: 96px 1fr 78px auto; align-items: center; gap: 10px; }
.course-name { font-weight: 600; font-size: 13px; }
.course-track { position: relative; height: 12px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.course-fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 6px; }
.course-fill.pos { background: var(--green); }
.course-fill.neg { background: var(--red); }
.course-pnl { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 13px; }
.course-n { text-align: right; }
@media (max-width: 520px) { .course-row { grid-template-columns: 84px 1fr 70px; } .course-n { display: none; } }

/* pace map */
.pace-map { margin: 12px 0; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--panel-2); }
.pace-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.pace-head h4 { margin: 0; font-size: 15px; }
.pace-tag { font-size: 13px; font-weight: 600; padding: 3px 11px; border-radius: 20px; }
.pace-tag.front { background: var(--blue-soft); color: var(--purple); }
.pace-tag.closers { background: var(--green-soft); color: var(--green); }
.pace-tag.even { background: #fff; border: 1px solid var(--border); color: var(--muted); }
.pace-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.pace-lane { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
.pace-lane-h { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); margin-bottom: 6px; text-align: center; }
.pace-chips { display: flex; flex-direction: column; gap: 4px; }
.pace-chip { font-size: 12px; padding: 3px 7px; border-radius: 7px; background: var(--panel-2); border: 1px solid var(--border); text-align: center; }
.pace-chip.bet { background: var(--blue-soft); border-color: var(--purple); color: var(--purple); font-weight: 700; }
@media (max-width: 620px) { .pace-grid { grid-template-columns: 1fr 1fr; } }

/* settings - weight dials + live result */
.settings-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 16px; align-items: start; }
.dials-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.dials { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; }
.dial { display: flex; flex-direction: column; gap: 5px; }
.dial-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.dial-label { font-size: 14px; font-weight: 600; }
.dial-val { font-size: 13px; font-weight: 800; color: var(--purple); font-variant-numeric: tabular-nums; }
.dial.changed .dial-val { color: var(--magenta); }
.dial input[type='range'] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 7px; border-radius: 7px;
  background: linear-gradient(90deg, var(--blue-soft), #e8dffa); border: 1px solid var(--border); outline: none;
}
.dial input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 19px; height: 19px; border-radius: 50%;
  background: var(--grad); box-shadow: var(--glow); cursor: pointer; border: 2px solid #fff;
}
.dial input[type='range']::-moz-range-thumb { width: 17px; height: 17px; border: 2px solid #fff; border-radius: 50%; background: var(--purple); cursor: pointer; }
.settings-live { position: sticky; top: 86px; }
.live-hero { text-align: center; padding: 18px 14px; border-radius: 14px; background: var(--panel-2); margin-bottom: 12px; }
.live-hero.up { background: var(--green-soft); }
.live-hero.down { background: var(--red-soft); }
.live-big { font-size: 30px; font-weight: 800; line-height: 1.1; }
.live-sub { font-size: 14px; color: var(--muted); margin-top: 4px; }
.live-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lstat { display: flex; flex-direction: column; gap: 1px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 11px; }
.lstat .k { font-size: 11px; color: var(--muted); }
.lstat .v { font-size: 17px; font-weight: 800; }
@media (max-width: 760px) { .settings-grid { grid-template-columns: 1fr; } .settings-live { position: static; } }
@media (max-width: 460px) { .dials { grid-template-columns: 1fr; } }

/* mobile: turn the menu into a fixed bottom navigation bar (app-style) */
@media (max-width: 620px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--panel); border-top: 1px solid var(--border); border-radius: 0;
    gap: 2px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 18px rgba(76, 29, 149, 0.14);
  }
  .tab { flex: 1; flex-direction: column; gap: 3px; color: var(--muted); padding: 6px 2px; border-radius: 12px; font-size: 11px; }
  .tab .tab-ico { font-size: 21px; }
  .tab .tab-label { font-size: 11px; }
  .tab:hover { background: transparent; }
  .tab.active { background: var(--blue-soft); color: var(--purple); box-shadow: none; font-weight: 700; }
  /* Clear the fixed bottom nav so content / buttons aren't hidden under it. */
  body { padding-bottom: calc(86px + env(safe-area-inset-bottom, 0px)); }
  main { scroll-padding-bottom: 90px; }
  /* Give buttons a bit more breathing room from the text/fields above on mobile. */
  button.primary.big { margin: 20px 0 6px; }
  .sim-item-actions, .adm-actions { margin-top: 4px; }
}

/* modal / popover */
.modal-overlay { position: fixed; inset: 0; background: rgba(39, 26, 61, 0.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); max-width: 560px; width: 100%; max-height: 88vh; overflow: auto; padding: 20px 22px; position: relative; }
.modal-x { position: absolute; top: 12px; right: 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: 14px; color: var(--muted); }
.modal-x:hover { color: var(--text); border-color: var(--purple); }
.rm-head h3 { margin: 0 0 2px; }
.rm-reason { background: var(--blue-soft); color: var(--purple); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin: 12px 0; }
.rm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; margin: 12px 0; }
.rm-row { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--border); padding: 5px 0; font-size: 14px; }
.rm-k { color: var(--muted); }
.rm-v { font-weight: 600; text-align: right; }
.rm-sub { margin: 14px 0 8px; font-size: 14px; }
@media (max-width: 480px) { .rm-grid { grid-template-columns: 1fr; } }

/* clickable horse name */
.horse-link { background: none; border: none; padding: 0; color: var(--purple); font: inherit; font-weight: 700; cursor: pointer; text-align: left; }
.horse-link:hover { text-decoration: underline; }

/* share + slip-add buttons */
.share-btn { background: var(--blue-soft); color: var(--purple); border: 1px solid var(--border); border-radius: 9px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.share-btn:hover { border-color: var(--purple); }
.bet-actions { flex: 1 0 100%; display: flex; justify-content: flex-end; }
.slip-add { background: #fff; border: 1px solid var(--purple); color: var(--purple); border-radius: 8px; padding: 4px 11px; font-size: 12px; font-weight: 700; cursor: pointer; }
.slip-add:hover { background: var(--blue-soft); }
.slip-add.in-slip { background: var(--purple); color: #fff; }
.tb-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

/* bet slip floating button + modal */
#slip-fab { position: fixed; right: 18px; bottom: 18px; z-index: 60; background: var(--grad); color: #fff; border: none; border-radius: 30px; padding: 12px 18px; font-size: 15px; font-weight: 700; cursor: pointer; box-shadow: var(--glow); display: flex; align-items: center; gap: 8px; }
.slip-count { background: #fff; color: var(--purple); border-radius: 20px; padding: 0 8px; font-size: 13px; min-width: 22px; text-align: center; }
.slip-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.slip-row { display: grid; grid-template-columns: 1fr auto auto auto; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.slip-main { display: flex; flex-direction: column; min-width: 0; }
.slip-num { display: flex; flex-direction: column; align-items: flex-end; }
.slip-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }
.slip-del:hover { color: var(--red); }
.slip-totals { display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.slip-totals b { display: block; font-size: 20px; }
.slip-actions { margin-top: 12px; text-align: right; }
@media (max-width: 620px) { #slip-fab { bottom: 84px; right: 12px; } }

/* pace note in the verdict */
.verdict-pace { display: block; font-weight: 500; font-size: 13px; margin-top: 4px; opacity: 0.9; }

/* auth gate */
.auth-overlay { position: fixed; inset: 0; z-index: 200; background: var(--grad); display: flex; align-items: center; justify-content: center; padding: 20px; overflow: auto; }
.auth-card { background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); width: 100%; max-width: 420px; padding: 26px 26px 30px; }
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 14px; }
.auth-brand .logo { font-size: 30px; }
.auth-brand h1 { margin: 0; font-size: 24px; color: var(--purple); }
#auth-root h2 { margin: 0 0 12px; font-size: 20px; text-align: center; }
#auth-root label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 0; font-weight: 600; }
#auth-root input { width: 100%; margin-top: 5px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; background: #fff; }
#auth-root .primary { width: 100%; margin-top: 16px; }
.auth-links { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.auth-links a { color: var(--purple); font-size: 14px; cursor: pointer; font-weight: 600; }
.auth-links a:hover { text-decoration: underline; }
.auth-links a.disabled { color: var(--muted); cursor: default; pointer-events: none; opacity: 0.7; }
.auth-err { background: var(--red-soft); color: #9a2540; border-radius: 9px; padding: 8px 11px; font-size: 13px; margin-top: 8px; }
.auth-ok { background: var(--green-soft); color: #0c6e4a; border-radius: 9px; padding: 8px 11px; font-size: 13px; margin-top: 8px; }
.auth-dev { background: #fff7e6; border: 1px solid #f0d999; color: #7a5b00; border-radius: 9px; padding: 8px 11px; font-size: 13px; margin-top: 8px; }

/* user menu chip */
.user-menu { display: flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, 0.16); border: none; color: #fff; padding: 5px 13px 5px 5px; border-radius: 24px; cursor: pointer; font-size: 14px; font-weight: 600; }
.user-menu:hover { background: rgba(255, 255, 255, 0.28); }
.um-avatar { width: 28px; height: 28px; border-radius: 50%; background: #fff; color: var(--purple); display: flex; align-items: center; justify-content: center; font-weight: 800; }
.um-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 620px) { .um-name { display: none; } }

/* profile modal extras */
.pf-label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 10px; }
.pf-label input { width: 100%; margin-top: 5px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; }
.pf-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.pf-danger { background: none; border: 1px solid var(--red); color: var(--red); border-radius: 9px; padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: 13px; }
.pf-danger:hover { background: var(--red-soft); }

/* footer / version */
.site-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 22px 14px 30px; }
.site-footer .ver { font-weight: 700; }

/* admin panel */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.adm-form { display: flex; flex-direction: column; gap: 8px; }
.adm-form input, .adm-form select { padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; background: #fff; }
.adm-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.adm-table th, .adm-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.adm-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.adm-table tr:last-child td { border-bottom: none; }
.adm-table select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: #fff; font-size: 13px; }
.adm-table input.adm-name { padding: 6px 9px; border: 1px solid var(--border); border-radius: 7px; background: #fff; font-size: 13px; width: 100%; max-width: 170px; }
.adm-table input.adm-name:focus { border-color: var(--purple); outline: none; }
.adm-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { background: var(--blue-soft); color: var(--purple); border-radius: 20px; padding: 1px 8px; font-size: 11px; font-weight: 700; }
@media (max-width: 760px) { .admin-grid { grid-template-columns: 1fr; } }
@media (max-width: 620px) {
  .adm-table thead { display: none; }
  .adm-table, .adm-table tbody, .adm-table tr, .adm-table td { display: block; width: 100%; }
  .adm-table tr { border: 1px solid var(--border); border-radius: 10px; padding: 8px; margin-bottom: 10px; }
  .adm-table tr:last-child td { border-bottom: none; }
  .adm-table td { border: none; padding: 5px 6px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  .adm-table td::before { content: attr(data-label); color: var(--muted); font-weight: 600; }
}

/* simulations */
.sim-new-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px 22px; margin-bottom: 18px; }
.sim-new-grid .control { display: flex; flex-direction: column; gap: 7px; font-size: 13px; color: var(--muted); font-weight: 600; }
.sim-new-grid input, .sim-new-grid select { width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; background: #fff; color: var(--text); font-weight: 400; }
.sim-new-grid select { appearance: none; -webkit-appearance: none; background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8" viewBox="0 0 12 8"><path d="M1 1l5 5 5-5" fill="none" stroke="%237b7090" stroke-width="2"/></svg>'); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
.sim-item { display: flex; align-items: center; gap: 14px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; background: var(--panel-2); flex-wrap: wrap; }
.sim-item-main { flex: 1 1 220px; min-width: 0; }
.sim-item-name { font-weight: 700; font-size: 16px; }
.sim-item-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sim-item-num { display: flex; flex-direction: column; align-items: flex-end; min-width: 90px; }
.sim-item-num .k { font-size: 11px; color: var(--muted); }
.sim-item-num .v { font-size: 18px; font-weight: 800; }
.sim-yield { font-size: 12px; font-weight: 700; }
.sim-item-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sim-view-name { background: var(--blue-soft); color: var(--purple); border-radius: 9px; padding: 8px 12px; margin-bottom: 12px; font-size: 14px; }
@media (max-width: 620px) { .sim-item-num { align-items: flex-start; min-width: 0; } }

/* slip controls + bet history */
.slip-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.slip-main { flex: 1 1 150px; display: flex; flex-direction: column; }
.slip-mkt { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: #fff; font-size: 13px; }
.slip-stake { display: flex; align-items: center; gap: 4px; }
.slip-stake input { width: 78px; padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.slip-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; }
.slip-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.bets-metrics { display: flex; gap: 16px 28px; flex-wrap: wrap; }
.bets-metrics .metric { display: flex; flex-direction: column; gap: 2px; }
.bets-metrics .metric .k { font-size: 13px; color: var(--muted); line-height: 1.2; }
.bets-metrics .metric .v { font-size: 22px; font-weight: 800; line-height: 1.15; }
@media (max-width: 620px) { .bets-metrics { display: grid; grid-template-columns: 1fr 1fr; width: 100%; } }
.bet-status { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 20px; }
.bet-status.won { background: var(--green-soft); color: var(--green); }
.bet-status.placed { background: var(--blue-soft); color: var(--purple); }
.bet-status.lost { background: var(--red-soft); color: var(--red); }
.bet-status.pending { background: var(--panel-2); color: var(--muted); }

/* minimise race cards */
.race-card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.head-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.min-btn { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--border); background: var(--panel-2); color: var(--purple); font-size: 18px; line-height: 1; cursor: pointer; flex-shrink: 0; }
.min-btn:hover { background: var(--blue-soft); border-color: var(--purple); }
.race-card.minimised { padding: 12px 16px; opacity: 0.82; }
.race-card.minimised .head { align-items: center; }
.race-card.minimised:hover { opacity: 1; }
