/* ---- tokens (defined once; everything composes from these) ---- */
:root {
  --canvas: #F2F2F7;
  --surface: #FFFFFF;
  --ink: #1C1C1E;
  --ink-2: #6E6E73;
  --ink-3: #AEAEB2;
  --line: rgba(60, 60, 67, 0.12);
  --accent: #0E7A57;
  --accent-bg: rgba(14, 122, 87, 0.10);
  --danger: #D23C3C;
  --amber: #B25E09;
  --r-card: 16px;
  --r-ctl: 10px;
  --pad: 16px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--canvas);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.35;
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---- header ---- */
.top { padding: max(14px, env(safe-area-inset-top)) var(--pad) 8px; }
.top-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.subtitle { color: var(--ink-2); font-size: 15px; margin-top: 2px; }

.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.sync.busy .sync-dot { background: var(--ink-3); animation: pulse 1s infinite; }
.sync.err { color: var(--danger); } .sync.err .sync-dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---- segmented control ---- */
.seg { display: flex; background: rgba(118, 118, 128, 0.12); border-radius: 9px; padding: 2px; margin-top: 14px; }
.seg-btn { flex: 1; border: 0; background: transparent; border-radius: 7px; padding: 7px 0;
  font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer; }
.seg-btn[aria-selected="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,0.10); }

/* ---- week bar + day strip ---- */
.weekbar { display: flex; align-items: center; justify-content: center; gap: 4px; margin: 14px var(--pad) 8px; }
.wk-arrow { width: 36px; height: 36px; border: 0; background: var(--surface); border-radius: 50%;
  font-size: 20px; color: var(--accent); cursor: pointer; border: 1px solid var(--line); line-height: 1; }
.wk-label { border: 0; background: none; font-size: 16px; font-weight: 700; padding: 6px 14px; cursor: pointer; min-width: 150px; }
.wk-label small { display: block; font-size: 12px; font-weight: 500; color: var(--ink-2); }

.daystrip { display: flex; gap: 6px; padding: 0 var(--pad) 4px; }
.day-chip { flex: 1; border: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 7px 0 6px; text-align: center; cursor: pointer; transition: background 0.15s var(--ease); }
.day-chip .dw { display: block; font-size: 11px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; }
.day-chip .dn { display: block; font-size: 16px; font-weight: 700; margin-top: 1px; }
.day-chip .dot { display: block; width: 4px; height: 4px; border-radius: 50%; margin: 3px auto 0; background: transparent; }
.day-chip.has-data .dot { background: var(--accent); }
.day-chip.today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.day-chip[aria-selected="true"] { background: var(--accent); border-color: var(--accent); }
.day-chip[aria-selected="true"] .dw, .day-chip[aria-selected="true"] .dn { color: #fff; }
.day-chip[aria-selected="true"] .dot { background: rgba(255,255,255,0.7); }
.day-chip:disabled { opacity: 0.35; cursor: default; }

/* ---- cards (iOS inset grouped) ---- */
.view { padding: 8px var(--pad) 24px; display: flex; flex-direction: column; gap: 14px; max-width: 560px; margin: 0 auto; width: 100%; }
.card { background: var(--surface); border-radius: var(--r-card); border: 1px solid var(--line); overflow: hidden; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; padding: 12px var(--pad) 0; }
.card-h h2 { font-size: 13px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.card-h .meta { font-size: 13px; color: var(--ink-2); }
.card-body { padding: 10px var(--pad) 14px; }

/* rows inside cards: label left, control right (iOS settings) */
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.row + .row { border-top: 1px solid var(--line); }
.row label, .row .lbl { font-size: 16px; color: var(--ink); }
.row .unit { color: var(--ink-3); font-size: 14px; margin-left: 4px; }

.num { border: 0; background: none; text-align: right; font-size: 17px; font-weight: 600; width: 96px;
  color: var(--ink); padding: 10px 0; }
.row-ctl { display: inline-flex; align-items: center; gap: 8px; }
.use-avg { border: 0; background: var(--accent-bg); color: var(--accent); font-size: 13px; font-weight: 600;
  border-radius: 999px; padding: 5px 10px; cursor: pointer; }
.num::placeholder { color: var(--ink-3); font-weight: 400; }

/* big hero input (weight) */
.hero { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 6px 0 2px; }
.hero input { border: 0; background: none; font-size: 56px; font-weight: 800; letter-spacing: -0.03em;
  width: 200px; text-align: center; color: var(--ink); font-variant-numeric: tabular-nums; }
.hero input::placeholder { color: var(--ink-3); font-weight: 300; }
.hero .unit { font-size: 20px; font-weight: 600; color: var(--ink-2); }
.delta { text-align: center; font-size: 14px; font-weight: 600; padding-bottom: 10px; color: var(--ink-2); }
.delta.down { color: var(--accent); } .delta.up { color: var(--amber); }

/* chips (macro day) */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 10px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--canvas); border-radius: 999px; padding: 7px 14px;
  font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* macro grid */
.macro-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding-top: 4px; }
.macro-cell { background: var(--canvas); border-radius: var(--r-ctl); padding: 8px 6px 6px; text-align: center; }
.macro-cell label { display: block; font-size: 11px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; }
.macro-cell input { border: 0; background: none; width: 100%; text-align: center; font-size: 18px; font-weight: 700; padding: 4px 0 0; }
.macro-cell input::placeholder { color: var(--ink-3); font-weight: 400; }
.cal-line { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; font-size: 15px; color: var(--ink-2); }
.cal-line strong { font-size: 17px; color: var(--ink); font-variant-numeric: tabular-nums; }

/* 1-5 scale segmented */
.scale { display: flex; gap: 6px; }
.scale button { width: 38px; height: 34px; border: 1px solid var(--line); background: var(--canvas);
  border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.scale button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* iOS switch */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.knob { position: absolute; inset: 0; background: rgba(118,118,128,0.20); border-radius: 999px; transition: background 0.2s var(--ease); pointer-events: none; }
.knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.2); transition: transform 0.2s var(--ease); }
.switch input:checked + .knob { background: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(20px); }
.switch input:focus-visible + .knob { outline: 2px solid var(--accent); outline-offset: 2px; }

