:root {
  --bg: #FAF7F2;
  --surface: #ffffff;
  --line: #EFEADC;
  --line-strong: #E8E2D4;
  --ink: #2e2a22;
  --ink-2: #3a352c;
  --muted: #5c5648;
  --faint: #a39c8c;
  --accent: #A8703F;
  --accent-soft: #FBF1E4;
  --danger: #a35c4a;
  --radius: 14px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-2);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 20px calc(60px + env(safe-area-inset-bottom));
}
.wrap--narrow { max-width: 660px; }

.loading { color: var(--faint); text-align: center; margin-top: 60px; }

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
h1 {
  font-size: clamp(24px, 5vw, 30px);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0;
}
.sub { font-size: 14px; color: var(--faint); margin: 4px 0 0; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-bottom: 16px;
}
.back:hover { text-decoration: underline; }

/* ---------- controls ---------- */
.searchbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.searchbar input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: none;
  font-size: 16px;
  color: var(--ink-2);
}
.searchbar .icon { color: var(--faint); flex-shrink: 0; display: flex; }
.iconbtn {
  border: none;
  background: #F0EBDD;
  border-radius: 6px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
  padding: 0;
}

.chips { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- primary bar ---------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  margin-bottom: 18px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
}
.bar strong { font-weight: 600; }
.bar span { font-size: 13px; opacity: .9; }

/* ---------- gallery ---------- */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.tile {
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  overflow: hidden;
  transition: transform .12s ease, box-shadow .12s ease;
}
@media (hover: hover) {
  .tile:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(80,60,30,.10); }
}
.tile__img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--accent-soft);
}
.tile__body { padding: 10px 12px 12px; }
.tile__title { font-size: 14px; font-weight: 600; color: var(--ink); line-height: 1.3; }
.tile__zh { font-size: 12px; color: var(--faint); margin-top: 3px; }
.tags { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }
.tag {
  font-size: 11px;
  background: #F5F1E6;
  color: #8a7a5c;
  padding: 2px 8px;
  border-radius: 999px;
}

.empty { color: var(--faint); text-align: center; margin-top: 40px; }

/* ---------- detail ---------- */
.hero {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 16px;
  display: block;
  margin-bottom: 20px;
  background: var(--accent-soft);
}
.badge {
  display: inline-block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 4px 10px;
  margin-bottom: 10px;
}
.zh { font-size: 15px; color: var(--faint); margin: 4px 0 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn--solid { background: var(--accent); color: #fff; }

.section { margin-top: 26px; }
.section h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--faint);
  margin: 0 0 10px;
  font-weight: 600;
}

.servings {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  margin-top: 20px;
  font-size: 14px;
  color: var(--muted);
}
.servings .stepper { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.servings button {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  font-size: 17px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}
.servings .count { min-width: 54px; text-align: center; font-weight: 600; color: var(--ink); }

.ings { list-style: none; padding: 0; margin: 0; }
.ings li {
  display: flex;
  gap: 12px;
  font-size: 15px;
  padding: 9px 0;
  border-bottom: 1px solid #F0EBDD;
}
.ings .amt { min-width: 96px; font-weight: 600; color: var(--accent); flex-shrink: 0; }

.steps { padding-left: 20px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.steps li { font-size: 15px; line-height: 1.55; }

.notes {
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
  margin: 0;
  background: var(--accent-soft);
  border: 1px solid #EFE3D0;
  border-radius: 12px;
  padding: 12px 14px;
}

/* ---------- week planner ---------- */
.weekgrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 16px;
}
@media (min-width: 700px) { .weekgrid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .weekgrid { grid-template-columns: repeat(3, 1fr); } }

.day {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.day__name { font-size: 15px; font-weight: 700; color: var(--ink); margin-bottom: 10px; }
.meal { margin-bottom: 12px; }
.meal:last-child { margin-bottom: 0; }
.meal__name {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--faint);
  margin-bottom: 6px;
}
.slot {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border-radius: 10px;
  padding: 6px 8px;
  margin-bottom: 6px;
}
.slot img { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.slot__name {
  font-size: 13px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slot__x {
  border: none;
  background: none;
  color: var(--faint);
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
  line-height: 1;
}
.addslot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px dashed #D8CFBB;
  background: none;
  color: var(--accent);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
}
.addslot--pending {
  border-style: solid;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pending {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--accent-soft);
  border: 1px solid #E8D7BF;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 16px;
}
.pending img { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.pending__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
}
.pending__title { font-size: 14px; font-weight: 600; color: var(--ink); margin-top: 2px; }
.pending button {
  border: 1px solid #D8CFBB;
  background: var(--surface);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ---------- shopping list ---------- */
.check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid #F0EBDD;
  cursor: pointer;
}
.check--done { opacity: .4; }
.check--done .check__name { text-decoration: line-through; }
.box {
  width: 21px;
  height: 21px;
  border-radius: 6px;
  border: 2px solid #D8CFBB;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  line-height: 1;
}
.check--done .box { background: var(--accent); border-color: var(--accent); }
.check__name { font-size: 15px; font-weight: 600; color: var(--ink); text-transform: capitalize; }
.check__detail { font-size: 13px; color: var(--faint); margin-top: 2px; }
.check__detail .for { color: #c0b8a6; }

.danger {
  width: 100%;
  margin-top: 22px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--danger);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.rowbtns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.rowbtns .danger, .rowbtns .btn { margin-top: 0; width: auto; flex: 1; justify-content: center; }

/* ---------- picker sheet ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
@media (min-width: 700px) { .overlay { align-items: center; justify-content: center; } }

.sheet {
  background: var(--bg);
  width: 100%;
  max-height: 78vh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (min-width: 700px) {
  .sheet { max-width: 560px; border-radius: 18px; max-height: 76vh; }
}
.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.sheet__controls { padding: 12px 16px 2px; border-bottom: 1px solid var(--line); }
.sheet__controls .chips { margin-bottom: 12px; }
.sheet__list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pick {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  text-align: left;
}
.pick img {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--accent-soft);
}
.pick__title { font-size: 14px; font-weight: 600; color: var(--ink); }
.pick__zh { font-size: 12px; color: var(--faint); margin-top: 2px; }

@media print {
  .bar, .back, .chips, .searchbar, .danger, .rowbtns { display: none !important; }
  body { background: #fff; }
}
