/* ===== 主題色票 ===== */
:root {
  --bg: #faf7ff; --surface: #ffffff; --surface-2: #f3eefc; --text: #332c3d; --muted: #857a96;
  --primary: #a78bfa; --primary-strong: #7c5cd6; --primary-soft: #ece4fb;
  --accent: #7cc7a1; --accent-soft: #e2f5ea;
  --border: #e6def4; --shadow: 0 6px 20px rgba(90, 60, 140, .10);
  --ok: #3f9c6b; --warn: #b8791a; --err: #d9534f; --info: #6b8fbf;
  --protein: #d9648a; --fat: #e39a2e; --carbs: #4f8fd3;
  --radius: 20px; --radius-s: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17131f; --surface: #221c2e; --surface-2: #2c2539; --text: #f0eaf7; --muted: #a79cb8;
    --primary: #b39ddb; --primary-strong: #c9b6f0; --primary-soft: #3b2f55;
    --accent: #7cc7a1; --accent-soft: #23402f;
    --border: #3a3149; --shadow: 0 6px 20px rgba(0, 0, 0, .35);
    --ok: #6fcf97; --warn: #e6b04a; --err: #ff7b76; --info: #8fb3e6;
    --protein: #d9648a; --fat: #c4841c; --carbs: #4a8fd0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17131f; --surface: #221c2e; --surface-2: #2c2539; --text: #f0eaf7; --muted: #a79cb8;
  --primary: #b39ddb; --primary-strong: #c9b6f0; --primary-soft: #3b2f55;
  --accent: #7cc7a1; --accent-soft: #23402f;
  --border: #3a3149; --shadow: 0 6px 20px rgba(0, 0, 0, .35);
  --ok: #6fcf97; --warn: #e6b04a; --err: #ff7b76; --info: #8fb3e6;
  --protein: #d9648a; --fat: #c4841c; --carbs: #4a8fd0;
  color-scheme: dark;
}

/* ===== 基本 ===== */
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* 蓋過自己設的 display:flex 之類, 讓 hidden 屬性永遠有效 */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 16px; line-height: 1.55; min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
body.bare { padding-bottom: 0; display: flex; align-items: center; justify-content: center; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.5rem; margin: .2em 0 .4em; }
h2 { font-size: 1.05rem; margin: 0 0 .6em; }
p { margin: .4em 0; }
b { font-weight: 700; }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 6px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.mt-s { margin-top: .4rem; }
.text-warn { color: var(--warn); }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.page { max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.bare-wrap { width: min(440px, 100% - 32px); margin: 24px auto; position: relative; }
.big-emoji { font-size: 3rem; line-height: 1; margin-bottom: .3rem; }

/* ===== 頂欄 / 底欄 ===== */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: .4rem; font-weight: 700; }
.brand-icon { font-size: 1.4rem; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.user-chip { display: inline-flex; align-items: center; gap: .35rem; padding: 4px 10px 4px 6px; border-radius: 999px; background: var(--surface); border: 2px solid var(--chip, var(--primary)); font-size: .9rem; }
.user-chip.static { border-width: 1.5px; padding: 2px 8px 2px 4px; font-size: .85rem; }
.user-emoji { font-size: 1.1rem; }
.theme-toggle { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; width: 38px; height: 38px; font-size: 1.1rem; cursor: pointer; display: grid; place-items: center; }
.theme-toggle.floating { position: absolute; right: 0; top: -8px; }
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border); padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.bottomnav a { display: flex; flex-direction: column; align-items: center; font-size: .72rem; color: var(--muted); padding: 2px 18px; border-radius: 12px; }
.bottomnav a span { font-size: 1.35rem; line-height: 1.2; }
.bottomnav a.active { color: var(--primary-strong); background: var(--primary-soft); }

