:root {
  --bg: #F5F4ED; --card: #EBE8DC; --line: #DDD9C9; --text: #2B2926; --muted: #7A756A;
  --accent: #C96442; --accent-text: #fff; --err: #A63D2A;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #262320; --card: #2F2B27; --line: #433D36; --text: #EDE7DA; --muted: #A0988A; --accent: #D4744F; --err: #E58A76; }
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; font: 16px/1.5 var(--sans); color: var(--text); background: var(--bg); }
[hidden] { display: none !important; }
.wrap { max-width: 560px; margin: 0 auto; padding: 20px 16px 48px; }
.narrow { padding-top: 12vh; }
h1 { font-family: var(--serif); font-weight: 500; font-size: 1.7rem; margin: 0 0 16px; letter-spacing: -0.01em; }
h2, h3 { font-family: var(--serif); font-weight: 500; margin: 0; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
.top { display: flex; justify-content: space-between; align-items: baseline; }
.header-actions { display: flex; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.muted { color: var(--muted); font-size: .92rem; margin: 0; }
.explanation { white-space: pre-line; line-height: 1.65; }
.error { color: var(--err); margin: 0; font-size: .92rem; }
.error:empty { display: none; }
.success { color: #4E7B42; margin: 0; font-size: .92rem; }
.success:empty { display: none; }
@media (prefers-color-scheme: dark) {
  .success { color: #98C98C; }
}
label { display: flex; flex-direction: column; gap: 6px; font-size: .92rem; color: var(--muted); }
input:not([type=file]), textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; }
input[type=number] { appearance: textfield; -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { appearance: none; -webkit-appearance: none; margin: 0; }
textarea { resize: vertical; min-height: 82px; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.password-toggle { display: inline-flex; flex-direction: row; align-items: center; gap: 7px; cursor: pointer; width: max-content; }
.password-toggle input { width: auto; margin: 0; accent-color: var(--accent); }
.btn { font: inherit; font-weight: 600; background: var(--accent); color: var(--accent-text); border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer; flex: 1; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.google-disabled { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.link { font: inherit; font-size: .92rem; background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .82rem; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.field-grid, .quantity-row, .stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { color: var(--muted); font-size: .92rem; margin-bottom: 8px; }
.option-grid { display: grid; gap: 9px; }
.option-card { display: grid; grid-template-columns: auto 1fr; align-items: start; gap: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; }
.option-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.option-card input { width: auto; margin: 4px 0 0; accent-color: var(--accent); }
.option-card span { display: flex; flex-direction: column; gap: 3px; }
.option-card strong { color: var(--text); font-size: .94rem; }
.option-card small { color: var(--muted); font-size: .8rem; }
.refreshed { animation: refreshed-targets .75s ease-out; }
@keyframes refreshed-targets {
  0% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.calculation { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.calculation dl { margin: 10px 0 0; display: grid; gap: 6px; }
.calculation dl div { display: flex; justify-content: space-between; gap: 14px; }
.calculation dt { color: var(--muted); }
.calculation dd { margin: 0; text-align: right; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { font: inherit; background: none; border: 0; padding: 10px 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }
.total { display: flex; align-items: baseline; gap: 8px; color: var(--muted); }
.total strong { font-family: var(--serif); font-weight: 500; font-size: 2.4rem; color: var(--text); margin-left: auto; }
.stat { display: flex; flex-direction: column; color: var(--muted); padding: 15px; }
.stat strong { font-family: var(--serif); color: var(--text); font-size: 2rem; font-weight: 500; line-height: 1.15; margin-top: 4px; }
.stat small { margin-top: 2px; }
.photo { border: 1.5px dashed var(--line); border-radius: 12px; min-height: 120px; align-items: center; justify-content: center; cursor: pointer; overflow: hidden; }
.photo input { display: none; }
.photo img { width: 100%; max-height: 260px; object-fit: cover; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.meal { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.meal img, .meal .ph { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--line); flex: none; }
.meal .ph { display: grid; place-items: center; }
.meal .info { flex: 1; min-width: 0; }
.meal .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal .tm { color: var(--muted); font-size: .85rem; }
.meal .desc { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal .nutrition { display: grid; grid-template-columns: auto auto; column-gap: 4px; align-items: baseline; text-align: right; }
.meal .nutrition strong { font-family: var(--serif); font-size: 1.05rem; }
.meal .nutrition span { color: var(--muted); font-size: .72rem; }
.meal .del { background: none; border: 0; color: var(--muted); font-size: 1.3rem; cursor: pointer; padding: 6px 8px; }
#chart svg { width: 100%; height: auto; display: block; }
#chart .trend + .trend { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
#chart .trend-line { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
#chart circle { fill: var(--accent); }
#chart text { fill: var(--muted); font: 11px var(--sans); text-anchor: middle; }
#chart .point-value { fill: var(--text); }
#chart .axis { stroke: var(--line); }
#chart .target-line { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
#chart .target-label { text-anchor: end; fill: var(--muted); }

@media (max-width: 430px) {
  .field-grid { grid-template-columns: 1fr; }
  .meal { align-items: flex-start; }
  .meal .nutrition { grid-template-columns: auto; }
  .meal .nutrition span { margin-bottom: 2px; }
}
