:root {
  --color-bg: #14161c;
  --color-surface: #1e212b;
  --color-surface-alt: #262a36;
  --color-text: #f1f3f8;
  --color-text-muted: #9aa1b2;
  --color-accent: #ffb020;
  --color-accent-text: #14161c;
  --color-scratched: #4a4f5c;
  --color-danger: #e5484d;
  --color-border: #2f3340;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 96px;
  min-height: 100vh;
}

h1, h2 {
  margin: 0 0 12px;
}

.banner {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 0.95rem;
}

.banner--error {
  background: var(--color-danger);
  color: var(--color-text);
}

.banner--settle {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border: 1px solid var(--color-accent);
}

.btn {
  display: inline-block;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: 8px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn--primary {
  background: var(--color-accent);
  color: var(--color-accent-text);
}

/* --- login --- */

.login__title {
  text-align: center;
  margin-bottom: 24px;
}

.login__form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login__label {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.login__input {
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
}

/* --- bet screen --- */

.state__title {
  color: var(--color-text);
}

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

.countdown {
  color: var(--color-accent);
  font-weight: 600;
}

.horse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.horse-btn {
  position: relative;
  min-height: 48px;
  height: 56px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  /* Safari's double-tap-to-zoom otherwise intercepts the first tap on a
     horse button, masking the hx-disabled-elt guard behind it. This also
     removes Safari's ~300ms tap delay. */
  touch-action: manipulation;
}

.horse-btn--selected {
  background: var(--color-accent);
  color: var(--color-accent-text);
  border-color: var(--color-accent);
}

.horse-btn.htmx-request {
  opacity: 0.55;
}

.horse-btn.htmx-request::after {
  content: "…";
}

.horse-btn--scratched {
  background: var(--color-scratched);
  color: var(--color-text-muted);
  border-color: var(--color-scratched);
  pointer-events: none;
  opacity: 0.6;
}

.horse-btn__check {
  position: absolute;
  top: 2px;
  right: 6px;
  font-size: 0.9rem;
}

.your-horse {
  font-size: 4rem;
  font-weight: 800;
  color: var(--color-accent);
  margin: 24px 0;
}

.prev-outcome {
  margin-top: 20px;
  padding: 12px;
  border-radius: 8px;
  background: var(--color-surface);
}

.prev-outcome__race {
  color: var(--color-text-muted);
  margin: 0 0 4px;
  font-size: 0.85rem;
}

.prev-outcome__line {
  margin: 0;
}

/* --- leaderboard --- */

.leaderboard__table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard__row {
  border-bottom: 1px solid var(--color-border);
}

.leaderboard__row td {
  padding: 10px 6px;
}

.leaderboard__row--me {
  background: var(--color-surface-alt);
  font-weight: 700;
}

.leaderboard__row--truncated td {
  color: var(--color-text-muted);
  font-style: italic;
}

.leaderboard__row--pinned {
  border-top: 2px solid var(--color-border);
}

.leaderboard__rank {
  width: 2.5em;
  color: var(--color-text-muted);
}

/* --- bottom tab bar --- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}

.tabbar__tab {
  flex: 1;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 600;
}

.tabbar__tab:hover,
.tabbar__tab:active {
  color: var(--color-accent);
}

.tabbar__tab--active {
  color: var(--color-accent);
}

/* --- operator panel ---------------------------------------------------- */

.page--operator {
  padding-bottom: 24px;
}

.state__subtitle {
  color: var(--color-text-muted);
  margin: 0 0 16px;
}

/* One accent-filled dominant control per view — larger than every other
   button on the page, so the operator can run the evening by looking for
   the one big button. Stacks on top of .btn.btn--primary. */
.operator-primary-btn {
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 16px 28px;
  font-size: 1.25rem;
  margin-top: 12px;
}

/* Visible but muted — used for every subordinate/recovery action (Reopen,
   Correct result, Add guest / Unlock / Fix a bet), vs. a bare .btn which
   has no background/color of its own. */
.btn--secondary {
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.results-entry,
.not-bet-list,
.secondary-actions,
.scratch-list,
.scratch-list--collapsed {
  margin-top: 20px;
}

/* --- results entry: tap-a-position, tap-a-horse ------------------------ */

.results-entry__slots {
  display: flex;
  gap: 10px;
  margin: 12px 0 16px;
}

.results-slot {
  flex: 1;
  min-height: 48px;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  padding: 8px 4px;
}

.results-slot__label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.results-slot__value {
  font-size: 1.3rem;
  font-weight: 700;
}

.results-slot--active {
  border-color: var(--color-accent);
}

.results-slot--filled {
  background: var(--color-surface-alt);
}

.results-entry__grid {
  margin-top: 12px;
}

/* Scratched and already-used are independent facts about a horse — both
   may apply at once (placed in the result being corrected, scratched
   since) — so they're independent classes, not a mutually-exclusive
   if/elif, and get three visually distinct treatments: not running,
   already used, and both. The operator must be able to tell which at a
   glance before tapping. */
.horse-btn--used {
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  border-color: var(--color-border);
  opacity: 0.6;
}

.horse-btn--used::after {
  content: "\2713";
  position: absolute;
  top: 2px;
  right: 6px;
  font-size: 0.9rem;
}

/* Both scratched AND used: background stays the scratched grey — "can't
   run" is the more operationally important fact — but the checkmark badge
   from .horse-btn--used still shows, and the border turns danger-colored,
   so this reads as neither plain scratched nor plain used. Declared
   explicitly rather than relying on cascade order between the two single-
   class rules above, which have equal specificity. */
.horse-btn--scratched.horse-btn--used {
  background: var(--color-scratched);
  color: var(--color-text-muted);
  border-color: var(--color-danger);
}

.results-entry__publish {
  margin-top: 16px;
}

.results-entry__publish:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- open view: bet count + who-hasn't-bet chips ------------------------ */

.bet-count {
  font-size: 2.5rem;
  font-weight: 800;
  margin: 0 0 12px;
}

.bet-count__of {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

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

.chip {
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.85rem;
}

.scratch-list--collapsed summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--color-text-muted);
}

.scratch-warning {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: 6px 0 12px;
}

/* --- scratches ----------------------------------------------------------- */

.scratch-item {
  display: inline-block;
  margin: 0 6px 6px 0;
}

.scratch-item__label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

.scratch-item--scratched .scratch-item__label {
  background: var(--color-scratched);
  color: var(--color-text-muted);
  border-color: var(--color-scratched);
}

.scratch-item__checkbox {
  width: 18px;
  height: 18px;
}

/* --- add-guest result: unmissable, own block, not a flash line --------- */

.added-guest-callout {
  margin: 16px 0 24px;
  padding: 24px;
  border-radius: 12px;
  background: var(--color-accent);
  color: var(--color-accent-text);
  text-align: center;
}

.added-guest-callout__label {
  margin: 0 0 4px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

.added-guest-callout__value {
  margin: 0;
  font-size: 3.5rem;
  font-weight: 800;
  word-break: break-all;
}

/* --- confirm page --------------------------------------------------------- */

.confirm-page {
  min-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 16px;
}

/* --- secondary actions: add guest / unlock / fix a bet ------------------ */

.secondary-actions details {
  margin-bottom: 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--color-surface);
}

.secondary-actions summary {
  cursor: pointer;
  font-weight: 600;
}

.secondary-actions form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.fixbet-horse-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.fixbet-horse-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  touch-action: manipulation;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

.fixbet-horse-option--scratched {
  background: var(--color-scratched);
  color: var(--color-text-muted);
  border-color: var(--color-scratched);
}

.operator-footer {
  margin-top: 32px;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.operator-footer--stale {
  color: var(--color-danger);
  font-weight: 700;
}
