:root {
  --bg: #0b0d11;
  --bg2: #11141b;
  --card: #181c25;
  --card2: #202632;
  --line: #2a3140;
  --text: #f3f0ea;
  --muted: #8d95a5;
  --faint: #6b7384;
  --accent: #ff7a3d;
  --accent-dim: #ff7a3d22;
  --accent2: #ffc4a0;
  --good: #3ecf8e;
  --good-dim: #3ecf8e22;
  --warn: #f5c14a;
  --warn-dim: #f5c14a22;
  --bad: #ff6b6b;
  --blue: #6ab0ff;
  --nav: #0e1117;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  --radius: 16px;
  --tap: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --nav-h: calc(64px + var(--safe-bot));
  --header-h: calc(56px + var(--safe-top));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
html { height: 100%; }
body {
  min-height: 100%;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

#app { min-height: 100dvh; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: linear-gradient(180deg, #0b0d11 70%, #0b0d11cc 100%);
  border-bottom: 1px solid var(--line);
  min-height: var(--header-h);
}
.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .02em;
  flex: 1;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: #12161e;
  display: grid; place-items: center;
  overflow: hidden;
  flex: 0 0 auto;
}
.brand-mark img { width: 28px; height: 28px; display: block; }

.icon-btn {
  width: var(--tap); height: var(--tap);
  border: 0; border-radius: 12px;
  background: var(--card);
  color: var(--text);
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.icon-btn:active { transform: scale(.97); background: var(--card2); }
.icon-btn svg { width: 22px; height: 22px; }

main {
  padding: 12px 14px calc(var(--nav-h) + 20px);
}

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--nav);
  border-top: 1px solid var(--line);
  padding: 4px 4px var(--safe-bot);
  min-height: var(--nav-h);
}
.bottom-nav button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .01em;
}
.bottom-nav button svg { width: 22px; height: 22px; }
.bottom-nav button.active { color: var(--accent); background: var(--accent-dim); }

