/* Breakpoints (kept consistent, referenced in comments since custom
   properties can't drive @media conditions): 480 / 768 / 1024 / 1280 */

:root {
  --color-bg: #ffffff;
  --color-bg-alt: #f5f5f4;
  --color-bg-dark: #1c1917;
  --color-text: #1c1917;
  --color-text-muted: #57534e;
  --color-text-on-dark: #f5f5f4;
  --color-text-on-dark-muted: #d6d3d1;
  --color-border: #e7e5e4;
  --color-primary: #9a3412;
  --color-primary-strong: #7c2d12;
  --color-accent: #0f766e;

  /* Sequential ramp (rust, light->dark) for the calendar heatmap --
     same hue as --color-primary so it reads as one brand */
  --heatmap-0: #f6f4f4;
  --heatmap-1: #f4cbbe;
  --heatmap-2: #eb8f70;
  --heatmap-3: #e34e1c;
  --heatmap-4: #9c3411;

  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --space-5: 4rem;

  --radius: 0.75rem;
  --max-width: 75rem;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

/* The [hidden] attribute must win over any component's own `display`
   rule (flex/grid/etc.), or a "hidden" field silently stays visible --
   same specificity, later author rule wins otherwise. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}

h1, h2, h3 {
  line-height: 1.2;
  margin: 0 0 var(--space-2);
}

p {
  margin: 0 0 var(--space-2);
}

a {
  color: var(--color-primary);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.wrap {
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--space-2);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-accent);
  margin-bottom: var(--space-1);
}

/* Buttons — min 44px tap target */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
  border: 2px solid transparent;
}

.button-primary {
  background: var(--color-primary);
  color: #fff;
}

.button-primary:hover,
.button-primary:focus-visible {
  background: var(--color-primary-strong);
}

.button-ghost {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}

.button-ghost:hover,
.button-ghost:focus-visible {
  border-color: var(--color-primary);
}

.button-danger {
  color: #b91c1c;
  border-color: #b91c1c;
}

.button-danger:hover,
.button-danger:focus-visible {
  background: #fde8e4;
  border-color: #b91c1c;
}

.button-large {
  padding: 1rem 2rem;
  font-size: 1.125rem;
}

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

/* Header */

.site-header {
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-bg);
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  position: relative;
  min-height: 64px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--color-text);
  text-decoration: none;
}

.logo-mark {
  color: var(--color-primary);
}

.nav-toggle-checkbox {
  position: absolute;
  opacity: 0;
  width: 44px;
  height: 44px;
  margin: 0;
  top: 10px;
  right: var(--space-2);
  pointer-events: none;
}

.nav-toggle-label {
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-inline: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-weight: 600;
}

.nav-panel {
  display: none;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2) 0;
  width: 100%;
}

.nav-toggle-checkbox:checked ~ .nav-panel {
  display: flex;
}

