:root {
    --bg: #0f0f14;
    --surface: #1a1a22;
    --surface-2: #23232d;
    --border: #2f2f3b;
    --text: #f3f3f6;
    --muted: #9b9bab;
    --red: #e10600;
    --red-soft: rgba(225, 6, 0, 0.16);
    --green: #22c55e;
    --green-soft: rgba(34, 197, 94, 0.15);
    --amber: #f5b301;
    --amber-soft: rgba(245, 179, 1, 0.15);
    --purple: #a855f7;
    --purple-soft: rgba(168, 85, 247, 0.18);
    --radius: 12px;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Titillium Web", system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

a { color: inherit; }

/* ---------- Top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(15, 15, 20, 0.92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.topbar-inner, .tabs, .page {
    max-width: 760px;
    margin: 0 auto;
    padding-left: 16px;
    padding-right: 16px;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 900;
    font-size: 1.25rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-decoration: none;
}

.brand-mark {
    width: 22px;
    height: 14px;
    background: var(--red);
    transform: skewX(-20deg);
    border-radius: 2px;
}

.logout {
    color: var(--muted);
    font-size: 0.85rem;
    text-decoration: none;
}

.tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tabs a {
    flex: 0 0 auto;
    padding: 10px 14px;
    color: var(--muted);
    font-weight: 600;
    text-decoration: none;
    border-bottom: 3px solid transparent;
}

.tabs a.active {
    color: var(--text);
    border-bottom-color: var(--red);
}

/* ---------- Page ---------- */

.page {
    padding-top: 20px;
    padding-bottom: 48px;
}

h1, h2, h3 {
    margin: 0 0 8px;
    line-height: 1.15;
}

h1 { font-size: 1.75rem; font-weight: 900; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }

.eyebrow {
    color: var(--red);
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 4px;
}

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

.section { margin-top: 28px; }

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.card + .card { margin-top: 12px; }

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-weight: 600;
}

