:root {
  --bg-1: #f3f7f4;
  --bg-2: #e7f0ea;
  --ink: #1c2b24;
  --muted: #5c6f65;
  --brand: #1a5c45;
  --brand-deep: #0f3d2e;
  --accent: #c4783a;
  --surface: rgba(255, 255, 255, 0.78);
  --line: rgba(26, 92, 69, 0.14);
  --shadow: 0 18px 50px rgba(15, 61, 46, 0.08);
  --radius: 22px;
  --font-display: "ZCOOL XiaoWei", "Noto Serif SC", serif;
  --font-body: "Noto Sans SC", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg-1);
  line-height: 1.6;
  overflow-x: hidden;
}

.page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(196, 120, 58, 0.18), transparent 55%),
    radial-gradient(ellipse 70% 45% at 100% 0%, rgba(26, 92, 69, 0.16), transparent 50%),
    linear-gradient(165deg, #f7faf8 0%, #eaf3ee 45%, #f2f0e8 100%);
}

.page-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.35) 0 1px, transparent 1.5px),
    radial-gradient(circle at 80% 70%, rgba(26, 92, 69, 0.08) 0 1px, transparent 1.5px);
  background-size: 48px 48px, 36px 36px;
  opacity: 0.7;
  pointer-events: none;
}

.site-header {
  padding: 1.25rem 0 0.5rem;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  min-width: 0;
}

.brand {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  color: var(--brand);
  text-decoration: none;
  letter-spacing: 0.04em;
  animation: fade-up 0.7s ease both;
}

.brand-tag {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  animation: fade-up 0.7s ease 0.08s both;
}

.auth-bar {
  flex-shrink: 0;
  animation: fade-up 0.7s ease 0.1s both;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--brand-deep);
  font-size: 0.9rem;
  font-weight: 600;
}

.cloud-hint {
  margin: 1rem auto 0;
  max-width: 28rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 61, 46, 0.35);
  backdrop-filter: blur(4px);
}

.auth-dialog {
  width: min(100%, 380px);
  padding: 1.25rem;
  border-radius: var(--radius);
  background: #f7faf8;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.auth-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}

.btn-clear-modal {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(26, 92, 69, 0.08);
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.auth-error {
  margin: 0.5rem 0 0;
  color: #a33;
  font-size: 0.88rem;
}

.auth-tip {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.auth-dialog .goal-field + .goal-field {
  margin-top: 0.75rem;
}

.main-wrap {
  max-width: 720px;
  padding-bottom: 4rem;
}

.hero {
  padding: 2.5rem 0 1.5rem;
  text-align: center;
  animation: fade-up 0.75s ease 0.12s both;
}

.hero-title {
  font-family: var(--font-display);
  font-size: clamp(3rem, 12vw, 4.5rem);
  color: var(--brand-deep);
  letter-spacing: 0.08em;
  margin: 0 0 0.75rem;
  line-height: 1.1;
}

.hero-desc {
  margin: 0 auto 1.75rem;
  max-width: 28rem;
  color: var(--muted);
  font-size: 1.05rem;
}

.cta-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.btn-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.7rem 1.35rem;
  border-radius: 999px;
  font-weight: 600;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-deep);
  --bs-btn-hover-border-color: var(--brand-deep);
  --bs-btn-active-bg: var(--brand-deep);
  --bs-btn-active-border-color: var(--brand-deep);
}

.btn-outline-primary {
  --bs-btn-color: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand);
  --bs-btn-hover-border-color: var(--brand);
  --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: var(--brand-deep);
  --bs-btn-active-border-color: var(--brand-deep);
  background: rgba(255, 255, 255, 0.55);
}

.btn-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(26, 92, 69, 0.18);
}

.config-hint {
  margin: 1.25rem auto 0;
  max-width: 28rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: rgba(196, 120, 58, 0.12);
  color: #7a4a1f;
  font-size: 0.88rem;
}

.config-hint code {
  font-size: 0.82rem;
  color: var(--brand-deep);
}

.preview-section,
.result-section {
  margin-top: 1.5rem;
  animation: fade-up 0.5s ease both;
}

.preview-frame {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0f3d2e;
  box-shadow: var(--shadow);
  aspect-ratio: 4 / 3;
}

.preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  animation: soft-zoom 0.6s ease both;
}

