:root {
  color-scheme: light;
  --bg: #fff4f2;
  --card: #fffdfb;
  --line: #e8dad6;
  --text: #2b2525;
  --sub: #6f6260;
  --weak: #a3918e;
  --primary: #9e1f35;
  --cal: #a14a55;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
}

#app {
  max-width: 520px;
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 96px 1fr 96px;
  align-items: center;
  height: 64px;
  padding: 0 16px;
  background: rgba(255, 244, 242, .94);
  backdrop-filter: blur(16px);
}

.topbar h1 {
  margin: 0;
  text-align: center;
  font-size: 27px;
  line-height: 1;
  font-weight: 800;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.back-btn {
  justify-self: start;
  font-size: 38px;
}

.view {
  display: none;
  padding: 4px 22px 28px;
}

.view.active {
  display: block;
}

.hero {
  text-align: center;
}

.cat {
  width: 156px;
  height: 156px;
  object-fit: cover;
  border-radius: 26px;
}

.chip {
  display: inline-flex;
  margin-top: 6px;
  padding: 4px 10px;
  border: 1px solid #211417;
  border-radius: 999px;
  background: #ffe3e8;
  font-size: 12px;
  font-weight: 800;
}

.hero h2 {
  margin: 8px 0 6px;
  font-size: 22px;
  line-height: 1.25;
}

.hero p, .loading-view p {
  margin: 0;
  color: rgba(0, 0, 0, .48);
  font-size: 14px;
}

.actions {
  margin-top: 18px;
}

input[type=file] {
  display: none;
}

.primary-action, .secondary-action, .primary-small {
  border: 0;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.primary-action {
  height: 54px;
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  font-weight: 900;
}

.secondary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.secondary-action {
  min-height: 48px;
  border: 1px solid #211417;
  background: transparent;
  color: var(--text);
  font-weight: 700;
}

.card {
  margin-top: 12px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 4px 10px rgba(43, 37, 37, .06);
}

.card-head, .goal-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-head strong {
  flex: 1;
  font-size: 17px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.metrics small {
  display: block;
  color: var(--sub);
  font-size: 12px;
}

.metrics b {
  display: block;
  margin-top: 3px;
  font-size: 16px;
}

.today-card p, .goal-card p {
  margin: 10px 0 0;
  color: var(--sub);
  font-size: 14px;
  font-weight: 700;
}

.goal-card p {
  flex: 1;
  margin: 0;
}

.loading-view {
  min-height: calc(100vh - 64px);
  text-align: center;
  align-content: center;
}

.loader {
  width: 48px;
  height: 48px;
  margin: 0 auto 18px;
  border: 5px solid #ffe1de;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.photo {
  width: 100%;
  height: 204px;
  object-fit: cover;
  border-radius: 22px;
}

.result-card {
  margin-top: 20px;
  padding: 22px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 4px 12px rgba(43, 37, 37, .06);
}

.result-top, .kcal-row, .meta-row, .date-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.result-title {
  flex: 1;
  min-width: 0;
}

.result-title h2 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 29px;
  line-height: 1.1;
}

.result-title p {
  margin: 5px 0 0;
  color: #7a6a68;
  font-size: 15px;
}

.confidence, .pressure {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  background: #fff0f0;
  color: #7a5a5a;
  font-size: 14px;
  font-weight: 600;
}

.kcal-row {
  align-items: flex-end;
  margin-top: 20px;
}

.kcal {
  flex: 1;
  color: var(--cal);
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
}

.pressure {
  padding: 6px 12px;
}

.pressure.easy { background: #eaf7ee; color: #3b8a55; }
.pressure.watch { background: #fff5d8; color: #a6781d; }
.pressure.mid { background: #ffead8; color: #b76a24; }
.pressure.high { background: #ffe1de; color: #b95045; }
.pressure.max { background: #ffd8d8; color: #b23a3a; }

.pressure-line {
  margin: 10px 0 0;
  color: #5f5050;
  font-size: 16px;
}

.meal-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 18px 0;
}

.meal-chip {
  height: 40px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdfb;
  color: var(--sub);
  white-space: nowrap;
}

.meal-chip.active {
  border-color: transparent;
  background: #ffd96a;
  color: #3a2d2d;
  font-weight: 700;
}

.nutrition {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.nutrition div {
  padding: 12px;
  border-radius: 16px;
  background: #fff7f4;
}

.nutrition small {
  color: #8a7673;
  font-size: 13px;
}

.nutrition b {
  display: block;
  margin-top: 5px;
  font-size: 17px;
}

.soft-line {
  height: 1px;
  margin: 18px 0;
  background: var(--line);
}

.roast {
  margin: 0;
  color: var(--text);
  font-size: 20px;
  line-height: 1.35;
  font-weight: 700;
}

.exercise {
  margin: 12px 0 0;
  color: #5f5050;
  font-size: 16px;
}

.remain-tip {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--bg);
  color: var(--sub);
  font-size: 15px;
}

.detail-card {
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
  color: #3a2d2d;
  font-size: 16px;
  line-height: 1.6;
}

.save-status {
  margin: 14px 0 10px;
  text-align: center;
  color: #8a7673;
  font-size: 15px;
}

.bottom-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.main-btn, .ghost-btn {
  height: 52px;
  border-radius: 18px;
  font-size: 17px;
  font-weight: 700;
}

.main-btn {
  border: 0;
  background: var(--primary);
  color: #fff;
}

.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--primary);
}

.text-danger {
  display: block;
  margin: 8px auto 0;
  border: 0;
  background: transparent;
  color: var(--cal);
  font-size: 15px;
}

.week-card {
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.date-head {
  margin: 24px 0 10px;
  align-items: center;
}

.date-head strong {
  flex: 1;
  font-size: 18px;
}

.date-head span {
  font-size: 16px;
}

.history-card {
  height: 108px;
  margin-bottom: 14px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.thumb {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 16px;
  background: #fff1eb;
}

.history-main {
  flex: 1;
  min-width: 0;
}

.history-main h3 {
  margin: 0 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.history-main .meta-row {
  align-items: center;
}

.history-main .meta-row span:first-child {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--sub);
}

.chev {
  color: #7a6a68;
  font-size: 28px;
}

.footer-note {
  margin: 34px 0 0;
  text-align: center;
  color: var(--weak);
  font-size: 14px;
}

.week-strip {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 4px;
  margin: 8px -4px 18px;
  padding: 12px 10px;
  border-radius: 28px;
  background: #f4efec;
}

.week-nav {
  width: 36px;
  height: 58px;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: #6f6260;
  font-size: 42px;
  line-height: 1;
}

.week-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.week-day {
  min-width: 0;
  height: 70px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: #b0a3a0;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
}

.week-day span {
  font-size: 13px;
  font-weight: 700;
}

.week-day b {
  font-size: 22px;
  line-height: 1;
}

.week-day i {
  width: 7px;
  height: 7px;
  border-radius: 999px;
}

.week-day .today-dot { background: #ffb7c0; }
.week-day .has-dot { background: #ffd96a; }

.week-day.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 10px 18px rgba(43, 37, 37, .08);
}

.diary-paper {
  min-height: calc(100vh - 230px);
  padding: 22px 18px 92px;
  border: 1px solid #eaded7;
  border-radius: 28px;
  background:
    repeating-linear-gradient(to bottom, transparent 0 66px, #efe5df 67px, transparent 68px),
    #fffdf8;
  box-shadow: 0 10px 24px rgba(92, 60, 52, .08);
}

.diary-summary {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
}

.diary-icon {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #fff0f2;
  color: #9a6b65;
  font-size: 27px;
  font-weight: 900;
}

.diary-summary h3 {
  margin: 0;
  font-size: 21px;
  line-height: 1.25;
}

.diary-summary p {
  margin: 8px 0 0;
  color: #9a8a86;
  font-size: 15px;
  font-weight: 700;
}

.sticker-wall {
  display: grid;
  gap: 30px;
  padding-top: 4px;
}

.food-sticker {
  width: 86%;
  display: grid;
  grid-template-columns: 124px 1fr;
  align-items: center;
  gap: 16px;
}

.food-sticker.right {
  justify-self: end;
  grid-template-columns: 1fr 124px;
  text-align: right;
}

.food-sticker.right .sticker-img {
  grid-column: 2;
  grid-row: 1;
}

.food-sticker.right .sticker-text {
  grid-column: 1;
  grid-row: 1;
}

.sticker-img {
  width: 112px;
  height: 112px;
  object-fit: cover;
  border: 5px solid #fff;
  border-radius: 22px;
  background: #fff1eb;
  box-shadow: 0 12px 18px rgba(70, 42, 34, .14);
}

.sticker-text span {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff4f2;
  color: #9a6b65;
  font-size: 12px;
  font-weight: 800;
}

.sticker-text h3 {
  margin: 10px 0 6px;
  color: #6a4a46;
  font-size: 19px;
  line-height: 1.25;
}

.sticker-text p {
  margin: 0;
  color: #b8aaa6;
  font-size: 18px;
  font-weight: 900;
}

.diary-empty {
  min-height: 420px;
  display: grid;
  justify-items: center;
  align-content: center;
  text-align: center;
}

.diary-empty div {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: #fff;
  font-size: 34px;
}

.diary-empty h2 {
  margin: 18px 0 8px;
}

.diary-empty p {
  margin: 0;
  color: var(--sub);
}

.diary-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(520px, 100vw);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr 1.45fr 1fr;
  align-items: center;
  gap: 10px;
  height: calc(86px + env(safe-area-inset-bottom));
  padding: 10px 24px calc(10px + env(safe-area-inset-bottom));
  background: #fff;
  box-shadow: 0 -8px 18px rgba(43, 37, 37, .08);
}

.diary-tab {
  border: 0;
  background: transparent;
  color: #9c8b87;
  font-weight: 800;
  display: grid;
  justify-items: center;
  gap: 5px;
}

.diary-tab.active {
  color: var(--text);
}

.diary-tab span {
  font-size: 14px;
}

.diary-camera {
  height: 58px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 900;
}

.calendar-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
  background: rgba(43, 37, 37, .22);
}

.calendar-sheet {
  width: min(520px, 100vw);
  max-height: 82vh;
  margin: 0 auto;
  padding: 18px 18px calc(22px + env(safe-area-inset-bottom));
  border-radius: 26px 26px 0 0;
  background: #fffdfb;
  box-shadow: 0 -12px 24px rgba(43, 37, 37, .12);
}

.calendar-head {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  margin-bottom: 14px;
}

.calendar-head strong {
  text-align: center;
  font-size: 20px;
}

.calendar-head button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  font-size: 28px;
}

.calendar-week,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.calendar-week {
  margin-bottom: 8px;
  color: var(--weak);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
}

.calendar-cell {
  min-height: 58px;
  padding: 5px;
  border: 1px solid #eee2de;
  border-radius: 15px;
  background: #fff;
  color: var(--text);
}

.calendar-cell.muted {
  opacity: .35;
}

.calendar-cell.selected {
  border-color: #ffd96a;
  background: #fff8db;
}

.calendar-cell b {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.calendar-cell div {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.calendar-cell img,
.calendar-cell div span {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  object-fit: cover;
}

.calendar-cell div span {
  display: grid;
  place-items: center;
  background: #fff0f2;
  color: #9a6b65;
  font-size: 10px;
  font-weight: 800;
}

.empty-state {
  min-height: calc(100vh - 90px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
}

.empty-icon {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: #fff;
  font-size: 34px;
}

.empty-state h2 {
  margin: 18px 0 8px;
}

.empty-state p {
  color: var(--sub);
}

.primary-small {
  margin-top: 14px;
  min-width: 120px;
  height: 44px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.profile-form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--sub);
  font-size: 14px;
  font-weight: 700;
}

.field input, .field select {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.toast {
  position: fixed;
  left: 20px;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 100;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(43, 37, 37, .92);
  color: #fff;
  text-align: center;
}