.nav-toggle-checkbox:focus-visible ~ .nav-toggle-label {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.nav-panel a {
  padding: var(--space-1) 0;
  color: var(--color-text);
  text-decoration: none;
  font-weight: 600;
}

.nav-cta {
  margin-top: var(--space-1);
  align-self: flex-start;
}

.nav-dropdown summary {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: var(--space-1) 0;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.nav-dropdown summary::-webkit-details-marker {
  display: none;
}

.nav-dropdown summary::after {
  content: "▾";
  font-size: 0.7em;
  color: var(--color-text-muted);
}

.nav-dropdown[open] summary::after {
  content: "▴";
}

.nav-dropdown summary:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.nav-dropdown-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: 0 0 var(--space-1) var(--space-3);
}

.nav-dropdown-panel a {
  padding: var(--space-1) 0;
  color: var(--color-text);
  text-decoration: none;
  font-weight: 600;
}

/* Hero */

.hero {
  background: var(--color-bg-alt);
  padding-block: var(--space-4) var(--space-5);
}

.hero-inner {
  text-align: center;
}

.hero h1 {
  font-size: clamp(1.75rem, 5vw + 1rem, 3rem);
  max-width: 20ch;
  margin-inline: auto;
}

.lede {
  color: var(--color-text-muted);
  max-width: 48ch;
  margin-inline: auto;
  font-size: 1.05rem;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
  margin-block: var(--space-3);
}

.trust-line {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.hero-visual {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.stat-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  text-align: left;
  box-shadow: 0 12px 24px -18px rgb(0 0 0 / 0.35);
}

.stat-head {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.stat-icon {
  font-size: 1rem;
  line-height: 1;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
}

.stat-sub {
  font-size: 0.8rem;
  color: var(--color-accent);
}

/* Sport strip */

.sport-strip {
  padding-block: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.sport-strip-label {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  margin-bottom: var(--space-2);
}

.sport-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-1) var(--space-3);
  font-weight: 700;
  color: var(--color-text-muted);
}

/* Quote */

.quote-section {
  padding-block: var(--space-4);
}

blockquote {
  margin: 0 auto;
  max-width: 42ch;
  text-align: center;
  font-size: 1.25rem;
}

blockquote footer {
  margin-top: var(--space-2);
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* Sections generic */

section {
  padding-block: var(--space-5);
}

section h2 {
  font-size: clamp(1.5rem, 3vw + 1rem, 2.25rem);
  max-width: 24ch;
}

.section-lede {
  color: var(--color-text-muted);
  max-width: 60ch;
}

/* Card grids */

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.card {
  background: var(--color-bg-alt);
  border-radius: var(--radius);
  padding: var(--space-3);
}

.card h3 {
  font-size: 1.05rem;
}

.card p {
  margin: 0;
  color: var(--color-text-muted);
}

.card--icon {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

.badge-icon {
  font-size: 1.75rem;
  display: inline-block;
  margin-bottom: var(--space-1);
}

/* Comparison */

.compare-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.compare-block {
  border-radius: var(--radius);
  padding: var(--space-3);
}

.compare-block h3 {
  font-size: 1.05rem;
}

.compare-block p {
  margin: 0;
}

.compare-block--a {
  background: #fde8e4;
}

.compare-block--b {
  background: #fdf2d6;
}

.compare-block--c {
  background: #d9f2ef;
  border: 2px solid var(--color-accent);
}

/* Detail sections (feature + mock visual) */

.detail-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.detail-section--reverse .detail-inner {
  flex-direction: column;
}

.stars {
  color: #c2410c;
  letter-spacing: 0.15em;
  margin-bottom: var(--space-1);
}

.detail-visual {
  background: var(--color-bg-alt);
  border-radius: var(--radius);
  padding: var(--space-2);
  overflow-x: auto;
}

.mock-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 28rem;
  font-size: 0.9rem;
}

.mock-table th,
.mock-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

.mock-table th {
  color: var(--color-text-muted);
  font-weight: 700;
}

.mock-csv {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.8rem;
  overflow-x: auto;
}

.mock-csv-row {
  margin: 0;
  padding: 0.25rem 0;
  white-space: pre;
}

.mock-csv-row--head {
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

/* Security */

.security {
  background: var(--color-bg-alt);
}

/* CTA */

.cta {
  text-align: center;
  background: var(--color-bg-dark);
  color: var(--color-text-on-dark);
}

.cta p {
  color: var(--color-text-on-dark-muted);
}

.cta h2 {
  margin-inline: auto;
}

.cta-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.cta .button-primary {
  margin-top: var(--space-2);
}

/* FAQ */

.faq-list {
  margin-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.faq-list details {
  border-bottom: 1px solid var(--color-border);
  padding-block: var(--space-2);
}

.faq-list summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.faq-list p {
  color: var(--color-text-muted);
  margin: var(--space-1) 0 0;
}

/* Race plan calculator */

.plan-hero {
  background: var(--color-bg-alt);
  padding-block: var(--space-4) var(--space-3);
}

.plan-hero .lede {
  margin-inline: 0;
}

.plan-section {
  padding-top: var(--space-3);
}

/* Generation parameters stay on top, full width; the generated plan
   renders full-width below -- avoids squeezing the plan table into a
   half-width sidebar column. */
.plan-layout {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.form-notice {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2);
}

.plan-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.form-fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-fieldset legend {
  font-weight: 700;
  padding-inline: 0.25rem;
}

.plan-form-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-field-label {
  font-weight: 600;
}

.form-field label,
.form-field-label {
  font-size: 0.95rem;
}

.form-field input[type="text"],
.form-field input[type="number"],
.form-field input[type="date"],
.form-field input[type="search"],
.form-field input[type="file"],
.form-field select {
  min-height: 44px;
  font-size: 1rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}

.form-field input:focus-visible,
.form-field select:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 1px;
}

.form-field input[type="range"] {
  width: 100%;
  min-height: 44px;
}

.radio-row,
.checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding-inline: 0.25rem;
}

.radio-option input {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.checkbox-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  border: 1.5px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  font-weight: 500;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.checkbox-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.checkbox-option:focus-within {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.checkbox-option:has(input:checked) {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

.checkbox-option-icon {
  font-size: 1.1rem;
  line-height: 1;
}

/* Route names can run long; cap each pill's width and ellipsize so several
   fit per line instead of each activity forcing its own row (full name
   still available via the label's title attribute on hover/focus). */
#share-route-picker .checkbox-option {
  max-width: 220px;
  /* Flex items default to min-width: auto (their content's full intrinsic
     width), which overrides max-width when the two conflict -- without
     this the pill silently ignores max-width and never actually shrinks. */
  min-width: 0;
}

#share-route-picker .checkbox-option-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.form-advanced {
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2);
}

.form-advanced summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.form-advanced .form-field {
  margin-top: var(--space-2);
}

.form-hint {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  margin: var(--space-1) 0 0;
}

.form-error {
  background: #fde8e4;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  padding: var(--space-2);
  color: var(--color-primary-strong);
  font-weight: 600;
}

.plan-results {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  background: var(--color-bg-alt);
  /* keeps the sticky header from covering the heading when JS scrolls
     the results into view after generating a plan */
  scroll-margin-top: calc(64px + var(--space-2));
}

.plan-results-placeholder {
  color: var(--color-text-muted);
  margin: 0;
}

.plan-results-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.plan-results-header h2 {
  margin: 0;
}

/* Pace-zone analyzer + the "Fitness & pace zones" fieldset sit side by
   side on wider screens -- they're two views of the same paces, so
   keeping them adjacent beats stacking them a whole section apart. */
.plan-analyzer-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* The Strava-history pace-zone analyzer card -- kept tighter than the
   other plan-results cards since it's just a quick reference, shown
   above the (much longer) generation form and results. */
#pace-analyzer {
  padding: var(--space-2);
}

#pace-analyzer-results .plan-history,
#pace-analyzer-results .plan-warnings {
  margin-block: var(--space-2);
}

.pace-analyzer-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-block: var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.pace-analyzer-controls input[type="range"] {
  width: 100%;
  min-height: 44px;
}

.pace-analyzer-populate {
  margin-top: var(--space-3);
}

.plan-history,
.plan-warnings {
  margin-block: var(--space-3);
}

.plan-history ul,
.plan-warnings ul {
  margin: var(--space-1) 0 0;
  padding-left: 1.25rem;
}

.plan-table-wrap {
  overflow-x: auto;
}

.plan-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 32rem;
  font-size: 0.9rem;
  background: var(--color-bg);
}