.btn-clear {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(28, 43, 36, 0.55);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.btn-analyze {
  width: 100%;
  margin-top: 1rem;
  min-height: 50px;
  border-radius: 14px;
  font-weight: 600;
  font-size: 1.05rem;
}

.compress-hint {
  margin: 0.75rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.portion-block {
  margin-bottom: 1.15rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.portion-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.portion-value {
  font-weight: 700;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
}

.portion-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.portion-chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.meal-chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.4rem 0.95rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.portion-chip.is-active,
.portion-chip:hover,
.meal-chip.is-active,
.meal-chip:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.portion-slider {
  width: 100%;
  accent-color: var(--brand);
}

.today-block,
.week-block,
.history-block {
  margin: 2.25rem auto 0;
  max-width: 28rem;
  text-align: left;
  padding: 1.1rem 1.15rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  animation: fade-up 0.7s ease 0.2s both;
}

.today-date {
  color: var(--muted);
  font-size: 0.85rem;
}

.today-empty {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.goal-form {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.goal-profile {
  padding: 0.75rem;
  border-radius: 12px;
  background: rgba(26, 92, 69, 0.06);
  border: 1px solid var(--line);
}

.goal-profile-title {
  margin: 0 0 0.55rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--brand-deep);
}

.goal-profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-bottom: 0.55rem;
}

.goal-recommend-hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.goal-type-chips {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
}

.goal-type-chip {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.45rem 0.2rem;
  cursor: pointer;
}

.goal-type-chip.is-active {
  border-color: var(--brand);
  background: rgba(26, 92, 69, 0.12);
  color: var(--brand-deep);
}

@media (max-width: 420px) {
  .goal-type-chips {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.goal-field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.goal-field input,
.goal-field select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.8);
  width: 100%;
}

.goal-form-actions {
  display: flex;
  gap: 0.5rem;
}

.progress-row + .progress-row {
  margin-top: 0.75rem;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(26, 92, 69, 0.1);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), #2f8f6d);
  transition: width 0.35s ease;
}

.progress-fill.is-over {
  background: linear-gradient(90deg, #b45309, #c4783a);
}

.today-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}

.shoot-tip {
  margin: 0.75rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.result-actions {
  display: grid;
  gap: 0.65rem;
  margin-top: 1.25rem;
}

.copy-toast {
  margin: 0.65rem 0 0;
  text-align: center;
  color: var(--brand);
  font-size: 0.9rem;
  font-weight: 600;
}

.today-item {
  padding: 0.75rem 0.55rem;
  text-align: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
}

.today-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
}

.today-label {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.today-meals {
  margin-top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.today-meal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.meal-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--brand-deep);
  background: rgba(26, 92, 69, 0.12);
}

.meal-badge.meal-breakfast { background: rgba(196, 120, 58, 0.16); color: #7a4a1f; }
.meal-badge.meal-lunch { background: rgba(26, 92, 69, 0.14); color: var(--brand-deep); }
.meal-badge.meal-dinner { background: rgba(45, 74, 110, 0.12); color: #2d4a6e; }
.meal-badge.meal-snack { background: rgba(110, 90, 60, 0.12); color: #6e5a3c; }

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.btn-link-clear {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
}

.btn-link-clear:hover {
  color: var(--brand);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.history-item + .history-item {
  margin-top: 0.55rem;
}

.history-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.35rem 0;
  cursor: pointer;
  color: inherit;
}

.history-del {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.history-del:hover {
  color: #a33;
  background: rgba(170, 50, 50, 0.08);
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}

.history-action-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
}

.history-action-btn:hover {
  color: #a33;
  border-color: rgba(170, 50, 50, 0.35);
}

.history-img-tag {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  border-radius: 6px;
  background: rgba(26, 92, 69, 0.1);
  color: var(--brand-deep);
  font-size: 0.72rem;
  font-weight: 600;
}

.history-manage-tip {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.history-thumb {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: cover;
  background: rgba(26, 92, 69, 0.12);
  flex-shrink: 0;
}

.history-thumb.is-empty {
  background: linear-gradient(135deg, rgba(26, 92, 69, 0.18), rgba(196, 120, 58, 0.16));
}

.history-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.history-meta strong {
  font-weight: 650;
  color: var(--brand-deep);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta span {
  font-size: 0.82rem;
  color: var(--muted);
}

.history-time {
  opacity: 0.85;
}

.week-tabs {
  display: flex;
  gap: 0.35rem;
}

.week-tab {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.week-tab.is-active,
.week-tab:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.week-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.35rem;
  min-height: 150px;
  align-items: end;
}

.week-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
}

.week-bar-wrap {
  position: relative;
  width: 100%;
  height: 120px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border-radius: 10px 10px 4px 4px;
  background: rgba(26, 92, 69, 0.06);
  overflow: hidden;
}

.week-goal-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed rgba(196, 120, 58, 0.7);
  z-index: 1;
}

.week-bar {
  width: 58%;
  min-height: 0;
  border-radius: 8px 8px 2px 2px;
  background: linear-gradient(180deg, #2f8f6d, var(--brand));
  transition: height 0.35s ease;
  z-index: 2;
}

.week-bar.is-over {
  background: linear-gradient(180deg, #d97706, #c4783a);
}

.week-day,
.week-val {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.2;
}

.week-val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--brand-deep);
}

.week-summary {
  margin: 0.85rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.btn-install {
  display: block;
  width: 100%;
  max-width: 28rem;
  margin: 1.25rem auto 0;
  border-radius: 14px;
  min-height: 46px;
  font-weight: 600;
}

.install-hint {
  max-width: 28rem;
  margin: 0.65rem auto 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.result-header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.result-title {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  color: var(--brand-deep);
  margin: 0 0 0.35rem;
}

.result-summary {
  margin: 0;
  color: var(--muted);
}

.nutri-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

@media (min-width: 576px) {
  .nutri-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.nutri-item {
  padding: 1rem 0.75rem;
  text-align: center;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  animation: fade-up 0.45s ease both;
}

.nutri-item:nth-child(1) { animation-delay: 0.05s; }
.nutri-item:nth-child(2) { animation-delay: 0.1s; }
.nutri-item:nth-child(3) { animation-delay: 0.15s; }
.nutri-item:nth-child(4) { animation-delay: 0.2s; }
.nutri-item:nth-child(5) { animation-delay: 0.25s; }
.nutri-item:nth-child(6) { animation-delay: 0.3s; }

.nutri-value {
  display: block;
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.02em;
}

.nutri-label {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.ingredients-block,
.tips-block {
  margin-top: 1.5rem;
  padding: 1.15rem 1.2rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.block-title {
  font-size: 1rem;
  font-weight: 650;
  margin: 0 0 0.75rem;
  color: var(--brand-deep);
}

.ingredient-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ingredient-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}

.ingredient-list li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.ingredient-list .meta {
  color: var(--muted);
  white-space: nowrap;
}

.ingredient-hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.ingredient-row {
  display: grid !important;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 5.2rem 2rem;
  gap: 0.4rem;
  align-items: center;
}

.ingredient-row input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  padding: 0.4rem 0.55rem;
  font-size: 0.9rem;
  color: var(--ink);
}

.ingredient-row .ing-del {
  border: 0;
  background: transparent;
  color: #a33;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.ingredient-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 520px) {
  .ingredient-row {
    grid-template-columns: 1fr 1fr 2rem;
    grid-template-areas:
      "name name del"
      "amount cal del";
  }

  .ingredient-row .ing-name { grid-area: name; }
  .ingredient-row .ing-amount { grid-area: amount; }
  .ingredient-row .ing-cal { grid-area: cal; }
  .ingredient-row .ing-del { grid-area: del; align-self: start; }
}

.export-row {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.share-preview {
  margin-top: 1rem;
  text-align: center;
}

.share-preview img {
  width: min(100%, 320px);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.tips-block p {
  margin: 0;
  color: var(--muted);
}

.disclaimer {
  margin: 1rem 0 0;
  font-size: 0.78rem;
  color: #8a9a90;
  text-align: center;
}

#errorBox {
  margin-top: 1.25rem;
  border-radius: 12px;
  font-size: 0.95rem;
  word-break: break-word;
}

.site-footer {
  padding: 1.5rem 0 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer p {
  margin: 0;
}

.is-analyzing .btn-analyze {
  pointer-events: none;
  opacity: 0.85;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes soft-zoom {
  from {
    opacity: 0.4;
    transform: scale(1.04);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
