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

:root {
  --paper: #EEF2F3;
  --surface: #FFFFFF;
  --sunk: #E3E9EC;
  --ink: #17212B;
  --ink-2: #4E5C69;
  --ink-3: #7C8994;
  --line: #D3DCE0;
  --bib: #FCFCFA;
  --bib-ink: #17212B;

  --swim: #1C8BD9;
  --bike: #E39B12;
  --run: #E0533D;
  --brick: #C77428;
  --strength: #5B6B7F;
  --boxing: #B0306A;
  --walk: #5E9A63;
  --other: #8A949C;
  --rest: #A9B4BC;

  --done: #1F9D6B;
  --missed: #D14343;
  --excused: #8A949C;
  --amber: #D98E04;

  --display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --body: "Barlow", "Segoe UI", system-ui, -apple-system, sans-serif;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --tabbar-h: 62px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #142231;
    --surface: #1B2C3D;
    --sunk: #112030;
    --ink: #E6EDF1;
    --ink-2: #A3B4C1;
    --ink-3: #74889A;
    --line: #2A3F53;
    --swim: #3DA3EE;
    --bike: #F0AE2E;
    --run: #F06A55;
    --strength: #8496AD;
    --boxing: #D9558F;
    --done: #34B884;
    --missed: #EE6464;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.45 var(--body);
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--swim); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
body.signed-out .topbar .icon-btn, body.signed-out .page-title { visibility: hidden; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.brand { display: flex; align-items: center; gap: 7px; text-decoration: none; font: 800 22px/1 var(--display); letter-spacing: .01em; }
.page-title { margin: 0; font: 600 17px/1.2 var(--display); color: var(--ink-2); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: var(--ink-2); text-decoration: none; background: none; border: 0; cursor: pointer; }
.icon-btn:hover { background: var(--sunk); }

main { max-width: 680px; margin: 0 auto; padding: 8px 16px 24px; outline: none; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--ink-3); font-size: 12px; font-weight: 500; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--ink); }
.tabbar a.active svg { stroke-width: 2.3; }

.fab {
  position: fixed; z-index: 31; right: max(16px, calc(50% - 324px));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  width: 56px; height: 56px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--ink); color: var(--paper);
  box-shadow: 0 6px 18px rgba(16, 32, 48, .28);
  display: grid; place-items: center;
}
.fab:active { transform: scale(.96); }

