/* ---------------------------------------------------------------------------
   WRB — app styles.

   This is a phone app (spec §35). There is one layout, sized for a thumb; on a
   wide screen it simply centres itself in a phone-width column. No desktop
   variant, no sidebar, no breakpoint that rearranges anything.
   --------------------------------------------------------------------------- */

:root {
  --bg: #f2f4f6;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --ink: #12161b;
  --ink-2: #49525f;
  --muted: #79838f;
  --line: #e3e7ec;
  --accent: #fc4c02;          /* the one loud colour: Record, links, progress */
  --accent-ink: #ffffff;
  --run: #0e9cf9;
  --walk: #7fbd2d;
  --bike: #fe9411;
  --run-dark: #0081dd;
  --walk-dark: #71ac27;
  --bike-dark: #f47512;
  /* The figures' own colours, and the pale circles they sit on. */
  --walk-fig: #487f24; --run-fig: #0170bc; --bike-fig: #fd610e;
  --walk-tint: #dcebc4; --run-tint: #cce9fd; --bike-tint: #ffe9cd;
  --good: #12a150;
  --bad: #dc2626;
  --radius: 12px;
  --tabbar: 66px;
  --phone: 520px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* .live and .tab set display, which would otherwise beat the hidden attribute
   the recorder uses to swap between the live screen and the save sheet. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0 0 .4rem; line-height: 1.2; letter-spacing: -.015em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
p { margin: 0 0 .7rem; }

/* Times and distances are tabular so columns of numbers line up. */
.num, .stat-value, .metric-value, .live-value, table td, .feed-stat b {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* The phone column. Everything lives inside it. */
.phone {
  max-width: var(--phone);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}
@media (min-width: 560px) {
  body { background: #dfe4e9; }
  .phone { box-shadow: 0 0 0 1px rgba(16, 24, 40, .06), 0 18px 50px -20px rgba(16, 24, 40, .35); }
}

/* --- Top bar -------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title {
  font-size: 1.2rem;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-back {
  font-size: 1.7rem;
  line-height: 1;
  width: 26px;
  margin-top: -3px;
  color: var(--accent);
}
.topbar-actions { display: flex; align-items: center; gap: .4rem; }

.icon-btn {
  position: relative;
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: .95rem;
}
.badge {
  position: absolute;
  top: -2px; right: -2px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: .62rem;
  font-weight: 700;
  padding: 1px 5px;
}

/* --- Main ----------------------------------------------------------------- */
.main {
  padding: 12px 12px calc(var(--tabbar) + 22px + env(safe-area-inset-bottom));
}
.main-bare { padding: 0; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05);
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: 10px;
}
.card-head h2 { margin: 0; }
.card-head a, .card-head .muted { font-size: .8rem; }
.card-head a { color: var(--accent); font-weight: 600; }

/* One column, always. The grid classes stay so pages read the same. */
.grid { display: grid; gap: 12px; }

/* --- Stats ---------------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 12px;
}
.stat { min-width: 0; }
.stat-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 1px;
}
.stat-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -.025em; }
.stat-value small { font-size: .72rem; font-weight: 600; color: var(--muted); }

.hero-stat { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.hero-stat .stat-value { font-size: 2.5rem; }

/* --- Buttons + forms ------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 44px;                 /* thumb-sized, always */
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
}
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { color: var(--bad); border-color: #f1cccc; background: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .82rem; }

.field { margin-bottom: 13px; }
.field label {
  display: block;
  font-size: .76rem;
  font-weight: 700;
  color: var(--ink-2);
  margin-bottom: 5px;
}
.field .hint { font-size: .74rem; color: var(--muted); margin-top: 4px; line-height: 1.35; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=time], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px;                  /* iOS zooms anything smaller on focus */
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(252, 76, 2, .3);
  outline-offset: 1px;
  border-color: var(--accent);
}
textarea { min-height: 78px; resize: vertical; }
.field-row { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.checkline { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.checkline input { width: auto; min-height: 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: 4px; }

/* Horizontal filter/segment strip — scrolls rather than wrapping. */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: .84rem;
  font-weight: 600;
  white-space: nowrap;
}
.chip.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* --- Flash + empty -------------------------------------------------------- */
.flash {
  border-radius: 10px;
  padding: 11px 13px;
  margin-bottom: 12px;
  font-size: .88rem;
  font-weight: 500;
  border: 1px solid;
}
.flash-success { background: #e9f8ef; border-color: #b7e5c8; color: #0f7038; }
.flash-error { background: #fdecec; border-color: #f4c4c4; color: #a52020; }
.flash-info { background: #eaf2fe; border-color: #c3d9fa; color: #1a4fa0; }

.empty-state { text-align: center; padding: 30px 18px; }
.empty-icon { font-size: 1.9rem; margin-bottom: .3rem; }
.empty-state p { color: var(--muted); margin: 0 auto .9rem; }
.soon-list {
  list-style: none;
  padding: 0;
  margin: 0 auto 1rem;
  text-align: left;
  color: var(--ink-2);
  font-size: .86rem;
}
.soon-list li { padding: 5px 0 5px 18px; position: relative; }
.soon-list li::before { content: "•"; position: absolute; left: 3px; color: var(--accent); }

/* --- Activity feed (spec §15) --------------------------------------------- */
.day-header {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 800;
  color: var(--muted);
  margin: 16px 2px 8px;
}
.feed-card {
  display: block;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05);
}
.feed-card:active { background: #fbfcfd; }

/* Nested in a card — the dashboard's "Recent activities" — the row drops its
   own horizontal padding and shadow so the icon lines up under the heading
   and the map's right edge with the "See all" link. A card inside a card
   otherwise indents twice and looks misaligned against its own title. */
.card > .feed-card {
  padding-left: 0;
  padding-right: 0;
  box-shadow: none;
  margin-bottom: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}
.card > .feed-card:last-of-type { border-bottom: 0; padding-bottom: 0; }
/* Info on the left, map on the right spanning the whole card. */
.feed-grid { display: flex; align-items: center; gap: 12px; }
.feed-info { flex: 1; min-width: 0; }
.feed-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.activity-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  background: var(--surface-2);
  flex: none;
}
/* Light tints, not solid colour: each figure is drawn in its own colour and
   would disappear against a circle of the same one. */
.activity-icon.type-run { background: var(--run-tint); }
.activity-icon.type-walk { background: var(--walk-tint); }
.activity-icon.type-bike { background: var(--bike-tint); }
.activity-icon .sport-icon { width: 76%; height: 76%; vertical-align: 0; }

/* The athlete's figures inline with text — chips, headings, table cells —
   sized to the text around them. */
.sport-icon {
  display: inline-block;
  width: 1.35em;
  height: 1.35em;
  object-fit: contain;
  vertical-align: -.32em;
}
.feed-heading { display: block; min-width: 0; flex: 1; }
.feed-title {
  display: block;
  font-weight: 700;
  font-size: .97rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.feed-sub {
  display: block;
  color: var(--muted);
  font-size: .76rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feed-stats { display: flex; gap: 16px; min-width: 0; }
.feed-stat { display: block; }
.feed-stat b { display: block; font-size: 1.12rem; font-weight: 700; letter-spacing: -.02em; }
.feed-stat span {
  font-size: .64rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
}
.route-thumb {
  position: relative;
  display: block;
  flex: none;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface-2);
}
.route-thumb img { position: absolute; max-width: none; }
.route-thumb svg { position: absolute; inset: 0; width: 100%; height: 100%; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: var(--surface-2);
  color: var(--ink-2);
}
.pill-pr { background: rgba(252, 76, 2, .13); color: #b03604; }

/* --- Tables (splits, records, gear) --------------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th {
  text-align: left;
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 800;
  padding: 7px 8px 7px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 9px 8px 9px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.split-bar {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: var(--accent);
  opacity: .8;
  min-width: 3px;
}

/* --- Charts (CSS bars, no library) ---------------------------------------- */
.chart { display: flex; align-items: flex-end; gap: 4px; height: 150px; padding-top: 6px; }
.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.chart-bar {
  width: 100%;
  max-width: 30px;
  background: var(--accent);
  border-radius: 4px 4px 2px 2px;
  min-height: 2px;
}
.chart-bar.is-empty { background: var(--surface-2); }
.chart-label {
  font-size: .6rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.chart-value { font-size: .62rem; font-weight: 700; color: var(--ink-2); }

/* --- Goals ---------------------------------------------------------------- */
.goal { padding: 11px 0; border-bottom: 1px solid var(--line); }
.goal:first-child { padding-top: 0; }
.goal:last-child { border-bottom: 0; padding-bottom: 0; }
.goal-head { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; margin-bottom: 7px; }
.goal-label { font-weight: 700; font-size: .9rem; }
.goal-numbers { font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.progress.is-complete span { background: var(--good); }

/* --- Menu rows (the You tab) ---------------------------------------------- */
.menu { background: var(--surface); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.menu-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  min-height: 56px;
}
.menu-row:last-child { border-bottom: 0; }
.menu-row:active { background: var(--surface-2); }
.menu-icon {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  flex: none;
}
.menu-text { flex: 1; min-width: 0; }
.menu-text strong { display: block; font-size: .93rem; font-weight: 650; }
.menu-text small { color: var(--muted); font-size: .76rem; }
.menu-chevron { color: var(--muted); font-size: 1.2rem; }

.profile-head { display: flex; align-items: center; gap: 13px; }
.avatar {
  width: 54px; height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 1.3rem;
  flex: none;
}

/* --- Map ------------------------------------------------------------------ */
.map { height: 240px; border-radius: 10px; overflow: hidden; background: var(--surface-2); }

/* --- Live recording screen (spec §5, §6) -----------------------------------
   A map filling the viewport with the numbers on a card over it. The screen
   is chrome-free: no top bar, no tab bar, nothing but the map and the three
   numbers that matter while moving.
   --------------------------------------------------------------------------- */
.rec {
  position: fixed;
  inset: 0;
  max-width: var(--phone);
  margin: 0 auto;
  background: var(--surface-2);
  z-index: 60;
}
.rec-map { position: absolute; inset: 0; }

.rec-fab {
  position: absolute;
  width: 44px; height: 44px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .22);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  z-index: 500;
}
.rec-fab svg { width: 21px; height: 21px; }
.rec-fab:active { background: var(--surface-2); }
/* Top right, framed — where the athlete asked for it. */
.rec-close {
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  border: 2px solid #d3d6da;
}
.rec-close svg { width: 18px; height: 18px; }

/* Map tools stacked on the right, clear above the stats card. */
.rec-tools {
  position: absolute;
  right: 14px;
  bottom: calc(322px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 500;
}
.rec-tools .rec-fab { position: static; }
.rec-calibrate.is-armed { background: var(--accent); color: #fff; }
.rec-calibrate.is-set { color: var(--accent); }

.rec-panel {
  position: absolute;
  left: 12px; right: 12px;
  bottom: calc(176px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 16px;
  padding: 11px 14px 9px;
  box-shadow: 0 6px 24px -8px rgba(16, 24, 40, .35);
  z-index: 500;
}
.rec-panel-head { position: relative; text-align: center; margin-bottom: 8px; }
.rec-panel-title { font-weight: 700; font-size: .92rem; color: #4b5058; }
.rec-expand {
  position: absolute; right: -6px; top: -6px;
  width: 32px; height: 32px;
  border: 0; background: none; padding: 0;
  display: grid; place-items: center;
  color: var(--ink);
  cursor: pointer;
}
.rec-expand svg { width: 18px; height: 18px; }
.rec-stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.rec-stats b {
  display: block;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.rec-stats span { font-size: .68rem; color: var(--muted); font-weight: 600; }
.rec-status {
  text-align: center;
  font-size: .64rem;
  color: var(--muted);
  margin-top: 7px;
  min-height: 1.1em;
}
.rec-status.is-warn { color: #b45309; }

/* Bigger numbers: the card takes the screen above the dock, stats stacked. */
.rec.is-expanded .rec-panel {
  top: calc(70px + env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-radius: 20px;
}
.rec.is-expanded .rec-stats { grid-template-columns: 1fr; row-gap: 26px; }
.rec.is-expanded .rec-stats b { font-size: 3.4rem; }
.rec.is-expanded .rec-stats span { font-size: .85rem; }
.rec.is-expanded .rec-panel-head { position: absolute; left: 14px; right: 14px; top: 14px; }
.rec.is-expanded .rec-tools { display: none; }

/* --- dock: a sheet with a grab handle and three labelled circles --------- */
.rec-dock {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 500;
  background: #f4f6f8;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -2px 14px rgba(0, 0, 0, .1);
  padding: 9px 20px calc(16px + env(safe-area-inset-bottom));
}
.rec-handle { width: 38px; height: 5px; border-radius: 3px; background: #c9ccd1; margin: 0 auto 14px; }
.rec-row { display: flex; align-items: flex-start; justify-content: space-between; }
.rec-item {
  width: 86px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-size: .82rem;
  font-weight: 600;
  color: #333;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.rec-circle {
  position: relative;
  width: 58px; height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e6e8eb;
  color: var(--ink);
}
.rec-circle svg { width: 25px; height: 25px; }
.rec-item:active .rec-circle { filter: brightness(.94); }
.rec-fig { width: 72%; height: 72%; object-fit: contain; }

.rec-sport.type-walk { background: var(--walk-tint); }
.rec-sport.type-run { background: var(--run-tint); }
.rec-sport.type-bike { background: var(--bike-tint); }
.rec-badge {
  position: absolute; top: -3px; right: -3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2.5px solid #f4f6f8;
  display: grid; place-items: center;
  color: #fff;
  background: var(--run-fig);
}
.rec-badge svg { width: 11px; height: 11px; }
.rec-sport.type-walk .rec-badge { background: var(--walk-fig); }
.rec-sport.type-bike .rec-badge { background: var(--bike-fig); }

.rec-go {
  width: 74px; height: 74px;
  margin-top: -8px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px -6px rgba(252, 76, 2, .75);
}
.rec-go svg { width: 30px; height: 30px; }
.rec-main .rec-label { color: var(--accent); font-weight: 800; }
.rec-when-paused { display: none; }
#btnPause.is-paused .rec-when-running { display: none; }
#btnPause.is-paused .rec-when-paused { display: grid; }
.rec-when-running, .rec-when-paused { place-items: center; }
.rec-when-running { display: grid; }
.rec-finish { background: #fff; border: 2px solid #f0caca; color: var(--bad); }
.rec-finish svg { width: 19px; height: 19px; }

/* --- Choose a sport ------------------------------------------------------ */
.rec-sheet-wrap {
  position: absolute;
  inset: 0;
  z-index: 3000;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: flex-end;
}
.rec-sheet {
  width: 100%;
  background: #f4f6f8;
  border-radius: 22px 22px 0 0;
  padding: 9px 0 calc(24px + env(safe-area-inset-bottom));
}
.rec-sheet .rec-handle { margin-bottom: 10px; }
.rec-sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px 12px;
  border-bottom: 1px solid var(--line);
}
.rec-sheet-head h2 { margin: 0; font-size: 1.25rem; font-weight: 800; }
.rec-sheet-close { border: 0; background: none; padding: 4px; color: var(--ink); cursor: pointer; }
.rec-sheet-close svg { width: 22px; height: 22px; display: block; }
.rec-sheet-group { padding: 14px 20px 2px; }
.rec-sheet-group + .rec-sheet-group { border-top: 1px solid var(--line); }
.rec-sheet-group h3 { margin: 0 0 2px; font-size: .95rem; font-weight: 800; }
.rec-opt {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.rec-opt-icon { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.rec-opt-icon.type-walk { background: var(--walk-tint); }
.rec-opt-icon.type-run { background: var(--run-tint); }
.rec-opt-icon.type-bike { background: var(--bike-tint); }
.rec-tick { margin-left: auto; width: 24px; height: 24px; display: none; }
.rec-tick svg { width: 24px; height: 24px; display: block; }
.rec-opt.is-active { font-weight: 700; }
.rec-opt.is-active .rec-tick { display: block; }
.rec-opt.is-active[data-type="walk"] { color: var(--walk-fig); }
.rec-opt.is-active[data-type="run"] { color: var(--run-fig); }
.rec-opt.is-active[data-type="bike"] { color: var(--bike-fig); }

/* --- Auth screens --------------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; }
.auth-brand { text-align: center; font-size: 1.5rem; font-weight: 800; margin-bottom: 4px; letter-spacing: -.02em; }
.auth-brand span { color: var(--accent); }
.auth-tag { text-align: center; color: var(--muted); font-size: .86rem; margin-bottom: 18px; }
.auth-alt { text-align: center; font-size: .85rem; color: var(--muted); margin-top: 14px; }
.auth-alt a { color: var(--accent); font-weight: 700; }

/* --- Bottom tab bar ------------------------------------------------------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--phone);
  display: flex;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 40;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tabbar);
  color: var(--muted);
  font-size: .68rem;
  font-weight: 700;
}
.tab-icon { font-size: 1.35rem; line-height: 1; }
.tab.is-active { color: var(--accent); }
.tab-primary .tab-icon {
  background: var(--accent);
  color: #fff;
  width: 50px; height: 50px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin-top: -20px;
  box-shadow: 0 6px 14px -4px rgba(252, 76, 2, .65);
}
.tab-primary.is-active .tab-icon { color: #fff; }

.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }
.stack > * + * { margin-top: 9px; }

/* --- Training: workout rows (spec §20, §21) -------------------------------- */
.workout {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.workout:last-child { border-bottom: 0; padding-bottom: 0; }
.workout.is-rest { opacity: .5; }
.workout.is-missed .workout-title { color: var(--bad); }
.workout.is-skipped { opacity: .55; }

.workout-day {
  width: 34px;
  flex: none;
  text-align: center;
  line-height: 1.15;
}
.workout-day span {
  display: block;
  font-size: .62rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 800;
  color: var(--muted);
}
.workout-day b { font-size: 1.05rem; font-weight: 700; }

.workout-main { flex: 1; min-width: 0; }
.workout-title { font-weight: 650; font-size: .92rem; }
.workout-sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.workout-done {
  display: block;
  margin-top: 4px;
  font-size: .78rem;
  font-weight: 650;
  color: var(--good);
}
.workout-actions { display: flex; gap: 5px; flex: none; }
.workout-actions .btn { min-width: 38px; padding: 5px 8px; }

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: .64rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: var(--surface-2);
  color: var(--ink-2);
  margin-right: 4px;
}
.tag-long { background: rgba(37, 99, 235, .13); color: #1d4ed8; }
.tag-intervals { background: rgba(252, 76, 2, .13); color: #b03604; }
.tag-tempo { background: rgba(217, 119, 6, .15); color: #92400e; }
.tag-race { background: var(--ink); color: #fff; }
.tag-recovery, .tag-easy { background: rgba(18, 161, 80, .13); color: #0f7038; }

/* --- Training calendar ----------------------------------------------------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-head div {
  text-align: center;
  font-size: .62rem;
  font-weight: 800;
  color: var(--muted);
  padding-bottom: 4px;
}
.cal-day {
  aspect-ratio: 1;
  border-radius: 9px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: .82rem;
  font-weight: 600;
}
.cal-day.is-outside { opacity: .35; }
.cal-day.is-today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day.is-selected { background: var(--ink); color: #fff; }
.cal-dots { display: flex; gap: 2px; height: 6px; align-items: center; }
.dot { width: 5px; height: 5px; border-radius: 50%; display: inline-block; }
.dot-done { background: var(--good); }
.dot-planned { background: var(--muted); }
.dot-missed { background: var(--bad); }
.cal-legend {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-top: 12px;
  font-size: .72rem;
  color: var(--muted);
}
.cal-legend span { display: flex; align-items: center; gap: 5px; }

/* --- Leaderboard (spec §25) ------------------------------------------------ */
.board-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.board-row:last-child { border-bottom: 0; }
.board-row.is-you {
  background: rgba(252, 76, 2, .07);
  margin: 0 -14px;
  padding-left: 14px;
  padding-right: 14px;
  border-radius: 8px;
}
.board-rank {
  width: 26px;
  flex: none;
  text-align: center;
  font-weight: 800;
  font-size: .9rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.board-row:nth-child(1) .board-rank { color: #b8860b; }
.board-name {
  flex: 1;
  min-width: 0;
  font-weight: 650;
  font-size: .92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-name small { font-weight: 500; margin-left: 4px; }
.board-value { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Social (spec §26) ----------------------------------------------------- */
.feed-link { display: block; }
.feed-author {
  display: block;
  font-size: .74rem;
  font-weight: 800;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.feed-social {
  display: flex;
  gap: 6px;
  margin: 10px -4px -2px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}
.social-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 4px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .84rem;
  font-weight: 700;
  cursor: pointer;
}
.social-btn:active { background: var(--surface-2); }
.social-btn.is-on { color: var(--accent); }

.comment {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.comment:last-child { border-bottom: 0; }
.comment-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  font-weight: 800;
  font-size: .8rem;
  flex: none;
}
.comment-main { flex: 1; min-width: 0; }
.comment-who { font-size: .82rem; font-weight: 700; }
.comment-who small { color: var(--muted); font-weight: 500; margin-left: 5px; }
.comment-body { font-size: .9rem; overflow-wrap: anywhere; }

.athlete-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.athlete-row:last-child { border-bottom: 0; }
.athlete-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  flex: none;
}
.athlete-main { flex: 1; min-width: 0; }
.athlete-main strong { display: block; font-size: .93rem; }
.athlete-main small { color: var(--muted); font-size: .78rem; }
.athlete-actions { display: flex; gap: 6px; flex: none; }

/* --- Import results (spec §33) --------------------------------------------- */
.import-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.import-row:last-child { border-bottom: 0; }
.import-mark {
  width: 26px; height: 26px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: .8rem;
  background: var(--surface-2);
  color: var(--ink-2);
}
.import-row.is-activity .import-mark { background: rgba(18, 161, 80, .15); color: #0f7038; }
.import-row.is-route .import-mark { background: rgba(37, 99, 235, .13); color: #1d4ed8; }
.import-row.is-error .import-mark { background: rgba(220, 38, 38, .12); color: var(--bad); }
.import-main { flex: 1; min-width: 0; }
.import-main a { color: var(--accent); }
input[type=file] {
  width: 100%;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--surface);
  font: inherit;
  font-size: .88rem;
}

/* --- Route builder (spec §23) ---------------------------------------------- */
.builder-map {
  height: 340px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: crosshair;
}
.builder-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 12px;
}
.builder-actions { margin-left: auto; display: flex; gap: 6px; }

/* --- Recorder: escape hatch and save sheet --------------------------------- */
.live-close {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  left: 10px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
  color: #cfd6de;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.live-close:active { background: rgba(255, 255, 255, .16); }

/* Sits over the live screen rather than replacing it, so a half-finished
   activity is never one navigation away from being lost. */
.sheet-wrap {
  position: fixed;
  inset: 0;
  max-width: var(--phone);
  margin: 0 auto;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  background: rgba(6, 8, 11, .72);
  backdrop-filter: blur(3px);
}
.sheet {
  width: 100%;
  background: #161b21;
  color: #fff;
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
}
.sheet h2 { font-size: 1.15rem; margin-bottom: 6px; }
.sheet-summary { color: #9aa4b0; font-size: .86rem; margin-bottom: 16px; line-height: 1.4; }
.sheet .field label { color: #8b95a1; }
.sheet .field input, .sheet .field select, .sheet .field textarea {
  background: #0f141a;
  border-color: #262d36;
  color: #fff;
}
/* The save sheet's buttons. Defined here rather than with the recorder,
   because the sheet is the only thing that still uses them. */
.live-btn {
  min-height: 56px;
  border-radius: 14px;
  border: 0;
  font: inherit;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}
.live-btn.secondary { background: #1c232b; color: #cfd6de; }
.sheet .live-btn { width: 100%; margin-top: 9px; }
.live-btn.ghost { background: transparent; color: #8b95a1; }

/* --- Brand ----------------------------------------------------------------- */
.auth-logo {
  display: block;
  margin: 0 auto 12px;
  width: 132px;
  max-width: 42%;
  height: auto;
  border-radius: 22.3%;    /* the iOS squircle, so it matches the home screen */
}

/* --- Dashboard banner ------------------------------------------------------ */
.dash-photo {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05);
}

/* --- Dashboard weather (spec §29) ------------------------------------------ */
.weather {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 11px 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .05);
}
.weather-icon { font-size: 1.5rem; line-height: 1; flex: none; }
.weather-main { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: .45rem; }
.weather-temp { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.weather-desc { font-size: .84rem; color: var(--ink-2); }
.weather-meta {
  font-size: .72rem;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --- Weather forecast row --------------------------------------------------- */
.weather { display: block; }
.weather-now { display: flex; align-items: center; gap: 11px; }
.weather-forecast {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}
.wf-day { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.wf-name {
  font-size: .64rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.wf-icon { font-size: 1.05rem; line-height: 1.2; }
.wf-high { font-size: .82rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.wf-low { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.weather-ask { margin: 0; }

.map-credit {
  font-size: .66rem;
  color: var(--muted);
  text-align: center;
  margin: 14px 0 0;
}
.map-credit a { text-decoration: underline; }


/* --- pocket mode --------------------------------------------------------- */

/* An iPhone suspends a web page when the screen LOCKS, and geolocation stops
   with it. The screen must therefore stay awake for the whole activity, which
   leaves the opposite problem: a bright, touch-live screen in a pocket. This
   covers it in black and eats every touch. On an OLED phone black pixels are
   switched off, so the cost is far closer to a sleeping screen than a lit one. */
.rec-blackout {
  position: fixed;
  inset: 0;
  z-index: 4000;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
/* The lead has to beat a lifetime of habit — reaching for the side button is
   automatic, and it is the one thing that kills the recording — so it is bright
   and large for the few seconds anyone is looking. The rest stays dim, and all
   of it fades to black so the screen costs nothing in a pocket. */
.rec-blackout-hint {
  margin: 0;
  padding: 0 34px;
  text-align: center;
  transition: opacity 1.4s ease;
}
.rec-blackout-hint b {
  display: block;
  margin-bottom: 10px;
  color: #d8d8d8;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.4;
}
.rec-blackout-hint span {
  display: block;
  color: #5a5a5a;
  font-size: .82rem;
  line-height: 1.7;
}
.rec-blackout.is-alarm .rec-blackout-hint b { color: #ff9d6b; }
.rec-blackout.is-dim .rec-blackout-hint { opacity: 0; }

/* Fills over the hold, so a deliberate press reads as progress and a pocket
   brush reads as nothing. */
.rec-blackout-hold {
  position: absolute;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: 132px;
  height: 3px;
  border-radius: 2px;
  background: #1c1c1c;
  opacity: 0;
  transition: opacity .2s ease;
}
.rec-blackout-hold i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 2px;
  background: #7a7a7a;
}
.rec-blackout.is-holding .rec-blackout-hold { opacity: 1; }
.rec-blackout.is-holding .rec-blackout-hold i { width: 100%; transition: width 1.6s linear; }

/* Map credit on the recorder: required by the tile licence, and nothing more
   than that. Top-left is the only corner not under a control or the panel. */
.rec .leaflet-top.leaflet-left { top: env(safe-area-inset-top); }
.rec .leaflet-control-attribution {
  margin: 6px 0 0 8px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .7);
  font-size: 9px;
  line-height: 1.5;
  color: #555;
}
.rec .leaflet-control-attribution a { color: inherit; }
