/* Food Log — a day of eating, read as two budgets spent against the clock. */

:root {
  --ground: #e3e7de;
  --raised: #f2f4ee;
  --ink: #1e2a20;
  --ink-soft: #5e6b5c;
  --rule: #cbd2c4;
  --kcal: #6b7f4a;
  --salt: #2f4d6e;
  --over: #9e3528;

  --dock: 92px;
  --page: 640px;          /* one column; the desktop grid widens it */
  --side: 340px;          /* the budget column, once there are two */
  --gutter: 56px;
  --step: 1.333;          /* perfect fourth */
  --t-micro: 11.5px;
  --t-small: 13.5px;
  --t-body: 16px;
  --t-mid: 21px;
  --t-big: clamp(40px, 13vw, 54px);

  --sans: "Archivo", ui-sans-serif, -apple-system, system-ui, sans-serif;
  --fig: "Fraunces", ui-serif, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #171c17;
    --raised: #1f251f;
    --ink: #e6eadf;
    --ink-soft: #97a192;
    --rule: #333b32;
    --kcal: #9dbb6a;
    --salt: #6fa3c9;
    --over: #d4654f;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding-bottom: calc(var(--dock) + 28px + env(safe-area-inset-bottom));
  background: var(--ground);
  color: var(--ink);
  font: 400 var(--t-body)/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

main { max-width: var(--page); margin: 0 auto; padding: 0 20px; }

/* One column on a phone: budget, note, diary, then the rest of the nutrition.
   .panel is only a box once the screen is wide enough to hold two columns. */
.layout { display: flex; flex-direction: column; }
.panel { display: contents; }
.diary { order: 2; }
.rest { order: 3; }
.account { order: 4; }

:is(button, input, summary):focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 3px;
}

.num, .clock, .rest-grid dd, .seg-kcal, .seg-na {
  font-family: var(--fig);
  font-variant-numeric: tabular-nums lining-nums;
  font-variation-settings: "SOFT" 18, "WONK" 0;
}

/* ---- date ---- */

.daybar {
  position: relative;
  display: flex; align-items: center; gap: 4px;
  padding: 22px 0 26px;
}
.daybar h1 {
  flex: 1; margin: 0 8px 0 0;
  font-family: var(--fig); font-weight: 400; font-size: var(--t-mid);
  font-variation-settings: "SOFT" 30, "WONK" 1, "opsz" 40;
  letter-spacing: -.005em;
  cursor: pointer;
}
.step {
  width: 34px; height: 34px; flex: none;
  border: 0; border-radius: 50%; background: transparent;
  color: var(--ink-soft); font-size: 15px; cursor: pointer;
  transition: background .15s, color .15s;
}
.step:hover { background: var(--raised); color: var(--ink); }
#day-input { position: absolute; left: 44px; bottom: 18px; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; }

/* ---- the two budgets ---- */

.figures { display: flex; gap: 28px; align-items: flex-start; }
.figure { flex: 1 1 0; min-width: 0; }
.num {
  display: block;
  font-size: var(--t-big); font-weight: 300; line-height: .92;
  font-variation-settings: "SOFT" 10, "WONK" 0, "opsz" 120;
  letter-spacing: -.028em;
  color: var(--kcal);
}
.figure.salt .num { color: var(--salt); }
.figure.salt.past .num { color: var(--over); }
.unit {
  display: block; margin-top: 9px;
  font-size: var(--t-small); line-height: 1.35; color: var(--ink-soft);
}

.rails { margin-top: 22px; }
.rail {
  position: relative;
  display: flex; gap: 2px;
  height: 13px; margin-bottom: 4px;
  background: color-mix(in srgb, var(--rule) 55%, transparent);
  border-radius: 2px;
  overflow: hidden;
}
.rail:last-of-type { margin-bottom: 9px; }
.seg {
  min-width: 2px;
  background: var(--kcal);
  transition: flex-basis .5s cubic-bezier(.22,.7,.3,1);
}
[data-rail="sodium_mg"] .seg { background: var(--salt); }
.spill { position: absolute; top: 0; bottom: 0; background: var(--over); z-index: 1; }
/* The target line sits inside the fill once you cross it, which is the point. */
.limit {
  position: absolute; top: 0; bottom: 0; width: 1px;
  margin-left: -1px;            /* stays visible when the target is the full rail */
  background: var(--ink); opacity: .55; z-index: 2;
}
.rail-key {
  display: flex; gap: 2px;
  font-size: var(--t-micro); color: var(--ink-soft); letter-spacing: .01em;
}
.rail-key span { overflow: hidden; white-space: nowrap; text-overflow: clip; }

/* ---- what the day adds up to ---- */

.note {
  margin: 24px 0 0;
  padding: 1px 0 2px 15px;
  border-left: 2px solid var(--kcal);
  font-family: var(--fig);
  font-size: 16.5px; line-height: 1.45;
  font-variation-settings: "SOFT" 28, "WONK" 1, "opsz" 24;
  color: var(--ink);
  animation: rise .22s ease-out;
}
.note.watch { border-left-color: var(--salt); }
.note.over { border-left-color: var(--over); }
.note.thinking { color: var(--ink-soft); border-left-color: var(--rule); }

/* ---- the diary ---- */

.diary { margin-top: 34px; }
.diary ol { list-style: none; margin: 0; padding: 0; }

.meal {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin: 26px 0 8px; padding-bottom: 7px;
  border-bottom: 1px solid var(--rule);
  font-size: var(--t-small); font-weight: 600;
  color: var(--ink);
}
.meal span:last-child { font-weight: 400; color: var(--ink-soft); }
.meal:first-child { margin-top: 0; }

.entry {
  display: grid;
  grid-template-columns: 52px 1fr 52px 78px 20px;
  align-items: baseline; gap: 10px;
  padding: 9px 0;
}
.clock { font-size: var(--t-small); color: var(--ink-soft); font-variation-settings: "SOFT" 10, "opsz" 14; }
.what { min-width: 0; }
.what b {
  display: block; font-weight: 500; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.what i {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  font-style: normal; margin-top: 1px;
  font-size: var(--t-small); line-height: 1.35; color: var(--ink-soft);
  overflow: hidden;
}
/* Estimated rows outnumber matched ones, so the mark has to whisper. */
.guess {
  cursor: help;
  text-decoration: underline dotted color-mix(in srgb, var(--ink-soft) 40%, transparent);
  text-underline-offset: 3px;
}
.seg-kcal { text-align: right; font-size: 15px; font-variation-settings: "SOFT" 10, "opsz" 20; }

/* the salt column: one shared left edge, so bar lengths compare down the page */
.saltcell { display: flex; align-items: center; gap: 7px; }
.saltbar {
  flex: 1; height: 7px; border-radius: 1px;
  background: color-mix(in srgb, var(--rule) 55%, transparent);
  overflow: hidden;
}
.saltbar span { display: block; height: 100%; background: var(--salt); }
.saltbar span.past { background: var(--over); }
.seg-na { font-size: var(--t-small); color: var(--ink-soft); text-align: right; min-width: 38px; }

.drop {
  border: 0; background: transparent;
  color: color-mix(in srgb, var(--ink-soft) 45%, transparent);
  width: 24px; height: 24px; border-radius: 50%;
  font-size: 17px; line-height: 1; cursor: pointer;
  transition: color .15s, background .15s;
}
.entry:hover .drop { color: var(--ink-soft); }
.drop:hover { background: var(--raised); color: var(--over); }

.empty { color: var(--ink-soft); font-size: var(--t-small); padding: 6px 0 2px; }

/* ---- the rest ---- */

.rest { margin: 34px 0 10px; border-top: 1px solid var(--rule); }
.rest summary {
  list-style: none; cursor: pointer;
  padding: 14px 0; font-size: var(--t-small); color: var(--ink-soft);
}
.rest summary::-webkit-details-marker { display: none; }
.rest summary::after { content: " \002B"; color: var(--ink-soft); }
.rest[open] summary::after { content: " \2212"; }
.rest-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 16px 14px; margin: 0 0 22px;
}
.rest-grid div { min-width: 0; }
.rest-grid dt { font-size: var(--t-micro); color: var(--ink-soft); margin-bottom: 1px; }
.rest-grid dd { margin: 0; font-size: var(--t-mid); font-weight: 300; font-variation-settings: "SOFT" 10, "opsz" 40; }
.rest-grid dd small { font-size: 11px; color: var(--ink-soft); font-family: var(--sans); margin-left: 2px; }

/* ---- the dock ---- */

.dock {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  padding: 18px 20px calc(16px + env(safe-area-inset-bottom));
  background: var(--ground);
  border-top: 1px solid var(--rule);
}
.dock-inner { max-width: var(--page); margin: 0 auto; }

.say {
  margin: 0 0 10px; padding: 0 4px;
  font-size: var(--t-small); line-height: 1.45; color: var(--ink-soft);
  animation: rise .22s ease-out;
}
.say.trouble { color: var(--over); }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }

.transcript { margin: 0 0 10px; }
.transcript summary {
  list-style: none; cursor: pointer; padding: 0 4px;
  font-size: var(--t-micro); color: var(--ink-soft);
}
.transcript summary::-webkit-details-marker { display: none; }
.log {
  display: flex; flex-direction: column; gap: 7px;
  max-height: 34vh; overflow-y: auto;
  padding: 10px 4px 2px;
}
.line { font-size: var(--t-small); line-height: 1.45; }
.line b { font-weight: 500; color: var(--ink); }
.line.them { color: var(--ink-soft); }

.composer {
  display: flex; align-items: center; gap: 8px;
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 5px 5px 5px 6px;
}
.composer:focus-within { border-color: var(--ink-soft); }
.composer input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 16px; padding: 9px 4px; outline: none;
}
.composer input::placeholder { color: var(--ink-soft); }

