:root {
  --bg: #f3f7f2; --card: #fff; --ink: #18241b; --muted: #6d7c70; --line: #dde7dc;
  --accent: #2b8a3e; --accent-ink: #fff; --soft: #dcefdc; --warm: #fff3d6; --warm-ink: #8a5a00;
  --c-trend: #2b8a3e; --c-scale: #3b74c4; --track: #dcefdc; --over: #c2410c; --tabbar: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #101511; --card: #1b221c; --ink: #e9f1ea; --muted: #94a596; --line: #2d382f; --accent: #63d47a; --accent-ink: #062b0f; --soft: #213a26; --warm: #3a2f12; --warm-ink: #ffd772;
    --c-trend: #37a750; --c-scale: #5b8fd9; --track: #233a28; --over: #fb923c; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0; color: var(--ink); background: var(--bg);
  font: 17px/1.45 -apple-system, system-ui, sans-serif;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
body.locked { overflow: hidden; }
main { max-width: 600px; margin: 0 auto; display: grid; gap: 14px; }
.view { display: grid; gap: 14px; }
h1 { margin: 0; font-size: 26px; line-height: 1.1; flex: 1; }
h2 { margin: 0; font-size: 19px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 14px; }
.head { display: flex; align-items: center; gap: 10px; }
.logo { width: 44px; height: 44px; border-radius: 10px; }

.card { background: var(--card); border-radius: 18px; padding: 14px 16px; display: grid; gap: 10px; box-shadow: 0 1px 0 var(--line); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.row label { font-weight: 600; }
.actions { display: flex; align-items: center; gap: 6px; }
.lbl { font-weight: 600; margin-top: 6px; display: grid; gap: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two .lbl { margin-top: 0; font-size: 15px; }
.hint-text { margin: -4px 0 0; }

input[type=text], input[type=number], input[type=search], textarea {
  font: inherit; font-size: 17px; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; min-height: 44px; padding: 8px 12px; width: 100%;
}
input[type=search] { -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; line-height: 1.4; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--soft); color: var(--accent); font-size: 26px; line-height: 1; }
.stepper output { min-width: 44px; text-align: center; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--card); border-radius: 12px; padding: 3px; box-shadow: 0 1px 0 var(--line); }
.seg button { font: inherit; font-size: 15px; min-height: 40px; border: 0; border-radius: 10px; background: none; color: var(--ink); padding: 0 6px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.seg.lang { width: 240px; margin: 8px auto 0; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: -4px -16px; padding: 4px 16px; scrollbar-width: none; }
.chips:empty { display: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { font: inherit; font-size: 15px; flex: none; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.chips button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

.btn { font: inherit; font-weight: 700; min-height: 48px; border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink); padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; text-align: center; }
.btn.big { min-height: 58px; font-size: 19px; }
.btn.ghost { background: var(--soft); color: var(--accent); }
.btn.google { background: #fff; color: #1f1f1f; border: 1px solid #dadce0; gap: 10px; font-weight: 600; }
.btn.danger { background: none; color: #e03131; margin-top: 18px; }
.signin { text-align: center; padding: 18px 16px; }
.signin p { margin: 0; }
.link { font: inherit; border: 0; background: none; color: var(--accent); min-height: 44px; padding: 0 4px; }
.link.strong { font-weight: 700; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--soft); color: var(--ink); font-size: 18px; flex: none; }
.icon-btn.add { background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1; font-weight: 400; }
#fav { font-size: 22px; color: var(--muted); }
#fav.on { color: #f59f00; }
button { cursor: pointer; }
button:active { transform: scale(.97); }
button:disabled { opacity: .4; }

/* list */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.list:empty { display: none; }
.list li { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; background: var(--card); border-radius: 16px; padding: 10px; cursor: pointer; box-shadow: 0 1px 0 var(--line); min-height: 84px; }
.list .thumb { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; background: var(--soft); display: grid; place-items: center; font-size: 28px; }
.list .t { font-weight: 700; line-height: 1.25; }
.list .s { font-size: 14px; color: var(--muted); }
.star { color: #f59f00; }
.chev { color: var(--muted); font-size: 26px; padding-right: 4px; }

/* one recipe */
.r-photo { width: 100%; max-height: 320px; object-fit: cover; border-radius: 18px; display: block; cursor: zoom-in; }
.r-name { font-size: 26px; line-height: 1.15; }
#r-meta { margin: 4px 0 0; }
.note { margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--warm); color: var(--warm-ink); font-size: 15px; }
.ing { list-style: none; margin: 0; padding: 0; }
.ing li { padding: 10px 0 10px 32px; border-top: 1px solid var(--line); position: relative; cursor: pointer; min-height: 44px; }
.ing li:first-child { border-top: 0; }
.ing li::before { content: ''; position: absolute; left: 0; top: 12px; width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--line); }
.ing li.done { color: var(--muted); text-decoration: line-through; }
.ing li.done::before { background: var(--accent); border-color: var(--accent); }
.ing li.h { font-weight: 700; padding-left: 0; cursor: default; margin-top: 6px; }
.ing li.h::before, .ing li.muted::before { display: none; }
.ing li.muted { padding-left: 0; cursor: default; }
.steps { margin: 0; padding-left: 26px; display: grid; gap: 12px; }
.steps li::marker { font-weight: 700; color: var(--accent); }
.steps b.tm { color: var(--accent); }
.steps.preview { background: var(--card); border-radius: 14px; padding: 12px 12px 12px 34px; font-size: 15px; }
.steps.preview:empty { display: none; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { font-size: 14px; font-weight: 700; padding: 3px 9px; border-radius: 8px; background: var(--soft); color: var(--accent); white-space: nowrap; }
.badge.temp { background: var(--warm); color: var(--warm-ink); }
.pre { margin: 0; white-space: pre-wrap; }

/* editor */
.sheet, .cook { position: fixed; inset: 0; z-index: 10; background: var(--bg); display: flex; flex-direction: column; }
.sheet-top, .cook-top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); background: var(--card);
  padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
}
.sheet-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 10px;
  padding: 16px max(16px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.sheet-body > * { width: 100%; max-width: 600px; margin-left: auto; margin-right: auto; }
.e-photo:empty { display: none; }
.e-photo img { width: 100%; max-height: 220px; object-fit: cover; border-radius: 14px; display: block; }
.file input { display: none; }

/* cook mode */
.cook-title { flex: 1; min-width: 0; display: grid; text-align: center; line-height: 1.2; }
.cook-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 5px; background: var(--line); }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.timers { display: flex; gap: 8px; overflow-x: auto; padding: 10px max(16px, env(safe-area-inset-left)) 0; }
.timers[hidden] { display: none; }
.timers button { font: inherit; font-size: 15px; font-weight: 700; flex: none; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 0; background: var(--soft); color: var(--accent); font-variant-numeric: tabular-nums; }
.timers button.ring { background: #e03131; color: #fff; }
.cook-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 20px max(18px, env(safe-area-inset-right)) 20px max(18px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 20px;
}
.cook-body > * { width: 100%; max-width: 640px; margin: 0 auto; }
.cook-text { font-size: 25px; line-height: 1.35; margin: 0; font-weight: 500; }
.cook-text b.tm { color: var(--accent); white-space: nowrap; }
.cook-tm { display: grid; gap: 14px; }
.cook-tm:empty { display: none; }
.tm-card { background: var(--card); border-radius: 20px; padding: 14px; display: grid; gap: 14px; box-shadow: 0 1px 0 var(--line); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; }
.tile { background: var(--soft); color: var(--accent); border-radius: 14px; padding: 10px 6px; text-align: center; display: grid; align-content: center; min-height: 76px; }
.tile small { font-size: 14px; font-weight: 600; opacity: .85; }
.tile b { font-size: 24px; line-height: 1.15; }
.tile.temp { background: var(--warm); color: var(--warm-ink); }
.tile.mode b { font-size: 19px; }
.timer { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timer .clock { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; flex: 1; min-width: 120px; line-height: 1; }
.timer .clock.ring { color: #e03131; }
.cook-nav {
  display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; border-top: 1px solid var(--line); background: var(--card);
  padding: 10px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.cook-nav .btn { min-height: 60px; font-size: 19px; }
.cook-nav .btn.finish { background: #f59f00; color: #2b1a00; }
.cook.ringing .cook-body { animation: flash .5s 6 alternate; }
@keyframes flash { to { background: rgba(224, 49, 49, .25); } }
.panel { position: absolute; inset: 0; z-index: 2; background: var(--bg); display: flex; flex-direction: column; }
.panel-top {
  display: flex; align-items: center; justify-content: space-between; background: var(--card); border-bottom: 1px solid var(--line);
  padding: max(6px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
}
.panel .ing { flex: 1; overflow-y: auto; padding: 8px max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); font-size: 19px; }
.panel .ing li::before { top: 14px; }

.viewer { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

.hint { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--soft); border-radius: 14px; padding: 8px 8px 8px 14px; font-size: 15px; }
.toast { position: fixed; left: 50%; bottom: max(96px, calc(env(safe-area-inset-bottom) + 84px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 40; max-width: calc(100vw - 32px); text-align: center; }



/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding: 4px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
.tabbar button { font: inherit; font-size: 12px; border: 0; background: none; color: var(--muted); min-height: 54px; display: grid; justify-items: center; align-content: center; gap: 1px; }
.tabbar .ti { font-size: 22px; line-height: 1.1; }
.tabbar button.on { color: var(--accent); font-weight: 700; }
.logo.big { width: 72px; height: 72px; border-radius: 16px; margin: 0 auto; }
.signin h2 { margin-top: 4px; }
.strong { font-weight: 700; }
.right { text-align: right; }

/* today */
.day-title { text-align: center; font-size: 22px; }
.summary { gap: 14px; }
.hero-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.hero { font-size: 48px; line-height: 1; font-weight: 800; display: block; }
.hero.over { color: var(--over); }
.meters { display: grid; gap: 10px; }
.meter-top { display: flex; justify-content: space-between; font-size: 15px; font-variant-numeric: tabular-nums; }
.meter-top span:first-child { font-weight: 600; }
.track { height: 10px; border-radius: 5px; background: var(--track); overflow: hidden; }
.track i { display: block; height: 100%; width: 0; border-radius: 5px; background: var(--accent); }
.meter.over .track i { background: var(--over); }
.meter.over .meter-top b { color: var(--over); }
.wquick { grid-template-columns: auto 1fr auto; align-items: center; }
.unit-in { position: relative; display: flex; align-items: center; gap: 6px; }
.unit-in input { flex: 1; min-width: 0; }
.entries, .results, .wlist, .links { list-style: none; margin: 0; padding: 0; }
.entries { display: grid; gap: 8px; }
.entries:empty { display: none; }
.entries li { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; background: var(--card); border-radius: 14px; padding: 10px 14px; min-height: 56px; cursor: pointer; box-shadow: 0 1px 0 var(--line); }
.entries .t, .results .t { font-weight: 600; line-height: 1.25; }
.entries .s, .results .s { font-size: 14px; color: var(--muted); }
.entries .kcal { font-size: 18px; font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 6px 2px; cursor: pointer; }
.check input { width: 24px; height: 24px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.check small { display: block; font-size: 13px; }

/* add sheet */
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.three .btn { font-size: 14px; padding: 0 6px; }
h3.sec { margin: 10px 0 2px; font-size: 15px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.results { display: grid; background: var(--card); border-radius: 14px; box-shadow: 0 1px 0 var(--line); }
.results li { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px 14px; min-height: 56px; border-top: 1px solid var(--line); cursor: pointer; }
.results li:first-child { border-top: 0; }
.src { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 7px; background: var(--soft); color: var(--accent); white-space: nowrap; }
.src.off { background: var(--warm); color: var(--warm-ink); }
.src.recipe { background: var(--ink); color: var(--bg); }
.amount-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.amount-row input { font-size: 24px; font-weight: 700; text-align: center; min-height: 56px; }
select { font: inherit; font-size: 17px; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 12px; min-height: 44px; padding: 8px 10px; width: 100%; }
.macro-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.macro-row div { background: var(--soft); border-radius: 14px; padding: 8px 4px; text-align: center; color: var(--ink); }
.macro-row div:first-child { background: var(--accent); color: var(--accent-ink); }
.macro-row b { display: block; font-size: 20px; line-height: 1.15; }
.macro-row.big b { font-size: 24px; }
.macro-row span { font-size: 12px; opacity: .85; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { display: grid; gap: 4px; font-size: 15px; font-weight: 600; }
.small-btn { min-height: 40px; font-size: 15px; padding: 0 12px; }
.links li { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; }
.links li:first-child { border-top: 0; }
.links:empty { display: none; }

/* scanner */
.scan { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; }
.scan video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; left: 10%; right: 10%; top: 38%; height: 22%; border: 3px solid rgba(255,255,255,.9); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
.scan-top, .scan-bottom { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
.scan-top { top: 0; padding-top: max(10px, env(safe-area-inset-top)); background: linear-gradient(rgba(0,0,0,.6), transparent); }
.scan-top .link { color: #fff; }
.scan-bottom { bottom: 0; padding-bottom: max(16px, env(safe-area-inset-bottom)); justify-content: center; background: linear-gradient(transparent, rgba(0,0,0,.6)); }

/* weight */
.tiles3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border-radius: 16px; padding: 10px 12px; display: grid; gap: 2px; box-shadow: 0 1px 0 var(--line); }
.stat b { font-size: 19px; line-height: 1.2; }
.row.tight { min-height: 0; }
.chart-card { gap: 6px; }
.chart { min-height: 190px; touch-action: pan-y; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.trend { stroke: var(--c-trend); }
.chart .dot { stroke: var(--card); stroke-width: 2; }
.chart .dot.scale { fill: var(--c-scale); }
.chart .end { stroke: var(--card); stroke-width: 2; fill: var(--c-trend); }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.legend { display: flex; gap: 12px; font-size: 13px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 5px; }
.key { display: inline-block; flex: none; }
.key.dot { width: 9px; height: 9px; border-radius: 50%; }
.key.line { width: 14px; height: 2px; border-radius: 1px; }
.key.scale { background: var(--c-scale); }
.key.trend { background: var(--c-trend); }
.tip { position: absolute; z-index: 30; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.15); pointer-events: none; display: grid; gap: 2px; }
.tip > div { display: flex; align-items: center; gap: 6px; }
.tip .tip-day { color: var(--muted); }
.tip b { font-variant-numeric: tabular-nums; }
.tip span { color: var(--muted); }
.wlist li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; min-height: 48px; border-top: 1px solid var(--line); cursor: pointer; font-variant-numeric: tabular-nums; }
.wlist li:first-child { border-top: 0; }
#tdee-note { margin: -6px 0 0; }

[hidden] { display: none !important; }
