:root {
    --bg: #f6f5f1;
    --fg: #1a1a1a;
    --muted: #6a6a6a;
    --line: #e2e0d8;
    --accent: #b8002e;
    --card: #ffffff;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.5;
}

.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 2rem 1rem 4rem;
}

.page-header {
    border-bottom: 1px solid var(--line);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    margin: 0;
    font-size: 1.8rem;
    letter-spacing: -0.01em;
}

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

.empty {
    color: var(--muted);
    padding: 2rem 0;
}

.empty code {
    background: var(--card);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    border: 1px solid var(--line);
    font-size: 0.85em;
}

.day-group {
    margin-bottom: 1.75rem;
}

.day-heading {
    font-size: 1rem;
    font-weight: 600;
    text-transform: capitalize;
    color: var(--muted);
    margin: 0 0 0.5rem;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.day-iso {
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}

.meeting {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    margin-bottom: 0.4rem;
    color: var(--fg);
    text-decoration: none;
    transition: border-color 120ms, background 120ms;
}
.meeting:hover {
    border-color: var(--accent);
    background: #fdfdf9;
}

.meeting.multi-track {
    background: #fafaf6;
    border-style: dashed;
}

.meeting-main {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.flag {
    font-size: 1.1rem;
}

.track-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    font-size: 0.7rem;
    background: var(--line);
    color: var(--muted);
    padding: 0.1rem 0.45rem;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.meeting-meta {
    display: flex;
    gap: 0.75rem;
    color: var(--muted);
    font-size: 0.85rem;
    align-items: center;
    flex-shrink: 0;
}

.pools code {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 0.05rem 0.35rem;
    font-size: 0.75rem;
    margin-right: 0.2rem;
}

@media (max-width: 480px) {
    .meeting {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.35rem;
    }
    .meeting-meta {
        width: 100%;
        justify-content: space-between;
    }
}

/* Horse detail page */
.back {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
}
.back:hover { color: var(--fg); }

.horse-header h1 {
    margin: 0;
    font-size: 2rem;
}
.horse-header .nat {
    color: var(--muted);
    font-size: 1rem;
    font-weight: 400;
}

.horse-facts {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 1rem 1.25rem;
    margin: 1.25rem 0;
}
.horse-facts dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.4rem 1.25rem;
    margin: 0;
}
.horse-facts dt {
    color: var(--muted);
    font-size: 0.85rem;
}
.horse-facts dd {
    margin: 0;
}

.form-graph {
    margin: 2rem 0 1rem;
}
.form-graph h2 {
    font-size: 1rem;
    margin: 0 0 0.5rem;
}
.form-graph .subtle {
    font-weight: 400;
}

svg.graph {
    width: 100%;
    height: auto;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
}
svg.graph .grid {
    stroke: var(--line);
    stroke-width: 0.5;
    stroke-dasharray: 2 3;
}
svg.graph .ylabel,
svg.graph .axis-label {
    font-size: 9px;
    fill: var(--muted);
    font-family: inherit;
}
svg.graph .axis-label.end {
    text-anchor: end;
}
svg.graph .ylabel {
    text-anchor: end;
}
svg.graph .line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 1.5;
    opacity: 0.5;
}
svg.graph .dot {
    fill: #c9c4b5;
    stroke: white;
    stroke-width: 1;
}
svg.graph .dot.podium {
    fill: #d9a05a;
}
svg.graph .dot.win {
    fill: var(--accent);
}
svg.graph .dot.src-historical {
    fill: transparent;
    stroke: var(--muted);
    stroke-width: 1.2;
}
svg.graph .dot.src-historical.podium {
    stroke: #b07a35;
}
svg.graph .dot.src-historical.win {
    stroke: var(--accent);
}

.legend {
    font-size: 0.75rem;
    color: var(--muted);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin: 0.4rem 0 0;
    flex-wrap: wrap;
}
.legend .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #c9c4b5;
}
.legend .dot.podium { background: #d9a05a; }
.legend .dot.win { background: var(--accent); }
.legend .legend-mark {
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1;
}

.form-graph.empty {
    background: var(--card);
    border: 1px dashed var(--line);
    border-radius: 6px;
    padding: 1.25rem;
    text-align: center;
}

.form-table {
    margin-top: 1.5rem;
}
.form-table h2 {
    font-size: 1rem;
    margin: 0 0 0.5rem;
}
.form-table table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
    font-size: 0.85rem;
}
.form-table th {
    text-align: left;
    background: var(--bg);
    color: var(--muted);
    font-weight: 600;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--line);
}
.form-table td {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--line);
}
.form-table tbody tr:last-child td {
    border-bottom: none;
}
.form-table td.place {
    font-weight: 600;
}
.form-table td.nowrap {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.form-table .src {
    text-align: right;
    font-size: 0.75rem;
}

@media (max-width: 600px) {
    .form-table {
        overflow-x: auto;
    }
}

/* Race day detail page */
.raceday-page .raceday-header h1 {
    margin: 0;
    font-size: 1.7rem;
}

.pools-overview {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin: 1rem 0 1.5rem;
}
.pool-card {
    flex: 1 1 auto;
    min-width: 140px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
    text-decoration: none;
    color: inherit;
    transition: border-color 120ms, transform 120ms;
}
a.pool-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}
.pool-card strong {
    display: block;
    font-size: 1rem;
    color: var(--accent);
}

