:root {
  --paper: #FBF6EE;
  --card: #FFFDF8;
  --porcelain: #FFF7EC;
  --glaze: #F1E2CC;
  --kraft: #F3E9DA;
  --ink: #2B2420;
  --ink-soft: #6B5E55;
  --tomato: #D9502A;
  --tomato-deep: #BF411E;
  --mustard: #E0A030;
  --leaf: #3F7D4E;
  --sky: #2F6FB0;
  --wobble: 18px 22px 16px 24px / 22px 16px 24px 18px;
  --wobble-sm: 12px 15px 11px 16px / 15px 11px 16px 12px;
  --shadow: 3px 4px 0 rgba(43, 36, 32, 0.14);
  --font-body: 'LXGW WenKai Screen', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --font-title: 'ZCOOL KuaiLe', 'LXGW WenKai Screen', 'PingFang SC', sans-serif;
  --tabbar-h: 68px; /* #tabs：2 边框 + 6 + 54 + 6，不含底部安全区 */
  color-scheme: light;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  background-color: var(--paper);
  background-image: radial-gradient(rgba(43, 36, 32, 0.09) 1px, transparent 1.2px);
  background-size: 18px 18px;
  overscroll-behavior-y: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--mustard); outline-offset: 2px; }
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
[hidden] { display: none !important; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 12px) max(16px, env(safe-area-inset-right))
    calc(env(safe-area-inset-bottom) + var(--tabbar-h) + 28px) max(16px, env(safe-area-inset-left));
}

/* ---------- 顶部 ---------- */
#top { display: flex; align-items: center; gap: 10px; padding: 4px 2px 14px; }
.brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; white-space: nowrap; }
.datenav .day { white-space: nowrap; font-size: 15px; }
.brand svg { width: 38px; height: 38px; flex-shrink: 0; }
.brand b { font-family: var(--font-title); font-size: 26px; font-weight: 400; letter-spacing: 2px; line-height: 1; }
.top-title { font-family: var(--font-title); font-size: 24px; font-weight: 400; margin-left: 4px; }
.datenav { margin-left: auto; display: flex; align-items: center; gap: 0; }
.datenav .day { text-align: center; min-width: 100px; padding: 0 4px; font-weight: 700; line-height: 1.25; }
.datenav .day small { display: block; font-size: 12px; font-weight: 400; color: var(--ink-soft); }
.datenav .day small.is-today { color: var(--tomato-deep); font-weight: 700; }
.iconbtn {
  width: 44px; height: 44px; border: 0; background: none; border-radius: 50%;
  font-size: 22px; line-height: 1; display: grid; place-items: center;
}
.iconbtn:active { background: var(--glaze); }
/* 320px 宽：去掉「食刻」字样、收窄日期，避免顶栏横向溢出 */
@media (max-width: 359px) {
  #top:has(.datenav) .brand b { display: none; }
  .datenav .day { min-width: 0; font-size: 14px; }
}

/* ---------- 卡片 ---------- */
.card {
  position: relative;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: var(--wobble);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 18px;
}
.card h3 { font-family: var(--font-title); font-weight: 400; font-size: 19px; margin-bottom: 8px; }
.tilt-l { transform: rotate(-0.6deg); }
.tilt-r { transform: rotate(0.5deg); }

.tape {
  position: absolute; top: -11px; left: 50%; width: 92px; height: 22px;
  transform: translateX(-50%) rotate(-3deg);
  background: repeating-linear-gradient(135deg, rgba(224, 160, 48, 0.75) 0 8px, rgba(224, 160, 48, 0.5) 8px 16px);
  border-left: 2px dotted rgba(255, 255, 255, 0.8);
  border-right: 2px dotted rgba(255, 255, 255, 0.8);
}
.tape.green { background: repeating-linear-gradient(135deg, rgba(63, 125, 78, 0.6) 0 8px, rgba(63, 125, 78, 0.4) 8px 16px); }
.tape.red { background: repeating-linear-gradient(135deg, rgba(217, 80, 42, 0.65) 0 8px, rgba(217, 80, 42, 0.42) 8px 16px); }

