* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #0a0f0a; --card: #141b14; --line: #223022; --text: #e8f0e8; --muted: #8aa08a;
  --accent: #4ade80; --amber: #fbbf24; --red: #f87171;
}
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
#app { max-width: 430px; margin: 0 auto; min-height: 100vh; position: relative; padding-bottom: 130px; }
.screen { padding: 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h1.title { font-size: 22px; margin: 24px 0 16px; text-align: center; }

/* PIN */
.pin-wrap { display: flex; flex-direction: column; align-items: center; padding-top: 10vh; gap: 8px; }
.logo { font-size: 56px; }
.pin-dots { display: flex; gap: 14px; margin: 18px 0 8px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--accent); border-color: var(--accent); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px);} 50% { transform: translateX(8px);} 75% { transform: translateX(-5px);} }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; margin-top: 12px; }
.keypad button {
  height: 72px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font-size: 26px; cursor: pointer;
}
.keypad button:active { background: var(--line); }

/* Profile picker */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.profile-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 22px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; min-height: 130px; justify-content: center;
}
.profile-card .pav { font-size: 44px; }
.profile-card.add { border-style: dashed; color: var(--muted); }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form input, .form select, textarea {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px; font-size: 16px; width: 100%;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.avatar-row { display: flex; flex-wrap: wrap; gap: 8px; }
.avatar-row button { font-size: 24px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.avatar-row button.on { border-color: var(--accent); background: #1a2e1f; }
.btn { border-radius: 14px; padding: 14px; font-size: 16px; font-weight: 600; border: none; cursor: pointer; }
.btn.primary { background: var(--accent); color: #052e12; }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }

/* Topbar */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.topbar-mid { text-align: center; }
.avatar-btn { font-size: 30px; background: var(--card); border: 1px solid var(--line); border-radius: 50%; width: 48px; height: 48px; cursor: pointer; }
.icon-btn { font-size: 20px; background: none; border: none; cursor: pointer; width: 44px; height: 44px; }

/* Ring */
.ring-wrap { position: relative; width: 210px; margin: 8px auto; }
.ring { width: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 14; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 14; stroke-linecap: round;
  stroke-dasharray: 540.35; stroke-dashoffset: 540.35; transition: stroke-dashoffset .8s ease, stroke .3s; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-kcal { font-size: 40px; font-weight: 700; }

/* Macros */
.macros { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin: 10px 0 18px; }
.macro { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.macro .bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.macro .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .6s; }
.macro .lab { font-size: 11px; color: var(--muted); }
.macro .val { font-size: 13px; font-weight: 600; margin-top: 2px; }

/* Meals */
.meal-block { margin-bottom: 14px; }
.meal-block h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.entry { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; margin-bottom: 8px; }
.entry img { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; }
.entry .e-main { flex: 1; min-width: 0; }
.entry .e-names { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .e-kcal { font-weight: 700; white-space: nowrap; }
.entry .e-del { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 8px; }
.empty-hint { text-align: center; color: var(--muted); padding: 30px 20px; }

/* FABs */
.fab-row { position: fixed; bottom: calc(64px + env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; gap: 12px; justify-content: center; z-index: 5; }
.fab { border-radius: 999px; padding: 15px 26px; font-size: 16px; font-weight: 700; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
.fab.primary { background: var(--accent); color: #052e12; border: none; }

/* Tabbar */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; max-width: 430px; margin: 0 auto; display: flex;
  background: rgba(10,15,10,.95); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
.tabbar button { flex: 1; background: none; border: none; color: var(--muted); font-size: 14px; font-weight: 600; padding: 14px; cursor: pointer; }
.tabbar button.on { color: var(--accent); }

/* Overlay + confirm card */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.card { background: var(--card); border-radius: 22px 22px 0 0; padding: 18px; width: 100%; max-width: 430px; max-height: 88vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.card h2 { font-size: 18px; }
#confirm-photo-wrap img { width: 100%; max-height: 200px; object-fit: cover; border-radius: 14px; }
.ai-item { border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.ai-item .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.ai-item .nm { font-weight: 600; outline: none; flex: 1; }
.ai-item .nm:focus { border-bottom: 1px dashed var(--accent); }
.ai-item .kc { font-weight: 700; white-space: nowrap; }
.ai-item .sub { font-size: 12px; color: var(--muted); }
.pills { display: flex; gap: 6px; }
.pills button { flex: 1; border-radius: 999px; border: 1px solid var(--line); background: none; color: var(--text); padding: 7px 0; font-size: 13px; cursor: pointer; }
.pills button.on { background: var(--accent); color: #052e12; border-color: var(--accent); font-weight: 700; }
.ai-item .rm { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 4px 8px; }
.meal-select { display: flex; gap: 6px; }
.meal-select button { flex: 1; border-radius: 10px; border: 1px solid var(--line); background: none; color: var(--muted); padding: 9px 0; font-size: 12px; cursor: pointer; }
.meal-select button.on { color: var(--accent); border-color: var(--accent); font-weight: 700; }
.confirm-total { display: flex; justify-content: space-between; font-size: 16px; padding: 4px 2px; }
.spinner { text-align: center; padding: 26px; color: var(--muted); }
.spinner::before { content: "🥢"; display: block; font-size: 34px; animation: bob 1s infinite alternate; }
@keyframes bob { to { transform: translateY(-8px) rotate(12deg); } }
.err { color: var(--red); text-align: center; padding: 8px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 8px 14px; font-size: 13px; cursor: pointer; }

/* Trends */
.seg { display: flex; background: var(--card); border-radius: 12px; padding: 4px; margin: 10px 0; border: 1px solid var(--line); }
.seg button { flex: 1; border: none; background: none; color: var(--muted); padding: 10px; border-radius: 9px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--accent); color: #052e12; }
.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; text-align: center; }
.stat-num { font-size: 28px; font-weight: 700; color: var(--accent); }
.chart { position: relative; display: flex; align-items: flex-end; gap: 3px; height: 220px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 14px 28px; }
.chart .bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.chart .bar-col i { display: block; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.chart .bar-col i.over { background: var(--red); }
.chart .bar-col .dlab { position: absolute; bottom: -20px; left: 0; right: 0; text-align: center; font-size: 9px; color: var(--muted); }
.chart .goal-line { position: absolute; left: 10px; right: 10px; border-top: 2px dashed var(--amber); }
