/* Steady State Pace Calculator — design system
   Deep Slate / Forest Green / Warm Gold / Warm Cream / Slate Grey
   Georgia (headings + numbers) · Trebuchet MS (labels, body, UI) */

:root {
  --slate: #1A2332;
  --slate-soft: #243044;
  --green: #3D7A5E;
  --green-dark: #2F614A;
  --gold: #C8A96E;
  --cream: #F4F1EC;
  --cream-deep: #ECE7DE;
  --grey: #8A9BB0;
  --text: #1A2332;
  --text-mid: #4A5568;
  --text-light: #8A9BB0;
  --border: #DDD6C9;
  --error: #9B4A3C;
  /* Zone ramp — brand-derived */
  --z1: #3D7A5E;
  --z2: #5E8A8A;
  --z3: #C8A96E;
  --z4: #B07A45;
  --z5: #9B4A3C;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: 'Trebuchet MS', 'Segoe UI', Tahoma, sans-serif;
}

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

html { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--cream);
  color: var(--text);
  min-height: 100%;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  font-size: 15px;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────── */
.app-header {
  background: var(--slate);
  color: var(--cream);
  padding: calc(16px + env(safe-area-inset-top)) 20px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { display: block; }
.brand-text .eyebrow {
  font-size: 9px; letter-spacing: 3px; text-transform: uppercase;
  color: var(--gold); font-weight: bold;
}
.brand-text h1 { font-family: var(--serif); font-size: 19px; font-weight: bold; line-height: 1.15; }

.unit-toggle { display: flex; border: 1px solid rgba(244,241,236,0.3); border-radius: 6px; overflow: hidden; }
.unit-btn {
  background: transparent; border: none; color: var(--grey);
  font-family: var(--sans); font-size: 12px; font-weight: bold;
  padding: 7px 12px; cursor: pointer;
}
.unit-btn.active { background: var(--gold); color: var(--slate); }

/* ── Views & tab bar ───────────────────────────────── */
.view { display: none; padding: 20px 16px 28px; max-width: 760px; margin: 0 auto; }
.view.active { display: block; }

.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--slate);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid rgba(244,241,236,0.12);
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  color: var(--grey); font-family: var(--sans); font-size: 10px; font-weight: bold;
  letter-spacing: 0.5px; text-transform: uppercase;
  padding: 10px 4px 12px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.tab svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.tab.active { color: var(--gold); }
.tab:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }

/* ── Forms ─────────────────────────────────────────── */
.form-card {
  background: var(--slate);
  border-radius: 12px;
  padding: 20px 18px;
  margin-bottom: 20px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; }
.field.full { grid-column: 1 / -1; }
.field label {
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--gold); font-weight: bold; margin-bottom: 6px;
}
.field input, .field select {
  background: rgba(244,241,236,0.07);
  border: 1px solid rgba(244,241,236,0.22);
  border-radius: 7px;
  color: var(--cream);
  font-family: var(--sans);
  font-size: 16px; /* prevents iOS zoom */
  padding: 11px 12px;
  width: 100%;
  appearance: none;
}
.field input::placeholder { color: rgba(138,155,176,0.7); }
.field input:focus, .field select:focus { outline: 2px solid var(--gold); border-color: transparent; }
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6' fill='%238A9BB0'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.field .hint { font-size: 11px; color: var(--grey); margin-top: 4px; }

