:root {
  /* Text colours are checked for contrast: body text 4.5:1 or better, bars and icons 3:1 where they carry meaning. */
  --bg: #FAF6F1; --card: #FFFFFF; --ink: #27232E; --muted: #6A6573; --line: #EEE8DF; --track: #F1ECE4; --rail: #E6DFD4;
  --brand: #BD4A2E; --on-brand: #FFFFFF; --brand-soft: #FBE6DF; --warm: #E0921C; --good: #238469; --on-good: #FFFFFF; --good-soft: #DDF2EB;
  --shadow: 0 1px 2px rgba(60, 40, 20, .04), 0 8px 24px rgba(60, 40, 20, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17151B; --card: #221F28; --ink: #F3EFF6; --muted: #A39DAD; --line: #322E3A; --track: #2E2A36; --rail: #3A3544;
    --brand: #F0806A; --on-brand: #2B0E07; --brand-soft: #3A2622; --warm: #F0AE55; --good: #48B99B; --on-good: #0B2A22; --good-soft: #1E3A33;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
button { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
img { -webkit-user-drag: none; -webkit-touch-callout: none; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
}
body.lock { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
h2 { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

#app { max-width: 460px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 14px) 16px 120px; }

/* top */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wk { font-weight: 700; font-size: 15px; }
.wk span { color: var(--muted); font-weight: 500; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.lang { display: flex; background: var(--track); border-radius: 99px; padding: 3px; }
.lang button { position: relative; padding: 7px 12px; border-radius: 99px; font-size: 13px; font-weight: 600; color: var(--muted); }
.lang button::after { content: ""; position: absolute; inset: -7px 0; }   /* a 44 px tall touch area without a bigger pill */
.lang button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.icon-btn { width: 44px; height: 44px; margin-right: -8px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.icon-btn svg { width: 20px; height: 20px; }

.daynav { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 12px; }
.daynav .arrow { width: 44px; height: 44px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); font-size: 22px; line-height: 1; }
.daynav .arrow:disabled { opacity: .3; box-shadow: none; }
.daylabel { font-size: 24px; font-weight: 800; letter-spacing: -.01em; text-align: center; }
.daylabel small { display: block; font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.back { display: block; margin: 2px auto 0; padding: 6px 14px; font-size: 13px; font-weight: 700; letter-spacing: 0; color: var(--brand); }

.seg { display: flex; background: var(--track); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1 1 auto; min-height: 44px; padding: 8px 6px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

.card { background: var(--card); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }

/* energy */
.energy { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 11; stroke-linecap: round; }
.ring .bg { stroke: var(--rail); }
.ring .fg { stroke: var(--brand); transition: stroke-dashoffset .6s cubic-bezier(.2, .8, .2, 1); }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.ring-text b { font-size: 30px; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.ring-text span { font-size: 12px; color: var(--muted); margin-top: 4px; }
.macros { flex: 1; min-width: 0; display: grid; gap: 10px; }
.macro-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; font-weight: 600; }
.macro-top span { font-size: 12px; font-weight: 500; color: var(--muted); }

/* bars */
.bar { height: 10px; background: var(--rail); border-radius: 5px; overflow: hidden; display: flex; gap: 2px; }
.bar.thin { height: 7px; margin-top: 4px; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--warm); transition: width .6s cubic-bezier(.2, .8, .2, 1); min-width: 0; }
.bar i.zero { display: none; }
.bar.brand i { background: var(--brand); }
.bar.met i { background: var(--good); }
.bar i.supp {
  background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, .55) 0 3px, transparent 3px 6px);
}
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 8px; border-radius: 3px; background: var(--warm); margin-right: 5px; vertical-align: middle; }
.legend i.supp { background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, .55) 0 3px, transparent 3px 6px); }

.nut { margin-bottom: 6px; padding: 5px 0; min-height: 44px; display: block; width: 100%; text-align: left; }
.chev { color: var(--muted); font-size: 16px; }
.nut:last-child { margin-bottom: 0; }
.nut-top { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.nut-top b { font-size: 15px; font-weight: 600; flex: 1; }
.nut-top .amt { font-size: 12px; color: var(--muted); }
.pct { font-size: 13px; font-weight: 700; min-width: 46px; text-align: right; }
.pct.ok { color: var(--ink); }
.pct.ok::before {
  content: "✓"; display: inline-grid; place-items: center; width: 16px; height: 16px; margin-right: 4px;
  border-radius: 50%; background: var(--good); color: var(--on-good); font-size: 10px; vertical-align: 1px;
}

/* every day */
.daily { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tile { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.tile .pic { position: relative; width: 100%; aspect-ratio: 3 / 4; padding: 5px 2px; border-radius: 16px; overflow: hidden; background: var(--track); outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .2s, transform .15s; }
.tile:active .pic { transform: scale(.94); }
.tile img { width: 100%; height: 100%; object-fit: contain; display: block; filter: grayscale(.75) opacity(.55); transition: filter .25s; }
.tile.on { color: var(--ink); }
.tile.on .pic { outline-color: var(--good); }
.tile.on img { filter: none; }
.tile .tick {
  position: absolute; right: 4px; bottom: 4px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--good); color: var(--on-good); font-size: 12px; display: grid; place-items: center;
  transform: scale(0); transition: transform .25s cubic-bezier(.3, 1.6, .5, 1);
}
.tile.on .tick { transform: scale(1); }

/* log */
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; padding-top: 0; }
.row:last-child { padding-bottom: 0; }
.ico { width: 44px; height: 44px; flex: none; border-radius: 13px; background: var(--track); display: grid; place-items: center; font-size: 24px; overflow: hidden; }
.ico img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.row-main { flex: 1; min-width: 0; }
.row-main b { display: block; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main span { font-size: 13px; color: var(--muted); }
.step { display: flex; align-items: center; background: var(--track); border-radius: 99px; }
.step button { width: 44px; height: 44px; font-size: 20px; font-weight: 600; border-radius: 50%; }
.ghost { margin-top: 12px; padding: 12px 20px; min-height: 44px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 15px; }
.step button:active { background: var(--line); }
.empty { text-align: center; color: var(--muted); padding: 10px 0 4px; font-size: 14px; }
.empty div { font-size: 32px; margin-bottom: 4px; }

/* 7 days */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; }
.wd { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.wd .col { position: relative; width: 100%; max-width: 26px; height: 84px; background: var(--rail); border-radius: 6px; display: flex; align-items: flex-end; overflow: hidden; }
.wd .col i { display: block; width: 100%; background: var(--brand); border-radius: 4px 4px 0 0; transition: height .6s cubic-bezier(.2, .8, .2, 1); }
.wd .col::after { content: ""; position: absolute; left: 0; right: 0; bottom: 80%; border-top: 2px dashed var(--muted); opacity: .5; }
.wd.sel { color: var(--ink); }
.cap { font-size: 12px; color: var(--muted); margin-top: 12px; text-align: center; }

/* add button */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 18px);
  background: var(--brand); color: var(--on-brand); font-weight: 700; font-size: 17px; padding: 15px 30px; border-radius: 99px;
  box-shadow: 0 10px 26px rgba(189, 74, 46, .35); z-index: 5; white-space: nowrap;
}
.fab:active { transform: translateX(-50%) scale(.96); }

/* add sheet */
.sheet {
  position: fixed; inset: 0; z-index: 10; background: var(--bg); display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .32s cubic-bezier(.2, .8, .2, 1); visibility: hidden;
  padding-top: env(safe-area-inset-top);
}
.sheet.open { transform: none; visibility: visible; }
.sheet > * { width: 100%; max-width: 460px; margin-left: auto; margin-right: auto; }
.sheet-head { display: flex; gap: 10px; padding: 14px 16px 10px; align-items: center; }
.sheet-head input {
  flex: 1; min-width: 0; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; -webkit-appearance: none; appearance: none;
}
.done { font-weight: 700; color: var(--brand); padding: 10px 4px; min-height: 44px; min-width: 44px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 12px; scrollbar-width: none; flex: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; min-height: 44px; padding: 8px 16px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); font-size: 14px; font-weight: 600; color: var(--muted); }
.chips button.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; align-content: start; padding: 2px 16px calc(env(safe-area-inset-bottom) + 90px); }
.food { position: relative; background: var(--card); border-radius: 18px; padding: 12px 8px 10px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; min-height: 140px; }   /* fits a two-line name */
.food:active { transform: scale(.96); }
.food > * { flex: none; }
.food .ico { width: 52px; height: 52px; font-size: 30px; border-radius: 15px; }
.food b { font-size: 13px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.food span { font-size: 12px; color: var(--muted); line-height: 1.2; margin-top: auto; }   /* the portion sits on the tile's bottom edge */
.food .badge { position: absolute; top: 6px; right: 6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--good); color: var(--on-good); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.grid .none { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

/* modals */
.backdrop { position: fixed; inset: 0; background: rgba(20, 15, 25, .45); z-index: 20; opacity: 0; pointer-events: none; transition: opacity .25s; }
.backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--card); border-radius: 26px 26px 0 0;
  padding: 22px 20px calc(env(safe-area-inset-bottom) + 22px); max-width: 460px; margin: 0 auto;
  transform: translateY(105%); transition: transform .3s cubic-bezier(.2, .8, .2, 1); visibility: hidden; text-align: center;
}
.modal.open { transform: none; visibility: visible; }
.modal .ico { width: 72px; height: 72px; font-size: 40px; border-radius: 20px; margin: 0 auto 10px; }
.modal h3 { margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.modal p { margin: 0 0 4px; font-size: 14px; color: var(--muted); }
.modal .sofar { color: var(--ink); font-weight: 600; }
.p-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px; }
.p-btns button { background: var(--brand-soft); color: var(--brand); border-radius: 18px; padding: 16px 0; font-size: 24px; font-weight: 800; }
.p-btns button:active { background: var(--brand); color: var(--on-brand); }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--rail); margin: -10px auto 14px; }
.close { position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; border-radius: 50%; font-size: 24px; line-height: 1; color: var(--muted); }
.p-q { font-size: 13px; font-weight: 600; margin-top: 16px; color: var(--muted); }
.link { margin-top: 16px; font-size: 14px; font-weight: 600; color: var(--muted); padding: 6px 12px; }