.plan-table--workouts {
  min-width: 60rem;
}

.plan-table--workouts th[scope="row"] {
  white-space: nowrap;
}

/* History-derived pace-zone table: just 2 narrow columns, so it doesn't
   need the same min-width as the wider plan tables -- letting it shrink
   keeps it from forcing horizontal scroll on a small phone. */
.plan-table--compact {
  min-width: 0;
  font-size: 0.85rem;
}

.plan-table--compact th,
.plan-table--compact td {
  padding: 0.4rem 0.6rem;
}

.plan-table th,
.plan-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

.plan-table th[scope="col"] {
  color: var(--color-text-muted);
  font-weight: 700;
}

/* The whole plan is one continuous table, with a "Week" column instead
   of a repeated header-like row per week -- a subtle band shade plus a
   stronger top border on each week's first row mark the boundaries. */
.plan-table--workouts .plan-week-band-1 {
  background: var(--color-bg-alt);
}

.plan-table--workouts .plan-week-start th,
.plan-table--workouts .plan-week-start td {
  border-top: 2px solid var(--color-text-muted);
}

/* Saved plans: list view */

.plan-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.plan-list-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2);
  background: var(--color-bg);
}

.plan-list-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.plan-list-item-name {
  font-weight: 700;
  font-size: 1.1rem;
}

