/* Turn for Home — racing-program feel, mobile-first. */
:root {
  --bg: #e8dcc8;
  --paper: #faf8f3;
  --ink: #1a1a1a;
  --muted: #5c5c5c;
  --accent: #274034;
  --accent-light: #3d5c4d;
  --rail: #403427;
  --border: #d4cfc4;
  --player: #1a3d2e;
  --sign-green: #1a3d2e;
  --sign-green-dark: #122a20;
  --sign-gold: #e8c547;
  --sign-gold-dim: #c9a227;
  --gold: #c9a227;
  --gold-light: #f0d878;
  --turf: #2d5a34;
  --dirt: #a67c52;
  --radius: 6px;
  --font: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Roboto Slab", Georgia, "Times New Roman", serif;
  --dirt-tile: url(dirt.svg);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: #9a7048;
  background-image: var(--dirt-tile);
  background-repeat: repeat;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-tap-highlight-color: rgba(39, 64, 52, 0.15);
}

#root {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header — Churchill-style track sign on dirt ── */
.site-header {
  margin-bottom: 1rem;
}

.derby-sign {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 1;
  max-height: 128px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background:
    repeating-linear-gradient(
      90deg,
      var(--sign-green) 0,
      var(--sign-green) 10px,
      var(--sign-green-dark) 10px,
      var(--sign-green-dark) 12px
    );
  border: 3px solid var(--sign-gold);
  border-radius: 2px;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.sign-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--sign-gold);
  font-family: var(--font-display);
  line-height: 1.05;
}

.sign-label {
  font-size: clamp(0.5rem, 2vw, 0.68rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sign-main {
  font-size: clamp(1.35rem, 5.5vw, 2.1rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sign-monogram {
  flex-shrink: 0;
  width: clamp(2.6rem, 12vw, 3.75rem);
  height: clamp(2.6rem, 12vw, 3.75rem);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--sign-gold);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.15);
  color: var(--sign-gold);
  font-family: var(--font-display);
  font-size: clamp(1rem, 4.5vw, 1.45rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  box-shadow: inset 0 0 0 1px rgba(232, 197, 71, 0.25);
}

#app { flex: 1; }

.site-footer {
  margin-top: auto;
  padding-top: 1rem;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.88);
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.site-footer a {
  color: var(--gold-light);
}

/* ── Views ── */
.view {
  position: relative;
  background: var(--paper);
  border: 2px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.6) inset,
    0 2px 8px rgba(39, 64, 52, 0.08);
}

.view::before {
  content: "♘";
  position: absolute;
  top: 0.6rem;
  right: 0.75rem;
  font-size: 1.4rem;
  color: rgba(39, 64, 52, 0.12);
  pointer-events: none;
}

.view h2 {
  margin: 0 0 0.5rem;
  padding-bottom: 0.35rem;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--accent);
  font-weight: 700;
  border-bottom: 2px solid var(--gold);
}

.view .lead {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.howto {
  margin: 0 0 1.25rem;
  padding: 0.75rem 1rem;
  background: rgba(39, 64, 52, 0.06);
  border-left: 4px solid var(--accent);
  font-size: 0.92rem;
}

.howto h3 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--accent);
}

.howto p { margin: 0 0 0.65rem; }
.howto p:last-child { margin-bottom: 0; }

.notice {
  padding: 0.6rem 0.75rem;
  background: #fff3cd;
  border: 1px solid #e6d89c;
  border-radius: var(--radius);
  color: #5c4b00;
}

/* ── Stable bar ── */
.stable-bar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1.1rem 1.25rem;
  margin: -0.5rem -0.5rem 1.25rem;
  background:
    linear-gradient(135deg, var(--accent) 0%, #1a3028 100%);
  color: #fff;
  font-size: 1.05rem;
  border-radius: var(--radius);
  border: 3px solid var(--rail);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), 0 3px 10px rgba(0,0,0,0.12);
}

.stable-bar-main {
  font-weight: 600;
  font-size: 1.2rem;
  line-height: 1.3;
}

.stable-bar .stable-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
}

.stable-bar .record {
  font-weight: 400;
  color: rgba(255,255,255,0.88);
  font-size: 1rem;
}

.stable-bar-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
}

