:root {
  --bg: #0d0f14;
  --bg-elev: #161a23;
  --bg-elev2: #1d222e;
  --line: #2a3140;
  --text: #eef1f6;
  --text-dim: #8b94a7;
  --accent: #5b8cff;       /* 中性藍 */
  --good: #2fd27a;         /* 達標綠 */
  --warn: #ffb020;         /* 不足橘 */
  --bad: #ff5d6c;          /* 超標紅 */
  --ring-track: #262c3a;
  --radius: 18px;
  --mono: "SF Mono", "JetBrains Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", Roboto, sans-serif;
}

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

/* hidden 屬性必須蓋過下面任何 display 規則(否則 overlay 會一直擋住點擊) */
[hidden] { display: none !important; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1; /* tabular figures,數字對齊不跳 */
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.screen { max-width: 560px; margin: 0 auto; padding: 20px 18px 60px; }

/* ---------- Auth ---------- */
#auth-screen {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
}
.auth-card {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 26px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 28px; letter-spacing: 2px; }
.brand.small { font-weight: 600; letter-spacing: 1px; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 12px var(--good);
}
.brand-sub { color: var(--text-dim); margin: 10px 0 22px; font-size: 14px; }

.tabs { display: flex; gap: 6px; background: var(--bg-elev2); padding: 4px; border-radius: 12px; margin-bottom: 20px; }
.tab {
  flex: 1; padding: 10px; border: none; border-radius: 9px;
  background: transparent; color: var(--text-dim);
  font-size: 15px; font-weight: 600; cursor: pointer; transition: .15s;
  font-family: var(--sans);
}
.tab.active { background: var(--accent); color: #fff; }

.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 7px; }
.field input {
  width: 100%; padding: 13px 14px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 11px; color: var(--text); font-size: 16px;
  font-family: var(--sans); outline: none; transition: border-color .15s;
}
.field input:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%; padding: 14px; margin-top: 6px;
  background: var(--accent); color: #fff; border: none;
  border-radius: 12px; font-size: 16px; font-weight: 700;
  cursor: pointer; transition: filter .15s; font-family: var(--sans);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.auth-error { color: var(--bad); font-size: 14px; margin-top: 12px; min-height: 18px; text-align: center; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.who { color: var(--text-dim); font-size: 14px; }
.ghost-btn {
  background: transparent; border: 1px solid var(--line);
  color: var(--text-dim); padding: 7px 12px; border-radius: 9px;
  font-size: 14px; cursor: pointer; font-family: var(--sans);
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-dim); }

/* ---------- Hero:吉祥物 ---------- */
.hero-mascot { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }

