:root {
  /* HungerHush "Dusk" palette (see the brand guide) */
  --bg: #1E1830;           /* Night */
  --surface: #2A2242;      /* Plum */
  --surface-2: #352B52;
  --ink: #F3EEFF;          /* Moon */
  --ink-2: #D6CCEE;
  --ink-3: #A79CC6;
  --line: #3A3058;
  --accent: #C7B3FF;       /* Lilac */
  --accent-ink: #1E1830;
  --accent-soft: #3D3266;
  --warm: #F6B89A;         /* Peach */
  --warm-soft: #4A3448;
  --amber: #E8CB86;
  --water: #9FD3E6;        /* water only */
  --user-bubble: #C7B3FF;
  --user-ink: #1E1830;
  --bot-bubble: #2A2242;
  --radius: 18px;
  --tabbar-h: 64px;
  --font: "Figtree", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -0.02em; margin: 0; }

/* ---------- Sign in ---------- */
.signin { min-height: 100%; display: grid; place-items: center; padding: 32px 24px; }
.signin-inner { max-width: 360px; text-align: center; }
.signin h1 { font-size: 2.2rem; margin: 16px 0 8px; }
.lede { color: var(--ink-2); margin: 0 0 28px; }
.fine { color: var(--ink-3); font-size: 0.85rem; margin-top: 16px; }
.error { color: var(--warm); font-size: 0.9rem; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 12px 20px; font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; width: 100%; }
.btn.small { padding: 8px 14px; font-size: 0.9rem; }
.btn.danger { color: var(--warm); }

/* ---------- App shell ---------- */
.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.topbar {
  padding: calc(env(safe-area-inset-top) + 10px) 20px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.35rem; }

.view { min-height: 0; }
.scroll { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.stack { padding: 16px 16px 32px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; max-width: 640px; margin: 0 auto; }
.panel, .panel * { min-width: 0; }
.panel { overflow-wrap: break-word; }

.tabbar {
  display: grid; grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  border: 0; background: none; padding: 8px 0 6px;
  display: grid; justify-items: center; gap: 2px;
  color: var(--ink-3); font-size: 0.72rem; font-weight: 500;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--accent); }

