:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-soft: #fbfaf6;
  --ink: #202622;
  --muted: #667168;
  --line: #dedbd2;
  --green: #2e7d62;
  --green-soft: #e4f5e8;
  --blue: #355aa4;
  --blue-soft: #eaf0ff;
  --amber: #9a5c15;
  --amber-soft: #fff0d9;
  --coral: #d56b53;
  --coral-soft: #fde9e3;
  --shadow: 0 12px 28px rgba(64, 57, 42, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 540px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px 14px calc(92px + var(--safe-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(46, 125, 98, 0.18);
}

.brand-kicker {
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  margin-top: 2px;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 20px;
  letter-spacing: 0;
}

h3 {
  font-size: 17px;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button svg,
.tab-button svg,
.primary-button svg,
.secondary-button svg,
.settings-row svg,
.medical-note svg {
  width: 19px;
  height: 19px;
  stroke-width: 2.2;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.summary-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.date-line {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-title {
  margin-top: 7px;
  font-size: 24px;
  line-height: 1.16;
  font-weight: 850;
}

.summary-title strong {
  color: var(--green);
}

.summary-subtitle {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.progress-meter {
  position: relative;
  width: 76px;
  height: 76px;
  flex: 0 0 76px;
  display: grid;
  place-items: center;
  color: var(--green);
  font-weight: 850;
}

.progress-meter svg {
  position: absolute;
  inset: 0;
  width: 76px;
  height: 76px;
  transform: rotate(-90deg);
}

.progress-meter circle {
  fill: none;
  stroke-width: 5;
}

.progress-meter circle:first-child {
  stroke: #ece7dc;
}

#progressCircle {
  stroke: var(--green);
  stroke-linecap: round;
  stroke-dasharray: 113.1;
  stroke-dashoffset: 113.1;
  transition: stroke-dashoffset 0.22s ease;
}

.progress-meter span {
  position: relative;
  font-size: 17px;
}

.status-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 0 4px;
  scrollbar-width: none;
}

.status-strip::-webkit-scrollbar {
  display: none;
}

.status-chip {
  min-width: max-content;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.status-chip.active {
  border-color: #b7d9c6;
  background: var(--green-soft);
  color: var(--green);
}

.medical-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 10px;
  padding: 12px;
  border-radius: 8px;
  background: var(--amber-soft);
  color: #6d4d1f;
  font-size: 13px;
  line-height: 1.45;
}

.medical-note svg {
  flex: 0 0 auto;
  margin-top: 1px;
  color: var(--amber);
}

.section-block {
  margin-top: 22px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 2px 11px;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.page-head {
  margin-top: 12px;
}

.meal-card,
.exercise-card,
.morning-card,
.history-card,
.trend-card,
.info-panel,
.empty-panel,
.settings-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(64, 57, 42, 0.06);
}

.meal-card,
.exercise-card,
.morning-card {
  margin-bottom: 13px;
  padding: 15px;
}

.meal-card.done,
.exercise-card.done,
.morning-card.done {
  border-color: #99d1b2;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.meal-name {
  font-size: 19px;
  font-weight: 850;
}

.meal-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.done-toggle {
  min-width: 84px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.done-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  min-width: 0;
}

.field.full {
  margin-top: 12px;
}

label,
.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #d8d4c9;
  border-radius: 8px;
  background: #fffefb;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(46, 125, 98, 0.12);
}

input,
select {
  height: 42px;
  padding: 0 10px;
  font-size: 14px;
}

textarea {
  min-height: 76px;
  padding: 10px;
  resize: vertical;
  line-height: 1.45;
  font-size: 14px;
}

.food-panel {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  border: 1px solid #ebe7dc;
}

.food-row {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 9px;
}

.food-row:last-child {
  margin-bottom: 0;
}

.food-tag {
  height: 34px;
  line-height: 34px;
  border-radius: 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 850;
}

.food-tag.vegetable {
  background: var(--green-soft);
  color: var(--green);
}

.food-tag.protein {
  background: var(--blue-soft);
  color: var(--blue);
}

.food-tag.carb {
  background: var(--amber-soft);
  color: var(--amber);
}

.exercise-card {
  background: #fffdf8;
}

.morning-card {
  background: linear-gradient(180deg, #ffffff, #fbf7ef);
}

.morning-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.metric-hint {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.save-bar {
  position: sticky;
  bottom: calc(69px + var(--safe-bottom));
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 0.42fr;
  gap: 9px;
  margin-top: 18px;
  padding: 12px 0;
  background: linear-gradient(180deg, rgba(246, 244, 239, 0), var(--bg) 28%);
}

.primary-button,
.secondary-button {
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 850;
}

.primary-button {
  background: var(--green);
  color: #ffffff;
}

.secondary-button {
  background: #ece7dc;
  color: #4d584f;
}

.bottom-tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(100%, 540px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px 12px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.tab-button {
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.tab-button.active {
  background: var(--green-soft);
  color: var(--green);
}

.history-card {
  margin-bottom: 10px;
  padding: 14px;
}

.trend-card {
  margin-bottom: 14px;
  padding: 14px;
}

.trend-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.trend-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.trend-head select {
  width: 150px;
  flex: 0 0 150px;
  height: 38px;
  font-size: 13px;
}

.trend-svg {
  width: 100%;
  height: 210px;
  display: block;
  border-radius: 8px;
  background: var(--surface-soft);
}

.trend-line {
  fill: none;
  stroke: var(--green);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trend-grid-line {
  stroke: #e7e0d5;
  stroke-width: 1;
}

.trend-dot {
  fill: #ffffff;
  stroke: var(--green);
  stroke-width: 3;
}

.trend-axis,
.trend-label {
  fill: var(--muted);
  font-size: 11px;
}

.trend-value {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.trend-empty {
  min-height: 150px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
  padding: 18px;
}

.history-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.history-date {
  font-size: 16px;
  font-weight: 850;
}

.history-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.mini-progress {
  min-width: 62px;
  color: var(--green);
  text-align: right;
  font-weight: 850;
}

.history-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.history-tags span {
  padding: 5px 8px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.history-detail {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.history-detail h3 {
  margin-bottom: 10px;
}

.detail-row {
  padding: 10px 0;
  border-top: 1px solid #eee9df;
}

.detail-row:first-of-type {
  border-top: 0;
}

.detail-row strong {
  display: block;
  margin-bottom: 4px;
}

.detail-row p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.settings-group {
  overflow: hidden;
}

.settings-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 13px 14px;
  border: 0;
  border-bottom: 1px solid #eee9df;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.settings-row:last-child {
  border-bottom: 0;
}

.settings-row > svg {
  flex: 0 0 auto;
  color: var(--green);
}

.settings-row strong {
  display: block;
  font-size: 15px;
}

.settings-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.settings-row.danger > svg,
.settings-row.danger strong {
  color: var(--coral);
}

.info-panel,
.empty-panel {
  margin-top: 14px;
  padding: 15px;
}

.info-panel p,
.empty-panel p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.empty-panel {
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  z-index: 30;
  max-width: min(420px, calc(100vw - 40px));
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(32, 38, 34, 0.92);
  color: #ffffff;
  font-size: 14px;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 374px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  h1 {
    font-size: 25px;
  }

  .summary-title {
    font-size: 22px;
  }

  .form-grid,
  .form-grid.two,
  .morning-grid {
    grid-template-columns: 1fr;
  }

  .save-bar {
    grid-template-columns: 1fr;
  }

  .trend-head {
    display: block;
  }

  .trend-head select {
    width: 100%;
    margin-top: 10px;
  }
}
