:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --soft: #f2f3f5;
  --soft-2: #eceef2;
  --line: #e4e6ea;
  --ink: #12141a;
  --muted: #5b6270;
  --faint: #9aa0aa;
  --accent: #2f5bff;
  --accent-ink: #ffffff;
  --accent-soft: #eaf0ff;
  --done: #12a150;
  --done-soft: #e3f6eb;
  --miss: #f2750c;
  --miss-ink: #c25400;
  --miss-soft: #fff1e6;
  --prot: #2f5bff;
  --fat: #f2a20c;
  --carb: #0d9488;
  --shadow: 0 1px 2px rgba(18, 20, 26, .04), 0 4px 16px rgba(18, 20, 26, .05);
  --font: "Onest", -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --card: #191c22; --soft: #22262e; --soft-2: #2a2f38; --line: #2a2f38;
    --ink: #f1f2f4; --muted: #a2a9b4; --faint: #6b727d; --accent: #5b7cff; --accent-soft: #1e2a52;
    --done: #22b863; --done-soft: #143222; --miss: #ff8a33; --miss-ink: #ffa25c; --miss-soft: #3a2414;
    --prot: #6f8dff; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --card: #191c22; --soft: #22262e; --soft-2: #2a2f38; --line: #2a2f38;
  --ink: #f1f2f4; --muted: #a2a9b4; --faint: #6b727d; --accent: #5b7cff; --accent-soft: #1e2a52;
  --done: #22b863; --done-soft: #143222; --miss: #ff8a33; --miss-ink: #ffa25c; --miss-soft: #3a2414;
  --prot: #6f8dff; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { font-size: 15px; line-height: 1.4; -webkit-font-smoothing: antialiased; min-height: 100vh; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.lbl { font-size: 13px; font-weight: 600; color: var(--muted); }
.err { color: var(--miss-ink); min-height: 1.2em; margin: 0; font-size: 14px; }

/* ---------- shell ---------- */
.view { max-width: 560px; margin: 0 auto; padding: calc(20px + env(safe-area-inset-top)) 16px calc(110px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px; }
.view.no-tabs { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); }
.tabs-in { display: flex; width: 100%; max-width: 560px; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; font-size: 11px; font-weight: 600; color: var(--muted); }
.tabs a svg { width: 25px; height: 25px; }
.tabs a.active { color: var(--accent); }
body.hide-tabs .tabs { display: none; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.top .date { font-size: 14px; color: var(--muted); font-weight: 500; }
h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; }
h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.sq { width: 44px; height: 44px; border-radius: 14px; border: 0; background: var(--card); color: var(--ink); display: grid; place-items: center; flex: none; box-shadow: var(--shadow); }
.sq svg { width: 22px; height: 22px; }

