/* ============================================================
   Horse Racing Simulator — app.css
   ============================================================ */

:root {
    --bg:        #0d1117;
    --surface:   #161b22;
    --surface2:  #1e2530;
    --border:    #30363d;
    --text:      #e6edf3;
    --muted:     #8b949e;
    --accent:    #2f81f7;
    --accent2:   #f7a825;
    --green:     #3fb950;
    --red:       #f85149;
    --gold:      #f1c40f;
    --radius:    12px;
    --radius-sm: 7px;
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 15px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin-top: 0; font-weight: 700; }

/* ── Container ─────────────────────────────────────────── */
.container {
    max-width: 1280px;
    margin: 28px auto;
    padding: 0 20px 60px;
}

/* ── Section titles ────────────────────────────────────── */
.section-title {
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    margin: 32px 0 18px;
}

/* ── Buttons ───────────────────────────────────────────── */
button, .button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--accent);
    color: #fff;
    border: 0;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    cursor: pointer;
    font-size: .92rem;
    font-weight: 600;
    transition: background .15s, transform .1s;
}
button:hover, .button:hover { background: #1a6fe8; transform: translateY(-1px); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.button-sim {
    background: linear-gradient(135deg, #f7a825, #e8830a);
    color: #000;
    font-weight: 700;
    padding: 11px 22px;
    font-size: 1rem;
}
.button-sim:hover { background: linear-gradient(135deg, #ffc53d, #f7a825); }

/* ── Forms ─────────────────────────────────────────────── */
label { display: block; margin-bottom: 14px; font-weight: 600; }
input, textarea, select {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: .93rem;
    width: 100%;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47,129,247,.2);
}
textarea { min-height: 80px; resize: vertical; }

/* ── Race header ───────────────────────────────────────── */
.race-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.race-header h1 {
    font-size: 1.75rem;
    margin-bottom: 10px;
}
.race-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    margin-top: 4px;
}
.runs-label { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.runs-select { width: auto; padding: 8px 12px; }

/* ── Meta badges ───────────────────────────────────────── */
.race-meta-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 4px;
}
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: .78rem;
    font-weight: 600;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
}
.badge-surface.dirt   { background: #3a2910; border-color: #8a5a1a; color: #f0a830; }
.badge-surface.turf   { background: #0e2d12; border-color: #2a6e2a; color: #5fca6a; }
.badge-surface.synthetic { background: #1a1d3a; border-color: #3a3d7a; color: #9090f0; }
.badge-purse   { background: #1e2b10; border-color: #3a5a18; color: #90d040; }
.badge-class   { background: #2a1a10; border-color: #6a3010; color: #f09060; }

/* ── Horse grid ────────────────────────────────────────── */
.horse-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 16px;
    margin-bottom: 40px;
}

/* ── Horse card ────────────────────────────────────────── */
.horse-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: border-color .2s, box-shadow .2s;
    position: relative;
}
.horse-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 20px rgba(47,129,247,.12);
}
.horse-card.scratched { opacity: .45; }

/* confidence colours — left border accent */
.horse-card.conf-hot  { border-left: 3px solid var(--gold); }
.horse-card.conf-warm { border-left: 3px solid var(--green); }
.horse-card.conf-mid  { border-left: 3px solid var(--accent); }
.horse-card.conf-cold { border-left: 3px solid var(--border); }

.horse-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.post-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface2);
    border: 2px solid var(--border);
    font-weight: 700;
    font-size: .95rem;
    flex-shrink: 0;
}
.horse-card-name {
    flex: 1;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
}
.scratch-label {
    font-size: .7rem;
    background: var(--red);
    color: #fff;
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 6px;
}
.sim-win-badge {
    font-size: .95rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--surface2);
    border: 1px solid var(--border);
    flex-shrink: 0;
}
.sim-win-badge.conf-hot  { background: rgba(241,196,15,.15);  border-color: var(--gold);  color: var(--gold); }
.sim-win-badge.conf-warm { background: rgba(63,185,80,.15);   border-color: var(--green); color: var(--green); }
.sim-win-badge.conf-mid  { background: rgba(47,129,247,.15);  border-color: var(--accent); color: var(--accent); }
.sim-win-badge.conf-cold { background: var(--surface2); color: var(--muted); }

/* stats pills */
.horse-stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}
.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px 9px;
    font-size: .78rem;
}
.stat-label { color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.stat-val { font-weight: 700; }
.rpr-val  { color: var(--accent2); }
.form-str { font-family: monospace; letter-spacing: .05em; }
.odds-val { color: var(--green); }

/* people pills */
.horse-people-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
.person-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: .8rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 8px;
}
.person-role {
    font-size: .7rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--border);
    border-radius: 3px;
    padding: 1px 4px;
}
.person-stat {
    font-size: .72rem;
    color: var(--green);
    font-weight: 700;
}

/* breeding */
.horse-breeding {
    font-size: .78rem;
    color: var(--muted);
    margin-bottom: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* sim bar */
.horse-sim-bar-wrap {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 8px 0 6px;
    overflow: hidden;
}
.horse-sim-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    border-radius: 2px;
    transition: width .5s;
}
.horse-sim-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: .78rem;
    color: var(--muted);
}
.longshot-flag { color: var(--gold); font-weight: 700; }

/* ── Results table ─────────────────────────────────────── */
.results-section {
    margin-top: 16px;
}
.results-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}
.results-meta { font-size: .82rem; color: var(--muted); }

.results-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0 20px;
}
.results-table th {
    background: var(--surface2);
    color: var(--muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 10px 12px;
    border-bottom: 2px solid var(--border);
    text-align: left;
}
.results-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    font-size: .88rem;
}
.results-table .num-col { text-align: right; }
.result-row-first td { background: rgba(241,196,15,.06); }
.result-row:hover td { background: var(--surface2); }

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-weight: 700;
    font-size: .8rem;
    background: var(--surface2);
    border: 1px solid var(--border);
}
.rank-badge.rank-1 { background: rgba(241,196,15,.2); border-color: var(--gold);  color: var(--gold); }
.rank-badge.rank-2 { background: rgba(192,192,192,.15); border-color: #aaa; color: #ccc; }
.rank-badge.rank-3 { background: rgba(205,127,50,.15);  border-color: #cd7f32; color: #cd7f32; }

.horse-name-cell { font-weight: 600; }

.win-bar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}
.win-bar {
    height: 6px;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    border-radius: 3px;
    min-width: 2px;
    flex-shrink: 0;
}

.longshot-cell { color: var(--gold); font-weight: 700; }

.results-footnote {
    font-size: .78rem;
    color: var(--muted);
    line-height: 1.6;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

/* ── Simulation overlay ─────────────────────────────────── */
.sim-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.75);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

.sim-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    width: 100%;
    max-width: 540px;
    padding: 32px;
    box-shadow: 0 24px 80px rgba(0,0,0,.6);
    animation: modal-in .2s ease;
}

@keyframes modal-in {
    from { opacity: 0; transform: scale(.94) translateY(12px); }
    to   { opacity: 1; transform: scale(1)  translateY(0);  }
}

.sim-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}
.sim-icon {
    font-size: 1.8rem;
    animation: pulse 1.2s ease infinite;
}
@keyframes pulse {
    0%,100% { opacity: 1; }
    50%      { opacity: .5; }
}
#sim-title {
    font-size: 1.3rem;
    font-weight: 700;
}

.sim-meta {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 14px;
    font-size: .95rem;
}
.sim-counter {
    font-size: 1.6rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--accent2);
    min-width: 60px;
}
.sim-of { color: var(--muted); }

.sim-progress-track {
    height: 12px;
    background: var(--surface2);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 24px;
    position: relative;
}
.sim-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent) 0%, var(--accent2) 100%);
    border-radius: 6px;
    transition: width .3s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    position: relative;
}
.sim-pct-label {
    position: absolute;
    right: -36px;
    top: 50%;
    transform: translateY(-50%);
    font-size: .72rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.sim-leaderboard { margin-bottom: 20px; }
.sim-lb-title {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin-bottom: 10px;
}
.sim-leaders {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.sim-leader-placeholder {
    color: var(--muted);
    font-style: italic;
    font-size: .88rem;
}
.sim-leader-item {
    display: grid;
    grid-template-columns: 22px 1fr 90px 48px;
    align-items: center;
    gap: 8px;
    font-size: .88rem;
    animation: fade-in .2s ease;
}
@keyframes fade-in {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}
.sl-rank {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface2);
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: .75rem;
    font-weight: 700;
    flex-shrink: 0;
}
.sl-name  { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sl-bar-wrap {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.sl-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    border-radius: 3px;
    transition: width .4s ease;
}
.sl-pct {
    text-align: right;
    font-weight: 700;
    color: var(--accent2);
    font-size: .85rem;
    white-space: nowrap;
}

.sim-status {
    font-size: .82rem;
    color: var(--muted);
    text-align: center;
    min-height: 20px;
}

/* ── Generic table (other pages) ───────────────────────── */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0 28px;
}
th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
th {
    background: var(--surface2);
    color: var(--muted);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .06em;
}
tr:hover td { background: var(--surface2); }

/* ── Muted text ─────────────────────────────────────────── */
.muted { color: var(--muted); }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 700px) {
    .race-header { flex-direction: column; }
    .horse-grid  { grid-template-columns: 1fr; }
    .sim-modal   { padding: 22px 16px; }
    .sim-counter { font-size: 1.2rem; }
}

