﻿/* The race sheet: the look of a paper lap sheet on a clipboard at the corral. */

@font-face { font-family: "Barlow Condensed"; font-weight: 600; font-display: swap; src: url("/vendor/fonts/barlow-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 800; font-display: swap; src: url("/vendor/fonts/barlow-condensed-latin-800-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-display: swap; src: url("/vendor/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 600; font-display: swap; src: url("/vendor/fonts/ibm-plex-mono-latin-600-normal.woff2") format("woff2"); }

:root {
  --paper: #f3eee2;
  --ink: #1b1a17;
  --pencil: #5c584e;
  --rule: #cfc8b6;
  --red: #b3281b;
  --r0: #2a78d6;
  --r1: #eb6834;
  --r2: #1baf7a;
  --r3: #eda100;
  --r4: #e87ba4;
  --r5: #008300;
  --r6: #6250d6;
  --r7: #e34948;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --head: "Barlow Condensed", "Arial Narrow", sans-serif;
  color-scheme: light;
}

.s0 { --c: var(--r0); }
.s1 { --c: var(--r1); }
.s2 { --c: var(--r2); }
.s3 { --c: var(--r3); }
.s4 { --c: var(--r4); }
.s5 { --c: var(--r5); }
.s6 { --c: var(--r6); }
.s7 { --c: var(--r7); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 var(--mono);
  padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
}

h1, h2, p { margin: 0; }

h1 {
  font: 800 clamp(2.5rem, 11vw, 4.4rem)/0.95 var(--head);
  text-transform: uppercase;
  letter-spacing: 0.005em;
}

h2 {
  font: 800 1.3rem/1.1 var(--head);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

a { color: inherit; }
button, a, [role="button"] { touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; user-select: none; -webkit-user-select: none; }
input, textarea, select { font: 400 16px/1.4 var(--mono); }
code { font-size: 0.86rem; overflow-wrap: anywhere; }

:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ---- masthead ---- */

.top {
  max-width: 1120px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 8px;
  border-bottom: 4px solid var(--ink);
}
.top > div:first-child { min-width: 0; }
.top-right {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  margin-top: 6px;
  font-size: 0.86rem;
}
.sub { color: var(--pencil); font-size: 0.88rem; }

.pill { margin-right: auto; color: var(--pencil); }
.pill.live { color: var(--red); font-weight: 600; }
.pill.live::before { content: "\25CF  "; }

.ghost {
  background: none;
  border: 0;
  padding: 2px 0;
  font-size: 0.86rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ghost:active { color: var(--red); }

/* ---- sheet layout ---- */

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

.sheet { display: flex; flex-direction: column; gap: 22px; }
.col { display: contents; }
#hero { order: 1; }
#latest { order: 2; }
#note { order: 3; }
#boardWrap { order: 4; }
#mapWrap { order: 5; }
#spareWrap { order: 6; }
#detail { order: 7; }
#cheer { order: 8; }
.foot { order: 9; }

@media (min-width: 900px) {
  .sheet {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 0 44px;
    align-items: start;
  }
  .col { display: flex; flex-direction: column; gap: 22px; padding-top: 14px; }
  .foot { grid-column: 1 / -1; }
}

/* ---- the clock ---- */

.hero { padding-top: 12px; }
.eyebrow { font: 800 1.5rem/1 var(--head); text-transform: uppercase; letter-spacing: 0.03em; }
.clock {
  font: 600 clamp(4rem, 21vw, 6.4rem)/1 var(--mono);
  letter-spacing: -0.05em;
  margin-top: 6px;
}
.clock-label { color: var(--pencil); font-size: 0.86rem; }
.bar {
  position: relative;
  height: 10px;
  margin: 12px 0 8px;
  border-bottom: 1px solid var(--ink);
  background: repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px calc(100% / 12));
}
.bar span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--red);
  opacity: 0.85;
  transition: width 600ms ease-out;
}
.phase { font-size: 0.92rem; }

.latest { border-left: 4px solid var(--red); padding-left: 10px; font-size: 0.92rem; }
.latest b { font-weight: 600; text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.06em; margin-right: 4px; }
.latest time { color: var(--pencil); font-size: 0.8rem; white-space: nowrap; }

.note { border: 1px dashed var(--ink); padding: 8px 10px; transform: rotate(-0.4deg); }

.signal { color: var(--red); font-size: 0.88rem; }

/* ---- ruled sections ---- */

.card {
  border-top: 2px solid var(--ink);
  padding-top: 8px;
  scroll-margin-top: 58px;
}
.hint { color: var(--pencil); font-size: 0.84rem; }
.foot { color: var(--pencil); font-size: 0.8rem; padding: 14px 0; border-top: 1px solid var(--rule); }

/* ---- race board ---- */

.board { list-style: none; margin: 4px 0 0; padding: 0; }
.board li { border-bottom: 1px solid var(--rule); }
.board-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1.3rem minmax(0, 1fr) auto;
  gap: 2px 8px;
  align-items: baseline;
  text-align: left;
  background: none;
  border: 0;
  padding: 9px 0 8px;
}
.board-row:active { background: rgb(0 0 0 / 5%); }
.board-row .rank { font-weight: 600; }
.board-row .who { display: grid; min-width: 0; }
.board-row .who strong {
  font: 800 1.35rem/1.1 var(--head);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-row.on .who strong { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.board-row .status { color: var(--pencil); font-size: 0.78rem; font-weight: 400; }
.board-row .score { display: grid; justify-items: end; }
.board-row .score strong { font-weight: 600; }

.swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 5px;
  background: var(--c);
}

.tally { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px 6px; min-height: 18px; margin-bottom: 2px; }
.tally span { position: relative; display: inline-flex; gap: 3px; height: 16px; }
.tally i { display: block; width: 1.5px; height: 16px; background: var(--ink); transform: rotate(3deg); }
.tally i:nth-child(even) { transform: rotate(-2deg); height: 15px; }
.tally .five::after {
  content: "";
  position: absolute;
  left: -3px;
  right: -3px;
  top: 7px;
  height: 1.5px;
  background: var(--ink);
  transform: rotate(-22deg);
}

/* ---- chart ---- */

.legend { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 6px; font-size: 0.82rem; }
.legend > span { display: inline-flex; align-items: center; }
.chart { margin-top: 6px; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .grid { stroke: var(--rule); stroke-width: 1; }
.chart .zero { stroke: var(--ink); stroke-width: 1.5; }
.chart .axis { fill: var(--pencil); font: 400 11px var(--mono); }
.chart .guide { stroke: var(--pencil); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--c); stroke: var(--paper); stroke-width: 2; }
.chart .dot.on { stroke: var(--ink); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart-read { font-size: 0.84rem; min-height: 1.4em; margin-top: 2px; }

/* ---- map ---- */

.map-card { position: relative; isolation: isolate; border: 2px solid var(--ink); padding: 0; }
#map { height: min(52svh, 400px); background: #e6e0d0; }
.leaflet-tile-pane { filter: grayscale(1) contrast(0.92) brightness(1.04); }
.leaflet-container { font-family: var(--mono) !important; }
.leaflet-container a { color: var(--ink); }
.leaflet-bar, .leaflet-bar a { border-radius: 0 !important; }
.runner-dot {
  width: 16px;
  height: 16px;
  background: var(--c, var(--red));
  border: 2px solid var(--ink);
  border-radius: 50%;
}
.runner-dot.stale { background: #9a958a; }
.leaflet-tooltip {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 0;
  box-shadow: none;
  font: 800 0.95rem/1.1 var(--head);
  padding: 1px 5px;
}
.leaflet-tooltip-top::before { display: none; }

/* ---- runner sheet ---- */

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px 12px;
  flex-wrap: wrap;
  border-top: 2px solid var(--ink);
  padding-top: 8px;
}
.detail-head h2 { font-size: 1.7rem; }
.ghost.link { text-decoration: underline; }

.stats { display: grid; gap: 0 28px; }
@media (min-width: 560px) { .stats { grid-template-columns: 1fr 1fr; } }
.stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 0;
}
.stat .label { order: 1; color: var(--pencil); font-size: 0.86rem; white-space: nowrap; }
.stat::after { content: ""; order: 2; flex: 1; border-bottom: 1px dotted var(--pencil); transform: translateY(-3px); }
.stat strong { order: 3; font-weight: 600; white-space: nowrap; }

.splits { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 0.88rem; }
.splits th {
  color: var(--pencil);
  font-size: 0.74rem;
  font-weight: 400;
  text-align: right;
  border-bottom: 1px solid var(--ink);
  padding: 0 0 3px;
}
.splits td { text-align: right; padding: 4px 0; border-bottom: 1px solid var(--rule); }
.splits th:first-child, .splits td:first-child { text-align: left; }
.splits td:nth-child(2) { font-weight: 600; }
.splits td:last-child { color: var(--pencil); }

/* ---- forms ---- */

form { display: grid; gap: 8px; margin-top: 8px; }
input, textarea, select {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  padding: 8px 2px;
  background: transparent;
  color: var(--ink);
  resize: vertical;
}
select { appearance: auto; }
input::placeholder, textarea::placeholder { color: var(--pencil); opacity: 0.8; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.primary, .btn {
  border-radius: 0;
  padding: 9px 14px;
  font: 600 0.9rem/1.2 var(--mono);
  text-decoration: none;
  display: inline-block;
  text-align: center;
  transition: transform 100ms ease-out;
}
.primary { background: var(--ink); color: var(--paper); border: 2px solid var(--ink); }
.btn { background: transparent; color: var(--ink); border: 2px solid var(--ink); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.primary-link { background: var(--ink); color: var(--paper); }
.primary:active, .btn:active, .clap:active { transform: translateY(1px); }

/* ---- cheers ---- */

.feed { list-style: none; margin: 12px 0 0; padding: 0; }
.feed li { border-top: 1px solid var(--rule); padding: 7px 0; overflow-wrap: anywhere; font-size: 0.92rem; }
.feed .who { font-weight: 600; }
.feed time { color: var(--pencil); font-size: 0.76rem; margin-left: 6px; }
.feed li.reply { border-left: 4px solid var(--red); padding-left: 8px; }
.feed li.flash { background: rgb(179 40 27 / 12%); }
.memo-play { display: block; margin-top: 4px; padding: 5px 9px; font-size: 0.8rem; }
#memoPreview { max-width: 100%; height: 38px; }

/* ---- dock and pinned clock ---- */

.strip {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 1000;
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: space-between;
  gap: 10px;
  padding: calc(5px + env(safe-area-inset-top, 0px)) 16px 5px;
  background: var(--ink);
  color: var(--paper);
}
.strip .label { font-size: 0.68rem; margin-right: 6px; opacity: 0.75; }
.strip strong { font-weight: 600; font-size: 0.95rem; }

.dock {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 1000;
  display: flex;
  background: var(--ink);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.clap, .dock-link {
  flex: 1;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--paper);
  font: 800 1.2rem/1 var(--head);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
}
.dock-link { border-left: 1px solid var(--pencil); }
.clap:active, .dock-link:active { background: var(--red); }
.clap .count { font: 400 0.92rem var(--mono); opacity: 0.85; }

@media (hover: hover) and (pointer: fine) {
  .board-row:hover { background: rgb(0 0 0 / 4%); }
  .ghost:hover, a:hover { color: var(--red); }
  .primary:hover { background: var(--red); border-color: var(--red); }
  .btn:hover { background: rgb(0 0 0 / 6%); }
  .clap:hover, .dock-link:hover { background: #33312b; }
}

/* ---- join and crew pages ---- */

.crew-grid { display: grid; gap: 20px; }
main > .crew-grid, main > .card { margin-top: 16px; }
.crew-grid label { display: grid; gap: 2px; font-size: 0.84rem; color: var(--pencil); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; font-size: 0.88rem; }
.kv dt { color: var(--pencil); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.bad { color: var(--red); font-weight: 600; font-size: 0.86rem; }
.ok { color: inherit; }
.crew-cheer { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.crew-cheer.hidden-cheer span { opacity: 0.5; text-decoration: line-through; }
.steps { margin: 8px 0 0; padding-left: 1.2rem; display: grid; gap: 4px; font-size: 0.9rem; }
.qr { display: block; width: min(240px, 100%); height: auto; margin-top: 10px; background: #fff; padding: 6px; image-rendering: pixelated; }
.crew-runner { border-top: 1px solid var(--rule); padding-top: 8px; display: grid; gap: 6px; }
.crew-runner .row .btn { padding: 5px 8px; font-size: 0.78rem; }
.crew-runner strong { font: 800 1.2rem/1.1 var(--head); }
