:root {
  --cream: #f7f1e5;
  --card: #fffdf7;
  --ink: #2b2620;
  --muted: #8a7d6b;
  --green: #2f5d3f;
  --green-dark: #234a31;
  --maroon: #8c2f39;
  --gold: #c9a227;
  --border: #e7dcc6;
  --shadow: 0 2px 10px rgba(60, 45, 25, 0.08);
  --radius: 16px;
  --tabbar-h: 68px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--cream);
  position: relative;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

#view { padding: 0 0 24px; }

/* ---------- header ---------- */
.page-head {
  padding: 28px 20px 12px;
}
.page-head .kicker {
  font-size: 12px; letter-spacing: 2.5px; text-transform: uppercase;
  color: var(--maroon); font-weight: 600; margin-bottom: 6px;
}
.page-head h1 {
  font-family: 'Playfair Display', serif;
  font-size: 32px; font-weight: 700; line-height: 1.1;
}
.page-head p.sub { color: var(--muted); font-size: 14px; margin-top: 6px; }

/* ---------- search & filters ---------- */
.search-wrap { padding: 8px 20px 0; }
.search-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 12px 16px; box-shadow: var(--shadow);
}
.search-box svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.search-box input {
  border: none; outline: none; background: transparent;
  font-size: 16px; width: 100%; color: var(--ink); font-family: inherit;
}

.chips {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 14px 20px 4px; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--card);
  color: var(--ink); border-radius: 999px; padding: 9px 16px;
  font-size: 14px; font-weight: 500; cursor: pointer; font-family: inherit;
}
.chip.active { background: var(--green); border-color: var(--green); color: #fff; }

.filters-row {
  display: flex; gap: 10px; padding: 10px 20px 0; align-items: center;
}
.filters-row select {
  flex: 1; appearance: none; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; font-size: 14px; font-family: inherit; color: var(--ink);
}
.fav-toggle {
  margin: 12px 20px 0; display: inline-flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; font-family: inherit; color: var(--ink);
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); cursor: pointer;
}
.fav-toggle[aria-pressed="true"] {
  background: rgba(140, 47, 57, 0.08); border-color: var(--maroon); color: var(--maroon);
}
.fav-toggle svg { width: 16px; height: 16px; }
.filter-row { display: flex; gap: 8px; padding: 10px 20px 0; }
.filter-row .field { flex: 1; }
.filter-row label {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 5px 2px;
}
.filter-row select {
  width: 100%; appearance: none; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; font-size: 14px; font-family: inherit; color: var(--ink);
}
.result-count { padding: 12px 20px 0; color: var(--muted); font-size: 13px; }

/* ---------- recipe cards ---------- */
.cards { display: flex; flex-direction: column; gap: 14px; padding: 12px 20px 0; }
.card {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  cursor: pointer; text-align: left; width: 100%; font-family: inherit; color: inherit;
}
.card-art {
  height: 108px; display: flex; align-items: flex-end; justify-content: space-between;
  padding: 12px 16px; color: rgba(255,255,255,0.95);
  position: relative; overflow: hidden;
}
.deco { position: absolute; right: -14px; top: -24px; opacity: 0.35; transform: rotate(12deg); pointer-events: none; }
.card-art .num {
  font-family: 'Playfair Display', serif; font-size: 40px; font-weight: 700;
  line-height: 1; text-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.card-art .cat {
  font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; font-weight: 600;
  background: rgba(255,255,255,0.22); padding: 5px 10px; border-radius: 999px;
  backdrop-filter: blur(2px);
}
.card-body { padding: 14px 16px 16px; }
.card-body h2 { font-family: 'Playfair Display', serif; font-size: 19px; margin-bottom: 8px; }
.meta { display: flex; gap: 14px; color: var(--muted); font-size: 13px; }
.meta span { display: inline-flex; align-items: center; gap: 5px; }
.meta svg { width: 14px; height: 14px; color: var(--muted); }
.fav-dot { float: right; width: 18px; height: 18px; color: var(--maroon); }

/* ---------- detail ---------- */
.detail-hero { padding: 20px 20px 18px; color: #fff; position: relative; overflow: hidden; }
.detail-hero .crumb {
  font-size: 12px; letter-spacing: 2px; text-transform: uppercase; opacity: 0.85; margin-bottom: 8px;
}
.detail-hero h1 { font-family: 'Playfair Display', serif; font-size: 30px; line-height: 1.15; margin-bottom: 10px; }
.detail-hero .meta { color: rgba(255,255,255,0.9); }
.detail-hero .meta svg { color: rgba(255,255,255,0.85); }
.detail-sec { padding: 18px 20px 0; }
.detail-sec h3 {
  font-family: 'Playfair Display', serif; font-size: 20px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.detail-sec h3 .count {
  font-family: 'Inter', sans-serif; font-size: 12px; color: var(--muted); font-weight: 500;
}
.desc { color: #4a4238; line-height: 1.55; font-size: 15px; }
.ing-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.ing-list li {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: 15px; cursor: pointer; line-height: 1.45;
}
.ing-list li.done { text-decoration: line-through; color: var(--muted); }
.checkbox {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--green); margin-top: 1px; position: relative;
}
li.done .checkbox { background: var(--green); }
li.done .checkbox::after {
  content: ''; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(42deg);
}
.method-list { list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 10px; }
.method-list li {
  counter-increment: step; display: flex; gap: 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; font-size: 15px; line-height: 1.55;
}
.method-list li::before {
  content: counter(step); flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: var(--green); color: #fff; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.source-line { color: var(--muted); font-size: 13px; margin: 10px 20px 0; }
.source-line a { color: var(--green); font-weight: 600; }
.watch-link { white-space: nowrap; }

.action-bar { display: flex; gap: 10px; padding: 20px 20px 0; }
.btn {
  flex: 1; border: none; border-radius: 14px; padding: 15px; font-size: 16px; font-weight: 600;
  cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); }
.btn-outline { background: var(--card); border: 1px solid var(--border); color: var(--ink); flex: 0 1 auto; padding: 15px 18px; }
.btn-outline.active { border-color: var(--maroon); color: var(--maroon); }

.note-box { padding: 18px 20px 0; }
.note-box textarea {
  width: 100%; min-height: 84px; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-family: inherit; font-size: 15px; background: var(--card);
  color: var(--ink); resize: vertical;
}
.note-box .btn { margin-top: 10px; padding: 12px; font-size: 15px; }

/* ---------- cooking mode ---------- */
.cook {
  position: fixed; inset: 0; z-index: 50; background: var(--cream); color: var(--ink);
  display: flex; flex-direction: column; max-width: 520px; margin: 0 auto;
}
.cook-top { padding: 16px 20px 8px; display: flex; align-items: center; gap: 12px; }
.cook-top .title {
  font-size: 14px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--ink); display: inline-flex; align-items: center;
  justify-content: center; flex: none; cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.active { border-color: var(--green); color: var(--green); }
.cook-progress { padding: 8px 20px; }
.cook-progress .bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.cook-progress .bar i { display: block; height: 100%; background: var(--green); border-radius: 999px; transition: width 0.3s; }
.cook-step-count {
  padding: 12px 20px 0; font-size: 13px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--maroon);
}
.cook-body { flex: 1; overflow-y: auto; padding: 10px 20px 16px; }
.cook-step { font-family: 'Playfair Display', serif; font-size: 25px; line-height: 1.45; font-weight: 500; margin: 6px 0 18px; }
.cook-ing { border-top: 1px dashed var(--border); padding-top: 12px; margin-top: 4px; }
.cook-ing[hidden] { display: none; }
.cook-ing h4 { margin: 0 0 8px; font-size: 15px; font-weight: 700; }
.cook-ing ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14.5px; display: grid; gap: 4px; }
#timerChip { margin: 4px 0 6px; }
.timer-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px;
  background: var(--maroon); color: #fdf3ee; font-weight: 700; font-size: 15px;
  border: none; cursor: pointer; font-family: inherit; font-variant-numeric: tabular-nums;
}
.timer-chip svg { width: 18px; height: 18px; }
.cook-nav { display: flex; gap: 12px; padding: 12px 20px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--card); }
.cook-nav .btn { flex: none; }
.cook-nav .btn:disabled { opacity: 0.35; }
.cook-done { text-align: center; padding: 40px 10px; }
.cook-done .done-title { font-family: 'Playfair Display', serif; font-size: 28px; margin-bottom: 10px; color: var(--ink); }
.cook-done p { color: var(--muted); margin-bottom: 20px; }

/* ---------- grocery ---------- */
.grocery-group { margin: 18px 20px 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.grocery-group header { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: rgba(201,162,39,0.08); border-bottom: 1px solid var(--border); }
.g-num { font-size: 12px; color: var(--muted); font-weight: 700; }
.g-title { font-weight: 700; font-size: 15px; flex: 1; }
.g-remove { color: var(--maroon); font-size: 13px; font-weight: 700; padding: 6px 8px; background: none; border: none; cursor: pointer; font-family: inherit; }
.grocery-group ul { list-style: none; margin: 0; padding: 6px; }
.grocery-group li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 8px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.grocery-group li.done .g-label { text-decoration: line-through; color: var(--muted); }
.grocery-actions { padding: 16px 20px 0; display: flex; gap: 10px; }
.empty { text-align: center; padding: 60px 30px; color: var(--muted); }
.empty .big { font-family: 'Playfair Display', serif; font-size: 22px; color: var(--ink); margin-bottom: 8px; }

/* ---------- add form ---------- */
.form { padding: 8px 20px 0; display: flex; flex-direction: column; gap: 14px; }
.form label { font-size: 13px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; color: var(--muted); display: block; margin-bottom: 6px; }
.form input, .form select, .form textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 13px 14px;
  font-size: 16px; font-family: inherit; background: var(--card); color: var(--ink);
}
.form textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.form .row2 { display: flex; gap: 10px; }
.form .row2 > div { flex: 1; }
.roadmap {
  margin: 18px 20px 0; border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 16px; color: var(--muted); font-size: 14px; line-height: 1.5; background: rgba(255,255,255,0.4);
}
.roadmap strong { color: var(--ink); }

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  background: rgba(255, 253, 247, 0.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border); display: flex; z-index: 40;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 500; font-family: inherit;
  position: relative;
}
.tab .badge {
  position: absolute; top: 6px; left: calc(50% + 2px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--maroon); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.tab .badge[hidden] { display: none; }
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--green); }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: calc(var(--tabbar-h) + 20px); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  font-size: 14px; opacity: 0; transition: all 0.25s; pointer-events: none; z-index: 60;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.back-link {
  display: inline-flex; align-items: center; gap: 6px; background: none; border: none;
  color: var(--muted); font-size: 14px; font-weight: 500; cursor: pointer; font-family: inherit;
  padding: 18px 20px 0;
}
.back-link svg { width: 16px; height: 16px; }