.note { background: #FFF3C9; padding-top: 22px; }
.note .hello { font-size: 17px; }

.muted { color: var(--ink-soft); font-size: 14px; }
.foot { text-align: center; color: var(--ink-soft); font-size: 13px; margin: 8px 0 0; }
.banner {
  background: var(--kraft); border: 1.5px dashed var(--ink-soft); border-radius: var(--wobble-sm);
  padding: 8px 12px; font-size: 14px; margin-bottom: 14px;
}

/* ---------- 标签 ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--ink); background: var(--card); border-radius: 999px;
  padding: 8px 14px; font-size: 15px; line-height: 1.3; min-height: 44px;
  display: inline-flex; align-items: center; gap: 4px;
  transition: transform 0.12s ease;
}
button.chip:active { transform: scale(0.94); }
.chip.on {
  background: var(--tomato-deep); border-color: var(--ink); color: #FFF7EC; font-weight: 700;
  box-shadow: 2px 2px 0 var(--ink); transform: rotate(-1.5deg);
}
.chip.on:nth-child(even) { transform: rotate(1.2deg); }
.chip.static { min-height: 0; padding: 3px 11px; font-size: 13px; background: var(--porcelain); }
.chip.add { border-style: dashed; color: var(--ink-soft); }
.chip .del { margin-left: 2px; opacity: 0.75; }

/* ---------- 三餐 ---------- */
.meal { margin-bottom: 22px; }
.meal-head { display: flex; align-items: baseline; gap: 8px; margin: 0 4px 10px; }
.meal-head h2 {
  font-family: var(--font-title); font-weight: 400; font-size: 23px;
  background: linear-gradient(transparent 62%, rgba(224, 160, 48, 0.5) 62%);
  padding: 0 4px;
}
.meal-head span { color: var(--ink-soft); font-size: 13px; }
.dish {
  display: flex; gap: 14px; align-items: center; width: 100%; text-align: left;
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--wobble);
  box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 12px;
}
.dish:nth-child(odd) { transform: rotate(-0.4deg); }
.dish:nth-child(even) { transform: rotate(0.4deg); }
.dish:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 rgba(43, 36, 32, 0.14); }
.dish .emoji {
  width: 58px; height: 58px; flex-shrink: 0; font-size: 34px; display: grid; place-items: center;
  background: var(--porcelain); border: 2px solid var(--glaze); border-radius: 50%;
}
.dish .info { flex: 1; min-width: 0; }
.dish .name { font-size: 18px; font-weight: 700; line-height: 1.35; }
.dish .meta { font-size: 13px; color: var(--ink-soft); }
.dish .intro { font-size: 14px; color: var(--ink-soft); line-height: 1.45; margin-top: 2px; }
.dish .go { font-size: 20px; color: var(--ink-soft); }
.skipped { color: var(--ink-soft); font-size: 14px; padding: 6px 8px; }

.list li { padding: 5px 0 5px 20px; position: relative; }
.list li::before { content: '✎'; position: absolute; left: 0; color: var(--tomato-deep); font-size: 14px; }

/* ---------- 空状态 ---------- */
.empty { text-align: center; padding: 34px 20px 26px; }
.empty .big { font-size: 60px; line-height: 1.2; }
.empty h2 { font-family: var(--font-title); font-weight: 400; font-size: 23px; margin: 8px 0 6px; }
.empty .chips { justify-content: center; margin: 12px 0; }

