:root {
  --bg:#f3f4f6; --card:#ffffff; --ink:#111827; --muted:#6b7280;
  --line:#e5e7eb; --accent:#111827; --accent-ink:#ffffff; --good:#166534; --warn:#92400e;
  --control:#ffffff; --secondary:#e5e7eb; --overlay:rgba(17,24,39,.5);
}
:root[data-theme="dark"] {
  --bg:#0f172a; --card:#1e293b; --ink:#f8fafc; --muted:#cbd5e1;
  --line:#334155; --accent:#f8fafc; --accent-ink:#111827; --good:#86efac;
  --warn:#fcd34d; --control:#0f172a; --secondary:#334155; --overlay:rgba(2,6,23,.76);
}
@media (prefers-color-scheme:dark) {
  :root:not([data-theme="light"]) {
    --bg:#0f172a; --card:#1e293b; --ink:#f8fafc; --muted:#cbd5e1;
    --line:#334155; --accent:#f8fafc; --accent-ink:#111827; --good:#86efac;
    --warn:#fcd34d; --control:#0f172a; --secondary:#334155; --overlay:rgba(2,6,23,.76);
  }
}
* { box-sizing:border-box; }
[hidden] { display:none !important; }
body {
  margin:0; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  background:var(--bg); color:var(--ink); padding-bottom:96px;
}
header {
  padding:calc(18px + env(safe-area-inset-top)) 18px 18px;
  background:#111827; color:white;
}
.header-row { max-width:760px; margin:auto; display:flex; align-items:flex-start; justify-content:space-between; gap:16px; }
header h1 { margin:0; font-size:26px; }
header p { margin:6px 0 0; opacity:.75; font-size:14px; }
.icon-button {
  width:44px; height:44px; flex:0 0 44px; padding:0; display:grid; place-items:center;
  border:1px solid rgba(255,255,255,.22); background:rgba(255,255,255,.12); color:white;
}
.icon-button svg { width:22px; height:22px; }
main { max-width:760px; margin:auto; padding:14px; }
.grid { display:grid; gap:12px; }
.grid.two { grid-template-columns:1fr 1fr; }
.card {
  background:var(--card); border-radius:18px; padding:16px;
  box-shadow:0 2px 10px rgba(0,0,0,.05);
}
h2 { font-size:19px; margin:0 0 12px; }
h3 { font-size:16px; margin:16px 0 8px; }
.metric { font-size:28px; font-weight:700; }
.sub { color:var(--muted); font-size:13px; }
.row { display:flex; gap:10px; align-items:center; justify-content:space-between; }
input, button, select {
  font:inherit; border-radius:12px; border:1px solid var(--line); padding:11px 12px;
}
input, select { width:100%; background:var(--control); color:var(--ink); }
button {
  min-height:44px; background:var(--accent); color:var(--accent-ink); border:none; font-weight:600; cursor:pointer;
}
button.secondary { background:var(--secondary); color:var(--ink); }
button.danger { background:#b91c1c; color:white; }
button:focus-visible, input:focus-visible, select:focus-visible { outline:3px solid #60a5fa; outline-offset:2px; }
.pill { display:inline-block; padding:6px 10px; border-radius:999px; background:#eef2ff; font-size:12px; }
.progress { background:#e5e7eb; height:10px; border-radius:999px; overflow:hidden; }
.progress > div { height:100%; background:var(--accent); width:0%; }
.check {
  display:flex; gap:10px; align-items:center; padding:10px 0; border-bottom:1px solid var(--line);
}
.check:last-child { border-bottom:none; }
.check input { width:20px; height:20px; }
.timeline { display:grid; gap:10px; }
.event { display:grid; grid-template-columns:76px 1fr; gap:10px; }
.event time { color:var(--muted); font-size:13px; }
.tabs {
  position:fixed; bottom:0; left:0; right:0; display:grid; grid-template-columns:repeat(5,1fr);
  background:var(--card); border-top:1px solid var(--line); padding-bottom:env(safe-area-inset-bottom); z-index:5;
}
.tab {
  border:none; border-radius:0; background:var(--card); color:var(--muted); padding:12px 4px;
  font-size:11px; font-weight:600;
}
.tab.active { color:var(--ink); }
section.view { display:none; }
section.view.active { display:block; }
.recipe details { border-top:1px solid var(--line); padding:12px 0; }
.recipe details:first-of-type { border-top:none; }
summary { font-weight:700; cursor:pointer; }
ul, ol { padding-left:20px; }
.workout li { margin:7px 0; }
canvas { width:100%; height:220px; }
.notice { background:#fffbeb; color:var(--warn); padding:12px; border-radius:12px; font-size:13px; }
:root[data-theme="dark"] .notice { background:#422006; }
@media (prefers-color-scheme:dark) { :root:not([data-theme="light"]) .notice { background:#422006; } }
body.settings-open { overflow:hidden; }
.settings-overlay {
  position:fixed; inset:0; z-index:20; display:flex; justify-content:flex-end;
  background:var(--overlay);
}
.settings-panel {
  width:min(100%,520px); height:100%; overflow:auto; overscroll-behavior:contain;
  background:var(--bg); padding:calc(14px + env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom));
  box-shadow:-8px 0 30px rgba(0,0,0,.18);
}
.settings-header { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:14px; }
.settings-header h2 { margin:0; font-size:28px; }
.close-button { width:44px; height:44px; padding:0; font-size:24px; line-height:1; }
.settings-form { display:grid; gap:12px; }
.settings-group { margin:0; border:0; min-width:0; }
.settings-group legend { padding:0 2px 8px; color:var(--muted); font-size:13px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; }
.settings-list { overflow:hidden; background:var(--card); border-radius:18px; box-shadow:0 2px 10px rgba(0,0,0,.05); }
.setting-row { display:grid; gap:7px; padding:13px 16px; border-bottom:1px solid var(--line); }
.setting-row:last-child { border-bottom:0; }
.setting-row label, .setting-label { font-weight:600; }
.setting-help { color:var(--muted); font-size:13px; line-height:1.4; }
.choice-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:7px; }
.choice { position:relative; }
.choice input { position:absolute; opacity:0; pointer-events:none; }
.choice span { min-height:44px; display:grid; place-items:center; padding:9px 7px; border:1px solid var(--line); border-radius:11px; text-align:center; font-size:13px; font-weight:600; }
.choice input:checked + span { background:var(--accent); color:var(--accent-ink); border-color:var(--accent); }
.choice input:focus-visible + span { outline:3px solid #60a5fa; outline-offset:2px; }
.toggle-row { grid-template-columns:1fr auto; align-items:center; }
.toggle { width:50px; height:30px; accent-color:#16a34a; }
.settings-actions { display:grid; gap:9px; }
.settings-actions button, .file-button { width:100%; }
.file-button { min-height:44px; display:grid; place-items:center; padding:11px 12px; border-radius:12px; background:var(--secondary); color:var(--ink); font-weight:600; cursor:pointer; }
.file-button input { position:absolute; width:1px; height:1px; opacity:0; }
.status-message { min-height:20px; margin:0; font-size:14px; font-weight:600; }
.status-message.success { color:var(--good); }
.status-message.error { color:#b91c1c; }
:root[data-theme="dark"] .status-message.error { color:#fca5a5; }
@media (prefers-color-scheme:dark) { :root:not([data-theme="light"]) .status-message.error { color:#fca5a5; } }
.confirm-box { display:grid; gap:9px; padding:12px; border:1px solid #ef4444; border-radius:12px; background:var(--card); }
.confirm-actions { display:grid; grid-template-columns:1fr 1fr; gap:9px; }
.about-list { margin:0; padding:0; list-style:none; }
.compact-action { width:100%; margin-top:10px; }
.metric-unit { font-size:14px; color:var(--muted); }
.nutrition-progress { margin:10px 0 7px; }
.macro-grid, .meal-total-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:7px; margin-top:10px; }
.macro-grid div, .meal-total-grid div { padding:8px; border:1px solid var(--line); border-radius:10px; font-size:12px; }
.macro-grid strong, .meal-total-grid strong { display:block; margin-top:2px; font-size:14px; }
.food-date-header { display:grid; grid-template-columns:44px 1fr 44px; align-items:end; gap:10px; text-align:center; }
.food-date-header h2 { margin-bottom:4px; }
.date-button { width:44px; padding:0; font-size:24px; }
.food-daily-totals { margin-top:14px; }
.food-meals { display:grid; gap:12px; margin:12px 0; }
.meal-header { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.meal-header h2 { margin:0; }
.meal-entry { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:8px; padding:11px 0; border-top:1px solid var(--line); }
.meal-entry-actions { display:flex; gap:6px; align-items:center; }
.meal-entry-actions button { min-width:44px; padding:7px; }
.empty-food { margin:12px 0; color:var(--muted); font-size:14px; }
.food-dialog { width:min(calc(100% - 24px),520px); max-height:calc(100% - 24px); overflow:auto; margin:auto; padding:16px; border-radius:20px; background:var(--bg); }
.food-form-grid, .macro-inputs { display:grid; gap:12px; }
.macro-inputs { grid-template-columns:repeat(2,minmax(0,1fr)); }
.food-form-grid label { display:block; margin-bottom:6px; font-weight:600; }
.field-error { min-height:18px; margin:4px 0 0; color:#b91c1c; font-size:12px; }
.dialog-actions { display:grid; grid-template-columns:1fr 1fr; gap:9px; margin-top:14px; }
.over-target { color:var(--warn); font-weight:600; }
.estimate-label { font-size:.72em; font-weight:500; color:var(--muted); }
.split-fields { display:grid; grid-template-columns:1fr 1fr; gap:9px; }
.split-fields label { display:grid; gap:6px; font-size:13px; }
.two-choice { grid-template-columns:repeat(2,1fr); }
.nutrition-summary { margin-top:10px; padding:16px; border-radius:18px; background:var(--card); box-shadow:0 2px 10px rgba(0,0,0,.05); }
.nutrition-summary h3 { margin:0 0 12px; }
.summary-grid { display:grid; grid-template-columns:1fr 1fr; gap:1px; margin:0; overflow:hidden; border:1px solid var(--line); border-radius:12px; background:var(--line); }
.summary-grid div { min-width:0; padding:10px; background:var(--card); }
.summary-grid dt { color:var(--muted); font-size:12px; }
.summary-grid dd { margin:3px 0 0; font-size:16px; font-weight:700; }
.validation-summary { display:grid; gap:6px; margin-top:12px; }
.validation-summary p { margin:0; padding:9px 10px; border-radius:10px; font-size:13px; }
.validation-summary .error { color:#991b1b; background:#fef2f2; }
.validation-summary .warning { color:var(--warn); background:#fffbeb; }
.safety-copy { margin:12px 0 0; }
:root[data-theme="dark"] .validation-summary .error { color:#fecaca; background:#450a0a; }
:root[data-theme="dark"] .validation-summary .warning { background:#422006; }
@media (prefers-color-scheme:dark) {
  :root:not([data-theme="light"]) .validation-summary .error { color:#fecaca; background:#450a0a; }
  :root:not([data-theme="light"]) .validation-summary .warning { background:#422006; }
}
.about-list li { padding:4px 0; }
@media (max-width:520px) { .grid.two { grid-template-columns:1fr; } }
@media (max-width:360px) { .macro-inputs { grid-template-columns:1fr; } }
