/* ============ 我的菜谱 - 样式 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --primary: #FF6B35;
  --primary-dark: #E8561F;
  --bg: #F7F5F2;
  --card: #FFFFFF;
  --text: #2D2A26;
  --text-2: #8A857D;
  --border: #ECE9E4;
  --danger: #E5484D;
  --star: #FFB800;
  --green: #2E9E5B;
  --tab-h: 56px;
  --radius: 16px;
}

html { height: 100%; }
body {
  height: 100%;
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
}

.hidden { display: none !important; }
button { font-family: inherit; touch-action: manipulation; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--text); }
img { display: block; }

/* ============ 顶部栏 ============ */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px 10px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--bg);
}
.app-header h1 { font-size: 22px; font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px; border: none; border-radius: 50%;
  background: var(--card); font-size: 22px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.icon-btn:active { transform: scale(.92); }

.sub-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--bg);
}
.sub-header h2 { font-size: 18px; }
.text-btn { border: none; background: none; font-size: 16px; color: var(--text-2); padding: 8px; }
.text-btn.primary { color: var(--primary); font-weight: 600; }

/* ============ 首页 ============ */
.search-box { padding: 0 20px 12px; }
.search-box input {
  width: 100%; height: 44px; padding: 0 16px;
  border: none; border-radius: 22px; background: var(--card);
  font-size: 16px; outline: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
  -webkit-appearance: none; appearance: none;
}

.chips {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 2px 20px 14px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 7px 16px;
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--card); color: var(--text-2); font-size: 14px;
  white-space: nowrap;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.chip.static { pointer-events: none; }

/* 菜谱卡片网格 */
.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 0 20px;
}
.card {
  position: relative; background: var(--card); border-radius: var(--radius);
  overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,.05);
  cursor: pointer; transition: transform .12s;
}
.card:active { transform: scale(.97); }
.card-img { aspect-ratio: 1/1; background: linear-gradient(135deg, #FFE8DB, #FFF3EC); }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.card-noimg {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 44px; color: #E8A87C;
}
.card-body { padding: 10px 12px 12px; }
.card-name {
  font-size: 15px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 40px;
}
.card-meta {
  display: flex; align-items: center; gap: 6px; margin-top: 6px;
  font-size: 12px; color: var(--text-2);
}
.card-star {
  position: absolute; top: 8px; right: 8px;
  width: 34px; height: 34px; border: none; border-radius: 50%;
  background: rgba(255,255,255,.92); font-size: 16px;
  filter: grayscale(1); opacity: .85;
}
.card-star.on { filter: none; opacity: 1; }

.diff-badge {
  padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600;
  background: #F0EEE9; color: var(--text-2);
}
.diff-badge.simple { background: #E4F5EA; color: var(--green); }
.diff-badge.mid { background: #FFF0E4; color: var(--primary-dark); }
.diff-badge.hard { background: #FDE8E8; color: var(--danger); }

/* 空状态 */
.empty { text-align: center; padding: 60px 30px; color: var(--text-2); }
.empty-icon { font-size: 56px; margin-bottom: 12px; }
.empty p { font-size: 16px; font-weight: 600; color: var(--text); }
.empty .empty-sub { font-size: 14px; font-weight: 400; color: var(--text-2); margin-top: 6px; }

/* ============ 表单 ============ */
.form { padding: 4px 20px 20px; }
.field { margin-bottom: 20px; }
.field label {
  display: block; font-size: 14px; font-weight: 600; color: var(--text-2);
  margin-bottom: 8px;
}
.req { color: var(--danger); }
.field input[type="text"], .field select, .field textarea, .cat-add-row input {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); outline: none;
  -webkit-appearance: none; appearance: none;
}
.field textarea { resize: vertical; }
.field select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238A857D' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  padding-right: 36px;
}
.field input:focus, .field select:focus, .field textarea:focus,
.cat-add-row input:focus { border-color: var(--primary); }
.field-row { display: flex; gap: 12px; }
.field.half { flex: 1; }

/* 图片选择 */
#image-picker { text-align: center; }
#image-placeholder {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 34px 16px; color: var(--text-2); background: var(--card);
  cursor: pointer;
}
#image-preview {
  width: 100%; max-height: 260px; object-fit: cover;
  border-radius: var(--radius);
}
.chip-btn {
  margin-top: 10px; padding: 7px 18px;
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--card); color: var(--danger); font-size: 14px;
}

/* 动态列表(食材/步骤) */
.dyn-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.dyn-index {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%;
  background: #FFE8DB; color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.dyn-row input { flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); outline: none; font-size: 16px; }
.dyn-row input:focus { border-color: var(--primary); }
.dyn-del {
  flex-shrink: 0; width: 32px; height: 32px; border: none; border-radius: 50%;
  background: #F5F2ED; color: var(--text-2); font-size: 13px;
}
.add-row-btn {
  width: 100%; padding: 11px; border: 1px dashed var(--border); border-radius: 12px;
  background: none; color: var(--primary); font-size: 15px; font-weight: 600;
}

.switch-row { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text) !important; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--primary); }
.switch-row.small { font-size: 14px; color: var(--text-2); }