/* ---------- 按钮 ---------- */
.btn {
  border: 2px solid var(--ink); border-radius: var(--wobble-sm); background: var(--card);
  padding: 10px 18px; min-height: 46px; font-weight: 700; box-shadow: 2px 3px 0 var(--ink);
}
.btn:active { transform: translate(2px, 3px); box-shadow: none; }
.btn.primary { background: var(--tomato-deep); color: #FFF7EC; }
.btn.block { width: 100%; }
.btn.sm { min-height: 44px; padding: 6px 14px; font-size: 14px; box-shadow: 2px 2px 0 var(--ink); }
.btn[disabled] { opacity: 0.55; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }

/* ---------- 采购 ---------- */
.progress { height: 12px; border: 2px solid var(--ink); border-radius: 99px; background: var(--card); overflow: hidden; margin: 8px 0 2px; }
.progress i { display: block; height: 100%; background: var(--leaf); transition: width 0.25s ease; }
.shop-item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 2px; border-bottom: 1.5px dashed var(--glaze); min-height: 48px; }
.shop-item:last-child { border-bottom: 0; }
.shop-item input {
  appearance: none; -webkit-appearance: none; width: 26px; height: 26px; flex-shrink: 0; margin: 1px 0 0;
  border: 2px solid var(--ink); border-radius: 8px 10px 7px 11px; background: var(--card); display: grid; place-items: center;
}
.shop-item input:checked { background: var(--leaf); }
.shop-item input:checked::after { content: '✓'; color: #fff; font-size: 17px; font-weight: 700; line-height: 1; }
.shop-item .txt { flex: 1; min-width: 0; }
.shop-item .line { display: flex; justify-content: space-between; gap: 10px; }
.shop-item .amt { color: var(--tomato-deep); font-weight: 700; white-space: nowrap; }
.shop-item small { display: block; color: var(--ink-soft); font-size: 13px; line-height: 1.45; }
.shop-item.done .line { text-decoration: line-through; color: var(--ink-soft); }
.shop-item.done .amt { color: var(--ink-soft); }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field label, .label { display: block; font-weight: 700; margin-bottom: 5px; }
.field .hint { font-size: 13px; color: var(--ink-soft); line-height: 1.45; margin-top: 4px; }
.input {
  width: 100%; border: 2px solid var(--ink); border-radius: var(--wobble-sm); background: var(--card);
  padding: 10px 12px; min-height: 46px; font-size: 16px; outline: none;
}
.input:focus { box-shadow: 0 0 0 3px rgba(224, 160, 48, 0.55); }
textarea.input { min-height: 84px; resize: vertical; line-height: 1.55; }
.stepper { display: inline-flex; align-items: center; gap: 12px; }
.stepper b { font-size: 20px; min-width: 28px; text-align: center; }
.seg { display: flex; border: 2px solid var(--ink); border-radius: var(--wobble-sm); overflow: hidden; background: var(--card); }
.seg button { flex: 1; border: 0; background: none; padding: 9px 6px; min-height: 44px; line-height: 1.3; }
.seg button + button { border-left: 2px solid var(--ink); }
.seg button.on { background: var(--ink); color: var(--porcelain); font-weight: 700; }
.seg small { display: block; font-size: 12px; font-weight: 400; opacity: 0.85; }
.mins { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.mins span { display: block; font-size: 13px; color: var(--ink-soft); }
.group { margin-bottom: 18px; }
.group h3 { font-family: var(--font-title); font-weight: 400; font-size: 18px; margin: 0 2px 8px; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h) + 4px); z-index: 5;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); pointer-events: none;
}
.savebar .inner { max-width: 528px; margin: 0 auto; pointer-events: auto; }
.pick-pad { height: 72px; }