.btn {
  font-family: var(--sans); font-weight: bold; font-size: 14px;
  border: none; border-radius: 8px; padding: 13px 22px; cursor: pointer;
}
.btn:focus-visible { outline: 2px solid var(--slate); outline-offset: 2px; }
.btn-primary { background: var(--green); color: #fff; width: 100%; margin-top: 16px; font-size: 15px; }
.btn-primary:active { background: var(--green-dark); }
.btn-secondary { background: transparent; border: 1.5px solid var(--slate); color: var(--slate); }
.btn-ghost { background: transparent; border: 1.5px solid rgba(244,241,236,0.35); color: var(--cream); }
.btn-small { padding: 8px 14px; font-size: 12px; border-radius: 6px; }

.status { border-radius: 8px; padding: 12px 14px; font-size: 13px; margin-bottom: 16px; display: none; }
.status.show { display: block; }
.status.ok { background: rgba(61,122,94,0.12); color: var(--green-dark); border: 1px solid rgba(61,122,94,0.3); }
.status.warn { background: rgba(200,169,110,0.15); color: #8A6D33; border: 1px solid rgba(200,169,110,0.45); }
.status.err { background: rgba(155,74,60,0.1); color: var(--error); border: 1px solid rgba(155,74,60,0.3); }

/* ── Results ───────────────────────────────────────── */
.section-title {
  font-size: 11px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--text-light); font-weight: bold;
  margin: 26px 0 12px;
  display: flex; align-items: center; gap: 10px;
}
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.athlete-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.athlete-name { font-family: var(--serif); font-size: 26px; font-weight: bold; }
.athlete-meta { font-size: 13px; color: var(--text-mid); margin-top: 2px; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* The signature: anchor numeral with zone bands fanning beneath */
.anchor-block {
  background: var(--slate);
  border-radius: 12px;
  padding: 22px 20px 0;
  margin-top: 16px;
  overflow: hidden;
}
.anchor-label { font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: var(--gold); font-weight: bold; }
.anchor-value { font-family: var(--serif); font-size: 64px; font-weight: bold; color: var(--cream); line-height: 1.05; }
.anchor-value .unit { font-size: 20px; color: var(--grey); font-family: var(--sans); font-weight: normal; }
.anchor-sub { font-size: 12px; color: var(--grey); margin-top: 2px; margin-bottom: 18px; }
.zone-fan { display: flex; flex-direction: column; gap: 3px; margin: 0 -20px; }
.fan-band { height: 9px; opacity: 0.95; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.stat-card.gold-edge { border-top: 3px solid var(--gold); }
.stat-label { font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--text-light); font-weight: bold; }
.stat-value { font-family: var(--serif); font-size: 30px; font-weight: bold; margin-top: 3px; }
.stat-value .small { font-size: 13px; color: var(--text-light); font-family: var(--sans); font-weight: normal; }
.stat-sub { font-size: 11px; color: var(--text-mid); margin-top: 2px; }

.race-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.race-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 14px; position: relative; }
.race-card.goal { border-color: var(--gold); border-width: 1.5px; }
.goal-badge {
  position: absolute; top: 10px; right: 10px;
  background: var(--gold); color: var(--slate);
  font-size: 9px; font-weight: bold; letter-spacing: 1px; text-transform: uppercase;
  padding: 3px 8px; border-radius: 4px;
}
.race-dist { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--text-light); font-weight: bold; }
.race-time { font-family: var(--serif); font-size: 27px; font-weight: bold; margin-top: 2px; }
.race-pace { font-size: 12px; color: var(--text-mid); }
.race-target { font-size: 11px; color: var(--text-mid); margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--border); }

/* Zones table → cards on mobile */
.zones-list { display: flex; flex-direction: column; gap: 8px; }
.zone-row {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: 12px; align-items: center;
}
.zone-chip { width: 4px; height: 100%; min-height: 44px; border-radius: 2px; }
.zone-id { font-family: var(--serif); font-weight: bold; font-size: 16px; }
.zone-purpose { font-size: 12px; color: var(--text-mid); }
.zone-hr { font-size: 11.5px; color: var(--text-mid); margin-top: 2px; }
.zone-pace { font-family: var(--serif); font-weight: bold; font-size: 19px; text-align: right; white-space: nowrap; }
.zone-pace .u { font-size: 11px; color: var(--text-light); font-family: var(--sans); font-weight: normal; }

.note {
  background: var(--cream-deep); border-left: 3px solid var(--gold);
  border-radius: 0 8px 8px 0; padding: 12px 14px;
  font-size: 12.5px; color: var(--text-mid); margin-top: 12px;
}

