:root {
  --bg: #f4f6fb;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #d6e8ff 0%, transparent 60%),
             radial-gradient(900px 500px at 110% 0%, #d3f0f8 0%, transparent 55%);
  --card: #ffffff;
  --text: #161b2e;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-2: #0284c7;
  --spartan: #d92638;
  --border: #e4e7ef;
  --error: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  --kcal: #f97316;
  --protein: #16a34a;
  --carbs: #ca8a04;
  --water: #06b6d4;
  --fat: #db2777;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d14;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, #10264d 0%, transparent 60%),
               radial-gradient(900px 500px at 110% 0%, #0a3547 0%, transparent 55%);
    --card: #151824;
    --text: #e7e9f3;
    --muted: #98a2b3;
    --accent: #3b82f6;
    --accent-2: #0284c7;
  --spartan: #d92638;
    --border: #262b3b;
    --error: #f87171;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

/* Explicit dark theme, for when the toggle forces it over a light system setting. */
:root[data-theme="dark"] {
  --bg: #0b0d14;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #10264d 0%, transparent 60%),
             radial-gradient(900px 500px at 110% 0%, #0a3547 0%, transparent 55%);
  --card: #151824;
  --text: #e7e9f3;
  --muted: #98a2b3;
  --accent: #3b82f6;
  --accent-2: #0284c7;
  --spartan: #d92638;
  --border: #262b3b;
  --error: #f87171;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
/* Native controls (date picker, scrollbars, select) follow the chosen theme. */
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg-grad) fixed, var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- App shell ----------
   Phones: the shell fills the screen. It is a column: top bar, scrolling content,
   input bar. Only the chat scrolls, so the input bar never jumps. */
.shell {
  width: 100%;
  max-width: 920px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* Desktop and large tablets: a centered, rounded app window. */
@media (min-width: 900px) and (min-height: 560px) {
  body { padding: 24px; }
  .shell {
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: color-mix(in srgb, var(--card) 72%, transparent);
    -webkit-backdrop-filter: blur(3px); /* light blur: the particles stay visible through the window */
    backdrop-filter: blur(3px);
    box-shadow: var(--shadow);
  }
}
@media (min-width: 1400px) {
  .shell { max-width: 1040px; }
}
/* While loading, the desktop window shrinks to a compact, centered panel. */
@media (min-width: 900px) and (min-height: 560px) {
  body[data-view="loading"] { display: grid; place-items: center; }
  body[data-view="loading"] .shell { height: auto; max-width: 460px; }
  body[data-view="loading"] .center { padding: 48px 0; }
}

/* ---------- Top bar ---------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-text { min-width: 0; }
.logo img { width: 100%; height: 100%; display: block; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35)); }
.logo {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
}
h1 { font-size: 1.25rem; margin: 0; letter-spacing: -0.01em; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }

.center { flex: 1; display: grid; place-items: center; }
.muted { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--error); }

/* ---------- Login ---------- */
.login-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  padding: 24px 16px;
}
.card {
  /* 10% see-through, so the particle network shows faintly behind the content */
  background: color-mix(in srgb, var(--card) 90%, transparent);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.login-card {
  width: 100%;
  max-width: 380px;
  margin: auto; /* centers on both axes, and stays reachable when the keyboard shrinks the screen */
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h2 { margin: 0 0 4px; font-size: 1.2rem; }
.login-card .error { margin: 0; }
.login-card .error:empty { display: none; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.875rem; color: var(--muted); }
.field input { width: 100%; }

/* ---------- Chat ---------- */
.app-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}
.log:empty { justify-content: center; align-items: center; }
.log:empty::before {
  content: "Describe what you ate and I'll estimate the calories and macros.";
  max-width: 360px;
  padding: 28px 24px;
  text-align: center;
  line-height: 1.5;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 16px;
}

.msg {
  align-self: flex-start;
  width: 100%;
  max-width: 620px;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--card) 90%, transparent);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
  animation: rise 0.25s ease-out;
}
.msg.muted { width: auto; }
.msg strong { display: block; font-size: 1.02rem; margin-bottom: 4px; }
.msg.user {
  align-self: flex-end;
  width: auto;
  max-width: min(85%, 520px);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.25);
}
.msg.error { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, transparent); }
.items { color: var(--muted); font-size: 0.875rem; margin-bottom: 12px; line-height: 1.5; }

.macros {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.tile {
  min-width: 0;
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  background: color-mix(in srgb, var(--c) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}
.tile .value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--c);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tile .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 2px;
}

.actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- Buttons and inputs ---------- */
button {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 44px;
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  transition: transform 0.12s ease, box-shadow 0.2s ease, opacity 0.2s, border-color 0.2s;
}
button.primary {
  border: none;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}
button.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(37, 99, 235, 0.35); }
button.ghost { background: transparent; color: var(--muted); padding: 8px 14px; min-height: 40px; flex: none; }
button.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: default; }

input {
  font: inherit;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input[type="date"] { padding: 6px 12px; font-size: 0.85rem; border-radius: 999px; min-height: 40px; }

/* ---------- Input bar ---------- */
.composer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) 60%, transparent);
}
.date-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip { width: auto; min-height: 40px; padding: 6px 14px; font-size: 0.82rem; }
.chip:hover:not(:disabled) { border-color: var(--accent); }
.chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-color: transparent;
}
.input-row { display: flex; gap: 10px; align-items: center; }
.input-row input { flex: 1; min-width: 0; }
.input-row button { flex: none; }

/* ---------- Tabs ---------- */
.tabs {
  flex: none;
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto;
  min-height: 40px;
  padding: 6px 16px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.92rem;
  box-shadow: none;
}
.tab:hover { color: var(--text); }
#account-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.tab[aria-selected="true"] {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.meals-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px;
}
.panel-inner { max-width: 680px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Sections, forms and lists ---------- */
.section { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.section h2 { margin: 0; font-size: 1.05rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .span-all { grid-column: 1 / -1; }
.form-grid p { margin: 0; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.inline-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline-form .field { width: 170px; }
.inline-form .field.grow { flex: 1; min-width: 150px; width: auto; }

.entries { display: flex; flex-direction: column; }
.entry {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.entry:last-child { border-bottom: none; }
.entries > .muted { margin-bottom: 4px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
button.small { min-height: 34px; padding: 4px 12px; font-size: 0.8rem; flex: none; }

/* ---------- Today summary ---------- */
.big-number { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.big-number .unit { font-size: 0.95rem; font-weight: 500; color: var(--muted); }
.stat-line { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 0.9rem; }
.bar-row { display: flex; flex-direction: column; gap: 6px; }
.bar-head { display: flex; justify-content: space-between; gap: 12px; font-size: 0.9rem; }
.bar-value { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--c) 16%, transparent);
}
.bar > span { display: block; height: 100%; width: var(--pct, 0%); background: var(--c); border-radius: 999px; transition: width 0.4s ease; }

/* ---------- Top bar actions, selects, user management ---------- */
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }
button.icon-only { width: 40px; min-width: 40px; padding: 0; display: grid; place-items: center; font-size: 1.05rem; }

select {
  font: inherit;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  width: 100%;
}
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
select:disabled, input:disabled { opacity: 0.55; cursor: not-allowed; }

.section h3 { margin: 8px 0 0; font-size: 0.95rem; }
.profile { margin: 0; }
.entry { flex-wrap: wrap; }
.entry .grow { flex: 1; min-width: 0; }
.row-actions { display: flex; gap: 8px; flex: none; }
.editor { width: 100%; margin-top: 8px; padding-top: 14px; border-top: 1px dashed var(--border); }
.field.check { flex-direction: row; align-items: center; gap: 10px; align-self: end; min-height: 44px; font-size: 0.9rem; }
.field.check input { width: 18px; min-height: 18px; height: 18px; box-shadow: none; accent-color: var(--accent); }
.pill-accent { background: color-mix(in srgb, var(--accent) 22%, transparent); border-color: var(--accent); }
.pill-warn { background: color-mix(in srgb, var(--error) 14%, transparent); border-color: color-mix(in srgb, var(--error) 45%, transparent); }
button.danger:hover:not(:disabled) { color: var(--error); border-color: var(--error); }

/* ---------- Meal photo ---------- */
.icon-btn {
  flex: none;
  width: 44px;
  min-width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
}
.photo-preview { display: flex; align-items: center; gap: 12px; }
.photo-preview img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.photo-preview .muted { flex: 1; min-width: 0; }
.msg.user .thumb {
  display: block;
  width: 100%;
  max-width: 260px;
  max-height: 220px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 8px;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Tablets and phones ---------- */
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .log { padding: 16px; gap: 12px; }
  .composer { padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); }
  .msg { max-width: 100%; }
  .msg.user { max-width: 90%; }
}
@media (max-width: 520px) {
  .topbar p { display: none; }
  .logo { width: 38px; height: 38px; font-size: 20px; }
  .macros { grid-template-columns: repeat(2, 1fr); }
  .tile .value { font-size: 1.05rem; }
  .login-card { padding: 20px; }
  /* Keep Today / Yesterday / date picker on one row to leave more room for the chat. */
  .date-bar { gap: 6px; flex-wrap: nowrap; }
  .date-bar > .muted { display: none; }
  .chip { padding: 6px 12px; flex: none; }
  input[type="date"] { flex: 1 1 0; min-width: 0; padding: 6px 10px; }
}

/* Short screens, such as a phone held sideways. */
@media (max-height: 480px) {
  .topbar { padding: 6px 16px; }
  .topbar p { display: none; }
  .logo { width: 32px; height: 32px; font-size: 17px; }
  .log { padding: 12px 16px; }
  .composer { gap: 6px; padding-top: 8px; }
  .login-view { padding: 12px 16px; }
}
/* Phone held sideways: date controls and the message box share one row. */
@media (max-height: 480px) and (min-width: 600px) {
  .composer { flex-direction: row; align-items: center; gap: 12px; }
  #meal-date, .photo-preview { flex: none; }
  .date-bar { flex: none; }
  .date-bar > .muted { display: none; }
  .input-row { flex: 1; min-width: 0; }
  .panel { padding: 12px 16px; }
}

/* New sections on small screens. */
@media (max-width: 640px) {
  .panel { padding: 16px; }
  .section { padding: 16px; }
}
@media (max-width: 520px) {
  .tab { padding: 6px 10px; font-size: 0.88rem; }
  .grid-3 { gap: 8px; }
  .grid-3 .field { font-size: 0.8rem; }
  .grid-3 input { padding-left: 10px; padding-right: 10px; }
  .inline-form .field { width: 100%; }
  .inline-form button { width: 100%; }
  .big-number { font-size: 1.75rem; }
}

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

/* AI usage */
.usage-grid { display: grid; grid-template-columns: auto repeat(4, 1fr); gap: 8px 16px; align-items: baseline; margin: 0 0 8px; }
.usage-grid .head { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.usage-grid .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.usage-note { margin: 0; }
@media (max-width: 480px) { .usage-grid { gap: 8px 8px; font-size: 0.85rem; } .usage-grid .head { font-size: 0.7rem; letter-spacing: 0; } }

/* ---------- Landing (the signed-out screen) ---------- */
#particles { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; display: none; pointer-events: none; }
body[data-view="login"] #particles, body[data-view="app"] #particles { display: block; }
.shell { position: relative; z-index: 1; }

/* Signed out, the app window disappears and the page itself is the stage. */
body[data-view="login"] .shell {
  max-width: 1120px;
  height: 100%;
  border: none;
  border-radius: 0;
  background: none;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  overflow: visible;
}
body[data-view="login"] .topbar { border-bottom: none; justify-content: flex-end; }
body[data-view="login"] .brand { display: none; }

.landing {
  margin: auto;
  width: 100%;
  max-width: 1000px;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 380px);
  gap: 56px;
  align-items: center;
  padding: 8px 0 24px;
}
.hero { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; }
.hero-mark { width: 104px; height: 104px; filter: drop-shadow(0 10px 28px rgba(217, 38, 56, 0.35)) drop-shadow(0 4px 14px rgba(37, 99, 235, 0.35)); }
.eyebrow { margin: 0; display: flex; align-items: center; gap: 10px; text-transform: uppercase; letter-spacing: 0.18em; font-size: 0.75rem; font-weight: 600; color: var(--accent); }
.eyebrow::before { content: ""; width: 28px; height: 2px; background: var(--spartan); box-shadow: 0 0 10px var(--spartan); }
.hero-title { margin: 0; font-size: clamp(3rem, 8vw, 4.8rem); line-height: 1; letter-spacing: -0.04em; font-weight: 800; }
.hero-title span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-lead { margin: 0; max-width: 36ch; font-size: 1.1rem; line-height: 1.5; color: var(--muted); }
.roadmap { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 0; padding: 0; }
.roadmap li {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) 62%, transparent);
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.roadmap .live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }
.roadmap .soon { border-style: dashed; color: var(--muted); }
.roadmap .soon::after { content: "soon"; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.8; }

.landing .login-card {
  margin: 0;
  max-width: none;
  background: color-mix(in srgb, var(--card) 78%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

@media (max-width: 899px) {
  .landing { grid-template-columns: minmax(0, 420px); justify-content: center; gap: 28px; text-align: center; }
  /* On a phone the sign-in form comes right after the headline; the rest of the pitch sits below it. */
  .hero { display: contents; }
  .hero > * { justify-self: center; }
  .landing .login-card { order: 4; width: 100%; }
  .roadmap { order: 5; }
  .hero-mark { width: 76px; height: 76px; }
  .eyebrow { justify-content: center; }
  .landing { gap: 18px; }
  .roadmap { justify-content: center; }
}
@media (max-height: 700px) and (min-width: 900px) {
  .hero-mark { width: 64px; height: 64px; }
}
@media (prefers-reduced-motion: no-preference) {
  .hero > *, .landing .login-card { animation: rise 0.7s ease-out both; }
  .hero > :nth-child(2) { animation-delay: 0.05s; }
  .hero > :nth-child(3) { animation-delay: 0.1s; }
  .hero > :nth-child(4) { animation-delay: 0.15s; }
  .landing .login-card { animation-delay: 0.25s; }
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- Today: layout toggle and pie charts ---------- */
.today-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 12px; }
.view-toggle { display: inline-flex; margin-left: auto; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 999px; background: color-mix(in srgb, var(--card) 90%, transparent); }
.view-toggle button { min-height: 34px; padding: 4px 16px; border: none; border-radius: 999px; background: transparent; color: var(--muted); box-shadow: none; font-size: 0.85rem; }
.view-toggle button[aria-pressed="true"] { color: var(--text); background: color-mix(in srgb, var(--accent) 18%, transparent); box-shadow: inset 0 -2px 0 var(--accent); }
.pies { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.pie { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; min-width: 0; }
.pie .muted { font-size: 0.78rem; overflow-wrap: anywhere; }
.pie-label { font-weight: 600; font-size: 0.92rem; margin-top: 4px; }
.pie-chart { position: relative; width: 100%; max-width: 120px; aspect-ratio: 1; }
.pie-chart svg { width: 100%; height: 100%; display: block; }
.pie-track { fill: none; stroke: color-mix(in srgb, var(--muted) 22%, transparent); stroke-width: 5; }
.pie-arc { fill: none; stroke: var(--c); stroke-width: 5; stroke-linecap: round; transition: stroke-dasharray 0.5s ease; }
.pie-arc.over { stroke: var(--error); }
.pie-center { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .pies { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 20px; } }

/* =====================================================================
   Material layer (Apple-style glass)
   Principles: translucent layers over a soft colour field, a hairline of light on every edge,
   large soft shadows, generous radii, system typography, segmented controls.
   Blue and Spartan red stay the brand; everything below only changes surfaces and type.
   Note: an element with backdrop-filter becomes the backdrop for its children, so the app window
   blurs the particles once and the cards inside are plain translucent fills.
   ===================================================================== */
:root {
  --bg: #eef2f9;
  --bg-grad: radial-gradient(900px 600px at 8% -8%, rgba(59, 130, 246, 0.30), transparent 60%),
             radial-gradient(800px 560px at 108% 4%, rgba(34, 211, 238, 0.26), transparent 58%),
             radial-gradient(700px 520px at 70% 112%, rgba(217, 38, 56, 0.10), transparent 60%);
  --win: rgba(255, 255, 255, 0.58);
  --win-edge: rgba(255, 255, 255, 0.85);
  --fill: rgba(255, 255, 255, 0.62);
  --fill-edge: rgba(255, 255, 255, 0.9);
  --field: rgba(255, 255, 255, 0.72);
  --seg: rgba(60, 70, 100, 0.10);
  --seg-on: rgba(255, 255, 255, 0.95);
  --stroke: rgba(16, 24, 40, 0.08);
  --lift: 0 1px 1px rgba(16, 24, 40, 0.04), 0 10px 28px -10px rgba(16, 24, 40, 0.16);
  --window-shadow: 0 2px 4px rgba(16, 24, 40, 0.04), 0 30px 70px -20px rgba(30, 58, 138, 0.28);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07090f;
    --bg-grad: radial-gradient(900px 600px at 8% -8%, rgba(37, 99, 235, 0.40), transparent 60%),
               radial-gradient(800px 560px at 108% 4%, rgba(6, 182, 212, 0.22), transparent 58%),
               radial-gradient(700px 520px at 15% 112%, rgba(217, 38, 56, 0.18), transparent 60%);
    --win: rgba(18, 22, 34, 0.58);
    --win-edge: rgba(255, 255, 255, 0.09);
    --fill: rgba(255, 255, 255, 0.055);
    --fill-edge: rgba(255, 255, 255, 0.10);
    --field: rgba(255, 255, 255, 0.06);
    --seg: rgba(118, 118, 128, 0.24);
    --seg-on: rgba(255, 255, 255, 0.16);
    --stroke: rgba(255, 255, 255, 0.08);
    --lift: 0 10px 30px -12px rgba(0, 0, 0, 0.55);
    --window-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 30px 80px -20px rgba(0, 0, 0, 0.7);
  }
}
:root[data-theme="dark"] {
  --bg: #07090f;
  --bg-grad: radial-gradient(900px 600px at 8% -8%, rgba(37, 99, 235, 0.40), transparent 60%),
             radial-gradient(800px 560px at 108% 4%, rgba(6, 182, 212, 0.22), transparent 58%),
             radial-gradient(700px 520px at 15% 112%, rgba(217, 38, 56, 0.18), transparent 60%);
  --win: rgba(18, 22, 34, 0.58);
  --win-edge: rgba(255, 255, 255, 0.09);
  --fill: rgba(255, 255, 255, 0.055);
  --fill-edge: rgba(255, 255, 255, 0.10);
  --field: rgba(255, 255, 255, 0.06);
  --seg: rgba(118, 118, 128, 0.24);
  --seg-on: rgba(255, 255, 255, 0.16);
  --stroke: rgba(255, 255, 255, 0.08);
  --lift: 0 10px 30px -12px rgba(0, 0, 0, 0.55);
  --window-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 30px 80px -20px rgba(0, 0, 0, 0.7);
}

/* Typography: the system font, which is SF Pro on Apple devices. */
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  letter-spacing: -0.006em;
}
h1, h2, h3, .hero-title, .big-number { letter-spacing: -0.02em; }
.section h2 { font-size: 1.12rem; font-weight: 650; }

/* The app window. */
@media (min-width: 900px) and (min-height: 560px) {
  .shell {
    border: 1px solid var(--win-edge);
    border-radius: 30px;
    background: var(--win);
    -webkit-backdrop-filter: blur(14px) saturate(170%);
    backdrop-filter: blur(14px) saturate(170%);
    box-shadow: inset 0 1px 0 var(--win-edge), var(--window-shadow);
  }
}
.topbar { border-bottom-color: var(--stroke); }
.tabs { border-bottom: none; padding: 4px 16px 10px; }

/* Segmented controls: the tabs and the Detailed / Compact switch. */
.tabs {
  gap: 2px;
  margin: 2px 16px 8px;
  padding: 3px;
  border-radius: 14px;
  background: var(--seg);
}
.tab { border-radius: 11px; min-height: 36px; font-weight: 600; transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease; }
.tab[aria-selected="true"] {
  background: var(--seg-on);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14), 0 3px 8px rgba(0, 0, 0, 0.08);
}
.view-toggle { padding: 3px; border: none; background: var(--seg); }
.view-toggle button { border-radius: 999px; transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease; }
.view-toggle button[aria-pressed="true"] {
  background: var(--seg-on);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14), 0 3px 8px rgba(0, 0, 0, 0.08);
}

