/* Marathon Trainer — Design Tokens & Global Styles */

:root {
  /* Surfaces (warm sand & stone) */
  --bg-base: #f0ece4;
  --bg-app: #f6f2ea;
  --bg-card: #fbf8f2;
  --bg-elev: #ffffff;
  --bg-sunken: #ebe6dc;

  /* Ink scale */
  --ink-1: #2a2520;
  --ink-2: #5d564d;
  --ink-3: #8a8276;
  --ink-4: #b8b1a5;
  --ink-5: #d8d2c6;

  --line: rgba(42, 37, 32, 0.08);
  --line-strong: rgba(42, 37, 32, 0.16);

  /* Accent (terracotta) */
  --accent: #b8553a;
  --accent-pressed: #9c4530;
  --accent-tint: #f1d9cf;
  --accent-tint-2: #fae8df;

  /* Status */
  --ok: #6b7a4f;
  --warn: #b88033;
  --err: #a4453a;

  /* Phase palette (earth tones) */
  --phase-build: #6b7a4f;
  --phase-build-bg: #e6e8d8;
  --phase-cutback: #a89171;
  --phase-cutback-bg: #ece3d4;
  --phase-peak: #c1683f;
  --phase-peak-bg: #f3dfd1;
  --phase-taper: #6b7280;
  --phase-taper-bg: #e1e2e0;
  --phase-race: #2a2520;
  --phase-race-bg: #d6cfc1;

  /* Typography */
  --font-ui: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;

  /* Type scale */
  --t-xs: 11px;
  --t-sm: 13px;
  --t-md: 15px;
  --t-lg: 22px;
  --t-xl: 44px;

  /* Spacing */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 48px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  /* Shadows */
  --shadow-1: 0 1px 0 rgba(42,37,32,0.04), 0 0 0 0.5px rgba(42,37,32,0.06);
  --shadow-2: 0 1px 2px rgba(42,37,32,0.05), 0 4px 14px rgba(42,37,32,0.06), 0 0 0 0.5px rgba(42,37,32,0.05);
  --shadow-modal: 0 20px 60px rgba(42,37,32,0.18), 0 0 0 0.5px rgba(42,37,32,0.08);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: var(--font-ui);
  font-size: var(--t-md);
  line-height: 1.45;
  letter-spacing: -0.005em;
  color: var(--ink-1);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: 104px;
  min-height: 100vh;
}

/* Utility classes */
.mt-num { font-family: var(--font-mono); font-feature-settings: "tnum" 1; letter-spacing: -0.01em; }
.mt-mono { font-family: var(--font-mono); }
.mt-scroll { overflow-y: auto; scrollbar-width: none; }
.mt-scroll::-webkit-scrollbar { display: none; }

/* Animations */
@keyframes mt-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.mt-fade-in { animation: mt-fade-in 180ms ease-out; }

@keyframes mt-toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Bottom Navigation */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  border-top: 1px solid var(--line);
  background: rgba(251, 248, 242, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  padding: 10px 4px calc(12px + env(safe-area-inset-bottom, 0));
}

#bottom-nav .nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 2px 6px;
  text-decoration: none;
  color: var(--ink-3);
  flex: 1;
  border-radius: 8px;
  transition: color 120ms;
}

#bottom-nav .nav-item.active {
  color: var(--accent);
}

#bottom-nav .nav-item span {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

#bottom-nav .nav-item.active span {
  font-weight: 600;
}

/* Toast slot */
#toast-slot {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  pointer-events: none;
}

#toast-slot .toast {
  padding: 10px 16px;
  background: var(--ink-1);
  color: #fff;
  border-radius: 999px;
  font-size: var(--t-sm);
  font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  animation: mt-toast-in 200ms ease-out;
  white-space: nowrap;
  pointer-events: auto;
}

/* Modal slot */
#modal-slot:empty { display: none; }

#modal-slot .modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(42,37,32,0.42);
  display: flex;
  align-items: flex-end;
  animation: mt-fade-in 180ms;
}