.session-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.session-card { background: #fff; border: 1px solid var(--border); border-top-width: 3px; border-radius: 10px; padding: 13px; }
.session-name { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; font-weight: bold; color: var(--text-mid); }
.session-pace { font-family: var(--serif); font-size: 26px; font-weight: bold; margin-top: 2px; }
.session-desc { font-size: 11px; color: var(--text-light); }

.builder { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.builder-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.builder .field label { color: var(--text-light); }
.builder .field input, .builder .field select {
  background: var(--cream); border: 1px solid var(--border); color: var(--text);
}
.builder-output {
  display: none; margin-top: 14px; padding: 14px;
  background: var(--slate); color: var(--cream); border-radius: 8px;
  font-family: var(--serif); font-size: 17px; font-weight: bold;
}
.builder-output.show { display: block; }
.builder-output .range { font-family: var(--sans); font-size: 12px; font-weight: normal; color: var(--grey); display: block; margin-top: 3px; }

/* ── Athletes view ─────────────────────────────────── */
.athlete-card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  cursor: pointer;
}
.athlete-card:active { background: var(--cream-deep); }
.ac-name { font-family: var(--serif); font-weight: bold; font-size: 17px; }
.ac-meta { font-size: 12px; color: var(--text-mid); margin-top: 1px; }
.retest-badge {
  display: inline-block; background: rgba(200,169,110,0.18); color: #8A6D33;
  font-size: 10px; font-weight: bold; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 2px 8px; border-radius: 4px; margin-left: 6px;
}
.ac-delete {
  background: none; border: none; color: var(--text-light); cursor: pointer;
  font-size: 18px; padding: 8px; line-height: 1;
}
.ac-delete:focus-visible { outline: 2px solid var(--slate); border-radius: 4px; }
.empty-state { text-align: center; color: var(--text-light); padding: 48px 20px; font-size: 14px; }
.empty-state .big { font-family: var(--serif); font-size: 20px; color: var(--text-mid); margin-bottom: 6px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

/* ── Squad view ────────────────────────────────────── */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: 10px; }
table.squad { border-collapse: collapse; width: 100%; min-width: 720px; font-size: 12.5px; }
table.squad th {
  background: var(--slate); color: var(--grey);
  font-size: 9.5px; letter-spacing: 1px; text-transform: uppercase;
  padding: 10px 12px; text-align: left; white-space: nowrap;
  position: sticky; top: 0;
}
table.squad td { padding: 9px 12px; border-bottom: 1px solid var(--cream-deep); white-space: nowrap; }
table.squad td.pace { font-family: var(--serif); font-weight: bold; }
table.squad tr:last-child td { border-bottom: none; }

/* ── Method view ───────────────────────────────────── */
.method-card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 10px; overflow: hidden;
}
.method-card summary {
  list-style: none; cursor: pointer;
  padding: 15px 16px;
  font-family: var(--serif); font-weight: bold; font-size: 16px;
  display: flex; justify-content: space-between; align-items: center;
}
.method-card summary::-webkit-details-marker { display: none; }
.method-card summary::after { content: '\25BE'; color: var(--text-light); transition: transform 0.18s; }
.method-card[open] summary::after { transform: rotate(180deg); }
.method-body { padding: 0 16px 16px; font-size: 13.5px; color: var(--text-mid); }
.method-body p { margin-bottom: 10px; }
.method-body strong { color: var(--text); }
.method-body ol { padding-left: 20px; margin-bottom: 10px; }
.method-body ol li { margin-bottom: 5px; }
.ref-list { list-style: none; margin-bottom: 10px; }
.ref-list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 7px 0; border-bottom: 1px solid var(--cream-deep);
  font-size: 12.5px;
}
.ref-list li:last-child { border-bottom: none; }
.ref-list .val { font-family: var(--serif); font-weight: bold; color: var(--text); white-space: nowrap; }
.caveat {
  background: rgba(155,74,60,0.07); border-left: 3px solid var(--error);
  border-radius: 0 8px 8px 0; padding: 12px 14px;
  font-size: 12.5px; color: var(--text-mid);
}
.evidence { font-size: 11.5px; color: var(--text-light); margin-top: 8px; }

/* ── Toast ─────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(90px + env(safe-area-inset-bottom));
  background: var(--slate); color: var(--cream);
  padding: 11px 18px; border-radius: 8px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
  z-index: 100; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ── Print: coach's full output ────────────────────── */
@media print {
  body { padding: 0; background: #fff; font-size: 12px; }
  .app-header, .tab-bar, .form-card, .result-actions, .builder, .toast, .status { display: none !important; }
  .view { display: none !important; }
  #view-calculate.active { display: block !important; padding: 0; max-width: none; }
  .anchor-block { background: #fff; border: 2px solid var(--slate); }
  .anchor-value, .anchor-label { color: var(--slate); }
  .anchor-sub { color: var(--text-mid); }
  .zone-row, .stat-card, .race-card, .session-card { break-inside: avoid; }
  .section-title { margin-top: 16px; }
}

@media (min-width: 700px) {
  .form-grid { grid-template-columns: repeat(3, 1fr); }
  .builder-row { grid-template-columns: repeat(4, 1fr); align-items: end; }
  .anchor-value { font-size: 76px; }
}