/* ============ 详情页 ============ */
.detail-img { width: 100%; aspect-ratio: 4/3; background: linear-gradient(135deg, #FFE8DB, #FFF3EC); }
.detail-img img { width: 100%; height: 100%; object-fit: cover; }
.detail-img .card-noimg { font-size: 64px; }
.detail-body { padding: 20px; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-head h2 { font-size: 22px; line-height: 1.35; flex: 1; }
.detail-head .card-star { position: static; flex-shrink: 0; width: 40px; height: 40px; font-size: 18px; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 22px; }
.detail-sec { margin-bottom: 24px; }
.detail-sec h3 {
  font-size: 16px; margin-bottom: 10px; padding-left: 10px;
  border-left: 4px solid var(--primary); line-height: 1.2;
}
.ing-list li { list-style: none; padding: 10px 0; border-bottom: 1px dashed var(--border); font-size: 15px; }
.ing-list li::before { content: "🥄 "; }
.step-list li { list-style: none; display: flex; gap: 12px; margin-bottom: 14px; font-size: 15px; line-height: 1.6; }
.step-num {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; margin-top: 2px;
}
.tips-box {
  background: #FFF6E0; border-radius: 12px; padding: 12px 14px;
  font-size: 14px; color: #8A6D1F; white-space: pre-wrap;
}
.detail-back {
  border: none; background: none; font-size: 22px; padding: 4px 8px 4px 0;
  color: var(--text);
}

/* ============ 我的页 ============ */
.my-card { padding: 0 20px; }
.stat {
  background: linear-gradient(135deg, var(--primary), #FF9A62);
  color: #fff; border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px; font-size: 15px;
  box-shadow: 0 4px 14px rgba(255,107,53,.3);
}
.stat b { font-size: 22px; }
.my-section {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.my-section h3 { font-size: 16px; margin-bottom: 8px; }
.hint { font-size: 13px; color: var(--text-2); margin-bottom: 12px; line-height: 1.6; }
.btn-col { display: flex; flex-direction: column; gap: 10px; }
.cat-add-row { display: flex; gap: 10px; margin-bottom: 10px; }
.cat-add-row input { flex: 1; padding: 10px 12px; font-size: 15px; }
.cat-add-row button { flex-shrink: 0; }
#custom-categories { padding: 0; }
#custom-categories .chip { position: relative; padding-right: 30px; }
#custom-categories .chip .chip-x {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: none; background: none; color: var(--text-2); font-size: 13px; padding: 2px;
}
.about { text-align: center; font-size: 12px; color: var(--text-2); padding: 10px 0 4px; }

/* ============ 按钮 ============ */
.btn {
  flex: 1; padding: 13px 16px; border: none; border-radius: 12px;
  font-size: 16px; font-weight: 600;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.secondary { background: #F5F2ED; color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn-row { display: flex; gap: 12px; margin-top: 16px; }

/* ============ 底部导航 ============ */
#tab-bar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  display: flex; background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; border: none; background: none;
  font-size: 11px; color: var(--text-2);
}
.tab.active { color: var(--primary); font-weight: 600; }
.tab-icon { font-size: 22px; line-height: 1; }

/* ============ 弹窗(底部抽屉) ============ */
.modal { position: fixed; inset: 0; z-index: 100; }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slideUp .25s ease;
  max-height: 85vh; overflow-y: auto;
}
@keyframes slideUp { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.sheet h3 { font-size: 18px; margin-bottom: 10px; text-align: center; }
.sheet textarea {
  width: 100%; margin-top: 12px; padding: 12px;
  border: 1px solid var(--border); border-radius: 12px;
  font-size: 13px; background: #FAF8F5; outline: none;
  resize: vertical; word-break: break-all;
}

/* 随机推荐 */
.random-card { text-align: center; padding: 12px 0 4px; cursor: pointer; }
.random-card img {
  width: 180px; height: 180px; object-fit: cover;
  border-radius: 18px; margin: 0 auto 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
}
.random-noimg {
  width: 120px; height: 120px; border-radius: 18px; margin: 0 auto 14px;
  background: linear-gradient(135deg, #FFE8DB, #FFF3EC);
  display: flex; align-items: center; justify-content: center; font-size: 52px;
}
.random-card h4 { font-size: 20px; margin-bottom: 10px; }
.random-meta { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.random-empty { text-align: center; color: var(--text-2); padding: 30px 0; }

/* ============ 提示 Toast ============ */
.toast {
  position: fixed; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px);
  left: 50%; transform: translateX(-50%);
  background: rgba(45,42,38,.92); color: #fff;
  padding: 10px 22px; border-radius: 22px; font-size: 14px;
  z-index: 200; max-width: 85%; text-align: center;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============ 桌面浏览器查看时居中 ============ */
@media (min-width: 481px) {
  body { background: #EDEAE5; }
  #app { box-shadow: 0 0 30px rgba(0,0,0,.08); background: var(--bg); }
}
