:root {
  --bg: #f7f5fa;
  --surface: #ffffff;
  --surface-2: #f0ecf6;
  --border: #e3ddec;
  --text: #221f29;
  --muted: #6e6878;
  --accent: #7b5cc4;
  --accent-ink: #ffffff;
  --accent-soft: #ede6f8;
  --ok: #7b5cc4;
  --ok-soft: #ede6f8;
  --warn: #a55b00;
  --warn-soft: #fbeedb;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --idle: #8b8694;
  --idle-soft: #eceaf0;
  /* macro colours */
  --protein: #2a9d8f;
  --carbs: #3d7dd8;
  --fat: #e08a2b;
  --alcohol: #d0679b;
  --burn: #d9534f;
  --grid: #ebe6f1;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
  --tabbar: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151319; --surface: #1e1b24; --surface-2: #27232f; --border: #363042;
    --text: #ebe8f0; --muted: #a39dad; --accent: #b9a2ec; --accent-ink: #1b1428;
    --accent-soft: #2f2643; --ok: #b9a2ec; --ok-soft: #2f2643; --warn: #e8a54b; --warn-soft: #3a2c17;
    --bad: #f07b72; --bad-soft: #3d2120; --idle: #8f8a99; --idle-soft: #2c2933;
    --protein: #4cc3b4; --carbs: #6aa0ee; --fat: #f0a656; --alcohol: #e98ab8; --burn: #f07b72; --grid: #2d2935;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151319; --surface: #1e1b24; --surface-2: #27232f; --border: #363042;
  --text: #ebe8f0; --muted: #a39dad; --accent: #b9a2ec; --accent-ink: #1b1428;
  --accent-soft: #2f2643; --ok: #b9a2ec; --ok-soft: #2f2643; --warn: #e8a54b; --warn-soft: #3a2c17;
  --bad: #f07b72; --bad-soft: #3d2120; --idle: #8f8a99; --idle-soft: #2c2933;
  --protein: #4cc3b4; --carbs: #6aa0ee; --fat: #f0a656; --alcohol: #e98ab8; --burn: #f07b72; --grid: #2d2935;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }

/* ---------- layout */
#app { max-width: 760px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--tabbar) + var(--safe-bottom) + 24px); }
.topbar {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 10px; display: flex; align-items: center; gap: 8px;
}
.topbar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 4px 16px 16px; }
.section { margin-top: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 2px 8px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 14px; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list > .item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 52px; border-top: 1px solid var(--border); }
.list > .item:first-child { border-top: 0; }
.item.tap { cursor: pointer; }
.item.tap:active { background: var(--surface-2); }
a.item { color: inherit; text-decoration: none; }
.item .title { font-weight: 560; }
.item .sub { font-size: .85rem; color: var(--muted); }
.empty { padding: 22px 16px; text-align: center; color: var(--muted); }