.date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.date-nav .date-label {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}
.date-nav .sub {
  display: block;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.chip:active { background: var(--card2); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a0d08;
}
.chip.ghost { color: var(--muted); }
.today-chip { margin-left: auto; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.scroll-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 0 10px;
  margin: 0 -14px;
  padding-left: 14px;
  padding-right: 14px;
}
.scroll-chips::-webkit-scrollbar { display: none; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card h2, .card h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .01em;
}
.card .hint, .hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.accent { color: var(--accent); }

.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}
.progress-head strong { font-size: 18px; }
.bar {
  height: 10px;
  background: #0e1118;
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--line);
}
.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #ff8a4a, #ff7a3d);
  border-radius: 999px;
  width: 0;
  transition: width .2s ease;
}
.bar.good > span { background: linear-gradient(90deg, #2fb87a, #3ecf8e); }
.bar.warn > span { background: linear-gradient(90deg, #e0a62e, #f5c14a); }

.range-bar {
  height: 14px;
  background: #0e1118;
  border-radius: 999px;
  position: relative;
  border: 1px solid var(--line);
  margin: 6px 0 4px;
}
.range-bar .zone {
  position: absolute;
  top: 0; bottom: 0;
  background: var(--good-dim);
  border-left: 1px solid #3ecf8e55;
  border-right: 1px solid #3ecf8e55;
}
.range-bar .fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: #ff7a3d88;
  border-radius: 999px 0 0 999px;
  max-width: 100%;
}
.range-bar .fill.in { background: #3ecf8e99; }
.range-bar .fill.over { background: #f5c14a99; }
.range-bar .marker {
  position: absolute;
  top: -3px; bottom: -3px;
  width: 4px;
  margin-left: -2px;
  background: var(--text);
  border-radius: 2px;
  box-shadow: 0 0 0 2px #0006;
}

.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.check-list li:first-child { border-top: 0; padding-top: 2px; }
.check-list label {
  flex: 1;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  padding-top: 6px;
}
.cue {
  display: block;
  font-weight: 400;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 3px;
}
.check-list li.done label { color: var(--muted); text-decoration: line-through; text-decoration-color: #5a6270; }
.check-list li.done .cue { text-decoration: none; }

.chk {
  appearance: none;
  width: 28px; height: 28px;
  margin: 6px 0 0;
  flex: 0 0 28px;
  border-radius: 8px;
  border: 2px solid #4a5364;
  background: #0e1118;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.chk:checked {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231a0d08' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><path d='M5 12l5 5L20 7'/></svg>");
  background-size: 18px; background-repeat: no-repeat; background-position: center;
}
.chk:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
}
.btn:active { transform: scale(.98); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a0d08;
}
.btn.danger { color: var(--bad); border-color: #5a2a2a; background: #2a1518; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1; }

.notes {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  background: #0e1118;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  color: var(--text);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.field label, .flabel {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.field input, .field select, .field textarea, .in, select.in {
  width: 100%;
  min-height: 44px;
  background: #0e1118;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 16px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.grid-macros { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.callout {
  background: #1a1712;
  border: 1px solid #3a3226;
  color: #e6d3b3;
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
  margin-bottom: 12px;
}
.callout strong { color: var(--accent2); }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.status-pill.eat { background: var(--good-dim); color: var(--good); }
.status-pill.fast { background: #3a2a12; color: var(--warn); }

.meal-card {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}
.meal-card:first-of-type { border-top: 0; }
.meal-card .when { font-size: 12px; color: var(--accent2); font-weight: 700; }
.meal-head { display: flex; gap: 10px; align-items: flex-start; }
.meal-head label { flex: 1; font-weight: 700; padding-top: 6px; }
.pro-target { font-size: 12px; color: var(--muted); font-weight: 600; }

.food-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.food-item .name { font-weight: 700; }
.food-item .meta { font-size: 12px; color: var(--muted); }
.food-item .cals { font-weight: 700; text-align: right; }
.icon-x {
  width: 40px; height: 40px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--faint);
  font-size: 20px;
  grid-row: span 2;
}
.icon-x:active { color: var(--bad); }

.quick-adds { display: flex; flex-wrap: wrap; gap: 8px; }
.quick-adds button {
  border: 1px dashed #3a4252;
  background: #141822;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
}
.quick-adds button:active { background: var(--card2); }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card2);
  font-size: 22px;
  font-weight: 600;
}
.stepper .val { font-size: 22px; font-weight: 800; min-width: 4.5ch; text-align: center; }

.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day-cell {
  background: #12161e;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 4px;
  text-align: center;
  min-height: 86px;
  color: var(--text);
}
.day-cell .dow { font-size: 10px; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.day-cell .num { font-size: 16px; font-weight: 800; margin: 2px 0 4px; }
.day-cell .pct { font-size: 11px; font-weight: 700; }
.day-cell.is-today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day-cell.is-selected { background: var(--accent-dim); }
.day-cell.is-future { opacity: .55; }

.week-list .wk-day {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  width: 100%;
  text-align: left;
  background: transparent;
  border-left: 0; border-right: 0; border-bottom: 0;
  color: inherit;
}
.week-list .wk-day:first-child { border-top: 0; }
.mini-ring { width: 36px; height: 36px; flex: 0 0 36px; }
.wk-day .title { font-weight: 700; }
.wk-day .meta { font-size: 12px; color: var(--muted); }

.chart-wrap { overflow: hidden; }
.chart-wrap svg { width: 100%; height: 180px; display: block; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: #12161e;
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
}
.stat .k { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 20px; font-weight: 800; margin-top: 2px; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  overflow: auto;
  padding: calc(10px + var(--safe-top)) 14px calc(24px + var(--safe-bot));
}
.sheet header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
  padding-bottom: 8px;
}
.sheet header h2 { margin: 0; flex: 1; font-size: 18px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 12px);
  transform: translateX(-50%);
  background: #2a3140;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  z-index: 80;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.prio {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--accent2);
  margin-bottom: 4px;
}
.section-gap { margin-top: 8px; }
.hidden { display: none !important; }
.center { text-align: center; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.tiny { font-size: 12px; color: var(--muted); }
.install-hint {
  background: var(--accent-dim);
  border: 1px solid #ff7a3d55;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

@media (min-width: 720px) {
  #app { max-width: 520px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); min-height: 100dvh; background: var(--bg); }
  .bottom-nav, .app-header, .sheet { max-width: 520px; left: 50%; right: auto; transform: translateX(-50%); width: 100%; }
  .app-header, .sheet { transform: translateX(-50%); }
}
