:root {
  --bg: #0B0D10; --card: #15181D; --raised: #1D2128; --border: #262B33;
  --text: #F2F4F7; --muted: #8A94A6; --accent: #C6F432; --on-accent: #0B0D10;
  --danger: #FF5C5C; --warn: #FFB547; --r: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  max-width: 560px; margin: 0 auto; padding: 10px 12px; background: var(--bg);
}
header h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 800; text-align: center; }
main { max-width: 560px; margin: 0 auto; padding: 4px 16px 40px; }

.icon, .icon-space { width: 40px; height: 40px; flex: none; }
.icon { border: 0; border-radius: 12px; background: var(--card); font-size: 22px; font-weight: 700; cursor: pointer; }
.icon.small { width: 32px; height: 32px; font-size: 18px; color: var(--muted); background: transparent; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.center { display: flex; align-items: center; justify-content: center; min-height: 120px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
h2 { margin: 8px 0 0; font-size: 18px; font-weight: 800; }
h3 { margin: 0 0 6px; font-size: 16px; }
ul, ol { margin: 0; padding-left: 20px; color: var(--muted); }
li + li { margin-top: 4px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 24px; padding: 18px; }
.card.error { color: var(--danger); display: flex; flex-direction: column; gap: 12px; }
.note { background: var(--raised); border-left: 4px solid var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 14px; color: var(--muted); }
.date { color: var(--muted); font-weight: 600; }

input {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--border); outline: none;
}
input:focus { border-color: var(--accent); }
textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 14px; font: inherit; color: inherit;
  background: var(--card); border: 1px solid var(--border); outline: none;
}
textarea { resize: vertical; min-height: 90px; }
select { min-height: 50px; width: auto; flex: none; }
textarea:focus, select:focus { border-color: var(--accent); }
input[type=checkbox] { width: 22px; min-height: 22px; height: 22px; padding: 0; flex: none; accent-color: var(--accent); }

