/* Design tokens: 5 colors, one type scale, 8px grid */
/* Light theme, locked (no dark variant by user request) */
:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --text: #1b2228;
  --muted: #5f6d78;
  --accent: #8a5600;
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --soft: color-mix(in srgb, var(--text) 7%, transparent);
  --on-accent: #ffffff;
  --fs-1: 13px; --fs-2: 15px; --fs-3: 17px; --fs-4: 22px; --fs-5: 40px;
  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px; --s5: 40px;
  --r: 12px; --r-sm: 8px;
  --tab-h: 60px;
  color-scheme: light;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

* { box-sizing: border-box; }
:root { accent-color: var(--accent); caret-color: var(--accent); scrollbar-color: var(--muted) transparent; }
::selection { background: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--text); }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: var(--fs-2)/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
main { max-width: 640px; margin: 0 auto; padding: var(--s2) var(--s2) var(--s3); padding-top: calc(var(--s2) + env(safe-area-inset-top)); }
h1 { font-size: var(--fs-4); font-weight: 650; margin: 0 0 var(--s2); letter-spacing: -0.01em; }
h2 { font-size: var(--fs-1); font-weight: 600; color: var(--muted); margin: var(--s4) 0 var(--s1); }
p { margin: 0 0 var(--s1); }
p:last-child { margin-bottom: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-1); }
.big { font-size: var(--fs-3); }
.center { text-align: center; }
.mt1 { margin-top: var(--s1); } .mt2 { margin-top: var(--s2); } .mt3 { margin-top: var(--s3); }
.mb1 { margin-bottom: var(--s1); } .mb2 { margin-bottom: var(--s2); }

/* Card: title + body, never nested */
.card { background: var(--surface); border-radius: var(--r); padding: var(--s2); margin-bottom: var(--s2); }
.card > h3, .card-title { font-size: var(--fs-3); font-weight: 650; margin: 0 0 var(--s1); }
.row { display: flex; gap: var(--s1); align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s1); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s1); }
.stack > * + * { margin-top: var(--s1); }
.list > * { padding: 10px 0; border-bottom: 1px solid var(--line); }
.list > *:last-child { border-bottom: 0; }

/* Buttons: 44px min, no gradients */
button, .btn {
  font: inherit; font-size: var(--fs-2);
  min-height: 44px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--soft); color: var(--text);
  cursor: pointer; touch-action: manipulation; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
button:active { opacity: .8; }
button:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 650; }
.btn-outline { background: transparent; border-color: var(--muted); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-block { width: 100%; }
.btn-tall { min-height: 56px; font-size: var(--fs-3); }
.btn-sm { min-height: 44px; padding: 6px 10px; font-size: var(--fs-1); }
.btn-icon { width: 44px; padding: 0; flex: none; font-size: var(--fs-3); }
:is(button, a, input, select, summary, [tabindex]):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Chips: tap-only choices */
.chips { display: flex; flex-wrap: wrap; gap: var(--s1); }
.chip { min-height: 44px; min-width: 44px; padding: 8px 14px; border-radius: 999px; background: var(--soft); border: 1px solid transparent; color: var(--text); font-size: var(--fs-2); }
.chip.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 650; }
.chips.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); }
.chips.grid .chip { padding: 8px 4px; border-radius: var(--r-sm); }
.chips.stretch .chip { flex: 1; }

/* Inputs */
input, select { font: inherit; font-size: 16px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 9px 12px; min-height: 44px; width: 100%; }
input[type="range"] { -webkit-appearance: none; appearance: none; height: 44px; background: transparent; border: 0; padding: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--soft); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); margin-top: -11px; border: 0; }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--soft); }
input[type="range"]::-moz-range-thumb { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); border: 0; }
label { display: block; font-size: var(--fs-1); color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: var(--s2); }
.field:last-child { margin-bottom: 0; }

/* Disclosure */
details { border-top: 1px solid var(--line); }
details:first-of-type { border-top: 0; }
summary { list-style: none; cursor: pointer; min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: var(--s1); padding: 10px 0; font-weight: 600; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--muted); font-size: var(--fs-4); line-height: 1; font-weight: 400; }
details[open] > summary::after { content: "−"; }
.details-body { padding: 0 0 var(--s2); }

