:root {
  --bg: #f6f4f2;
  --card: #ffffff;
  --card-2: #efebe7;
  --text: #1b1714;
  --muted: #776d66;
  --line: #e6e0da;
  --accent: #d9733b;
  --accent-ink: #b35a24;
  --accent-soft: #fbeadf;
  --good: #1f9d55;
  --good-soft: #def5e7;
  --danger: #d93838;
  --gold: #c98a00;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabs-h: 0px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --card: #1d1b19;
    --card-2: #2a2724;
    --text: #f3f0ed;
    --muted: #a0968e;
    --line: #34302c;
    --accent: #e07f48;
    --accent-ink: #f0985f;
    --accent-soft: #3a2416;
    --good: #3ccf7a;
    --good-soft: #163324;
    --danger: #f06363;
    --gold: #f5c542;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding-bottom: calc(var(--tabs-h) + var(--safe-b));
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Pages stack from the bottom, nearest the thumb */
main {
  max-width: 640px; margin: 0 auto;
  padding: calc(var(--safe-t) + 14px) 16px 26px;
  min-height: calc(100vh - var(--tabs-h) - var(--safe-b));
  min-height: calc(100dvh - var(--tabs-h) - var(--safe-b));
  display: flex; flex-direction: column; justify-content: flex-end;
}
main > * { flex-shrink: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.page-head h1 { font-size: 28px; margin: 0; letter-spacing: -.02em; }


.card { background: var(--card); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card h2, .section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.section-title { margin: 14px 2px 10px; display: flex; justify-content: space-between; align-items: center; }
.section-title button { text-transform: none; letter-spacing: 0; font-size: 16px; color: var(--accent-ink); font-weight: 600; padding: 6px 2px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 14px 16px; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 17px;
  transition: transform .12s ease-out, opacity .12s ease-out;
}
.btn:active { transform: scale(.98); opacity: .9; }
.btn.soft { background: var(--accent-soft); color: var(--accent-ink); }
.btn.ghost { background: var(--card-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); font-weight: 600; }
.btn.good { background: var(--good); }
.btn.small { width: auto; padding: 9px 16px; font-size: 16px; border-radius: 10px; }
.link { color: var(--accent-ink); font-weight: 600; font-size: 16px; padding: 10px 4px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

/* Weekly chart */
.chart { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; align-items: end; height: 132px; }
.bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar-val { font-size: 12px; font-weight: 600; color: var(--muted); }
.bar { width: 100%; max-width: 30px; background: var(--accent); border-radius: 6px 6px 3px 3px; min-height: 3px; transform-origin: bottom; animation: grow .4s ease-out both; }
.bar.zero { background: var(--line); }
.bar-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
@keyframes grow { from { transform: scaleY(0); } }

/* Lists */
.list { background: var(--card); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--card); }
.item:last-child { border-bottom: 0; }
button.item:active { background: var(--card-2); }
.item .title { font-weight: 600; }
.item .sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); width: 18px; height: 18px; flex: none; }
.group-label { font-size: 13px; font-weight: 600; color: var(--muted); padding: 16px 4px 6px; text-transform: uppercase; letter-spacing: .06em; }
.check-dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; }
.check-dot svg { width: 16px; height: 16px; stroke-width: 3; }
.item.picked .check-dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.item.picked { background: var(--accent-soft); }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--card-2); color: var(--muted); }

