/* Baantimer — design "Velodroom" (Claude Design canvas "Baantimer redesign").
   Night ground, the track's three lines as the motif (blue stayers' line,
   red sprinters' line, white measurement line), a maple-yellow tap button
   like the boards, digits in Barlow Condensed (as on Paracycling Results).
   Readable at arm's length: huge tabular digits, 44 px+ targets.
   Faster = blue, slower = orange (told apart by sign and lightness too). */

@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-display: swap; src: url(../fonts/barlow-condensed-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 700; font-display: swap; src: url(../fonts/barlow-condensed-latin-700-normal.woff2) format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 800; font-display: swap; src: url(../fonts/barlow-condensed-latin-800-normal.woff2) format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 100 900; font-display: swap; src: url(../fonts/inter-latin-wght-normal.woff2) format('woff2'); }

:root {
    --ground: #0B0E13;
    --surface: #161B23;
    --surface-2: #1E2530;
    --line: #232B36;
    --text: #F5F3EE;
    --muted: #A3ADBA;
    --maple: #F4B63F;
    --maple-deep: #B9851F;
    --maple-ink: #14110B;
    --blue: #4DA3FF;
    --red: #FF5A4E;
    --orange: #FF8A45;
    --faster: var(--blue);
    --slower: var(--orange);
    --danger: var(--red);
    --tile-on: #1E1A10;
    --display: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
    --body: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --nav-h: 68px;
    color-scheme: dark;
}

/* Bright sun: white ground, same accents, darker shades so text keeps 4.5:1. */
:root[data-theme='light'] {
    --ground: #FFFFFF;
    --surface: #F1F3F6;
    --surface-2: #E6E9EE;
    --line: #D5DAE1;
    --text: #0B0E13;
    --muted: #4F5966;
    --blue: #1660C4;
    --red: #C62D22;
    --orange: #B4520F;
    --tile-on: #FFF4DC;
    color-scheme: light;
}
@media (prefers-color-scheme: light) {
    :root[data-theme='auto'] {
        --ground: #FFFFFF;
        --surface: #F1F3F6;
        --surface-2: #E6E9EE;
        --line: #D5DAE1;
        --text: #0B0E13;
        --muted: #4F5966;
        --blue: #1660C4;
        --red: #C62D22;
        --orange: #B4520F;
        --tile-on: #FFF4DC;
        color-scheme: light;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--text); }
body {
    font: 16px/1.45 var(--body);
    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: var(--maple); }