textarea { width: 100%; border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--canvas);
  padding: 10px 12px; font-size: 16px; min-height: 76px; resize: vertical; margin-top: 8px; }
textarea::placeholder { color: var(--ink-3); }

/* disclosure (health markers) */
.disclose { width: 100%; display: flex; justify-content: space-between; align-items: center;
  background: none; border: 0; padding: 13px 0; font-size: 16px; color: var(--ink); cursor: pointer; }
.disclose .chev { color: var(--ink-3); transition: transform 0.2s var(--ease); font-size: 14px; }
.disclose[aria-expanded="true"] .chev { transform: rotate(90deg); }

/* buttons */
.btn-primary { display: block; width: 100%; border: 0; background: var(--accent); color: #fff;
  font-size: 17px; font-weight: 600; padding: 14px; border-radius: 12px; cursor: pointer; margin-top: 14px; }
.btn-primary:active { opacity: 0.85; }
.btn-ghost { display: inline-flex; align-items: center; gap: 6px; border: 1px dashed var(--ink-3); color: var(--ink-2);
  background: none; border-radius: var(--r-ctl); padding: 10px 14px; font-size: 15px; font-weight: 600; cursor: pointer; }

/* weekly summary */
.sum-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; padding-top: 6px; }
.sum-cell { text-align: center; padding: 8px 2px; }
.sum-cell .v { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sum-cell .k { font-size: 12px; color: var(--ink-2); margin-top: 1px; }
.spark { width: 100%; height: 56px; margin-top: 10px; }

/* photos */
.photo-grid { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 0 4px; }
.photo-grid img { width: 84px; height: 112px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.empty { color: var(--ink-3); font-size: 15px; padding: 10px 0; }

/* coach card */
.coach-block { padding: 8px 0; }
.coach-block + .coach-block { border-top: 1px solid var(--line); }
.coach-block .k { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.coach-block .v { font-size: 15px; margin-top: 3px; white-space: pre-wrap; }
.coach-block .v.none { color: var(--ink-3); }

/* guides */
.g-row { display: flex; justify-content: space-between; align-items: center; width: 100%;
  border: 0; background: none; padding: 15px var(--pad); font-size: 17px; color: var(--ink);
  cursor: pointer; text-align: left; }
.g-row + .g-row { border-top: 1px solid var(--line); }
.g-row .chev { color: var(--ink-3); font-size: 18px; }
.g-row:active { background: var(--canvas); }

.g-back { border: 0; background: none; color: var(--accent); font-size: 17px; font-weight: 600;
  padding: 2px 0 6px; cursor: pointer; text-align: left; width: fit-content; }

.g-reader { display: flex; flex-direction: column; gap: 14px; }
.g-reader .card { padding: 4px var(--pad) 14px; }
.g-kv.card { padding: 4px var(--pad); }
.g-kv .g-val { font-weight: 600; text-align: right; }
.g-sec h2 { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; margin: 14px 0 4px; }
.g-when { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 6px; }
.g-macro { display: inline-block; font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-bg); border-radius: 999px; padding: 3px 9px; margin-left: 8px;
  vertical-align: 2px; letter-spacing: 0.01em; }
.g-sec p { font-size: 16px; line-height: 1.55; margin: 8px 0; }
.g-sec ul { list-style: none; margin-top: 6px; }
.g-sec li { font-size: 16px; line-height: 1.5; padding: 9px 0 9px 18px; position: relative; }
.g-sec li::before { content: ""; position: absolute; left: 2px; top: 18px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--accent); opacity: 0.55; }
.g-sec li + li { border-top: 1px solid var(--line); }
.g-sec li em { color: var(--ink-2); font-style: normal; }
.g-list { display: block; color: var(--ink-2); font-size: 15px; line-height: 1.6; margin-top: 6px; }
.g-note { background: var(--canvas); border-radius: var(--r-ctl); padding: 10px 12px !important;
  font-size: 15px !important; color: var(--ink-2); }

/* whoop strip */
.wh-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 8px; padding-top: 6px; }
.wh-cell { text-align: center; padding: 6px 2px; }
.wh-cell .v { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; gap: 5px; }
.wh-cell .k { font-size: 12px; color: var(--ink-2); margin-top: 1px; }
.wh-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.wh-high .wh-dot { background: var(--accent); } .wh-high { color: var(--accent); }
.wh-mid .wh-dot { background: var(--amber); } .wh-mid { color: var(--amber); }
.wh-low .wh-dot { background: var(--danger); } .wh-low { color: var(--danger); }

