/* ==========================================================================
   Lean — styles
   Tokens first, then base, then components. One accent color (green) for
   anything you can tap; neutrals for everything else.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Surfaces: canvas (L0) → raised cards (L1) → sunken inputs */
  --canvas: #f5f6f4;
  --raised: #ffffff;
  --sunken: #eef0ec;
  --border: rgba(26, 29, 27, 0.10);
  --border-strong: rgba(26, 29, 27, 0.20);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  --edge: none;

  /* Text */
  --text: #1a1d1b;
  --text-2: #59615c;

  /* Single accent */
  --accent: #2b7653;
  --accent-press: #22603f;
  --accent-soft: rgba(43, 118, 83, 0.10);
  --accent-tint: rgba(43, 118, 83, 0.35);
  --on-accent: #ffffff;

  /* Spacing (4/8pt) */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s6: 24px; --s8: 32px; --s12: 48px;

  /* Type: 3 weights, sizes from a minor-third scale */
  --w-regular: 400; --w-medium: 500; --w-semi: 600;
  --t-meta: 0.75rem;      /* 12px */
  --t-secondary: 0.875rem;/* 14px */
  --t-body: 1rem;         /* 16px */
  --t-h3: 1.2rem;         /* ~19px */
  --t-h1: 1.728rem;       /* ~28px */
  --t-hero: 3.25rem;      /* 52px */

  --radius: 14px;
  --radius-sm: 10px;
  --hit: 44px;
  --tabbar-h: 64px;
  --vp-wide: 640px; /* this is a phone-first app; content column caps here */
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #111412;
    --raised: #1a1e1b;
    --sunken: #0c0e0d;
    --border: rgba(232, 236, 233, 0.11);
    --border-strong: rgba(232, 236, 233, 0.22);
    --shadow: none;
    --edge: inset 0 1px 0 rgba(255, 255, 255, 0.05);

    --text: #e7ebe8;
    --text-2: #9ea7a1;

    --accent: #5cbf8c;
    --accent-press: #4caa7a;
    --accent-soft: rgba(92, 191, 140, 0.12);
    --accent-tint: rgba(92, 191, 140, 0.40);
    --on-accent: #0b1f14;
  }
}

/* ---------- Base ---------- */

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

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

body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--t-body);
  font-weight: var(--w-regular);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; font-weight: var(--w-semi); line-height: 1.2; }
h1 { font-size: var(--t-h1); letter-spacing: -0.01em; }
h2 { font-size: var(--t-h3); }
h3 { font-size: var(--t-body); }
p  { margin: 0; }

button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.meta { font-size: var(--t-meta); line-height: 1.4; color: var(--text-2); }
.secondary { font-size: var(--t-secondary); color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Layout ---------- */

.app { width: 100%; min-height: 100dvh; }

.page {
  width: 100%;
  max-width: var(--vp-wide);
  margin-inline: auto;
  padding: calc(env(safe-area-inset-top) + var(--s6)) var(--s4)
           calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s8));
  display: flex;
  flex-direction: column;
  gap: var(--s6);
  outline: none;
}

.page-header { display: flex; flex-direction: column; gap: var(--s1); }
.page-header .eyebrow { font-size: var(--t-secondary); color: var(--text-2); font-weight: var(--w-medium); }

.section { display: flex; flex-direction: column; gap: var(--s3); }
.section-title { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }

/* ---------- Cards & lists (L1 surfaces) ---------- */

.card {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), var(--edge);
  padding: var(--s4);
}
.card.soft { background: var(--accent-soft); border-color: transparent; box-shadow: none; }

.list {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), var(--edge);
  overflow: hidden;
  margin: 0; padding: 0; list-style: none;
}
.list > li + li { border-top: 1px solid var(--border); }

.row {
  display: flex; align-items: center; gap: var(--s3);
  min-height: 60px;
  padding: var(--s3) var(--s4);
  width: 100%;
  text-align: left;
  background: none; border: 0;
}
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: var(--w-medium); }
.row-icon {
  flex: none; width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--sunken); color: var(--text-2);
}
.row-icon svg { width: 20px; height: 20px; }

/* ---------- Checklist ---------- */

.check-row { cursor: pointer; }
.check-row:active { background: var(--sunken); }

.check {
  flex: none;
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--border-strong);
  display: grid; place-items: center;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.check svg { width: 16px; height: 16px; fill: none; stroke: var(--on-accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transition: opacity 150ms ease; }
[aria-checked="true"] .check { background: var(--accent); border-color: var(--accent); }
[aria-checked="true"] .check svg { opacity: 1; }
[aria-checked="true"] .row-title { color: var(--text-2); }

.progress-meter {
  height: 6px; border-radius: 999px; background: var(--sunken); overflow: hidden;
}
.progress-meter > span {
  display: block; height: 100%; background: var(--accent); border-radius: 999px;
  transition: width 250ms ease;
}

/* ---------- Plan chips (what's on today) ---------- */

.plan-grid { display: grid; gap: var(--s2); }
.plan-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), var(--edge);
}
.plan-item .row-icon { background: var(--accent-soft); color: var(--accent); }
.plan-item.quiet .row-icon { background: var(--sunken); color: var(--text-2); }

