@font-face {
  font-family: "Montserrat";
  src: url("/fonts/montserrat.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #2b2e30;
  --muted: #5b6164;
  --paper: #f3f3f0;
  --surface: #ffffff;
  --line: #d3d5cf;
  --bar: #2b2e30;
  --bar-ink: #d9dcd6;
  --lime: #9ccf51;
  --lime-deep: #86b83c;
  --lime-wash: #e4f2cf;
  --lime-ink: #1d2a0c;
  --link: #3d6a10;
  --danger: #b3261e;
  --danger-wash: #fbe9e7;
  --warn: #7a5100;
  --warn-wash: #fbf1dc;
  --radius: 12px;
  --control: 10px;
  --tag: 6px;
  --rail: 32px;
  --gutter: clamp(16px, 3vw, 32px);
  /* One type scale: nothing under 14px. */
  --title: 28px;
  --section: 20px;
  --body: 16px;
  --detail: 14px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--body)/1.5 "Montserrat", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 3px solid var(--lime-deep); outline-offset: 2px; }

a { color: var(--link); text-underline-offset: 3px; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: var(--title); font-weight: 700; line-height: 1.2; margin-bottom: 16px; }
h2 { font-size: var(--section); font-weight: 700; line-height: 1.3; }
h3 { font-size: var(--body); font-weight: 700; }
[hidden] { display: none !important; }

/* Header and footer */
.bar { background: var(--bar); color: #fff; }
.bar-inner, .footer-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px var(--gutter);
}
.mark {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-size: var(--section);
  font-weight: 700;
  text-decoration: none;
  margin-right: 16px;
}
.mark img { border-radius: 8px; display: block; }
.bar nav { display: flex; gap: 24px; }
.bar nav a { color: var(--bar-ink); text-decoration: none; padding: 4px 0; border-bottom: 2px solid transparent; }
.bar nav a[aria-current] { color: #fff; font-weight: 700; border-bottom-color: var(--lime); }
.bar-link { color: #fff; margin-left: auto; font-size: var(--detail); }

.account-menu { margin-left: auto; position: relative; }
.account-menu summary {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--bar-ink);
  cursor: pointer;
  list-style: none;
}
.account-menu summary::-webkit-details-marker { display: none; }
.person-icon { width: 28px; height: 28px; }
.account-menu > div {
  position: absolute;
  right: 0;
  top: calc(100% + 12px);
  z-index: 20;
  min-width: 220px;
  padding: 8px;
  display: grid;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(38 41 43 / 0.16);
}
.account-heading { padding: 8px 12px; font-weight: 700; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.account-menu a, .account-menu form button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--control);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: var(--detail);
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  min-height: 0;
}
.account-menu a:hover, .account-menu form button:hover { background: var(--paper); }
.account-menu form { display: block; margin: 0; }

main { flex: 1; width: 100%; padding: 24px var(--gutter) 40px; }

footer { background: var(--bar); color: var(--bar-ink); font-size: var(--detail); }
.footer-inner { justify-content: space-between; flex-wrap: wrap; padding-block: 16px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 24px; }
.footer-links a { color: var(--bar-ink); text-decoration: none; }
.footer-links a:hover { color: #fff; }

/* Surfaces */
.panel, .sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 640px;
  display: grid;
  gap: 16px;
}
.panel + .panel { margin-top: 16px; }
.panel hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 0; }
.sheet { margin: 24px auto; max-width: 520px; }
.sheet h1 { margin-bottom: 0; }
main > .prose { max-width: 68ch; }
.prose { display: grid; gap: 12px; }
.prose h2 { margin-top: 12px; }
.lede { color: var(--ink); }
.note { color: var(--muted); font-size: var(--detail); }
.warning, .alert {
  padding: 12px 16px;
  border-radius: var(--control);
  background: var(--warn-wash);
  color: var(--warn);
}
.alert { background: var(--danger-wash); color: var(--danger); margin-bottom: 16px; max-width: 640px; }
.sheet .alert { margin-bottom: 0; }

/* Forms */
form { display: grid; gap: 16px; }
label { display: grid; gap: 4px; font-size: var(--detail); font-weight: 500; }
input, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--control);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--body);
}
input[readonly], textarea[readonly] { background: var(--paper); }
.consent { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; }
.consent input { width: auto; margin-top: 3px; }

button, .button {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 24px;
  border: 1px solid transparent;
  border-radius: var(--control);
  background: var(--lime);
  color: var(--lime-ink);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--lime-deep); }
