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

:root {
  --bg: #FFF7F0;
  --card: #FFFFFF;
  --ink: #4A3629;
  --ink-2: #8C7362;
  --ink-3: #BCA68F;
  --brand: #FF7D5C;
  --brand-2: #FFB25E;
  --line: #F3E4D6;
  --shadow: 0 12px 30px rgba(255, 125, 92, .18);
  --radius: 22px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: #F3E7DC;
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

.phone {
  position: relative;
  width: 100%;
  max-width: 430px;
  /* dvh 兜底：老浏览器（旧 WebView / 低版本 Safari）不支持 dvh 时退回 vh */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(260px 180px at 88% -6%, #FFE7CE 0%, rgba(255, 231, 206, 0) 70%),
    radial-gradient(200px 160px at -10% 12%, #FFE3D3 0%, rgba(255, 227, 211, 0) 70%),
    var(--bg);
}

@media (min-width: 431px) {
  body { padding: 0; }
  .phone { box-shadow: 0 0 60px rgba(120, 80, 50, .18); }
}

/* ========== 顶部 ========== */
.app-header {
  padding: calc(14px + env(safe-area-inset-top)) 20px 10px;
  flex: none;
}

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

.brand-logo {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  font-size: 24px;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  border-radius: 15px;
  box-shadow: 0 6px 14px rgba(255, 125, 92, .35);
}

.brand-text h1 { font-size: 19px; font-weight: 800; letter-spacing: .5px; }
.brand-text p { font-size: 12px; color: var(--ink-2); margin-top: 2px; }

/* ========== 筛选 chips ========== */
.chips {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 4px 16px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 15px;
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 3px 10px rgba(120, 80, 50, .06);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
  user-select: none;
}
.chip:active { transform: scale(.94); }
.chip.active {
  background: linear-gradient(120deg, var(--brand-2), var(--brand));
  color: #fff;
  box-shadow: 0 6px 14px rgba(255, 125, 92, .35);
}
.chip input[type="date"] {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* ========== 内容 ========== */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 4px 16px calc(96px + env(safe-area-inset-bottom));
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

/* ---- Hero 卡片 ---- */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  padding: 26px 22px 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-2) 0%, var(--brand) 60%, #FF6B4A 100%);
  box-shadow: var(--shadow);
}
.hero::before {
  content: "";
  position: absolute;
  width: 150px; height: 150px;
  right: -50px; top: -60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
}
.hero::after {
  content: "☁️";
  position: absolute;
  right: 22px; top: 20px;
  font-size: 42px;
  opacity: .4;
  transform: rotate(12deg);
}

.hero-kicker {
  font-size: 13px;
  letter-spacing: 1px;
  opacity: .92;
  font-weight: 600;
}
.hero-big {
  margin-top: 8px;
  font-size: 62px;
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}
.hero-sub {
  margin-top: 6px;
  font-size: 13.5px;
  opacity: .95;
}

.hero-stats {
  margin-top: 20px;
  display: flex;
  background: rgba(255, 255, 255, .18);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 18px;
  padding: 12px 4px 10px;
  backdrop-filter: blur(4px);
}
.hero-stats .st { flex: 1; text-align: center; }
.hero-stats b { display: block; font-size: 22px; font-weight: 800; line-height: 1.2; }
.hero-stats span { font-size: 11px; opacity: .88; }

/* 无记录 hero */
.hero.hero--empty { text-align: center; padding: 34px 22px 28px; }
.hero--empty::after { content: none; }
.hero--empty .empty-emoji { font-size: 58px; animation: bob 2.2s ease-in-out infinite; }
.hero--empty .hero-title {
  margin-top: 10px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.5;
}
.hero--empty .hero-sub { margin-top: 6px; opacity: .92; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

/* ---- 区段标题 ---- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 22px 4px 12px;
}
.section-head h2 { font-size: 17px; font-weight: 800; }
.section-head h2::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); margin-right: 7px; }
.section-head .meta { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---- 时间线 ---- */
.timeline { list-style: none; }
.meal { display: flex; }
.rail {
  flex: none;
  width: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.rail .dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 4px #FFE1D2;
  margin-top: 22px;
  flex: none;
}
.rail .ln { flex: 1; width: 2px; background: var(--line); margin-top: 6px; min-height: 8px; }
.meal:last-child .rail .ln { display: none; }

.meal-body { flex: 1; padding: 0 0 12px 8px; min-width: 0; }
.meal-card {
  background: var(--card);
  border-radius: 18px;
  padding: 13px 15px;
  box-shadow: 0 6px 16px rgba(120, 80, 50, .06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.meal-time { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.meal-phase { font-size: 11.5px; color: var(--ink-2); margin-top: 2px; }
.meal-badges { text-align: right; flex: none; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--brand);
  background: #FFEEE5;
  padding: 4px 9px;
  border-radius: 999px;
  margin: 2px 0;
}
.badge.weak { color: var(--ink-2); background: #F6F1EB; font-weight: 600; }

/* ---- 空态 ---- */
.empty-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 30px 20px;
  text-align: center;
  box-shadow: 0 6px 16px rgba(120, 80, 50, .06);
}
.empty-card .e-emoji { font-size: 42px; }
.empty-card p { margin-top: 10px; font-size: 14px; color: var(--ink-2); }
.empty-card .btn-main { margin-top: 16px; }

/* ---- 加载骨架屏 ---- */
.sk { border-radius: 12px; background: linear-gradient(100deg, #F0E4D8 40%, #FBF2EA 50%, #F0E4D8 60%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.hero.hero--loading { background: linear-gradient(135deg, #F6C49A, #F6A98F); }
.hero--loading .sk { background: rgba(255, 255, 255, .45); }
.sk-big { width: 55%; height: 56px; margin-top: 14px; border-radius: 14px; }
.sk-line { height: 14px; margin-top: 12px; }
.sk-stats { height: 62px; margin-top: 18px; border-radius: 18px; }
.sk-card { height: 64px; margin-top: 14px; }

/* ---- 错误卡 ---- */
.error-card .e-emoji { font-size: 40px; }
.error-card p { color: var(--brand); word-break: break-all; padding: 0 6px; }

/* ---- 按钮禁用 ---- */
.btn:disabled { opacity: .6; transform: none !important; }

/* ========== 浮窗 ========== */
.fab {
  position: absolute;
  right: 18px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 14px 20px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--brand-2), var(--brand));
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: .5px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(255, 110, 70, .45);
  transition: transform .15s ease;
}
.fab:active { transform: scale(.93); }

/* ========== 弹窗 ========== */
/* fixed 铺满整个视口，脱离 .phone 容器限制，保证任何浏览器遮罩都全屏 */
.modal-mask {
  position: fixed;
  left: 0; top: 0;
  width: 100%;
  height: 100vh; /* dvh 兜底 */
  height: 100dvh;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(56, 36, 24, .45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fadeIn .18s ease;
}
.modal-mask[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 330px;
  /* 矮屏 / 横屏时弹窗可滚动，避免超出可视区 */
  max-height: calc(100vh - 48px); /* dvh 兜底 */
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border-radius: 26px;
  padding: 26px 22px 20px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(56, 36, 24, .3);
  animation: pop .22s cubic-bezier(.34, 1.56, .64, 1);
}
.modal-emoji {
  width: 68px; height: 68px;
  margin: 0 auto;
  display: grid; place-items: center;
  font-size: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FFE9D6, #FFD9C4);
  animation: bob 2.2s ease-in-out infinite;
}
.modal-title { margin-top: 14px; font-size: 19px; font-weight: 800; }
.modal-desc { margin-top: 8px; font-size: 13.5px; color: var(--ink-2); line-height: 1.7; }
.modal-desc b { color: var(--brand); font-size: 15px; font-variant-numeric: tabular-nums; }

/* 两个按钮用 margin 拉开间距：不用 flex gap，兼容旧内核/小屏 WebView */
.modal-actions { display: flex; margin-top: 22px; }
.modal-actions .btn + .btn { margin-left: 12px; }
.btn {
  flex: 1;
  height: 50px;
  border: none;
  border-radius: 16px;
  font-size: 15.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
}
.btn:active { transform: scale(.95); }
.btn-ghost { background: #F5EDE6; color: var(--ink-2); }
.btn-main { background: linear-gradient(120deg, var(--brand-2), var(--brand)); color: #fff; box-shadow: 0 8px 18px rgba(255, 125, 92, .35); }

@keyframes pop { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: scale(1); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ========== Toast ========== */
.toast {
  position: absolute;
  left: 50%;
  top: 74px;
  z-index: 80;
  transform: translateX(-50%);
  background: rgba(60, 42, 30, .92);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .18);
  animation: toastIn .25s cubic-bezier(.34, 1.56, .64, 1);
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }
