:root {
  color-scheme: light;
  --bg: #fff5f8;
  --panel: #ffffff;
  --panel-soft: #fff0f5;
  --text: #3a2b31;
  --muted: #8f6473;
  --line: #f1c9d6;
  --accent: #e889a9;
  --accent-strong: #b94671;
  --accent-soft: #ffe1eb;
  --gold: #f0a23a;
  --blue: #75aee8;
  --rose: #d96f93;
  --green: #7fbd7b;
  --purple: #c07ccf;
  --shadow: 0 18px 48px rgba(185, 70, 113, 0.11);
  --character-bg: none;
  --radius: 8px;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 10% 6%, rgba(255, 222, 232, 0.95), transparent 260px),
    radial-gradient(circle at 88% 8%, rgba(255, 236, 204, 0.72), transparent 240px),
    linear-gradient(180deg, rgba(255, 234, 241, 0.82), rgba(255, 245, 248, 0) 360px),
    var(--bg);
  color: var(--text);
}

body::before {
  content: "";
  position: fixed;
  right: max(16px, 4vw);
  bottom: 16px;
  width: min(260px, 42vw);
  aspect-ratio: 1;
  background-image: var(--character-bg);
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  right: 5vw;
  top: 110px;
  width: 170px;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 42% 42%, rgba(255, 255, 255, 0.94) 0 8px, transparent 9px),
    radial-gradient(circle at 58% 42%, rgba(255, 255, 255, 0.94) 0 8px, transparent 9px),
    radial-gradient(circle at 50% 58%, rgba(255, 204, 219, 0.88) 0 18px, transparent 19px),
    rgba(255, 225, 235, 0.48);
  filter: blur(0.2px);
  opacity: 0.45;
  pointer-events: none;
  z-index: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 0 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.1;
}

h2 {
  font-size: 20px;
  line-height: 1.25;
}

.top-actions,
.date-picker,
.save-bar,
.section-heading,
.counter-buttons,
.trend-legend,
.tools {
  display: flex;
  align-items: center;
}

.top-actions {
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.date-picker {
  gap: 10px;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(43, 54, 46, 0.06);
}

.date-picker input {
  flex: 1 1 0;
  width: auto;
}

.date-picker span {
  flex: 0 0 auto;
}

.date-picker span,
label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.icon-button,
.primary-button,
.ghost-button,
.tools button,
.import-button,
.counter-buttons button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s ease;
}

.icon-button {
  width: 44px;
  background: var(--panel);
  border-color: var(--line);
  color: var(--accent-strong);
  font-size: 26px;
  line-height: 1;
}

.icon-button:hover,
.ghost-button:hover,
.tools button:hover,
.import-button:hover,
.counter-buttons button:hover {
  border-color: #eaa4bb;
  background: #fff7fa;
}