.routine { text-align: left; width: 100%; display: flex; flex-direction: column; justify-content: flex-start; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; transition: transform .15s ease-out; }
.routine.pressing { transform: scale(.97); }
.routine .title { font-weight: 700; font-size: 17px; margin-bottom: 4px; }
.routine .sub { color: var(--muted); font-size: 14px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.routines { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.routines .card { margin: 0; }
.hint { font-size: 13px; color: var(--muted); text-align: center; margin: 4px 0 12px; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; font-size: 15px; }

input.field, select.field {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-size: 16px; outline: none;
}
input.field:focus { border-color: var(--accent); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; touch-action: pan-x; }
.chips * { touch-action: pan-x; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 99px; background: var(--card); font-size: 14px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Search dock on the Exercises page, just above the tab bar */
.dock { position: sticky; bottom: calc(var(--tabs-h) + var(--safe-b)); background: var(--bg); padding: 10px 0 4px; margin-top: 8px; z-index: 3; }
.dock .row input { flex: 1; }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head strong { font-size: 17px; }
.cal-head button { width: 44px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: var(--accent-ink); background: var(--card-2); }
.cal-head button svg { width: 20px; height: 20px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal .dow { font-size: 12px; color: var(--muted); padding-bottom: 4px; }
.cal .day { aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; font-size: 15px; }
.cal .day.has { background: var(--accent); color: #fff; font-weight: 700; }
.cal .day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal .day.out { visibility: hidden; }

/* Sheets: actions sit in a bar at the bottom */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); animation: fade .2s ease-out both; }
.sheet {
  position: relative; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 8px 16px 0;
  display: flex; flex-direction: column;
  animation: up .25s ease-out both;
  -webkit-overflow-scrolling: touch;
}
.sheet > * { flex-shrink: 0; }
.sheet.full { height: 100%; max-height: none; border-radius: 0; padding-top: calc(var(--safe-t) + 10px); }
.sheet-title { margin: 6px 0 12px; font-size: 22px; letter-spacing: -.01em; }
.sheet-foot {
  order: 99; position: sticky; bottom: 0; z-index: 3; margin-top: auto;
  background: var(--bg); border-top: 1px solid var(--line);
  margin-left: -16px; margin-right: -16px; padding: 8px 16px calc(10px + var(--safe-b));
}
.foot-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.foot-mid { flex: 1; text-align: center; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.sheet-pad { height: 16px; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 2px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* Active workout */
.w-title { font-size: 24px; font-weight: 700; border: 0; background: transparent; width: 100%; padding: 4px 0; outline: none; }
.w-meta { color: var(--muted); font-size: 15px; margin-bottom: 14px; }
.ex-card { background: var(--card); border-radius: 14px; padding: 12px 10px 8px; margin-bottom: 12px; box-shadow: var(--shadow); }
.ex-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 8px; }
.ex-head .name { color: var(--accent-ink); font-weight: 700; font-size: 17px; text-align: left; }
.ex-head .more { width: 40px; height: 32px; border-radius: 8px; background: var(--card-2); display: grid; place-items: center; color: var(--accent-ink); flex: none; }
.ex-head .more svg { width: 18px; height: 18px; }
.set-row {
  display: grid; grid-template-columns: 34px 1fr 64px 52px 50px 40px; gap: 4px; align-items: center;
  padding: 2px; border-radius: 8px; background: var(--card); font-variant-numeric: tabular-nums; text-align: center;
}
.set-row.head { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding-bottom: 2px; }
.swipe { position: relative; overflow: hidden; border-radius: 8px; margin-bottom: 4px; }
.swipe-bg { position: absolute; inset: 0; background: var(--danger); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: flex-end; padding-right: 16px; border-radius: 8px; }
.swipe .set-row { position: relative; touch-action: pan-y; }
.swipe .set-row * { touch-action: pan-y; }
.set-row.done { background: color-mix(in srgb, var(--good-soft) 100%, var(--card)); }
.set-row .num { width: 30px; height: 30px; border-radius: 8px; background: var(--card-2); font-weight: 700; font-size: 15px; }
.set-row .prev { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; }
.set-row .prev button { color: inherit; padding: 6px 0; }
.set-row input, .set-row select {
  width: 100%; height: 34px; border: 0; border-radius: 8px; background: var(--card-2);
  text-align: center; font-size: 16px; font-weight: 600; outline: none; padding: 0 2px;
  -webkit-appearance: none; appearance: none; text-align-last: center;
}
.set-row input::placeholder { color: var(--muted); font-weight: 500; opacity: .8; }
.set-row.done input, .set-row.done select { background: transparent; }
.set-row select.empty { color: var(--muted); }
.tick { width: 36px; height: 34px; border-radius: 8px; background: var(--card-2); display: grid; place-items: center; color: var(--muted); }
.tick svg { width: 18px; height: 18px; stroke-width: 3; }
.done .tick { background: var(--good); color: #fff; }
.add-set { width: 100%; padding: 9px; border-radius: 10px; background: var(--card-2); font-weight: 600; font-size: 15px; margin-top: 2px; }

/* Routine editor */
.r-ex { display: flex; align-items: center; gap: 8px; position: relative; transition: transform .15s ease-out; }
.r-ex.dragging { transition: none; z-index: 2; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.drag-handle { width: 32px; height: 40px; display: grid; place-items: center; color: var(--muted); touch-action: none; flex: none; }
.drag-handle * { touch-action: none; }
.drag-handle svg { width: 20px; height: 20px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 32px; height: 32px; border-radius: 8px; background: var(--card-2); font-weight: 700; font-size: 18px; color: var(--accent-ink); }
.stepper span { min-width: 50px; text-align: center; font-size: 14px; color: var(--muted); }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn svg { width: 18px; height: 18px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat-grid div { background: var(--card); border-radius: 12px; padding: 10px 4px; }
.stat-grid strong { display: block; font-size: 18px; }
.stat-grid span { font-size: 12px; color: var(--muted); }
.pr { color: var(--gold); font-weight: 700; }
.trophy { font-size: 44px; text-align: center; margin: 8px 0 0; }
.set-line { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; font-size: 15px; }
.set-line .n { color: var(--muted); width: 28px; }


.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 12px); transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 15px;
  animation: drop .2s ease-out both; max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 14px; white-space: nowrap;
}
.toast button { color: var(--accent); font-weight: 700; padding: 4px 2px; }
.toast[hidden] { display: none; }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -8px); } }

.future { margin: 0; padding-left: 18px; }
.future li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.future li:last-child { border-bottom: 0; }
.future .why { display: block; font-size: 13px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.routine .last { margin-top: auto; padding-top: 8px; font-size: 13px; font-weight: 600; color: var(--accent-ink); }

/* No tab bar: Workout is home; other pages have a back button at the bottom */
.start-row { display: flex; gap: 10px; }
.start-row .btn { flex: 1; }
.gear { width: 54px; flex: none; border-radius: 12px; background: var(--card-2); color: var(--text); display: grid; place-items: center; }
.gear svg { width: 24px; height: 24px; }
.chart-card { display: block; width: 100%; text-align: left; }
.page-foot { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0 0; margin-top: 12px; z-index: 3; }
.back { display: inline-flex; align-items: center; gap: 2px; height: 46px; padding: 0 16px 0 10px; border-radius: 12px; background: var(--card-2); font-weight: 600; color: var(--accent-ink); flex: none; }
.back svg { width: 20px; height: 20px; }