/* ---------- Chat ---------- */
.chat-view { display: grid; grid-template-rows: 1fr auto; min-height: 0; }
.thread {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.day-sep {
  align-self: center; color: var(--ink-3); font-size: 0.75rem; font-weight: 500;
  margin: 12px 0 4px; text-transform: uppercase; letter-spacing: 0.06em;
}
.msg { max-width: 84%; display: grid; gap: 6px; }
.msg.user { align-self: flex-end; justify-items: end; }
.msg.assistant { align-self: flex-start; }
.bubble {
  padding: 10px 14px; border-radius: var(--radius);
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .bubble { background: var(--user-bubble); color: var(--user-ink); border-bottom-right-radius: 5px; }
.msg.assistant .bubble { background: var(--bot-bubble); border-bottom-left-radius: 5px; }
.msg .time { font-size: 0.7rem; color: var(--ink-3); padding: 0 6px; }
.bubble strong { font-weight: 600; }

.cards { display: grid; gap: 6px; }
.card {
  background: var(--surface-2); border-radius: 14px; padding: 9px 12px;
  font-size: 0.86rem; display: grid; gap: 3px; border-left: 3px solid var(--accent);
}
.card.workout { border-left-color: var(--amber); }
.card.hunger { border-left-color: var(--warm); }
.card.weight { border-left-color: var(--ink-3); }
.card.deleted { opacity: 0.6; text-decoration: line-through; }
.card .k { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 600; }
.card .title { font-weight: 600; }
.card .nums { color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.tag { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 0.72rem; font-weight: 600; }
.tag.whole { background: var(--accent-soft); color: var(--accent); }
.tag.processed, .tag.mixed { background: var(--surface); color: var(--ink-2); }
.tag.ultraprocessed { background: var(--warm-soft); color: var(--warm); }
.blur { filter: blur(6px); cursor: pointer; user-select: none; transition: filter .2s; }
.blur.revealed { filter: none; }

.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

.welcome { text-align: center; color: var(--ink-2); margin: auto; padding: 24px; max-width: 340px; }
.welcome h2 { font-size: 1.5rem; color: var(--ink); margin-bottom: 8px; }
.welcome .btn { margin-top: 18px; }

.composer-wrap { border-top: 1px solid var(--line); background: var(--bg); padding: 8px 10px 10px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 0 2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; font-size: 0.82rem; color: var(--ink-2);
}
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; font-size: 16px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: 22px; padding: 11px 16px; font: inherit;
  max-height: 140px; outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.send:disabled { opacity: .45; }

/* ---------- Panels (Today / Trends / Settings) ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 16px;
}
.panel h2 { font-size: 1.1rem; margin-bottom: 10px; }
.panel .sub { color: var(--ink-3); font-size: 0.85rem; margin: -6px 0 12px; }
.muted { color: var(--ink-3); }

.meter { display: grid; gap: 4px; margin-bottom: 12px; }
.meter .row { display: flex; justify-content: space-between; font-size: 0.9rem; }
.meter .row b { font-weight: 600; }
.meter .bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter .fill { height: 100%; border-radius: 999px; background: var(--accent); }
.meter.fiber .fill { background: var(--amber); }
.meter.fat .fill { background: #E7A6C9; }
.meter.cal .fill { background: var(--ink-3); }

.mix { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.mix span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.8rem; color: var(--ink-2); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: 0; }

.gap-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.gap-list li { background: var(--warm-soft); color: var(--ink); border-radius: 12px; padding: 9px 12px; font-size: 0.9rem; }
.gap-list li.ok { background: var(--accent-soft); }

.log-list { margin: 0; padding: 0; list-style: none; display: grid; }
.log-list li { display: grid; grid-template-columns: 66px 1fr auto; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 0.92rem; align-items: baseline; }
.log-list li:first-child { border-top: 0; }
.log-list .t { color: var(--ink-3); font-size: 0.8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.log-list .n { color: var(--ink-2); font-size: 0.8rem; text-align: right; white-space: nowrap; }

.chart svg { width: 100%; height: auto; display: block; }
.chart text { font: 10px var(--font); fill: var(--ink-3); }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 10px 12px; }
.stat .v { font-family: var(--display); font-size: 1.4rem; font-weight: 600; }
.stat .l { font-size: 0.75rem; color: var(--ink-3); }

/* Settings form */
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 0.82rem; color: var(--ink-2); font-weight: 500; }
.field textarea { resize: vertical; line-height: 1.4; }
.field input[type=text], .field input[type=number], .field textarea {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 12px; padding: 10px 12px; font: inherit;
  width: 100%; min-width: 0; font-size: 16px; /* 16px stops iOS zooming in */
}
.field .hint { font-size: 0.75rem; color: var(--ink-3); }
.toggle { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.toggle:first-of-type { border-top: 0; }
.toggle input { width: 44px; height: 26px; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.pick button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 5px 11px; font-size: 0.82rem; color: var(--ink-2); }
.pick button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.saved-note { color: var(--accent); font-size: 0.85rem; }

/* ---------- Photos ---------- */
.photo-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  color: var(--ink-2); border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.photo-preview {
  display: flex; align-items: center; gap: 10px; padding: 0 2px 8px; font-size: 0.82rem;
}
.photo-preview img { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; }
.photo-preview .muted { flex: 1; }
.photo-remove { border: 0; background: var(--surface-2); width: 30px; height: 30px; border-radius: 50%; font-size: 1.1rem; }
.bubble .thumb { display: block; width: 180px; max-width: 100%; border-radius: 12px; margin: -2px -4px 6px; }

/* ---------- Meal card details ---------- */
.card details { margin-top: 4px; }
.card summary { cursor: pointer; color: var(--accent); font-size: 0.78rem; font-weight: 600; list-style: none; }
.card summary::-webkit-details-marker { display: none; }
.card .items { margin: 6px 0 0; padding: 0; list-style: none; display: grid; gap: 3px; }
.card .items li { display: flex; justify-content: space-between; gap: 10px; color: var(--ink-2); font-size: 0.8rem; }
.card .items li span:last-child { white-space: nowrap; }
.card .assume { margin-top: 6px; font-size: 0.78rem; color: var(--ink-3); font-style: italic; }
.card .share { font-size: 0.75rem; color: var(--accent); font-weight: 600; }
.card.pantry { border-left-color: var(--amber); }

/* ---------- Today: processing filter ---------- */
.mix span, .legend button { cursor: pointer; }
.mix span.dim { opacity: 0.3; }
.legend button { border: 0; background: none; padding: 2px 0; color: inherit; font: inherit; }
.legend button.on { font-weight: 700; color: var(--ink); }
.mix-hint { font-size: 0.75rem; color: var(--ink-3); margin-top: 6px; }
.log-list li.hl { background: var(--warm-soft); border-radius: 10px; margin: 0 -8px; padding: 9px 8px; }
.log-list li.hl.whole { background: var(--accent-soft); }
.log-list li.dim { opacity: 0.4; }
.log-list .tag { margin-left: 6px; }

/* ---------- Charts: tap readout ---------- */
.readout { min-height: 1.3em; font-size: 0.85rem; color: var(--ink-2); margin: -4px 0 6px; }
.readout b { color: var(--ink); }
.chart rect.hit { fill: transparent; cursor: pointer; }
.chart rect.bar.sel { opacity: 0.6; }

/* ---------- Hunger heat map ---------- */
.heat { display: grid; grid-template-columns: 34px repeat(9, minmax(0, 1fr)); gap: 3px; font-size: 0.68rem; color: var(--ink-3); }
.heat .h { text-align: center; }
.heat .d { align-self: center; }
.heat .c { aspect-ratio: 1; border-radius: 5px; background: var(--surface-2); border: 0; padding: 0; cursor: pointer; }
.heat .c.sel { outline: 2px solid var(--ink); outline-offset: 1px; }
.heat-key { display: flex; align-items: center; gap: 6px; font-size: 0.72rem; color: var(--ink-3); margin-top: 8px; }
.heat-key i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.insight-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.insight-list li { display: grid; gap: 2px; font-size: 0.9rem; }
.insight-list .sub2 { color: var(--ink-3); font-size: 0.78rem; }
.full-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 44px; gap: 8px; align-items: center; font-size: 0.86rem; padding: 4px 0; }
.full-row .bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.full-row .fill { height: 100%; background: var(--accent); border-radius: 999px; }
.full-row.short .fill { background: var(--warm); }
.full-row .hrs { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.full-head { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 600; margin: 10px 0 2px; }

/* ---------- Household ---------- */
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.6rem; letter-spacing: 0.2em; font-weight: 700; margin: 6px 0; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chip-list span { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 999px; padding: 4px 6px 4px 10px; font-size: 0.82rem; }
.chip-list button { border: 0; background: none; color: var(--ink-3); font-size: 1rem; line-height: 1; padding: 0 4px; }
.row-input { display: flex; gap: 8px; }
.row-input input { flex: 1; }
.disclaimer { font-size: 0.85rem; color: var(--ink-2); line-height: 1.5; }
.error-inline { color: var(--warm); font-size: 0.85rem; margin-top: 6px; }

/* ---------- Processing split ---------- */
.split { display: inline-flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface); width: 72px; flex: none; }
.split i { display: block; height: 100%; }
.split-row { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--ink-2); }
.split.mini { display: flex; width: 64px; height: 6px; margin-top: 5px; }
.log-list .which { display: block; font-size: 0.78rem; color: var(--ink-2); margin-top: 3px; }
.card .items .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

/* ---------- Flag a reply ---------- */
.flag-btn { border: 0; background: none; padding: 0; color: var(--ink-3); font: inherit; font-size: 0.7rem; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.flagged { color: var(--accent); }
.flag-form { display: grid; gap: 6px; width: 100%; max-width: 320px; }
.flag-form textarea { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 12px; padding: 8px 10px; font: inherit; font-size: 16px; resize: none; }

/* Pace mark on Today's bars */
.meter .bar { position: relative; overflow: visible; }
.meter .fill { position: relative; z-index: 0; }
.meter .pace { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--ink-2); border-radius: 2px; opacity: 0.7; }

/* ---------- Day navigation (Today tab) ---------- */
.day-nav { display: flex; align-items: center; gap: 10px; }
.day-nav button[data-day-step] { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 1.3rem; line-height: 1; }
.day-nav button:disabled { opacity: 0.35; }
.day-nav span { font-weight: 600; min-width: 92px; text-align: center; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; font-size: 0.85rem; cursor: pointer; }
.day-nav .link { margin-left: auto; }
.log-list details { margin-top: 4px; }
.log-list summary { cursor: pointer; color: var(--accent); font-size: 0.78rem; font-weight: 600; list-style: none; }
.log-list summary::-webkit-details-marker { display: none; }
.log-list .items { margin: 6px 0 0; padding: 0; list-style: none; display: grid; gap: 3px; }
.log-list .items li { display: flex; justify-content: space-between; gap: 10px; border: 0; padding: 0; grid-template-columns: none; color: var(--ink-2); font-size: 0.8rem; }
.log-list .items .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.log-list .assume { margin-top: 6px; font-size: 0.78rem; color: var(--ink-3); font-style: italic; }

.log-list > li > details { grid-column: 2 / -1; margin-top: 2px; }
.gap-list li.neutral { background: var(--surface-2); }

/* Invite gate + invite link */
.gate-form { display: flex; gap: 8px; margin-top: 20px; }
.gate-form input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 0.08em; text-align: center; }
.gate-form .btn { width: auto; padding-left: 20px; padding-right: 20px; }
.linkbtn { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
.code-link { font-size: 0.85rem; letter-spacing: 0; font-weight: 500; word-break: break-all; }

/* Plans */
.photo-btn.locked { opacity: 0.45; }
.plan-perks { margin: 10px 0 14px 18px; padding: 0; color: var(--ink-2, inherit); font-size: 0.92rem; line-height: 1.5; }
.plan-perks li { margin: 2px 0; }

/* ---------- HungerHush brand ---------- */
.wordmark { font-family: var(--display); font-weight: 500; letter-spacing: -0.03em; color: var(--ink); }
.wordmark em { font-style: italic; font-weight: 600; color: var(--accent); }
.topbar h1 .wordmark { font-size: 1.5rem; }
.brand-icon { display: block; margin: 0 auto; border-radius: 22%; }
.signin { background: radial-gradient(120% 70% at 50% 0%, #2E2548 0%, var(--bg) 60%); }
.signin .wordmark-lg { font-size: 2.1rem; margin-top: 14px; display: block; }
.signin .tagline { font-size: 0.8rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; margin: 6px 0 26px; }
.signin .tagline .n { color: var(--warm); }
.signin .hook { font-size: 2.4rem; line-height: 1.05; margin: 0 0 12px; }
.signin .hook em { color: var(--accent); font-style: italic; }
.btn.primary { font-weight: 700; }
.tabbar { background: #191428; }
.composer-wrap, .topbar { background: var(--bg); }
.card { border-left-color: var(--accent); }
.toggle input { accent-color: var(--accent); }

/* Delete account + legal links */
.danger-zone { border-color: #5A3A4E; }
.legal-links a { color: var(--ink-2); }
.error.notice { color: var(--ink-2); }
.fine a { color: var(--ink-2); }
