/* PySport Live — public live results. Mobile first; light and dark follow the
   phone. Colours are tokens on :root; components only reference tokens. */

:root {
    --bg: #eef2f6;
    --surface: #ffffff;
    --surface-2: #f4f7fa;
    --ink: #14212b;
    --muted: #5b6b78;
    --line: #d9e1e8;
    --accent: #e8590c;
    --accent-ink: #ffffff;
    --bar: #0f2a43;
    --bar-ink: #ffffff;
    --live: #1f9d55;
    --r1: #d62828;
    --r2: #1c3f94;
    --r3: #3b82d6;
    --warn-bg: #fdecd9;
    --warn-ink: #8a3b00;
    --hl: #fff4c2;
    --shadow: 0 1px 2px rgba(15, 42, 67, .08), 0 2px 8px rgba(15, 42, 67, .06);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b141b;
        --surface: #131f29;
        --surface-2: #1a2834;
        --ink: #e8eef3;
        --muted: #8fa3b3;
        --line: #26384a;
        --accent: #ff8a3d;
        --accent-ink: #1b1007;
        --bar: #0a1c2d;
        --live: #3ddc84;
        --r1: #ff6b6b;
        --r2: #8fb0ff;
        --r3: #5cb4ff;
        --warn-bg: #3a2514;
        --warn-ink: #ffc08a;
        --hl: #3a3410;
        --shadow: none;
        color-scheme: dark;
    }
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    min-height: 100vh;
}

button, input, select { font: inherit; color: inherit; }

a { color: inherit; }

/* ── header ─────────────────────────────────────────────────────────────── */

.hdr {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: var(--bar);
    color: var(--bar-ink);
    border-bottom: 3px solid var(--accent);
}

.hdr-home {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    text-decoration: none;
}

.hdr-logo { border-radius: 6px; flex: none; }

.hdr-title {
    font-weight: 700;
    letter-spacing: .01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lang {
    flex: none;
    background: rgba(255, 255, 255, .12);
    color: var(--bar-ink);
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: 8px;
    padding: 6px 8px;
    font-weight: 600;
}

.lang option { color: #14212b; }

/* ── page ───────────────────────────────────────────────────────────────── */

.main {
    max-width: 880px;
    margin: 0 auto;
    padding: 16px 16px 48px;
}

.muted { color: var(--muted); }

.section {
    margin: 24px 0 10px;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}

.event-name, .group-name {
    margin: 0;
    font-size: 1.6rem;
    line-height: 1.15;
    text-wrap: balance;
}

.event-date, .group-count { color: var(--muted); margin-top: 2px; }

.status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: .85rem;
    color: var(--muted);
}

.status--offline { color: var(--warn-ink); background: var(--warn-bg); padding: 6px 10px; border-radius: 8px; }

.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--live);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 25%, transparent);
    flex: none;
}

.dot--off { background: var(--warn-ink); box-shadow: none; }

.empty { padding: 48px 0; text-align: center; }
.empty-title { font-size: 1.3rem; font-weight: 700; }

/* ── search ─────────────────────────────────────────────────────────────── */

.search { margin-top: 18px; }

.search-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.search-input:focus-visible, .tab:focus-visible, .row-main:focus-visible, .cat:focus-visible, .lang:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.search-out { margin-top: 8px; display: grid; gap: 6px; }

.hit {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0 12px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    text-decoration: none;
}

.hit-name { font-weight: 600; }
.hit-meta { grid-column: 1; color: var(--muted); font-size: .85rem; }
.hit-time { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.search-none { padding: 10px 4px; color: var(--muted); }

/* ── categories ─────────────────────────────────────────────────────────── */

.cats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.cat {
    display: grid;
    gap: 2px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    text-decoration: none;
}

.cat-name { font-size: 1.35rem; font-weight: 800; letter-spacing: .01em; }
.cat-count { font-size: .8rem; color: var(--muted); }

.cat-bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: 6px; }
.cat-fill { display: block; height: 100%; background: var(--accent); }

.events { display: grid; gap: 6px; }

