:root {
  --bg: #f4f7f5; --card: #ffffff; --ink: #14201c; --muted: #66756f; --line: #e3e9e6;
  --accent: #0f9d76; --accent-ink: #ffffff; --accent-soft: #e2f5ee;
  --warn: #c77700; --warn-soft: #fff3dc; --bad: #c8402f; --bad-soft: #fde8e4; --info-soft: #e6effb; --info: #2f6fc0;
  --c-prot: #d9534f; --c-carb: #e0a019; --c-veg: #2f9e55; --c-fruit: #d9628f; --c-fat: #7a68c9;
  --r: 18px; --shadow: 0 1px 2px rgba(20,32,28,.05), 0 6px 20px rgba(20,32,28,.05);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513; --card: #18211e; --ink: #e9f1ee; --muted: #93a39c; --line: #26322e;
    --accent: #2ecf9f; --accent-ink: #06231a; --accent-soft: #143329;
    --warn: #f0b24a; --warn-soft: #33290f; --bad: #f08273; --bad-soft: #3a1c17; --info-soft: #15263c; --info: #7fb0ee;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; } h2 { font-size: 1.1rem; } h3 { font-size: .98rem; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .tiny { font-size: .75rem; }
.num { font-variant-numeric: tabular-nums; }
.splash { min-height: 100dvh; display: grid; place-items: center; color: var(--muted); }

/* Layout */
.shell { min-height: 100dvh; padding-bottom: calc(76px + var(--safe-b)); }
.main { max-width: 1040px; margin: 0 auto; padding: 18px 16px 24px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + var(--safe-b)); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; position: relative; }
.nav a .ic { font-size: 1.3rem; line-height: 1; filter: grayscale(1) opacity(.65); }
.nav a.on { color: var(--accent); } .nav a.on .ic { filter: none; }
.nav .brand { display: none; }
.badge { position: absolute; top: 2px; left: calc(50% + 8px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .65rem; display: grid; place-items: center; }
@media (min-width: 900px) {
  .shell { padding-bottom: 0; padding-left: 220px; }
  .nav { top: 0; right: auto; width: 220px; flex-direction: column; gap: 4px; border-top: 0; border-right: 1px solid var(--line); padding: 20px 12px; }
  .nav a { flex: none; flex-direction: row; gap: 12px; padding: 11px 12px; font-size: .95rem; }
  .nav a.on { background: var(--accent-soft); }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 12px 18px; }
  .nav .brand img { width: 30px; height: 30px; border-radius: 9px; }
  .badge { position: static; margin-left: auto; }
  .main { padding: 28px 28px 40px; }
  .grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
  .span2 { grid-column: span 2; }
}
@media (min-width: 600px) and (max-width: 899px) { .grid.two, .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } .span2 { grid-column: span 2; } }

/* Cards */
.card { background: var(--card); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); min-width: 0; }
.card > .row:first-child { margin-bottom: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: grid; gap: 10px; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emoji { width: 40px; height: 40px; border-radius: 12px; background: var(--bg); display: grid; place-items: center; font-size: 1.25rem; flex: none; }
.empty { color: var(--muted); font-size: .9rem; padding: 6px 0; }

/* Buttons */
.btn { border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 650; background: var(--accent); color: var(--accent-ink); min-height: 46px; }
.btn:active { transform: scale(.98); }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.sm { min-height: 36px; padding: 6px 12px; border-radius: 11px; font-size: .88rem; }
.btn.block { width: 100%; }
.icon-btn { border: 0; background: transparent; width: 38px; height: 38px; border-radius: 11px; color: var(--muted); font-size: 1.05rem; flex: none; }
.icon-btn:hover { background: var(--bg); }
.round { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 1.2rem; font-weight: 600; flex: none; }

/* Forms */
label.f { display: grid; gap: 5px; font-size: .82rem; font-weight: 600; color: var(--muted); }
input, select { width: 100%; padding: 12px 13px; border-radius: 13px; border: 1px solid var(--line); background: var(--bg); min-height: 46px; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; background: var(--bg); border-radius: 13px; padding: 4px; gap: 4px; border: 1px solid var(--line); }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 8px 6px; font-weight: 600; color: var(--muted); font-size: .88rem; white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.seg.col button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .8rem; padding: 7px 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 8px 13px; font-size: .88rem; font-weight: 550; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Day ring + bars */
.hero { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring .c { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .big { font-size: 1.7rem; font-weight: 750; line-height: 1; }
.bars { flex: 1; display: grid; gap: 11px; min-width: 0; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; border-radius: 4px; }
.datebar { display: flex; align-items: center; gap: 6px; }
.datebar b { min-width: 120px; text-align: center; }
.glasses { display: flex; flex-wrap: wrap; gap: 6px; }
.glass { width: 30px; height: 36px; border-radius: 6px 6px 10px 10px; border: 2px solid var(--info); opacity: .35; background: transparent; padding: 0; min-height: 0; }
.glass.on { background: var(--info); opacity: 1; }

/* Alerts */
.alert { display: flex; gap: 10px; padding: 12px; border-radius: 14px; font-size: .92rem; align-items: flex-start; }
.alert .ic { font-size: 1.1rem; line-height: 1.3; }
.alert.good { background: var(--accent-soft); } .alert.warn { background: var(--warn-soft); } .alert.info { background: var(--info-soft); } .alert.bad { background: var(--bad-soft); }

/* Builder */
.slot { border: 1px solid var(--line); border-radius: 16px; padding: 13px; }
.slot .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.qty { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.qty input { text-align: center; width: 84px; min-height: 40px; padding: 8px; }
.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.totals div { background: var(--bg); border-radius: 13px; padding: 10px 4px; }
.totals b { display: block; font-size: 1.1rem; }
.sticky { position: sticky; bottom: calc(84px + var(--safe-b)); z-index: 5; }
@media (min-width: 900px) { .sticky { bottom: 16px; } }

/* Treadmill */
.plan-bars { display: flex; align-items: flex-end; gap: 2px; height: 46px; margin-top: 10px; }
.plan-bars i { flex-grow: 1; background: var(--accent); border-radius: 3px 3px 0 0; opacity: .8; min-width: 2px; }
.timer { text-align: center; padding: 6px 0 2px; }
.timer .clock { font-size: 4rem; font-weight: 750; line-height: 1; font-variant-numeric: tabular-nums; }
.timer .seglabel { font-size: 1.25rem; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.speed { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.speed div { background: var(--bg); border-radius: 14px; padding: 12px; text-align: center; }
.speed b { font-size: 1.7rem; display: block; line-height: 1.1; }

/* Chart */
.chart svg { width: 100%; height: auto; display: block; }
.stat { text-align: center; } .stat b { font-size: 1.35rem; display: block; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* Sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 520px; max-height: 92dvh; overflow: auto; border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (min-width: 600px) { .sheet-bg { align-items: center; } .sheet { border-radius: 22px; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }

/* Auth */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 400px; padding: 26px 22px; }
.auth img { width: 64px; height: 64px; border-radius: 18px; display: block; margin: 0 auto 14px; }
.auth h1, .auth p { text-align: center; }
.err { color: var(--bad); font-size: .88rem; min-height: 1.2em; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.tag.off { background: var(--bad-soft); color: var(--bad); }