/* ---------- Buttons & inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--hit);
  padding: 0 var(--s4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--raised);
  font-weight: var(--w-medium);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
}
.btn:active { background: var(--sunken); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:active { background: var(--accent-press); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--accent); padding: 0 var(--s2); }
.btn-ghost:active { background: var(--accent-soft); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: var(--s2); flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

.field { display: flex; flex-direction: column; gap: var(--s1); }
.field label { font-size: var(--t-secondary); font-weight: var(--w-medium); }

.input {
  min-height: var(--hit);
  width: 100%;
  padding: 0 var(--s3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--sunken);
  font-size: var(--t-body); /* 16px stops iOS zooming in */
}
.input::placeholder { color: var(--text-2); opacity: 0.55; }
.input:disabled { opacity: 0.6; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.input-unit { position: relative; flex: 1; min-width: 0; }
.input-unit .input { padding-right: 40px; }
.input-unit span {
  position: absolute; right: var(--s3); top: 50%; transform: translateY(-50%);
  font-size: var(--t-secondary); color: var(--text-2); pointer-events: none;
}

.inline-form { display: flex; gap: var(--s2); align-items: stretch; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

/* Day-of-week toggles in Settings */
.day-picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--s1); }
.day-chip {
  min-height: var(--hit);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--raised);
  font-size: var(--t-secondary);
  font-weight: var(--w-medium);
  cursor: pointer;
}
.day-chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------- Weight screen ---------- */

.hero { display: flex; flex-direction: column; gap: var(--s2); }
.hero-value {
  font-size: var(--t-hero); font-weight: var(--w-semi);
  line-height: 1.05; letter-spacing: -0.02em;
}
.hero-value small { font-size: var(--t-h3); font-weight: var(--w-medium); color: var(--text-2); letter-spacing: 0; margin-left: var(--s1); }
.hero-facts { display: flex; flex-wrap: wrap; gap: var(--s2); }
.pill {
  display: inline-flex; align-items: center; gap: var(--s1);
  font-size: var(--t-secondary);
  padding: var(--s1) var(--s3);
  border-radius: 999px;
  background: var(--sunken);
  color: var(--text);
}
.pill.good { background: var(--accent-soft); }

.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; overflow: visible; }
.chart-legend { display: flex; gap: var(--s4); flex-wrap: wrap; margin-top: var(--s3); }
.legend-item { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--t-meta); color: var(--text-2); }
.legend-key { width: 16px; height: 0; border-top: 2px solid var(--accent); }
.legend-key.pace { border-top: 2px dashed var(--text-2); opacity: 0.7; }
.legend-key.dot { width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--accent-tint); }

.chart-tip {
  position: absolute; z-index: 2;
  pointer-events: none;
  background: var(--raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.07);
  padding: var(--s2) var(--s3);
  font-size: var(--t-secondary);
  line-height: 1.4;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 12px));
}
.chart-tip.below { transform: translate(-50%, 16px); }
.chart-tip[hidden] { display: none; }
.chart-tip strong { font-weight: var(--w-semi); }

.week-row { display: grid; grid-template-columns: 1fr auto; gap: var(--s1) var(--s3); padding: var(--s3) var(--s4); }
.week-row .avg { font-weight: var(--w-semi); text-align: right; }
.week-row .readings { grid-column: 1 / -1; }

/* ---------- Tab bar ---------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--raised) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--hit);
  color: var(--text-2);
  text-decoration: none;
  font-size: var(--t-meta);
  font-weight: var(--w-medium);
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--accent); }

/* Shared icon look */
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* Toast for "Saved" etc. */
.toast {
  position: fixed; left: 50%; z-index: 20;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s4));
  transform: translateX(-50%);
  background: var(--text); color: var(--canvas);
  padding: var(--s2) var(--s4);
  border-radius: 999px;
  font-size: var(--t-secondary);
  font-weight: var(--w-medium);
  transition: opacity 200ms ease;
}

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

/* ---------- Lift screen ---------- */

.plan-item.is-link { text-decoration: none; color: inherit; }
.plan-item.is-link:active { background: var(--sunken); }
.plan-cta {
  display: inline-flex; align-items: center; gap: 2px;
  color: var(--accent); font-size: var(--t-secondary); font-weight: var(--w-medium);
}
.plan-cta .icon { width: 16px; height: 16px; }

.exercise { display: flex; flex-direction: column; gap: var(--s2); }
.ex-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }

.tip {
  display: flex; align-items: flex-start; gap: var(--s2);
  padding: var(--s2) var(--s3);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  font-size: var(--t-secondary);
}
.tip .icon { flex: none; width: 16px; height: 16px; margin-top: 2px; color: var(--accent); }

.set-grid { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s1); }
.set-row { display: grid; align-items: center; gap: var(--s2); }
.set-grid.two .set-row { grid-template-columns: 32px 1fr 1fr 28px; }
.set-grid.one .set-row { grid-template-columns: 32px 1fr 28px; }
.set-head { font-size: var(--t-meta); color: var(--text-2); font-weight: var(--w-medium); text-align: center; }
.set-num { text-align: center; color: var(--text-2); font-size: var(--t-secondary); }
.set-head .set-num { font-size: var(--t-meta); }
.set-row .input { text-align: center; padding: 0 var(--s2); }
.set-check {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--border);
  transition: background-color 150ms ease, border-color 150ms ease;
}
.set-check svg { width: 14px; height: 14px; fill: none; stroke: var(--on-accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.set-row.is-done .set-check { background: var(--accent); border-color: var(--accent); }
.set-row.is-done .set-check svg { opacity: 1; }

.plain-list { list-style: none; margin: var(--s3) 0 0; padding: 0; }
.plain-list li {
  display: flex; justify-content: space-between; gap: var(--s3);
  padding: var(--s2) 0;
  border-top: 1px solid var(--border);
}