button:disabled { cursor: default; }
button.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); border-radius: var(--control); }
button.secondary:hover { background: var(--paper); }
button.danger { background: var(--danger); color: #fff; }

/* Garmin section */
.connection { display: flex; align-items: center; gap: 16px; }
.connection img { border-radius: 14px; flex: none; }
.connection p { color: var(--muted); font-size: var(--detail); }
.tag {
  display: inline-block;
  padding: 2px 10px;
  margin-right: 8px;
  border-radius: var(--tag);
  font-weight: 700;
}
.tag-ok { background: var(--lime-wash); color: var(--lime-ink); }
.tag-warn { background: var(--warn-wash); color: var(--warn); }
.tag-busy { background: var(--paper); color: var(--muted); }

/* Return message */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: inset 4px 0 0 var(--lime);
  border-radius: var(--radius);
}
.banner p { flex: 1; }
.banner svg { width: 24px; height: 24px; display: block; color: var(--link); }
.banner a svg { color: var(--muted); }

/* Training */
.training-board > .note { margin-bottom: 16px; }
.week {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.weekday {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
  min-height: 132px;
  padding: 12px;
  border-right: 1px solid var(--line);
}
.weekday:last-child { border-right: 0; }
.weekday.today { box-shadow: inset 0 0 0 2px var(--lime-deep); }
.weekday.today:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.weekday.today:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.weekhead { font-weight: 700; }
.weekday.today .weekhead { justify-self: start; margin-left: -8px; padding: 0 8px; border-radius: var(--tag); background: var(--lime); color: var(--lime-ink); }
.weekshape { width: 100%; height: 40px; align-self: end; display: block; }
.restday { align-self: end; height: 40px; }
.distance { font-size: var(--detail); min-height: 21px; }
.done { position: absolute; right: 12px; bottom: 14px; width: 18px; height: 18px; color: var(--link); }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.training-range { position: relative; display: flex; align-items: center; gap: 12px; }
.range-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background: var(--surface);
}
.range-step[aria-disabled] { opacity: 0.4; }
.refresh { display: flex; }
.refresh .range-step { min-height: 0; padding: 0; }
.refresh .range-step:hover { background: var(--paper); }
.refresh-status { margin: -8px 0 16px; }
.chev { width: 20px; height: 20px; }
.period {
  min-height: 44px;
  padding: 0 4px;
  background: none;
  color: var(--ink);
  font-size: var(--section);
  font-weight: 700;
  border-radius: var(--control);
}
.period:hover { background: none; }
.now {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: var(--control);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--detail);
  text-decoration: none;
}
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--control); overflow: hidden; background: var(--surface); }
.segmented a { display: flex; align-items: center; justify-content: center; min-height: 42px; min-width: 88px; padding: 0 16px; color: var(--ink); text-decoration: none; }
.segmented .selected { background: var(--lime); color: var(--lime-ink); font-weight: 700; }

.month-picker {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 10;
  width: 300px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(38 41 43 / 0.16);
}
.picker-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.months a { padding: 8px; border-radius: var(--control); color: var(--ink); font-size: var(--detail); text-align: center; text-decoration: none; }
.months .selected { background: var(--lime); color: var(--lime-ink); font-weight: 700; }