.mic {
  flex: none; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: transparent; color: var(--ink-soft); cursor: pointer;
  transition: background .15s, color .15s;
}
.mic:hover { background: var(--ground); color: var(--ink); }
.mic.live { background: var(--over); color: var(--raised); }
.mic.live::after {
  content: ""; position: absolute; width: 38px; height: 38px; border-radius: 50%;
  border: 1.5px solid var(--over); animation: ripple 1.5s ease-out infinite;
}
@keyframes ripple { to { transform: scale(1.7); opacity: 0; } }
.mic:disabled { opacity: .4; cursor: default; }

.send {
  flex: none; border: 0; cursor: pointer;
  padding: 0 17px; height: 38px; border-radius: 999px;
  background: var(--ink); color: var(--ground);
  font: 500 var(--t-small)/1 var(--sans);
  transition: opacity .15s;
}
.send:disabled { opacity: .4; cursor: default; }

/* ---- the sign-in page ----
   Same pill the app is driven by all day, so the first thing you touch is the
   thing you keep touching. */

body.gate {
  min-height: 100svh;
  display: grid; align-content: center;
  /* Optical centre, and high enough that a phone keyboard does not cover it. */
  padding: 40px 0 calc(min(20vh, 160px) + env(safe-area-inset-bottom));
}
.gate main { max-width: 420px; width: 100%; }
.gate h1 {
  margin: 0;
  font-family: var(--fig); font-weight: 300;
  font-size: clamp(42px, 12vw, 58px); line-height: .95;
  font-variation-settings: "SOFT" 20, "WONK" 1, "opsz" 120;
  letter-spacing: -.025em;
}
.gate .blurb {
  margin: 14px 0 30px;
  font-size: var(--t-body); line-height: 1.45; color: var(--ink-soft);
}
.gate .composer { padding-left: 18px; }
.gate .aside {
  margin: 16px 0 0; padding: 0 4px;
  font-size: var(--t-small); line-height: 1.45; color: var(--ink-soft);
}
.gate .aside.trouble { color: var(--over); }

/* ---- who is signed in ---- */

.account {
  display: flex; align-items: baseline; gap: 10px;
  margin: 30px 0 0; padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: var(--t-small); color: var(--ink-soft);
}
.account span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account button {
  flex: none; border: 0; background: transparent; padding: 0; cursor: pointer;
  color: var(--ink-soft); font: inherit; text-decoration: underline;
  text-underline-offset: 3px; text-decoration-color: var(--rule);
}
.account button:hover { color: var(--ink); }

/* A tablet has room for a longer line but not for a second column. */
@media (min-width: 760px) {
  :root { --page: 720px; }
  main { padding: 0 28px; }
}

/* ---- two columns ----
   The budget, the note and the nutrition grid stay put on the left while the
   diary scrolls past them, and the composer sits under the budget it feeds. */

@media (min-width: 920px) {
  :root { --page: 1100px; }

  main { padding: 0 32px; }

  .daybar { padding: 34px 0 30px; }
  .daybar h1 { font-size: 26px; }

  .layout {
    display: grid;
    grid-template-columns: var(--side) minmax(0, 1fr);
    column-gap: var(--gutter);
    align-items: start;
  }
  .panel { display: block; position: sticky; top: 28px; }
  .diary { grid-column: 2; grid-row: 1; margin-top: 2px; }

  /* Stacked, the two numbers read as the headline of the page. */
  .figures { display: block; }
  .figure + .figure { margin-top: 26px; }
  .num { font-size: 50px; }

  .rails { margin-top: 28px; }
  .rail { height: 15px; }

  .rest { margin-top: 28px; }
  .rest-grid { grid-template-columns: repeat(2, 1fr); gap: 15px 18px; }

  .meal { margin: 30px 0 9px; }
  .entry { grid-template-columns: 62px 1fr 68px 140px 24px; gap: 14px; padding: 10px 0; }
  .what b { font-size: 16px; }
  .seg-kcal { font-size: 16px; }
  .saltbar { height: 8px; }

  .dock { padding: 16px 32px calc(14px + env(safe-area-inset-bottom)); }
  .dock-inner {
    display: grid;
    grid-template-columns: var(--side) minmax(0, 1fr);
    column-gap: var(--gutter);
    grid-template-areas: "script script" "composer say";
    align-items: center;
  }
  .transcript { grid-area: script; }
  .say { grid-area: say; margin: 0; }
  .composer { grid-area: composer; }
  .log { max-height: 26vh; }
}

@media (min-width: 1240px) {
  :root { --side: 370px; --gutter: 72px; }
}

@media (max-width: 400px) {
  /* 50px is what "12:30pm" needs; anything less and the clock runs into the name. */
  .entry { grid-template-columns: 50px 1fr 46px 66px 20px; gap: 7px; }
  .figures { gap: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::after { animation: none !important; transition: none !important; }
}
