:root{
  --bg:#f5f6f8;
  --card:#ffffff;
  --text:#14171c;
  --muted:#69717b;
  --line:#e6e8ec;
  --accent:#16a34a;
  --good:#16a34a;
  --danger:#e5484d;
  --shadow:0 1px 3px rgba(20,30,50,.05), 0 8px 24px rgba(20,30,50,.04);
  --radius:14px;
  --maxw:480px;
}
@media (prefers-color-scheme: dark){
  :root{
    --bg:#0e1116; --card:#161a20; --text:#e9edf2; --muted:#909aa6;
    --line:#242a33; --accent:#34d399; --good:#34d399;
    --shadow:0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.25);
  }
}

*{ box-sizing:border-box; }
html,body{ margin:0; padding:0; }
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg); color:var(--text); -webkit-font-smoothing:antialiased;
  letter-spacing:-0.01em;
}
h2,h3{ margin:0 0 .5rem; letter-spacing:-0.02em; }
h3{ font-size:.95rem; }
.muted{ color:var(--muted); }
.small{ font-size:.82rem; }
.center{ text-align:center; }

.app{ max-width:var(--maxw); margin:0 auto; min-height:100vh; padding:0 16px calc(88px + env(safe-area-inset-bottom)); }

/* Header */
.app-header{ position:sticky; top:0; z-index:5; background:var(--bg); display:flex; align-items:center; justify-content:space-between; padding:16px 2px 12px; }
.brand{ display:flex; align-items:center; gap:9px; font-size:1.05rem; color:var(--text); font-weight:400; }
.brand strong{ font-weight:800; }
.brand .mark{ color:var(--muted); }

/* Tabs */
.tab{ display:none; animation:fade .22s ease; }
.tab.is-active{ display:block; }
@keyframes fade{ from{opacity:0; transform:translateY(4px);} to{opacity:1; transform:none;} }
.screen-title{ font-size:1.5rem; margin:6px 0 12px; }

/* Today header */
.today-head{ display:flex; align-items:baseline; justify-content:space-between; margin:6px 2px 10px; }
.today-count{ font-size:1.7rem; font-weight:800; }
.today-count small{ font-size:.8rem; font-weight:500; color:var(--muted); margin-left:2px; }
.today-streak{ font-size:.85rem; font-weight:600; color:var(--accent); }
.goal-bar{ height:6px; background:var(--line); border-radius:99px; overflow:hidden; margin-bottom:16px; }
.goal-bar-fill{ height:100%; width:0; background:var(--accent); border-radius:99px; transition:width .5s ease; }

/* Card */
.card{ background:var(--card); border:1px solid var(--line); border-radius:var(--radius); box-shadow:var(--shadow); padding:16px; margin-bottom:14px; }

/* ---- The day skewer (hero) ---- */
.skewer-card{ padding:18px 16px 14px; }
.skewer{ position:relative; height:46px; }
.skewer.seg{ height:44px; }
.skewer.mini{ height:34px; flex:1; }
.skewer-line{ position:absolute; left:0; right:0; top:50%; height:2px; background:var(--line); border-radius:2px; }
.dot{ position:absolute; top:50%; transform:translate(-50%,-50%); border-radius:50%; opacity:.9; mix-blend-mode:multiply; transition:transform .15s ease; }
@media (prefers-color-scheme: dark){ .dot{ mix-blend-mode:screen; } }
.seg-block{ margin-bottom:10px; }
.seg-block:last-child{ margin-bottom:0; }
.seg-head{ display:flex; justify-content:space-between; align-items:baseline; font-size:.76rem; font-weight:700; margin-bottom:1px; }
.seg-range{ font-weight:500; color:var(--muted); font-size:.7rem; }
.tick{ position:absolute; bottom:-2px; transform:translateX(-50%); font-size:.66rem; color:var(--muted); }
.skewer-empty{ position:absolute; inset:0; display:flex; align-items:center; justify-content:center; text-align:center; font-size:.82rem; color:var(--muted); padding:0 10px; }
.skewer-legend{ display:flex; flex-wrap:wrap; gap:6px 14px; margin-top:18px; }
.lg{ font-size:.78rem; color:var(--muted); display:inline-flex; align-items:center; gap:5px; background:none; border:none; font-family:inherit; cursor:pointer; padding:2px 0; }
.lg b{ color:var(--text); }
.lg.off{ opacity:.38; }
.lg.off b{ color:var(--muted); }
.lg-dot{ width:9px; height:9px; border-radius:50%; display:inline-block; flex:0 0 auto; }