/* Checklist */
.check { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; min-height: 44px; cursor: pointer; border-bottom: 1px solid var(--line); }
.check:last-child { border-bottom: 0; }
.check input { width: 24px; height: 24px; min-height: 0; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.check.done span { text-decoration: line-through; color: var(--muted); }

/* Progress ring hero */
.hero { display: flex; gap: var(--s2); align-items: center; }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { display: block; transform: rotate(-90deg); }
.ring .in { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .n { font-size: var(--fs-5); font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.ring .l { font-size: var(--fs-1); color: var(--muted); margin-top: 4px; }
.stats { display: grid; grid-template-columns: 1fr; gap: var(--s1); }
.stat b { display: block; font-size: var(--fs-4); font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { font-size: var(--fs-1); color: var(--muted); }
.stat.wide { grid-column: 1 / -1; }

/* Badge (text only) */
.badge { display: inline-block; font-size: var(--fs-1); padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.badge.up { background: var(--accent); color: var(--on-accent); font-weight: 650; }
.badge.done { border: 1px solid var(--accent); color: var(--accent); background: transparent; }

/* Rule note (border only, no nested card) */
.rule { padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.rule b { color: var(--accent); }
.warn { color: var(--muted); padding: 8px 0 0; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: var(--fs-2); font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: var(--fs-1); }
tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Report string */
pre.rep { white-space: pre-wrap; word-break: break-word; background: var(--bg); border-radius: var(--r-sm); padding: 12px; margin: 0 0 var(--s1); font: var(--fs-2)/1.5 ui-monospace, Menlo, monospace; }

/* Calendar heatmap */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { font-size: 11px; color: var(--muted); text-align: center; padding-bottom: 2px; }
.cal .d { aspect-ratio: 1; border-radius: 6px; background: var(--soft); font-size: 12px; display: flex; align-items: center; justify-content: center; color: var(--muted); position: relative; }
.cal .d.free { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.cal .d.slip { background: transparent; border: 2px solid var(--text); color: var(--text); font-weight: 600; }
.cal .d.today { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.cal .d.future { opacity: .4; }
.legend { display: flex; gap: var(--s2); font-size: var(--fs-1); color: var(--muted); margin-top: var(--s1); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }

/* Charts (inline SVG) */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar.empty { fill: var(--soft); }
.chart .goal { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart text { fill: var(--muted); font-size: 11px; }
.spark { width: 100%; height: 36px; display: block; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark circle { fill: var(--accent); }

/* Bottom tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--surface); border-top: 1px solid var(--line); display: flex; padding: 4px 0 env(safe-area-inset-bottom); }
.tabs a { flex: 1; color: var(--muted); text-decoration: none; font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; border-radius: var(--r-sm); }
.tabs a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: var(--accent); }
.tabs a.on svg { stroke-width: 2.2; }

/* Sheet / full-screen flow */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 70%, transparent); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh; overflow: auto; border-radius: 18px 18px 0 0; padding: var(--s2) var(--s2) calc(var(--s2) + env(safe-area-inset-bottom)); }
.sheet-wrap.full { align-items: stretch; }
.sheet-wrap.full .sheet { max-height: none; border-radius: 0; height: 100%; display: flex; flex-direction: column; padding-top: calc(var(--s2) + env(safe-area-inset-top)); }
.sheet .body { flex: 1; overflow: auto; }
.sheet .foot { padding-top: var(--s2); display: grid; grid-template-columns: 1fr 2fr; gap: var(--s1); }
.sheet .foot.single { grid-template-columns: 1fr; }
.dots { display: flex; gap: 6px; justify-content: center; margin: var(--s1) 0 var(--s2); }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--soft); }
.dots i.on { background: var(--accent); }
.dots i.done { background: var(--muted); }
.q { font-size: var(--fs-4); font-weight: 650; margin: var(--s2) 0; line-height: 1.25; }
.timer { font-size: 56px; font-weight: 700; text-align: center; letter-spacing: -0.02em; margin: var(--s2) 0; font-variant-numeric: tabular-nums; }
.bignum { font-size: var(--fs-5); font-weight: 700; text-align: center; line-height: 1.1; font-variant-numeric: tabular-nums; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 12px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; background: var(--text); color: var(--bg); padding: 6px 6px 6px 16px; border-radius: 999px; font-size: var(--fs-2); font-weight: 600; display: flex; align-items: center; gap: 12px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); white-space: nowrap; }
.toast.show { opacity: 1; pointer-events: auto; }
.toast button { min-height: 40px; padding: 4px 12px; border-radius: 999px; background: var(--bg); color: var(--text); border: 0; font-weight: 650; }

/* Workout session */
.ex-item { border-bottom: 1px solid var(--line); }
.ex-item:last-child { border-bottom: 0; }
.ex-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s1); min-height: 52px; padding: 8px 0; cursor: pointer; }
.ex-head .name { font-weight: 650; }
.ex-head .meta { font-size: var(--fs-1); color: var(--muted); }
.ex-body { padding-bottom: var(--s2); }
.setrow { display: grid; grid-template-columns: 40px 1fr 52px; gap: var(--s1); align-items: center; margin: 6px 0; }
.setrow .idx { font-size: var(--fs-1); color: var(--muted); }
.setrow .val { justify-content: flex-start; font-variant-numeric: tabular-nums; }
.setrow .val.done { border-color: var(--accent); }
.setrow .ok { width: 52px; padding: 0; }
.setrow .ok.done { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.editor { padding: 12px 0 12px 48px; margin: 0 0 8px; border-bottom: 1px solid var(--line); }
.editor .stack > * + * { margin-top: 6px; }
.chips.rir { grid-template-columns: repeat(5, 1fr); }
.stepper { display: grid; grid-template-columns: 44px 1fr 44px; gap: 4px; align-items: center; }
.stepper b { text-align: center; font-size: var(--fs-3); font-variant-numeric: tabular-nums; }
.stepper input { text-align: center; font-weight: 650; font-size: var(--fs-3); background: transparent; border-color: transparent; padding: 4px; }
.stepper input:focus { border-color: var(--line); background: var(--bg); }
.rest { position: sticky; top: 0; z-index: 3; background: var(--accent); color: var(--on-accent); border-radius: var(--r-sm); padding: 8px 8px 8px 16px; display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s2); font-weight: 650; font-variant-numeric: tabular-nums; }
.rest button { background: var(--on-accent); color: var(--accent); border: 0; min-height: 36px; }

.empty { color: var(--muted); padding: var(--s1) 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