.event-link {
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    text-decoration: none;
}

/* ── category page ──────────────────────────────────────────────────────── */

.back { display: inline-block; margin-bottom: 10px; color: var(--muted); text-decoration: none; font-size: .9rem; }

.tabs {
    display: flex;
    gap: 4px;
    margin: 16px 0 12px;
    padding: 4px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.tab {
    flex: 1;
    padding: 8px 10px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    cursor: pointer;
}

.tab--on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* results list */

.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.row {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}

.row--hl { border-color: var(--accent); background: var(--hl); }

.row-main {
    display: grid;
    grid-template-columns: 2.2rem 1fr auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.place { font-size: 1.15rem; font-weight: 800; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.place.r1, .place.r2, .place.r3 { font-weight: 800; }

.who { display: grid; min-width: 0; }
.nm { font-weight: 600; overflow-wrap: anywhere; }
.sub { font-size: .8rem; color: var(--muted); }

.tm { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-variant-numeric: tabular-nums; }
.tm .t { font-weight: 700; font-size: 1.05rem; }
.tm .gap { font-size: .8rem; color: var(--muted); }

.badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 6px;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .04em;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--line);
}

.badge--mp, .badge--dsq, .badge--mpl, .badge--ot { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.badge--ooc { background: transparent; }

.r1 { color: var(--r1); font-weight: 700; }
.r2 { color: var(--r2); font-weight: 700; }
.r3 { color: var(--r3); font-weight: 700; }
.rk { font-weight: 400; font-size: .85em; opacity: .85; }

/* a runner's splits, opened under the row */

.detail { padding: 0 12px 12px; border-top: 1px dashed var(--line); }

.legs { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.legs th { text-align: left; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 4px 0; }
.legs td { padding: 5px 0; border-top: 1px solid var(--line); }
.legs .c-ctl { font-weight: 600; }
.legs .code, .grid .code { color: var(--muted); font-weight: 400; }
.legs .mp, .grid .mp { color: var(--warn-ink); font-weight: 800; }
.legs tr.is-recovered .v { font-style: italic; color: var(--muted); }

/* splits grid */

.grid-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    -webkit-overflow-scrolling: touch;
}

.grid { border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; white-space: nowrap; }

.grid th, .grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: center; }

.grid thead th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    font-size: .75rem;
    font-weight: 700;
    color: var(--muted);
}

.grid .c-name {
    position: sticky;
    left: 0;
    z-index: 1;
    width: 9.5rem;
    max-width: 9.5rem;
    overflow: hidden;
    text-align: left;
    font-size: .9rem;
    background: var(--surface);
    border-right: 1px solid var(--line);
    font-weight: 600;
}

.grid thead .c-name { background: var(--surface-2); z-index: 2; }
.grid .has-badge .gname { max-width: 4.2rem; }
.grid .gplace { display: inline-block; min-width: 1.2rem; color: var(--muted); font-weight: 800; }
.grid .gname { display: inline-block; max-width: 6.4rem; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; margin-right: 4px; }
.grid .cell { line-height: 1.2; }
.grid .leg { display: block; font-weight: 600; }
.grid .cum { display: block; font-size: .78rem; color: var(--muted); }
.grid .cum.r1, .grid .cum.r2, .grid .cum.r3 { font-weight: 600; }
.grid .is-recovered .leg, .grid .is-recovered .cum { font-style: italic; color: var(--muted); font-weight: 400; }
.grid .c-time { font-weight: 700; }
.grid tr.row--hl .c-name, .grid tr.row--hl td { background: var(--hl); }

.legend { margin-top: 18px; font-size: .8rem; color: var(--muted); }
.legend p { margin: 0 0 6px; }

@media (min-width: 640px) {
    .event-name, .group-name { font-size: 2rem; }
    .main { padding-top: 24px; }
}

@media (prefers-reduced-motion: no-preference) {
    .cat, .row { transition: border-color .15s; }
    .cat:hover, .event-link:hover, .hit:hover { border-color: var(--accent); }
}