#modal-slot .modal-sheet {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  background: var(--bg-elev);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 20px 20px 32px;
  box-shadow: var(--shadow-modal);
}

#modal-slot .modal-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--ink-5);
  margin: 0 auto 16px;
}

#modal-slot .modal-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 8px;
}

#modal-slot .modal-body {
  font-size: 14px;
  color: var(--ink-2);
  margin-bottom: 20px;
  line-height: 1.45;
}

#modal-slot .modal-actions {
  display: flex;
  gap: 10px;
}

/* Divider */
.mt-divider { height: 1px; background: var(--line); }

/* Buttons */
button { font-family: inherit; font-size: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  transition: background 120ms, color 120ms, transform 120ms;
  cursor: pointer;
  border-radius: var(--r-md);
  border: 0;
  gap: 8px;
}

.btn--md { font-size: var(--t-md); padding: 12px 18px; }
.btn--sm { font-size: var(--t-sm); padding: 8px 14px; }
.btn--full { width: 100%; }

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:active { background: var(--accent-pressed); }
.btn--secondary { background: var(--bg-sunken); color: var(--ink-1); }
.btn--ghost { background: transparent; color: var(--ink-1); }
.btn--destructive { background: transparent; color: var(--err); border: 1px solid var(--err); }

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: 16px;
}

.card--elevated { box-shadow: var(--shadow-2); }
.card--no-pad { padding: 0; }

/* Accordion */
.accordion {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}

.accordion-header {
  width: 100%;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}

.accordion-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.accordion-title { font-size: var(--t-md); font-weight: 600; color: var(--ink-1); }
.accordion-status { font-size: 12px; color: var(--ink-3); }

.accordion-chevron {
  transition: transform 180ms;
  color: var(--ink-3);
  flex-shrink: 0;
}

.accordion.open .accordion-chevron { transform: rotate(180deg); }

.accordion-body {
  display: none;
  padding: 0 16px 16px;
  border-top: 1px solid var(--line);
}

.accordion.open .accordion-body { display: block; }
.accordion-body-inner { padding-top: 14px; }

/* Phase badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  white-space: nowrap;
}

.badge--sm { padding: 2px 7px; font-size: 10px; }

.badge--build { color: var(--phase-build); background: var(--phase-build-bg); }
.badge--cutback { color: var(--phase-cutback); background: var(--phase-cutback-bg); }
.badge--peak { color: var(--phase-peak); background: var(--phase-peak-bg); }
.badge--taper { color: var(--phase-taper); background: var(--phase-taper-bg); }
.badge--race_week { color: var(--phase-race); background: var(--phase-race-bg); }

/* Section header */
.section-header {
  padding: 0 20px;
  margin-bottom: 8px;
}

.section-header__title {
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  text-transform: uppercase;
  margin: 0;
}

.section-header__sub {
  font-size: var(--t-sm);
  color: var(--ink-3);
  margin-top: 2px;
}

/* Screen header */
.screen-header {
  padding: 8px 20px 16px;
}