/* sections */
.section { margin-top: 26px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h2 { margin: 0; font: 700 22px/1.1 var(--display); }
.section-head a, .link-btn { font-size: 14px; font-weight: 600; color: var(--swim); text-decoration: none; background: none; border: 0; padding: 4px 0; cursor: pointer; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.tiny { font-size: 12.5px; color: var(--ink-3); }
.panel { background: var(--surface); border-radius: var(--r-md); padding: 14px 16px; }
.panel + .panel { margin-top: 10px; }

/* race bib: the one bold element */
.bib {
  position: relative; margin-top: 6px;
  background: var(--bib); color: var(--bib-ink);
  border-radius: 6px; padding: 16px 22px 0; overflow: hidden;
  box-shadow: 0 1px 0 rgba(0,0,0,.06), 0 10px 26px -14px rgba(16, 32, 48, .45);
  text-decoration: none; display: block;
}
.bib::before, .bib::after, .bib .pin-b::before, .bib .pin-b::after {
  content: ""; position: absolute; width: 11px; height: 11px; border-radius: 50%;
  background: var(--paper); box-shadow: inset 0 1.5px 2px rgba(0,0,0,.28);
}
.bib::before { top: 10px; left: 10px; }
.bib::after { top: 10px; right: 10px; }
.bib .pin-b::before { bottom: 18px; left: 10px; }
.bib .pin-b::after { bottom: 18px; right: 10px; }
.bib-race { font: 700 16px/1.2 var(--display); text-align: center; padding: 0 18px; }
.bib-number { font: 800 clamp(84px, 30vw, 132px)/.9 var(--display); text-align: center; letter-spacing: -.02em; margin: 6px 0 2px; }
.bib-sub { text-align: center; font-size: 14px; color: #4E5C69; padding-bottom: 14px; }
.bib-stripe { display: grid; grid-template-columns: 1fr 1fr 1fr; height: 10px; margin: 0 -22px; }
.bib-stripe i:nth-child(1) { background: #1C8BD9; }
.bib-stripe i:nth-child(2) { background: #E39B12; }
.bib-stripe i:nth-child(3) { background: #E0533D; }
.bib.empty .bib-number { font-size: 56px; padding: 10px 0 4px; }

/* lane rows: plan items and activity cards */
.lane-list { display: flex; flex-direction: column; gap: 8px; }
.lane {
  position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px;
  background: var(--surface); border-radius: var(--r-md); padding: 12px 12px 12px 18px; min-height: 60px;
}
.lane::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; border-radius: var(--r-md) 0 0 var(--r-md); background: var(--c); }
.lane.brick::before, .t-brick.lane::before { background: linear-gradient(var(--bike) 50%, var(--run) 50%); }
.lane-main { min-width: 0; cursor: pointer; }
.lane-title { font-weight: 600; line-height: 1.25; }
.lane-meta { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.lane.is-done .lane-title { color: var(--ink-2); }
.lane.is-missed { background: color-mix(in srgb, var(--missed) 7%, var(--surface)); }
.lane.is-rest { background: transparent; border: 1px dashed var(--line); }
.lane.is-rest::before { display: none; }
.lane-actions { display: flex; align-items: center; gap: 4px; }

.card, .lane { --c: var(--other); }
.t-swim { --c: var(--swim); } .t-bike { --c: var(--bike); } .t-run { --c: var(--run); }
.t-brick { --c: var(--brick); } .t-strength { --c: var(--strength); } .t-boxing { --c: var(--boxing); }
.t-walk { --c: var(--walk); } .t-other { --c: var(--other); } .t-rest { --c: var(--rest); }

.check {
  width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); background: transparent;
  display: grid; place-items: center; cursor: pointer; flex: none; color: transparent;
}
.check svg { width: 18px; height: 18px; }
.check.done { background: var(--done); border-color: var(--done); color: #fff; }
.check.missed { border-color: var(--missed); color: var(--missed); }
.check.excused { border-color: var(--excused); color: var(--excused); border-style: dashed; }
.more { width: 32px; height: 36px; border: 0; background: none; color: var(--ink-3); cursor: pointer; border-radius: 8px; font-size: 20px; line-height: 1; }
.more:hover { background: var(--sunk); }

.status-tag { font-size: 12.5px; font-weight: 600; }
.status-tag.missed { color: var(--missed); }
.status-tag.excused { color: var(--excused); }
.status-tag.done { color: var(--done); }

/* week strip */
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day-cell { text-align: center; padding: 8px 0 10px; border-radius: var(--r-sm); background: var(--surface); text-decoration: none; }
.day-cell.today { outline: 2px solid var(--ink); outline-offset: -2px; }
.day-cell b { display: block; font: 700 15px/1 var(--display); }
.day-cell small { display: block; font-size: 11.5px; color: var(--ink-3); margin-bottom: 6px; }
.dots { display: flex; justify-content: center; flex-wrap: wrap; gap: 3px; padding: 0 3px; min-height: 9px; }
.dot { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--c); }
.dot.done { background: var(--c); }
.dot.missed { border-color: var(--missed); background: transparent; position: relative; }
.dot.missed::after { content: ""; position: absolute; inset: 1px; background: var(--missed); border-radius: 50%; transform: scale(.4); }
.dot.excused { border-style: dashed; opacity: .6; }

/* figures */
.figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-radius: var(--r-md); overflow: hidden; }
.figures.four { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 560px) { .figures.four { grid-template-columns: repeat(4, 1fr); } }
.figure { background: var(--surface); padding: 12px 12px 10px; min-width: 0; }
.figure .v { font: 700 26px/1 var(--display); }
.figure .v small { font: 600 15px var(--display); color: var(--ink-2); margin-left: 2px; }
.figure .l { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.figure.c-swim .v { color: var(--swim); } .figure.c-bike .v { color: var(--bike); } .figure.c-run .v { color: var(--run); }

.bar-row { display: grid; grid-template-columns: 82px 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.bar-row + .bar-row { margin-top: 10px; }
.bar { height: 8px; border-radius: 4px; background: var(--sunk); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--c, var(--ink)); border-radius: 4px; max-width: 100%; }
.bar.over i { background: var(--amber); }

.readiness { display: grid; grid-template-columns: 14px 1fr; gap: 12px; align-items: start; }
.readiness .light { width: 14px; height: 14px; border-radius: 50%; margin-top: 4px; }
.light.green { background: var(--done); } .light.amber { background: var(--amber); } .light.red { background: var(--missed); }

/* activity feed */
.feed { display: flex; flex-direction: column; gap: 10px; }
.card {
  position: relative; display: block; text-decoration: none; background: var(--surface);
  border-radius: var(--r-md); padding: 14px 16px 14px 20px; overflow: hidden;
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--c); }
.card.t-brick::before { background: linear-gradient(var(--bike) 50%, var(--run) 50%); }
.card-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.card-title { font: 700 19px/1.15 var(--display); }
.card-when { font-size: 13px; color: var(--ink-3); white-space: nowrap; }
.card-stats { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 8px; }
.card-stats div { min-width: 60px; }
.card-stats b { display: block; font: 700 19px/1.1 var(--display); }
.card-stats span { font-size: 12.5px; color: var(--ink-3); }
.route-preview { display: block; width: 100%; height: 86px; margin-top: 10px; background: var(--sunk); border-radius: var(--r-sm); }
.route-preview polyline { fill: none; stroke: var(--c); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 13px; font-size: 14px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.chip .sw { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* detail */
.detail-head { margin-top: 8px; }
.detail-head h2 { margin: 0; font: 800 32px/1.05 var(--display); }
.detail-head .tag { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); margin-top: 6px; }
.detail-head .tag i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.map { height: 260px; border-radius: var(--r-md); overflow: hidden; margin-top: 14px; background: var(--sunk); z-index: 0; }
.chart-box { position: relative; height: 220px; background: var(--surface); border-radius: var(--r-md); padding: 10px 8px 6px; }
.chart-box.tall { height: 260px; }
.chart-box.short { height: 170px; }

table.data { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.data th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: 12.5px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.data td { padding: 8px; border-bottom: 1px solid var(--line); }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; }
.table-wrap { background: var(--surface); border-radius: var(--r-md); padding: 4px 8px; overflow-x: auto; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--sunk); }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.field label, .field .label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
.field .hint { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: var(--r-sm);
  border: 1.5px solid var(--line); background: var(--surface); font-size: 16px;
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { border-color: var(--swim); outline: none; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.unit-input { position: relative; }
.unit-input .input { padding-right: 44px; }
.unit-input span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 14px; color: var(--ink-3); pointer-events: none; }
.hms { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.rpe { display: flex; align-items: center; gap: 12px; }
.rpe input[type=range] { flex: 1; accent-color: var(--ink); height: 32px; }
.rpe output { font: 700 22px/1 var(--display); min-width: 30px; text-align: center; }
.rpe-word { font-size: 13px; color: var(--ink-2); min-height: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1.5px solid var(--ink);
  background: var(--ink); color: var(--paper); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--missed); border-color: color-mix(in srgb, var(--missed) 40%, transparent); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

.exercise { background: var(--sunk); border-radius: var(--r-md); padding: 10px; }
.exercise + .exercise { margin-top: 10px; }
.exercise-head { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.set-row { display: grid; grid-template-columns: 26px 1fr 1fr 32px; gap: 8px; align-items: center; margin-top: 8px; }
.set-row .n { font: 700 16px var(--display); color: var(--ink-3); text-align: center; }
.set-row .input { min-height: 42px; }
.x-btn { width: 32px; height: 32px; border-radius: 8px; border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 18px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--sunk); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; font-weight: 600; font-size: 14.5px; cursor: pointer; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(10, 20, 30, .42); }
.sheet {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 680px;
  max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper); border-radius: 20px 20px 0 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 22px);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-grip { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 14px; font: 700 24px/1.1 var(--display); }
.menu { display: flex; flex-direction: column; gap: 6px; }
.menu button, .menu a {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  padding: 13px 14px; border-radius: 12px; border: 0; background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none;
}
.menu .sw { width: 12px; height: 12px; border-radius: 4px; background: var(--c); flex: none; }
.menu small { display: block; font-weight: 400; color: var(--ink-2); font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 84px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-weight: 500; font-size: 15px;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--missed); color: #fff; }

.empty { text-align: center; padding: 28px 16px; color: var(--ink-2); background: var(--surface); border-radius: var(--r-md); }
.empty p { margin: 0 0 12px; }

.kpi-board { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--ink); color: var(--paper); border-radius: var(--r-md); overflow: hidden; }
.kpi-board div { padding: 14px 8px 12px; text-align: center; border-left: 1px solid color-mix(in srgb, var(--paper) 15%, transparent); }
.kpi-board div:first-child { border-left: 0; }
.kpi-board b { display: block; font: 800 30px/1 var(--display); }
.kpi-board span { font-size: 12.5px; opacity: .78; }

.week-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.week-nav button { width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; font-size: 18px; }
.week-nav b { font: 700 19px var(--display); }
.day-block + .day-block { margin-top: 16px; }
.day-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.day-label b { font: 700 17px var(--display); }
.day-label.today b::after { content: "Today"; margin-left: 8px; font: 600 12px var(--body); background: var(--ink); color: var(--paper); padding: 2px 7px; border-radius: 6px; vertical-align: 2px; }

.tmpl-item { background: var(--surface); border-radius: var(--r-md); padding: 10px; display: grid; gap: 8px; }
.tmpl-item + .tmpl-item { margin-top: 8px; }
.tmpl-grid { display: grid; grid-template-columns: 92px 1fr 32px; gap: 8px; align-items: center; }
.tmpl-grid2 { display: grid; grid-template-columns: 1fr 92px; gap: 8px; }

.login { min-height: 80vh; display: grid; place-items: center; }
.login .panel { width: 100%; max-width: 380px; padding: 26px 22px; }
.login h2 { font: 800 34px/1 var(--display); margin: 0 0 4px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.records li { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.records { list-style: none; margin: 0; padding: 0 14px; background: var(--surface); border-radius: var(--r-md); }
.records li:last-child { border-bottom: 0; }
.records b { font: 700 18px var(--display); }
.records a { text-decoration: none; }

.loading { padding: 40px 0; text-align: center; color: var(--ink-3); }
.spacer { height: 10px; }

@media (min-width: 720px) {
  .tabbar { left: 50%; transform: translateX(-50%); max-width: 680px; border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
