:root {
  --bg: #fdf6ec;
  --surface: #ffffff;
  --surface-2: #f6ead9;
  --ink: #43302b;
  --ink-soft: #8a7368;
  --accent: #dc2626;
  --accent-dark: #991b1b;
  --accent-soft: #fee2e2;
  --green: #3f8f5b;
  --gold: #e0a338;
  --line: #ecdcc9;
  --shadow: 0 8px 24px rgba(90, 50, 30, 0.10);
  --radius: 18px;
  --radius-sm: 12px;
  --maxw: 520px;
  --navh: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #221a16;
    --surface: #2e241e;
    --surface-2: #3a2d25;
    --ink: #f3e6da;
    --ink-soft: #b79b8c;
    --accent: #ef4444;
    --accent-dark: #fca5a5;
    --accent-soft: #451a1a;
    --green: #6fbf8b;
    --gold: #e8b45a;
    --line: #4a3a30;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  }
  body { color-scheme: dark; }
}

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

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  min-height: 100dvh;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -0.02em; }
.brand-mark { font-size: 22px; }
.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  width: 40px; height: 40px;
  border-radius: 12px;
  font-size: 18px;
  cursor: pointer;
}
.icon-btn-wide { width: auto; min-width: 52px; padding: 0 10px; font-size: 14px; font-weight: 800; letter-spacing: 0.04em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- main view ---------- */
.view {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 16px calc(var(--navh) + var(--safe-b) + 24px);
  min-height: 100dvh;
}

/* ---------- generic ---------- */
h1, h2, h3 { margin: 0 0 8px; letter-spacing: -0.02em; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.sub { color: var(--ink-soft); margin: 0 0 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  font-weight: 700;
  font-size: 16px;
  padding: 14px 22px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(220, 38, 38, 0.35); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.btn-lg { padding: 18px 28px; font-size: 18px; width: 100%; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 14px; }

.searchbar {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 13px 18px;
  font-size: 16px;
  outline: none;
  margin-bottom: 14px;
}
.searchbar:focus { border-color: var(--accent); }

/* ---------- hero / today ---------- */
.hero {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  border-radius: var(--radius);
  padding: 26px 22px;
  margin-bottom: 18px;
  box-shadow: 0 12px 28px rgba(220, 38, 38, 0.35);
}
.hero .big { font-size: 25px; font-weight: 800; line-height: 1.2; margin-bottom: 6px; }
.hero .small { opacity: 0.92; font-size: 14.5px; }
.hero .btn {
  margin-top: 16px;
  background: #fff;
  color: var(--accent-dark);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.15);
}

.pick-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 8px; }
.pick-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  text-align: center;
}
.pick-btn.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }

/* ---------- recipe cards ---------- */
.r-card {
  display: flex;
  gap: 14px;
  padding: 14px;
  cursor: pointer;
}
.r-art {
  flex: 0 0 76px;
  height: 76px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 38px;
  background: var(--surface-2);
  overflow: hidden;
  position: relative;
}
.art { position: relative; }
.art img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; border-radius: inherit; }
.art-fallback { display: grid; place-items: center; width: 100%; height: 100%; }
.r-art .art-fallback { font-size: 38px; }
.r-art img { border-radius: 14px; }
.r-main { flex: 1; min-width: 0; }
.r-name { font-weight: 800; font-size: 16.5px; margin-bottom: 4px; }
.r-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12.5px; color: var(--ink-soft); }
.meta-pill {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px 9px;
  font-weight: 600;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.r-tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: 11.5px; font-weight: 700; color: var(--accent-dark); background: var(--accent-soft); border-radius: 6px; padding: 2px 7px; }

.r-heart {
  border: none;
  background: none;
  font-size: 22px;
  cursor: pointer;
  align-self: flex-start;
  padding: 4px;
  filter: grayscale(1);
  opacity: 0.55;
}
.r-heart.fav { filter: none; opacity: 1; }

/* ---------- recipe detail ---------- */
.detail { padding-bottom: 30px; }
.detail-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 16px;
}
.detail-art {
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-soft), var(--surface-2));
  height: 190px;
  display: grid;
  place-items: center;
  font-size: 84px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}
.detail-art .art-fallback { font-size: 84px; }
.detail-art img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; border-radius: inherit; }
.detail h1 { font-size: 25px; }
.detail .cuisine { color: var(--accent-dark); font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }

.section-title { font-size: 17px; font-weight: 800; margin: 24px 0 10px; display: flex; align-items: center; gap: 8px; }

.ing-list { list-style: none; margin: 0; padding: 0; }
.ing-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 15px;
}
.ing-list li.done { opacity: 0.55; text-decoration: line-through; }
.ing-check {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 7px;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 13px;
  color: #fff;
  background: var(--surface);
}
.ing-list li.done .ing-check { background: var(--green); border-color: var(--green); }

.step-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 170px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin-top: 8px;
}
.step-num { font-size: 13px; font-weight: 800; color: var(--accent-dark); text-transform: uppercase; letter-spacing: 0.06em; }
.step-text { font-size: 16.5px; margin: 12px 0; line-height: 1.55; }
.step-nav { display: flex; gap: 10px; }
.step-nav .btn { flex: 1; padding: 12px; }
.dots { display: flex; gap: 5px; justify-content: center; margin-top: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--accent); width: 20px; border-radius: 5px; }

.detail-actions { display: flex; gap: 10px; margin-top: 26px; flex-wrap: wrap; }
.detail-actions .btn { flex: 1; min-width: 130px; }
.servings-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 0; }
.servings-row .btn { padding: 6px 12px; font-size: 15px; flex: 0 0 auto; }
.servings-note { font-size: 13px; color: var(--ink-soft); }

/* ---------- planner ---------- */
.week-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 18px;
}
.day-cell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 2px;
  text-align: center;
  cursor: pointer;
}
.day-cell.today-sel { border-color: var(--accent); background: var(--accent-soft); }
.day-cell .dow { font-size: 10.5px; font-weight: 800; color: var(--ink-soft); text-transform: uppercase; }
.day-cell .dnum { font-size: 15px; font-weight: 800; margin-top: 2px; }
.day-cell .dmeal { font-size: 10px; margin-top: 3px; color: var(--accent-dark); }

.plan-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.plan-entry .pe-art { width: 44px; height: 44px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 24px; flex: 0 0 auto; overflow: hidden; position: relative; }
.plan-entry .pe-art .art-fallback { font-size: 24px; }
.plan-entry .pe-name { font-weight: 700; font-size: 14.5px; flex: 1; }
.plan-entry .pe-x { border: none; background: none; font-size: 17px; color: var(--ink-soft); cursor: pointer; padding: 6px; }

.empty {
  text-align: center;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 16px;
  font-size: 14.5px;
}

/* ---------- bottom nav ---------- */
.bottomnav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: var(--maxw);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex;
  padding: 8px 10px calc(8px + var(--safe-b));
  z-index: 30;
}
.nav-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 700;
  padding: 6px 0 4px;
  cursor: pointer;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.nav-btn .nav-ico { font-size: 21px; filter: grayscale(1); opacity: 0.6; }
.nav-btn.active { color: var(--accent-dark); }
.nav-btn.active .nav-ico { filter: none; opacity: 1; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--navh) + 18px);
  background: var(--ink);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden { display: none !important; }

@media (min-width: 640px) {
  .view { padding-top: 26px; }
  .r-art { flex-basis: 96px; height: 96px; }
  .r-art .art-fallback { font-size: 46px; }
  .r-art img { border-radius: 14px; }
}
