:root {
  --ink: #18211c;
  --muted: #68736c;
  --paper: #f8f5ef;
  --card: #fffdf9;
  --line: #e3ded4;
  --green: #215c43;
  --green-dark: #174330;
  --lime: #dbe9a9;
  --coral: #f17a5c;
  --shadow: 0 18px 50px rgba(43, 52, 44, .11);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: radial-gradient(circle at 80% 5%, #eef1d7 0, transparent 26rem), var(--paper); }
button { color: inherit; font: inherit; }
button:focus-visible { outline: 3px solid rgba(33, 92, 67, .3); outline-offset: 3px; }
.app-shell { width: min(100%, 760px); min-height: 100dvh; margin: 0 auto; }
.topbar { height: 76px; padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.settings-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: rgba(255,255,255,.72); color: var(--green); font-size: 17px; cursor: pointer; }
.brand { border: 0; background: none; padding: 0; display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 800; cursor: pointer; }
.brand-mark { width: 35px; height: 35px; border-radius: 12px 12px 12px 4px; display: grid; place-items: center; color: white; background: var(--green); font-family: Georgia, serif; font-size: 20px; }
.language-switch { display: flex; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.65); }
.language-switch button { border: 0; padding: 7px 11px; border-radius: 999px; background: transparent; font-size: 12px; font-weight: 800; cursor: pointer; color: var(--muted); }
.language-switch button.active { color: white; background: var(--green); }
.view { display: none; animation: reveal .28s ease both; }
.view.active { display: block; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }
.hero-view { padding: 34px 22px 56px; }
.hero-copy { max-width: 570px; }
.eyebrow { display: block; color: var(--green); font-size: 11px; line-height: 1.2; letter-spacing: .15em; text-transform: uppercase; font-weight: 900; }
h1 { margin: 13px 0 16px; max-width: 600px; font-family: Georgia, "Noto Serif TC", serif; font-size: clamp(44px, 12vw, 74px); line-height: .98; letter-spacing: -.045em; font-weight: 500; }
.hero-copy p { max-width: 460px; margin: 0; font-size: 16px; line-height: 1.7; color: var(--muted); }
.camera-launch { width: 100%; margin-top: 38px; padding: 25px; border: 0; border-radius: 25px; display: grid; grid-template-columns: 58px 1fr; grid-template-rows: auto auto; column-gap: 17px; text-align: left; background: var(--green); color: white; box-shadow: 0 18px 35px rgba(33, 92, 67, .22); cursor: pointer; transition: transform .18s ease, background .18s ease; }
.camera-launch:hover { transform: translateY(-2px); background: var(--green-dark); }
.camera-icon { grid-row: 1 / 3; align-self: center; width: 58px; height: 58px; border-radius: 19px; display: grid; place-items: center; background: var(--lime); }
.camera-icon svg { width: 29px; fill: var(--green-dark); }
.launch-label { align-self: end; font-size: 19px; font-weight: 850; }
.launch-note { align-self: start; margin-top: 3px; font-size: 12px; color: rgba(255,255,255,.68); }
.privacy-note { margin: 16px 4px 0; display: flex; gap: 9px; align-items: flex-start; color: var(--muted); font-size: 11px; line-height: 1.55; }
.privacy-note > span:first-child { color: var(--coral); font-size: 8px; margin-top: 3px; }
.account-strip { margin-top: 24px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,253,249,.72); }
.account-state { min-height: 61px; padding: 10px 13px; display: grid; grid-template-columns: 36px minmax(0,1fr) auto; align-items: center; gap: 10px; }
.account-state[hidden] { display: none; }
.account-avatar { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: #e9e5db; color: var(--green); font-weight: 900; }
.account-avatar.signed { color: white; background: var(--green); }
.account-copy { color: var(--muted); font-size: 11px; line-height: 1.45; }
.account-copy strong { color: var(--ink); }
.account-action { border: 0; padding: 8px 10px; border-radius: 10px; color: var(--green); background: var(--lime); font-size: 11px; font-weight: 850; text-decoration: none; cursor: pointer; white-space: nowrap; }
.daily-card { margin-top: 24px; padding: 20px; border-radius: 22px; background: var(--green); color: white; box-shadow: 0 16px 35px rgba(33,92,67,.17); }
.daily-card-head { display: flex; align-items: start; justify-content: space-between; gap: 15px; }
.daily-card .eyebrow { color: var(--lime); }
.daily-card h2 { margin: 6px 0 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 28px; font-weight: 500; }
.daily-card-head button { border: 1px solid rgba(255,255,255,.25); border-radius: 10px; padding: 7px 9px; color: white; background: rgba(255,255,255,.1); font-size: 10px; font-weight: 800; cursor: pointer; }
.profile-prompt { margin-top: 18px; }
.profile-prompt p { margin: 0 0 13px; color: rgba(255,255,255,.72); font-size: 12px; line-height: 1.55; }
.profile-prompt .button { min-height: 42px; background: var(--lime); color: var(--green-dark); box-shadow: none; }
.progress-track { height: 9px; margin: 22px 0 18px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.18); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--lime); transition: width .35s ease; }
.progress-track span.over { background: var(--coral); }
.daily-numbers { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.daily-numbers div { min-width: 0; }
.daily-numbers strong { display: block; font-size: 22px; line-height: 1; }
.daily-numbers span { display: block; margin-top: 6px; color: rgba(255,255,255,.65); font-size: 9px; }
.estimate-disclaimer { margin: 15px 0 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.daily-card .estimate-disclaimer { color: rgba(255,255,255,.55); }
.history-section { margin-top: 70px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 18px; }
.section-heading h2, .page-heading h2, .loading-copy h2, .message-view h2 { margin: 7px 0 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 30px; font-weight: 500; letter-spacing: -.025em; }
.count-badge { min-width: 32px; height: 32px; padding: 0 10px; border-radius: 999px; display: grid; place-items: center; background: #e9e5db; color: var(--muted); font-size: 12px; font-weight: 800; }
.history-list { display: grid; gap: 11px; }
.history-card { border: 1px solid var(--line); border-radius: 19px; padding: 10px; display: grid; grid-template-columns: 70px 1fr auto; align-items: center; gap: 13px; background: rgba(255,253,249,.82); cursor: pointer; }
.history-card img { width: 70px; height: 70px; border-radius: 13px; object-fit: cover; background: #ddd; }
.history-card h3 { margin: 0 0 6px; font-size: 14px; }
.history-card p { margin: 0; color: var(--muted); font-size: 11px; }
.history-calories { text-align: right; padding-right: 8px; }
.history-calories strong { display: block; font-size: 22px; }
.history-calories span { font-size: 10px; color: var(--muted); }
.empty-history { border: 1px dashed #d8d2c7; border-radius: 20px; padding: 28px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.empty-history > span { display: inline-grid; width: 38px; height: 38px; border-radius: 50%; place-items: center; background: #ebe7de; color: var(--green); }
.empty-history p { margin: 11px 0 0; }
.camera-view { position: fixed; inset: 0; z-index: 20; background: #090d0a; color: white; overflow: hidden; }
.camera-view.active { display: block; }
.camera-view video { width: 100%; height: 100%; object-fit: cover; }
.camera-shade { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(to bottom, rgba(0,0,0,.42), transparent 24%, transparent 67%, rgba(0,0,0,.55)); }
.camera-header { position: absolute; top: 0; left: 0; right: 0; padding: max(18px, env(safe-area-inset-top)) 20px 0; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; text-align: center; font-size: 12px; font-weight: 750; }
.round-button, .round-spacer { width: 44px; height: 44px; border-radius: 50%; }
.round-button { border: 1px solid rgba(255,255,255,.25); color: white; background: rgba(15,20,16,.42); backdrop-filter: blur(8px); font-size: 27px; line-height: 1; cursor: pointer; }
.camera-footer { position: absolute; bottom: max(28px, env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; font-size: 11px; font-weight: 750; }
.shutter { width: 78px; height: 78px; border: 3px solid white; border-radius: 50%; padding: 6px; background: transparent; cursor: pointer; }
.shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: white; transition: transform .12s ease; }
.shutter:active span { transform: scale(.88); }
.preview-view { padding: 28px 22px 48px; }
.page-heading { margin: 7px 0 23px; }
.photo-frame { overflow: hidden; border-radius: 26px; background: #ddd; box-shadow: var(--shadow); aspect-ratio: 4 / 5; }
.photo-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.action-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 11px; margin-top: 21px; }
.button { min-height: 54px; border-radius: 16px; border: 0; padding: 0 20px; font-size: 14px; font-weight: 850; cursor: pointer; }
.button.primary { color: white; background: var(--green); box-shadow: 0 12px 28px rgba(33, 92, 67, .17); }
.button.secondary { border: 1px solid var(--line); background: var(--card); }
.button.full { width: 100%; margin-top: 22px; }
.loading-view { min-height: calc(100dvh - 76px); padding: 34px 22px; text-align: center; }
.scanner-card { position: relative; width: min(78vw, 380px); margin: 0 auto; overflow: hidden; border-radius: 29px; aspect-ratio: 1; background: #ddd; box-shadow: var(--shadow); }
.scanner-card img { width: 100%; height: 100%; object-fit: cover; filter: saturate(.9); }
.scanner-card::after { content: ""; position: absolute; inset: 0; border: 1px solid rgba(255,255,255,.6); border-radius: inherit; }
.scan-line { position: absolute; left: 7%; right: 7%; top: 8%; height: 2px; background: var(--lime); box-shadow: 0 0 17px 4px rgba(219,233,169,.55); animation: scan 2.2s ease-in-out infinite alternate; }
@keyframes scan { to { top: 91%; } }
.loading-copy { margin-top: 35px; }
.loading-copy p { max-width: 360px; margin: 12px auto; color: var(--muted); font-size: 13px; line-height: 1.6; }
.dot-loader { display: flex; justify-content: center; gap: 5px; margin-bottom: 15px; }
.dot-loader span { width: 6px; height: 6px; border-radius: 50%; background: var(--coral); animation: blink 1s infinite alternate; }
.dot-loader span:nth-child(2) { animation-delay: .2s; }
.dot-loader span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { to { opacity: .25; transform: translateY(-3px); } }
.result-view { padding-bottom: 45px; }
.result-hero { position: relative; height: min(56vh, 500px); overflow: hidden; border-radius: 0 0 34px 34px; background: #ddd; }
.result-hero > img { width: 100%; height: 100%; object-fit: cover; }
.result-overlay { position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(0,0,0,.25), transparent 40%, rgba(0,0,0,.52)); }
.result-close { position: absolute; top: 19px; right: 20px; }
.total-card { position: absolute; left: 22px; right: 22px; bottom: 20px; display: grid; grid-template-columns: 1fr auto auto; align-items: end; gap: 8px; color: white; }
.total-card > span { grid-column: 1 / 4; font-size: 11px; letter-spacing: .12em; font-weight: 800; }
.total-card strong { font-family: Georgia, serif; font-size: 66px; font-weight: 500; line-height: .84; }
.total-card small { margin-bottom: 4px; font-size: 13px; font-weight: 800; }
.result-content { padding: 31px 22px 0; }
.portion-panel { margin: -3px 0 32px; padding: 20px; border: 1px solid var(--line); border-radius: 20px; background: var(--card); }
.portion-heading { display: flex; align-items: end; justify-content: space-between; gap: 14px; }
.portion-heading h2 { margin: 5px 0 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 24px; font-weight: 500; }
.portion-heading > strong { color: var(--green); font-size: 27px; }
.portion-panel input[type="range"] { width: 100%; margin: 21px 0 6px; accent-color: var(--green); cursor: pointer; }
.range-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 9px; }
.section-heading.compact { margin-bottom: 15px; }
.food-items { display: grid; gap: 10px; }
.food-card { padding: 17px; display: grid; grid-template-columns: 1fr auto; gap: 12px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.food-card h3 { margin: 0; font-size: 15px; }
.food-meta { margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 5px 12px; color: var(--muted); font-size: 11px; }
.food-note { margin: 8px 0 0; font-size: 11px; line-height: 1.5; color: var(--muted); }
.food-kcal { text-align: right; }
.food-kcal strong { display: block; font-size: 22px; }
.food-kcal span { color: var(--muted); font-size: 10px; }
.confidence { display: inline-flex; align-items: center; gap: 4px; }
.confidence::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #d9a447; }
.confidence.high::before { background: #58a27a; }
.confidence.low::before { background: var(--coral); }
.analysis-summary { margin: 15px 4px 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.health-section { margin-top: 30px; }
.health-guidance { display: grid; gap: 9px; }
.health-card { padding: 14px 15px; border-left: 4px solid #d9a447; border-radius: 13px; background: #f3efe6; }
.health-card.suitable { border-color: #58a27a; background: #edf5f0; }
.health-card.avoid { border-color: var(--coral); background: #fbeeea; }
.health-card.uncertain { border-color: #8b8f8c; }
.health-card > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.health-card strong { font-size: 13px; }
.health-card span { border-radius: 999px; padding: 4px 7px; background: rgba(255,255,255,.75); font-size: 9px; font-weight: 850; }
.health-card p { margin: 7px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.save-actions { display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; margin-top: 22px; }
.saved-notice { margin-top: 22px; padding: 15px; border-radius: 14px; text-align: center; color: var(--green-dark); background: var(--lime); font-size: 12px; font-weight: 800; }
.modal-open { overflow: hidden; }
.settings-overlay { position: fixed; inset: 0; z-index: 50; display: grid; align-items: end; padding: 18px; background: rgba(15,24,18,.55); backdrop-filter: blur(7px); }
.settings-overlay[hidden] { display: none; }
.settings-sheet { width: min(100%, 650px); max-height: calc(100dvh - 36px); margin: 0 auto; padding: 24px; overflow-y: auto; border-radius: 27px; background: var(--paper); box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.settings-header { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.settings-header h2 { margin: 7px 0 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 29px; font-weight: 500; }
.close-settings { width: 40px; height: 40px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 50%; background: var(--card); font-size: 24px; cursor: pointer; }
.settings-intro { margin: 16px 0 20px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 750; }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select { width: 100%; min-height: 45px; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; color: var(--ink); background: var(--card); font: inherit; font-size: 13px; }
.conditions-fieldset { margin: 22px 0 0; padding: 0; border: 0; }
.conditions-fieldset legend { font-size: 12px; font-weight: 850; }
.conditions-fieldset > p { margin: 7px 0 13px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.condition-options { display: flex; flex-wrap: wrap; gap: 8px; }
.condition-chip { cursor: pointer; }
.condition-chip input { position: absolute; opacity: 0; pointer-events: none; }
.condition-chip span { display: inline-block; padding: 9px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--muted); font-size: 10px; font-weight: 750; }
.condition-chip input:checked + span { border-color: var(--green); color: white; background: var(--green); }
.profile-estimate { margin-top: 20px; padding: 17px; border-radius: 16px; display: grid; grid-template-columns: 1fr auto auto; align-items: end; gap: 7px; background: var(--green); color: white; }
.profile-estimate span { grid-column: 1 / 4; color: var(--lime); font-size: 10px; font-weight: 800; }
.profile-estimate strong { font-size: 31px; line-height: 1; }
.profile-estimate small { margin-bottom: 3px; }
.form-error { color: #a53c27; font-size: 11px; }
.message-view { min-height: calc(100dvh - 76px); padding: 70px 28px; text-align: center; }
.message-icon { width: 65px; height: 65px; margin: 0 auto 20px; border-radius: 22px; display: grid; place-items: center; background: #f8d9ce; color: #9d422d; font-family: Georgia, serif; font-size: 32px; }
.message-view p { max-width: 400px; margin: 14px auto 25px; color: var(--muted); line-height: 1.65; }

@media (min-width: 761px) {
  body { padding: 24px 0; }
  .app-shell { min-height: calc(100dvh - 48px); border: 1px solid rgba(217,211,200,.8); border-radius: 30px; overflow: hidden; background: rgba(248,245,239,.83); box-shadow: 0 28px 90px rgba(45,54,46,.12); }
  .camera-view { inset: 24px auto; left: 50%; width: min(100% - 48px, 760px); transform: translateX(-50%); border-radius: 30px; }
  .result-hero { margin: 0 18px; border-radius: 27px; }
  .settings-overlay { align-items: center; }
}

@media (max-width: 480px) {
  .save-actions { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label.wide { grid-column: auto; }
  .settings-overlay { padding: 0; }
  .settings-sheet { max-height: 94dvh; border-radius: 27px 27px 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
