:root {
  --bg: #F4F1EA;
  --card: #FFFFFF;
  --ink: #1F2421;
  --muted: #6B716C;
  --line: #E4DFD5;
  --field: #F4F1EA;
  --accent: #2F6B4F;
  --accent-ink: #FFFFFF;
  --accent-soft: #E1ECE5;
  --danger: #B5462E;
  --over: #C8643B;
  --protein: #3B78A1;
  --carbs: #C98E1E;
  --fat: #C8643B;
  --fibre: #6E8B3D;
  --shadow: 0 1px 2px rgba(31, 36, 33, .06), 0 4px 16px rgba(31, 36, 33, .04);
  --radius: 18px;
  --tab-h: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131614; --card: #1C201E; --ink: #ECEAE4; --muted: #9AA19C; --line: #2B302D; --field: #252A27;
    --accent: #6DBE94; --accent-ink: #0E1A13; --accent-soft: #1F3329; --danger: #E8775C; --over: #E68A5F;
    --protein: #6FA9D4; --carbs: #E2B04B; --fat: #E68A5F; --fibre: #9CBB66;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131614; --card: #1C201E; --ink: #ECEAE4; --muted: #9AA19C; --line: #2B302D; --field: #252A27;
  --accent: #6DBE94; --accent-ink: #0E1A13; --accent-soft: #1F3329; --danger: #E8775C; --over: #E68A5F;
  --protein: #6FA9D4; --carbs: #E2B04B; --fat: #E68A5F; --fibre: #9CBB66;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
.icon { flex: none; display: block; }

.main { padding: calc(env(safe-area-inset-top) + 8px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); max-width: 560px; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0 2px; }
.page-head h1 { font-size: 30px; line-height: 1.1; font-weight: 700; letter-spacing: -0.02em; }
.page-head .h-small, .h-small { font-size: 18px; font-weight: 650; }
.page-head.sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); margin: 0 -16px; padding: calc(env(safe-area-inset-top) + 6px) 16px 10px; border-bottom: 1px solid var(--line); }
.main:has(.page-head.sticky) { padding-top: 0; }
.eyebrow { font-size: 13px; color: var(--muted); font-weight: 500; }
.eyebrow.accent { color: var(--accent); font-weight: 600; }

/* ---------- Cards ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; border: 1px solid transparent; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .card { border-color: var(--line); } }
.card-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 650; color: var(--muted); }
.card-title.flat { color: var(--ink); font-size: 17px; }
.card.hero { cursor: pointer; }
.card.workout.next { border-color: var(--accent); }

.hero-row { display: flex; align-items: center; gap: 18px; }
.hero-row.compact { gap: 14px; }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; flex: 1; }
.stat { display: flex; flex-direction: column; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat.over .stat-value { color: var(--over); }
.big-num { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.unit { font-size: 15px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.over-text { color: var(--over); }

/* Ring */
.ring-wrap { position: relative; flex: none; }
.ring-track { stroke: var(--accent-soft); }
.ring-fill { stroke: var(--accent); transition: stroke-dasharray .5s ease; }
.ring.over .ring-fill { stroke: var(--over); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-num { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.ring-label { font-size: 12px; color: var(--muted); }

/* Macros */
.macros { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.macro-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.macro-name { font-weight: 600; }
.macro-val { font-variant-numeric: tabular-nums; }
.bar { height: 7px; border-radius: 4px; background: var(--field); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width .4s ease; }
.m-protein .bar-fill { background: var(--protein); } .m-carbs .bar-fill { background: var(--carbs); }
.m-fat .bar-fill { background: var(--fat); } .m-fibre .bar-fill { background: var(--fibre); }

/* Week */
.week-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.week-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.week-stat { display: flex; flex-direction: column; gap: 1px; background: var(--field); border-radius: 12px; padding: 10px 12px; }
.week-stat .stat-value { font-size: 18px; }
.target-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.wday { border: 0; background: var(--card); border-radius: 12px; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: var(--shadow); }
.wday-l { font-size: 11px; color: var(--muted); font-weight: 600; }
.wday-n { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.wday-bar { width: 6px; height: 28px; border-radius: 3px; background: var(--field); display: flex; align-items: flex-end; overflow: hidden; }
.wday-fill { width: 100%; background: var(--accent); border-radius: 3px; }
.wday-fill.over { background: var(--over); }
.wday.now .wday-n { color: var(--accent); }
.wday.sel { background: var(--accent); }
.wday.sel .wday-l, .wday.sel .wday-n { color: var(--accent-ink); }
.wday.sel .wday-bar { background: rgba(255, 255, 255, .3); }
.wday.sel .wday-fill { background: var(--accent-ink); }

/* Training card on Today */
.train-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.train-row h3 { font-size: 18px; font-weight: 650; }
.done-badge { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.done-badge.big { width: 60px; height: 60px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 18px; border-radius: 12px; border: 0; background: var(--field); color: var(--ink); font-weight: 600; font-size: 15px; text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn:active { transform: scale(.98); }
.danger-text { color: var(--danger) !important; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: var(--ink); display: inline-grid; place-items: center; position: relative; flex: none; }
.icon-btn:active { background: var(--field); }
.icon-btn.light { color: #fff; background: rgba(0, 0, 0, .35); }
.ghost-space { visibility: hidden; }

.notice { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 12px 14px; font-size: 14px; color: var(--ink); }
.notice span { flex: 1; }
.notice.strong { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.notice-act { flex: none !important; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid var(--line); background: var(--card); font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip-sub { font-weight: 400; opacity: .75; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--field); border-radius: 12px; padding: 3px; }
.segmented button { border: 0; background: transparent; min-height: 36px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted); }
.segmented button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

/* ---------- Lists ---------- */
.meal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.meal-head h2 { font-size: 18px; font-weight: 650; }
.entry-list li + li, .food-list li + li { border-top: 1px solid var(--line); }
.entry, .food-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 10px 0; border: 0; background: transparent; text-align: left; min-height: 52px; }
.entry-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.entry-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-kcal { font-weight: 600; font-variant-numeric: tabular-nums; }
.food-item .icon { color: var(--accent); }
.list-label { font-size: 13px; color: var(--muted); font-weight: 600; margin: 8px 0 2px; }
.ex-summary li { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; }

.menu { display: flex; flex-direction: column; }
.menu-item { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 0 4px; border: 0; background: transparent; text-align: left; font-size: 16px; border-bottom: 1px solid var(--line); }
.menu-item:last-child { border-bottom: 0; }

.facts li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.facts .ok { color: var(--accent); font-weight: 600; } .facts .warn { color: var(--over); font-weight: 600; }

/* ---------- Forms ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 0; }
.grow { flex: 1; min-width: 0; } .grow2 { flex: 2; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); }
.input { width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--field); font-size: 16px; -webkit-appearance: none; appearance: none; }
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
textarea.input { resize: vertical; min-height: 70px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input.title-in { font-weight: 650; font-size: 17px; }
.small-select { width: auto; min-height: 36px; padding: 4px 30px 4px 10px; font-size: 14px; }
.date-hidden { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.file-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
label.btn { position: relative; }
.date-chip { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 0; min-height: 0; width: auto; }

.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap .icon { position: absolute; left: 12px; color: var(--muted); }
.search-wrap .input { padding-left: 38px; }
.tool-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 13px; font-weight: 600; }
.tool .icon { color: var(--accent); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 4px; }
.switch { -webkit-appearance: none; appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--line); position: relative; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

/* Nutrition preview */
.nutri-preview { background: var(--field); border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.np-macros { display: flex; gap: 14px; }
.np { display: flex; flex-direction: column; align-items: center; }
.np-v { font-weight: 650; font-variant-numeric: tabular-nums; }
.np.m-protein .np-v { color: var(--protein); } .np.m-carbs .np-v { color: var(--carbs); }
.np.m-fat .np-v { color: var(--fat); } .np.m-fibre .np-v { color: var(--fibre); }

/* ---------- Workout logging ---------- */
.sets { display: flex; flex-direction: column; gap: 6px; }
.set-row { display: grid; grid-template-columns: 28px 1fr 74px 64px 44px; align-items: center; gap: 8px; }
.set-row.head { font-size: 12px; color: var(--muted); font-weight: 600; }
.set-row.head span:nth-child(3), .set-row.head span:nth-child(4) { text-align: center; }
.set-n { font-weight: 650; text-align: center; }
.set-in { text-align: center; min-height: 42px; padding: 8px 4px; font-variant-numeric: tabular-nums; }
.set-row.done .set-in { background: var(--accent-soft); border-color: transparent; }
.check { width: 44px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--field); color: var(--muted); display: grid; place-items: center; }
.check.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.timer { font-variant-numeric: tabular-nums; }
.summary-hero { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 6px 0; }
.summary-hero h3 { font-size: 22px; }
.pr-box { background: var(--accent-soft); border-radius: 14px; padding: 12px 14px; }
.pr-box h3 { font-size: 15px; color: var(--accent); margin-bottom: 4px; }
.pr-box li { font-weight: 600; padding: 2px 0; }

.ex-edit-head, .ex-edit { display: grid; grid-template-columns: 1fr 54px 64px 40px; gap: 6px; align-items: center; }
.ex-edit-head { font-size: 12px; color: var(--muted); font-weight: 600; }
.ex-edit .input { min-height: 42px; padding: 8px 10px; }
.ex-edit .input:not([list]) { text-align: center; padding: 8px 4px; }

/* ---------- Progress ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart-line { stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--accent); opacity: .08; }
.chart-dot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.chart-empty { fill: var(--muted); font-size: 13px; }
.m-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.m-table th, .m-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: right; }
.m-table th:first-child { text-align: left; }
.m-table thead th { font-size: 12px; color: var(--muted); font-weight: 600; }
.m-table .down { color: var(--accent); font-weight: 600; } .m-table .up { color: var(--over); font-weight: 600; }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo, .slot { position: relative; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; border: 0; padding: 0; background: var(--field); display: block; }
.photo img, .slot img, .compare img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tag { position: absolute; left: 6px; bottom: 6px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 8px; }
.slot-preview { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 600; border: 1.5px dashed var(--line); border-radius: 12px; }
.photo-full { width: 100%; border-radius: 14px; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.compare figure { margin: 0; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: var(--field); position: relative; }
.compare figcaption { position: absolute; left: 6px; bottom: 6px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 8px; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 18px 8px; }
.empty > .icon { color: var(--accent); }
.empty h3 { font-size: 18px; }
.empty .stack { width: 100%; margin-top: 6px; }
.empty.small { padding: 12px 0; }

/* ---------- Text helpers ---------- */
.muted { color: var(--muted); }
.small { font-size: 14px; } .tiny { font-size: 12px; }
.block { display: block; }
.center { text-align: center; }
.pad { padding: 16px 0; } .pad-s { padding: 4px 0; }

/* ---------- Tab bar ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr); background: color-mix(in srgb, var(--card) 88%, transparent); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--tab-h); color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; }
.tab.on { color: var(--accent); }

/* ---------- Sheets ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 12, .38); opacity: 0; transition: opacity .25s; z-index: 30; }
.sheet-backdrop.open { opacity: 1; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-width: 560px; margin: 0 auto; background: var(--card); border-radius: 22px 22px 0 0; max-height: 88vh; max-height: 88dvh; display: flex; flex-direction: column; transform: translateY(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); }
.sheet.tall { height: 88vh; height: 88dvh; }
.sheet.open { transform: translateY(0); }
.sheet-head { padding: 8px 16px 4px; }
.sheet-grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-title { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-body { padding: 8px 16px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.sheet-foot { padding: 10px 16px calc(env(safe-area-inset-bottom) + 12px); border-top: 1px solid var(--line); }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Scanner ---------- */
.scanner { position: fixed; inset: 0; z-index: 60; background: #000; }
.scan-video { width: 100%; height: 100%; object-fit: cover; }
.scan-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; }
.scan-top { padding: calc(env(safe-area-inset-top) + 10px) 14px 0; display: flex; justify-content: flex-end; }
.scan-frame { align-self: center; width: 78%; max-width: 340px; aspect-ratio: 16 / 9; border: 3px solid rgba(255, 255, 255, .9); border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
.scan-bottom { padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px); display: flex; flex-direction: column; gap: 10px; background: linear-gradient(transparent, rgba(0, 0, 0, .6)); }
.scan-status { color: #fff; text-align: center; font-weight: 600; }
.scan-bottom .input { background: rgba(255, 255, 255, .95); color: #111; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