:root[data-theme='light'] a { color: #8A5A00; }
@media (prefers-color-scheme: light) { :root[data-theme='auto'] a { color: #8A5A00; } }
h1, h2, p { margin: 0; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.app {
    max-width: 640px;
    margin: 0 auto;
    padding: max(16px, env(safe-area-inset-top)) 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
    display: flex; flex-direction: column; gap: 18px;
}
body.running .app { padding-bottom: max(16px, env(safe-area-inset-bottom)); gap: 14px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- type ---------- */
.eyebrow { font-family: var(--body); font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.eyebrow.blue { color: var(--blue); }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.5; }
.center { text-align: center; }
.hint { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }
.num, .delta { font-family: var(--display); font-weight: 700; }
.delta.faster { color: var(--faster); }
.delta.slower { color: var(--slower); }

/* ---------- header ---------- */
.brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand-name { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 800; font-size: 28px; letter-spacing: 0.01em; text-transform: uppercase; }
.logo { width: 30px; height: 30px; }
.pill {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 999px;
    background: var(--surface); color: var(--text) !important; text-decoration: none; font-weight: 600; font-size: 14px;
}
.pill b { font-family: var(--display); font-size: 18px; color: var(--maple); }
:root[data-theme='light'] .pill b { color: #8A5A00; }
.lines { display: flex; flex-direction: column; gap: 4px; margin-top: -6px; }
.lines span { display: block; height: 3px; border-radius: 3px; background: var(--blue); }
.lines span:nth-child(2) { background: var(--red); width: 82%; }
.lines span:nth-child(3) { background: var(--text); width: 64%; opacity: 0.85; }

.top { display: flex; flex-direction: column; gap: 4px; padding-top: 4px; }
.top h1 { font-family: var(--display); font-weight: 800; font-size: 34px; line-height: 1.05; text-transform: uppercase; }
.top.row { flex-direction: row; align-items: center; justify-content: space-between; }
.back { color: var(--muted) !important; text-decoration: none; padding: 6px 0; align-self: flex-start; }

.block { display: flex; flex-direction: column; gap: 10px; }

/* ---------- segmented controls, tiles, chips ---------- */
.seg { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface); }
.seg button { min-height: 46px; border: 0; border-radius: 10px; background: transparent; color: var(--text); font-weight: 600; font-size: 15px; padding: 0 6px; }
.seg button.num { font-family: var(--display); font-weight: 700; font-size: 19px; }
.seg button.on { background: var(--text); color: var(--ground); }
.seg.sub { margin-top: 2px; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile {
    min-height: 62px; padding: 10px 14px; border: 2px solid var(--line); border-radius: 14px;
    background: var(--surface); text-align: left; display: flex; flex-direction: column; gap: 2px;
}
.tile b { font-size: 15px; }
.tile span { font-size: 12px; color: var(--muted); }
.tile.wide { grid-column: span 2; }
.tile.on { border-color: var(--maple); background: var(--tile-on); }
.tile.on span { color: var(--maple); }
:root[data-theme='light'] .tile.on span { color: #8A5A00; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { min-height: 46px; padding: 0 16px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface); font-weight: 600; white-space: nowrap; }
.chip small { font-family: var(--display); font-size: 15px; color: var(--muted); }
.chip.on { background: var(--text); color: var(--ground); border-color: var(--text); }
.chip.on small { color: inherit; opacity: 0.7; }

.classes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.cls { min-height: 56px; border: 2px solid var(--line); border-radius: 14px; background: var(--surface); font-family: var(--display); font-weight: 800; font-size: 24px; }
.cls.on { background: var(--maple); border-color: var(--maple); color: var(--maple-ink); }

/* ---------- target / link cards ---------- */
.target {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 14px; border-radius: 14px; background: var(--surface);
    color: var(--text) !important; text-decoration: none;
}
.target span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.target small { font-size: 13px; color: var(--muted); }
.target > b { font-family: var(--display); font-weight: 800; font-size: 30px; color: var(--maple); white-space: nowrap; }
:root[data-theme='light'] .target > b { color: #8A5A00; }
.target.soft small { color: var(--text); }
.target .arrow { font-size: 22px; }
.target.pcr b { font-size: 15px; }
.target.pcr i { font-style: normal; color: var(--maple); font-size: 20px; }

/* ---------- fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.field input, .field textarea {
    width: 100%; min-height: 52px; padding: 10px 14px; border-radius: 14px;
    border: 2px solid var(--line); background: var(--surface); font-size: 17px;
}
.field textarea { resize: vertical; font-size: 15px; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--maple); }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.gear { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.gear-name { width: 100%; font-weight: 700; margin-top: 4px; }
.gear-part { display: flex; align-items: center; gap: 2px; background: var(--surface); border-radius: 14px; padding: 3px; }
.gear-part input {
    width: 52px; min-height: 44px; border: 0; background: transparent; text-align: center;
    font-family: var(--display); font-weight: 800; font-size: 28px; -moz-appearance: textfield;
}
.gear-part input::-webkit-outer-spin-button, .gear-part input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.step { width: 44px; height: 44px; border: 0; border-radius: 11px; background: var(--surface-2); font-size: 22px; line-height: 1; }
.times { color: var(--muted); }
.dev { font-size: 13px; color: var(--muted); margin-left: 4px; }

.switch { display: flex; gap: 12px; align-items: center; min-height: 48px; }
.switch input { width: 28px; height: 28px; accent-color: var(--maple); }

/* ---------- buttons ---------- */
.cta {
    width: 100%; min-height: 72px; border: 0; border-radius: 18px;
    background: var(--maple); color: var(--maple-ink);
    font-family: var(--display); font-weight: 800; font-size: 30px; letter-spacing: 0.02em; text-transform: uppercase;
}
.cta:disabled { opacity: 0.35; }
.cta.startall { min-height: 64px; font-size: 26px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 52px; padding: 0 20px; border-radius: 14px;
    border: 2px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; color: var(--text);
}
.btn.primary { background: var(--maple); color: var(--maple-ink); border-color: var(--maple); }
.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; align-self: flex-start; }
.link-sm { font-weight: 600; text-decoration: none; }
.sticky { position: sticky; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); }

/* ---------- running: one rider ---------- */
.run-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.run-title { display: flex; flex-direction: column; min-width: 0; }
.run-title strong { font-family: var(--display); font-weight: 800; font-size: 24px; line-height: 1.1; text-transform: uppercase; letter-spacing: 0.02em; }
.run-title span { color: var(--muted); font-size: 13px; }
.run-tools { display: flex; gap: 8px; flex-shrink: 0; }
.tool { min-height: 48px; min-width: 48px; padding: 0 16px; border-radius: 14px; border: 0; background: var(--surface); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.tool svg { width: 22px; height: 22px; }
.tool:disabled { opacity: 0.3; }
.tool.stop { color: var(--red); }

.progress { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 6px; }
.progress span { height: 6px; border-radius: 6px; background: var(--surface-2); }
.progress span.on { background: var(--maple); }

.solo { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.solo-time { font-family: var(--display); font-weight: 800; font-size: min(38vw, 22vh, 170px); line-height: 0.92; letter-spacing: -0.01em; }
.solo-meta { display: flex; gap: 18px; align-items: baseline; font-family: var(--display); font-weight: 700; font-size: 28px; flex-wrap: wrap; justify-content: center; }
.solo-meta small, .solo-total small { font-family: var(--body); font-size: 12px; color: var(--muted); font-weight: 600; }
.solo-total { margin-top: 6px; display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--muted); flex-wrap: wrap; justify-content: center; }
.solo-total b { font-family: var(--display); font-size: 22px; color: var(--text); }
.solo-total b.delta.faster { color: var(--faster); }
.solo-total b.delta.slower { color: var(--slower); }
.solo-total i { width: 4px; height: 4px; border-radius: 4px; background: var(--muted); opacity: 0.5; }

.tap {
    width: 100%; min-height: max(30vh, 220px); border: 0; border-radius: 28px;
    background: var(--maple); color: var(--maple-ink);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    box-shadow: 0 6px 0 var(--maple-deep);
    touch-action: none; user-select: none; -webkit-user-select: none;
}
.tap span { font-family: var(--display); font-weight: 800; font-size: clamp(48px, 16vw, 72px); line-height: 1; text-transform: uppercase; letter-spacing: 0.02em; }
.tap small { font-size: 15px; font-weight: 600; opacity: 0.75; }
.tap:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--maple-deep); }
.tap.done { background: var(--surface); color: var(--muted); box-shadow: none; }

.laps { list-style: none; margin: 0; padding: 0; }
.laps li { display: grid; grid-template-columns: 28px 1fr 1fr 1fr; gap: 8px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-family: var(--display); font-size: 21px; font-weight: 700; }
.laps .n, .laps .v, .laps .c { color: var(--muted); }
.laps .v, .laps .c { text-align: right; }
.laps li.best .t { color: var(--faster); }

/* ---------- running: several riders ---------- */
.grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
.grid.n4 { grid-template-columns: 1fr 1fr; }
.card {
    display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
    min-height: max(22vh, 150px); padding: 14px 16px; border-radius: 22px;
    border: 2px solid var(--lane); background: var(--surface); text-align: left;
    touch-action: none; user-select: none; -webkit-user-select: none;
}
.grid.n2 .card { min-height: max(32vh, 200px); }
.card-head { display: flex; justify-content: space-between; gap: 8px; font-size: 16px; }
.card-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-head span { font-family: var(--display); font-weight: 700; font-size: 22px; color: var(--muted); }
.card-body { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.card-time { font-family: var(--display); font-weight: 800; font-size: clamp(52px, 18vw, 80px); line-height: 0.9; }
.grid.n4 .card-time { font-size: clamp(36px, 10vw, 56px); }
.card-side { display: flex; flex-direction: column; align-items: flex-end; }
.card-side .delta { font-size: 22px; }
.card-next { font-family: var(--display); font-weight: 800; font-size: 24px; text-transform: uppercase; color: var(--lane); }
.card.waiting { border-style: dashed; }
.card.lit, .card:active { background: var(--maple); border-color: var(--maple); color: var(--maple-ink); }
.card.lit .card-head span, .card.lit .card-next, .card.lit .delta,
.card:active .card-head span, .card:active .card-next, .card:active .delta { color: var(--maple-ink); }
.card.done { opacity: 0.6; }
:root[data-theme='light'] .card-next { color: var(--text); }

/* ---------- results ---------- */
.card-flat { padding: 18px; border-radius: 20px; background: var(--surface); display: flex; flex-direction: column; gap: 12px; }
.result-who { display: flex; justify-content: space-between; gap: 8px; font-size: 16px; }
.result-main { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.big-time { font-family: var(--display); font-weight: 800; font-size: clamp(48px, 17vw, 72px); line-height: 0.9; display: flex; flex-direction: column; min-width: 0; }
.big-time small { font-family: var(--body); font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.result-avg { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; color: var(--muted); flex-shrink: 0; text-align: right; }
.result-avg b { font-family: var(--display); font-size: 26px; color: var(--text); }
.lap-chips { display: grid; grid-template-columns: repeat(min(var(--n), 4), minmax(0, 1fr)); gap: 6px; }
.lap-chips div { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 12px; background: var(--ground); }
.lap-chips small { font-size: 11px; color: var(--muted); }
.lap-chips b { font-family: var(--display); font-size: 22px; }
.lap-chips .best b { color: var(--faster); }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.row-between.baseline { align-items: baseline; }
.holder { display: flex; flex-direction: column; color: var(--text) !important; text-decoration: none; }
.holder b { font-size: 16px; }
.holder span { font-size: 13px; color: var(--muted); }
.wr-time { font-family: var(--display); font-weight: 800; font-size: 34px; }
.bar { position: relative; height: 10px; border-radius: 10px; background: var(--ground); overflow: hidden; }
.bar span { position: absolute; inset: 0 auto 0 0; border-radius: 10px; background: linear-gradient(90deg, var(--blue), var(--maple)); }
.row-between .delta { font-size: 20px; }
.row-between .num { font-size: 20px; color: var(--text); }

.champs { list-style: none; margin: 0; padding: 0; }
.champs li + li { border-top: 1px solid var(--line); }
.champs a { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; min-height: 56px; color: var(--text) !important; text-decoration: none; }
.champs a > span:first-child { display: flex; flex-direction: column; }
.champs b { font-size: 15px; }
.champs small { font-size: 12px; color: var(--muted); }
.place { font-family: var(--display); font-weight: 800; font-size: 28px; white-space: nowrap; }
.place small { font-family: var(--body); font-size: 12px; font-weight: 600; }
.place i { font-style: normal; font-family: var(--body); font-size: 14px; color: var(--maple); }
.place.podium { color: var(--maple); }
:root[data-theme='light'] .place.podium, :root[data-theme='light'] .place i { color: #8A5A00; }

.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th { text-align: right; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; padding: 6px 4px; border-bottom: 2px solid var(--line); }
.table td { text-align: right; padding: 8px 4px; border-bottom: 1px solid var(--line); font-family: var(--display); font-size: 19px; font-weight: 600; }
.table td b { font-weight: 800; }
.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; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
    width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 14px 16px; border: 2px solid transparent; border-radius: 16px; background: var(--surface);
    text-align: left; text-decoration: none; color: var(--text) !important; min-height: 68px;
}
.item[aria-pressed='true'] { border-color: var(--maple); background: var(--tile-on); }
.item-main { display: flex; flex-direction: column; min-width: 0; }
.item-main .muted { font-size: 13px; }
.item-figure { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; }
.item-figure b { font-family: var(--display); font-size: 28px; font-weight: 800; line-height: 1.05; }
.item-figure small { color: var(--muted); font-size: 12px; }

.cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cmp-card { background: var(--surface); border-radius: 14px; padding: 12px; display: flex; gap: 10px; }
.cmp-card > div { display: flex; flex-direction: column; min-width: 0; font-size: 13px; }
.cmp-card b { font-size: 14px; }
.tag { flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--maple); color: var(--maple-ink); font-family: var(--display); font-weight: 800; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; }

.add { margin-top: 6px; }
.add .field input { background: var(--ground); }

/* ---------- 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(--ground); border-top: 1px solid var(--surface-2);
}
.nav[hidden] { display: none; }
.tab { flex: 1; max-width: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--muted) !important; font-size: 12px; font-weight: 600; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--text) !important; }

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

/* ---------- v3: fixed track, event groups, event spec ---------- */
.track-row {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 14px; border-radius: 14px; background: var(--surface);
}
.track-row > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.track-row b { font-family: var(--display); font-weight: 800; font-size: 30px; line-height: 1; }
.track-row small { font-size: 13px; color: var(--muted); }
.track-row.custom { outline: 2px solid var(--orange); outline-offset: -2px; }
.track-row.custom small { color: var(--orange); }
.track-row .tool { background: var(--surface-2); }
.track-edit { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.track-edit .field { flex: 1 1 180px; }

.group { display: flex; flex-direction: column; gap: 8px; }
.group + .group { margin-top: 8px; }
.group-head { display: flex; flex-direction: column; }
.group-head b { font-size: 15px; }
.group-head span { font-size: 13px; color: var(--muted); }

.spec {
    display: flex; flex-direction: column; gap: 2px;
    padding: 12px 14px; border-radius: 14px; border: 2px solid var(--maple); background: var(--tile-on);
}
.spec b { font-family: var(--display); font-weight: 800; font-size: 24px; text-transform: uppercase; letter-spacing: 0.01em; }
.spec span { font-size: 14px; color: var(--muted); }
