/* ===== 基础变量与重置 ===== */
:root {
  --primary: #ff7a59;
  --primary-dark: #e8603f;
  --primary-soft: #fff1ec;
  --pink: #ff5c8a;
  --pink-soft: #ffe4ec;
  --bg: #fff8f3;
  --card: #ffffff;
  --text: #2d2320;
  --muted: #9b8c86;
  --line: #f1e4dd;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(190, 110, 80, 0.12);
  --row-h: 84px;
  --tabbar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: #f3e9e3;
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

button, input {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}
button { cursor: pointer; user-select: none; -webkit-user-select: none; }
input[type="date"], input[type="number"] { -webkit-appearance: none; appearance: none; }
input[type="number"] { -moz-appearance: textfield; }
ul { list-style: none; }
[hidden] { display: none !important; }

/* ===== 应用容器：手机全屏，桌面居中像 App ===== */
#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  overflow-x: hidden;
}
@media (min-width: 520px) {
  body { padding: 24px 0; background: linear-gradient(160deg, #fde9df, #f6d9d0); }
  #app {
    min-height: calc(100dvh - 48px);
    max-height: 900px;
    border-radius: 32px;
    box-shadow: 0 30px 80px rgba(120, 60, 40, 0.25);
    overflow: hidden;
  }
  .page { overflow-y: auto; }
}

/* ===== 页面切换 ===== */
.page {
  display: none;
  flex-direction: column;
  padding: 20px 18px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  min-height: 100vh;
  min-height: 100dvh;
  will-change: transform, opacity;
}
.page-active { display: flex; }
.page-enter { animation: pageIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both; }
.page-leave { animation: pageOut 0.18s ease-in both; }
@keyframes pageIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes pageOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(-12px); } }

.page-header { margin-bottom: 18px; }
.page-header h1 { font-size: 26px; font-weight: 800; letter-spacing: 0.5px; }
.page-header p { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* ===== 首页头部 ===== */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.greeting h1 { font-size: 26px; font-weight: 800; }
.greeting p { color: var(--muted); font-size: 14px; margin-top: 2px; }
.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--primary), var(--pink));
  display: grid;
  place-items: center;
  font-size: 26px;
  box-shadow: 0 6px 16px rgba(255, 122, 89, 0.35);
  animation: breathe 3.2s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }

/* ===== 经期横幅 ===== */
.period-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--pink-soft), #fff0f4);
  border: 1px solid #ffd3df;
  animation: bannerIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.period-banner.pre { background: linear-gradient(135deg, #fff4e5, #fff9f0); border-color: #ffe0b8; }
@keyframes bannerIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.period-banner-icon { font-size: 24px; }
.period-banner-text { flex: 1; display: flex; flex-direction: column; }
.period-banner-text strong { font-size: 15px; }
.period-banner-text small { color: var(--muted); font-size: 12px; }
.period-banner-link { color: var(--pink); font-size: 13px; font-weight: 600; padding: 6px 8px; }

/* ===== 餐次切换 ===== */
.meal-tabs {
  display: flex;
  gap: 6px;
  padding: 5px;
  background: #f4e8e1;
  border-radius: 999px;
  margin-bottom: 16px;
}
.meal-tab {
  flex: 1;
  padding: 9px 0;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), background 0.2s, color 0.2s, box-shadow 0.2s;
}
.meal-tab:active { transform: scale(0.94); }
.meal-tab.active {
  background: var(--card);
  color: var(--primary-dark);
  box-shadow: 0 3px 8px rgba(190, 110, 80, 0.18);
}

/* ===== 老虎机 ===== */
.slot-card {
  background: var(--card);
  border-radius: 24px;
  padding: 18px 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.slot-window {
  position: relative;
  height: calc(var(--row-h) * 3);
  overflow: hidden;
  border-radius: 16px;
  background: linear-gradient(180deg, #fff8f4, #fff3ee);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.slot-highlight {
  position: absolute;
  left: 8px;
  right: 8px;
  top: var(--row-h);
  height: var(--row-h);
  border-radius: 14px;
  background: var(--primary-soft);
  border: 2px dashed #ffc9b8;
  z-index: 1;
  pointer-events: none;
}
.slot-strip {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 2;
  will-change: transform;
  transform: translate3d(0, 0, 0);
}
.slot-item {
  height: var(--row-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 24px;
  font-weight: 700;
  color: #6b5a54;
  white-space: nowrap;
}
.slot-item .e { font-size: 32px; }
.slot-item.hit { color: var(--primary-dark); }
.slot-item.hit .e { animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
@keyframes pop { from { transform: scale(0.6); } to { transform: scale(1); } }
.slot-fade {
  position: absolute;
  left: 0;
  right: 0;
  height: 44px;
  z-index: 3;
  pointer-events: none;
}
.slot-fade-top { top: 0; background: linear-gradient(180deg, #fff8f4, rgba(255, 248, 244, 0)); }
.slot-fade-bottom { bottom: 0; background: linear-gradient(0deg, #fff3ee, rgba(255, 243, 238, 0)); }

.spin-btn {
  width: 100%;
  margin-top: 16px;
  padding: 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--pink));
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1px;
  box-shadow: 0 10px 24px rgba(255, 110, 90, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.15s, opacity 0.2s;
}
.spin-btn:active { transform: scale(0.97); box-shadow: 0 6px 14px rgba(255, 110, 90, 0.3); }
.spin-btn:disabled { opacity: 0.75; }
.spin-btn.spinning .spin-btn-icon { animation: dice 0.8s linear infinite; }
.spin-btn.spinning .spin-btn-text { animation: pulse 0.8s ease-in-out infinite; }
@keyframes dice { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ===== 结果卡片 ===== */
.result-card {
  position: relative;
  overflow: hidden;
  background: var(--card);
  border-radius: 24px;
  padding: 24px 20px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  animation: resultIn 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
@keyframes resultIn { from { opacity: 0; transform: translateY(20px) scale(0.92); } to { opacity: 1; transform: none; } }
.result-emoji { font-size: 56px; line-height: 1; animation: pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s both; }
.result-name { font-size: 28px; font-weight: 800; margin-top: 8px; }
.result-tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 8px; }
.result-tip { color: var(--muted); font-size: 14px; margin-top: 10px; min-height: 21px; }
.result-actions { display: flex; gap: 10px; margin-top: 16px; }

.btn {
  flex: 1;
  padding: 14px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  transition: transform 0.15s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.15s, background 0.15s;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--pink)); color: #fff; box-shadow: 0 8px 18px rgba(255, 110, 90, 0.3); }
.btn-ghost { background: var(--primary-soft); color: var(--primary-dark); }
.btn-sm { flex: none; padding: 10px 16px; font-size: 14px; }
.btn-block { width: 100%; flex: none; }

/* 彩纸 */
.confetti { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.confetti i {
  position: absolute;
  left: 50%;
  top: 40%;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  opacity: 0;
  animation: confettiFly 0.9s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}
@keyframes confettiFly {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); }
}

/* ===== 今日已选 ===== */
.today-card { background: var(--card); border-radius: 20px; padding: 16px; box-shadow: var(--shadow); }
.today-card h3 { font-size: 15px; margin-bottom: 10px; }
.today-list { display: flex; flex-wrap: wrap; gap: 8px; }
.today-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-dark);
  animation: bannerIn 0.3s both;
}
.today-item small { color: var(--muted); font-weight: 400; }

/* ===== 通用卡片与表单 ===== */
.card {
  background: var(--card);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card h3 { font-size: 16px; margin-bottom: 10px; }
.muted { color: var(--muted); font-size: 13px; margin-bottom: 10px; }

.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  background: #faf3ef;
  border: 1.5px solid transparent;
  font-size: 16px; /* iOS Safari 字号 < 16px 聚焦时会自动放大页面 */
  text-align: left;
  transition: border 0.2s, background 0.2s;
}
.input:focus { border-color: var(--primary); background: #fff; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 20px;
  font-weight: 700;
  flex: none;
  transition: transform 0.12s;
}
.stepper button:active { transform: scale(0.9); }
.stepper .input { text-align: center; padding: 10px 4px; }

/* ===== 菜单页 ===== */
.add-card {
  background: var(--card);
  border-radius: 20px;
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.add-row { display: flex; gap: 8px; }
.input-emoji { width: 58px; flex: none; text-align: center; padding: 12px 4px; font-size: 20px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: #f4e8e1;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.15s, background 0.15s, color 0.15s;
}
.chip:active { transform: scale(0.92); }
.chip.active { background: var(--primary-soft); color: var(--primary-dark); }
.chip-tag.active { background: var(--pink-soft); color: var(--pink); }

.dish-list { display: flex; flex-direction: column; gap: 8px; }
.dish-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  padding: 10px 12px;
  border-radius: 16px;
  box-shadow: 0 3px 10px rgba(190, 110, 80, 0.08);
  transition: opacity 0.25s, transform 0.25s;
  animation: bannerIn 0.3s both;
}
.dish-item.excluded { opacity: 0.45; }
.dish-item.removing { opacity: 0; transform: translateX(40px); }
.dish-emoji { font-size: 26px; width: 36px; text-align: center; flex: none; }
.dish-info { flex: 1; min-width: 0; }
.dish-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dish-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.dish-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 18px;
  background: #faf3ef;
  transition: transform 0.15s, background 0.15s;
}
.icon-btn:active { transform: scale(0.85); }
.icon-btn.fav { background: var(--pink-soft); }
.icon-btn.excl { background: #eee; filter: grayscale(1); opacity: 0.7; }
.icon-btn.excl.on { background: #fde2e2; filter: none; opacity: 1; }

/* ===== 姨妈页 ===== */
.period-status-card {
  background: linear-gradient(135deg, var(--pink), #ff8fab);
  color: #fff;
  border-radius: 24px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 14px 30px rgba(255, 92, 138, 0.35);
  margin-bottom: 14px;
}
.period-big { font-size: 44px; font-weight: 800; line-height: 1.1; letter-spacing: -1px; }
.period-label { font-size: 16px; font-weight: 600; margin-top: 6px; opacity: 0.95; }
.period-hint { font-size: 13px; margin-top: 6px; opacity: 0.85; }
.period-status-card.pre { background: linear-gradient(135deg, #ffa552, #ff7e5f); box-shadow: 0 14px 30px rgba(255, 150, 90, 0.35); }
.period-status-card.none { background: linear-gradient(135deg, #c9b8b1, #a99690); box-shadow: 0 14px 30px rgba(150, 120, 110, 0.25); }

.calendar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.calendar-head strong { font-size: 16px; }
.cal-nav { width: 36px; height: 36px; border-radius: 12px; background: #faf3ef; font-size: 22px; color: var(--primary-dark); }
.calendar-week, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.calendar-week span { font-size: 12px; color: var(--muted); padding: 6px 0; }
.calendar-grid { gap: 4px 0; }
.cal-day {
  position: relative;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 14px;
  border-radius: 12px;
  z-index: 0;
}
.cal-day.empty { pointer-events: none; }
.cal-day.period { color: #fff; font-weight: 700; }
.cal-day.period::before {
  content: "";
  position: absolute;
  inset: 3px 2px;
  border-radius: 12px;
  background: var(--pink);
  z-index: -1;
}
.cal-day.predict { color: var(--pink); font-weight: 700; }
.cal-day.predict::before {
  content: "";
  position: absolute;
  inset: 3px 2px;
  border-radius: 12px;
  border: 1.5px dashed var(--pink);
  z-index: -1;
}
.cal-day.today { color: var(--primary-dark); font-weight: 800; }
.cal-day.today::after {
  content: "";
  position: absolute;
  bottom: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary-dark);
}
.cal-day.period.today::after, .cal-day.predict.today::after { background: currentColor; }
.calendar-legend { display: flex; justify-content: center; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.dot-period { background: var(--pink); }
.dot-predict { border: 1.5px dashed var(--pink); }
.dot-today { background: var(--primary-dark); border-radius: 50%; }
.tips-list { display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: #5a4d48; }

/* ===== 设置页 ===== */
.emoji-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-picker button {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: #faf3ef;
  font-size: 24px;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
}
.emoji-picker button.active { background: var(--primary-soft); box-shadow: 0 0 0 2px var(--primary) inset; transform: scale(1.08); }
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 15px;
  cursor: pointer;
}
.switch-row input { display: none; }
.switch {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: #e5d8d1;
  transition: background 0.2s;
  flex: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
.switch-row input:checked + .switch { background: var(--primary); }
.switch-row input:checked + .switch::after { transform: translateX(20px); }
.danger-card .btn { color: #c94b4b; background: #fdecec; }
.footer { text-align: center; color: var(--muted); font-size: 13px; margin-top: 8px; }

/* ===== 底部导航 ===== */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 50;
}
@media (min-width: 520px) {
  .tabbar { bottom: 24px; border-radius: 0 0 32px 32px; max-height: 900px; }
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  transition: color 0.2s, transform 0.2s;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1); }
.tab.active { color: var(--primary-dark); }
.tab.active svg { transform: translateY(-2px) scale(1.1); }
.tab:active svg { transform: scale(0.9); }

/* ===== 轻提示 ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  transform: translateX(-50%) translateY(16px);
  background: rgba(45, 35, 32, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 100;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 减少动态效果 ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
