:root {
  --bg: #fdf8f4;
  --card: #ffffff;
  --text: #2b2320;
  --muted: #8d817a;
  --accent: #e8590c;
  --accent-soft: #fff1e8;
  --line: #efe4db;
  --danger: #c92a2a;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(70, 45, 25, .07);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130f;
    --card: #221d19;
    --text: #f3ece7;
    --muted: #a99c93;
    --accent: #ff8a3d;
    --accent-soft: #2f2218;
    --line: #342b25;
    --shadow: 0 2px 12px rgba(0, 0, 0, .35);
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

input, textarea, button, select { font: inherit; color: inherit; }

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 14px calc(90px + env(safe-area-inset-bottom));
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
  margin: 0 -14px;
  padding-left: 14px;
  padding-right: 14px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  min-width: 38px;
  height: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn:active { background: var(--accent-soft); }

/* ---------- 搜索 ---------- */
.searchbar { padding: 12px 0 8px; }

.searchbar input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.searchbar input:focus { border-color: var(--accent); }

/* ---------- 标签筛选 ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0 10px;
}

.chips:empty { padding: 0; }

.chip {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.chip.on {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

/* ---------- 卡片列表 ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
}

.card:active { transform: scale(.985); }

.thumb {
  aspect-ratio: 4 / 3;
  background-color: var(--accent-soft);
  background-size: cover;
  background-position: center;
}

.thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  opacity: .55;
}

.card-body { padding: 10px 12px 12px; }

.card-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.card-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12.5px;
}

.card .chips { padding: 8px 0 0; gap: 6px; }

.card .chip { padding: 2px 8px; font-size: 11.5px; cursor: inherit; }

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text);
  font-size: 16px;
}

.muted { color: var(--muted); font-size: 13.5px; }

/* ---------- 底部工具区 ---------- */
.footer { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 14px; }

.footer-actions { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 8px; }

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 13.5px;
  cursor: pointer;
}

.link-btn.danger { color: var(--danger); }

/* ---------- 详情 ---------- */
.detail { padding-top: 12px; }

.cover {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--accent-soft);
}

.detail-title {
  margin: 14px 0 6px;
  font-size: 23px;
  font-weight: 700;
  line-height: 1.3;
}

.meta-row { display: flex; flex-wrap: wrap; gap: 8px; }

.meta-pill {
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
}

.block { margin-top: 22px; }

.block h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 650;
  color: var(--accent);
  letter-spacing: .4px;
}

.ingredients, .steps { margin: 0; padding: 0; list-style: none; }

.ingredients li, .steps li {
  display: flex;
  gap: 10px;
  padding: 11px 12px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.ingredients li::before, .steps li::before { flex: none; color: var(--muted); }

.ingredients li::before { content: "○"; }

.steps { counter-reset: step; }
.steps li { counter-increment: step; }
.steps li::before { content: counter(step) "."; color: var(--accent); font-weight: 600; }

.ingredients li.done::before { content: "●"; color: var(--accent); }

.ingredients li.done span, .steps li.done span {
  color: var(--muted);
  text-decoration: line-through;
}

.note {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  font-size: 14.5px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
}

/* ---------- 按钮 ---------- */
.btn {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 14.5px;
  cursor: pointer;
}

.btn.primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.subtle { color: var(--accent); }

.btn.danger { color: var(--danger); }

.btn:active { opacity: .75; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }

.field-row { display: flex; gap: 10px; }

.field-row .field { flex: 1; min-width: 0; }

.label { color: var(--muted); font-size: 13px; }

.field input, .field textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.field textarea { resize: vertical; line-height: 1.6; }

.field input:focus, .field textarea:focus { border-color: var(--accent); }

.img-picker { display: flex; flex-direction: column; gap: 10px; }

.img-preview {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
}

.img-buttons { display: flex; gap: 10px; }

.img-buttons .btn { display: inline-flex; align-items: center; cursor: pointer; }

.form-actions { display: flex; gap: 10px; margin: 22px 0 10px; }

.form-actions .btn { flex: 1; }

/* ---------- 悬浮按钮 ---------- */
.fab {
  position: fixed;
  right: max(18px, calc(50vw - 380px + 18px));
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 30;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(232, 89, 12, .35);
  cursor: pointer;
}

.fab:active { transform: scale(.94); }

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 40;
  transform: translateX(-50%);
  max-width: 82vw;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(30, 25, 22, .92);
  color: #fff;
  font-size: 14px;
  text-align: center;
}

@media (min-width: 620px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}