:root {
  color-scheme: light dark;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --ink: #1c1d1a;
  --muted: #7b7c75;
  --faint: #e6e3db;
  --accent: #e0542e;
  --accent-ink: #ffffff;
  --p: #3f7f5f;
  --c: #d9a441;
  --f: #c7643f;
  --warn: #b5622a;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(30, 28, 20, .10), 0 2px 6px rgba(30, 28, 20, .06);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121311; --surface: #1c1d1a; --ink: #eeece6; --muted: #8f9088; --faint: #2b2c28;
    --accent: #ef6a42; --p: #6fb08d; --c: #e2b55a; --f: #e0805a; --warn: #e39457;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100dvh; font-size: 16px; line-height: 1.4; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.primary { background: var(--ink); color: var(--bg); border-radius: 999px; padding: .7rem 1.3rem; font-weight: 600; min-height: 44px; }
.ghost { border-radius: 999px; padding: .7rem 1.1rem; min-height: 44px; color: var(--ink); box-shadow: inset 0 0 0 1px var(--faint); }
.danger { color: var(--warn); padding: .7rem .4rem; min-height: 44px; }
.text-btn { color: var(--muted); font-size: .85rem; padding: .5rem .6rem; min-height: 40px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--ink); }
.icon-btn:disabled { opacity: .2; }
.quiet { color: var(--muted); }
.small { font-size: .8rem; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, label:focus-within.shutter { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Sign in */
.signin { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.signin-inner { width: min(340px, 100%); text-align: center; }
.signin-mark { border-radius: 14px; }
.signin h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -.01em; margin: .7rem 0 1.6rem; }
.signin form { display: grid; gap: .7rem; }
.signin input { width: 100%; padding: .85rem 1rem; border-radius: 14px; border: 1px solid var(--faint); background: var(--surface); }
#redeem .primary { width: 100%; }

/* App */
.app { max-width: 560px; margin: 0 auto; padding: env(safe-area-inset-top) 16px calc(140px + env(safe-area-inset-bottom)); min-height: 100dvh; }
.bar { display: flex; align-items: center; gap: 2px; height: 60px; margin: 0 -8px; }
.bar-gap { flex: 1; }
.day-label { font-weight: 600; font-size: 1.02rem; padding: .5rem .4rem; min-height: 44px; }

.summary { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 4px 12px; padding: 18px 2px 22px; }
.kcal { font-size: 3.4rem; font-weight: 300; letter-spacing: -.03em; line-height: 1; }
.kcal small, .weight small { font-size: .95rem; font-weight: 400; letter-spacing: 0; color: var(--muted); margin-left: .35rem; }
.weight { font-size: 1.5rem; font-weight: 400; text-align: right; padding-bottom: .25rem; }
.energy { grid-column: 1 / -1; display: flex; height: 6px; border-radius: 6px; overflow: hidden; background: var(--faint); margin-top: 14px; }
.energy i { display: block; height: 100%; width: 0; transition: width .5s ease; }
#bar-p { background: var(--p); } #bar-c { background: var(--c); } #bar-f { background: var(--f); }
.macros { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); margin: 12px 0 0; }
.macros dt { font-size: .76rem; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.macros dd { margin: 2px 0 0; font-size: 1.02rem; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.p { background: var(--p); } .dot.c { background: var(--c); } .dot.f { background: var(--f); }
.summary.empty { opacity: .35; }

.feed { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--faint); }
.feed li { border-bottom: 1px solid var(--faint); }
.entry { display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: center; width: 100%; text-align: left; padding: 12px 0; min-height: 80px; }
.thumb { width: 56px; height: 56px; border-radius: 14px; object-fit: cover; background: var(--faint); display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.entry-main { min-width: 0; }
.entry-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-meta { font-size: .8rem; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-num { font-size: 1.05rem; text-align: right; }
.entry-num small { display: block; color: var(--muted); font-size: .72rem; }
.flag { color: var(--warn); }
.entry.pending .entry-title { color: var(--muted); }
.entry.pending .thumb { animation: pulse 1.4s ease-in-out infinite; }
.entry.failed .entry-meta { color: var(--warn); white-space: normal; }
@keyframes pulse { 50% { opacity: .5; } }

.offline { text-align: center; color: var(--muted); font-size: .85rem; }

/* Shutter: centred on an empty day, docked at the bottom once the day has entries */
.shutter-wrap { position: fixed; left: 50%; transform: translate(-50%, 0); bottom: calc(28px + env(safe-area-inset-bottom)); display: flex; align-items: center; transition: bottom .45s cubic-bezier(.2,.8,.2,1); z-index: 5; }
.shutter { width: 76px; height: 76px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: var(--shadow), inset 0 0 0 4px rgba(255,255,255,.18); cursor: pointer; transition: transform .15s ease, width .45s cubic-bezier(.2,.8,.2,1), height .45s cubic-bezier(.2,.8,.2,1); }
.shutter:active { transform: scale(.94); }
.shutter svg { width: 32px; height: 32px; stroke-width: 1.7; }
.shutter input, .gallery input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.gallery { position: absolute; left: calc(100% + 18px); width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); background: var(--surface); box-shadow: var(--shadow); cursor: pointer; }
.gallery svg { width: 20px; height: 20px; }
body.empty-day .shutter-wrap { bottom: calc(50dvh - 70px); }
body.empty-day .shutter { width: 112px; height: 112px; }
body.empty-day .shutter svg { width: 42px; height: 42px; }

/* Sheets */
dialog.sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 92dvh; background: var(--surface); color: var(--ink); border-radius: 24px 24px 0 0; box-shadow: var(--shadow); }
dialog.sheet::backdrop { background: rgba(10, 10, 8, .38); }
dialog.sheet[open] { animation: rise .28s cubic-bezier(.2,.8,.2,1); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 24px; } }
.small-sheet { max-width: 420px; }
.sheet-inner { padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.sheet-grip:focus { outline: none; }
.sheet-grip { width: 38px; height: 4px; background: var(--faint); border-radius: 4px; margin: 0 auto 2px; }
.sheet h2 { font-size: 1.15rem; font-weight: 600; margin: 4px 0 0; }
.sheet h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 14px 0 -4px; }
.entry-photo { width: 100%; max-height: 28dvh; object-fit: cover; border-radius: 16px; background: var(--faint); }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.field { display: grid; position: relative; gap: 4px; }
.field span { font-size: .74rem; color: var(--muted); }
.field input, .field select, .correct textarea, .inline-form input { width: 100%; min-width: 0; padding: .65rem .75rem; border-radius: 12px; border: 1px solid var(--faint); background: var(--bg); }
.field em { position: absolute; right: .7rem; bottom: .7rem; font-style: normal; font-size: .78rem; color: var(--muted); pointer-events: none; }
.field.wide { grid-column: 1 / -1; }
.sanity { font-size: .82rem; color: var(--muted); margin: -4px 0 0; }
.sanity.off { color: var(--warn); }
.items { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.items li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--faint); }
.items li span:last-child { color: var(--muted); white-space: nowrap; }
.correct { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; }
.correct textarea { resize: none; }
.cost { font-size: .8rem; color: var(--muted); margin: 0; }
.actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

.cost-totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cost-totals div { background: var(--bg); border-radius: 14px; padding: 12px 14px; }
.cost-totals small { display: block; font-size: .74rem; color: var(--muted); }
.cost-totals b { font-size: 1.35rem; font-weight: 500; }
.cost-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.cost-table th { font-weight: 500; color: var(--muted); text-align: right; padding: 4px 0; font-size: .74rem; }
.cost-table th:first-child, .cost-table td:first-child { text-align: left; }
.cost-table td { text-align: right; padding: 6px 0; border-top: 1px solid var(--faint); }
.cost-log { list-style: none; margin: 0; padding: 0; font-size: .8rem; max-height: 260px; overflow: auto; }
.cost-log li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 7px 0; border-top: 1px solid var(--faint); }
.cost-log li span:nth-child(2) { text-align: right; }
.cost-log li span:nth-child(3), .cost-log li span:nth-child(4) { color: var(--muted); font-size: .74rem; }
.cost-log li span:nth-child(4) { text-align: right; }
.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.invites { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.invites li { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--faint); }

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