/* ===== 卡片 / 按鈕 / 表單 ===== */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.card-head h2 { margin: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 9px 18px; font: inherit; font-weight: 500; cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary-strong); border-color: var(--primary-strong); color: #fff; font-weight: 700; box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 45%, transparent); }
.btn.primary:disabled { opacity: .5; box-shadow: none; cursor: not-allowed; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #1b1526; } }
:root[data-theme="dark"] .btn.primary { color: #1b1526; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.btn.small { padding: 5px 12px; font-size: .85rem; }
.btn.big { padding: 13px 20px; font-size: 1.05rem; }
.input { width: 100%; border: 1.5px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: var(--radius-s); padding: 10px 12px; font: inherit; }
.input:focus { outline: none; border-color: var(--primary); }
textarea.input { resize: vertical; }
.field { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--muted); flex: 1; }
.field.small-w { flex: 0 0 90px; }
.alert { border-radius: var(--radius-s); padding: 10px 14px; font-size: .92rem; }
.alert.error { background: color-mix(in srgb, var(--err) 14%, var(--surface)); color: var(--err); }
.alert.ok { background: var(--accent-soft); color: var(--ok); }
.details summary { cursor: pointer; }
.details .input { margin-top: .5rem; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 500; background: var(--surface-2); color: var(--muted); }
.pill.running { background: color-mix(in srgb, var(--info) 18%, var(--surface)); color: var(--info); }
.pill.done { background: var(--accent-soft); color: var(--ok); }
.pill.error { background: color-mix(in srgb, var(--err) 14%, var(--surface)); color: var(--err); }
.pill.running::before { content: ""; display: inline-block; width: .6em; height: .6em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; margin-right: .35em; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 首頁 ===== */
.hero { border-top: 5px solid var(--chip, var(--primary)); }
.hero-head { display: flex; justify-content: space-between; align-items: flex-start; }
.hero-kcal { font-size: 2rem; line-height: 1.1; }
.hero-kcal.small { font-size: 1.3rem; }
.progress { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: .6rem; }
.progress.thin { height: 7px; margin-top: .3rem; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--primary)); border-radius: 999px; transition: width .4s ease; }
.progress.over span { background: linear-gradient(90deg, var(--warn), var(--err)); }
.minis { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .6rem; font-size: .85rem; color: var(--muted); }
.minis b { color: var(--text); }
.pick-row { display: flex; gap: .8rem; }
.pick-btn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: 16px 8px; border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface-2); cursor: pointer; font-weight: 500; }
.pick-btn:active { border-color: var(--primary); }
.pick-icon { font-size: 2rem; line-height: 1; }
.preview { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.preview img { width: 100%; max-height: 360px; object-fit: contain; display: block; }
.preview-clear { position: absolute; top: 8px; right: 8px; border: none; background: rgba(0,0,0,.55); color: #fff; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 1rem; }
.preview-meta { padding: 6px 12px; }
.upload-status { text-align: center; }
.meal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.meal-card { border-radius: var(--radius-s); background: var(--surface-2); padding: 8px; }
.meal-row { display: flex; align-items: center; gap: .8rem; }
.meal-list.compact .meal-row { padding: 0; }
.thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: var(--border); flex: none; }
.meal-list.compact .thumb { width: 44px; height: 44px; }
.meal-info { flex: 1; min-width: 0; }
.meal-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-kcal { text-align: right; flex: none; }
.meal-kcal b { font-size: 1.15rem; }
.meal-kcal small { display: block; color: var(--muted); font-size: .7rem; }
.partner { border-top: 5px solid var(--chip, var(--accent)); }

/* ===== 三大營養素條 (dataviz: 固定色、2px 間隔、文字用文字色) ===== */
.macros { margin-top: .8rem; }
.macro-bar { display: flex; gap: 2px; height: 14px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.macro-bar.empty { opacity: .5; }
.macro-bar .seg { display: block; height: 100%; flex: 0 0 auto; min-width: 0; }
.seg.protein, .dot.protein { background: var(--protein); }
.seg.fat, .dot.fat { background: var(--fat); }
.seg.carbs, .dot.carbs { background: var(--carbs); }
.macro-legend { list-style: none; display: flex; gap: 1rem; flex-wrap: wrap; margin: .5rem 0 0; padding: 0; font-size: .85rem; color: var(--muted); }
.macro-legend b { color: var(--text); margin: 0 .2em; }
.macro-legend small { font-size: .75rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35em; vertical-align: -1px; }

/* ===== 分析頁 ===== */
.photo-card { padding: 0; overflow: hidden; }
.photo { width: 100%; max-height: 420px; object-fit: cover; display: block; }
.photo-meta { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px 4px; }
.desc { padding: 0 16px 12px; margin: 0; font-size: 1.25rem; line-height: 1.4; }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; font-size: .86rem; max-height: 60vh; overflow: auto; }
.log li { display: flex; gap: .5rem; padding: 4px 6px; border-radius: 8px; color: var(--muted); animation: fadein .25s ease; }
.log li .t { flex: none; font-variant-numeric: tabular-nums; opacity: .6; font-size: .75rem; padding-top: 2px; width: 62px; }
.log li .m { flex: 1; word-break: break-word; }
.log li .m a { color: var(--info); text-decoration: underline; }
.log li.step { color: var(--text); font-weight: 700; margin-top: .5rem; background: var(--surface-2); }
.log li.ok { color: var(--ok); }
.log li.warn { color: var(--warn); }
.log li.error { color: var(--err); font-weight: 500; }
.log li.live::after { content: ""; width: .7em; height: .7em; border: 2px solid var(--info); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; margin-top: 4px; flex: none; }
#log-card.collapsed .log { display: none; }
@keyframes fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.result-hero { display: flex; align-items: baseline; gap: .4rem; }
.result-hero b { font-size: 2.6rem; line-height: 1; }
.items { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: .88rem; }
.items th, .items td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.items th { color: var(--muted); font-weight: 500; font-size: .78rem; }
.items td.num, .items th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.items .item-name { font-weight: 500; }
.items .item-sub { color: var(--muted); font-size: .78rem; }
.items .item-sub a { color: var(--info); text-decoration: underline; }
.badge { display: inline-block; border-radius: 6px; padding: 1px 6px; font-size: .72rem; font-weight: 500; vertical-align: 1px; }
.badge.official { background: var(--accent-soft); color: var(--ok); }
.badge.fda { background: color-mix(in srgb, var(--info) 18%, var(--surface)); color: var(--info); }
.badge.off { background: color-mix(in srgb, var(--carbs) 18%, var(--surface)); color: var(--carbs); }
.badge.estimate { background: var(--surface-2); color: var(--muted); }
.badge.cache { background: var(--primary-soft); color: var(--primary-strong); }
.comment-card { background: linear-gradient(135deg, var(--accent-soft), var(--surface)); }
.ai-comment { display: flex; gap: .8rem; align-items: flex-start; }
.ai-avatar { font-size: 2rem; line-height: 1; flex: none; }
.ai-comment p { margin: 0 0 .4em; white-space: pre-line; }
.tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .4rem; }
.tags span { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: .78rem; }
.tags .score { background: var(--primary-soft); border-color: transparent; color: var(--primary-strong); font-weight: 700; }
.talk { list-style: none; margin: 0 0 .8rem; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.talk li { display: flex; gap: .6rem; align-items: flex-start; }
.talk .who { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 2px solid var(--chip, var(--border)); font-size: 1.2rem; }
.talk .bubble { background: var(--surface-2); border-radius: 4px 16px 16px 16px; padding: 8px 12px; max-width: 85%; }
.talk .bubble .meta { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.talk .bubble .meta button { border: none; background: none; color: var(--muted); cursor: pointer; font: inherit; font-size: .72rem; text-decoration: underline; padding: 0 0 0 .5em; }
.talk li.mine { flex-direction: row-reverse; }
.talk li.mine .bubble { border-radius: 16px 4px 16px 16px; background: var(--primary-soft); }
.talk-form { display: flex; gap: .5rem; }
.talk-form .input { flex: 1; }
.talk-empty { color: var(--muted); font-size: .88rem; }

/* ===== 登入 / 身分 / 紀錄 / 設定 ===== */
.login-card .input { text-align: center; font-size: 1.1rem; letter-spacing: .1em; }
.identity-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin-top: 1rem; }
.identity-card { display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: 18px 8px; border: 2px solid var(--border); border-radius: var(--radius); background: var(--surface-2); cursor: pointer; font: inherit; color: inherit; }
.identity-card:hover, .identity-card.current { border-color: var(--chip); box-shadow: 0 0 0 4px color-mix(in srgb, var(--chip) 25%, transparent); }
.identity-emoji { font-size: 3rem; line-height: 1; }
.identity-name { font-weight: 700; font-size: 1.1rem; }
.tabs { display: flex; gap: .5rem; margin-bottom: .8rem; }
.tab { flex: 1; text-align: center; padding: 8px; border-radius: 999px; border: 2px solid var(--border); background: var(--surface-2); font-weight: 500; }
.tab.active { border-color: var(--chip); background: color-mix(in srgb, var(--chip) 18%, var(--surface)); }
.month-nav { display: flex; align-items: center; justify-content: space-between; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; }
.day .meal-list { margin-top: .6rem; }
.seg-control { display: flex; gap: .4rem; }
.seg-control button { flex: 1; border: 1.5px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 8px; font: inherit; cursor: pointer; }
.seg-control button.active { border-color: var(--primary); background: var(--primary-soft); font-weight: 700; }
.user-fields { border: 1.5px solid var(--border); border-left: 5px solid var(--chip); border-radius: var(--radius-s); padding: 8px 12px 12px; }
.user-fields legend { padding: 0 .4em; font-weight: 700; }
table.plain { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.plain th, table.plain td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.plain th { color: var(--muted); font-weight: 500; font-size: .78rem; }
.ok-dot { color: var(--ok); }
@media (max-width: 420px) { .items .col-macro { display: none; } .macro-legend { gap: .6rem; } }

/* 品項「為什麼這樣估」 */
.items .why { margin-top: 4px; font-size: .78rem; color: var(--muted); }
.items .why summary { cursor: pointer; color: var(--info); }
.items .why p { margin: .3em 0 0; white-space: pre-line; line-height: 1.45; }

/* 分析頁的區塊包在 #meal-page 裡, 也要有間距 */
#meal-page { display: flex; flex-direction: column; gap: 14px; }

/* ===== 今日目標進度條 ===== */
.targets { display: flex; flex-direction: column; gap: 10px; margin-top: .9rem; }
.trow { --c: var(--primary); }
.trow.protein { --c: var(--protein); } .trow.fat { --c: var(--fat); } .trow.carbs { --c: var(--carbs); }
.trow.fiber { --c: var(--accent); } .trow.sugar, .trow.sodium { --c: var(--info); }
.tlabel { display: flex; align-items: baseline; gap: .35rem; font-size: .85rem; }
.tlabel b { margin-left: auto; font-size: 1rem; }
.tbar { position: relative; display: flex; height: 10px; border-radius: 6px; background: color-mix(in srgb, var(--c) 18%, var(--surface-2)); overflow: hidden; margin-top: 3px; }
.tfill { display: block; height: 100%; background: var(--c); border-radius: 6px 0 0 6px; }
.tover { display: block; height: 100%; background: repeating-linear-gradient(135deg, var(--err) 0 4px, color-mix(in srgb, var(--err) 60%, transparent) 4px 8px); margin-left: 2px; }
.trow.over .tfill { background: var(--err); }
.thint { font-size: .74rem; color: var(--muted); margin-top: 2px; }
.thint.over { color: var(--err); font-weight: 500; }
.thint.done { color: var(--ok); }
.thint.near { color: var(--warn); }

/* ===== 表情 / 留言 / 分享 ===== */
.social { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; margin-top: 8px; padding-top: 6px; border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
.react-area { position: relative; display: flex; align-items: center; gap: .25rem; flex: 1; min-width: 0; }
.react-summary { display: inline-flex; gap: .2rem; flex-wrap: wrap; }
.rchip, .react, .sbtn { border: 1px solid transparent; background: var(--surface); border-radius: 999px; padding: 3px 8px; font: inherit; font-size: .88rem; cursor: pointer; color: var(--text); line-height: 1.2; display: inline-flex; align-items: center; gap: .2rem; }
.rchip.mine { background: var(--primary-soft); border-color: var(--primary); }
.rchip .cnt, .sbtn .cnt { font-size: .74rem; font-weight: 600; color: var(--muted); }
.sbtn .cnt:empty { display: none; }
.sbtn { color: var(--muted); }
.sbtn:hover, .rchip:hover { border-color: var(--border); }
.react-open .plus { font-size: .7rem; font-weight: 700; margin-left: -1px; }
.react-pop { position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 30; display: flex; gap: 2px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; box-shadow: var(--shadow); animation: fadein .15s ease; }
.react-opt { border: 2px solid transparent; background: transparent; border-radius: 50%; width: 38px; height: 38px; font-size: 1.35rem; cursor: pointer; line-height: 1; padding: 0; transition: transform .1s ease; }
.react-opt:hover { transform: scale(1.25); }
.react-opt.mine { border-color: var(--primary); background: var(--primary-soft); }
.react.static { cursor: default; background: var(--surface-2); }
.react.static .cnt { font-size: .75rem; font-weight: 600; color: var(--muted); }
.inline-comments { flex-basis: 100%; padding: 6px 2px 4px; }
.inline-comments .talk { margin-bottom: .5rem; }
.inline-comments .talk-form .input { padding: 7px 10px; font-size: .9rem; }
.photo-social { padding: 0 10px 8px; }
.photo-social .social { margin-top: 0; border-top: none; padding-top: 0; }
.share-page .topbar { justify-content: space-between; }
.share-reacts { display: flex; gap: .4rem; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: .9rem; z-index: 50; box-shadow: var(--shadow); animation: fadein .2s ease; }

/* ===== 品項清單 (改成堆疊卡片, 手機不會擠) ===== */
.item-list { display: flex; flex-direction: column; gap: 8px; margin-top: 1rem; }
.item { background: var(--surface-2); border-radius: var(--radius-s); padding: 10px 12px; }
.item-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.item-head .item-name { font-weight: 600; flex: 1 1 60%; min-width: 0; }
.item-badges { display: inline-flex; gap: .25rem; flex-wrap: wrap; justify-content: flex-end; }
.item-stats { display: flex; align-items: baseline; gap: .35rem; margin-top: 4px; font-variant-numeric: tabular-nums; }
.item-stats b { font-size: 1.2rem; }
.item-stats small { color: var(--muted); font-size: .75rem; }
.item-stats .pfc { margin-left: auto; font-size: .85rem; color: var(--text); display: inline-flex; align-items: center; gap: .15rem; }
.item-stats .pfc .dot { margin: 0 2px 0 8px; }
.item-stats .pfc .dot:first-child { margin-left: 0; }
.item .item-sub { margin-top: 4px; color: var(--muted); font-size: .8rem; line-height: 1.45; }
.item .item-sub a { color: var(--info); text-decoration: underline; }
.item .why { margin-top: 6px; font-size: .78rem; color: var(--muted); }
.item .why summary { cursor: pointer; color: var(--info); }
.item .why p { margin: .3em 0 0; white-space: pre-line; line-height: 1.45; }
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, var(--surface)); color: var(--warn); }

/* 來源說明 */
.legend { list-style: none; margin: .9rem 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: .78rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .4rem; }
.legend .badge { flex: none; }
@media (max-width: 400px) { .legend { grid-template-columns: 1fr; } }

/* 用餐時間欄位在窄螢幕不要撐出去 */
.details .input, input[type="datetime-local"].input { display: block; width: 100%; max-width: 100%; min-width: 0; -webkit-appearance: none; appearance: none; }

/* ===== 來源 ? 說明、時間編輯、標籤裝飾 ===== */
.help { border: 1px solid var(--border); background: var(--surface); color: var(--muted); width: 18px; height: 18px; border-radius: 50%; font-size: .7rem; font-weight: 700; line-height: 1; cursor: pointer; padding: 0; vertical-align: 1px; }
.help:hover { color: var(--primary-strong); border-color: var(--primary); }
.item-head { position: relative; }
.help-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; width: min(320px, 90vw); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-s); box-shadow: var(--shadow); padding: 8px 10px; font-size: .78rem; color: var(--muted); display: flex; flex-direction: column; gap: 6px; animation: fadein .15s ease; }
.help-pop > div { display: flex; gap: .5rem; align-items: flex-start; }
.help-pop > div.cur { color: var(--text); font-weight: 500; }
.help-pop .badge { flex: none; margin-top: 1px; }
.icon-btn { border: none; background: transparent; cursor: pointer; font-size: .95rem; padding: 0 4px; line-height: 1; opacity: .7; }
.icon-btn:hover { opacity: 1; }
.meal-when { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.time-form { display: flex; gap: .4rem; align-items: center; flex-basis: 100%; margin-top: 6px; }
.time-form .input { flex: 1; padding: 6px 10px; font-size: .9rem; }
.desc { font-weight: 700; color: var(--text); }
.photo-card .desc { padding-top: 4px; }

.ai-comment p.quote { font-size: 1rem; line-height: 1.6; }
.ai-comment p.note { color: var(--muted); font-size: .9rem; }
.tags .tag { position: relative; }
.tags .tag.good, .tags .score.good {
  border: none; color: #5a4100; font-weight: 600;
  background: linear-gradient(110deg, #f7d774 0%, #fff1b3 35%, #f4c95d 55%, #fff5c2 75%, #f2c14e 100%);
  background-size: 220% 100%; animation: shimmer 2.8s linear infinite;
  box-shadow: 0 0 0 1px rgba(214, 164, 32, .35), 0 2px 8px rgba(240, 190, 60, .35);
}
.tags .tag.good::before { content: "✨"; margin-right: 2px; font-size: .75em; }
.tags .tag.bad, .tags .score.bad {
  background: color-mix(in srgb, var(--err) 12%, var(--surface)); color: var(--err);
  border: 1px dashed color-mix(in srgb, var(--err) 55%, transparent); font-weight: 500;
}
.tags .tag.bad::before { content: "▲"; margin-right: 3px; font-size: .6em; vertical-align: 2px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -20% 0; } }
@media (prefers-reduced-motion: reduce) { .tags .tag.good, .tags .score.good { animation: none; } }