.race-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}
.race-header h2 {
    margin: 0;
    font-size: 1.1rem;
    display: flex;
    align-items: baseline;
    gap: 0.7rem;
}
.race-header .race-time {
    color: var(--muted);
    font-weight: 400;
    font-variant-numeric: tabular-nums;
    font-size: 0.95rem;
}
.race-meta {
    margin-top: 0.2rem;
    font-size: 0.9rem;
}
.race-meta .race-name {
    font-weight: 500;
    margin-right: 0.4rem;
}
.race-conditions {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.race-conditions summary {
    cursor: pointer;
}
.race-conditions p {
    margin: 0.4rem 0 0;
    line-height: 1.5;
}
.abandoned-flag {
    color: #83122a;
    background: #fde9ed;
    border: 1px solid #f5b8c5;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    margin: 0.6rem 0 0;
    font-size: 0.85rem;
    display: inline-block;
}

.start-list {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.75rem;
    font-size: 0.88rem;
}
.start-list th {
    text-align: left;
    color: var(--muted);
    font-weight: 600;
    border-bottom: 1px solid var(--line);
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.start-list td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.start-list tbody tr:last-child td {
    border-bottom: none;
}
.start-list td.start-no {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    width: 3rem;
}
.start-list td.place-col {
    text-align: right;
    font-variant-numeric: tabular-nums;
    width: 4rem;
}
.start-list a {
    color: var(--fg);
    text-decoration: none;
    border-bottom: 1px dotted var(--line);
}
.start-list a:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.start-list tr.placed.place-1 td { background: rgba(184, 0, 46, 0.06); }
.start-list tr.placed.place-1 .place-col strong { color: var(--accent); }
.start-list tr.placed.place-2 td { background: rgba(217, 160, 90, 0.08); }
.start-list tr.placed.place-3 td { background: rgba(217, 160, 90, 0.04); }

/* Tips page */
.tips-page .tips-summary {
    margin: 0.5rem 0 1rem;
    padding: 0.6rem 0.75rem;
    background: rgba(184, 0, 46, 0.06);
    border-left: 3px solid var(--accent);
    border-radius: 3px;
    font-size: 0.95rem;
}
.tips-page .tip-pick {
    display: inline-block;
    margin-right: 0.5rem;
    font-weight: 500;
}
.tips-table th.num,
.tips-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    width: 3.2rem;
}
.tips-table .score-total {
    font-size: 1.05rem;
    color: var(--accent);
}
.tips-table tr.top-pick td { background: rgba(184, 0, 46, 0.04); }
.tips-table tr.rank-1 .score-total { font-weight: 700; }
.tips-table .tips-detail {
    font-size: 0.78rem;
    max-width: 16rem;
}
.raceday-header a.tips-link {
    display: inline-block;
    margin-top: 0.5rem;
    color: var(--accent);
    border-bottom: 1px dotted var(--accent);
    text-decoration: none;
    font-weight: 500;
}
.tips-pool-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.8rem 0 0.6rem;
}
.tips-pool-nav a {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 0.85rem;
    color: var(--fg);
    text-decoration: none;
    background: var(--card);
}
.tips-pool-nav a.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.tips-pool-nav a:hover {
    border-color: var(--accent);
}
.combo-suggest {
    background: var(--card);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    padding: 0.8rem 1rem;
    margin: 1rem 0 1.5rem;
}
.combo-suggest h2 {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
}
.combo-suggest ol.combo-races {
    margin: 0 0 0.5rem;
    padding-left: 1.2rem;
}
.combo-suggest li {
    margin-bottom: 0.25rem;
}

/* Login page */
.login-page {
    max-width: 360px;
    margin: 4rem auto;
    text-align: left;
}
.login-page h1 {
    text-align: center;
    margin: 0 0 1.5rem;
    font-size: 1.6rem;
}
.login-page .error {
    background: #fde9ed;
    color: #83122a;
    border: 1px solid #f5b8c5;
    padding: 0.6rem 0.8rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.login-form {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    background: var(--card);
    padding: 1.25rem;
    border: 1px solid var(--line);
    border-radius: 6px;
}
.login-form label {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.5rem;
}
.login-form input {
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 1rem;
    background: white;
}
.login-form input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}
.login-form .remember-me {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.75rem;
    color: var(--fg);
    font-size: 0.9rem;
    cursor: pointer;
}
.login-form .remember-me input {
    width: auto;
    margin: 0;
}

.login-form button {
    margin-top: 0.75rem;
    padding: 0.6rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.login-form button:hover {
    background: #9a0026;
}

.user-bar {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
    font-size: 0.8rem;
    color: var(--muted);
    display: flex;
    gap: 0.6rem;
    align-items: center;
}
.user-bar a {
    color: var(--accent);
    text-decoration: none;
}
.user-bar a:hover {
    text-decoration: underline;
}