.alert.error { background: var(--red-soft); color: #ff8a85; }
.alert.ok { background: var(--green-soft); color: #7ee2a4; }

/* ---------- Chips ---------- */

.chip {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    background: var(--surface-2);
    color: var(--muted);
}

.chip.eats { background: var(--green-soft); color: var(--green); }
.chip.buys { background: var(--red-soft); color: #ff6a64; }
.chip.tie { background: var(--amber-soft); color: var(--amber); }
.chip.live { background: var(--red); color: #fff; }
.chip.done { background: var(--green-soft); color: var(--green); }
.chip.open { background: var(--purple-soft); color: var(--purple); }

/* ---------- Tables ---------- */

.table-wrap {
    overflow-x: auto;
    margin: 0 -16px;
    padding: 0 16px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

th, td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

tr:last-child td { border-bottom: none; }

td.num, th.num { text-align: right; }

td.pos {
    width: 2.2em;
    font-weight: 900;
    color: var(--muted);
}

tr.me td { background: rgba(255, 255, 255, 0.04); }
tr.me td.name { font-weight: 700; }

td.total {
    font-weight: 900;
    font-size: 1.1rem;
}

tr.line td { border-bottom: 2px dashed var(--border); }

th a, td a { text-decoration: none; }
th a:hover, td a:hover { color: var(--text); text-decoration: underline; }

/* ---------- Leaderboard ---------- */

.podium {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 16px 0 4px;
}

.podium .spot {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 8px;
    text-align: center;
}

.podium .spot.first { border-color: var(--red); }

.podium .place {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
}

.podium .who {
    font-weight: 700;
    font-size: 1.05rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.podium .pts {
    font-weight: 900;
    font-size: 1.5rem;
}

.leg-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

/* ---------- Forms ---------- */

.pick-grid {
    display: grid;
    gap: 10px;
}

.pick-slot {
    display: grid;
    grid-template-columns: 44px 1fr;
    align-items: center;
    gap: 10px;
}

.slot-num {
    font-weight: 900;
    font-size: 1.1rem;
    text-align: center;
    padding: 10px 0;
    border-radius: 8px;
    background: var(--surface-2);
}

.pick-slot:nth-child(-n+3) .slot-num { background: var(--red); }

select, input[type="password"], input[type="text"], input[type="datetime-local"] {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    font: inherit;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    appearance: none;
    -webkit-appearance: none;
}

select {
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                      linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: 34px;
}

select:focus, input:focus, button:focus-visible {
    outline: 2px solid var(--red);
    outline-offset: 1px;
}

select option:disabled { color: #555; }

label.field {
    display: block;
    margin-bottom: 14px;
}

label.field > span {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
    margin-bottom: 6px;
}

button, .button {
    display: inline-block;
    min-height: 48px;
    padding: 12px 20px;
    font: inherit;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #fff;
    background: var(--red);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

button.block { width: 100%; margin-top: 16px; }

button.ghost {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    min-height: 40px;
    padding: 8px 14px;
    font-size: 0.85rem;
}

.lock-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 12px 0 18px;
    padding: 12px 14px;
    background: var(--surface-2);
    border-radius: 10px;
}

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

/* ---------- Rounds ---------- */

.race-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.race-list li { border-bottom: 1px solid var(--border); }
.race-list li:last-child { border-bottom: none; }

.race-list a, .race-list .cancelled {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 12px 0;
    text-decoration: none;
}

.race-list .rnd {
    font-weight: 900;
    color: var(--muted);
}

.race-list .cancelled { opacity: 0.45; }
.race-list .cancelled .race-name { text-decoration: line-through; }

.race-name { font-weight: 700; }

/* ---------- Round detail ---------- */

.round-nav {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 0.9rem;
}

.round-nav a {
    color: var(--muted);
    text-decoration: none;
}

.results-list {
    list-style: none;
    margin: 0;
    padding: 0;
    columns: 2;
    column-gap: 20px;
}

.results-list li {
    display: flex;
    gap: 10px;
    padding: 5px 0;
    break-inside: avoid;
}

.results-list .p {
    width: 2.4em;
    font-weight: 900;
    color: var(--muted);
    flex: 0 0 auto;
}

.results-list li:nth-child(-n+3) .p { color: var(--red); }
.results-list li.top7 .name { font-weight: 700; }

.player-card .card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 8px;
}

.player-card .score {
    font-size: 1.6rem;
    font-weight: 900;
}

.pick-line {
    display: grid;
    grid-template-columns: 34px 1fr auto 44px;
    gap: 8px;
    align-items: center;
    padding: 7px 8px;
    border-radius: 8px;
    margin-bottom: 4px;
    background: var(--surface-2);
    font-variant-numeric: tabular-nums;
}

.pick-line .slot { font-weight: 900; color: var(--muted); }
.pick-line .driver { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-line .finished { color: var(--muted); font-size: 0.85rem; text-align: right; }
.pick-line .pts { font-weight: 900; text-align: right; }

.pick-line.exact { background: var(--purple-soft); }
.pick-line.exact .pts, .pick-line.exact .finished { color: var(--purple); }
.pick-line.close { background: var(--green-soft); }
.pick-line.close .pts { color: var(--green); }
.pick-line.dnf { background: var(--red-soft); }
.pick-line.dnf .pts, .pick-line.dnf .finished { color: #ff6a64; }
.pick-line.miss .driver { color: var(--muted); }

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    font-size: 0.8rem;
    color: var(--muted);
    margin: 8px 0 14px;
}

.legend i {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    margin-right: 5px;
    vertical-align: -1px;
}

/* ---------- Login ---------- */

.login {
    max-width: 380px;
    margin: 8vh auto 0;
}

.login .brand { font-size: 2rem; margin-bottom: 4px; }
.login .brand-mark { width: 30px; height: 18px; }

/* ---------- Admin ---------- */

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 20px;
}

.inline-form {
    display: flex;
    gap: 6px;
    align-items: center;
}

.inline-form input { min-height: 38px; padding: 6px 8px; min-width: 190px; }

@media (min-width: 640px) {
    .pick-grid { grid-template-columns: 1fr 1fr; column-gap: 16px; }
    h1 { font-size: 2rem; }
}

@media (max-width: 420px) {
    .results-list { columns: 1; }
    .podium .pts { font-size: 1.25rem; }
}