/* Cards: translucent fill with a hairline of light on top. */
.card, .msg {
  background: var(--fill);
  border: 1px solid var(--fill-edge);
  border-radius: 22px;
  box-shadow: inset 0 1px 0 var(--fill-edge), var(--lift);
}
.msg { border-bottom-left-radius: 8px; }
.msg.user { border: none; border-bottom-right-radius: 8px; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 8px 20px -8px rgba(37, 99, 235, 0.5); }
.section { padding: 20px; gap: 14px; }
.entry { border-bottom-color: var(--stroke); }

/* Phones have no window behind the cards, so each card blurs the background itself. */
@media not all and (min-width: 900px) and (min-height: 560px) {
  .card, .msg:not(.user) {
    -webkit-backdrop-filter: blur(18px) saturate(170%);
    backdrop-filter: blur(18px) saturate(170%);
  }
}

/* Controls. */
button { background: var(--fill); border-color: var(--stroke); box-shadow: inset 0 1px 0 var(--fill-edge); }
button.ghost { background: transparent; border-color: var(--stroke); box-shadow: none; }
button.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff) 0%, var(--accent) 45%, var(--accent-2) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 8px 18px -6px rgba(37, 99, 235, 0.55);
}
.chip.active {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff) 0%, var(--accent) 45%, var(--accent-2) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 6px 14px -6px rgba(37, 99, 235, 0.55);
}
input, select { background: var(--field); border-color: var(--stroke); border-radius: 14px; }
input[type="date"] { border-radius: 999px; }
.composer { background: var(--fill); border-top-color: var(--stroke); }

