/* PaceBand
   Mobile first: one column, large touch targets, actions pinned to the bottom of the screen.
   From 54rem up: settings panel on the left, a timing sheet on the right. The sheet switches to
   stacked cards when its own column is too narrow (app.js toggles .stacked), not just
   when the viewport is.
   Look: condensed race-signage numerals, bib-orange accent, cool slate neutrals. */

@font-face { font-family: "Barlow"; font-weight: 400; font-style: normal; font-display: swap; src: url("fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-style: normal; font-display: swap; src: url("fonts/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-style: normal; font-display: swap; src: url("fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 500; font-style: normal; font-display: swap; src: url("fonts/barlow-condensed-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 600; font-style: normal; font-display: swap; src: url("fonts/barlow-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 700; font-style: normal; font-display: swap; src: url("fonts/barlow-condensed-latin-700-normal.woff2") format("woff2"); }

:root {
  color-scheme: light;
  --bg: #e9edf0;
  --surface: #ffffff;
  --field: #f4f6f7;
  --ink: #0d1b24;
  --muted: #566772;
  --line: #d2dadf;
  --accent: #d4460a;
  --accent-ink: #ffffff;
  --accent-soft: #fbe9df;
  --bad: #b42318;
  --font-display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --font-body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1318;
    --surface: #131d24;
    --field: #0e171d;
    --ink: #e8eef1;
    --muted: #8fa1ac;
    --line: #25343d;
    --accent: #ff7a3d;
    --accent-ink: #1a0a02;
    --accent-soft: #2d1b11;
    --bad: #ff8a7a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1318;
  --surface: #131d24;
  --field: #0e171d;
  --ink: #e8eef1;
  --muted: #8fa1ac;
  --line: #25343d;
  --accent: #ff7a3d;
  --accent-ink: #1a0a02;
  --accent-soft: #2d1b11;
  --bad: #ff8a7a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.45;
  padding-inline: max(0.75rem, env(safe-area-inset-left), env(safe-area-inset-right));
  padding-block: max(1rem, env(safe-area-inset-top)) 0;
}
.wrap { max-width: 72rem; margin-inline: auto; }
.top { margin-bottom: 0.875rem; }
h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.625rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0;
  text-wrap: balance;
}
.top p { margin: 0.125rem 0 0; color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}
.field { display: flex; flex-direction: column; gap: 0.375rem; min-width: 0; }
.lbl, label.lbl {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.hint { font-size: 0.8125rem; color: var(--muted); margin: 0; }
.err { font-size: 0.8125rem; color: var(--bad); margin: 0; }
.err:empty { display: none; }

input[type="text"], input[type="time"], textarea {
  width: 100%;
  min-width: 0;
  font: 500 1rem var(--font-body);
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  min-height: 2.75rem;
  font-variant-numeric: tabular-nums;
}
/* iOS Safari gives date and time inputs an intrinsic width and its own chrome; reset both so the field fits its container. */
input[type="time"] { -webkit-appearance: none; appearance: none; display: block; max-width: 100%; height: 2.75rem; text-align: left; }
input[type="time"]::-webkit-date-and-time-value { text-align: left; min-width: 0; margin: 0; }
input.big { font: 600 1.75rem var(--font-display); letter-spacing: 0.02em; min-height: 3.25rem; }
input.bad { border-color: var(--bad); }
.with-unit { display: flex; align-items: center; gap: 0.5rem; }
.u { color: var(--muted); font-size: 0.875rem; white-space: nowrap; }

button { font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:active { filter: brightness(0.94); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; gap: 0.5rem; overflow-x: auto; scrollbar-width: none; margin-inline: -1rem; padding-inline: 1rem; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0.875rem;
  min-height: 2.5rem;
  flex: none;
  white-space: nowrap;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.dist-row { display: flex; gap: 0.75rem; align-items: center; }
.dist-row .with-unit { flex: 1; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex: none; }
.seg button { border: 0; background: var(--field); color: var(--ink); padding: 0.5rem 1rem; min-height: 2.75rem; font-weight: 600; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

.btn {
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  border-radius: 6px;
  padding: 0.5rem 0.875rem;
  min-height: 2.75rem;
  font-weight: 500;
  align-self: flex-start;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.row-inline { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row-inline .with-unit { flex: 1 1 8rem; }
#pace2-wrap { margin-top: 0.5rem; }
.adv summary { cursor: pointer; padding-block: 0.5rem; min-height: 2.75rem; display: flex; align-items: center; }
.adv[open] summary { padding-bottom: 0.25rem; min-height: 0; }
.adv[open] > :not(summary) { margin-top: 0.5rem; }

/* Results */
.results { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

.hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2.5rem;
  align-items: flex-end;
  justify-content: space-between;
}
.hb { display: contents; }
.hero-main { min-width: 0; }
.hero-time {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(3.25rem, 11vw, 5rem);
  line-height: 0.95;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.stats { display: flex; flex-wrap: wrap; gap: 0.75rem 1.75rem; }
.stat { display: flex; flex-direction: column; gap: 0.0625rem; }
.stat b { font-family: var(--font-display); font-weight: 600; font-size: 1.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
small { font-size: 0.65em; font-weight: 600; color: var(--muted); }

/* Two paces: two blocks side by side, slow one in the ink colour */
.hero.range {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.5rem;
  align-items: start;
  justify-content: stretch;
}
.hero.range .hb { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.hero.range .hero-time { font-size: clamp(2.25rem, 7vw, 3.75rem); }
.hero.range .hb.slow .hero-time { color: var(--ink); }
.hero.range .stats { gap: 0.5rem 1.25rem; }
.hero.range .stat b { font-size: 1.25rem; }

.live-bar { display: flex; align-items: center; gap: 0.75rem; min-height: 2.75rem; }
.live-bar .btn { align-self: auto; }
.live-btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.live-btn[aria-pressed="true"]::before { content: ""; display: inline-block; width: 0.5rem; height: 0.5rem; margin-right: 0.5rem; border-radius: 50%; background: var(--accent); }

.live-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.875rem 1rem; display: grid; gap: 0.75rem; font-variant-numeric: tabular-nums; }
.lv-elapsed { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.lv-elapsed b { font-family: var(--font-display); font-weight: 700; font-size: 2.25rem; line-height: 1; }
.lv-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: 0.75rem; }
.lv-col { display: flex; flex-direction: column; gap: 0.125rem; min-width: 0; padding-left: 0.75rem; border-left: 4px solid var(--accent); }
.lv-col.slow { border-left-color: var(--ink); }
.lv-pos { font-family: var(--font-display); font-weight: 600; font-size: 1.75rem; line-height: 1.1; }
.lv-next { font-size: 0.875rem; color: var(--muted); }
.lv-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.lv-actions .btn { align-self: auto; flex: 1 1 6rem; }
.lv-actions .primary { flex: 2 1 12rem; }
.c-dist { flex-wrap: wrap; }
.drift { display: block; flex-basis: 100%; font: 500 0.8125rem var(--font-body); color: var(--muted); }
.drift:empty { display: none; }
.lv-next b { color: var(--ink); font-weight: 600; }
.strip-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.75rem 1.5rem 0.25rem; }
.strip { position: relative; height: 2.75rem; }
.rail { position: absolute; left: 0; right: 0; top: 0.5rem; height: 4px; border-radius: 2px; background: var(--line); }
.tick { position: absolute; top: 0.125rem; width: 2px; height: 16px; margin-left: -1px; background: var(--ink); border-radius: 1px; }
.tick.done { background: var(--muted); }
.cursor { position: absolute; top: 0.5rem; width: 1rem; height: 1rem; margin: -0.375rem 0 0 -0.5rem; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 0 0 2px var(--accent); z-index: 1; }
.cursor.slow { background: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.tick.end { background: var(--accent); width: 4px; margin-left: -2px; }
.tl { position: absolute; top: 1.375rem; transform: translateX(-50%); font-size: 0.75rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Sheet: one grid template per mode, shared by the header and every row */
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; --cols: minmax(0, 1.4fr) 5.25rem 5.75rem 7rem 2.75rem; }
.sheet.range { --cols: minmax(0, 1fr) 5.5rem 7rem 5.5rem 7rem 2.75rem; }
.ghead, .head, .row {
  display: grid;
  grid-template-columns: var(--cols);
  column-gap: 0.75rem;
  align-items: center;
  padding: 0.5rem 0.875rem;
}
.ghead { background: var(--field); padding-bottom: 0; }
.head { background: var(--field); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.row { border-top: 1px solid var(--line); }
.row.fixed { background: var(--accent-soft); }
.row.over { opacity: 0.6; }
.row.passed { opacity: 0.45; }
.row.passed-fast { opacity: 0.75; }
.times { display: contents; }

.g { grid-row: 1; text-align: center; font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; padding-bottom: 0.25rem; border-bottom: 3px solid var(--line); font-variant-numeric: tabular-nums; }
.g1 { grid-column: 2 / span 2; border-bottom-color: var(--accent); }
.g2 { grid-column: 4 / span 2; border-bottom-color: var(--ink); }

/* Placement shared by header cells and row cells */
.p-dist, .p-split, .p-race, .p-clock, .p-race2, .p-clock2, .p-rm { grid-row: 1; }
.p-dist { grid-column: 1; }
.p-split { grid-column: 2; }
.p-race { grid-column: 3; }
.p-clock { grid-column: 4; }
.p-race2, .p-clock2 { display: none; }
.p-rm { grid-column: 5; }
.sheet.range .p-split { display: none; }
.sheet.range .p-race { grid-column: 2; }
.sheet.range .p-clock { grid-column: 3; }
.sheet.range .p-race2 { display: block; grid-column: 4; }
.sheet.range .p-clock2 { display: block; grid-column: 5; }
.sheet.range .p-rm { grid-column: 6; }
.head .num { text-align: right; }

.t { text-align: right; font-family: var(--font-display); font-weight: 600; font-size: 1.25rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t.p-split { color: var(--muted); font-weight: 500; }
.t em { font: 500 0.8125rem var(--font-body); font-style: normal; color: var(--muted); }
.sheet.range .t.p-race2, .sheet.range .t.p-clock2 { color: var(--ink); }
.sheet.range .t.p-race, .sheet.range .t.p-clock { color: var(--ink); }

.static { font-weight: 600; padding-block: 0.5rem; }
.static-d { font-variant-numeric: tabular-nums; padding-block: 0.5rem; }
.c-dist { display: flex; align-items: center; gap: 0.375rem; min-width: 0; }
.c-dist input { max-width: 7rem; }
.static .u { margin-left: 0.375rem; font-weight: 500; }
.rm { width: 2.75rem; height: 2.75rem; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 1.25rem; line-height: 1; }
.rm:hover { background: var(--field); color: var(--bad); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Stacked cards, chosen by app.js from the width of the results column */
.sheet.stacked .ghead, .sheet.stacked .head { display: none; }
.sheet.stacked .row { grid-template-columns: minmax(0, 1fr) 2.75rem; row-gap: 0.5rem; }
.sheet.stacked .p-dist { grid-column: 1; grid-row: 1; }
.sheet.stacked .p-rm { grid-column: 2; grid-row: 1; }
.sheet.stacked .times { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; grid-column: 1 / -1; grid-row: 2; }
.sheet.stacked .times .t { grid-column: auto; grid-row: auto; text-align: left; }
.sheet.stacked .t::before {
  content: attr(data-l);
  display: block;
  font: 600 0.6875rem var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.sheet.stacked.range .times { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.sheet.stacked.range .t::before { content: attr(data-lr); }
.sheet.stacked.range .times .p-race { grid-column: 1; grid-row: 1; }
.sheet.stacked.range .times .p-race2 { grid-column: 2; grid-row: 1; }
.sheet.stacked.range .times .p-clock { grid-column: 1; grid-row: 2; }
.sheet.stacked.range .times .p-clock2 { grid-column: 2; grid-row: 2; }
/* Two paces on a card: a Fast and a Slow column, race time big, time of day small underneath */
.sheet.stacked.range .times { row-gap: 0; column-gap: 1rem; }
.sheet.stacked.range .times .p-race, .sheet.stacked.range .times .p-race2 { font-size: 1.5rem; }
.sheet.stacked.range .times .p-race::before { color: var(--accent); }
.sheet.stacked.range .times .p-race2::before { color: var(--ink); }
.sheet.stacked.range .times .p-clock, .sheet.stacked.range .times .p-clock2 { font: 500 0.9375rem var(--font-body); font-variant-numeric: tabular-nums; color: var(--muted); }
.sheet.stacked.range .times .p-clock::before, .sheet.stacked.range .times .p-clock2::before { content: "at "; display: inline; font: inherit; letter-spacing: 0; text-transform: none; }
.sheet.stacked.range .times .p-race2, .sheet.stacked.range .times .p-clock2 { border-left: 1px solid var(--line); padding-left: 1rem; }
.sheet.stacked.range .t.p-race { color: var(--accent); }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin-inline: calc(-1 * max(0.75rem, env(safe-area-inset-left)));
  padding: 0.625rem max(0.75rem, env(safe-area-inset-left)) max(0.625rem, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.actions .btn { align-self: auto; }
.actions .primary { grid-column: 1 / -1; }
.results > .note { padding-bottom: 1.5rem; }
.note { font-size: 0.8125rem; color: var(--muted); margin: 0; max-width: 60ch; }
#fallback { height: 9rem; font: 0.8125rem/1.4 ui-monospace, Menlo, Consolas, monospace; }

@media (min-width: 54rem) {
  body { padding-inline: max(1rem, env(safe-area-inset-left), env(safe-area-inset-right)); padding-block: max(1.5rem, env(safe-area-inset-top)) 3rem; }
  h1 { font-size: 2rem; }
  .top { margin-bottom: 1.25rem; }
  .grid { grid-template-columns: minmax(0, 19rem) minmax(0, 1fr); gap: 1.5rem; }
  .panel { padding: 1.125rem; gap: 1.125rem; }
  .chips { flex-wrap: wrap; overflow: visible; margin-inline: 0; padding-inline: 0; }
  .chip, .btn, .seg button, input[type="text"], input[type="time"] { min-height: 0; }
  input[type="time"] { height: auto; }
  input.big { min-height: 0; padding-block: 0.375rem; }
  .hero { padding: 1.125rem 1.25rem; gap: 1rem 2.5rem; }
  .actions { position: static; display: flex; flex-wrap: wrap; margin: 0; padding: 0; background: none; border: 0; }
  .actions .primary { grid-column: auto; }
  .results > .note { padding-bottom: 0; }
}
@media (max-width: 420px) {
  .hero.range { padding-inline: 0.875rem; gap: 1rem 0.75rem; }
  .hero.range .stat b { font-size: 1.0625rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
