* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  color: var(--ink);
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input { font-family: inherit; }
.hidden { display: none !important; }

/* ---- layout ---- */
/* App shell pinned to all four viewport edges. bottom:0 = the viewport's bottom
   edge, which (with viewport-fit=cover) is the physical screen bottom — so it
   can't gap below AND can't overshoot past it. The nav's safe-area bottom
   padding keeps its labels clear of the home indicator. Only <main> scrolls. */
.shell {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  max-width: var(--maxw); margin: 0 auto;
  display: flex; flex-direction: column;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
header.bar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); padding: calc(var(--sp-4) + env(safe-area-inset-top)) var(--sp-5) var(--sp-3);
  background: linear-gradient(180deg, rgba(20,17,13,0.92), rgba(20,17,13,0.6));
  backdrop-filter: blur(12px);
}
header .title { display: flex; align-items: baseline; gap: var(--sp-2); }
header .title b { font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; letter-spacing: -0.5px; }
header .title b .dot { color: var(--accent); }
header .sub { font-family: var(--font-mono); font-size: 0.7rem; color: var(--ink-mute); letter-spacing: 0.04em; }
.datenav { display: flex; align-items: center; gap: var(--sp-2); }
.datenav button { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); color: var(--ink-soft); font-size: 1rem; display: grid; place-items: center; }
.datenav button:disabled { opacity: 0.3; }
.datenav .today-label { font-size: 0.8rem; color: var(--ink-soft); min-width: 74px; text-align: center; }

main { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: var(--sp-3) var(--sp-4) var(--sp-6); }
.view { display: flex; flex-direction: column; gap: var(--sp-4); }

/* ---- cards ---- */
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--sp-4);
}
.eyebrow { font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-mute); margin-bottom: var(--sp-3); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-2); }

/* ---- habit rows ---- */
.habit { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid var(--line); }
.habit:first-of-type { border-top: none; }
.habit .ico { font-size: 1.5rem; width: 30px; text-align: center; flex: none; filter: saturate(1.1); }
.habit .body { flex: 1 1 130px; min-width: 0; }
.habit .nm { font-size: 1rem; font-weight: 500; }
.habit .meta { font-size: 0.72rem; color: var(--ink-mute); margin-top: 2px; display: flex; align-items: center; gap: var(--sp-2); white-space: nowrap; }
.habit > .toggle { margin-left: auto; }
/* steppers & number presets get their own full-width row so the meta text
   (e.g. "0 of last 7 · goal 8 glass") never collides with the controls */
.habit > .stepper, .habit > .numset { flex: 1 0 100%; margin-top: 2px; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line-2); }
.dots i.on { background: var(--accent); }

/* binary toggle */
.toggle { width: 46px; height: 46px; border-radius: 14px; border: 1.5px solid var(--line-2); flex: none; display: grid; place-items: center; font-size: 1.3rem; color: transparent; transition: all .2s var(--ease); }
.toggle.on { background: radial-gradient(circle at 32% 28%, var(--glow), var(--accent) 75%); border-color: transparent; color: var(--bg); box-shadow: 0 8px 22px -10px var(--accent); }
.toggle:active { transform: scale(0.92); }

/* stepper (count) */
.stepper { display: flex; align-items: center; justify-content: center; gap: var(--sp-3); flex: none; }
.stepper button { width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line-2); font-size: 1.3rem; color: var(--ink-soft); display: grid; place-items: center; }
.stepper button:active { transform: scale(0.92); }
.stepper .val { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; font-size: 1.05rem; font-weight: 600; }
.stepper .val small { display: block; font-size: 0.62rem; color: var(--ink-mute); font-weight: 400; }

/* number quick-set */
.numset { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; justify-content: center; }
.chip { font-family: var(--font-mono); font-size: 0.78rem; padding: 7px 11px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--ink-soft); }
.chip.on { background: var(--accent); color: var(--bg); border-color: transparent; font-weight: 600; }
.chip:active { transform: scale(0.94); }

.habit.done .nm { color: var(--ink-soft); }
.muted-row { opacity: 0.6; }

/* ---- macro rings ---- */
.rings { display: flex; gap: var(--sp-5); align-items: center; justify-content: center; flex-wrap: wrap; }
.ring { --p: 0; width: 104px; height: 104px; border-radius: 50%; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; line-height: 1.05;
  position: relative; flex: none;
  background: radial-gradient(closest-side, var(--panel) 80%, transparent 81% 100%),
              conic-gradient(var(--rc, var(--accent)) calc(var(--p) * 1%), var(--line-2) 0); }
.ring .rv { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.ring .rl { font-size: 0.56rem; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.1em; }
.ring .rt { font-size: 0.6rem; color: var(--ink-faint); white-space: nowrap; }

/* ---- meals ---- */
.meal { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) 0; border-top: 1px solid var(--line); }
.meal:first-of-type { border-top: none; }
.meal .body { flex: 1; min-width: 0; }
.meal .nm { font-size: 0.92rem; }
.meal .mac { font-family: var(--font-mono); font-size: 0.68rem; color: var(--ink-mute); }
.meal .del { color: var(--ink-faint); font-size: 1.1rem; padding: 4px 8px; }
.recipe-chips { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-3); }
.rchip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line-2); font-size: 0.82rem; color: var(--ink-soft); }
.rchip:active { transform: scale(0.95); }
.rchip b { color: var(--accent); font-family: var(--font-mono); font-size: 0.72rem; }