.plan-list-item-meta {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.plan-list-item-actions {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
}

/* Saved plans: editor view */

.plan-editor-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.plan-name-field {
  flex: 1 1 16rem;
}

.plan-name-input {
  min-height: 44px;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 0.5rem 0.75rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  width: 100%;
}

.plan-name-input:hover,
.plan-name-input:focus-visible {
  border-color: var(--color-border);
  background: var(--color-bg);
}

.plan-editor-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.save-status {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  min-height: 1em;
}

.save-status--error {
  color: var(--color-primary-strong);
  font-weight: 600;
}

.plan-save-status {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.plan-unit-field {
  margin-bottom: var(--space-2);
}

/* Each week is its own block of workout cards laid out in a reflowing
   grid (auto-fill/minmax) rather than a wide table -- this is what keeps
   the editor scroll-free on desktop and gives mobile full-width, clearly
   labeled fields instead of cramped table cells needing horizontal scroll. */
.plan-week-block {
  margin-bottom: var(--space-4);
}

.plan-week-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: var(--space-2);
}

.plan-week-heading-detail {
  color: var(--color-text-muted);
  font-weight: 400;
  font-size: 0.9rem;
}

.plan-workout-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
  gap: var(--space-2);
  align-items: start;
}

.plan-workout-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2);
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.plan-workout-done {
  opacity: 0.6;
}

.plan-workout-card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-2);
}

.plan-workout-card-selects {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  flex: 1 1 auto;
}

.plan-workout-card-selects .form-field {
  min-width: 6rem;
  flex: 1 1 6rem;
}

.plan-workout-date {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  margin: -0.5rem 0 0;
}

.plan-workout-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: var(--space-2);
}

.plan-workout-pace-inputs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.plan-workout-pace-inputs input {
  min-width: 0;
  flex: 1 1 3.5rem;
}

.plan-workout-card .form-field input,
.plan-workout-card .form-field select {
  min-height: 44px;
  font-size: 0.9rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  background: var(--color-bg);
  color: var(--color-text);
  width: 100%;
}

.plan-workout-add-card {
  min-height: 44px;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-text-muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
}

.plan-workout-add-card:hover,
.plan-workout-add-card:focus-visible {
  border-color: var(--color-primary);
  color: var(--color-text);
}

/* Saved plans: editor table (>=1024px -- see the DESKTOP_QUERY breakpoint
   in saved-plan.js, which picks this table over the mobile cards above).
   table-layout:fixed with the JS-authored <colgroup> is what actually
   guarantees this never forces horizontal scroll: a content-sized table
   with 9 columns of selects/inputs doesn't reliably fit even at 1024px,
   but a fixed layout caps every column at its assigned share and never
   grows the table past 100% of its container. */
.plan-table--editor {
  table-layout: fixed;
  width: 100%;
  min-width: 0;
}

.plan-table--editor th,
.plan-table--editor td {
  padding: 0.4rem 0.5rem;
}

.plan-table--editor th[scope="row"] {
  font-size: 0.85rem;
}

.plan-table--editor input,
.plan-table--editor select {
  min-height: 44px;
  width: 100%;
  font-size: 0.85rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: 0.4rem;
  background: var(--color-bg);
  color: var(--color-text);
}

/* The default .button padding (0.75rem 1.5rem) is too wide for a table
   cell -- at the narrow end of the desktop range (1024px) it overflowed
   its column, invisible without scrolling inside .plan-table-wrap even
   though the page itself never showed a scrollbar. */
.plan-table--editor .button {
  width: 100%;
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  min-height: 44px;
}

.workout-cell-pace {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.workout-cell-pace input {
  min-width: 0;
}

.workout-cell-done {
  text-align: center;
}

.workout-cell-done input {
  width: 22px;
  height: 22px;
  min-height: 0;
}

.plan-week-header-row td {
  background: var(--color-bg-alt);
  padding-block: 0.6rem;
}

.plan-add-workout-row td {
  padding: var(--space-1) 0.5rem;
}

/* Dashboard / charts */

.sync-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: flex-end;
  margin-bottom: var(--space-3);
}

.filters-row .form-field {
  flex: 1 1 12rem;
}

.filters-row .form-field--full-width {
  flex-basis: 100%;
}

.custom-range-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.custom-range-row .form-field {
  flex: 1 1 8rem;
}

.link-button {
  background: none;
  border: none;
  padding: 0.35rem 0;
  min-height: 44px;
  color: var(--color-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.link-button:hover,
.link-button:focus-visible {
  text-decoration: underline;
}

.chart-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  background: var(--color-bg);
  margin-bottom: var(--space-3);
}

.chart-card h2 {
  margin-bottom: 0.15rem;
}

.chart-unit {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin: 0 0 var(--space-2);
}

.chart-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
}