#settings { text-align: left; }
#settings h3 { margin-bottom: 14px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; font-weight: 600; }
.field small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.field input[type=date] { width: auto; min-width: 150px; }
.field input { width: 96px; font: inherit; font-weight: 700; text-align: right; color: var(--ink); background: var(--track); border: 0; border-radius: 12px; padding: 10px 12px; -webkit-appearance: none; appearance: none; }
.primary { width: 100%; margin-top: 16px; background: var(--brand); color: var(--on-brand); font-weight: 700; padding: 14px; border-radius: 16px; }
.primary:active, .ghost:active { transform: scale(.98); }
.fine { font-size: 12px; color: var(--muted); margin-top: 12px !important; line-height: 1.5; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 22px); transform: translate(-50%, 300%); z-index: 30;
  background: #27232E; color: #FAF6F1; border: 1px solid rgba(255, 255, 255, .14); border-radius: 99px; padding: 12px 18px; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 6px; transition: transform .3s cubic-bezier(.2, .8, .2, 1); max-width: calc(100vw - 32px); white-space: nowrap;
}
.toast:not(.open) { visibility: hidden; }
.toast.open { transform: translate(-50%, 0); }
body:not(.lock) .toast { bottom: calc(env(safe-area-inset-bottom) + 86px); }
.toast span { overflow: hidden; text-overflow: ellipsis; }
.toast button { position: relative; color: #F5B25C; font-weight: 700; padding: 2px 4px 2px 12px; flex: none; }
.toast button::after { content: ""; position: absolute; inset: -14px -10px; }

/* weight */
.card .primary { margin-top: 0; }
.w-big { font-size: 40px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.w-big small { font-size: 16px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.w-sub { font-size: 14px; color: var(--muted); margin: 2px 0 12px; }
.status { display: inline-block; font-size: 13px; font-weight: 600; background: var(--track); border-radius: 99px; padding: 4px 12px; margin-bottom: 14px; }
.chart svg { width: 100%; height: auto; display: block; margin-bottom: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11.5px; }
.chart .band { fill: var(--good-soft); stroke: var(--good); stroke-width: 1; stroke-opacity: .5; }
.chart .now { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .me { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--ink); stroke: var(--card); stroke-width: 2; }
.chart .lab { fill: var(--ink); font-size: 11px; font-weight: 700; }
.legend i.band { background: var(--good-soft); border: 1px solid var(--good); }
.legend i.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); }
.x { width: 44px; height: 44px; border-radius: 50%; color: var(--muted); font-size: 20px; flex: none; }
.w-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 18px 0 20px; font-weight: 600; color: var(--muted); }
.w-row button { width: 48px; height: 48px; border-radius: 50%; background: var(--track); color: var(--ink); font-size: 24px; flex: none; }
.w-row input { width: 124px; font: inherit; font-size: 36px; font-weight: 800; text-align: center; border: 0; background: none; color: var(--ink); padding: 0; -moz-appearance: textfield; appearance: textfield; }
.w-row input::-webkit-outer-spin-button, .w-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* nutrient sources */
.modal { max-height: 90vh; overflow-y: auto; }
.left { text-align: left; }
.left h2 { margin: 18px 0 10px; }
.n-stat { font-size: 15px; margin: 12px 0; color: var(--muted); }
.n-stat b { font-size: 24px; font-weight: 800; color: var(--ink); }
.n-stat span { display: block; font-size: 12px; }
.modal .tip { background: var(--track); border-radius: 12px; padding: 10px 12px; color: var(--ink); font-size: 13px; line-height: 1.45; }
.src { width: 100%; text-align: left; }
.modal .src .ico { width: 44px; height: 44px; font-size: 24px; margin: 0; border-radius: 13px; }