/* ---- buttons ---- */
.btn { font-weight: 500; color: var(--bg); background: radial-gradient(circle at 32% 28%, var(--glow), var(--accent) 72%);
  border-radius: var(--radius-sm); padding: var(--sp-3) var(--sp-5); box-shadow: 0 10px 30px -12px var(--accent); transition: transform .2s var(--ease), filter .2s; }
.btn:active { transform: translateY(1px); filter: brightness(1.05); }
.btn.block { width: 100%; }
.btn-ghost { color: var(--ink); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: var(--sp-3) var(--sp-5); }
.btn-ghost:active { border-color: var(--accent); }
.btn.add-food { width: 100%; margin-top: var(--sp-3); }

/* ---- bottom tab bar ---- */
nav.tabs {
  flex: none;
  display: flex; justify-content: space-around;
  padding: var(--sp-2) var(--sp-4) calc(var(--sp-2) + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
nav.tabs button { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 0.62rem; color: var(--ink-faint); padding: 6px 16px; letter-spacing: 0.04em; }
nav.tabs button .ti { font-size: 1.25rem; }
nav.tabs button.on { color: var(--accent); }

/* ---- bottom sheet / modal ---- */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0.55); backdrop-filter: blur(2px); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: var(--maxw); max-height: 90vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--panel), var(--panel-2)); border: 1px solid var(--line);
  border-radius: 24px 24px 0 0; padding: var(--sp-5) var(--sp-4) calc(var(--sp-6) + env(safe-area-inset-bottom));
  box-shadow: var(--shadow); animation: rise .26s var(--ease); }
@keyframes rise { from { transform: translateY(30px); opacity: .4; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 99px; background: var(--line-2); margin: -8px auto var(--sp-4); }
.sheet h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; margin-bottom: var(--sp-3); }
.segmented { display: flex; gap: 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: var(--sp-4); }
.segmented button { flex: 1; padding: 9px; border-radius: 9px; font-size: 0.82rem; color: var(--ink-mute); }
.segmented button.on { background: var(--panel-2); color: var(--ink); box-shadow: 0 1px 0 var(--line-2); }

/* ---- forms ---- */
label.field { display: block; margin-bottom: var(--sp-3); }
label.field span { display: block; font-size: 0.72rem; color: var(--ink-mute); margin-bottom: 5px; letter-spacing: 0.03em; }
input.in, select.in, textarea.in {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 11px;
  padding: 12px 13px; color: var(--ink); font-size: 1rem; outline: none; transition: border-color .15s;
}
input.in:focus, select.in:focus, textarea.in:focus { border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--sp-2); }

/* nutrition result preview */
.nutri { border: 1px solid var(--line-2); border-radius: 14px; padding: var(--sp-3); margin: var(--sp-3) 0; background: var(--bg-2); }
.nutri .nn { font-weight: 600; margin-bottom: 2px; }
.nutri .macros { display: flex; gap: var(--sp-4); margin-top: var(--sp-2); font-family: var(--font-mono); font-size: 0.8rem; }
.nutri .macros b { display: block; color: var(--ink); font-size: 1rem; }
.nutri .macros span { color: var(--ink-mute); font-size: 0.62rem; text-transform: uppercase; }
.conf { font-size: 0.62rem; padding: 2px 7px; border-radius: 99px; border: 1px solid var(--line-2); color: var(--ink-mute); }

/* settings list */
.mlist .mrow { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid var(--line); }
.mlist .mrow:first-child { border-top: none; }
.mlist .mrow .ico { font-size: 1.25rem; width: 28px; text-align: center; }
.mlist .mrow .body { flex: 1; }
.mlist .mrow .nm { font-size: 0.95rem; }
.mlist .mrow .meta { font-size: 0.68rem; color: var(--ink-mute); font-family: var(--font-mono); }
.switch { width: 44px; height: 26px; border-radius: 99px; background: var(--line-2); position: relative; transition: background .2s; flex: none; }
.switch.on { background: var(--accent); }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); transition: transform .2s var(--ease); }
.switch.on::after { transform: translateX(18px); background: var(--bg); }
.linkbtn { color: var(--accent); font-size: 0.84rem; }
.danger { color: var(--danger); }

/* login */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: var(--sp-4); padding: var(--sp-6); max-width: 420px; margin: 0 auto; }
.auth .logo { font-family: var(--font-display); font-size: 2.4rem; font-weight: 600; letter-spacing: -1px; }
.auth .logo .dot { color: var(--accent); }
.auth .tag { color: var(--ink-mute); text-align: center; margin-top: -10px; }
.auth form { width: 100%; }

/* toast */
#toast { position: fixed; bottom: calc(96px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 16px; font-size: 0.85rem;
  box-shadow: var(--shadow); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: 90%; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--danger); color: #ffd9d2; }

.empty { color: var(--ink-mute); font-size: 0.86rem; text-align: center; padding: var(--sp-4); }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }

/* Tighten the header on phones so the title + date nav never collide. */
@media (max-width: 480px) {
  header.bar { padding: calc(var(--sp-4) + env(safe-area-inset-top)) var(--sp-4) var(--sp-3); }
  header .title .sub { display: none; }
  header .title b { font-size: 1.25rem; }
}

/* ---- Tablet / iPad / computer: widen out and flow cards into columns,
   instead of a narrow phone-width column floating in the middle. The card
   count + width decide the columns (1 → 2 → 3) so it fits the device. ---- */
@media (min-width: 760px) {
  .shell { max-width: 960px; }
  main { padding: var(--sp-5) var(--sp-5) var(--sp-6); }
  .view { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--sp-5); align-items: start; }
}
@media (min-width: 1200px) {
  .shell { max-width: 1140px; }
}