.training-timeline { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 24px; }
.timeline-legend { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 4px 20px; font-size: var(--detail); }
.timeline-legend span { display: inline-flex; align-items: center; gap: 8px; }
.timeline-legend i { width: 16px; height: 16px; }
.l1 { background: #aec6e0; }
.l2 { background: #8dbf4e; }
.l3 { background: #e8a04a; }
.l4 { background: #cf4a43; }
.l5 { background: #d6d7d3; }

.section-label { color: var(--muted); padding-top: 12px; }
.day-section { position: relative; padding-left: var(--rail); }
.day-section::before { content: ""; position: absolute; left: 7px; top: 0; bottom: 0; width: 1px; background: var(--line); }
.daygroup + .daygroup { background: linear-gradient(var(--line), var(--line)) 0 0 / 100% 1px no-repeat; }
.day-section + .day-section {
  background: linear-gradient(var(--line), var(--line)) var(--rail) 0 / calc(100% - var(--rail)) 1px no-repeat;
}
.daygroup {
  position: relative;
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 16px;
  padding: 12px 0;
}
.daygroup::before { content: none; }
.daygroup::after { content: ""; position: absolute; left: calc(2px - var(--rail)); top: 34px; width: 11px; height: 11px; border-radius: 50%; background: #8a8e8c; }
.daygroup.today::after { background: var(--lime-deep); }
.daylabel { display: grid; align-content: start; }
.daylabel small { font-size: var(--detail); color: var(--muted); }
.daylabel strong { font-size: var(--section); }
.entry { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; }
.entry-text { display: grid; align-content: start; gap: 2px; }
.context, .coach-note, .step-label { font-size: var(--detail); color: var(--muted); }
.note-toggle { min-height: 0; padding: 0; background: none; color: var(--link); font-weight: 500; border-radius: 0; text-decoration: underline; font-size: var(--detail); }
.note-toggle:hover { background: none; }
.feedback-line { display: flex; align-items: center; gap: 8px; font-size: var(--detail); margin-top: 4px; }
.feedback-tag { color: var(--muted); }
.feedback-trigger {
  min-height: 32px;
  padding: 0;
  gap: 8px;
  background: none;
  color: var(--link);
  font-size: var(--detail);
  border-radius: var(--control);
}
.feedback-trigger:hover { background: none; text-decoration: underline; }
.feedback-trigger svg { width: 18px; height: 18px; }
.steps { display: block; width: 100%; height: 48px; }
.barline { stroke: var(--line); stroke-width: 1; }
.z1 { fill: #aec6e0; }
.z2 { fill: #8dbf4e; }
.z3 { fill: #e8a04a; }
.z4, .z5 { fill: #cf4a43; }
.recovery { fill: #d6d7d3; }
.empty { color: var(--muted); padding: 16px 0; }

/* Feedback */
.feedback-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  color: var(--ink);
}
.feedback-dialog::backdrop { background: rgb(38 41 43 / 0.55); }
.dialog-panel { padding: 24px; gap: 12px; }
.dialog-head { display: flex; justify-content: space-between; gap: 16px; }
.dialog-head h2 { font-size: var(--section); }
.dialog-workout { color: var(--muted); }
.draft-tag {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 10px;
  border-radius: var(--tag);
  background: var(--paper);
  font-size: var(--detail);
}
.dialog-close { align-self: flex-start; min-height: 40px; width: 40px; height: 40px; padding: 0; background: none; color: var(--ink); flex: none; }
.dialog-close:hover { background: var(--paper); }
.dialog-close svg { width: 24px; height: 24px; }
.metrics label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--body);
  font-weight: 400;
}
.metrics input { padding: 6px 10px; text-align: right; font-weight: 700; }
.garmin-notes { display: grid; gap: 4px; }
.garmin-notes h3 { margin: 0; font-size: var(--body); }
.garmin-notes p { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.comment { font-size: var(--body); font-weight: 700; }
.comment textarea { font-weight: 400; }
.feedback-notice { color: var(--muted); font-size: var(--detail); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; }

/* One training */
.card-line { display: none; }
.entry-link { color: inherit; text-decoration: none; }
.entry-link:hover { text-decoration: underline; }
.detail { max-width: 640px; display: grid; gap: 12px; }
.detail h1 { margin: 0; }
.detail-back { display: inline-flex; align-items: center; gap: 4px; justify-self: start; min-height: 44px; color: var(--ink); font-size: var(--detail); text-decoration: none; }
.detail-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
.detail-tabs a { padding: 10px; text-align: center; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.detail-tabs a[aria-current] { color: var(--ink); font-weight: 700; border-bottom-color: var(--lime-deep); }
.detail-date { color: var(--muted); }
.detail-note { white-space: pre-line; }
.step-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: var(--detail); }
.step-table td { padding: 10px 8px; border-top: 1px solid var(--line); }
.step-table tr:first-child td { border-top: 0; }
.step-zone { width: 40px; }
.step-amount, .step-heart { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip { display: inline-block; min-width: 24px; padding: 0 4px; border-radius: var(--tag); text-align: center; font-weight: 700; }
.chip.z1 { background: #aec6e0; }
.chip.z2 { background: #8dbf4e; }
.chip.z3 { background: #e8a04a; }
.chip.z4, .chip.z5 { background: #cf4a43; color: #fff; }
.chip.recovery { background: #d6d7d3; }
.detail-form { gap: 12px; }
.detail-form .draft-tag { justify-self: start; margin: 0; background: var(--surface); border: 1px solid var(--line); }
.detail-form .save { justify-self: stretch; }

/* Phone: the list is short, and one training opens on its own page */
@media (max-width: 720px) {
  .mark { font-size: 0; gap: 0; margin-right: 0; }
  .account-label { display: none; }
  main { padding-top: 12px; }
  .training-page > h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

  /* Week bar: wide cards that swipe, about 2.5 in view. */
  .week {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    margin: 0 calc(-1 * var(--gutter)) 8px;
    padding: 0 var(--gutter);
    gap: 8px;
    border: 0;
    border-radius: 0;
    background: none;
    scrollbar-width: none;
  }
  .weekday {
    flex: 0 0 38%;
    min-height: 0;
    padding: 8px 10px;
    gap: 2px;
    grid-template-rows: auto 24px auto;
    scroll-snap-align: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .weekday:last-child { border-right: 1px solid var(--line); }
  .weekday.today { outline: 0; border-color: var(--lime-deep); box-shadow: inset 0 0 0 1px var(--lime-deep); }
  .weekhead { font-size: var(--detail); }
  .weekday.today .weekhead { padding: 0 8px; }
  .weekshape { height: 24px; }
  .restday { height: 24px; border: 0; transform: none; }
  .done { right: 10px; bottom: 8px; }

  /* Filter and month in one row that stays while the list scrolls. */
  .panel-head {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-wrap: nowrap;
    gap: 4px;
    margin: 0 calc(-1 * var(--gutter)) 4px;
    padding: 8px var(--gutter);
    background: var(--paper);
    border-bottom: 1px solid var(--line);
  }
  .month-filter { order: -1; flex: none; }
  .month-filter a { min-width: 40px; min-height: 36px; padding: 0 4px; font-size: var(--detail); }
  .training-range { flex: 1; min-width: 0; justify-content: flex-end; gap: 0; }
  .range-step { width: 32px; height: 32px; flex: none; }
  .period { min-width: 0; min-height: 36px; padding: 0; font-size: var(--detail); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .now { display: none; }
  .refresh-status { margin: 4px 0 8px; }
  .month-picker { left: auto; right: 0; }

  /* One row: date, rail with one dot, card. */
  .training-timeline { padding: 0; background: none; border: 0; border-radius: 0; }
  .timeline-legend { display: none; }
  .day-section { padding-left: 0; }
  .day-section::before { content: none; }
  .day-section + .day-section, .daygroup + .daygroup { background: none; }
  .section-label { padding: 8px 0 2px; font-size: var(--detail); font-weight: 600; }
  .daygroup { grid-template-columns: 56px 16px minmax(0, 1fr); gap: 0; padding: 4px 0; }
  .daygroup + .daygroup { border-top: 0; }
  .daygroup::before { content: ""; position: absolute; top: 0; bottom: 0; width: 1px; left: 63px; background: var(--line); }
  .daygroup::after {
    left: 58px;
    top: 50%;
    margin-top: -6px;
    width: 12px;
    height: 12px;
    background: var(--paper);
    border: 2px solid var(--muted);
  }
  .daygroup.closed::after { background: var(--lime-deep); border-color: var(--lime-deep); }
  .daygroup.today::after { background: var(--paper); border-color: var(--lime-deep); }
  .daygroup.today.closed::after { background: var(--lime-deep); }
  .daylabel { align-content: center; justify-items: start; }
  .daylabel strong { order: -1; font-size: var(--detail); font-weight: 700; white-space: nowrap; }
  .daylabel small { color: var(--muted); }
  .daygroup.today .daylabel strong { color: var(--link); }
  .entry {
    grid-column: 3;
    position: relative;
    display: block;
    padding: 6px 10px 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .daygroup.past:not(.closed) .entry, .daygroup.today .entry { border-color: var(--lime-deep); }
  .entry-text { display: block; }
  .entry h3 { font-size: var(--detail); font-weight: 700; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .entry-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
  .card-line {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font-size: var(--detail);
    line-height: 1.3;
    color: var(--muted);
  }
  .context, .coach-note, .feedback-line, .step-label { display: none; }
  .steps { height: 6px; margin-top: 4px; }

  /* One training */
  .detail { gap: 8px; }
  .detail-tabs { margin: 0 calc(-1 * var(--gutter)); }
  .step-table td { padding: 8px 6px; }
  .metrics label { grid-template-columns: minmax(0, 1fr) 120px; padding: 6px 0; font-size: var(--detail); }
  .feedback-dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
}