/* settings extras */
.field.col { flex-direction: column; align-items: stretch; gap: 8px; }
.acts { display: flex; background: var(--track); border-radius: 12px; padding: 3px; }
.acts button { flex: 1; padding: 8px 4px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.acts button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

:lang(th) body, body.th { line-height: 1.55; }
body.th h2 { letter-spacing: 0; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Cloud account and onboarding: kept separate from original screen styling. */
[hidden] { display: none !important; }
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 32px 20px; box-sizing: border-box; }
.auth-inner { width: 100%; max-width: 390px; background: var(--card); border-radius: 28px; padding: 28px 24px; box-sizing: border-box; box-shadow: var(--shadow); }
.auth-mark,.welcome-mark { color: var(--brand); font-size: 42px; text-align: center; line-height: 1; }
.auth h1,.welcome h1 { font-size: 32px; margin: 6px 0 12px; text-align: center; letter-spacing: -.05em; }
.auth p,.welcome p { text-align: center; color: var(--muted); font-size: 15px; }
.auth form { display: grid; gap: 12px; margin-top: 24px; }
.auth label { display: grid; font-size: 13px; font-weight: 700; gap: 6px; }
.auth input { border-radius: 12px; border: 1px solid var(--line); padding: 13px 12px; background: var(--bg); color: var(--ink); font-size: 16px; }
.auth .primary { width: 100%; margin-top: 6px; }
.auth .auth-error { color: #b43628; font-size: 13px; line-height: 1.45; text-align: left; margin-top: 12px; overflow-wrap: anywhere; }
.auth .auth-meta { font-size: 12px; line-height: 1.5; margin-top: 18px; }
.auth .auth-retry { margin-top: 12px; width: 100%; min-height: 44px; font-weight: 700; color: var(--brand); }
.welcome { min-height: 70dvh; display: flex; flex-direction: column; justify-content: center; gap: 12px; align-items: center; max-width: 340px; margin: 0 auto; }
.welcome .primary { width: 100%; }
.secondary-action { padding: 12px 8px; color: var(--brand); font-size: 14px; font-weight: 700; }
.sync-state { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); padding: 8px 2px; }
.sync-state i { width: 7px; height: 7px; border-radius: 50%; background: #399b66; }
.sync-state.pending i,.sync-state.checking i { background: #d99e44; }
.sync-state.offline i { background: #ce594e; }
.account-actions { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--line); }
.account-title { font-weight: 700; margin-bottom: 8px; }
.account-action { width: 100%; text-align: left; display: block; padding: 12px 4px; border-bottom: 1px solid var(--line); font-size: 14px; color: var(--brand); }
.account-action.logout { color: var(--muted); }

.sync-state.error i { background: #ce594e; }
