/* Four Pins design system: "Race Bib". Paper, black ink, race red, hard offset shadows.
   Tokens first, then base, layout and components. See DESIGN.md for the rules and styleguide.html for every piece. */

:root {
  /* colour */
  --paper: #F4F1EA;        /* page background */
  --paper-2: #ECE8DF;      /* sunken areas, flags, inputs at rest */
  --card: #FFFFFF;
  --ink: #141414;          /* text, borders, shadows */
  --ink-2: #6E695F;        /* secondary text (4.8:1 on paper) */
  --line: #E2DDD2;         /* hairlines between quiet things */
  --red: #D2302A;          /* fills with white text (5:1) */
  --red-ink: #B8261D;      /* red text on paper or white */
  --red-tint: #FBE1DD;
  --on-red: #FFFFFF;

  /* entry status (text on tint, all 5:1 or better) */
  --st-maybe-fg: #5C5C5C;    --st-maybe-bg: transparent;
  --st-ballot-fg: #6B4B00;   --st-ballot-bg: #FFE7A3;
  --st-entered-fg: #FFFFFF;  --st-entered-bg: #141414;
  --st-deferred-fg: #4A3A86; --st-deferred-bg: #E6E0F5;
  --st-done-fg: #1F6B3A;     --st-done-bg: #DDF1E2;
  --st-dnf-fg: #8A2A1F;      --st-dnf-bg: #FBE1DD;

  /* type: the system font (SF Pro on iPhone); numbers use tabular figures */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-xs: 12px; --fs-sm: 14px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 28px; --fs-bib: 72px;

  /* space: 4px steps */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;

  /* shape */
  --r: 6px;                /* cards, buttons, inputs: bibs have small corners */
  --r-pill: 999px;
  --bw: 2px;               /* strong border */
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);

  /* sizes */
  --tap: 48px;             /* minimum touch target */
  --topbar-h: 56px;
  --tabs-h: 60px;
  --safe-b: env(safe-area-inset-bottom);
  --safe-t: env(safe-area-inset-top);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; min-height: 100dvh;
  font: var(--fs-md)/1.4 var(--font);
  color: var(--ink); background: var(--paper);
}
body.has-tabs { padding-bottom: calc(var(--tabs-h) + var(--safe-b) + 88px); }  /* room for tabs + floating button */
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: var(--fs-2xl); font-weight: 900; letter-spacing: -.5px; }
h2 { font-size: var(--fs-xl); font-weight: 800; letter-spacing: -.3px; }
h3 { font-size: var(--fs-lg); font-weight: 800; }
p { margin: 0 0 var(--s3); }
a { color: var(--red-ink); font-weight: 700; text-decoration: none; }
a:hover { text-decoration: underline; }
small, .muted { color: var(--ink-2); }
.small { font-size: var(--fs-sm); }
.block { display: block; }
.num { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: var(--fs-xs); font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
.icon { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 16px; height: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- layout ---------- */
.page { padding: var(--s4); max-width: 560px; margin: 0 auto; }
.stack > * + * { margin-top: var(--s3); }
.row { display: flex; align-items: center; gap: var(--s2); }
.grow { flex: 1; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--s2);
  min-height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) var(--s2) 0 var(--s4);
  background: var(--paper);
}
.topbar.scrolled { border-bottom: var(--bw) solid var(--ink); }
.topbar .title { flex: 1; min-width: 0; font-size: var(--fs-lg); font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { margin-left: calc(-1 * var(--s3)); }

/* logo: a bib with a pin in each corner */
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 900; font-size: var(--fs-xl); text-transform: uppercase; letter-spacing: .5px; color: var(--ink); }
.logo b { color: var(--red-ink); font-weight: 900; }
a.logo:hover { text-decoration: none; }
.logo-mark { width: 30px; height: 24px; border: var(--bw) solid var(--ink); border-radius: 5px; background: var(--card); position: relative; flex: none;
  --pin: 2px;  /* dot radius; bigger marks set a bigger one */
  background-image: radial-gradient(circle, var(--ink) var(--pin), transparent calc(var(--pin) + .5px)), radial-gradient(circle, var(--ink) var(--pin), transparent calc(var(--pin) + .5px)),
    radial-gradient(circle, var(--ink) var(--pin), transparent calc(var(--pin) + .5px)), radial-gradient(circle, var(--ink) var(--pin), transparent calc(var(--pin) + .5px));
  background-size: 10px 10px; background-repeat: no-repeat;
  background-position: 1px 1px, calc(100% - 1px) 1px, 1px calc(100% - 1px), calc(100% - 1px) calc(100% - 1px); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin: var(--s6) 0 var(--s2); }
.section-head.first { margin-top: var(--s2); }
.section-head h2 { font-size: var(--fs-sm); font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase; }