.screen-header__eyebrow {
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.screen-header__row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.screen-header__title {
  font-size: 26px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}

/* Stepper */
.stepper {
  display: inline-flex;
  align-items: stretch;
  background: var(--bg-sunken);
  border-radius: var(--r-md);
  height: 36px;
}

.stepper button {
  width: 36px;
  color: var(--ink-2);
  font-size: 18px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stepper-value {
  min-width: 64px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-family: var(--font-mono);
  font-size: var(--t-md);
  font-weight: 500;
}

.stepper-unit {
  font-size: var(--t-xs);
  color: var(--ink-3);
  font-weight: 500;
}

/* Segmented 1–10 */
.seg10 {
  display: flex;
  gap: 3px;
  background: var(--bg-sunken);
  padding: 3px;
  border-radius: var(--r-md);
}

.seg10 button {
  flex: 1;
  height: 30px;
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  color: var(--ink-3);
  transition: all 100ms;
}

.seg10 button.active {
  background: #fff;
  color: var(--ink-1);
  box-shadow: 0 1px 2px rgba(42,37,32,0.08), 0 0 0 0.5px rgba(42,37,32,0.06);
}

/* Slider */
.slider-wrap { }

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.slider-label { font-size: var(--t-sm); color: var(--ink-2); }

.slider-value {
  font-family: var(--font-mono);
  font-size: var(--t-md);
  font-weight: 600;
}

.slider-value-max {
  color: var(--ink-3);
  font-weight: 400;
}

.slider-track {
  position: relative;
  height: 24px;
  display: flex;
  align-items: center;
}

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  outline: none;
  background: var(--bg-sunken);
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 1px 3px rgba(42,37,32,0.18), 0 0 0 0.5px rgba(42,37,32,0.1);
  cursor: pointer;
}

input[type=range]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 1px 3px rgba(42,37,32,0.18), 0 0 0 0.5px rgba(42,37,32,0.1);
  cursor: pointer;
}

/* Toggle */
.toggle {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--ink-4);
  position: relative;
  transition: background 150ms;
  flex-shrink: 0;
  cursor: pointer;
  border: 0;
}

.toggle.on { background: var(--accent); }

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: left 150ms;
}

.toggle.on .toggle-thumb { left: 20px; }

/* Empty state */
.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--ink-3);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--bg-card);
}

.empty-state__title {
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 4px;
}

.empty-state__hint { font-size: 12px; }

/* Text input */
.input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-app);
  font-family: var(--font-ui);
  font-size: var(--t-sm);
  color: var(--ink-1);
  outline: none;
}

.input:focus { border-color: var(--line-strong); }

.input--textarea {
  min-height: 56px;
  resize: vertical;
  line-height: 1.45;
}

/* Tri-toggle (todo/done/skip) */
.tri-toggle {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg-sunken);
  border-radius: var(--r-md);
}

.tri-toggle button {
  width: 30px;
  height: 26px;
  border-radius: 6px;
  font-size: var(--t-sm);
  font-weight: 600;
  background: transparent;
  color: var(--ink-3);
}

.tri-toggle button.active {
  background: #fff;
  box-shadow: 0 1px 2px rgba(42,37,32,0.08);
}

.tri-toggle button.active[data-val="done"] { color: var(--ok); }
.tri-toggle button.active[data-val="skip"] { color: var(--err); }

/* Filter chips */
.filter-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}

.filter-chips::-webkit-scrollbar { display: none; }

.filter-chip {
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--ink-2);
  font-size: var(--t-sm);
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-1);
  border: 0;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--ink-1);
  color: #fff;
  box-shadow: none;
}

/* Tab bar */
.tab-bar {
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg-app);
  z-index: 5;
}

.tab-bar-inner {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-bar-inner::-webkit-scrollbar { display: none; }

.tab-btn {
  padding: 10px 12px;
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--ink-3);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  background: none;
  border-top: 0;
  border-left: 0;
  border-right: 0;
  cursor: pointer;
}

.tab-btn.active {
  font-weight: 600;
  color: var(--ink-1);
  border-bottom-color: var(--accent);
}

/* Label row (used in log form) */
.field-label {
  font-size: var(--t-xs);
  color: var(--ink-3);
  margin-bottom: 5px;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.field-row-label {
  font-size: var(--t-sm);
  color: var(--ink-2);
}

/* Chart card (progress screen) */
.chart-card {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-1);
  position: relative;
}

.chart-card__title {
  font-size: var(--t-md);
  font-weight: 600;
  margin: 0;
}

.chart-card__read {
  font-size: 12px;
  color: var(--ink-2);
  margin: 0 0 14px;
  line-height: 1.45;
}

.chart-card__legend {
  display: flex;
  gap: 10px;
}

.chart-card__legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chart-card__legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.chart-card__legend-label {
  font-size: 10px;
  color: var(--ink-3);
}
