:root {
  --bg: #f4f1ec;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #677382;
  --line: #e4ded4;
  --brand: #1f4e79;
  --brand-soft: #e3ecf5;
  --accent: #e07a3f;
  --good: #2e8b57;
  --good-soft: #e2f2e8;
  --warn: #c0392b;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(29, 39, 51, .06), 0 4px 16px rgba(29, 39, 51, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720; --card: #17212c; --ink: #e8edf2; --muted: #93a1b0; --line: #26323f;
    --brand: #7fb0dc; --brand-soft: #1c2c3c; --accent: #f0955c; --good: #5cc28a; --good-soft: #17322a;
    --warn: #ef6f61; --shadow: none; color-scheme: dark;
  }
  .ex-img { filter: invert(.88) hue-rotate(180deg); }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin-bottom: .6rem; }
h3 { font-size: 1rem; }
p { margin: .3rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--warn); min-height: 1.2em; font-size: .9rem; }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(14px + var(--safe-t)) 18px 10px; display: flex; justify-content: space-between; align-items: flex-end;
}
.topbar h1 { font-size: 1.6rem; letter-spacing: -.01em; }
.eyebrow { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.week-pill { background: var(--brand); color: #fff; border-radius: 999px; padding: 5px 12px; font-size: .85rem; font-weight: 600; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .week-pill { color: #0f1720; } }
main { padding: 4px 16px calc(96px + var(--safe-b)); max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }

/* tab bar */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b));
}
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; padding: 4px 0; }
.tabs svg { width: 24px; height: 24px; fill: currentColor; }
.tabs a.active { color: var(--brand); }

/* hero / today */
.hero { background: var(--brand); color: #fff; border: none; }
.hero .eyebrow { color: rgba(255,255,255,.75); }
.hero h2 { font-size: 1.3rem; margin: 4px 0 2px; }
.hero p { color: rgba(255,255,255,.85); }
@media (prefers-color-scheme: dark) { .hero { background: #1f4e79; } }

.check { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.check:last-child { border-bottom: 0; }
.check input { appearance: none; -webkit-appearance: none; width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); flex: none; display: grid; place-items: center; transition: .15s; }
.check input:checked { background: var(--good); border-color: var(--good); }
.check input:checked::after { content: ""; width: 7px; height: 13px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -1px); }
.check .t { flex: 1; }
.check .t b { display: block; font-weight: 600; }
.check .t span { color: var(--muted); font-size: .85rem; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row label { font-weight: 600; }
.row .sub { color: var(--muted); font-size: .85rem; font-weight: 400; display: block; }

input, textarea, select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.num { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
textarea { min-height: 70px; resize: vertical; }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.stepper output { min-width: 2.5ch; text-align: center; font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--good); border-radius: 99px; transition: width .3s; }

.btn { font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer; background: var(--brand-soft); color: var(--brand); }
.btn.primary { background: var(--brand); color: #fff; width: 100%; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0f1720; } }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; }
.btns .btn { flex: 1; }

/* week strip */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.week div { padding: 8px 0; border-radius: 10px; background: var(--bg); font-size: .75rem; color: var(--muted); }
.week div b { display: block; font-size: .95rem; color: var(--ink); }
.week div.today { outline: 2px solid var(--brand); }
.week div.done { background: var(--good-soft); }
.week .dot { display: block; height: 6px; width: 6px; border-radius: 50%; margin: 4px auto 0; background: transparent; }
.week .dot.s { background: var(--accent); }
.week .dot.w { background: var(--brand); }

/* workout */
.ex { padding: 0; overflow: hidden; }
.ex-img { width: 100%; height: auto; aspect-ratio: auto; display: block; background: #fff; border-bottom: 1px solid var(--line); }
.ex-body { padding: 14px 16px 16px; }
.ex-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.reps { background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .85rem; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.ex ul { margin: .5rem 0 .3rem; padding-left: 1.1rem; }
.ex li { margin: .25rem 0; }
.tip { font-size: .9rem; color: var(--muted); }
.tip b { color: var(--ink); }
.timer { text-align: center; }
.timer .btn { padding: 12px 6px; white-space: nowrap; }
.timer .clock { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.rounds { display: flex; gap: 8px; justify-content: center; margin: 8px 0 12px; }
.rounds button { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); background: var(--card); color: var(--ink); font-weight: 700; font-size: 1rem; cursor: pointer; }
.rounds button.on { background: var(--good); border-color: var(--good); color: #fff; }
.sticky-cta { position: sticky; bottom: calc(76px + var(--safe-b)); z-index: 4; }

/* progress */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px; }
.stat b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .75rem; color: var(--muted); }
.stat .good { color: var(--good); }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .line2 { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--card); stroke: var(--brand); stroke-width: 2; }
.chart .pt2 { fill: var(--card); stroke: var(--accent); stroke-width: 2; }
.chart .ref { stroke: var(--good); stroke-dasharray: 4 4; stroke-width: 1.5; }
.chart .ref-l { fill: var(--good); font-size: 10px; font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
td.r, th.r { text-align: right; }
.del { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 0 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { font-size: .85rem; color: var(--muted); font-weight: 600; display: grid; gap: 4px; }
.form-grid .full { grid-column: 1 / -1; }

/* food */
.rules { counter-reset: r; list-style: none; padding: 0; margin: 0; }
.rules li { counter-increment: r; position: relative; padding: 10px 0 10px 40px; border-bottom: 1px solid var(--line); }
.rules li:last-child { border-bottom: 0; }
.rules li::before { content: counter(r); position: absolute; left: 0; top: 10px; width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 700; display: grid; place-items: center; font-size: .9rem; }
.meal { padding: 10px 0; border-bottom: 1px solid var(--line); }
.meal:last-child { border-bottom: 0; }
.meal b { display: block; color: var(--brand); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.plate { display: flex; gap: 14px; align-items: center; }
.plate svg { width: 92px; height: 92px; flex: none; }

/* settings */
.rem { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rem:last-child { border-bottom: 0; }
.rem .days { color: var(--muted); font-size: .8rem; }
.rem input[type=time] { width: 124px; padding: 8px; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { appearance: none; -webkit-appearance: none; position: absolute; inset: 0; margin: 0; width: 100%; height: 100%; border-radius: 99px; background: var(--line); border: 0; padding: 0; cursor: pointer; transition: .2s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked { background: var(--good); }
.switch input:checked::after { transform: translateX(20px); }
.notice { background: var(--brand-soft); border-radius: 12px; padding: 12px; font-size: .9rem; margin-bottom: 12px; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; text-align: center; }
.login-card label { text-align: left; font-size: .85rem; color: var(--muted); font-weight: 600; display: grid; gap: 4px; }
.login-logo { width: 64px; height: 64px; border-radius: 16px; margin: 0 auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem; font-weight: 600;
  transition: .25s; pointer-events: none; z-index: 20; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
