:root {
  --bg: #0d0d0d;
  --surface: #181818;
  --surface-2: #222;
  --line: #2e2e2e;
  --text: #f2f2f2;
  --muted: #9a9a9a;
  --red: #d32f2f;
  --red-deep: #8b0000;
  --gold: #c9a227;
  --green: #43a047;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(var(--tabs-h) + env(safe-area-inset-bottom));
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--red); outline-offset: 0; }
#view { max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; }

/* Header / hero */
.hero { padding: 8px 2px 14px; }
.hero .kicker { color: var(--gold); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.hero h1 { margin: 4px 0 2px; font-size: 30px; line-height: 1.05; letter-spacing: -.01em; }
.hero h1 .of { color: var(--muted); font-size: 18px; font-weight: 600; }
.hero .focus { font-size: 18px; font-weight: 700; }
.hero .nick { color: var(--red); font-style: italic; }
.hero .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.daynav { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.daynav button { background: var(--surface-2); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.daynav button:disabled { opacity: .35; }
.daynav .spacer { flex: 1; }
.banner { background: #2a1a00; border: 1px solid #5c4300; color: #ffd27a; border-radius: var(--radius); padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.banner.test { background: #2b0a0a; border-color: var(--red-deep); color: #ffb4b4; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.card-head h2 { font-size: 16px; margin: 0; }
.card-head .count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--red); border-radius: inherit; transition: width .25s; }
.bar.green > i { background: var(--green); }
.bar.over > i { background: var(--gold); }

/* Checklist rows */
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.check {
  flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid #555;
  display: grid; place-items: center; margin-top: 1px; transition: background .15s, border-color .15s;
}
.check::after { content: "✓"; font-weight: 800; font-size: 15px; color: #fff; opacity: 0; }
.done .check { background: var(--green); border-color: var(--green); }
.done .check::after { opacity: 1; }
.row-main { flex: 1; min-width: 0; text-align: left; }
.row-title { font-weight: 600; }
.done .row-title { color: var(--muted); text-decoration: line-through; text-decoration-color: #666; }
.row-meta { color: var(--muted); font-size: 13px; margin-top: 1px; }
.row-meta b { color: var(--text); font-weight: 600; }
.row-note { color: #bbb; font-size: 13px; margin-top: 6px; }
.where { color: var(--gold); font-size: 12px; margin-top: 2px; opacity: .85; }
.row-extra { margin-top: 8px; }
.logged { color: var(--gold); font-size: 13px; margin-top: 3px; }

/* Nutrition */
.macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 6px; }
.macro .lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.macro .val { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; margin: 2px 0 4px; }
.macro .val small { color: var(--muted); font-weight: 500; font-size: 11px; }
.items { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; color: #ccc; }
.items li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.items li span:last-child { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.extra-food { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.extra-food .x { color: var(--muted); padding: 4px 8px; font-size: 18px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--red); color: #fff; font-weight: 700; border-radius: 12px; padding: 12px 16px; width: 100%; }
.btn.secondary { background: var(--surface-2); color: var(--text); font-weight: 600; }
.btn.small { width: auto; padding: 8px 12px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row > * { flex: 1; }

/* Plan tab */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip { flex: none; background: var(--surface-2); border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 600; }
.chip.active { background: var(--red); color: #fff; }
.chip.today { box-shadow: inset 0 0 0 2px var(--gold); }
.daycard { width: 100%; text-align: left; }
.daycard .top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.full { background: #1b3d1f; color: #8fe39a; }
.badge.now { background: var(--gold); color: #111; }

/* Progress */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.stat .num { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.weekbars { display: grid; gap: 8px; }
.weekbar { display: grid; grid-template-columns: 54px 1fr 44px; align-items: center; gap: 10px; font-size: 13px; }
.weekbar span:last-child { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.bench { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.bench th:first-child { width: 36%; }
.bench th:last-child { width: 16%; }
.bench th { color: var(--muted); font-weight: 600; text-align: left; padding: 4px 4px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.bench td { padding: 4px; border-top: 1px solid var(--line); }
.bench td:first-child { font-weight: 600; }
.bench input { padding: 6px; text-align: center; font-size: 16px; }
.bench .chg { text-align: right; font-weight: 700; white-space: nowrap; }
.pos { color: #8fe39a; } .neg { color: #ff8a80; }
.chart svg { width: 100%; height: auto; display: block; }

/* Grocery */
.aisle { color: var(--gold); font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; margin: 0 0 4px; }
.buy { color: var(--text); font-weight: 700; white-space: nowrap; text-align: right; }
.stock { color: var(--muted); font-size: 12px; margin-top: 2px; }
.link { color: var(--red); font-size: 12px; font-weight: 600; padding: 6px 0 0; text-align: left; }

.supp-edit { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.card-head + .supp-edit { border-top: 0; padding-top: 0; }

/* Forms */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.help { color: var(--muted); font-size: 13px; }
.help ol { padding-left: 18px; margin: 6px 0; }
.help li { margin: 3px 0; }
.status { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.status.on { background: #1b3d1f; color: #8fe39a; }
.status.off { background: #3a1616; color: #ff9b9b; }
textarea.code { font: 12px/1.35 ui-monospace, Consolas, monospace; height: 96px; resize: none; }

/* Bottom tabs */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(13, 13, 13, .92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
#tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); }
#tabs button .ico { font-size: 18px; line-height: 1; }
#tabs button.active { color: var(--red); }

/* Bottom sheet */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 20; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0; border-top: 1px solid var(--line);
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto;
}
#sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: #444; margin: 4px auto 12px; }
#sheet h3 { margin: 0 0 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button { padding: 8px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.active { background: var(--red); color: #fff; }
.preview { color: var(--muted); font-size: 13px; margin: -4px 0 12px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  background: #333; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5); max-width: calc(100% - 32px);
}
