:root {
  --cobalt: #2F2BE0;
  --cobalt-deep: #1E1A9E;
  --track: #E4572E;
  --track-dark: #B93E1C;
  --ink: #15123A;
  --paper: #FFFFFF;
  --mist: #EEEDFB;
  --muted: #6A6790;
  --lime: #C6F432;
  --display: "Big Shoulders Display", "Arial Narrow", Impact, sans-serif;
  --body: "Onest", system-ui, -apple-system, sans-serif;
  --radius: 18px;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--cobalt);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

/* Any author `display` beats the browser's own [hidden] rule, so hiding an element
   in JS silently fails and it keeps swallowing taps. Make [hidden] mean hidden. */
[hidden] { display: none !important; }

/* Rapid taps on a phone otherwise trigger double-tap zoom, and the second tap of a
   quick Save-Save lands on zoomed-away content. */
button, input, select, label, .tab { touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

main, .top { max-width: 560px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }

/* ---------- Header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-bottom: 8px;
  color: var(--paper);
}
.brand { display: flex; flex-direction: column; }
.brand-name {
  font-family: var(--display); font-weight: 900; font-size: 30px;
  letter-spacing: .02em; text-transform: uppercase; line-height: 1;
}
.countdown { font-size: 13px; font-weight: 600; opacity: .8; margin-top: 4px; }
.who-btn {
  min-width: 44px; height: 44px; border-radius: 22px; border: 3px solid var(--paper);
  font-family: var(--display); font-weight: 900; font-size: 20px; padding: 0 12px;
  background: var(--paper);
}

/* ---------- Hero: the track ---------- */
.hero { padding: 6px 0 18px; color: var(--paper); }
.standing {
  font-family: var(--display); font-weight: 800; font-size: 34px; line-height: 1.02;
  margin: 8px 0 16px; text-transform: uppercase; letter-spacing: .01em;
}
.standing em { font-style: normal; color: var(--lime); }
.standing small {
  display: block; font-family: var(--body); text-transform: none; font-weight: 500;
  font-size: 15px; line-height: 1.35; margin-top: 8px; opacity: .9; letter-spacing: 0;
}

.track {
  position: relative; background: var(--track); border-radius: 22px;
  padding: 10px 44px 10px 12px; box-shadow: 0 6px 0 var(--track-dark);
  overflow: hidden;
}
/* checkered finish line */
.track::after {
  content: ""; position: absolute; top: 0; bottom: 0; right: 14px; width: 18px;
  background:
    repeating-conic-gradient(var(--ink) 0 25%, var(--paper) 0 50%) 0 0 / 9px 9px;
}
.lane {
  position: relative; height: 44px; border-bottom: 2px solid rgba(255,255,255,.55);
}
.lane:last-child { border-bottom: 0; }
.lane-num {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  /* Was white at .35 (~1.6:1). Now they carry rank, so they have to be readable:
     solid white on the track is 3.68:1, which clears AA's 3:1 for large bold text. */
  font-family: var(--display); font-weight: 900; font-size: 22px; color: var(--paper);
}
.lane-inner { position: absolute; left: 22px; right: 0; top: 0; bottom: 0; }
.plan-tick {
  position: absolute; top: 4px; bottom: 4px; width: 0;
  border-left: 3px dashed rgba(255,255,255,.9);
}
.runner-dot {
  position: absolute; top: 50%; left: 0;
  width: 36px; height: 36px; margin-left: -18px; margin-top: -18px;
  border-radius: 50%; border: 3px solid var(--ink);
  display: grid; place-items: center;
  font-family: var(--display); font-weight: 900; font-size: 18px; color: var(--ink);
  transition: left 1.4s var(--spring);
  background: var(--c);
  box-shadow: 0 3px 0 var(--ink);
  padding: 0;
}
.runner-dot.me { outline: 3px solid var(--paper); outline-offset: 2px; }
/* White on the track orange is 3.68:1, under the 4.5:1 AA needs at 12px, and the
   dashed plan line can cut straight through it. On ink it is 17.8:1 and opaque. */
.runner-dot .pct {
  position: absolute; left: 100%; margin-left: 8px; white-space: nowrap;
  font-family: var(--body); font-size: 12px; font-weight: 700; line-height: 1;
  color: var(--paper); background: var(--ink); padding: 4px 7px; border-radius: 999px;
}
.runner-dot.flip .pct { left: auto; right: 100%; margin: 0 8px 0 0; }
.track-key { font-size: 12px; opacity: .8; margin: 10px 0 0; display: flex; align-items: center; gap: 8px; }
.key-plan { display: inline-block; height: 14px; border-left: 3px dashed var(--paper); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: 4px -16px 14px; padding: 0 16px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; min-height: 44px; padding: 0 16px; border-radius: 22px;
  border: 2px solid rgba(255,255,255,.4); background: transparent; color: var(--paper);
  font-weight: 700; font-size: 15px; transition: background .2s, color .2s, transform .15s;
}
.tabs button[aria-selected="true"] { background: var(--paper); color: var(--cobalt); border-color: var(--paper); }
.tabs button:active { transform: scale(.95); }

/* ---------- Bib cards ---------- */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.bib {
  --pin: radial-gradient(circle, var(--cobalt) 0 4px, transparent 4.5px);
  position: relative; background: var(--paper); border-radius: var(--radius);
  box-shadow: 0 5px 0 var(--cobalt-deep);
  overflow: hidden; cursor: pointer;
  transition: transform .15s;
  -webkit-tap-highlight-color: transparent;
}
.bib:active { transform: scale(.98); }
.bib.me { box-shadow: 0 5px 0 var(--cobalt-deep), 0 0 0 4px var(--lime); }
/* safety-pin holes */
.bib::before {
  content: ""; position: absolute; inset: 7px; pointer-events: none;
  background:
    var(--pin) 0 0 / 14px 14px no-repeat,
    var(--pin) 100% 0 / 14px 14px no-repeat,
    var(--pin) 0 100% / 14px 14px no-repeat,
    var(--pin) 100% 100% / 14px 14px no-repeat;
}
.bib-band {
  background: var(--c); padding: 7px 28px; display: flex; justify-content: space-between;
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
}
.bib-main {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 10px 24px 4px;
}
.rank {
  font-family: var(--display); font-weight: 900; font-size: 54px; line-height: .9;
  width: 1.1ch; text-align: center;
}
.rank.r1 { color: var(--track); }
.who { min-width: 0; }
.who-name {
  font-family: var(--display); font-weight: 900; font-size: 30px; line-height: .95;
  text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.who-sub { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 3px; }
.metric { text-align: right; }
.metric-val {
  font-family: var(--display); font-weight: 900; font-size: 40px; line-height: .9;
  font-variant-numeric: tabular-nums;
}
.metric-unit { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 24px 0; }
.chip {
  font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px;
  background: var(--mist); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chip.hot { background: #FFE2D6; color: #9A2C0E; }

.ready { padding: 10px 24px 18px; }
.ready-top { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; margin-bottom: 5px; }
.ready-top .status { color: var(--muted); }
.ready-top .status.ahead { color: #1D8A4E; }
.ready-top .status.behind { color: var(--track-dark); }
.bar { position: relative; height: 14px; border-radius: 7px; background: var(--mist); overflow: visible; }
.bar-fill {
  height: 100%; width: 0; border-radius: 7px; background: var(--c);
  border: 2px solid var(--ink); transition: width 1.2s var(--spring);
}
.bar-plan { position: absolute; top: -4px; bottom: -4px; border-left: 3px dashed var(--ink); }

/* ---------- Feed ---------- */
.feed { margin-top: 30px; color: var(--paper); }
.feed h2 {
  font-family: var(--display); font-weight: 900; font-size: 26px; text-transform: uppercase;
  margin: 0 0 10px;
}
.feed ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.feed li {
  display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: start;
  background: rgba(255,255,255,.1); border-radius: 14px; padding: 12px;
  font-size: 14px;
}
.feed .emo { font-size: 24px; line-height: 1; }
.feed b { display: block; font-size: 14px; }
.feed time { font-size: 12px; opacity: .65; }

.foot { color: rgba(255,255,255,.7); font-size: 12px; text-align: center; margin: 28px 0 10px; }
.foot button { background: none; border: 0; text-decoration: underline; color: inherit; padding: 8px; min-height: 44px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  height: 56px; padding: 0 26px; border-radius: 28px; border: 3px solid var(--ink);
  background: var(--lime); color: var(--ink); font-weight: 800; font-size: 17px;
  box-shadow: 0 5px 0 var(--ink); z-index: 20;
  display: flex; align-items: center; gap: 8px;
  transition: transform .12s, box-shadow .12s;
}
.fab span { font-size: 26px; line-height: 1; margin-top: -2px; }
.fab:active { transform: translateX(-50%) translateY(4px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- Bottom sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10,8,40,.55); z-index: 30; animation: fade .25s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 560px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  background: var(--paper); border-radius: 26px 26px 0 0;
  padding: 8px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slideUp .38s var(--spring);
  overscroll-behavior: contain;
}
.sheet.closing { animation: slideDown .22s ease-in forwards; }
.scrim.closing { animation: fade .22s reverse forwards; }
.grabber { width: 44px; height: 5px; border-radius: 3px; background: #D5D3EE; margin: 4px auto 12px; }
.sheet h2 {
  font-family: var(--display); font-weight: 900; font-size: 36px; text-transform: uppercase;
  margin: 0; line-height: 1;
}
.sheet h3 {
  font-family: var(--display); font-weight: 800; font-size: 20px; text-transform: uppercase;
  margin: 22px 0 8px; letter-spacing: .02em;
}
.sheet .lede { color: var(--muted); font-size: 14px; margin: 6px 0 0; }

.big-pred {
  margin-top: 16px; padding: 16px; border-radius: 18px; background: var(--ink); color: var(--paper);
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.big-pred .t { font-family: var(--display); font-weight: 900; font-size: 52px; line-height: 1; font-variant-numeric: tabular-nums; }
.big-pred .l { font-size: 13px; opacity: .8; }
.trend { font-weight: 700; font-size: 13px; padding: 3px 8px; border-radius: 999px; background: rgba(255,255,255,.15); }
.trend.up { background: var(--lime); color: var(--ink); }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--mist); border-radius: 14px; padding: 12px; }
.stat .v { font-family: var(--display); font-weight: 900; font-size: 28px; line-height: 1; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.stat .mini { height: 8px; border-radius: 4px; background: #D9D7F2; margin-top: 8px; overflow: hidden; }
.stat .mini i { display: block; height: 100%; background: var(--c); border-right: 2px solid var(--ink); }

.weeks { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 0; }
.weeks div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
/* flex:none, or the bar is a shrinkable flex item and every big week renders the
   same height — the chart went flat exactly where the plan builds. */
.weeks i { display: block; flex: none; width: 100%; border-radius: 6px 6px 3px 3px; background: var(--c); border: 2px solid var(--ink); min-height: 4px; }
.weeks span { font-size: 10px; font-weight: 700; color: var(--muted); }
.weeks div.now i { background: repeating-linear-gradient(45deg, var(--c) 0 5px, #fff 5px 8px); }

.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge {
  text-align: center; padding: 10px 6px; border-radius: 14px; background: var(--mist);
  font-size: 11px; font-weight: 700; line-height: 1.2;
}
.badge .b-emo { font-size: 30px; display: block; margin-bottom: 4px; }
.badge.locked { opacity: .38; filter: grayscale(1); }

.runs { list-style: none; padding: 0; margin: 0; }
.runs li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--mist); font-size: 14px; font-variant-numeric: tabular-nums; }
.runs li span:last-child { color: var(--muted); }
.runs .del { border: 0; background: none; color: var(--track-dark); font-weight: 700; min-height: 44px; padding: 0 0 0 12px; }
.form .check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; }
.form .check input {
  width: 22px; height: 22px; min-height: 0; padding: 0; flex: none;
  border-radius: 6px; accent-color: var(--ink);
}
.form .check small { color: var(--muted); }
.runs .editrun {
  flex: 1; text-align: left; border: 0; background: none; font: inherit; color: inherit;
  min-height: 44px; padding: 0 8px 0 0; border-radius: 8px;
}
.runs .editrun:active { background: var(--mist); }
.runs .editrun.editing { background: var(--mist); box-shadow: inset 3px 0 0 var(--ink); padding-left: 8px; }

/* forms */
.form { display: grid; gap: 14px; margin-top: 16px; }
.form label { display: grid; gap: 6px; font-weight: 700; font-size: 14px; }
.form input {
  font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 12px;
  border: 2px solid #D5D3EE; background: var(--paper); min-height: 48px; width: 100%;
}
.form input:focus { border-color: var(--cobalt); outline: none; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick { display: flex; flex-wrap: wrap; gap: 8px; }
.pick button {
  min-height: 44px; padding: 0 16px; border-radius: 22px; border: 3px solid var(--ink);
  background: var(--paper); font-weight: 800;
}
.pick button[aria-pressed="true"] { background: var(--c); }
.btn {
  min-height: 52px; border-radius: 26px; border: 3px solid var(--ink); background: var(--cobalt);
  color: var(--paper); font-weight: 800; font-size: 17px; box-shadow: 0 4px 0 var(--ink);
}
.btn.ghost { background: var(--paper); color: var(--ink); }
.note { font-size: 13px; color: var(--muted); margin: 0; }
.err { color: var(--track-dark); font-weight: 700; font-size: 14px; margin: 0; }

/* ---------- Pop-up ---------- */
.pop-wrap {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: rgba(10,8,40,.6); animation: fade .2s;
}
.pop {
  width: min(360px, 100%); background: var(--paper); border-radius: 26px; border: 4px solid var(--ink);
  box-shadow: 0 8px 0 var(--ink); padding: 26px 22px 20px; text-align: center;
  animation: popIn .55s var(--spring);
  position: relative;
}
.pop.roast { animation: popIn .45s var(--spring), wobble .6s .45s; background: #FFF1EB; }
.pop .p-emo { font-size: 64px; line-height: 1; display: block; animation: bounce 1.2s .3s infinite; }
.pop .p-kicker { font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-top: 12px; }
.pop h3 {
  font-family: var(--display); font-weight: 900; font-size: 34px; line-height: 1; text-transform: uppercase;
  margin: 6px 0 10px;
}
.pop p { margin: 0 0 18px; font-size: 16px; }
.pop .btn { width: 100%; }
.pop .count { font-size: 12px; color: var(--muted); margin-top: 10px; font-weight: 600; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

@keyframes fade { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(100%); } }
@keyframes slideDown { to { transform: translateY(100%); } }
@keyframes popIn { from { transform: scale(.4) rotate(-6deg); opacity: 0; } }
@keyframes wobble { 0%,100% { transform: rotate(0); } 20% { transform: rotate(-4deg); } 40% { transform: rotate(3deg); } 60% { transform: rotate(-2deg); } 80% { transform: rotate(1deg); } }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes rise { from { transform: translateY(18px); opacity: 0; } }
.cards > li { animation: rise .5s var(--spring) backwards; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 600px) {
  .standing { font-size: 42px; }
}
