/* Baantimer — readable at arm's length beside the track: high contrast, huge
   tabular digits, big targets. Dark by default (indoor velodromes, battery);
   a light theme for bright sun. One accent: signal yellow for the tap button. */

:root {
    --bg: #0b0d10;
    --panel: #161a1f;
    --line: #2a3038;
    --text: #f5f7fa;
    --muted: #9aa4b1;
    --accent: #ffd60a;
    --accent-ink: #0b0d10;
    --faster: #3ddc84;
    --slower: #ff6b6b;
    --danger: #ff6b6b;
    --radius: 14px;
    --nav-h: 64px;
    color-scheme: dark;
}

:root[data-theme='light'] {
    --bg: #ffffff;
    --panel: #f1f3f5;
    --line: #d5dae0;
    --text: #0b0d10;
    --muted: #4f5966;
    --accent: #ffd60a;
    --accent-ink: #0b0d10;
    --faster: #0a8a43;
    --slower: #c62828;
    --danger: #c62828;
    color-scheme: light;
}

@media (prefers-color-scheme: light) {
    :root[data-theme='auto'] {
        --bg: #ffffff;
        --panel: #f1f3f5;
        --line: #d5dae0;
        --text: #0b0d10;
        --muted: #4f5966;
        --faster: #0a8a43;
        --slower: #c62828;
        --danger: #c62828;
        color-scheme: light;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
    font: 17px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-variant-numeric: tabular-nums;
    -webkit-tap-highlight-color: transparent;
    min-height: 100dvh;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: inherit; }
h1, h2 { margin: 0; }

.app {
    max-width: 760px;
    margin: 0 auto;
    padding: max(14px, env(safe-area-inset-top)) 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- headers and blocks ---------- */
.top { padding: 8px 0 18px; }
.top h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; }
.top.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); text-decoration: none; padding: 6px 0; }
.block { margin: 0 0 22px; }
.block h2, h2.section { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin-bottom: 10px; }
h2.section { margin-top: 26px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hint { color: var(--muted); margin: 0 0 16px; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.sub { margin-top: 10px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px 4px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
    min-height: 48px; padding: 0 18px; border-radius: 999px;
    border: 2px solid var(--line); background: var(--panel);
    font-weight: 600; white-space: nowrap;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- fields ---------- */
.field { display: block; margin-top: 10px; }
.field > span { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea {
    width: 100%; min-height: 52px; padding: 10px 14px; border-radius: 10px;
    border: 2px solid var(--line); background: var(--panel); font-size: 1.15rem;
}
.field textarea { font-size: 1rem; resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field.small { width: 110px; margin-top: 0; }
.gear-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.gear-name { width: 100%; font-weight: 700; }
.times { font-size: 1.4rem; padding-bottom: 12px; color: var(--muted); }
.dev { padding-bottom: 14px; }
.switch { display: flex; gap: 12px; align-items: center; min-height: 48px; }
.switch input { width: 28px; height: 28px; accent-color: var(--accent); }

/* ---------- buttons ---------- */
.actions { margin: 26px 0 0; }
.actions.split { display: flex; gap: 10px; flex-wrap: wrap; }
.actions.sticky { position: sticky; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); }
.big {
    width: 100%; min-height: 76px; border: 0; border-radius: var(--radius);
    font-size: 1.45rem; font-weight: 800; letter-spacing: 0.01em;
}
.go { background: var(--accent); color: var(--accent-ink); }
.go:disabled { opacity: 0.35; }
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 52px; padding: 0 20px; border-radius: 12px;
    border: 2px solid var(--line); background: var(--panel); font-weight: 700; cursor: pointer;
}
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.danger { color: var(--danger); }
.link { background: none; border: 0; color: var(--text); font-weight: 700; text-decoration: underline; padding: 10px 0; min-height: 44px; }

/* ---------- running: one rider ---------- */
.run-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0 10px; }
.run-title { display: flex; flex-direction: column; min-width: 0; }
.run-title strong { font-size: 1.05rem; line-height: 1.2; }
.run-title span { color: var(--muted); font-size: 0.9rem; }
.run-tools { display: flex; gap: 8px; flex-shrink: 0; }
.tool { min-height: 48px; min-width: 48px; padding: 0 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.tool svg { width: 24px; height: 24px; }
.tool:disabled { opacity: 0.3; }
.tool.stop { color: var(--danger); }

.solo { text-align: center; padding: 6px 0 14px; }
.solo-label { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.85rem; }
.solo-time {
    font-size: min(27vw, 19vh, 190px); font-weight: 800; line-height: 1; letter-spacing: -0.04em;
    margin: 4px 0 6px;
}
.solo-meta { display: flex; justify-content: center; gap: 22px; font-size: 1.5rem; font-weight: 700; flex-wrap: wrap; }
.solo-meta small, .solo-total small { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.solo-total { margin-top: 8px; font-size: 1.2rem; font-weight: 700; }
.delta.faster { color: var(--faster); }
.delta.slower { color: var(--slower); }

.tap {
    display: block; width: 100%;
    height: max(34vh, 220px);
    border: 0; border-radius: 22px;
    background: var(--accent); color: var(--accent-ink);
    font-size: clamp(2.4rem, 11vw, 4.2rem); font-weight: 900; letter-spacing: -0.01em;
    touch-action: none; user-select: none; -webkit-user-select: none;
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
}
.tap:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); }
.tap.done { background: var(--panel); color: var(--muted); box-shadow: none; }

.laps { list-style: none; margin: 18px 0 0; padding: 0; }
.laps li { display: grid; grid-template-columns: 2.2em 1fr 1fr 1fr; gap: 8px; padding: 10px 4px; border-bottom: 1px solid var(--line); font-size: 1.1rem; }
.laps li.best .t { color: var(--faster); }
.laps .n { color: var(--muted); }
.laps .t { font-weight: 800; }
.laps .v, .laps .c { color: var(--muted); text-align: right; }

/* ---------- running: several riders ---------- */
.startall { margin-bottom: 12px; min-height: 64px; }
.grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
.grid.n3, .grid.n4 { grid-template-columns: 1fr 1fr; }
.card {
    display: flex; flex-direction: column; justify-content: space-between; gap: 4px;
    min-height: max(26vh, 170px); padding: 14px; border-radius: 18px;
    border: 3px solid var(--accent); background: var(--panel); text-align: left;
    touch-action: none; user-select: none; -webkit-user-select: none;
}
.grid.n1 .card, .grid.n2 .card { min-height: max(34vh, 200px); }
.card:active { background: var(--accent); color: var(--accent-ink); }
.card.waiting { border-style: dashed; }
.card.done { border-color: var(--line); opacity: 0.75; }
.card-head { display: flex; justify-content: space-between; gap: 8px; font-size: 1.1rem; }
.card-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-time { font-size: clamp(2.6rem, 13vw, 5rem); font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.grid.n3 .card-time, .grid.n4 .card-time { font-size: clamp(2rem, 9.5vw, 3.6rem); }
.card-meta { display: flex; gap: 12px; font-weight: 700; flex-wrap: wrap; }
.card-next { font-weight: 900; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); }
:root[data-theme='light'] .card-next { color: var(--text); }
@media (prefers-color-scheme: light) { :root[data-theme='auto'] .card-next { color: var(--text); } }
.card:active .card-next { color: var(--accent-ink); }

/* ---------- results ---------- */
.result { background: var(--panel); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.result-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; font-size: 1.1rem; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpis div { display: flex; flex-direction: column; }
.kpis small { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.kpis strong { font-size: 1.7rem; font-weight: 800; line-height: 1.15; }

.table { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 1rem; }
.table th { text-align: right; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; padding: 6px 4px; border-bottom: 2px solid var(--line); }
.table td { text-align: right; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.table th:first-child, .table td:first-child { text-align: left; color: var(--muted); }
.table tr.best b { color: var(--faster); }
.table tfoot td { font-weight: 800; border-bottom: 0; }

.list { list-style: none; margin: 0; padding: 0; }
.item {
    width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 14px 4px; border: 0; border-bottom: 1px solid var(--line); background: none;
    text-align: left; text-decoration: none; min-height: 68px;
}
.item.on { background: var(--panel); outline: 3px solid var(--accent); outline-offset: -3px; border-radius: 10px; padding: 14px 12px; }
.item-main { display: flex; flex-direction: column; min-width: 0; }
.item-main .muted { font-size: 0.88rem; }
.item-figure { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; }
.item-figure b { font-size: 1.45rem; font-weight: 800; }
.item-figure small { color: var(--muted); font-size: 0.78rem; }

.cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cmp > div { background: var(--panel); border-radius: 12px; padding: 12px; display: flex; gap: 10px; }
.cmp-head { display: flex; flex-direction: column; min-width: 0; font-size: 0.92rem; }
.tag { flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--text); color: var(--bg); font-weight: 900; display: inline-flex; align-items: center; justify-content: center; }
.cmp-table td { font-size: 1.1rem; }

.add { margin-top: 26px; padding: 16px; background: var(--panel); border-radius: var(--radius); }
.add .field input { background: var(--bg); }
.add .btn { margin-top: 6px; }

/* ---------- bottom navigation ---------- */
.nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    display: flex; justify-content: center;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg); border-top: 1px solid var(--line);
}
.nav[hidden] { display: none; }
.tab {
    flex: 1; max-width: 190px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    text-decoration: none; color: var(--muted); font-size: 0.74rem; font-weight: 700;
}
.tab svg { width: 26px; height: 26px; }
.tab.on { color: var(--text); }

@media (min-width: 700px) {
    .tap { height: 300px; }
}