.card { background: var(--card); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.big { font-size: 34px; font-weight: 800; letter-spacing: -.04em; line-height: 1.05; }
.mid { font-size: 26px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; }
.unit { font-size: 15px; color: var(--muted); font-weight: 500; letter-spacing: 0; }
.up { color: var(--done); }
.down { color: var(--miss-ink); }
.bar { height: 8px; border-radius: 99px; background: var(--soft-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.hint { font-size: 14px; color: var(--muted); }
.center { text-align: center; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 50px; padding: 0 20px; border-radius: 16px; border: 0;
  background: var(--soft); color: var(--ink); font-weight: 700; font-size: 16px; transition: transform .08s, filter .15s; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-white { background: #ffffff; color: #2f5bff; }
.btn-block { width: 100%; }
.btn-lg { height: 56px; font-size: 17px; border-radius: 18px; }
.btn-dashed { background: transparent; border: 1.5px dashed var(--line); height: 48px; font-size: 15px; font-weight: 600; }
.btn-danger { background: transparent; color: var(--miss-ink); }
.link { background: none; border: 0; color: var(--accent); font-weight: 700; font-size: 15px; padding: 6px 0; }
.plus { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.plus svg { width: 18px; height: 18px; }
.chip { height: 40px; padding: 0 14px; border-radius: 99px; border: 1.5px solid var(--line); background: var(--card); font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { display: flex; background: var(--soft-2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; height: 38px; border: 0; border-radius: 10px; background: transparent; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

input[type=text], input[type=number], input[type=password], input[type=date], select, textarea {
  width: 100%; height: 50px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); padding: 0 14px;
  font-size: 16px; outline: none; transition: border-color .15s; color: var(--ink); }
textarea { height: auto; padding: 12px 14px; resize: none; line-height: 1.4; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type=number] { -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
label.f { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.stack { display: grid; gap: 12px; }

/* ---------- week strip & calendar ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; text-align: center; }
.week > button { display: flex; flex-direction: column; align-items: center; gap: 6px; border: 0; background: none; padding: 0; }
.week .wd { font-size: 12px; font-weight: 600; color: var(--muted); }
.day { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; font-weight: 600; color: var(--ink); border: 0; background: transparent; padding: 0; position: relative; }
.day svg { width: 18px; height: 18px; }
.day.done { background: var(--done); color: #fff; }
.day.missed { background: var(--miss-soft); color: var(--miss-ink); font-weight: 700; }
.day.rest { color: var(--muted); }
.day.rest::after { content: ""; position: absolute; bottom: 4px; width: 4px; height: 4px; border-radius: 50%; background: var(--faint); }
.day.plan { box-shadow: inset 0 0 0 2px var(--accent-soft); color: var(--accent); }
.day.plan-strong { border: 2px dashed var(--accent); color: var(--accent); font-weight: 700; }
.day.today:not(.done):not(.missed) { box-shadow: inset 0 0 0 2px var(--accent); color: var(--accent); font-weight: 800; }
.day.out { color: var(--faint); opacity: .55; }
.day.note::before { content: ""; position: absolute; top: 2px; right: 2px; width: 8px; height: 8px; border-radius: 50%; background: var(--miss); border: 2px solid var(--card); }
.day.done.note::before { background: var(--accent); }
.legend { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 12px; font-size: 12px; color: var(--muted); font-weight: 500; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); row-gap: 6px; text-align: center; }
.month .wd { font-size: 12px; font-weight: 600; color: var(--muted); padding-bottom: 4px; }
.month .day { width: 44px; height: 44px; margin: 0 auto; }
@media (max-width: 360px) { .month .day { width: 38px; height: 38px; } .day { width: 36px; height: 36px; } }
.nav-m { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.nav-m button { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--soft); display: grid; place-items: center; color: var(--ink); }
.nav-m b { font-size: 18px; font-weight: 800; }

.note-row { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--soft-2); align-items: flex-start; cursor: pointer; }
.note-row:first-of-type { border-top: 0; }
.note-row .dd { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-weight: 800; flex: none; }
.note-row b { display: block; font-size: 15px; }
.note-row span { color: var(--muted); font-size: 14px; }

/* ---------- today hero ---------- */
.hero { background: var(--accent); color: #fff; border-radius: 24px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.hero .k { font-size: 14px; font-weight: 600; opacity: .85; }
.hero .t { font-size: 30px; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; }
.hero .s { font-size: 15px; opacity: .85; margin-top: 6px; }
.hero .link { color: #fff; opacity: .92; text-align: center; font-size: 14px; }
.hero.done { background: var(--done); }
.hero.rest { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.hero.rest .link { color: var(--accent); }
.hero.missed { background: var(--miss-soft); color: var(--ink); }
.hero.missed .link { color: var(--miss-ink); }
.ico-circle { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .2); }
.ico-circle svg { width: 26px; height: 26px; }

.macro3 > div { background: var(--soft); border-radius: 14px; padding: 10px 12px; min-width: 0; }
.macro3 .v { font-size: 18px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.macro3 .v span { font-size: 13px; color: var(--muted); font-weight: 500; }
.macro3 .bar { height: 5px; margin-top: 6px; }

.habit { display: flex; align-items: center; gap: 12px; min-height: 52px; border-top: 1px solid var(--soft-2); }
.habit:first-of-type { border-top: 0; }
.habit .name { flex: 1; font-size: 15px; font-weight: 600; }
.habit input[type=number] { width: 84px; height: 42px; text-align: center; padding: 0 8px; }
.tick { width: 30px; height: 30px; border-radius: 9px; border: 2px solid var(--line); background: transparent; display: grid; place-items: center; color: transparent; flex: none; padding: 0; }
.tick svg { width: 18px; height: 18px; }
.tick.on { background: var(--done); border-color: var(--done); color: #fff; }

/* ---------- workout ---------- */
.prog { height: 8px; border-radius: 99px; background: var(--soft-2); overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--done); border-radius: 99px; transition: width .4s; }
.timer { position: sticky; top: calc(8px + env(safe-area-inset-top)); z-index: 20; display: flex; align-items: center; gap: 12px; background: var(--ink); color: var(--bg); border-radius: 18px; padding: 10px 12px 10px 14px; }
.timer svg { width: 22px; height: 22px; flex: none; }
.timer .tl { flex: 1; font-size: 15px; font-weight: 600; }
.timer .tv { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer button { height: 36px; padding: 0 10px; border-radius: 10px; border: 0; background: color-mix(in srgb, var(--bg) 16%, transparent); color: var(--bg); font-weight: 700; font-size: 14px; }
.timer.go { background: var(--done); color: #fff; }
.timer.go button { color: #fff; background: rgba(255, 255, 255, .2); }

.ex { display: flex; flex-direction: column; gap: 12px; }
.ex.done { box-shadow: inset 0 0 0 2px var(--done), var(--shadow); }
.ex-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.ex-top h2 { font-size: 19px; font-weight: 800; }
.pill { font-size: 13px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 6px 10px; border-radius: 99px; white-space: nowrap; }
.pill.ok { color: var(--done); background: var(--done-soft); }
.last { background: var(--soft); border-radius: 14px; padding: 11px 14px; font-size: 14px; }
.last span { color: var(--muted); }
.up-hint { background: var(--done-soft); color: var(--ink); border-radius: 14px; padding: 11px 14px; font-size: 14px; font-weight: 600; }
.up-hint b { color: var(--done); }
.sets { display: grid; grid-template-columns: 26px minmax(0, 1fr) minmax(0, 1fr) 52px; gap: 10px; align-items: center; }
.sets .h { font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; }
.sets .n { font-weight: 700; color: var(--muted); text-align: center; }
.sets input { height: 52px; text-align: center; font-size: 20px; font-weight: 700; padding: 0 4px; background: var(--soft); border-color: transparent; }
.sets input:focus { background: var(--card); }
.sets .ok input { background: var(--done-soft); }
.chk { width: 52px; height: 52px; border-radius: 14px; border: 0; background: var(--soft); color: var(--faint); display: grid; place-items: center; padding: 0; }
.chk svg { width: 22px; height: 22px; }
.chk.on { background: var(--done); color: #fff; }
.ex-foot { display: flex; gap: 16px; }
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 94%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-top: 1px solid var(--line); }
.bottom-bar > div { max-width: 528px; margin: 0 auto; display: flex; gap: 10px; }

/* ---------- food ---------- */
.item { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--soft-2); font-size: 15px; }
.item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .nm span { color: var(--muted); font-size: 13px; font-weight: 500; margin-left: 4px; }
.item b { font-variant-numeric: tabular-nums; }
.item .x { width: 32px; height: 32px; border: 0; background: none; color: var(--faint); font-size: 18px; border-radius: 8px; padding: 0; }
.daysw { display: flex; align-items: center; gap: 2px; background: var(--card); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); }
.daysw button { width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; display: grid; place-items: center; color: var(--ink); }
.daysw span { font-size: 14px; font-weight: 700; padding: 0 4px; min-width: 70px; text-align: center; }
.search-list { max-height: 40vh; overflow: auto; margin: 4px -6px 0; }
.search-item { display: flex; justify-content: space-between; gap: 10px; padding: 12px 8px; border-radius: 12px; cursor: pointer; }
.search-item.sel, .search-item:active { background: var(--soft); }
.search-item span { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(18, 20, 26, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; background: var(--card); border-radius: 28px 28px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom)); animation: up .22s cubic-bezier(.2, .8, .2, 1); display: flex; flex-direction: column; gap: 16px; }
.grab { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto; flex: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.sheet-head h2 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.x-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--soft); display: grid; place-items: center; color: var(--ink); flex: none; }
.opts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.opt { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; height: 92px; border-radius: 18px; border: 2px solid var(--line); background: var(--card); font-size: 14px; font-weight: 700; }
.opt i { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; }
.opt i svg { width: 20px; height: 20px; }
.opt.o-done i { background: var(--done-soft); color: var(--done); }
.opt.o-missed i { background: var(--miss-soft); color: var(--miss-ink); }
.opt.o-rest i { background: var(--soft-2); color: var(--muted); }
.opt.o-done.on { border-color: var(--done); background: var(--done-soft); }
.opt.o-done.on i { background: var(--done); color: #fff; }
.opt.o-missed.on { border-color: var(--miss); background: var(--miss-soft); }
.opt.o-missed.on i { background: var(--miss); color: #fff; }
.opt.o-rest.on { border-color: var(--muted); background: var(--soft); }
@media (min-width: 600px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 28px; max-height: 86vh; } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

.toast { position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translate(-50%, -90px); z-index: 60; background: var(--ink); color: var(--bg);
  padding: 11px 18px; border-radius: 99px; font-weight: 700; font-size: 14px; transition: transform .25s cubic-bezier(.2, .8, .2, 1); pointer-events: none; white-space: nowrap; }
.toast.show { transform: translate(-50%, 0); }

/* ---------- charts ---------- */
.chart { width: 100%; position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-l { stroke: var(--soft-2); stroke-width: 1; }
.chart .ax { fill: var(--faint); font-size: 11px; font-family: var(--font); }
.chart .tgt { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1.2; }
.chart .tgt-l { fill: var(--muted); font-size: 11px; font-weight: 700; }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 12px; font-weight: 700; padding: 6px 10px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -125%); opacity: 0; transition: opacity .1s; }
.chart-empty { color: var(--faint); font-size: 14px; padding: 30px 0; text-align: center; }
.clegend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 10px; }
.clegend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: 3px; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 4px; }
table.t td { padding: 10px 4px; border-top: 1px solid var(--soft-2); font-variant-numeric: tabular-nums; }
.tw { overflow-x: auto; margin: 0 -4px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; text-align: center; background: var(--card); border-radius: 28px; padding: 32px 24px; box-shadow: var(--shadow); }
.login-card p { margin: 0; }
.logo { width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 28px; margin: 0 auto; }
.fade-in { animation: fade .25s ease; }