/* Bankroll — always prominent */
.bankroll-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 1rem;
  background: linear-gradient(180deg, #f5e6a8 0%, var(--gold) 50%, #a8861a 100%);
  color: #1a1400;
  border: 3px solid #8b6914;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 3px 6px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.4);
  white-space: nowrap;
}

.bankroll-chip .bankroll-label {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
}

.bankroll-chip .bankroll-amount {
  font-size: 1.45rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.bankroll-chip.bankroll-pending,
[data-live-bankroll].bankroll-pending {
  background: linear-gradient(180deg, #ffd89a 0%, #e07020 100%);
  border-color: #a05010;
  color: #3a1500;
}

.stable-bar .week {
  color: rgba(255,255,255,0.9);
  font-size: 1.05rem;
  font-weight: 600;
}

.stable-bar-btn,
.stable-bar-reset {
  min-height: 44px;
  padding: 0.45rem 0.9rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: transparent;
  border: 2px solid rgba(255,255,255,0.55);
  color: rgba(255,255,255,0.95);
  border-radius: 6px;
  cursor: pointer;
}

.stable-bar-btn:hover,
.stable-bar-reset:hover { background: rgba(255,255,255,0.15); }

/* ── Coat swatches ── */
.coat-swatch {
  display: inline-block;
  flex-shrink: 0;
  width: 1.15em;
  height: 1.15em;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.2);
  box-shadow: inset 0 -2px 4px rgba(0,0,0,0.15);
  vertical-align: middle;
}

.horse-name-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.coat-black  { background: #1a1a1a; }
.coat-bay    { background: linear-gradient(135deg, #6b3420 55%, #1a1a1a 55%); }
.coat-brown  { background: #5c3a1e; }
.coat-grey   { background: linear-gradient(180deg, #b0b0b0, #7a7a7a); }
.coat-palomino { background: linear-gradient(180deg, #f0d060, #c9a040); }
.coat-chestnut { background: #8b3a1a; }
.coat-buckskin { background: linear-gradient(180deg, #d4b870, #a08040); }

/* ── Stable roster ── */
.stable-roster {
  margin: 0 0 1rem;
  padding: 0.75rem;
  background: linear-gradient(180deg, #e8ebe9 0%, #dde1df 100%);
  border: 1px solid var(--border);
  border-left: 4px solid var(--turf);
  border-radius: var(--radius);
}

.stable-roster.empty {
  background: transparent;
  border-style: dashed;
  border-left-style: dashed;
  color: var(--muted);
  font-size: 0.9rem;
}

.stable-roster-title {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.stable-roster-title::before {
  content: "🏇 ";
}

.stable-roster-table,
.auction-table,
.field-table,
.costs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.stable-roster-table th,
.stable-roster-table td,
.auction-table th,
.auction-table td,
.field-table th,
.field-table td,
.costs-table td {
  padding: 0.4rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.stable-roster-table thead th,
.auction-table thead th,
.field-table thead th {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.roster-sub {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
}

/* ── Auction ── */
.auction-table tbody tr:hover:not(.cant-row) {
  background: rgba(39, 64, 52, 0.05);
}

.auction-table .horse-type { color: var(--muted); font-size: 0.85em; }

.auction-table .workout {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.88rem;
}

.auction-table .price,
.costs-table .price {
  font-weight: 700;
  font-size: 0.95rem;
  text-align: right;
  color: #1a5c2e;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.auction-table thead th:last-child,
.auction-table td.price {
  background: rgba(201, 162, 39, 0.08);
}

.auction-table thead th:last-child {
  background: #1f4a38;
}

.auction-table tr.cant-row {
  opacity: 0.75;
}

.auction-table tr.cant-row .price {
  opacity: 1;
  color: #8b1a1a;
}

.auction-table .cant-afford {
  font-size: 0.75rem;
  color: #8b1a1a;
  font-weight: 600;
  white-space: nowrap;
}

.auction-table .select-cell {
  width: 2.5rem;
  text-align: center;
}

.costs-table tr.total td { font-weight: 700; border-top: 2px solid var(--accent); }
.costs-table tr.total .price { color: var(--accent); font-size: 1.05rem; }

/* ── Race list ── */
.race-list {
  margin: 0 0 1rem;
  padding-left: 1.25rem;
}

.race-list li {
  margin-bottom: 0.35rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.race-list li.current {
  font-weight: 600;
  color: var(--accent);
  background: rgba(39, 64, 52, 0.08);
  border-left: 3px solid var(--gold);
  list-style: none;
  margin-left: -1.25rem;
  padding-left: calc(1.25rem + 0.5rem);
}

.race-list.compact { font-size: 0.9rem; }
.race-num { font-weight: 600; color: var(--accent); }

/* ── Track progress (racing view) ── */
.track-progress {
  position: relative;
  height: 2rem;
  margin: 0 0 1rem;
  background: linear-gradient(180deg, var(--dirt) 0%, #8b6340 100%);
  border-radius: 4px;
  border: 2px solid var(--rail);
  overflow: visible;
}

.track-rail {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 18px,
    rgba(255,255,255,0.15) 18px,
    rgba(255,255,255,0.15) 20px
  );
  border-radius: 2px;
  pointer-events: none;
}

.track-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: linear-gradient(180deg, rgba(45,90,52,0.5) 0%, rgba(45,90,52,0.2) 100%);
  border-radius: 2px 0 0 2px;
  transition: width 0.3s ease;
}

.track-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -55%);
  font-size: 1.3rem;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
  transition: left 0.3s ease;
}

/* ── Gate ── */
.gate-wrap {
  border: 3px solid var(--rail);
  border-radius: var(--radius);
  padding: 0.25rem;
  background: linear-gradient(180deg, #c8c8c8 0%, #a0a0a0 100%);
}

.gate-table tbody tr {
  background: #fff;
}

.gate-table tbody tr.player {
  background: rgba(39, 64, 52, 0.12);
  border-left: 4px solid var(--gold);
}

.gate-table td:first-child {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  text-align: center;
  width: 3rem;
}

/* ── Buttons ── */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-light) 0%, var(--accent) 100%);
  color: #fff;
  border-color: #1a3028;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #4a7560 0%, var(--accent-light) 100%);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(0,0,0,0.04);
  color: var(--ink);
}

.form-stable label,
.form-entry label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.form-stable input[type="text"],
.form-entry select {
  width: 100%;
  max-width: 22rem;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  font: inherit;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.form-stable input:focus,
.form-entry select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(39, 64, 52, 0.15);
}

.entry-fee { margin: 0.25rem 0 0.5rem; color: var(--muted); font-size: 0.9rem; }
.warn { color: #8b1a1a; font-weight: 600; }

.field-table tbody tr.player {
  background: rgba(39, 64, 52, 0.1);
  font-weight: 500;
  border-left: 3px solid var(--gold);
}

.call-table thead { background: #1f6b3a; }

.race-call-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0.5rem 0;
  font-size: 1.05rem;
  color: var(--accent);
  font-weight: 600;
}

.furlong-label {
  font-family: var(--font-display);
  font-size: 1.15rem;
}

.hint { font-size: 0.85rem; color: var(--muted); }

.board {
  margin: 0.75rem 0;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, rgba(39, 64, 52, 0.08) 0%, rgba(201, 162, 39, 0.1) 100%);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  line-height: 1.8;
  font-size: 1rem;
}

.board div::before {
  content: "🏆 ";
}

.result-msg { margin: 0.5rem 0 1rem; }
.result-msg strong { color: var(--accent); }

.leaders-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.leaders-col {
  background: rgba(39, 64, 52, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}

.leaders-col h3 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.leaders-col ul {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
}

.leaders-col li { margin-bottom: 0.55rem; }
.muted { color: var(--muted); }

.build-stamp {
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.85;
  margin-top: 0.5rem;
}

.table-wrap { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 640px) {
  .derby-sign {
    max-height: 100px;
    padding: 0.4rem 0.5rem;
    gap: 0.25rem;
  }

  .sign-label {
    letter-spacing: 0.08em;
  }

  .stable-bar { padding: 0.95rem 1rem; }
  .stable-bar .stable-name { font-size: 1.2rem; }
  .bankroll-chip .bankroll-amount { font-size: 1.25rem; }
  .bankroll-chip { padding: 0.4rem 0.85rem; }
  .btn {
    min-height: 48px;
    width: 100%;
    max-width: 22rem;
  }
  .btn-ghost { width: auto; }
  .stable-roster-table { font-size: 0.78rem; }
}