/* routines */
.routine-tile { border-color: var(--accent); }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.scroll .chip { flex: none; }
.r-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; cursor: pointer; }
.r-card:active { transform: scale(.98); }
.r-card:hover, .r-card:focus-visible { border-color: var(--accent); outline: none; }
.r-name { font-size: 18px; font-weight: 800; }
.r-title { margin: 0; font-size: 24px; }
.r-sub { color: var(--muted); font-size: 13px; }
.r-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.tag { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; padding: 3px 8px; border-radius: 999px; background: var(--accent); color: var(--on-accent); }
.tag.dim { background: var(--raised); color: var(--muted); }
.tag.on { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.r-macros { display: flex; flex-wrap: wrap; gap: 4px 14px; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.bookmark { font-size: 22px; color: var(--accent); }
.r-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.r-items li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.r-swaps { flex-basis: 100%; color: var(--muted); font-size: 12px; }
.stack.tight { gap: 8px; }
.ex-row { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.ex-row:last-child { border-bottom: 0; }
.ex-sets { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row.check { align-items: flex-start; gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grid6 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.grid4 input, .grid6 input { padding: 10px 8px; min-height: 44px; font-size: 14px; }
.meal-form .link { align-self: flex-start; }
.sets { display: flex; flex-wrap: wrap; gap: 10px; }
.set { width: 48px; height: 48px; border-radius: 14px; border: 2px solid var(--border); background: var(--raised); font-weight: 800; font-size: 16px; cursor: pointer; color: var(--muted); }
.set.done { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.set:active { transform: scale(.94); }

.btn {
  min-height: 50px; padding: 0 18px; border-radius: var(--r); border: 1px solid var(--border);
  background: var(--raised); font-weight: 700; cursor: pointer; transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.big { min-height: 56px; font-size: 17px; }
.btn.step { width: 60px; padding: 0; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 700; cursor: pointer; }
.link.danger { color: var(--danger); font-size: 14px; }

.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--raised); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* login */
.login { padding-top: 12px; }
.tabs { display: flex; background: var(--card); border-radius: 14px; padding: 4px; }
.tab { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 10px; font-weight: 700; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--raised); color: var(--text); }
.error-text { color: var(--danger); margin: 0; min-height: 1em; font-size: 14px; }

/* dashboard */
.ring { position: relative; width: 220px; height: 220px; }
.ring-progress { transition: stroke-dashoffset .6s ease; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-big { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.ring-label { color: var(--muted); font-weight: 600; font-size: 14px; margin-top: 4px; }
.ring-label.warn { color: var(--warn); }
.ring-small { color: var(--muted); font-size: 13px; margin-top: 6px; font-variant-numeric: tabular-nums; }
/* The ring card is a button: tap it to edit goals. */
.ring-btn { position: relative; width: 100%; font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease, border-color .12s ease; }
.ring-btn:active { transform: scale(.97); }
.ring-btn:hover, .ring-btn:focus-visible { border-color: var(--accent); outline: none; }
.edit-badge { position: absolute; top: 12px; right: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--raised); color: var(--muted); font-size: 12px; font-weight: 700; }
.macro { display: flex; flex-direction: column; gap: 6px; }
.macro-head { display: flex; justify-content: space-between; align-items: baseline; }
.macro-label { font-weight: 700; display: inline-flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.macro-value { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.macro-value b { color: var(--text); }
.track { height: 10px; border-radius: 10px; background: var(--raised); overflow: hidden; }
.fill { height: 100%; border-radius: 10px; transition: width .6s ease; }
.macro-left { color: var(--muted); font-size: 12px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  min-height: 96px; border-radius: 24px; border: 1px solid var(--border); background: var(--card);
  display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-start; padding: 14px 16px; text-align: left; cursor: pointer;
}
.tile b { font-size: 17px; }
.tile span { color: var(--muted); font-size: 13px; }
.tile.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tile.accent span { color: var(--on-accent); opacity: .7; }
.tile:active { transform: scale(.97); }
.meal { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 8px 12px 14px; }
.meal-type { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.meal-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-macros { color: var(--muted); font-size: 13px; }
.meal-kcal { color: var(--accent); font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* scanner */
.camera { position: relative; aspect-ratio: 3 / 4; max-height: 60vh; width: 100%; border-radius: 24px; overflow: hidden; background: #000; }
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame {
  position: absolute; left: 10%; right: 10%; top: 35%; bottom: 35%;
  border: 3px solid var(--accent); border-radius: 16px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35);
}
.camera .chip { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, .55); color: #fff; }
.scan-status { text-align: center; color: var(--muted); min-height: 1.4em; }
.row input { flex: 1; }

/* food search results */
.result { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 14px; }
.result:active { transform: scale(.98); }
.result:hover, .result:focus-visible { border-color: var(--accent); outline: none; }
.result-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.result-macros { color: var(--muted); font-size: 12px; margin-top: 2px; }
.result-kcal { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.result-kcal b { color: var(--accent); font-size: 18px; font-variant-numeric: tabular-nums; }
.result-kcal span { color: var(--muted); font-size: 11px; }

/* confirm */
.banner { background: var(--card); border-left: 4px solid var(--accent); border-radius: var(--r); padding: 12px 14px; }
.banner.warn { border-left-color: var(--warn); }
.banner p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.confirm { min-height: calc(100vh - 70px - env(safe-area-inset-top)); min-height: calc(100dvh - 70px - env(safe-area-inset-top)); }
.confirm .footer { margin-top: auto; }
.label { color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; margin-bottom: -6px; }
.name-input { font-size: 18px; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); font-weight: 600; cursor: pointer; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.item { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.item-name { background: transparent; border: 0; padding: 0; min-height: 0; font-weight: 700; flex: 1; }
.grams-row { display: flex; gap: 8px; }
.grams-box { flex: 1; display: flex; align-items: center; justify-content: center; gap: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; }
.grams { width: 90px; min-height: 48px; border: 0; background: transparent; text-align: right; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; padding: 0; }
.grams-box span { color: var(--muted); }
.ai-hint { color: var(--muted); font-size: 12px; text-align: center; }
.ai-hint:empty { display: none; }
.item-macros { display: flex; justify-content: space-between; font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.footer {
  position: sticky; bottom: 0; margin: 4px -16px -40px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 12px;
}
.totals { display: flex; justify-content: space-between; }
.total { display: flex; flex-direction: column; align-items: center; flex: 1; }
.total b { font-size: 20px; font-variant-numeric: tabular-nums; }
.total span { color: var(--muted); font-size: 11px; font-weight: 600; }

/* goals */
.goal-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.goal-input { width: 100px; text-align: right; font-size: 20px; font-weight: 800; background: transparent; border: 0; padding: 0; }
.unit { color: var(--muted); width: 34px; font-size: 14px; }

/* modal + toast */
.modal-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .6); display: flex; align-items: flex-end; justify-content: center; }
.modal {
  width: 100%; max-width: 560px; background: var(--card); border-radius: 24px 24px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px; max-height: 85vh; overflow: auto;
}
.modal h2 { margin: 0; }
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 30;
  background: var(--raised); border: 1px solid var(--border); padding: 12px 16px; border-radius: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: var(--danger); }
