:root {
  --bg: #0d0f0d;
  --panel: #14181410;
  --panel-solid: #161a16;
  --panel-2: #1c211c;
  --line: #2a312a;
  --ink: #e7ece6;
  --ink-dim: #8b968a;
  --ink-faint: #5c655b;
  --acc: #7dff8a;          /* phosphor green */
  --acc-dim: #3a6b40;
  --warn: #ffd166;
  --over: #ff6b6b;
  --carb: #6bb6ff;
  --fat: #ffb86b;
  --prot: #7dff8a;
  --radius: 4px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: -1px -1px;
  background-attachment: fixed;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at top, rgba(125,255,138,0.04), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

#app { position: relative; z-index: 1; }

.mono { font-family: var(--mono); }

/* ---------- Layout ---------- */
.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 120px;
  padding-bottom: calc(120px + env(safe-area-inset-bottom));
}

header.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
  background: rgba(13,15,13,0.82);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.5px;
  font-size: 16px;
}
.brand .dot { color: var(--acc); }
.brand small { color: var(--ink-faint); font-weight: 400; }

.logout-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius);
  cursor: pointer;
}
.logout-btn:hover { color: var(--ink); border-color: var(--ink-faint); }

/* ---------- Tabs ---------- */
nav.tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  background: rgba(18,21,18,0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  flex: 1;
  background: none;
  border: none;
  color: var(--ink-faint);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.5px;
  padding: 12px 4px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border-top: 2px solid transparent;
  margin-top: -1px;
}
nav.tabs button .ic { font-size: 18px; line-height: 1; }
nav.tabs button.active { color: var(--acc); border-top-color: var(--acc); }

/* ---------- Cards / panels ---------- */
.card {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 14px;
}
.card h2 {
  font-family: var(--mono);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-dim);
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h2::before {
  content: "";
  width: 6px; height: 6px;
  background: var(--acc);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--acc);
}

.section-title {
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--ink-faint);
  margin: 22px 2px 2px;
}

/* ---------- Dashboard ring/bars ---------- */
.day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px;
}
.date-nav { display: flex; align-items: center; gap: 10px; }
.date-nav button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  width: 34px; height: 34px;
  border-radius: var(--radius);
  font-size: 18px;
  cursor: pointer;
  font-family: var(--mono);
}
.date-label { font-family: var(--mono); font-size: 13px; color: var(--ink-dim); min-width: 120px; text-align: center; }

.kcal-hero {
  text-align: center;
  padding: 18px 0 6px;
}
.kcal-num {
  font-family: var(--mono);
  font-size: 46px;
  font-weight: 600;
  line-height: 1;
  color: var(--acc);
}
.kcal-num.over { color: var(--over); }
.kcal-sub { font-family: var(--mono); font-size: 13px; color: var(--ink-faint); margin-top: 6px; }

.bar-row { margin-top: 14px; }
.bar-label {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 12px;
  margin-bottom: 5px;
}
.bar-label .name { color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.bar-label .val { color: var(--ink); }
.bar-label .val .tgt { color: var(--ink-faint); }
.bar-track {
  height: 7px;
  background: var(--panel-2);
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 99px; transition: width 0.4s ease; }
.bar-fill.prot { background: var(--prot); }
.bar-fill.carbs { background: var(--carb); }
.bar-fill.fat { background: var(--fat); }
.bar-fill.over { background: var(--over) !important; }

/* ---------- Log entries ---------- */
.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.entry:last-child { border-bottom: none; }
.entry .e-main { flex: 1; min-width: 0; }
.entry .e-name {
  font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.entry .e-macros {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 2px;
}
.entry .e-kcal {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--acc);
  white-space: nowrap;
}
.entry .e-del {
  background: none; border: none; color: var(--ink-faint);
  font-size: 18px; cursor: pointer; padding: 4px 2px; line-height: 1;
}
.entry .e-del:hover { color: var(--over); }

.empty {
  text-align: center;
  color: var(--ink-faint);
  font-family: var(--mono);
  font-size: 13px;
  padding: 28px 10px;
}

/* ---------- Lists (foods/recipes) ---------- */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 8px;
}
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-name { font-size: 14px; font-weight: 500; }
.list-item .li-sub { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); margin-top: 3px; }
.li-actions { display: flex; gap: 6px; }
.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  border-radius: var(--radius);
  width: 34px; height: 34px;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--ink); }
.icon-btn.add { color: var(--acc); border-color: var(--acc-dim); }
.icon-btn.danger:hover { color: var(--over); border-color: var(--over); }

/* ---------- Forms ---------- */
.field { margin-top: 12px; }
.field label {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-dim);
  margin-bottom: 5px;
}
input, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  padding: 11px 12px;
  border-radius: var(--radius);
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--acc);
  box-shadow: 0 0 0 2px rgba(125,255,138,0.12);
}
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.btn {
  width: 100%;
  background: var(--acc);
  color: #08210b;
  border: none;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.5px;
  padding: 13px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: 16px;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-dim);
}
.btn.ghost:hover { color: var(--ink); border-color: var(--ink-faint); }
.btn.small { width: auto; padding: 9px 14px; font-size: 13px; margin-top: 0; }

.search-bar { position: relative; }
.search-bar input { padding-left: 36px; }
.search-bar::before {
  content: "⌕";
  position: absolute;
  left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--ink-faint);
  font-size: 18px;
}

/* ---------- Modal / sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
  animation: slideup 0.22s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup { from { transform: translateY(100%); } }
.sheet-handle {
  width: 38px; height: 4px; background: var(--line);
  border-radius: 99px; margin: 0 auto 14px;
}
.sheet h3 {
  font-family: var(--mono);
  font-size: 15px;
  margin-bottom: 4px;
}
.sheet .sub { color: var(--ink-faint); font-size: 13px; font-family: var(--mono); margin-bottom: 6px; }

@media (min-width: 600px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 12px; border-bottom: 1px solid var(--line); }
}

/* recipe builder rows */
.ri-row {
  display: flex; gap: 8px; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.ri-row .ri-name { flex: 1; font-size: 13px; }
.ri-row input { width: 88px; text-align: right; font-size: 14px; padding: 8px; }
.ri-row .ri-del { background: none; border: none; color: var(--ink-faint); font-size: 18px; cursor: pointer; }
.ri-macros {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-dim);
  background: var(--panel-2);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 12px;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px;
}
.ri-macros b { color: var(--acc); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px 24px;
}
.login-card .brand { font-size: 22px; margin-bottom: 4px; }
.login-card .tag { color: var(--ink-faint); font-family: var(--mono); font-size: 12px; margin-bottom: 22px; }

.toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--mono); font-size: 13px;
  padding: 10px 16px; border-radius: var(--radius);
  z-index: 100;
  animation: fade 0.2s ease;
  max-width: 90vw;
}
.toast.err { border-color: var(--over); color: var(--over); }

.add-fab {
  position: fixed;
  right: 16px;
  bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 25;
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--acc);
  color: #08210b;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(125,255,138,0.25);
  display: flex; align-items: center; justify-content: center;
}

.muted { color: var(--ink-faint); }
.hidden { display: none !important; }
