:root {
  --bg: #0c0e12;
  --bg-2: #11141a;
  --card: #151922;
  --card-2: #1b2030;
  --line: rgba(255, 255, 255, 0.07);
  --text: #e8eadf;
  --muted: #8b907f;
  --accent: #c8f542;
  --accent-ink: #14180a;
  --warn: #f0b429;
  --bad: #ef6b6b;
  --good: #7dce7a;
  --p: #b9a6ff;
  --f: #e6c15a;
  --c: #7ec8c0;
  --fi: #d08a5a;
  --cal: #c8f542;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tab: calc(64px + var(--safe-b));
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  max-width: 100%;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  max-width: min(430px, 100%);
  width: 100%;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  min-width: 0;
  overflow-x: clip;
}
.main {
  padding: 8px 12px calc(var(--tab) + 20px);
  display: grid;
  gap: 12px;
  min-width: 0;
}

.top {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: calc(12px + env(safe-area-inset-top)) 12px 0;
}
.eyebrow { margin: 0; color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.name { margin: 2px 0 0; font-size: 28px; letter-spacing: -0.03em; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--text); font-weight: 600;
}

.datestrip {
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  margin: 10px 12px 0; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 6px;
}
.date-arrow {
  height: 40px; display: grid; place-items: center; color: var(--text);
  border-radius: 10px;
}
.date-arrow:hover { background: var(--card-2); }
.date-arrow.is-disabled { opacity: 0.25; pointer-events: none; }
.date-now { text-align: center; }
.date-now strong { display: block; font-size: 15px; }
.date-now span { color: var(--muted); font-size: 12px; }

.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 0; width: min(430px, 100%);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(12, 14, 18, 0.92); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 6px 6px var(--safe-b);
  z-index: 20;
}
.tab {
  display: grid; justify-items: center; gap: 3px;
  color: var(--muted); font-size: 10px; font-weight: 500; padding: 8px 0 6px;
}
.tab svg { width: 20px; height: 20px; }
.tab.is-on { color: var(--accent); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
  overflow: hidden;
}
.card-head {
  display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card-head a, .card-head span { font-size: 12px; color: var(--muted); }

.macros { display: grid; gap: 12px; }
.macro-top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px; }
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; color: var(--muted); font-size: 11px; }
.bar { height: 7px; background: #0a0c10; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; }
.bar-cal { background: var(--cal); }
.bar-p { background: var(--p); }
.bar-f { background: var(--f); }
.bar-c { background: var(--c); }
.bar-fi { background: var(--fi); }
.bar i.is-over { background: var(--bad); }
.macro-left { margin: 4px 0 0; font-size: 11px; color: var(--muted); }
.macro-left.warn { color: var(--bad); }
.swatch { font-weight: 600; }
.swatch-cal { color: var(--cal); }
.swatch-p { color: var(--p); }
.swatch-f { color: var(--f); }
.swatch-c { color: var(--c); }
.swatch-fi { color: var(--fi); }

.weight-hero { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 10px; }
.big { font-size: 34px; letter-spacing: -0.04em; font-weight: 650; }
.big small { font-size: 14px; color: var(--muted); font-weight: 500; }
.delta { font-weight: 600; font-size: 14px; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }
.spark { width: 100%; height: 84px; color: var(--accent); display: block; }
.spark-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 6px; }

.empty { color: var(--muted); font-size: 14px; margin: 0; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }

.meals { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.meal {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 8px;
}
.meal img, .meal-ph { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; }
.meal-ph { background: var(--card-2); display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.meal-body { min-width: 0; }
.meal-body strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-body span { display: block; font-size: 11px; }
.meal-actions { display: flex; flex-direction: column; gap: 4px; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 14px; font-weight: 600;
  background: var(--card-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: #3a1c1c; color: #ffd0d0; }
.btn.wide { width: 100%; }
.icon-btn {
  background: transparent; border: 0; color: var(--muted); font-size: 11px; padding: 2px 4px;
}
.icon-btn.danger { color: var(--bad); }

.stack { display: grid; gap: 10px; min-width: 0; }
.row { display: flex; align-items: center; flex-wrap: wrap; min-width: 0; }
.gap { gap: 8px; }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.grid-5,
.macro-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.macro-fields label:first-child,
.grid-5 > :first-child:nth-last-child(5) {
  grid-column: 1 / -1;
}

label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); min-width: 0; }
input, select, textarea {
  background: #0a0c10; border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; outline: none;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  font-size: 16px;
}
input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: rgba(200, 245, 66, 0.45); }

.seg { display: flex; background: #0a0c10; border-radius: 12px; padding: 3px; gap: 3px; }
.seg button, .seg a {
  flex: 1; text-align: center; border: 0; background: transparent; color: var(--muted);
  border-radius: 10px; padding: 8px 6px; font-size: 13px; font-weight: 500;
}
.seg .is-on { background: var(--card-2); color: var(--text); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 10px; font-size: 12px; color: var(--muted);
}
.chip.ok { color: var(--good); }
.chip.go { color: var(--accent); }

.workout-ex { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; min-width: 0; }
.workout-ex h3 { margin: 0 0 8px; font-size: 16px; overflow-wrap: anywhere; }
.set-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) minmax(0, 1fr) 40px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
  min-width: 0;
}
.set-row input { padding: 10px 6px; text-align: center; font-size: 16px; }
.check {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: #0a0c10; color: var(--muted);
}
.check.is-on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gallery a, .gallery figure {
  margin: 0; position: relative; border-radius: 14px; overflow: hidden;
  background: var(--card-2); aspect-ratio: 3/4;
}
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery figcaption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 18px 8px 8px; font-size: 11px;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
}

.chat { display: grid; gap: 10px; }
.bubble {
  max-width: 92%; padding: 11px 13px; border-radius: 16px; font-size: 14px; line-height: 1.45;
  white-space: pre-wrap;
}
.bubble.user { margin-left: auto; background: #243018; border: 1px solid rgba(200,245,66,.18); }
.bubble.ai { background: var(--card-2); border: 1px solid var(--line); }
.pending {
  border: 1px dashed rgba(200,245,66,.35); border-radius: 14px; padding: 12px; background: #171b12;
}
.composer { display: grid; grid-template-columns: 1fr auto; gap: 8px; position: sticky; bottom: calc(var(--tab) + 8px); }

.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px; border-radius: 12px; z-index: 50; box-shadow: var(--shadow);
  font-size: 13px; max-width: min(420px, calc(100% - 24px));
}
.toast.err { border-color: rgba(239,107,107,.4); }
.dialog {
  border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text);
  padding: 18px; width: min(360px, calc(100% - 32px));
}
.dialog::backdrop { background: rgba(0,0,0,.65); }

.auth { padding: 64px 8px 24px; }
.auth h1 { margin: 6px 0 8px; font-size: 36px; letter-spacing: -0.04em; }
.lede { color: var(--muted); margin: 0 0 20px; }
.banner { padding: 10px 12px; border-radius: 12px; background: #2a1d10; }

.drop {
  border: 1px dashed var(--line); border-radius: 16px; padding: 22px; text-align: center;
  background: #0a0c10; color: var(--muted);
}
.preview { width: 100%; max-height: 220px; object-fit: cover; border-radius: 14px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.table td { overflow-wrap: anywhere; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; }
.table td, .table th { padding: 8px 0; border-bottom: 1px solid var(--line); }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.compare img { width: 100%; border-radius: 12px; aspect-ratio: 3/4; object-fit: cover; }

pre, .mono { overflow-wrap: anywhere; word-break: break-word; max-width: 100%; }

@media (min-width: 720px) {
  body { background: radial-gradient(900px 400px at 50% -10%, #1a2210, var(--bg)); }
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); background: var(--bg); }
}