/* Today: bigger numbers, softer bars and rings. */
.big-number { font-size: 2.5rem; font-weight: 700; letter-spacing: -0.035em; }
.big-number .unit { font-size: 1rem; letter-spacing: 0; }
.bar { height: 9px; background: color-mix(in srgb, var(--c) 18%, transparent); }
.bar > span { background: linear-gradient(90deg, color-mix(in srgb, var(--c) 78%, #fff), var(--c)); }
.pies { gap: 18px; }
.pie-chart { max-width: 128px; }
.pie-track { stroke: color-mix(in srgb, var(--muted) 20%, transparent); stroke-width: 4.2; }
.pie-arc { stroke-width: 4.2; filter: drop-shadow(0 0 2.5px color-mix(in srgb, var(--c) 55%, transparent)); }
.pie-center { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.03em; }
.pie-label { font-weight: 650; }

/* Landing: the sign-in card is the glass hero, the pitch floats on the colour field. */
.hero-mark { border-radius: 0; box-shadow: none; }
.hero-title { font-size: clamp(3.4rem, 9vw, 5.8rem); font-weight: 800; letter-spacing: -0.05em; }
.hero-lead { font-size: 1.15rem; line-height: 1.5; max-width: 34ch; }
.roadmap li {
  background: var(--fill);
  border: 1px solid var(--fill-edge);
  box-shadow: inset 0 1px 0 var(--fill-edge);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  backdrop-filter: blur(12px) saturate(160%);
}
.roadmap .soon { border-style: solid; }
.landing .login-card {
  padding: 30px 28px;
  gap: 16px;
  background: var(--win);
  border: 1px solid var(--win-edge);
  border-radius: 32px;
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
  box-shadow: inset 0 1px 0 var(--win-edge), var(--window-shadow);
}
.landing .login-card h2 { font-size: 1.35rem; font-weight: 700; }
.landing .login-card input { min-height: 48px; border-radius: 14px; }
.landing .login-card button.primary { min-height: 50px; font-size: 1rem; }

.tile { border-radius: 16px; }

/* ---------- Shared bits: card headers, key/value rows, stat tiles ---------- */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h2 { margin: 0; }
.stack-sm { display: flex; flex-direction: column; gap: 14px; }
.kv { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--stroke); }
.kv strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 12px 14px; border-radius: 16px; background: var(--field); border: 1px solid var(--stroke); }
.stat .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat .value { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--c, var(--text)); }
.stat .sub-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; min-height: 1.1em; }
.stat .sub { font-size: 0.78rem; color: var(--muted); }
.weight-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 14px; }
.delta { font-size: 0.8rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.delta.good { color: var(--protein); }
.delta.warn { color: var(--kcal); }

/* Weight trend chart */
.trend svg { display: block; overflow: visible; }
.trend-line { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.trend-area { fill: url(#trend-fill); }
.trend-stop-top { stop-color: var(--accent); stop-opacity: 0.28; }
.trend-stop-bottom { stop-color: var(--accent); stop-opacity: 0; }
.trend-dot { fill: var(--accent); }
.trend-last { fill: var(--bg); stroke: var(--accent); stroke-width: 2.5; }
.trend-axis { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: 0.78rem; }

/* Phones: the Detailed / Compact switch fills the row like an iOS segmented control. */
@media (max-width: 560px) {
  .today-toolbar .view-toggle { width: 100%; margin-left: 0; }
  .today-toolbar .view-toggle button { flex: 1; }
}
#goals-status:empty { display: none; }
#goals-status { margin: 0; }

/* ---------- Neon borders: each tile is outlined in the colour of its metric (Body and Goals) ---------- */
.stat {
  background: var(--field);
  border: 1.5px solid color-mix(in srgb, var(--c, var(--stroke)) 85%, transparent);
  box-shadow: 0 0 14px -4px color-mix(in srgb, var(--c, transparent) 65%, transparent);
}
.stat .value { color: var(--text); text-shadow: none; }

/* Phones: the date row on Today spans the full width, like the switch under it. */
@media (max-width: 560px) {
  .today-toolbar #today-date { flex: 1 1 100%; }
  .today-toolbar .date-bar { width: 100%; }
  .today-toolbar .chip { flex: 1 1 0; }
  .today-toolbar input[type="date"] { flex: 1.5 1 0; }
}

/* ---------- Logo: night and day versions, following the active theme ---------- */
img.logo-light { display: none; }
:root[data-theme="light"] img.logo-dark { display: none; }
:root[data-theme="light"] img.logo-light { display: block; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) img.logo-dark { display: none; }
  :root:not([data-theme="dark"]) img.logo-light { display: block; }
}
.hero-logo { line-height: 0; }

/* ---------- Confirmation dialog ---------- */
dialog.confirm-dialog {
  width: min(92vw, 380px);
  padding: 22px;
  border: 1px solid var(--fill-edge);
  border-radius: 22px;
  background: var(--fill);
  color: var(--text);
  box-shadow: inset 0 1px 0 var(--fill-edge), 0 30px 70px -20px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
}
dialog.confirm-dialog::backdrop { background: rgba(8, 12, 22, 0.45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
dialog.confirm-dialog[open] { animation: confirm-in 0.16s ease-out; }
dialog.confirm-dialog h2 { margin: 0 0 6px; font-size: 1.1rem; }
dialog.confirm-dialog p { margin: 0 0 4px; line-height: 1.45; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.confirm-actions button { min-width: 92px; }
button.primary.danger-solid {
  background: linear-gradient(180deg, color-mix(in srgb, var(--error) 85%, #fff) 0%, var(--error) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 8px 18px -6px color-mix(in srgb, var(--error) 60%, transparent);
}
@keyframes confirm-in { from { opacity: 0; transform: scale(0.96) translateY(6px); } }
@media (prefers-reduced-motion: reduce) { dialog.confirm-dialog[open] { animation: none; } }
