/* Turn for Home — Beta. Racing-program feel, readable, no table layout. */
:root {
  --bg: #f5f0e8;
  --paper: #faf8f3;
  --ink: #1a1a1a;
  --muted: #5c5c5c;
  --accent: #274034;
  --accent-light: #3d5c4d;
  --gold: #b8860b;
  --border: #d4cfc4;
  --player: #1a3d2e;
  --radius: 6px;
  --font: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  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: 640px;
  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;
}

.site-header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--accent);
}

.site-header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.tagline {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

#app {
  flex: 1;
}

.site-footer {
  margin-top: auto;
  padding-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

/* Views */
.view {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1rem;
  margin-bottom: 1rem;
}

.view h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  color: var(--accent);
  font-weight: 600;
}

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

/* Stable bar (shared) */
.stable-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.6rem 0.8rem;
  margin: -0.5rem -0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  border-radius: var(--radius);
  align-items: center;
}

.stable-bar .stable-name {
  font-weight: 600;
}

.stable-bar .record,
.stable-bar .bankroll {
  color: rgba(255,255,255,0.9);
}

.stable-bar .week {
  margin-left: auto;
  color: rgba(255,255,255,0.85);
}

.stable-bar-reset {
  margin-left: auto;
  min-height: 44px;
  min-width: 44px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.5);
  color: rgba(255,255,255,0.9);
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

/* Stable roster (always visible when you have a stable) */
.stable-roster {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stable-roster-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}

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

.stable-roster-table th,
.stable-roster-table td {
  padding: 0.3rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.stable-roster-table thead th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
}

.stable-roster-table .roster-name {
  font-weight: 500;
}

.stable-roster-table .roster-stats {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
}

.stable-roster-table .roster-record,
.stable-roster-table .roster-ready {
  color: var(--muted);
}

.stable-roster-table .roster-earnings {
  font-weight: 500;
}

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

.race-list li {
  margin-bottom: 0.35rem;
}

.race-list li.current {
  font-weight: 600;
  color: var(--accent);
}

.race-list .btn-small {
  margin-left: 0.5rem;
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
}

/* 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;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-light);
  border-color: var(--accent-light);
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--bg);
  color: var(--ink);
}

.btn-small {
  min-height: 36px;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

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

.btn-reset:hover:not(:disabled) {
  color: var(--ink);
}

/* Forms */
.form-stable,
.form-entry {
  margin-top: 1rem;
}

.form-stable label,
.form-entry label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
}

.form-stable input[type="text"],
.form-entry select {
  width: 100%;
  max-width: 20rem;
  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);
}

.dropdown-note {
  margin: 0.25rem 0 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 28rem;
}

.entry-fee {
  margin: 0.25rem 0 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

/* Field / result table */
.field-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.field-table th,
.field-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.field-table thead {
  background: var(--accent);
  color: #fff;
}

.field-table thead th {
  font-weight: 600;
}

.field-table tbody tr.player {
  background: rgba(39, 64, 52, 0.08);
  font-weight: 500;
}

.field-table tbody tr.player td {
  color: var(--player);
}

.result-msg {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.result-msg strong {
  color: var(--accent);
}

/* Auction */
.view-auction .form-auction {
  margin-top: 0.5rem;
}

.auction-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.auction-table th,
.auction-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.auction-table thead {
  background: var(--accent);
  color: #fff;
}

.auction-table thead th {
  font-weight: 600;
}

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

.auction-table .horse-stats {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
}

.auction-table .price {
  font-weight: 500;
}

.auction-table .cant-afford {
  color: var(--muted);
  font-size: 0.85rem;
}

/* Table wrapper for horizontal scroll on small screens */
.table-wrap {
  display: block;
}

/* ========== Mobile & touch ========== */
@media (max-width: 640px) {
  #root {
    padding: 0.5rem 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }

  .site-header h1 {
    font-size: 1.5rem;
  }

  .view {
    padding: 0.75rem 0.75rem;
  }

  .view h2 {
    font-size: 1.15rem;
  }

  .stable-bar {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    padding: 0.5rem 0.6rem;
    font-size: 0.8rem;
  }

  .stable-roster {
    padding: 0.5rem 0.6rem;
    margin-left: -0.25rem;
    margin-right: -0.25rem;
  }

  .stable-roster-table {
    font-size: 0.8rem;
  }

  .stable-roster-table th,
  .stable-roster-table td {
    padding: 0.35rem 0.4rem;
  }

  /* Scrollable tables so no horizontal page scroll */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1rem -0.5rem;
    padding: 0 0.5rem;
  }

  .field-table,
  .auction-table,
  .stable-roster-table {
    min-width: 280px;
  }

  .field-table th,
  .field-table td,
  .auction-table th,
  .auction-table td {
    padding: 0.5rem 0.4rem;
    font-size: 0.85rem;
  }

  .actions {
    gap: 0.5rem;
  }

  .btn {
    min-height: 48px;
    padding: 0.6rem 1rem;
    width: 100%;
    max-width: 20rem;
  }

  .btn-ghost {
    width: auto;
    max-width: none;
  }

  .race-list .btn-small {
    min-height: 36px;
  }

  .dropdown-note {
    font-size: 0.8rem;
  }
}

/* Very small screens */
@media (max-width: 380px) {
  .stable-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .stable-bar .week,
  .stable-bar-reset {
    margin-left: 0;
  }

  .stable-roster-table thead th {
    font-size: 0.7rem;
  }

  .stable-roster-table td {
    font-size: 0.75rem;
  }
}