.mascot-card {
  position: relative; background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 16px 20px;
  display: flex; flex-direction: column; align-items: center;
  /* 各狀態的代表色,由 JS 切換 class 控制 */
  --fill: var(--accent); --glow: transparent;
  transition: box-shadow .4s;
}
.mascot-card.state-blue  { --fill: #5b8cff; }
.mascot-card.state-green { --fill: var(--good);  --glow: var(--good); }
.mascot-card.state-amber { --fill: var(--warn);  --glow: var(--warn); }
.mascot-card.state-red   { --fill: var(--bad);   --glow: var(--bad);  }
.mascot-card.state-green { box-shadow: 0 0 0 1px var(--glow), 0 0 26px -8px var(--glow); }
.mascot-card.state-red   { box-shadow: 0 0 0 1px var(--glow), 0 0 30px -6px var(--glow); }

.mascot-wrap { width: 100%; max-width: 230px; }
.mascot { width: 100%; height: auto; overflow: visible; }
.mascot-body { fill: var(--bg-elev2); stroke: var(--line); stroke-width: 3; transition: fill .4s; }
.liquid { fill: var(--fill); opacity: .92; transition: fill .5s; animation: bob 3.2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(2.5px); } }
.eye { fill: #11151d; }
.eye-line { fill: none; stroke: #11151d; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.mouth { fill: none; stroke: #11151d; stroke-width: 4; stroke-linecap: round; }
.cheek { fill: #ff8aa0; opacity: .55; }

/* 被塞爆:整隻鼓一下 + 抖動 */
.mascot-card.state-red .mascot { animation: stuffed 1.6s ease-in-out infinite; }
@keyframes stuffed {
  0%,100% { transform: scale(1.04) rotate(0deg); }
  25% { transform: scale(1.06) rotate(-1.5deg); }
  75% { transform: scale(1.06) rotate(1.5deg); }
}
/* 溢出水滴 */
.drips .drip { fill: var(--fill); opacity: 0; }
.mascot-card.state-red .drips .drip { animation: drip 1.4s ease-in infinite; }
.drips .d2 { animation-delay: .45s; }
.drips .d3 { animation-delay: .9s; }
@keyframes drip {
  0% { opacity: 0; transform: translateY(0) scale(.7); }
  20% { opacity: .95; }
  100% { opacity: 0; transform: translateY(150px) scale(1); }
}

.mascot-readout { text-align: center; margin-top: 6px; }
.big-num { font-family: var(--mono); font-weight: 700; line-height: 1; }
.big-num #cal-value { font-size: 44px; }
.big-unit { font-size: 16px; color: var(--text-dim); margin-left: 6px; }
.mascot-note { font-family: var(--mono); font-size: 14px; color: var(--text-dim); margin-top: 8px; min-height: 18px; }
.mascot-card.state-green .mascot-note { color: var(--good); }
.mascot-card.state-amber .mascot-note { color: var(--warn); }
.mascot-card.state-red .mascot-note { color: var(--bad); font-weight: 700; }

.setup-cta {
  margin-top: 14px; width: 100%; padding: 12px;
  background: var(--bg-elev2); border: 1px dashed var(--accent);
  color: var(--accent); border-radius: 12px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: var(--sans);
}
.setup-cta:hover { background: rgba(91,140,255,.1); }

/* 蛋白條 */
.pro-bar-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.pro-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.pro-label { font-size: 14px; color: var(--text-dim); }
.pro-readout { font-family: var(--mono); font-size: 16px; }
.pro-readout b { font-size: 20px; }
.pro-readout span { color: var(--text-dim); }
.pro-track { height: 12px; background: var(--ring-track); border-radius: 8px; overflow: hidden; }
.pro-fill {
  height: 100%; width: 0%; border-radius: 8px; background: var(--bad);
  transition: width .7s cubic-bezier(.4,0,.2,1), background .4s;
}
.pro-bar-card.met .pro-fill { background: var(--good); }
.pro-bar-card.met .mascot-note { color: var(--good); }

.alert {
  background: rgba(255,176,32,.12); border: 1px solid rgba(255,176,32,.4);
  color: var(--warn); padding: 12px 14px; border-radius: 12px;
  font-size: 14px; margin-bottom: 16px; font-weight: 600;
}

/* ---------- Actions ---------- */
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 26px; }
.action {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--text); font-size: 13px; font-weight: 600;
  font-family: var(--sans); transition: .15s;
}
.action:hover { border-color: var(--accent); transform: translateY(-1px); }
.action-icon { font-size: 24px; }

/* ---------- Entry list ---------- */
.list-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.list-head h2 { font-size: 18px; }
.list-date { color: var(--text-dim); font-size: 13px; font-family: var(--mono); }
.entry-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.entry {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px;
}
.entry-badge { font-size: 18px; }
.entry-main { flex: 1; min-width: 0; }
.entry-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; font-family: var(--mono); }
.entry-macro { text-align: right; font-family: var(--mono); }
.entry-cal { font-size: 15px; font-weight: 700; }
.entry-pro { font-size: 12px; color: var(--good); }
.entry-del {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 4px 6px; border-radius: 8px;
}
.entry-del:hover { color: var(--bad); background: rgba(255,93,108,.1); }
.empty-hint { color: var(--text-dim); font-size: 14px; text-align: center; padding: 26px 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  padding: 0;
}
.modal {
  width: 100%; max-width: 560px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 20px 20px 0 0; padding: 22px 20px 30px;
  max-height: 88dvh; overflow-y: auto;
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-size: 18px; }
.preview-img { width: 100%; border-radius: 12px; margin-bottom: 16px; max-height: 240px; object-fit: cover; }
.analyzing { text-align: center; color: var(--text-dim); padding: 30px 0; }
.spinner {
  width: 34px; height: 34px; border: 3px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  margin: 0 auto 14px; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.items-hint { font-size: 12px; color: var(--text-dim); margin-bottom: 14px; }
.fav-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
}
.fav-item .fav-info { flex: 1; }
.fav-item .fav-name { font-weight: 600; font-size: 15px; }
.fav-item .fav-macro { font-family: var(--mono); font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.fav-add { background: var(--good); color: #04210f; border: none; border-radius: 9px; padding: 8px 14px; font-weight: 700; cursor: pointer; font-family: var(--sans); }
.fav-del { background: transparent; border: none; color: var(--text-dim); cursor: pointer; font-size: 16px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.pf-preview {
  margin-top: 14px; padding: 14px 16px; border-radius: 12px;
  background: var(--bg-elev2); border: 1px solid var(--accent);
}
.pf-tdee { font-family: var(--mono); font-size: 18px; }
.pf-tdee b { font-size: 24px; color: var(--accent); }
.pf-detail { font-size: 13px; color: var(--text-dim); margin-top: 6px; line-height: 1.5; font-family: var(--mono); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); background: var(--bg-elev2);
  border: 1px solid var(--line); color: var(--text);
  padding: 12px 18px; border-radius: 12px; font-size: 14px;
  z-index: 100; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.toast.bad { border-color: var(--bad); color: var(--bad); }