.primary-button:hover,
.history-item:hover {
  transform: translateY(-1px);
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.quick-stats article {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 88px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(43, 54, 46, 0.06);
}

.stat-icon {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 900;
}

.quick-stats p {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.quick-stats strong {
  font-size: 21px;
  line-height: 1.15;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 16px;
  align-items: start;
}

.record-panel,
.insights-panel {
  min-width: 0;
}

.record-panel,
.panel-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.record-panel {
  padding: 20px;
}

.section-heading {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-heading.compact {
  margin-bottom: 12px;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin: 10px 0 0;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.sync-status[data-mode="ok"] {
  border-color: #f0b1c5;
  background: #fff0f5;
  color: #b94671;
}

.sync-status[data-mode="error"] {
  border-color: #e0a2a2;
  background: #fff0f0;
  color: #9b2f2f;
}

.sync-status[data-mode="working"] {
  border-color: #d7c28d;
  background: #fff8df;
  color: #765a16;
}

.section-heading.compact h2 {
  white-space: nowrap;
}

.section-heading.compact select {
  min-width: 150px;
}

.ghost-button {
  padding: 0 14px;
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}

fieldset {
  position: relative;
  min-width: 0;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 252, 0.92);
}

fieldset.wide {
  grid-column: 1 / -1;
}

legend {
  padding: 0 8px;
  color: var(--accent-strong);
  font-size: 15px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #efc7d4;
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  outline: none;
}

input,
select {
  min-height: 42px;
  padding: 9px 11px;
}

textarea {
  resize: vertical;
  min-height: 88px;
  padding: 10px 11px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 137, 169, 0.18);
}

.two-col,
.counter-row,
.three-col,
.measurement-grid,
.nutrition-grid,
.cloud-settings {
  display: grid;
  gap: 12px;
}

.two-col,
.counter-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.three-col {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

.measurement-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 12px 0;
}

.nutrition-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-top: 12px;
}

.cloud-settings {
  grid-template-columns: 1.4fr 1fr 1.2fr;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1.4fr minmax(180px, 0.6fr);
  gap: 12px;
}

.cloud-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.cloud-message {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.cloud-message[data-mode="ok"] {
  border-color: #f0b1c5;
  background: #fff0f5;
  color: #b94671;
}

.cloud-message[data-mode="error"] {
  border-color: #e0a2a2;
  background: #fff0f0;
  color: #9b2f2f;
}

.cloud-message[data-mode="working"] {
  border-color: #d7c28d;
  background: #fff8df;
  color: #765a16;
}

.copy-button {
  margin-top: 12px;
  min-height: 44px;
}

.counter-buttons {
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.counter-buttons button {
  padding: 0 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.computed-line {
  margin: 10px 0 0;
  padding: 9px 11px;
  border: 1px dashed #efb5c8;
  border-radius: var(--radius);
  background: #fff7fa;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 900;
}

.advanced-section {
  margin: 10px 0 12px;
}

.advanced-section summary {
  min-height: 38px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff7fa;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.section-controls {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-bottom: 6px;
}

.section-controls button {
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.custom-head,
.meal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}

.custom-head h3,
.meal-head h3 {
  margin: 0;
  color: var(--accent-strong);
  font-size: 15px;
}

.custom-trackers {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.tracker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.tracker-row input[type="checkbox"] {
  width: 22px;
  min-height: 22px;
  justify-self: start;
  accent-color: var(--accent);
}

.mini-button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--accent-strong);
  font-weight: 800;
}

.empty-inline,
.small-note,
.helper-summary {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.meal-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.meal-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
}

.meal-head {
  margin: 0 0 12px;
}

.image-upload {
  margin-top: 10px;
}

.image-preview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.image-thumb {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  min-height: 24px;
  border: 0;
  border-radius: 50%;
  background: rgba(32, 35, 31, 0.78);
  color: #ffffff;
  line-height: 1;
}

.nutrition-panel {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
}

#macroCanvas {
  aspect-ratio: 1;
  width: 100%;
}

.macro-summary {
  display: grid;
  gap: 12px;
}

.macro-summary p {
  margin: 0;
}

.macro-bars {
  display: grid;
  gap: 9px;
}

.macro-bars span {
  position: relative;
  overflow: hidden;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff7fa;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.macro-bars span::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--value);
  background: rgba(232, 137, 169, 0.18);
  z-index: 0;
}

.macro-bars span {
  z-index: 1;
}

#fatBar::before {
  background: rgba(240, 162, 58, 0.18);
}

#carbBar::before {
  background: rgba(117, 174, 232, 0.17);
}

.save-bar {
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
}

.save-bar p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.primary-button {
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 900;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.insights-panel {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 16px;
}

.panel-block {
  padding: 16px;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 7;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffffff, #fff7fa);
}

#calendarCanvas {
  aspect-ratio: 16 / 10;
  margin-top: 10px;
}

[hidden] {
  display: none !important;
}

.trend-legend {
  gap: 14px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.trend-legend i {
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}

.line {
  width: 24px;
  height: 3px;
  border-radius: 2px;
}

.bar {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.weight-line {
  background: var(--rose);
}

.water-bar {
  background: var(--blue);
}

.waist-line {
  background: var(--accent);
}

.month-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.month-summary div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.month-summary dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.month-summary dd {
  margin: 5px 0 0;
  font-size: 19px;
  font-weight: 900;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 2px;
}

.history-item {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: inherit;
  text-align: left;
}

.history-date {
  color: var(--accent-strong);
  font-weight: 900;
}

.history-detail {
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-history {
  margin: 0;
  padding: 18px 12px;
  border: 1px dashed #c9d4c6;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.tools {
  gap: 8px;
  flex-wrap: wrap;
}

.tools button,
.import-button {
  flex: 1 1 110px;
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  border-color: var(--line);
  background: #ffffff;
  color: var(--text);
  font-weight: 800;
}

.import-button input {
  display: none;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .insights-panel {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tools {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .app-shell {
    width: min(calc(100% - 20px), 720px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    width: 100%;
    justify-content: initial;
  }

  .date-picker {
    width: 100%;
  }

  .date-picker input {
    min-width: 0;
  }

  .quick-stats,
  .form-grid,
  .meal-cards,
  .measurement-grid,
  .nutrition-grid,
  .cloud-settings,
  .settings-grid,
  .insights-panel {
    grid-template-columns: 1fr;
  }

  .record-panel,
  .panel-block {
    padding: 14px;
  }

  .three-col {
    grid-template-columns: 1fr;
  }

  .nutrition-panel {
    grid-template-columns: 1fr;
  }

  #macroCanvas {
    max-width: 260px;
    justify-self: center;
  }

  .save-bar {
    position: static;
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 520px) {
  .quick-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quick-stats article {
    min-height: 78px;
    padding: 12px;
  }

  .stat-icon {
    width: 34px;
    height: 34px;
    font-size: 11px;
  }

  .two-col,
  .counter-row,
  .month-summary {
    grid-template-columns: 1fr;
  }

  .history-item {
    grid-template-columns: 1fr;
  }
}