#dashboard-charts.is-loading {
  opacity: 0.5;
}

.leaflet-map {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  background: var(--color-bg-muted, #eee);
}

.leaflet-popup-content {
  font-size: 0.85rem;
}

.leaflet-popup-content strong {
  display: block;
  margin-bottom: 0.15rem;
}

.leaflet-control-zoom-in,
.leaflet-control-zoom-out {
  width: 44px !important;
  height: 44px !important;
  line-height: 44px !important;
}

.stat-group {
  margin-bottom: var(--space-3);
}

.stat-group-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

.stat-group-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 0 0 var(--space-1);
}

.stat-tile-row {
  display: grid;
  /* auto-fill (not auto-fit) so tiles stay the same width whether their
     row is full or not -- auto-fit collapses unused tracks and lets a
     short row's tiles stretch to fill the space instead. */
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-1);
}

.stat-tile-row .stat-card {
  box-shadow: none;
  gap: 0.1rem;
  padding: var(--space-2);
}

.stat-tile-row .stat-value {
  font-size: 1.2rem;
}

.stat-tile-row .stat-head {
  min-width: 0;
}

.stat-tile-row .stat-label {
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.stat-tile-row .stat-sub {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#type-table-foot td,
#type-table-foot th {
  font-weight: 700;
  border-top: 2px solid var(--color-border);
}

.heatmap-outer {
  display: flex;
  gap: 0.35rem;
}

.heatmap-daylabels {
  display: grid;
  grid-template-rows: repeat(8, 12px);
  gap: 3px;
  flex-shrink: 0;
}

.heatmap-daylabels span {
  font-size: 0.65rem;
  line-height: 12px;
  color: var(--color-text-muted);
}

.heatmap-scroll-wrap {
  overflow-x: auto;
  padding-bottom: var(--space-1);
  flex: 1;
  min-width: 0;
}

.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(8, 12px);
  gap: 3px;
  min-width: max-content;
}

.heatmap-month-label {
  font-size: 0.7rem;
  line-height: 12px;
  color: var(--color-text-muted);
}

.heatmap-cell {
  width: 100%;
  height: 100%;
  border-radius: 2px;
  background: var(--heatmap-0);
  display: block;
}

.heatmap-cell[data-level="0"] { background: var(--heatmap-0); }
.heatmap-cell[data-level="1"] { background: var(--heatmap-1); }
.heatmap-cell[data-level="2"] { background: var(--heatmap-2); }
.heatmap-cell[data-level="3"] { background: var(--heatmap-3); }
.heatmap-cell[data-level="4"] { background: var(--heatmap-4); }

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: var(--space-2);
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.heatmap-legend .heatmap-cell {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.chart-table-details {
  margin-top: var(--space-2);
}

.chart-table-details summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.chart-table-details .plan-table-wrap {
  margin-top: var(--space-1);
}

.raw-data-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.raw-data-count {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.raw-data-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.filter-disclosure {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2);
  margin-bottom: var(--space-2);
}

.filter-disclosure summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.filter-disclosure-count {
  color: var(--color-text-muted);
  font-weight: 400;
}

.filter-disclosure-actions {
  display: flex;
  gap: var(--space-2);
  margin: var(--space-1) 0;
}

.filter-disclosure .checkbox-grid {
  margin-top: var(--space-1);
}

.raw-data-table {
  font-size: 0.8rem;
}

.raw-data-table th,
.raw-data-table td {
  white-space: nowrap;
}

/* Share card builder */

.share-layout {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.share-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.share-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  /* Sticky on desktop only (enabled at the two-column breakpoint) so the
     preview stays visible while scrolling a tall controls column. */
  align-self: flex-start;
}

.share-canvas-wrap {
  width: 100%;
  max-width: 18rem;
  aspect-ratio: 1080 / 1920;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--color-border);
  box-shadow: 0 12px 24px -18px rgb(0 0 0 / 0.35);
}

.share-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Footer */

.site-footer {
  background: var(--color-bg-dark);
  color: var(--color-text-on-dark-muted);
  padding-top: var(--space-4);
}

.footer-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
}

.logo--footer {
  color: var(--color-text-on-dark);
  margin: 0 0 0.25rem;
  font-weight: 800;
  font-size: 1.1rem;
}

