:root {
  /* Light theme — the default */
  --bg: #F4F5F6;
  --panel: #FFFFFF;
  --panel-line: #E2E5E7;
  --amber: #E8A33D;
  --green: #2E9E6B;
  --red: #C0432F;
  --text: #171C1F;
  --muted: #697077;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', -apple-system, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #14181B;
  --panel: #1E2427;
  --panel-line: #2B3236;
  --amber: #E8A33D;
  --green: #5FBF8B;
  --red: #D9614F;
  --text: #EDEFEF;
  --muted: #8A9298;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* The [hidden] attribute must always beat author display rules (e.g. .camera-overlay
   sets display:flex, which otherwise leaves the camera overlay stuck on-screen). */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  height: 100%;
  overscroll-behavior-y: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 76px; /* room for tabbar */
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 8px;
}

.wordmark {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 15px;
  color: var(--amber);
}

.date-input {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
}

.view { display: none; padding: 4px 20px 20px; }
.view.active { display: block; }

/* Gauge */
.gauge-wrap { position: relative; margin: 8px auto 4px; width: 100%; max-width: 320px; }
.gauge { width: 100%; display: block; }
.gauge-track { fill: none; stroke: var(--panel-line); stroke-width: 14; stroke-linecap: round; }
.gauge-fill { fill: none; stroke: var(--amber); stroke-width: 14; stroke-linecap: round;
  stroke-dasharray: 251; stroke-dashoffset: 251; transition: stroke-dashoffset 0.6s ease, stroke 0.3s ease; }
.gauge-needle { stroke: var(--text); stroke-width: 2.5; stroke-linecap: round;
  transform-origin: 100px 110px; transition: transform 0.6s ease; }
.gauge-hub { fill: var(--text); }
.gauge-readout { position: absolute; top: 62%; left: 50%; transform: translate(-50%, -50%); text-align: center; }
.gauge-value { font-family: var(--mono); font-size: 32px; font-weight: 700; line-height: 1; }
.gauge-label { font-size: 10px; letter-spacing: 0.14em; color: var(--muted); margin-top: 4px; }

.stat-row { display: flex; gap: 10px; margin: 18px 0; }
.stat-card { flex: 1; background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 10px; padding: 10px 12px; }
.stat-label { font-size: 10px; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; }
.stat-value { font-family: var(--mono); font-size: 18px; font-weight: 500; margin-top: 4px; }

.panel { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px;
  padding: 16px; margin-bottom: 14px; }
.panel-title { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 12px; font-weight: 600; }

.log-list { display: flex; flex-direction: column; gap: 8px; }
.log-item { display: flex; justify-content: space-between; font-size: 14px; padding: 8px 0;
  border-bottom: 1px solid var(--panel-line); }
.log-item:last-child { border-bottom: none; }
.log-item .name { color: var(--text); }
.log-item .val { font-family: var(--mono); color: var(--muted); }

.input-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.text-input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--panel-line); color: var(--text);
  font-family: var(--sans); font-size: 14px; padding: 10px 12px; border-radius: 8px; }
.text-input.small { flex: 0 0 96px; }
.text-input.full { width: 100%; margin-bottom: 10px; }

.btn { background: var(--panel-line); color: var(--text); border: none; border-radius: 8px;
  padding: 12px 16px; font-family: var(--sans); font-weight: 600; font-size: 14px; }