/* Focus + balance banners */
.focus-line{ --accent2:var(--accent); display:flex; align-items:center; gap:8px; flex-wrap:wrap; font-size:.9rem; padding:11px 14px; margin-bottom:12px; border:1px solid var(--line); border-left:3px solid var(--accent2); border-radius:var(--radius); background:var(--card); }
.focus-prog{ margin-left:auto; font-weight:700; color:var(--accent2); }
.balance-banner{ --accent2:var(--good); font-size:.9rem; line-height:1.4; padding:12px 14px; margin-bottom:18px; border:1px solid var(--line); border-left:3px solid var(--accent2); border-radius:var(--radius); background:var(--card); }

/* Section title + snack grid */
.section-title{ display:flex; justify-content:space-between; align-items:center; font-weight:700; margin:4px 2px 4px; font-size:.95rem; }
.link-btn{ background:none; border:none; color:var(--accent); font-weight:600; cursor:pointer; font-size:.85rem; }
.hint{ font-size:.78rem; color:var(--muted); margin:0 2px 12px; }
.snack-grid{ display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.snack-card{ position:relative; background:var(--card); border:1px solid var(--line); border-left:3px solid var(--cat); border-radius:12px; padding:15px 13px; text-align:left; cursor:pointer; display:flex; flex-direction:column; gap:5px; box-shadow:var(--shadow); color:var(--text); font:inherit; transition:transform .08s ease; }
.snack-card:active{ transform:scale(.97); }
.snack-card.pop{ animation:pop .32s ease; }
@keyframes pop{ 0%{transform:scale(1);} 35%{transform:scale(1.05);} 100%{transform:scale(1);} }
.snack-name{ font-weight:700; font-size:.95rem; }
.snack-cat{ font-size:.74rem; color:var(--muted); display:inline-flex; align-items:center; gap:5px; }
.rep-badge{ position:absolute; top:9px; right:9px; background:var(--cat); color:#fff; font-weight:800; font-size:.78rem; padding:2px 8px; border-radius:99px; min-width:22px; text-align:center; }
.rep-badge.pulse{ animation:reppulse .3s ease; }
@keyframes reppulse{ 0%{transform:scale(1);} 50%{transform:scale(1.25);} 100%{transform:scale(1);} }
.add-snack{ width:100%; margin-top:12px; padding:13px; border:1.5px dashed var(--line); background:none; color:var(--muted); border-radius:12px; font-weight:600; cursor:pointer; font-size:.9rem; }

/* Breathe */
.breath-stage{ display:flex; justify-content:center; align-items:center; height:280px; }
.breath-circle{ width:130px; height:130px; border-radius:50%; background:radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--accent) 65%, #fff), var(--accent)); display:flex; align-items:center; justify-content:center; color:#fff; font-weight:700; box-shadow:0 12px 50px color-mix(in srgb, var(--accent) 40%, transparent); transform:scale(1); transition:transform 4s ease-in-out; }
.breath-circle.grow{ transform:scale(1.9); }
.breath-presets{ display:flex; gap:8px; justify-content:center; margin:6px 0 4px; flex-wrap:wrap; }
.chip{ border:1px solid var(--line); background:var(--card); color:var(--text); padding:8px 15px; border-radius:99px; cursor:pointer; font-weight:600; font-size:.84rem; }
.chip.active{ background:var(--accent); color:#fff; border-color:var(--accent); }
.chip.off{ color:var(--muted); }
.breath-controls{ display:flex; gap:8px; align-items:center; justify-content:center; margin-top:14px; flex-wrap:wrap; }
.inline-sel{ font-size:.85rem; color:var(--muted); display:inline-flex; align-items:center; gap:6px; }
select,.inline-sel select{ padding:8px 10px; border-radius:10px; border:1px solid var(--line); background:var(--bg); color:var(--text); font:inherit; }
.primary-btn{ background:var(--accent); border:none; color:#062a16; padding:12px 22px; border-radius:12px; font-weight:800; cursor:pointer; font-size:.95rem; }
.primary-btn.wide{ width:100%; margin-top:16px; }

/* Supplements */
.supp-row{ width:100%; display:flex; align-items:center; gap:12px; text-align:left; background:var(--bg); border:1px solid var(--line); border-radius:12px; padding:13px; margin-bottom:8px; cursor:pointer; color:var(--text); font:inherit; }
.supp-row .check{ width:20px; height:20px; border-radius:50%; border:2px solid var(--line); flex:0 0 auto; position:relative; }
.supp-row.taken .check{ background:var(--accent); border-color:var(--accent); }
.supp-row.taken .check::after{ content:""; position:absolute; left:6px; top:2px; width:5px; height:10px; border:solid #fff; border-width:0 2px 2px 0; transform:rotate(45deg); }
.supp-row.taken{ opacity:.6; }
.supp-row.taken .supp-name{ text-decoration:line-through; }
.supp-name{ font-weight:700; flex:1; }
.supp-time{ color:var(--muted); font-size:.85rem; font-variant-numeric:tabular-nums; }

/* Progress */
.wk-row{ display:flex; align-items:center; gap:10px; margin-top:6px; }
.wk-lbl{ width:30px; font-size:.74rem; color:var(--muted); font-weight:600; }
.wk-lbl.met{ color:var(--accent); }
.cat-row{ display:flex; align-items:center; gap:10px; padding:5px 0; }
.cat-name{ width:88px; font-size:.84rem; color:var(--muted); display:inline-flex; align-items:center; gap:6px; }
.cat-track{ flex:1; height:8px; background:var(--line); border-radius:99px; overflow:hidden; }
.cat-fill{ height:100%; border-radius:99px; transition:width .4s ease; min-width:2px; }
.cat-val{ width:22px; text-align:right; font-weight:700; font-size:.84rem; font-variant-numeric:tabular-nums; }
.stat-grid{ display:flex; gap:8px; }
.stat{ flex:1; text-align:center; background:var(--bg); border-radius:12px; padding:14px 4px; }
.stat b{ display:block; font-size:1.4rem; }
.stat span{ font-size:.72rem; color:var(--muted); }

/* Settings */
.row{ display:flex; justify-content:space-between; align-items:center; gap:10px; padding:9px 0; }
input[type=number]{ width:72px; padding:8px; border-radius:10px; border:1px solid var(--line); background:var(--bg); color:var(--text); text-align:center; font:inherit; }
input[type=checkbox]{ width:20px; height:20px; accent-color:var(--accent); }
.weekday-grid .row{ border-bottom:1px solid var(--line); }
.weekday-grid .row select{ min-width:120px; }
.hours{ display:inline-flex; align-items:center; gap:6px; }
.hours input{ width:58px; }
.ghost-btn{ background:var(--card); border:1px solid var(--line); color:var(--text); padding:10px 14px; border-radius:11px; font-weight:600; cursor:pointer; font-size:.9rem; }
.danger-btn{ background:none; border:1px solid color-mix(in srgb,var(--danger) 40%,transparent); color:var(--danger); padding:10px 14px; border-radius:11px; font-weight:600; cursor:pointer; width:100%; margin-top:10px; }
.btn-row{ display:flex; gap:10px; margin-top:6px; }
.btn-row .ghost-btn{ flex:1; text-align:center; }
.file-label{ display:inline-flex; align-items:center; justify-content:center; cursor:pointer; }
.manage-row{ display:flex; justify-content:space-between; align-items:center; padding:9px 0; border-bottom:1px solid var(--line); font-size:.9rem; }
.manage-row span{ display:inline-flex; align-items:center; gap:7px; }
.del-btn{ background:none; border:none; color:var(--muted); cursor:pointer; font-size:.95rem; padding:4px 8px; }
.donate .bmc-btn{ display:inline-block; background:#ffdd00; color:#0b0b0b; font-weight:800; padding:12px 18px; border-radius:11px; text-decoration:none; margin-top:4px; }

/* Tab bar */
.tabbar{ position:fixed; left:0; right:0; bottom:0; z-index:10; display:flex; max-width:var(--maxw); margin:0 auto; background:color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter:saturate(160%) blur(14px); border-top:1px solid var(--line); padding:8px 6px calc(8px + env(safe-area-inset-bottom)); }
.tabbar button{ flex:1; background:none; border:none; color:var(--muted); display:flex; flex-direction:column; align-items:center; gap:3px; font-size:.68rem; font-weight:600; cursor:pointer; padding:4px; }
.tabbar svg{ width:22px; height:22px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.tabbar button.is-active{ color:var(--accent); }

/* Dialog */
dialog{ border:none; border-radius:16px; padding:0; background:var(--card); color:var(--text); box-shadow:0 24px 70px rgba(0,0,0,.4); max-width:360px; width:92%; }
dialog::backdrop{ background:rgba(0,0,0,.5); }
.dialog-form{ padding:20px; display:flex; flex-direction:column; gap:12px; }
.dialog-form > label{ display:flex; flex-direction:column; gap:5px; font-size:.82rem; font-weight:600; color:var(--muted); }
.dialog-form input, .dialog-form select{ padding:10px; border-radius:10px; border:1px solid var(--line); background:var(--bg); color:var(--text); font-size:1rem; }
.dialog-actions{ display:flex; gap:10px; justify-content:flex-end; margin-top:4px; }
.breath-row{ display:flex; align-items:center; gap:8px; margin-bottom:8px; }
.breath-row .bp-name{ flex:1; }
.breath-row .bp-secs{ width:64px; }

/* Toast */
.toast{ position:fixed; left:50%; bottom:calc(94px + env(safe-area-inset-bottom)); transform:translateX(-50%) translateY(10px); background:var(--text); color:var(--bg); padding:11px 18px; border-radius:99px; font-weight:600; font-size:.88rem; opacity:0; transition:opacity .25s, transform .25s; z-index:20; max-width:90%; text-align:center; box-shadow:0 8px 30px rgba(0,0,0,.3); }
.toast.show{ opacity:1; transform:translateX(-50%) translateY(0); }

/* ---- focus line chips, weekday focus, group editor, time inputs ---- */
.fchip{ display:inline-flex; align-items:center; gap:4px; margin-right:8px; white-space:nowrap; }

.fw-row{ display:flex; align-items:flex-start; gap:8px; padding:8px 0; border-bottom:1px solid var(--line); }
.fw-row:last-child{ border-bottom:none; }
.fw-day{ width:34px; flex:0 0 auto; font-size:.78rem; font-weight:700; color:var(--muted); padding-top:6px; }
.fw-chips{ display:flex; flex-wrap:wrap; gap:6px; }
.fchip-btn{ --c:var(--accent); display:inline-flex; align-items:center; gap:5px; border:1px solid var(--line); background:var(--bg); color:var(--muted); padding:5px 9px; border-radius:99px; font-size:.74rem; font-weight:600; cursor:pointer; }
.fchip-btn.on{ color:var(--text); border-color:var(--c); background:color-mix(in srgb, var(--c) 16%, var(--bg)); }

.cat-edit-row{ display:flex; align-items:center; gap:8px; padding:7px 0; border-bottom:1px solid var(--line); }
.cat-edit-row:last-of-type{ border-bottom:none; }
.ce-color{ width:36px; height:36px; padding:0; border:1px solid var(--line); border-radius:8px; background:none; cursor:pointer; flex:0 0 auto; }
.ce-color::-webkit-color-swatch-wrapper{ padding:3px; }
.ce-color::-webkit-color-swatch{ border:none; border-radius:6px; }
.ce-name{ flex:1; min-width:0; padding:8px; border-radius:9px; border:1px solid var(--line); background:var(--bg); color:var(--text); font:inherit; }
.ce-hex{ width:82px; padding:8px; border-radius:9px; border:1px solid var(--line); background:var(--bg); color:var(--text); font:inherit; font-size:.82rem; }

input[type=time]{ padding:8px 10px; border-radius:10px; border:1px solid var(--line); background:var(--bg); color:var(--text); font:inherit; }

.row.is-disabled{ opacity:.42; }
.row.is-disabled select{ cursor:not-allowed; }

/* ---- long-press safety, glow slider, history ---- */
.snack-card{ user-select:none; -webkit-user-select:none; touch-action:manipulation; }
input[type=range]{ width:150px; accent-color:var(--accent); }

.hist-dials{ display:flex; gap:10px; margin-bottom:10px; }
.hist-dials .inline-sel{ flex:1; justify-content:space-between; }
.hist-dials .inline-sel select{ flex:1; min-width:0; }
.hist-custom{ display:flex; gap:10px; margin-bottom:10px; }
.hist-custom .inline-sel{ flex:1; justify-content:space-between; }
.hist-custom input[type=date]{ flex:1; min-width:0; padding:8px; border-radius:10px; border:1px solid var(--line); background:var(--bg); color:var(--text); font:inherit; }
.hist-row{ display:flex; align-items:center; gap:8px; padding:2px 0; }
.hist-lbl{ width:52px; flex:0 0 auto; font-size:.68rem; color:var(--muted); font-variant-numeric:tabular-nums; }
.skewer.hist{ height:22px; flex:1; }

.iso-chip{ display:inline-flex; align-items:center; gap:8px; background:var(--bg); border:1px solid var(--line); border-radius:99px; padding:6px 12px; font-size:.8rem; margin-bottom:10px; cursor:pointer; }
.iso-clear{ color:var(--accent); font-weight:700; }
.stat-area{ border-bottom:1px solid var(--line); }
.stat-area:last-of-type{ border-bottom:none; }
.stat-area-head{ display:flex; align-items:center; gap:8px; padding:11px 2px; cursor:pointer; user-select:none; -webkit-user-select:none; }
.stat-name{ font-weight:600; }
.stat-nums{ margin-left:auto; color:var(--muted); font-size:.82rem; font-variant-numeric:tabular-nums; }
.stat-exp{ color:var(--muted); transition:transform .2s; font-size:.7rem; margin-left:6px; }
.stat-area.open .stat-exp{ transform:rotate(90deg); }
.stat-sub{ padding:0 0 6px 26px; }
.stat-mv{ display:flex; align-items:center; gap:8px; padding:7px 2px; cursor:pointer; user-select:none; -webkit-user-select:none; border-top:1px dashed var(--line); }
.stat-mv .stat-name{ font-weight:500; font-size:.9rem; }

.add-custom{ display:flex; gap:6px; align-items:center; flex-wrap:wrap; }
.add-custom input{ flex:1 1 100%; min-width:0; padding:10px; border-radius:10px; border:1px solid var(--line); background:var(--bg); color:var(--text); font:inherit; }
.add-custom select{ flex:1 1 auto; min-width:0; }
.add-custom .primary-btn{ padding:10px 16px; flex:0 0 auto; }
#snack-search{ padding:10px; border-radius:10px; border:1px solid var(--line); background:var(--bg); color:var(--text); font:inherit; }
.snack-filter{ display:flex; gap:6px; flex-wrap:wrap; }
.small-chip{ padding:5px 11px; font-size:.76rem; }
.snack-library{ max-height:40vh; overflow-y:auto; border:1px solid var(--line); border-radius:10px; }
.lib-row{ width:100%; display:flex; align-items:center; gap:9px; padding:11px 12px; background:none; border:none; border-bottom:1px solid var(--line); cursor:pointer; color:var(--text); font:inherit; text-align:left; }
.lib-row:last-child{ border-bottom:none; }
.lib-name{ font-weight:600; flex:1; }
.lib-cat{ color:var(--muted); font-size:.74rem; }
.lib-act{ color:var(--accent); font-weight:800; width:42px; text-align:right; }
.lib-row.added{ opacity:.5; cursor:default; }
.lib-row.added .lib-act{ color:var(--muted); font-weight:600; }

.grid-tools{ display:flex; gap:10px; margin-top:10px; }
.grid-tools .ghost-btn{ flex:1; text-align:center; }
.grid-tools .ghost-btn.active{ background:var(--accent); color:#062a16; border-color:var(--accent); }
.snack-grid.rearranging .snack-card{ cursor:default; }
.reorder{ position:absolute; top:8px; right:8px; display:inline-flex; gap:4px; }
.ro-btn{ background:var(--bg); border:1px solid var(--line); color:var(--text); border-radius:8px; width:28px; height:24px; cursor:pointer; font-size:.85rem; line-height:1; padding:0; }
.ce-move{ display:inline-flex; flex-direction:column; gap:3px; flex:0 0 auto; }
.ce-move .ro-btn{ width:24px; height:17px; font-size:.66rem; }
.rep-badge.holding{ background:var(--accent); color:#062a16; }

/* recent records on cards */
.snack-recent{ display:flex; flex-direction:column; gap:1px; margin-top:4px; }
.sr-line{ font-size:.68rem; color:var(--muted); line-height:1.35; }
.sr-line b{ color:var(--text); font-weight:700; }
.sr-best{ color:var(--accent); }
.sr-best b{ color:var(--accent); }

/* stats movement sets + chart button */
.mv-chart{ flex:0 0 auto; background:none; border:none; cursor:pointer; padding:6px 2px 6px 12px; color:var(--accent); }
.mv-chart svg{ width:20px; height:20px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; display:block; }
.mv-sets{ padding:0 0 8px 4px; }
.set-row{ display:flex; justify-content:space-between; gap:10px; padding:5px 2px; font-size:.82rem; border-top:1px dashed var(--line); }
.set-row span:last-child{ font-weight:600; font-variant-numeric:tabular-nums; }

/* movement detail page */
.back-btn{ background:none; border:none; color:var(--accent); font-weight:700; font-size:.95rem; cursor:pointer; padding:6px 0; margin:8px 0 4px; }
.detail-title{ display:flex; align-items:center; gap:9px; margin-bottom:12px; }
.detail-title h2{ margin:0; font-size:1.35rem; }
.detail-chips{ display:flex; gap:6px; flex-wrap:wrap; margin-bottom:12px; }
.detail-sub{ display:flex; gap:16px; flex-wrap:wrap; margin-bottom:10px; }
.detail-sub .detail-chips{ margin-bottom:0; }
.line-chart{ width:100%; height:auto; display:block; }
.line-chart polyline{ fill:none; stroke:var(--accent); stroke-width:2; stroke-linejoin:round; stroke-linecap:round; }
.line-chart circle{ fill:var(--accent); }
.line-chart .lc-lbl{ fill:var(--muted); font-size:10px; }
.day-group{ margin-bottom:10px; }
.day-head{ font-size:.78rem; font-weight:700; color:var(--muted); padding:4px 2px; }