.wh-detail { border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; }
.whd-sub { font-size: 14px; color: var(--ink-2); margin-bottom: 8px; }
.whd-grp { font-size: 12px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; margin: 14px 0 2px; }
.whd-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%;
  border: 0; background: none; padding: 12px 0; cursor: pointer; text-align: left; border-top: 1px solid var(--line); }
.whd-l { display: flex; flex-direction: column; gap: 1px; }
.whd-k { font-size: 16px; font-weight: 600; color: var(--ink); }
.whd-s { font-size: 13px; color: var(--ink-2); }
.whd-v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.whd-v .chev { color: var(--ink-3); font-weight: 400; }

/* learn layer: tappable terms + bottom sheet */
.term { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer;
  border-bottom: 1.5px dotted var(--accent); }
.term:active { background: var(--accent-bg); }
.term-pill { cursor: pointer; }
.term-hint { font-size: 13px; color: var(--ink-2); text-align: center; padding: 2px 0 6px; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; transition: background 0.2s var(--ease); }
.sheet-backdrop.in { background: rgba(0,0,0,0.35); }
.sheet { background: var(--surface); border-radius: 20px 20px 0 0; width: 100%; max-width: 560px;
  max-height: 78dvh; overflow-y: auto; padding: 8px var(--pad) max(20px, env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 0.25s var(--ease); }
.sheet-backdrop.in .sheet { transform: translateY(0); }
.sheet-grab { width: 36px; height: 5px; border-radius: 999px; background: var(--line); margin: 6px auto 14px; }
.sheet h3 { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 8px; }
.sheet-body p { font-size: 16px; line-height: 1.55; margin: 8px 0; color: var(--ink); }
.sheet-math { background: var(--accent-bg); border-radius: var(--r-ctl); padding: 12px 14px; margin-top: 12px; }
.sheet-math .k { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.sheet-math p:last-child { font-size: 15px; line-height: 1.5; }
.sheet-impact { background: var(--canvas); border-radius: var(--r-ctl); padding: 12px 14px; margin-top: 10px; }
.sheet-impact .k { font-size: 12px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.sheet-impact p:last-child { font-size: 15px; line-height: 1.5; }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { transition: none; } }

/* gate */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: 100%; max-width: 320px; text-align: center; }
.gate-mark { display: block; width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 16px; }
.gate h1 { font-size: 28px; }
.gate-sub { color: var(--ink-2); margin: 6px 0 18px; }
.gate input { width: 100%; text-align: center; font-size: 24px; letter-spacing: 0.3em; padding: 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.gate-err { color: var(--danger); font-size: 14px; margin-top: 10px; }
.ts-widget { display: flex; justify-content: center; margin-top: 12px; min-height: 0; }

@media (min-width: 640px) { .daystrip, .weekbar { max-width: 560px; margin-left: auto; margin-right: auto; } .top { max-width: 592px; margin: 0 auto; } }