/* bottom tab bar, clear of the home bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: var(--bw) solid var(--ink);
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 700; color: var(--ink-2); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--ink); }
.tabs a[aria-current="page"] .icon { stroke-width: 2.6; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s5);
  font: 800 var(--fs-md)/1 var(--font); text-decoration: none; white-space: nowrap; cursor: pointer;
  color: var(--ink); background: var(--card);
  border: var(--bw) solid var(--ink); border-radius: var(--r); box-shadow: var(--shadow-sm);
  transition: transform .06s, box-shadow .06s;
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }  /* pressed flat, like a stamp */
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--red); color: var(--on-red); }
.btn.dark { background: var(--ink); color: #fff; }
.btn.quiet { border-color: transparent; box-shadow: none; background: transparent; color: var(--red-ink); padding: 0 var(--s3); }
.btn.quiet:active { transform: none; background: var(--paper-2); }
.btn.danger { color: var(--red-ink); }
.btn.block { display: flex; width: 100%; }
.btn.lg { min-height: 56px; font-size: var(--fs-lg); }
.icon-btn { display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); padding: 0; border: 0; border-radius: var(--r);
  background: transparent; color: var(--ink); cursor: pointer; }
.icon-btn:active { background: var(--paper-2); }
.fab { position: fixed; z-index: 11; right: var(--s4); bottom: calc(var(--tabs-h) + var(--safe-b) + var(--s4)); min-height: 52px; box-shadow: var(--shadow); }

/* ---------- bib card: the hero for the next race ---------- */
.bib {
  position: relative; background: var(--card); border: var(--bw) solid var(--ink); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 0 var(--s6) var(--s4); text-align: center; overflow: hidden;
}
.bib-band { display: flex; justify-content: space-between; gap: var(--s2); margin: 0 calc(-1 * var(--s6)) var(--s2); padding: 7px var(--s4);
  background: var(--red); color: var(--on-red); font-size: var(--fs-xs); font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; }
.bib-number { font-size: var(--fs-bib); font-weight: 900; line-height: .95; letter-spacing: -2px; font-variant-numeric: tabular-nums; margin: var(--s1) 0 var(--s2); }
.bib-number.none { font-size: var(--fs-2xl); letter-spacing: 0; color: var(--ink-2); padding: var(--s4) 0; }
.bib-name { font-size: var(--fs-lg); font-weight: 800; }
.bib-meta { display: flex; justify-content: center; flex-wrap: wrap; gap: var(--s1) var(--s4); font-size: var(--fs-sm); color: var(--ink-2); margin-top: var(--s1); }
.bib .flags { justify-content: center; margin-top: var(--s3); }
/* the four pin holes */
.bib::before, .bib::after, .bib-pins::before, .bib-pins::after {
  content: ""; position: absolute; width: 10px; height: 10px; border-radius: 50%; background: var(--paper); border: var(--bw) solid var(--ink);
}
.bib::before { left: 8px; top: 40px; } .bib::after { right: 8px; top: 40px; }
.bib-pins::before { left: 8px; bottom: 8px; } .bib-pins::after { right: 8px; bottom: 8px; }

/* ---------- race list item ---------- */
.race {
  display: flex; align-items: center; gap: var(--s3); min-height: 72px; padding: var(--s3); font-weight: 400;
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r); color: var(--ink); text-decoration: none;
}
a.race:hover { text-decoration: none; border-color: var(--ink); }
a.race:active { background: var(--paper-2); }
.race + .race { margin-top: var(--s2); }
.race .name { font-weight: 800; }
.race .sub { font-size: var(--fs-sm); color: var(--ink-2); margin-top: 2px; }
.race.past { background: transparent; }
.date-block { width: 48px; flex: none; text-align: center; line-height: 1; font-variant-numeric: tabular-nums; }
.date-block b { display: block; font-size: var(--fs-xl); font-weight: 900; }
.date-block small { display: block; margin-top: 3px; font-size: 11px; font-weight: 800; letter-spacing: 1px; color: var(--red-ink); text-transform: uppercase; }