/* ---------- 底部导航 ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  background: rgba(251, 246, 238, 0.96); border-top: 2px dashed var(--ink);
  padding: 6px max(8px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 6px) max(8px, env(safe-area-inset-left));
}
#tabs button {
  flex: 1; max-width: 132px; border: 0; background: none; border-radius: var(--wobble-sm);
  padding: 4px 0 3px; min-height: 54px; font-size: 13px; line-height: 1.3; color: var(--ink-soft);
}
#tabs button .ico { display: block; font-size: 24px; line-height: 1.2; filter: grayscale(0.6); opacity: 0.8; }
#tabs button.on { color: var(--ink); font-weight: 700; background: var(--glaze); }
#tabs button.on .ico { filter: none; opacity: 1; transform: rotate(-6deg) scale(1.08); }

/* ---------- 菜谱详情 ---------- */
#sheet { position: fixed; inset: 0; z-index: 20; overscroll-behavior: contain; }
.sheet-bg { position: absolute; inset: 0; background: rgba(43, 36, 32, 0.45); touch-action: none; }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto;
  max-height: calc(100vh - env(safe-area-inset-top) - 24px);
  max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
  overflow-y: auto; overscroll-behavior: contain;
  background-color: var(--paper);
  background-image: linear-gradient(rgba(47, 111, 176, 0.1) 1px, transparent 1px);
  background-size: 100% 30px;
  border: 2px solid var(--ink); border-bottom: 0; border-radius: 26px 22px 0 0;
  padding: 20px max(18px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 28px) max(18px, env(safe-area-inset-left));
  animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-body .x { position: sticky; top: 0; float: right; z-index: 2; background: var(--card); border: 2px solid var(--ink); font-size: 16px; }
.hero { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; }
.hero .emoji {
  width: 76px; height: 76px; font-size: 44px; display: grid; place-items: center; flex-shrink: 0;
  background: var(--porcelain); border: 2px solid var(--ink); border-radius: 50%; box-shadow: var(--shadow);
}
.hero h2 { font-family: var(--font-title); font-weight: 400; font-size: 26px; line-height: 1.25; }
.sheet-body h3 { font-family: var(--font-title); font-weight: 400; font-size: 20px; margin: 20px 0 8px; }
.ing { background: var(--card); border: 2px solid var(--ink); border-radius: var(--wobble); padding: 4px 14px; }
.ing li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1.5px dashed var(--glaze); }
.ing li:last-child { border-bottom: 0; }
.ing li span:last-child { color: var(--tomato-deep); font-weight: 700; text-align: right; }
.ing small { color: var(--ink-soft); font-weight: 400; }
.steps { counter-reset: step; }
.steps li { counter-increment: step; position: relative; padding: 0 0 16px 44px; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0; width: 32px; height: 32px;
  display: grid; place-items: center; font-family: var(--font-title); font-size: 18px;
  background: var(--mustard); border: 2px solid var(--ink); border-radius: 50% 46% 52% 48%;
}
.steps .tip {
  display: block; margin-top: 6px; font-size: 14px; color: var(--ink); line-height: 1.5;
  background: #FFF3C9; border-radius: var(--wobble-sm); padding: 6px 10px;
}
.steps .time { color: var(--ink-soft); font-size: 13px; white-space: nowrap; }
.fb { display: flex; gap: 10px; margin-top: 22px; }
.fb .btn { flex: 1; }
.fb .btn.on { background: var(--ink); color: var(--porcelain); }

/* ---------- 提示条 ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 140px); z-index: 30;
  transform: translateX(-50%) translateY(10px); width: max-content; max-width: 86vw;
  background: var(--ink); color: var(--porcelain); padding: 9px 18px; border-radius: 99px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- 由 app.js 切换的状态 ---------- */
/* 详情页打开：锁住背后的页面。iOS 16+ 认根元素上的 overflow；
   遮罩 touch-action:none + 弹层 overscroll-behavior:contain 兜住拖动穿透。 */
html:has(body.sheet-open), body.sheet-open { overflow: hidden; }
/* 键盘弹起：固定的底栏会顶到键盘上方挡住输入框，先藏起来。 */
body.kb-open #tabs, body.kb-open .savebar { display: none; }

.loading { text-align: center; padding: 60px 0; color: var(--ink-soft); }
.loading .spin { display: inline-block; font-size: 40px; animation: wiggle 1s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(-12deg); } 50% { transform: rotate(12deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