/* ---------- tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom);
}
.tabbar nav { max-width: 760px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); height: var(--tabbar); }
.tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; }
.tab svg { width: 25px; height: 25px; }
.tab.active { color: var(--accent); }
.tab .badge { position: absolute; top: 8px; left: calc(50% + 6px); background: var(--bad); color: #fff; border-radius: 9px;
  font-size: .65rem; min-width: 18px; height: 18px; line-height: 18px; text-align: center; padding: 0 5px; }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--text);
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .88rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 0; background: transparent;
  cursor: pointer; color: var(--text); flex: none; text-decoration: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn.small svg { width: 18px; height: 18px; }
.icon-btn.accent { color: var(--accent); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

.field { display: block; }
.field > span { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin: 0 2px 5px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); outline: none; font-size: 16px;
}
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.search { position: relative; }
.search .input { padding-left: 38px; padding-right: 48px; }
.search > svg, .search > span > svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.search .icon-btn { position: absolute; right: 2px; top: 1px; }
.check { display: flex; gap: 10px; align-items: center; min-height: 40px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 7px 13px;
  font-size: .88rem; font-weight: 560; cursor: pointer; color: var(--text); text-decoration: none; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 8px 6px; border-radius: 9px; font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 9px; font-size: .75rem; font-weight: 650; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.idle { background: var(--idle-soft); color: var(--idle); }
.note { border-radius: 12px; padding: 10px 12px; font-size: .9rem; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.note.info { background: var(--accent-soft); color: var(--text); }

.fab {
  position: fixed; right: max(16px, calc(50vw - 380px + 16px)); bottom: calc(var(--tabbar) + var(--safe-bottom) + 16px); z-index: 15;
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 6px 20px rgba(0,0,0,.2); display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- diary */
.datebar { display: flex; align-items: center; gap: 4px; }
.datebar .when { flex: 1; text-align: center; font-weight: 650; position: relative; }
.datebar .when input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.energy-card { display: grid; grid-template-columns: 132px 1fr; gap: 14px; align-items: center; padding: 14px; }
.ring-wrap { position: relative; width: 132px; height: 132px; }
.ring-wrap svg { width: 132px; height: 132px; transform: rotate(-90deg); }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-center .big { font-size: 1.55rem; font-weight: 750; line-height: 1.05; letter-spacing: -.02em; }
.ring-center .lbl { font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.ring-center .over { color: var(--bad); }
.eq { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; font-size: .9rem; align-items: center; }
.eq .k { color: var(--muted); }
.eq .v { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.eq .sw { width: 10px; height: 10px; border-radius: 3px; }
.eq .total { border-top: 1px solid var(--border); padding-top: 4px; margin-top: 2px; }
.macro-bars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 0 14px 14px; }
.mbar .lbl { font-size: .78rem; font-weight: 650; }
.mbar .lbl span { display: block; }
.mbar .lbl span:last-child { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.track { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.track > i { display: block; height: 100%; border-radius: 99px; }
.meal-head { display: flex; align-items: center; gap: 8px; margin: 18px 2px 6px; }
.meal-head h2 { flex: 1; }
.meal-head .kcal { font-weight: 650; font-variant-numeric: tabular-nums; }
.entry { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 10px; border-top: 1px solid var(--border); cursor: pointer; min-height: 56px; }
.entry:first-child { border-top: 0; }
.entry:active { background: var(--surface-2); }
.entry .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); }
.entry .ico svg { width: 19px; height: 19px; }
.entry .ico.food { background: var(--accent-soft); color: var(--accent); }
.entry .ico.recipe { background: #f3e8d6; color: #9a6418; }
.entry .ico.supplement { background: #ddf1f0; color: #2b8686; }
.entry .ico.exercise { background: #fde3e1; color: var(--burn); }
.entry .ico.biometric { background: #e2edf9; color: var(--carbs); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .entry .ico.recipe { background: #3a2d1a; color: #e5b46a; }
  :root:not([data-theme="light"]) .entry .ico.supplement { background: #1c3333; color: #6fd0cf; }
  :root:not([data-theme="light"]) .entry .ico.exercise { background: #3d2120; }
  :root:not([data-theme="light"]) .entry .ico.biometric { background: #1f2c3d; }
  :root:not([data-theme="light"]) .inbox .ico { background: #3a2d1a; color: #e5b46a; } }
:root[data-theme="dark"] .entry .ico.recipe, :root[data-theme="dark"] .inbox .ico { background: #3a2d1a; color: #e5b46a; }
:root[data-theme="dark"] .entry .ico.supplement { background: #1c3333; color: #6fd0cf; }
:root[data-theme="dark"] .entry .ico.exercise { background: #3d2120; }
:root[data-theme="dark"] .entry .ico.biometric { background: #1f2c3d; }
.entry .amt { font-size: .82rem; color: var(--muted); }
.entry .cal { font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; min-width: 52px; }
.entry .cal.burn { color: var(--burn); }
.meal-totals { display: flex; gap: 12px; flex-wrap: wrap; padding: 8px 14px; border-top: 1px solid var(--border);
  background: var(--surface-2); font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.meal-totals b { color: var(--text); font-weight: 650; }
.dotk { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 1px; }
.lock-banner { display: flex; align-items: center; gap: 10px; }
.locked .meal-head .icon-btn { display: none; }
.inbox { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.inbox .ico { width: 34px; height: 34px; border-radius: 10px; background: #f3e8d6; color: #9a6418; display: grid; place-items: center; flex: none; }

/* ---------- add food */
.food-row { display: flex; gap: 12px; align-items: center; padding: 11px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.food-row:first-child { border-top: 0; }
.food-row:active { background: var(--surface-2); }
.food-row .src { font-size: .72rem; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.food-row .kc { font-weight: 650; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.food-row .kc small { display: block; color: var(--muted); font-weight: 500; font-size: .72rem; }
.star { border: 0; background: none; color: var(--border); font-size: 1.4rem; cursor: pointer; padding: 0 4px; line-height: 1; }
.star.on { color: #e0a100; }
.amount-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; }
.nut-summary { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 6px; }
.nut-summary .v { font-size: 1.25rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.nut-summary .k { font-size: .72rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- nutrient report */
.nrow { display: grid; grid-template-columns: minmax(110px, 1.2fr) 1fr 2fr 42px; gap: 8px; align-items: center; padding: 7px 14px;
  border-top: 1px solid var(--border); font-size: .88rem; }
.nrow:first-child { border-top: 0; }
.nrow .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.nrow .pct { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; font-size: .82rem; }
.nrow .track { margin: 0; height: 9px; position: relative; overflow: visible; }
.nrow .track > i { background: var(--idle); }
.nrow .track > i.met { background: var(--ok); }
.nrow .track > i.under { background: var(--warn); }
.nrow .track > i.over { background: var(--bad); }
.nrow .track > i.none { background: var(--idle); opacity: .5; }
.nrow .track > b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--bad); border-radius: 1px; }
.nrow .track .clip { position: absolute; inset: 0; border-radius: 99px; overflow: hidden; }
.nrow .track .clip > i { display: block; height: 100%; }

/* ---------- details */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; text-align: center; }
.tile .v { font-size: 1.25rem; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile .k { font-size: .72rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.tile .s { font-size: .72rem; color: var(--muted); }
.streaks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.streak { text-align: center; padding: 10px 6px; }
.streak .v { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.streak .v small { font-size: .8rem; font-weight: 600; color: var(--muted); }
.streak .k { font-size: .78rem; font-weight: 600; margin-top: 4px; }
.streak .s { font-size: .7rem; color: var(--muted); }
.flame { color: #e0712b; }
.chart { width: 100%; display: block; }
.chart text { fill: var(--muted); font-size: 9px; font-family: inherit; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .target { stroke: var(--text); stroke-width: 1.2; stroke-dasharray: 4 3; opacity: .55; }
.chart .goal { stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: 6 4; }
.chart .line { fill: none; stroke: var(--carbs); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.chart .proj { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-dasharray: 2 4; stroke-linecap: round; }
.chart .dot { fill: var(--surface); stroke: var(--carbs); stroke-width: 1.4; }
.chart .sel { fill: var(--text); opacity: .06; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend i.dash { height: 0; border-top: 2px dashed var(--text); border-radius: 0; opacity: .6; vertical-align: 3px; width: 14px; }
.chart-tip { font-size: .85rem; min-height: 1.4em; margin-top: 6px; font-variant-numeric: tabular-nums; }

/* ---------- info */
.info-hero { display: flex; gap: 14px; align-items: center; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.avatar svg { width: 30px; height: 30px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: .92rem; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.stepper button { width: 44px; height: 44px; border: 0; background: none; font-size: 1.3rem; cursor: pointer; }
.stepper span { min-width: 120px; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; }
.big-target { font-size: 2.2rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.05; }
.opt { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.opt:first-child { border-top: 0; }
.opt input { margin-top: 3px; width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.target-row { display: grid; grid-template-columns: 1fr 86px 86px; gap: 8px; align-items: center; padding: 6px 14px; border-top: 1px solid var(--border); }
.target-row:first-child { border-top: 0; }
.target-row .input { min-height: 38px; padding: 6px 8px; font-size: .9rem; text-align: right; }
.target-row.head { font-size: .75rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
pre { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.token { word-break: break-all; background: var(--surface-2); padding: 10px; border-radius: 10px; font-family: ui-monospace, Menlo, monospace; font-size: .85rem; user-select: all; }
ol.steps { margin: 0; padding-left: 20px; }
ol.steps li { margin: 6px 0; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---------- sheets */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; opacity: 0; transition: opacity .18s; }
.scrim.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 640px; margin: 0 auto;
  background: var(--bg); border-radius: 20px 20px 0 0; max-height: 92vh; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .22s cubic-bezier(.2,.8,.2,1); box-shadow: 0 -8px 30px rgba(0,0,0,.2);
}
.sheet.tall { height: 92vh; }
.sheet.show { transform: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 10px 8px 18px; }
.sheet-head h2 { flex: 1; font-size: 1.1rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { overflow-y: auto; padding: 4px 18px calc(18px + var(--safe-bottom)); -webkit-overflow-scrolling: touch; flex: 1; }
@media (min-width: 700px) {
  .sheet { bottom: auto; top: 50%; border-radius: 20px; transform: translateY(-40%) scale(.98); opacity: 0; }
  .sheet.show { transform: translateY(-50%); opacity: 1; }
  .sheet.tall { height: 86vh; }
}

/* ---------- toast */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar) + var(--safe-bottom) + 12px); z-index: 60; display: grid;
  justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow);
  display: flex; gap: 12px; align-items: center; max-width: 520px; font-size: .92rem; animation: pop .18s ease-out; }
.toast.error { background: var(--bad); color: #fff; }
.toast button { background: none; border: 0; color: inherit; font-weight: 750; text-decoration: underline; cursor: pointer; padding: 4px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- scanner */
.scanner { position: fixed; inset: 0; z-index: 70; background: #000; color: #fff; display: flex; flex-direction: column; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; left: 8%; right: 8%; top: 32%; height: 22%; border: 3px solid rgba(255,255,255,.9); border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.scanner .frame.hit { border-color: #b9a2ec; }
.scanner .frame::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: rgba(255,80,80,.8); }
.scanner .top, .scanner .bottom { position: relative; z-index: 2; padding: 14px 16px; }
.scanner .top { padding-top: calc(env(safe-area-inset-top, 0px) + 12px); display: flex; gap: 8px; align-items: center; }
.scanner .bottom { margin-top: auto; padding-bottom: calc(var(--safe-bottom) + 16px); background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.scanner .icon-btn { color: #fff; background: rgba(0,0,0,.35); }
.scanner .hint { text-align: center; font-size: .9rem; opacity: .9; margin: 8px 0; text-shadow: 0 1px 3px #000; }
.scanner .input { background: rgba(255,255,255,.95); color: #111; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin-bottom: 14px; }
.logo svg { width: 32px; height: 32px; }

@media (max-width: 380px) {
  .energy-card { grid-template-columns: 112px 1fr; gap: 10px; }
  .ring-wrap, .ring-wrap svg { width: 112px; height: 112px; }
  .ring-center .big { font-size: 1.3rem; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .nrow { grid-template-columns: 1fr 1fr 34px; }
  .nrow .val { display: none; }
}
.bignum { font-size: 2rem; font-weight: 750; letter-spacing: -.02em; }
.item svg:not(.chart), .opt svg, .inbox svg, .meal-head svg { width: 20px; height: 20px; flex: none; }
.item > span:last-child > svg { color: var(--muted); }
.flame svg { width: 100%; height: 100%; }
.opt .input { width: 100%; }

/* ---- diary rows: swipe left to delete, drag handle to reorder */
.swipe { position: relative; overflow: hidden; border-top: 1px solid var(--border); background: var(--surface); }
.swipe:first-child, .drag-ph + .swipe:nth-child(2) { border-top: 0; }
.swipe > .entry { border-top: 0; background: var(--surface); position: relative; z-index: 1; touch-action: pan-y; }
.swipe-del { position: absolute; top: 0; right: 0; bottom: 0; left: 0; padding-left: calc(100% - 88px); border: 0; background: var(--bad); color: #fff;
  font: inherit; font-size: .8rem; font-weight: 650; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; }
.swipe-del svg { width: 20px; height: 20px; }
.swipe:not(.open) .swipe-del { visibility: hidden; }
.swipe.removing { opacity: .4; pointer-events: none; }
.drag-handle { flex: none; width: 30px; height: 40px; margin: -6px -6px -6px -2px; display: grid; place-items: center; border: 0; background: none;
  color: var(--muted); opacity: .55; cursor: grab; touch-action: none; border-radius: 8px; }
.drag-handle svg { width: 18px; height: 18px; }
.drag-handle:focus-visible { opacity: 1; outline: 2px solid var(--accent); outline-offset: -2px; }
.swipe.dragging { position: fixed; z-index: 60; pointer-events: none; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 30px rgba(40, 20, 80, .22); background: var(--surface); }
.swipe.dragging > .entry { border-radius: 12px; }
.swipe.dragging .drag-handle { opacity: 1; color: var(--accent); }
.swipe.dragging .swipe-del { display: none; }
.drag-ph { background: var(--accent-soft); border: 2px dashed var(--accent); border-radius: 10px; margin: 4px; box-sizing: border-box; }
.list.has-ph > .empty { display: none; }
body.drag-active { user-select: none; -webkit-user-select: none; cursor: grabbing; }
body.drag-active * { cursor: grabbing !important; }
