/* Food log — same bones as the baby log: dark, huge targets, nothing to read twice. */
:root {
  --bg: #0c0e0c;
  --tile: #171a17;
  --tile-press: #232723;
  --line: #2a2f2a;
  --text: #e4e2d6;
  --dim: #878b80;
  --accent: #8fbf6a;        /* sage green */
  --accent-bg: #1c2617;
  --over: #d98a4e;          /* over target: amber, not red. It's information, not a scolding */
  --rec: #c4453b;
  --gap: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app {
  height: 100dvh;
  display: flex; flex-direction: column; gap: var(--gap);
  padding: calc(var(--gap) + var(--safe-top)) var(--gap) calc(var(--gap) + var(--safe-bot));
}

/* ── today card + Audio bar live on Home only ── */
.today, #clippyRow { display: none; }
#app[data-screen="home"] .today { display: block; }
#app[data-screen="home"] #clippyRow { display: flex; }

.today { flex: 0 0 auto; width: 100%; text-align: left; cursor: pointer;
  border: 2px solid var(--line); border-radius: 22px; background: var(--tile); padding: 14px 18px; }
.today:active { background: var(--tile-press); }
.today-top { display: flex; align-items: baseline; gap: 10px; }
.kcal { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.05; }
.of { color: var(--dim); font-size: 17px; }
.meter { height: 10px; border-radius: 5px; background: var(--line); margin: 10px 0 8px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 5px;
  transition: width .3s; }
.meter.over i { background: var(--over); }
.macros { color: var(--dim); font-size: 15px; font-variant-numeric: tabular-nums; }
.macros b { color: var(--text); font-weight: 600; }

/* ── wide bars ── */
.bar {
  flex: 0 0 auto; min-height: 13dvh; width: 100%;
  border: 2px solid var(--line); border-radius: 22px; background: var(--tile);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 10px 14px; cursor: pointer;
}
.bar:active { background: var(--tile-press); }
.bar-label { font-size: 32px; font-weight: 650; letter-spacing: .5px; }
.bar-sub { font-size: 15px; color: var(--dim); text-align: center; line-height: 1.3;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.audio.busy .bar-sub { color: var(--accent); }
.bar.back { min-height: 10dvh; }
.bar.back .bar-label { font-size: 24px; color: var(--dim); }

.bar-row { gap: var(--gap); flex: 0 0 auto; }
.bar-row .audio { flex: 1 1 auto; width: auto; }
.bar-row .type-btn { flex: 0 0 22%; width: auto; padding: 8px 4px; }
.type-btn .kbd { font-size: 30px; line-height: 1; color: var(--dim); }

/* ── screens ── */
.screen { display: none; flex: 1 1 auto; min-height: 0; }
#app[data-screen="home"]      .screen[data-screen="home"] { display: grid; }
#app[data-screen="recording"] .screen[data-screen="recording"],
#app[data-screen="photo"]   .screen[data-screen="photo"],
#app[data-screen="type"]    .screen[data-screen="type"],
#app[data-screen="recent"]  .screen[data-screen="recent"],
#app[data-screen="history"] .screen[data-screen="history"],
#app[data-screen="settings"] .screen[data-screen="settings"] { display: flex; }

/* .grid sets the layout only; whether a .screen shows is decided by the rules above */
.grid { grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; gap: var(--gap); }
.photo-tiles, .type-tiles { display: grid; }

/* ── square tiles ── */
.tile {
  border: 2px solid var(--line); border-radius: 22px; background: var(--tile);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 10px; min-height: 0; cursor: pointer; position: relative;
  transition: background .08s, transform .08s;
}
.tile:active { background: var(--tile-press); transform: scale(.97); }
.tile b { font-size: clamp(30px, 10vw, 56px); font-weight: 650; line-height: 1; }
.screen[data-screen="home"] .tile b { font-size: clamp(44px, 15vw, 80px); }
.tile .name { font-size: 17px; color: var(--dim); }
.tile .sub { font-size: 14px; color: var(--dim); text-align: center; line-height: 1.25; }
.tile.wide { grid-column: 1 / -1; }
.tile.back b { color: var(--dim); font-size: 36px; }
.tile.back { border-style: dashed; }
.tile.accent { border-color: var(--accent); background: var(--accent-bg); }
.tile.accent .sub { color: var(--accent); }

/* ── photo preview ── */
.photo { flex-direction: column; gap: var(--gap); }
.photo img { flex: 1 1 auto; min-height: 0; width: 100%; object-fit: cover; border-radius: 22px;
  border: 2px solid var(--line); background: var(--tile); }
.photo-tiles { flex: 0 0 38dvh; }
.thumb { flex: 0 0 auto; height: 22dvh; width: 100%; object-fit: cover; border-radius: 18px;
  border: 2px solid var(--line); }
.thumb[hidden] { display: none; }

/* ── typing ── */
.type-screen { flex-direction: column; gap: var(--gap); }
.type-screen textarea { flex: 1 1 auto; min-height: 0; width: 100%; resize: none;
  font: inherit; font-size: 20px; line-height: 1.4; color: var(--text);
  background: var(--tile); border: 2px solid var(--accent); border-radius: 22px; padding: 16px;
  user-select: text; -webkit-user-select: text; }
.type-tiles { flex: 0 0 18dvh; }

/* ── recording ── */
.rec { flex-direction: column; gap: var(--gap); }
.rec-tile { flex: 1 1 auto; background: #2a1210; border-color: var(--rec); animation: pulse 1.6s ease-in-out infinite; }
.rec-tile b { font-size: 72px; font-variant-numeric: tabular-nums; }
.rec-tile .name { color: #e8b2aa; font-size: 20px; }
.rec-cancel { min-height: 12dvh; }
.rec-cancel b { font-size: 28px; color: var(--dim); }
@keyframes pulse { 50% { background: #3a1714; } }

/* ── lists (recent + history) ── */
.recent, .history { flex-direction: column; gap: var(--gap); min-height: 0; }
.scroll { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; border-radius: 18px; }
.empty { color: var(--dim); text-align: center; padding: 40px 10px; line-height: 1.4; }

.again { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--tile); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 14px; margin-bottom: 8px; cursor: pointer; }
.again:active { background: var(--tile-press); }
.again .w { flex: 1; font-size: 18px; }
.again .m { display: block; font-size: 13px; color: var(--dim); margin-top: 3px; }
.again .n { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--accent); }

.chart { background: var(--tile); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px 12px 6px; margin-bottom: 14px; }
.chart-head { display: flex; justify-content: space-between; font-size: 14px; color: var(--dim); margin-bottom: 6px; }
.chart-head b { color: var(--text); font-size: 17px; }
.chart svg { display: block; width: 100%; height: 120px; }

.day { margin-bottom: 18px; }
.day-head { position: sticky; top: 0; background: var(--bg); padding: 4px 4px 8px; z-index: 1;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.day-title { font-size: 20px; font-weight: 650; }
.day-total { font-size: 15px; color: var(--dim); font-variant-numeric: tabular-nums; text-align: right; }
.day-total b { color: var(--text); font-size: 18px; }
.day-total.over b { color: var(--over); }

.entry { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 10px;
  width: 100%; text-align: left; background: var(--tile); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 10px; margin-top: 6px; cursor: pointer; }
.entry:active { background: var(--tile-press); }
.entry .t { font-variant-numeric: tabular-nums; color: var(--dim); font-size: 14px; }
.entry .w { font-size: 17px; min-width: 0; }
.entry .m { display: block; font-size: 13px; color: var(--dim); margin-top: 2px; }
.entry .note { display: block; font-size: 13px; opacity: .75; font-style: italic; margin-top: 3px; }
.entry .k { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--accent); }
.entry .k.low::before { content: "~"; color: var(--dim); }
.memo { background: transparent; border-style: dashed; cursor: default; grid-template-columns: 64px 1fr; }
.memo .w { font-size: 15px; }
.memo .q { display: block; color: var(--dim); font-style: italic; margin-top: 4px; }
.memo img { display: block; width: 100%; max-height: 180px; object-fit: cover; border-radius: 10px; margin-top: 8px; }
.memo-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.memo-actions .small-btn { flex: 0 0 auto; padding: 10px 14px; font-size: 14px; }
.history-foot { display: flex; gap: var(--gap); }
.small-btn { flex: 1; text-align: center; padding: 14px 8px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--tile); color: var(--text);
  text-decoration: none; font-size: 16px; cursor: pointer; }

/* ── weight ── */
.weight-now { font-size: 26px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.weight-delta { font-size: 14px; color: var(--dim); }
.weight-delta.down { color: var(--accent); }
.ranges { display: flex; gap: 6px; }
.ranges button { background: none; border: 1px solid var(--line); border-radius: 10px;
  color: var(--dim); font-size: 13px; padding: 4px 10px; cursor: pointer; }
.ranges button.on { border-color: var(--accent); color: var(--accent); }
.chart .row-btns { margin-top: 8px; }
.chart .small-btn { padding: 10px 8px; font-size: 15px; }
.chart.weight svg { height: 140px; }
.chart .empty { padding: 14px 6px; }
.nums.two { grid-template-columns: 1fr 1.6fr; }
.w-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px;
  border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.w-row span { color: var(--dim); font-size: 14px; }
.w-row button { background: none; border: none; color: #d9776d; font-size: 14px; padding: 6px 4px; cursor: pointer; }

/* ── settings ── */
.settings { flex-direction: column; gap: var(--gap); min-height: 0; }
.card { background: var(--tile); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 19px; }
.card .sub-h { margin-top: 18px; }
.card .field input { background: var(--bg); }
.hint { color: var(--dim); font-size: 14px; line-height: 1.4; margin: 6px 0 10px; }
.wide-btn { display: block; width: 100%; }
.accent-btn { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.row-btns { display: flex; gap: 8px; }
.row-btns .small-btn:first-child { flex: 0 0 auto; padding-left: 18px; padding-right: 18px; }
.user { border-top: 1px solid var(--line); padding: 12px 0; }
.user:first-child { border-top: none; padding-top: 0; }
.user .u-name { font-size: 17px; }
.user .u-meta { display: block; font-size: 13px; color: var(--dim); margin-top: 2px; }
.user.off .u-name { color: var(--dim); text-decoration: line-through; }
.user .row-btns { margin-top: 8px; }
.user .row-btns .small-btn { flex: 1; padding: 10px 8px; font-size: 14px; }
.invite { margin-top: 12px; padding: 12px; border: 1px solid var(--accent); border-radius: 14px;
  background: var(--accent-bg); user-select: text; -webkit-user-select: text; }
.invite p { margin: 0 0 10px; line-height: 1.5; }
.invite code { font-size: 16px; color: var(--accent); word-break: break-all; }

/* ── edit sheet ── */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex;
  align-items: flex-end; z-index: 10; }
.sheet[hidden] { display: none; }
.sheet-card { width: 100%; background: var(--bg); border-top: 2px solid var(--line);
  border-radius: 24px 24px 0 0; padding: 18px var(--gap) calc(var(--gap) + var(--safe-bot));
  max-height: 92dvh; overflow-y: auto; }
.sheet-card h2 { margin: 0 0 12px; font-size: 22px; }
.field { margin-bottom: 12px; }
.field label { display: block; color: var(--dim); font-size: 14px; margin-bottom: 6px; }
.field input, .field textarea {
  user-select: text; -webkit-user-select: text;
  width: 100%; font: inherit; font-size: 18px; color: var(--text); background: var(--tile);
  border: 2px solid var(--line); border-radius: 14px; padding: 12px; }
.field textarea { min-height: 70px; resize: vertical; }
.nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.nums input { padding: 12px 8px; }
.choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.choice { padding: 12px 6px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--tile); font-size: 17px; cursor: pointer; }
.choice:active { border-color: var(--accent); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); margin-top: 8px; }
.sheet-actions .tile { min-height: 64px; }
.sheet-actions .tile b { font-size: 22px; }
#sheetDelete b { color: #d9776d; }

/* ── toast ── */
.toast { position: fixed; left: var(--gap); right: var(--gap);
  bottom: calc(var(--gap) + var(--safe-bot)); z-index: 20;
  background: #232823; border: 1px solid var(--line); border-radius: 18px;
  padding: 16px 18px; display: flex; align-items: center; gap: 12px;
  font-size: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.toast[hidden] { display: none; }
.toast span { flex: 1; }
.toast button { background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent);
  border-radius: 12px; padding: 10px 18px; font-size: 18px; font-weight: 650; cursor: pointer; }