.btn-accent { background: var(--amber); color: #1A1204; }
.btn-secondary { background: transparent; border: 1px solid var(--panel-line); color: var(--text); margin-bottom: 10px; }
.btn.full { width: 100%; }

.photo-tile { display: flex; align-items: center; justify-content: center; height: 160px;
  background: var(--bg); border: 1px dashed var(--panel-line); border-radius: 10px;
  margin-bottom: 10px; color: var(--muted); font-size: 13px; overflow: hidden; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }

.capture-row { display: flex; gap: 10px; margin-bottom: 10px; }
.capture-row.single { display: block; }
.capture-slot { position: relative; flex: 1; height: 140px; background: var(--bg);
  border: 1px dashed var(--panel-line); border-radius: 10px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; font-family: var(--sans); overflow: hidden; }
.capture-slot.wide { width: 100%; height: 180px; }
.capture-slot.filled { border-style: solid; border-color: var(--green); }
.slot-icon { font-size: 20px; color: var(--amber); }
.slot-label { font-size: 12px; }
.capture-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.help-text { font-size: 12px; color: var(--muted); line-height: 1.5; margin-bottom: 12px; }

/* ---------- Home menu ---------- */
.home-net { text-align: center; color: var(--muted); font-family: var(--mono); font-size: 14px; margin: 12px 0 16px; }
.home-net b { color: var(--text); }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.menu-card { display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 14px;
  padding: 18px 16px; min-height: 112px; color: var(--text); text-align: left;
  font-family: var(--sans); cursor: pointer; }
.menu-card:active { background: var(--panel-line); }
.mc-icon { font-size: 26px; line-height: 1; }
.mc-label { font-weight: 700; font-size: 16px; }
.mc-sub { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ---------- View header + back button ---------- */
.view-head { display: flex; align-items: center; gap: 12px; margin: 2px 0 14px; }
.btn-back { background: transparent; border: none; color: var(--amber);
  font-family: var(--sans); font-weight: 600; font-size: 15px; padding: 6px 2px; cursor: pointer; }
.view-title { font-weight: 700; font-size: 17px; }

/* ---------- Food search typeahead ---------- */
.search-results { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.search-item { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--panel-line); border-radius: 8px;
  padding: 11px 12px; color: var(--text); text-align: left; font-family: var(--sans); cursor: pointer; }
.search-item:active { background: var(--panel-line); }
.si-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.si-name { font-size: 14px; font-weight: 600; }
.si-brand { font-size: 11px; color: var(--muted); }
.si-sub { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.mini-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 10px 0 4px; }
.meal-time-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.meal-time-row label { font-size: 14px; color: var(--text); }
.meal-time-row input { flex: 0 0 130px; }
.search-empty { color: var(--muted); font-size: 13px; padding: 8px 2px; }

/* ---------- Predict items ---------- */
.predict-item { border-bottom: 1px solid var(--panel-line); padding: 10px 0; }
.predict-item:last-child { border-bottom: none; }
.pi-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.pi-top .name { font-size: 14px; }
.pi-top .val { font-family: var(--mono); color: var(--muted); font-size: 13px; white-space: nowrap; }
.pi-actions { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.btn-sm { padding: 7px 12px; font-size: 13px; margin: 0; }
.btn-sm[disabled] { opacity: 0.6; }
.btn-link { background: none; border: none; color: var(--red); font-family: var(--sans);
  font-size: 13px; padding: 4px 0; cursor: pointer; }

/* ---------- Food weight-impact trend ---------- */
.imp-head { font-size: 14px; color: var(--text); margin-bottom: 12px; line-height: 1.5; }
.imp-figures { display: flex; flex-direction: column; gap: 8px; }
.imp-fig { display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 1px solid var(--panel-line); padding-bottom: 6px; }
.imp-fig:last-child { border-bottom: none; }
.imp-k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.imp-v { font-family: var(--mono); font-size: 15px; }
.imp-up { color: var(--red); }
.imp-down { color: var(--green); }
.imp-flat { color: var(--muted); }
.imp-model-note { font-size: 12px; color: var(--muted); margin-top: 10px; font-family: var(--mono); line-height: 1.5; }
.impact-chart { width: 100%; height: 130px; display: block; margin: 12px 0 6px;
  background: var(--bg); border: 1px solid var(--panel-line); border-radius: 8px; }
.ic-baseline { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.6; }
.ic-line { fill: none; stroke-width: 2; }
.imp-legend { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.imp-leg-line { display: inline-block; width: 16px; height: 2px; background: var(--amber); }
.imp-leg-base { display: inline-block; width: 16px; height: 0; border-top: 2px dashed var(--muted); }

/* ---------- Segmented control (measurement context) ---------- */
.segmented { display: flex; gap: 6px; margin-bottom: 12px; }
.seg-btn { flex: 1; background: var(--bg); border: 1px solid var(--panel-line); color: var(--muted);
  border-radius: 8px; padding: 10px 8px; font-family: var(--sans); font-size: 13px; font-weight: 600; cursor: pointer; }
.seg-btn.active { background: var(--amber); color: #1A1204; border-color: var(--amber); }
.seg-sub { font-weight: 500; opacity: 0.85; font-size: 11px; }
.li-time { color: var(--muted); font-family: var(--mono); font-size: 11px; margin-left: 6px; }
.li-amt { color: var(--muted); font-size: 12px; }
.day-total { font-family: var(--mono); font-size: 15px; color: var(--amber); font-weight: 600; margin-bottom: 10px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.cog-btn { background: none; border: none; font-size: 20px; line-height: 1; padding: 2px 4px; cursor: pointer; }

/* ---------- Hamburger + nav drawer ---------- */
.hamburger { background: none; border: none; font-size: 22px; line-height: 1; padding: 2px 6px; cursor: pointer; color: var(--text); }
.nav-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 200; }
.nav-drawer { position: fixed; top: 0; left: 0; bottom: 0; width: 250px; max-width: 80vw;
  background: var(--panel); border-right: 1px solid var(--panel-line); z-index: 201;
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 3px;
  box-shadow: 2px 0 16px rgba(0,0,0,0.28); overflow-y: auto; }
.nav-drawer-head { font-family: var(--mono); font-weight: 700; letter-spacing: 0.1em; color: var(--amber); padding: 6px 10px 14px; }
.nav-link { text-align: left; background: none; border: none; color: var(--text); font-family: var(--sans);
  font-size: 15px; font-weight: 600; padding: 12px 10px; border-radius: 8px; cursor: pointer; }
.nav-link.active { background: var(--panel-line); color: var(--amber); }
.dual-legend { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.dl-swatch { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.net-formula { font-size: 11px; color: var(--muted); text-align: center; margin: -6px 0 14px; line-height: 1.5; }
.log-item .removeItem { background: none; border: none; color: var(--red); margin-left: 8px;
  cursor: pointer; font-size: 13px; }

/* ---------- Sub-tabs (Add Food: Recent / Search / Photo) ---------- */
.subtabs { display: flex; gap: 6px; margin-bottom: 14px; }
.subtab { flex: 1; background: var(--panel); border: 1px solid var(--panel-line); color: var(--muted);
  border-radius: 8px; padding: 9px 8px; font-family: var(--sans); font-size: 13px; font-weight: 600; cursor: pointer; }
.subtab.active { background: var(--amber); color: #1A1204; border-color: var(--amber); }
.subview { display: none; }
.subview.active { display: block; }

/* ---------- Time-series charts (weight / circumference) ---------- */
.chart-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.ts-wrap { background: var(--bg); border: 1px solid var(--panel-line); border-radius: 8px; padding: 4px; }
.ts-chart { width: 100%; height: auto; display: block; }
.ts-line { fill: none; stroke-width: 2; }
.ts-lab { fill: var(--muted); font-family: var(--mono); font-size: 9px; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 22px 8px; text-align: center; }

.camera-overlay { position: fixed; inset: 0; background: #000; z-index: 100;
  display: flex; align-items: center; justify-content: center; }
#cameraVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.guide { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.guide-line { fill: none; stroke: var(--amber); stroke-width: 2; opacity: 0.85; }
.guide-line.thin { stroke-width: 1; opacity: 0.55; }
.guide-line.dashed { stroke-dasharray: 6 6; }

.camera-instructions { position: absolute; top: 24px; left: 16px; right: 16px;
  text-align: center; color: #EDEFEF; font-size: 13px; background: rgba(0,0,0,0.55);
  padding: 10px 14px; border-radius: 10px; font-family: var(--sans); }

.camera-controls { position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 24px 28px calc(24px + env(safe-area-inset-bottom)); }
.camera-spacer { width: 72px; }
.shutter-btn { width: 72px; height: 72px; border-radius: 50%; background: #EDEFEF;
  border: 4px solid rgba(255,255,255,0.35); }
/* The camera overlay always sits over a dark camera view, so its controls stay light
   regardless of the app's light/dark theme. */
.camera-controls .btn-secondary { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.2); color: #EDEFEF; }

.preset-row { display: flex; gap: 10px; margin-bottom: 12px; }
.preset-row.wrap { flex-wrap: wrap; }
.preset-row.wrap .btn-preset { flex: 0 1 auto; }
.unit-label { color: var(--muted); font-family: var(--mono); font-size: 13px; padding: 0 4px; }
.btn-preset { flex: 1; background: var(--bg); border: 1px solid var(--panel-line); color: var(--text); }
.btn-preset.selected { background: var(--green); color: #062012; }

.result-card { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--panel-line); }
.result-source { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.result-name { font-size: 16px; font-weight: 600; margin: 4px 0 8px; }
.result-macros { font-family: var(--mono); font-size: 13px; color: var(--muted); margin-bottom: 12px; line-height: 1.6; }

.model-info { font-size: 13px; color: var(--muted); line-height: 1.6; }
.model-info .highlight { color: var(--amber); font-family: var(--mono); }

.trend-list { display: flex; flex-direction: column; gap: 6px; }
.trend-row { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 13px;
  padding: 6px 0; border-bottom: 1px solid var(--panel-line); }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; max-width: 480px; margin: 0 auto;
  display: flex; background: var(--panel); border-top: 1px solid var(--panel-line);
  padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; background: none; border: none; color: var(--muted); font-family: var(--sans);
  font-size: 12px; font-weight: 600; padding: 14px 0; letter-spacing: 0.04em; }
.tab.active { color: var(--amber); }