/* ---------- status chips ---------- */
.chip { display: inline-flex; align-items: center; gap: var(--s1); padding: 3px 9px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 800; white-space: nowrap; border: 1.5px solid transparent; }
.chip.maybe { color: var(--st-maybe-fg); background: var(--st-maybe-bg); border: 1.5px dashed #A8A398; }
.chip.ballot { color: var(--st-ballot-fg); background: var(--st-ballot-bg); }
.chip.entered { color: var(--st-entered-fg); background: var(--st-entered-bg); }
.chip.deferred { color: var(--st-deferred-fg); background: var(--st-deferred-bg); }
.chip.done { color: var(--st-done-fg); background: var(--st-done-bg); }
.chip.dns, .chip.dnf { color: var(--st-dnf-fg); background: var(--st-dnf-bg); }

/* ---------- merch flags: tap to toggle ---------- */
.flags { display: flex; flex-wrap: wrap; gap: var(--s2); }
.flag { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px; border-radius: var(--r);
  font: 700 var(--fs-sm)/1 var(--font); color: var(--ink-2); background: var(--paper-2); border: 1.5px solid transparent; }
.flag .icon { width: 16px; height: 16px; }
.flag[aria-pressed="true"], .flag.on { color: var(--ink); background: var(--card); border-color: var(--ink); }
button.flag { cursor: pointer; min-height: 40px; }
.flag:not(.on):not([aria-pressed="true"]) .label-off { text-decoration: line-through; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.stat { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r); padding: var(--s3); }
.stat b { display: block; font-size: var(--fs-2xl); font-weight: 900; line-height: 1; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.stat small { display: block; margin-top: var(--s1); font-size: 11px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; }

/* ---------- forms ---------- */
.field { display: block; }
.field + .field { margin-top: var(--s4); }
.field > span:first-child { display: block; margin-bottom: 6px; font-size: var(--fs-sm); font-weight: 800; }
.field .hint { display: block; margin-top: 6px; font-size: var(--fs-sm); color: var(--ink-2); }
.field .error { display: block; margin-top: 6px; font-size: var(--fs-sm); font-weight: 700; color: var(--red-ink); }
.input {
  display: block; width: 100%; min-height: var(--tap); padding: 10px var(--s3);
  font: 400 var(--fs-md)/1.3 var(--font);  /* 16px stops iPhone zooming on focus */
  color: var(--ink); background: var(--card);
  border: var(--bw) solid var(--ink); border-radius: var(--r); appearance: none;
}
.input::placeholder { color: #9A958B; }
.input:focus { outline: none; box-shadow: var(--shadow-sm); }
.input[aria-invalid="true"] { border-color: var(--red); }
textarea.input { min-height: 96px; resize: vertical; }
select.input { padding-right: 40px; background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%23141414' stroke-width='2.4'/%3E%3C/svg%3E") no-repeat right 14px center; }
.input.big-num { font-size: var(--fs-2xl); font-weight: 900; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.field-row > .field + .field { margin-top: 0; }
.field + .field-row, .field-row + .field, .field-row + .field-row { margin-top: var(--s4); }

/* segmented control: List / Calendar, distance presets */
.seg { display: flex; padding: 3px; gap: 3px; background: var(--paper-2); border-radius: var(--r); }
.seg button { flex: 1; min-height: 42px; border: 0; border-radius: 4px; background: transparent; color: var(--ink-2);
  font: 800 var(--fs-sm)/1 var(--font); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 0 0 1.5px var(--ink); }

/* switch */
.switch { display: flex; align-items: center; gap: var(--s3); min-height: var(--tap); cursor: pointer; }
.switch input { appearance: none; margin: 0; flex: none; width: 52px; height: 32px; border-radius: var(--r-pill);
  background: var(--paper-2); border: var(--bw) solid var(--ink); position: relative; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--card); border: var(--bw) solid var(--ink); transition: transform .15s; }
.switch input:checked { background: var(--red); }
.switch input:checked::after { transform: translateX(20px); }

/* ---------- list rows (settings, details) ---------- */
.list { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r); overflow: hidden; }
.list > * { display: flex; align-items: center; gap: var(--s3); min-height: 52px; padding: var(--s2) var(--s4); color: var(--ink); text-decoration: none; font-weight: 400; }
.list > * + * { border-top: 1px solid var(--line); }
.list > a:active { background: var(--paper-2); }
.list .k { flex: 1; color: var(--ink-2); font-size: var(--fs-sm); }
.list .v { font-weight: 700; text-align: right; }

/* ---------- calendar month ---------- */
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; text-align: center; }
.month .dow { font-size: 11px; font-weight: 800; color: var(--ink-2); padding: var(--s1) 0; }
.month .day { position: relative; aspect-ratio: 1; display: grid; place-items: center; border-radius: var(--r);
  font-size: var(--fs-sm); font-weight: 600; font-variant-numeric: tabular-nums; }
.month .day.out { color: #B8B3A8; }
.month .day.today { box-shadow: inset 0 0 0 var(--bw) var(--ink); font-weight: 900; }
.month .day.has-race { background: var(--red); color: var(--on-red); font-weight: 900; }
.month .day.has-maybe { background: transparent; color: var(--ink); outline: 1.5px dashed var(--ink-2); outline-offset: -4px; box-shadow: none; }

/* ---------- map pin (used as a Leaflet divIcon) ---------- */
.map-pin { display: inline-grid; place-items: center; min-width: 36px; height: 28px; padding: 0 6px; background: var(--card);
  border: var(--bw) solid var(--ink); border-radius: 5px; box-shadow: var(--shadow-sm); font: 900 13px/1 var(--font); position: relative; }
.map-pin::after { content: ""; position: absolute; left: 50%; bottom: -8px; width: 10px; height: 10px; background: var(--card);
  border-right: var(--bw) solid var(--ink); border-bottom: var(--bw) solid var(--ink); transform: translateX(-50%) rotate(45deg); }
.map-pin.entered { background: var(--red); color: var(--on-red); }
.map-pin.entered::after { background: var(--red); }

/* ---------- sheet (native <dialog>) ---------- */
dialog.sheet { width: 100%; max-width: 560px; max-height: 90dvh; margin: auto auto 0; padding: var(--s2) var(--s4) calc(var(--s4) + var(--safe-b));
  border: var(--bw) solid var(--ink); border-bottom: 0; border-radius: 14px 14px 0 0; background: var(--paper); color: var(--ink); }
dialog.sheet::backdrop { background: rgba(20, 20, 20, .45); }
dialog.sheet .grabber { width: 40px; height: 5px; border-radius: 3px; background: #C9C4B9; margin: 0 auto var(--s3); }
dialog.sheet .actions { display: flex; gap: var(--s2); margin-top: var(--s5); }
dialog.sheet .actions .btn { flex: 1; }

/* ---------- feedback ---------- */
.toast { position: fixed; z-index: 30; left: var(--s4); right: var(--s4); bottom: calc(var(--tabs-h) + var(--safe-b) + var(--s4));
  max-width: 520px; margin: 0 auto; padding: var(--s3) var(--s4); background: var(--ink); color: #fff; border-radius: var(--r);
  font-weight: 700; box-shadow: 4px 4px 0 var(--red); }
.toast:not(.show) { display: none; }
body:not(.has-tabs) .toast { bottom: calc(var(--safe-b) + var(--s4)); }
.toast.bad { background: var(--red); color: var(--on-red); box-shadow: 4px 4px 0 var(--ink); }
.notice { padding: var(--s3) var(--s4); border-radius: var(--r); border: 1.5px solid var(--ink); background: var(--card); font-size: var(--fs-sm); }
.notice.warn { background: var(--st-ballot-bg); border-color: var(--st-ballot-fg); color: var(--st-ballot-fg); }
.notice.error { background: var(--red-tint); border-color: var(--red-ink); color: var(--st-dnf-fg); }
.empty { text-align: center; padding: var(--s8) var(--s4); }
.empty .logo-mark { --pin: 3.5px; width: 60px; height: 48px; margin: 0 auto var(--s4); display: block; background-size: 18px 18px;
  background-position: 4px 4px, calc(100% - 4px) 4px, 4px calc(100% - 4px), calc(100% - 4px) calc(100% - 4px); }
.empty h3 { margin-bottom: var(--s2); }
.empty p { color: var(--ink-2); }

/* ---------- app shell ---------- */
.app-footer { max-width: 560px; margin: 0 auto; padding: var(--s6) var(--s4) calc(var(--s4) + var(--safe-b));
  text-align: center; font-size: var(--fs-xs); color: var(--ink-2); }
body.has-tabs .app-footer { padding-bottom: var(--s4); }
.row > .input { flex: 1; min-width: 0; }
.note { margin-top: var(--s2); }
.sheet-text { margin-top: var(--s2); }

/* sign-in and sign-up screens */
.auth { display: flex; flex-direction: column; gap: var(--s4); padding-top: var(--s4); }
.auth > .btn.quiet { align-self: center; }
.auth > p { margin: 0; }
.brand { text-align: center; padding: var(--s4) 0 var(--s2); }
.brand .logo-mark { --pin: 5.5px; display: block; width: 90px; height: 72px; margin: 0 auto var(--s4); border-width: 3px; box-shadow: var(--shadow); background-size: 24px 24px;
  background-position: 6px 6px, calc(100% - 6px) 6px, 6px calc(100% - 6px), calc(100% - 6px) calc(100% - 6px); }
.brand h1 { font-size: 34px; text-transform: uppercase; letter-spacing: .5px; }
.brand h1 b { color: var(--red-ink); }
.brand p { margin-top: var(--s2); }

/* a link to share: the address plus Share/Copy */
.link-box { display: flex; gap: var(--s2); margin: var(--s2) 0; }
.link-box .input { flex: 1; min-width: 0; font-size: var(--fs-sm); background: var(--paper-2); }

/* admin: people */
.list.people > .person { display: block; padding: var(--s3) var(--s4); }
.person-actions { display: flex; flex-wrap: wrap; gap: 0 var(--s1); margin: var(--s1) 0 0 calc(-1 * var(--s3)); }
.person-link:empty { display: none; }