.footer-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.footer-col h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-on-dark-muted);
  margin-bottom: var(--space-1);
}

.footer-col a {
  display: block;
  padding: 0.35rem 0;
  color: var(--color-text-on-dark);
  text-decoration: none;
}

.footer-legal {
  border-top: 1px solid #33302e;
  padding-block: var(--space-2);
  font-size: 0.8rem;
}

/* ---- 480px: small phone landscape / large phone ---- */
@media (min-width: 480px) {
  .hero-actions {
    flex-direction: row;
    justify-content: center;
  }

  .card-grid--2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---- 768px: tablet ---- */
@media (min-width: 768px) {
  .nav-toggle-checkbox,
  .nav-toggle-label {
    display: none;
  }

  .nav-panel {
    display: flex;
    flex-direction: row;
    align-items: center;
    width: auto;
    padding: 0;
  }

  .nav-panel a {
    padding-inline: var(--space-1);
  }

  .nav-cta {
    margin-top: 0;
    margin-left: var(--space-2);
  }

  .nav-dropdown {
    position: relative;
  }

  .nav-dropdown summary {
    padding-inline: var(--space-1);
  }

  .nav-dropdown-panel {
    position: absolute;
    top: 100%;
    left: 0;
    flex-direction: column;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-2);
    min-width: 10rem;
    box-shadow: 0 12px 24px -12px rgb(0 0 0 / 0.25);
    z-index: 20;
  }

  .nav-dropdown-panel a {
    padding-inline: var(--space-2);
  }

  .hero-visual {
    flex-direction: row;
  }

  .stat-card {
    flex: 1;
  }

  .card-grid--3 {
    grid-template-columns: repeat(2, 1fr);
  }

  .card-grid--4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .compare-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .detail-inner {
    flex-direction: row;
    align-items: center;
  }

  .detail-section--reverse .detail-inner {
    flex-direction: row-reverse;
  }

  .detail-text,
  .detail-visual {
    flex: 1;
  }

  .footer-inner {
    flex-direction: row;
    justify-content: space-between;
  }

  .footer-nav {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-4);
  }

  .chart-wrap {
    max-height: 320px;
  }

  .form-fieldset {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: var(--space-2) var(--space-3);
    align-items: start;
  }

  .form-fieldset legend {
    grid-column: 1 / -1;
  }

  .form-fieldset .form-field--full-width {
    grid-column: 1 / -1;
  }

  /* One column, matching the single-column analyzer card beside it,
     rather than the 2-up field grid the other fieldsets use. */
  .form-fieldset--paces {
    grid-template-columns: 1fr;
  }

  .plan-analyzer-row {
    flex-direction: row;
    align-items: stretch;
  }

  .plan-analyzer-row > #pace-analyzer,
  .plan-analyzer-row > .form-fieldset--paces {
    flex: 1;
    min-width: 0;
  }

  /* Race has more fields than Schedule/Course combined -- stack the
     latter two in one column next to Race rather than spreading all
     three evenly, which left a tall gap under the shorter two. */
  .plan-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "race schedule"
      "race course"
      "actions actions";
    align-items: stretch;
  }

  .form-fieldset--race { grid-area: race; }
  .form-fieldset--schedule { grid-area: schedule; }
  .form-fieldset--course { grid-area: course; }

  .plan-form-actions {
    grid-area: actions;
  }

  #dashboard-charts {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    align-items: start;
    gap: var(--space-3);
  }

  .chart-card--wide {
    grid-column: 1 / -1;
  }

  .stat-group-row {
    grid-template-columns: 2fr 1fr;
  }
}

/* ---- 1024px: small desktop / large tablet ---- */
@media (min-width: 1024px) {
  .card-grid--3 {
    grid-template-columns: repeat(3, 1fr);
  }

  .card-grid--4 {
    grid-template-columns: repeat(4, 1fr);
  }

  .hero h1 {
    max-width: 26ch;
  }

  .share-layout {
    flex-direction: row;
    align-items: flex-start;
  }

  .share-controls {
    flex: 1;
    min-width: 0;
  }

  .share-preview {
    flex: 0 0 22rem;
    position: sticky;
    top: var(--space-3);
  }
}

/* ---- 1280px: large desktop ---- */
@media (min-width: 1280px) {
  :root {
    --space-5: 6rem;
  }
}
