/* ===========================================================
   Design tokens
   Warm cream paper, honey-orange accents, near-black buttons and
   fresh green check marks — inspired by modern recipe sites.
   =========================================================== */
:root {
  --paper: #FAF7F0;
  --paper-dim: #F3EEE3;
  --card: #FFFFFF;
  --ink: #1A1712;
  --ink-soft: #736B5E;
  --accent: #F5A623;
  --accent-dark: #B9770E;
  --accent-soft: #FDF0D5;
  --green: #14B866;
  --green-dark: #0C7F45;
  --green-soft: #E1F6EA;
  --tomato: #E0522F;
  --tomato-soft: #FDEDE7;
  --dark: #1C1B19;
  --on-dark: #FFFFFF;
  --line: #EBE5D8;
  --line-strong: #D9D1C0;
  --radius-card: 22px;
  --radius-chip: 999px;
  --radius-btn: 999px;
  --shadow-card: 0 1px 2px rgba(60, 40, 10, 0.04), 0 12px 28px rgba(60, 40, 10, 0.08);
  --font-display: "Bricolage Grotesque", "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-ui: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ===========================================================
   Dark theme
   =========================================================== */
:root[data-theme="dark"] {
  --paper: #14120F;
  --paper-dim: #1D1A16;
  --card: #1F1C18;
  --ink: #F4EFE6;
  --ink-soft: #A49B8B;
  --accent: #F5A623;
  --accent-dark: #F5B84D;
  --accent-soft: #3A2C12;
  --green: #2FD07E;
  --green-dark: #7BE3AC;
  --green-soft: #16301F;
  --tomato: #EC7457;
  --tomato-soft: #3A241C;
  --dark: #F4EFE6;
  --on-dark: #14120F;
  --line: #2C2822;
  --line-strong: #3E382F;
  --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 12px 28px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}
body { min-height: 100%; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--ink);
}

p { margin: 0; }
.muted { color: var(--ink-soft); font-size: 0.94rem; line-height: 1.55; }
.muted-inline { font-family: var(--font-ui); font-size: 0.78rem; color: var(--ink-soft); font-weight: 400; }
.hidden { display: none !important; }
.hl { color: var(--accent); }

button { font-family: var(--font-ui); cursor: pointer; }
input, select { font-family: var(--font-ui); }

.skeleton {
  background: linear-gradient(100deg, var(--paper-dim) 30%, var(--line) 50%, var(--paper-dim) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ===========================================================
   Buttons
   =========================================================== */
.btn {
  border: none;
  border-radius: var(--radius-btn);
  padding: 12px 22px;
  font-size: 0.92rem;
  font-weight: 700;
  transition: transform 0.1s ease, opacity 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; }

.btn-primary { background: var(--dark); color: var(--on-dark); }
.btn-primary:hover:not(:disabled) { opacity: 0.86; }

.btn-accent { background: var(--accent); color: #1A1712; }
.btn-accent:hover:not(:disabled) { filter: brightness(0.94); }

.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line-strong); }
.btn-ghost:hover { background: var(--paper-dim); }

.btn-danger { color: var(--tomato); border-color: var(--tomato-soft); }
.btn-danger:hover { background: var(--tomato-soft); }

.btn-small { padding: 7px 14px; font-size: 0.78rem; }

.upload-card .btn-primary { width: 100%; }
.link-small {
  background: none; border: none; color: var(--accent-dark); font-weight: 700;
  font-size: 0.82rem; cursor: pointer; text-decoration: none; padding: 0;
}
.link-small:hover { text-decoration: underline; }

.theme-toggle {
  background: transparent;
  border: 1.5px solid var(--line-strong);
  color: var(--ink);
  border-radius: var(--radius-chip);
  padding: 0 14px;
  height: 36px;
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.theme-toggle:hover { background: var(--paper-dim); }

.brand-mark {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #1A1712;
  line-height: 1;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border-radius: 14px;
  flex-shrink: 0;
}

/* ===========================================================
   Landing / auth screen
   =========================================================== */
.auth-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 480px) 1fr;
  background: var(--paper);
}

.auth-left {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 40px;
}
.auth-inner { width: 100%; max-width: 380px; }

.theme-toggle-landing { position: absolute; top: 20px; left: 24px; }

.auth-brand-row { display: flex; align-items: center; gap: 12px; margin-bottom: 30px; }
.auth-brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }

.auth-inner h2 { font-size: 2.1rem; line-height: 1.1; margin-bottom: 8px; }
.auth-inner > .muted { margin-bottom: 24px; }

.auth-tabs {
  display: flex;
  background: var(--paper-dim);
  border-radius: var(--radius-chip);
  padding: 4px;
  margin-bottom: 22px;
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 10px 0;
  border-radius: var(--radius-chip);
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--ink-soft);
  transition: background 0.15s ease, color 0.15s ease;
}
.auth-tab.active { background: var(--dark); color: var(--on-dark); }

#authForm { display: flex; flex-direction: column; gap: 16px; }
#clerkAuth { margin-top: 10px; }
#clerkAuth .cl-rootBox, #clerkAuth .cl-card { width: 100%; box-shadow: none; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 0.78rem; font-weight: 700; color: var(--ink-soft); }
.field input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--line-strong);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input::placeholder { color: var(--ink-soft); opacity: 0.6; }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.field-pass { position: relative; display: block; }
.field-pass input { padding-right: 62px; }
.field-eye {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--ink-soft); font-size: 0.78rem; font-weight: 700;
}

.auth-row-between {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.82rem; color: var(--ink-soft);
}
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); }

#authSubmitBtn { padding: 14px 0; margin-top: 2px; }

.auth-switch-line { margin-top: 18px; font-size: 0.86rem; color: var(--ink-soft); display: flex; gap: 6px; justify-content: center; }
.auth-socials { display: flex; gap: 12px; justify-content: center; margin-top: 20px; }
.social {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1.5px solid var(--line-strong); background: var(--card); color: var(--ink);
  font-weight: 700; font-size: 0.85rem;
  transition: border-color 0.15s ease;
}
.social:hover { border-color: var(--accent); }
.auth-tagline { margin-top: 26px; text-align: center; font-size: 0.82rem; color: var(--ink-soft); line-height: 1.55; }

/* Right-hand food collage */
.auth-right {
  position: relative;
  margin: 16px 16px 16px 0;
  border-radius: 34px;
  overflow: hidden;
  background: linear-gradient(135deg, #F5A623 0%, #F7C567 100%);
  display: flex;
  align-items: flex-end;
}
.auth-collage {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  grid-template-rows: 1.3fr 1fr;
  gap: 12px;
  padding: 12px;
}
.collage-tile {
  border-radius: 24px;
  background-size: cover;
  background-position: center;
  background-color: rgba(255,255,255,0.25);
  animation: fadeIn 0.6s ease;
}
.collage-tile.t1 { grid-row: 1 / span 2; }
.auth-right::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(20,15,5,0) 45%, rgba(20,15,5,0.78) 100%);
  pointer-events: none;
}
.auth-visual-copy { position: relative; z-index: 2; padding: 40px 44px; max-width: 560px; }
.auth-visual-copy h2 { color: #fff; font-size: 2.5rem; line-height: 1.08; margin-bottom: 10px; }
.auth-visual-copy .hl { color: var(--accent); }
.auth-visual-copy p { color: rgba(255,255,255,0.85); font-size: 1rem; }

@media (max-width: 900px) {
  .auth-screen { grid-template-columns: 1fr; }
  .auth-right { display: none; }
  .auth-left { padding: 70px 22px 40px; }
}

/* ===========================================================
   Shell / header
   =========================================================== */
.app-shell { max-width: 1120px; margin: 0 auto; padding: 0 22px 80px; }

.topbar { padding: 26px 0 18px; margin-bottom: 26px; }

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }

.account-badge {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.brand-text h1 { font-size: 1.6rem; }
.brand-text p { color: var(--ink-soft); font-size: 0.92rem; margin-top: 2px; }

.tabs {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-chip);
  padding: 5px;
  box-shadow: var(--shadow-card);
}
.tab {
  background: transparent;
  border: none;
  color: var(--ink-soft);
  padding: 9px 18px;
  border-radius: var(--radius-chip);
  font-size: 0.9rem;
  font-weight: 700;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover { background: var(--paper-dim); color: var(--ink); }
.tab.active { background: var(--dark); color: var(--on-dark); }
.tab-count {
  display: inline-block; min-width: 18px; padding: 1px 6px; font-size: 0.72rem;
  background: var(--accent); color: #1A1712; border-radius: 999px; margin-left: 4px;
}
.tab-count:empty { display: none; }

/* ===========================================================
   Panels
   =========================================================== */
.panel { display: none; }
.panel.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.panel-header { margin-bottom: 20px; max-width: 640px; }
.panel-header h2 { font-size: 1.9rem; margin-bottom: 6px; }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin: 40px 0 16px;
}
.section-head h3 { font-size: 1.6rem; }
.section-head .muted { font-size: 0.85rem; }

/* ===========================================================
   Cards
   =========================================================== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 26px;
  box-shadow: var(--shadow-card);
}
.card h2 { font-size: 1.25rem; margin-bottom: 6px; }
.card > .muted { margin-bottom: 16px; display: block; }

.scan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 780px) { .scan-grid { grid-template-columns: 1fr; } }

/* ===========================================================
   Upload / dropzone
   =========================================================== */
.dropzone {
  display: block; border: 2px dashed var(--line-strong); border-radius: 18px;
  background: var(--paper-dim); cursor: pointer; overflow: hidden; margin-bottom: 14px;
  transition: border-color 0.15s ease;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone-inner {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 46px 20px; text-align: center;
}
.dropzone-icon { font-size: 0.85rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent-dark); }
.dropzone-text { color: var(--ink-soft); font-size: 0.9rem; font-weight: 600; }
.photo-preview { display: block; width: 100%; max-height: 280px; object-fit: cover; }

.hint { font-size: 0.82rem; color: var(--ink-soft); margin-top: 10px; min-height: 1.2em; }
.hint.error { color: var(--tomato); }
.hint.success { color: var(--green-dark); }

.plan-badge {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px; background: var(--line); color: var(--ink-soft);
}
.plan-badge.pro { background: linear-gradient(135deg, #F5A623, #E88B1F); color: #1A1712; }
.upgrade-modal { max-width: 380px; }
.upgrade-modal .field { margin-bottom: 14px; }
.upgrade-modal .auth-row-between { gap: 12px; align-items: flex-start; }

.profile-modal { max-width: 420px; }
.profile-header { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.profile-avatar {
  width: 56px; height: 56px; border-radius: 50%; background: var(--line);
  background-size: cover; background-position: center; flex-shrink: 0;
}
.profile-header h2 { margin: 0; font-size: 1.15rem; }
.profile-plan-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.profile-plan-actions { display: flex; gap: 10px; margin-bottom: 4px; }
.profile-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin: 20px 0; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.profile-stat { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.profile-stat-num { font-size: 1.3rem; font-weight: 800; font-family: var(--font-ui); }
.profile-stat span:last-child { font-size: 0.72rem; color: var(--ink-soft); }
#manageAccountBtn { margin-bottom: 10px; }

/* ===========================================================
   Ingredient entry
   =========================================================== */
.ingredient-search { position: relative; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.ingredient-search input {
  flex: 1; width: 100%; padding: 12px 16px; border: 1.5px solid var(--line-strong);
  border-radius: 14px; font-size: 0.95rem; background: var(--paper); color: var(--ink);
}
.ingredient-search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.suggestions {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-card); max-height: 200px; overflow-y: auto; z-index: 20;
}
.suggestion-item { padding: 10px 16px; font-size: 0.9rem; cursor: pointer; }
.suggestion-item:hover { background: var(--paper-dim); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; min-height: 36px; margin-bottom: 18px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); border: 1px solid transparent; color: var(--ink);
  padding: 6px 8px 6px 14px; border-radius: var(--radius-chip); font-size: 0.85rem; font-weight: 600;
}
.chip button {
  background: transparent; border: none; color: var(--ink-soft); font-size: 1rem;
  line-height: 1; padding: 2px 5px; border-radius: 50%;
}
.chip button:hover { background: var(--line); color: var(--tomato); }

.entry-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.entry-actions .btn-primary { flex: 1; min-width: 150px; }

/* ===========================================================
   Pantry
   =========================================================== */
.pantry-add { display: flex; gap: 10px; margin-bottom: 18px; max-width: 520px; flex-wrap: wrap; }
.pantry-add input[type="text"] {
  flex: 1; min-width: 160px; padding: 12px 16px; border: 1.5px solid var(--line-strong);
  border-radius: 14px; font-size: 0.92rem; background: var(--card); color: var(--ink);
}
.pantry-add input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.pantry-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; min-height: 40px; }
.pantry-empty { color: var(--ink-soft); font-size: 0.9rem; font-style: italic; }

/* ===========================================================
   HOME — hero
   =========================================================== */
.hero {
  position: relative;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  align-items: center;
  gap: 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 34px;
  padding: 44px 44px 44px 48px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute; right: -120px; top: -140px;
  width: 460px; height: 460px; border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
  pointer-events: none;
}
.hero-text { position: relative; z-index: 1; max-width: 480px; }
.hero-badge {
  display: inline-block;
  background: var(--accent-soft); color: var(--accent-dark);
  border-radius: var(--radius-chip); padding: 5px 14px;
  font-size: 0.78rem; font-weight: 700;
}
.hero h2 { font-size: 3rem; line-height: 1.04; margin: 16px 0 14px; }
.hero .muted { margin-bottom: 26px; font-size: 1rem; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.hero-visual { position: relative; z-index: 1; min-height: 340px; }
.hero-photo {
  position: absolute; inset: 0 0 0 30px;
  border-radius: 40px 90px 40px 90px;
  background-size: cover; background-position: center;
  cursor: pointer;
  box-shadow: 0 24px 50px rgba(60, 40, 10, 0.22);
  transition: transform 0.25s ease;
}
.hero-photo:hover { transform: scale(1.015) rotate(-0.4deg); }
.hero-photo:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.hero-float {
  position: absolute;
  width: 110px; height: 110px; border-radius: 50%;
  background-size: cover; background-position: center;
  border: 5px solid var(--card);
  box-shadow: 0 14px 30px rgba(60, 40, 10, 0.22);
  animation: floatArt 5s ease-in-out infinite;
}
.hero-float-a { left: -6px; top: 8px; }
.hero-float-b { left: 6px; bottom: 6px; width: 90px; height: 90px; animation-delay: -2.4s; }
@keyframes floatArt { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }

.hero-tag {
  position: absolute; right: 18px; bottom: 18px;
  background: var(--card); color: var(--ink);
  border-radius: 18px; padding: 12px 16px; max-width: 250px;
  box-shadow: 0 12px 28px rgba(60, 40, 10, 0.2);
  font-size: 0.78rem; line-height: 1.35; cursor: pointer;
}
.hero-tag small { display: block; color: var(--accent-dark); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.66rem; margin-bottom: 2px; }
.hero-tag strong { font-family: var(--font-display); font-size: 0.98rem; }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; padding: 30px 24px; }
  .hero h2 { font-size: 2.3rem; }
  .hero-visual { min-height: 260px; order: -1; }
  .hero-photo { inset: 0 0 0 20px; border-radius: 30px 60px 30px 60px; }
  .hero-float { width: 80px; height: 80px; }
  .hero-float-b { width: 64px; height: 64px; }
}

/* ===========================================================
   HOME — category pills, recipe grid, strip, CTA
   =========================================================== */
.pill-row {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin-bottom: 8px;
  scrollbar-width: thin;
}
.pill {
  flex-shrink: 0;
  background: var(--card); border: 1.5px solid var(--line); color: var(--ink);
  border-radius: var(--radius-chip); padding: 9px 18px; font-size: 0.86rem; font-weight: 700;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.pill:hover { border-color: var(--accent); }
.pill.active { background: var(--dark); color: var(--on-dark); border-color: var(--dark); }

.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.filter-chip {
  background: var(--card); border: 1.5px solid var(--line); color: var(--ink);
  padding: 7px 16px; border-radius: var(--radius-chip); font-size: 0.82rem; font-weight: 700;
}
.filter-chip:hover { border-color: var(--accent); }
.filter-chip.active { background: var(--dark); border-color: var(--dark); color: var(--on-dark); }

/* Unified recipe photo card */
.rgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}
.rcard {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 12px 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.rcard:hover { transform: translateY(-3px); box-shadow: var(--shadow-card); border-color: var(--line-strong); }
.rcard-img {
  position: relative; aspect-ratio: 1 / 0.86; border-radius: 16px; overflow: hidden;
  background: linear-gradient(135deg, var(--accent-soft), var(--paper-dim));
  display: flex; align-items: center; justify-content: center;
}
.rcard-img img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.3s ease; }
.rcard:hover .rcard-img img { transform: scale(1.05); }
.rcard-img .noimg { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent-dark); padding: 10px; text-align: center; }
.rcard .match-badge { position: absolute; top: 10px; right: 10px; box-shadow: 0 4px 10px rgba(0,0,0,0.15); }
.rcard h3 { font-size: 1.05rem; line-height: 1.25; padding: 0 4px; }
.rcard-sub { font-size: 0.8rem; color: var(--ink-soft); padding: 0 4px; margin-top: -4px; }
.rcard-missing { font-size: 0.8rem; color: var(--ink-soft); padding: 0 4px; margin-top: -4px; }
.rcard-missing strong { color: var(--tomato); }
.rcard-missing.all { color: var(--green-dark); font-weight: 700; }
.rcard-btn {
  margin-top: auto;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--dark); color: var(--on-dark);
  border-radius: var(--radius-chip); padding: 10px 14px 10px 18px;
  font-size: 0.8rem; font-weight: 700;
  transition: background 0.15s ease;
}
.rcard-btn i {
  font-style: normal; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #1A1712; display: inline-flex; align-items: center; justify-content: center;
}
.rcard-skel { min-height: 300px; border-radius: var(--radius-card); }

.match-badge {
  flex-shrink: 0; font-family: var(--font-ui); font-weight: 700; font-size: 0.78rem;
  padding: 5px 10px; border-radius: var(--radius-chip);
}
.match-badge.full { background: var(--green); color: #fff; }
.match-badge.high { background: var(--green-soft); color: var(--green-dark); }
.match-badge.mid { background: var(--accent-soft); color: var(--accent-dark); }
.match-badge.low { background: var(--tomato-soft); color: var(--tomato); }

/* Category tiles */
.explore-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.explore-card {
  position: relative;
  border-radius: 22px; overflow: hidden; cursor: pointer;
  aspect-ratio: 1 / 0.9;
  background: var(--paper-dim);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.explore-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-card); }
.explore-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.explore-card::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(20,15,5,0) 45%, rgba(20,15,5,0.7) 100%);
}
.explore-card-label {
  position: absolute; left: 14px; right: 14px; bottom: 12px; z-index: 1;
  font-family: var(--font-display); font-weight: 800; font-size: 1.02rem; color: #fff;
}

/* Horizontal strip */
.strip {
  display: flex; gap: 16px; overflow-x: auto; padding: 4px 2px 14px;
  scroll-snap-type: x proximity; scrollbar-width: thin;
}
.strip .rcard { flex: 0 0 260px; scroll-snap-align: start; }

/* CTA band */
.cta-band {
  margin-top: 44px;
  display: grid; grid-template-columns: 1.1fr 1fr; align-items: stretch;
  background: var(--dark); color: var(--on-dark);
  border-radius: 34px; overflow: hidden;
}
.cta-text { padding: 44px; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.cta-text h3 { color: var(--on-dark); font-size: 2rem; }
.cta-text p { color: var(--on-dark); opacity: 0.75; max-width: 380px; line-height: 1.55; margin-bottom: 8px; }
.cta-photo { min-height: 240px; background-size: cover; background-position: center; border-radius: 0; animation: none; }
@media (max-width: 760px) {
  .cta-band { grid-template-columns: 1fr; }
  .cta-text { padding: 30px 24px; }
}

/* ===========================================================
   External section / freestyle
   =========================================================== */
.external-section { margin-top: 40px; padding-top: 10px; }
.external-section h3 { font-size: 1.5rem; margin-bottom: 16px; }

.freestyle-box {
  margin-top: 36px; padding: 26px; background: var(--accent-soft);
  border-radius: var(--radius-card); text-align: center;
}
.freestyle-box .muted { display: block; margin-bottom: 14px; color: var(--ink); }
#freestyleResult { margin-top: 18px; text-align: left; }
#freestyleResult .card { background: var(--card); }

/* ===========================================================
   Recipe detail page
   =========================================================== */
.back-link {
  background: var(--card); border: 1.5px solid var(--line); color: var(--ink);
  border-radius: var(--radius-chip); padding: 8px 16px; font-size: 0.85rem; font-weight: 700;
  margin-bottom: 20px;
}
.back-link:hover { border-color: var(--accent); }

.rp {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 40px;
  align-items: start;
}
.rp-title { font-size: 3.1rem; line-height: 1.02; margin-bottom: 20px; }

.rp-meta { display: flex; flex-wrap: wrap; gap: 8px 30px; margin-bottom: 18px; }
.rp-meta div { display: flex; flex-direction: column; gap: 2px; }
.rp-meta span { font-size: 0.72rem; color: var(--ink-soft); font-weight: 500; }
.rp-meta strong { font-size: 0.95rem; font-weight: 700; }

.rp-desc { font-size: 1.02rem; line-height: 1.6; color: var(--ink); margin-bottom: 20px; max-width: 560px; }

.rp-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.recipe-tag {
  font-size: 0.74rem; background: var(--accent-soft); color: var(--accent-dark);
  padding: 4px 11px; border-radius: var(--radius-chip); font-weight: 700;
}

.rp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.rp-actions .btn { padding: 10px 18px; font-size: 0.84rem; }

.rp-h { font-size: 1.7rem; margin: 40px 0 18px; }

.rp-steps { list-style: none; counter-reset: step; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 14px; }
.rp-steps li {
  counter-increment: step;
  display: flex; gap: 16px; align-items: flex-start;
  font-size: 0.98rem; line-height: 1.6;
}
.rp-steps li::before {
  content: counter(step);
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 12px;
  background: var(--paper-dim); color: var(--ink);
  font-family: var(--font-display); font-weight: 800; font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center;
}

.rp-photo {
  border-radius: 34px 34px 34px 34px;
  overflow: hidden;
  aspect-ratio: 1 / 0.9;
  background: linear-gradient(135deg, var(--accent-soft), var(--paper-dim));
  box-shadow: var(--shadow-card);
  display: flex; align-items: center; justify-content: center;
  transform: rotate(1.2deg);
  margin-bottom: 24px;
}
.rp-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rp-photo .noimg { font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; color: var(--accent-dark); padding: 20px; text-align: center; }

.rp-ingredients {
  background: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 24px 24px 26px;
}
.rp-ingredients h3 { font-size: 1.35rem; }
.rp-ingredients .muted { font-size: 0.84rem; margin: 4px 0 14px; }
.rp-ing-list { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 11px; }
.rp-ing-list li { display: flex; align-items: center; gap: 12px; font-size: 0.94rem; flex-wrap: wrap; }
.rp-ing-list li::before {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 800;
}
.rp-ing-list li.have::before { content: "\2713"; background: var(--green); color: #fff; }
.rp-ing-list li.missing::before { content: "+"; background: var(--tomato-soft); color: var(--tomato); }
.rp-ing-list .measure { font-weight: 700; }

.sub-btn {
  background: transparent; border: none; color: var(--accent-dark); font-size: 0.76rem;
  font-weight: 700; margin-left: 4px; text-decoration: underline;
}
.substitute-result {
  flex-basis: 100%; font-size: 0.82rem; background: var(--card); border-radius: 10px;
  padding: 8px 12px; margin-left: 32px;
}

.nutrition-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.nutrition-stat { background: var(--paper-dim); border-radius: 16px; padding: 14px 8px; text-align: center; }
.nutrition-stat .value { font-family: var(--font-display); font-size: 1.4rem; font-weight: 800; }
.nutrition-stat .label { font-size: 0.68rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }

@media (max-width: 860px) {
  .rp { grid-template-columns: 1fr; gap: 26px; }
  .rp-title { font-size: 2.3rem; }
  .rp-side { order: -1; }
  .nutrition-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===========================================================
   Old-style list bits still used by AI freestyle card / cook mode
   =========================================================== */
.recipe-meta { display: flex; gap: 12px; font-size: 0.82rem; color: var(--ink-soft); margin: 6px 0 10px; }
.modal-section { margin-top: 20px; }
.modal-section h4 { font-size: 0.85rem; color: var(--ink-soft); font-weight: 700; margin: 0 0 10px; font-family: var(--font-ui); }
.ingredient-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.ingredient-list li { font-size: 0.9rem; display: flex; align-items: center; gap: 10px; }
.ingredient-list li::before {
  content: "\2713"; flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%;
  background: var(--green); color: #fff; font-size: 0.7rem; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
}
.steps-list { list-style: none; counter-reset: step; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.steps-list li { counter-increment: step; font-size: 0.92rem; line-height: 1.55; display: flex; gap: 12px; }
.steps-list li::before {
  content: counter(step); flex-shrink: 0; width: 28px; height: 28px; border-radius: 10px;
  background: var(--paper-dim); font-family: var(--font-display); font-weight: 800; font-size: 0.85rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.modal-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* ===========================================================
   Saved-recipe quick jump (Scan tab)
   =========================================================== */
.saved-recipe-jump { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line-strong); }
.saved-recipe-jump label { display: block; font-size: 0.78rem; font-weight: 700; color: var(--ink-soft); margin-bottom: 6px; }
.saved-recipe-jump select {
  width: 100%; padding: 11px 14px; border-radius: 14px; border: 1.5px solid var(--line-strong);
  background: var(--paper-dim); color: var(--ink); font-size: 0.88rem;
}

/* ===========================================================
   Mic / voice buttons
   =========================================================== */
.mic-btn {
  background: var(--card); border: 1.5px solid var(--line-strong); color: var(--ink);
  border-radius: var(--radius-chip); padding: 0 14px; height: 36px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700;
  transition: background 0.15s ease, color 0.15s ease;
}
.mic-btn:hover { background: var(--accent-soft); }
.mic-btn.listening { background: var(--tomato); border-color: var(--tomato); color: #fff; animation: micPulse 1.1s ease-in-out infinite; }
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--tomato-soft); }
  50% { box-shadow: 0 0 0 8px var(--tomato-soft); }
}
.mic-btn-inline { margin-left: 4px; }

/* ===========================================================
   How to Cook? modal
   =========================================================== */
.how-to-cook-modal { max-width: 560px; }
.htc-header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.htc-header h2 { font-size: 1.6rem; }
.htc-search-row { display: flex; gap: 8px; margin: 16px 0 12px; align-items: center; }
.htc-search-row input {
  flex: 1; padding: 12px 16px; border: 1.5px solid var(--line-strong); border-radius: 14px;
  font-size: 0.95rem; background: var(--paper); color: var(--ink);
}
.htc-search-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.htc-search-row .btn { padding: 11px 20px; }
.htc-try { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.htc-chip {
  background: var(--paper-dim); border: 1px solid var(--line); border-radius: var(--radius-chip);
  padding: 6px 14px; font-size: 0.82rem; font-weight: 700; color: var(--ink);
}
.htc-chip:hover { background: var(--accent); border-color: var(--accent); color: #1A1712; }
.htc-result-item {
  display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line);
  border-radius: 16px; margin-bottom: 8px; cursor: pointer; transition: border-color 0.15s ease;
}
.htc-result-item:hover { border-color: var(--accent); }
.htc-result-item img { width: 52px; height: 52px; border-radius: 12px; object-fit: cover; }
.htc-result-noimg {
  width: 52px; height: 52px; border-radius: 12px; flex-shrink: 0; display: flex; align-items: center;
  justify-content: center; background: var(--paper-dim); color: var(--ink-soft);
  font-size: 0.62rem; font-weight: 700; text-align: center;
}
.htc-result-name { font-weight: 700; font-size: 0.94rem; }
.htc-result-source { font-size: 0.75rem; color: var(--ink-soft); }
.htc-error {
  background: var(--tomato-soft); color: var(--tomato); border-radius: 16px;
  padding: 14px 16px; margin-bottom: 14px; font-size: 0.88rem; font-weight: 600;
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
}
.htc-ai-fallback { margin-top: 14px; text-align: center; padding: 16px; background: var(--paper-dim); border-radius: 16px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-soft); grid-column: 1 / -1; }

/* ===========================================================
   Modals (cook mode + how to cook)
   =========================================================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(26, 23, 18, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--paper); border-radius: 28px; max-width: 620px; width: 100%;
  max-height: 86vh; overflow-y: auto; padding: 34px; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-close {
  position: absolute; top: 16px; right: 16px; background: var(--paper-dim); border: none;
  width: 36px; height: 36px; border-radius: 50%; font-size: 1.3rem; color: var(--ink-soft); line-height: 1;
}
.modal-close:hover { background: var(--line); }

.cook-mode-modal { max-width: 500px; text-align: center; }
.cook-step-num { font-family: var(--font-display); font-size: 0.85rem; color: var(--accent-dark); font-weight: 800; margin-bottom: 8px; letter-spacing: 0.06em; }
.cook-step-text { font-size: 1.25rem; line-height: 1.5; margin-bottom: 28px; min-height: 100px; display: flex; align-items: center; justify-content: center; }
.cook-nav { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.cook-progress { display: flex; justify-content: center; gap: 5px; margin-bottom: 20px; flex-wrap: wrap; }
.cook-progress-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.cook-progress-dot.done { background: var(--green); }
.cook-progress-dot.current { background: var(--accent); }

/* ===========================================================
   Toast
   =========================================================== */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--dark); color: var(--on-dark); padding: 13px 24px;
  border-radius: var(--radius-chip); font-size: 0.88rem; font-weight: 700;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25); z-index: 200; animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===========================================================
   Responsive
   =========================================================== */
@media (max-width: 640px) {
  .app-shell { padding: 0 14px 60px; }
  .topbar { padding-top: 18px; }
  .brand { flex-wrap: wrap; }
  .brand-text h1 { font-size: 1.35rem; }
  .brand-text p { display: none; }
  .account-badge { margin-left: 0; width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .tabs { display: flex; overflow-x: auto; flex-wrap: nowrap; border-radius: 22px; }
  .tab { white-space: nowrap; padding: 9px 14px; }
  .card { padding: 20px; }
  .ingredient-list { grid-template-columns: 1fr; }
  .rgrid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .rcard { padding: 8px 8px 10px; }
  .rcard h3 { font-size: 0.92rem; }
  .rcard-btn { font-size: 0.72rem; padding: 8px 10px 8px 12px; }
  .strip .rcard { flex-basis: 200px; }
  .section-head h3 { font-size: 1.35rem; }
  .modal { padding: 26px 20px; }
}

/* ===========================================================
   Device polish: phones, small tablets, big screens
   =========================================================== */
html { -webkit-text-size-adjust: 100%; }
img { max-width: 100%; }
h1, h2, h3, .rcard h3, .rp-title, .rp-desc, .rp-steps li { overflow-wrap: anywhere; }

/* Full-height screens that respect mobile browser toolbars */
.auth-screen { min-height: 100vh; min-height: 100dvh; }

/* Tablets (portrait iPad, small Android tablets) */
@media (max-width: 900px) {
  .app-shell { padding: 0 18px 70px; }
  .brand { flex-wrap: wrap; row-gap: 12px; }
  .brand-text p { display: none; }
  .account-badge { margin-left: 0; width: 100%; flex-wrap: wrap; justify-content: space-between; }
  .hero { padding: 34px 28px; }
  .hero h2 { font-size: 2.6rem; }
  .rp-title { font-size: 2.6rem; }
}

/* Phones */
@media (max-width: 640px) {
  /* 16px inputs stop iPhones from zooming the page when a field is tapped */
  input, select, textarea { font-size: 16px !important; }

  /* Comfortable thumb targets */
  .btn, .tab, .pill, .filter-chip, .mic-btn, .theme-toggle { min-height: 42px; }
  .btn-small { min-height: 38px; padding: 8px 14px; }
  .chip button { padding: 6px 8px; }

  .hero { padding: 22px 18px; border-radius: 26px; }
  .hero h2 { font-size: 2.05rem; }
  .hero-actions .btn { flex: 1; }
  .hero-visual { min-height: 230px; }
  .hero-tag { max-width: 190px; padding: 9px 12px; right: 10px; bottom: 10px; }

  .section-head { margin-top: 32px; flex-direction: column; align-items: flex-start; gap: 2px; }
  .rp-title { font-size: 2rem; }
  .rp-h { font-size: 1.4rem; margin-top: 30px; }
  .rp-meta { gap: 8px 20px; }
  .rp-actions .btn { flex: 1 1 calc(50% - 8px); }
  .rp-ingredients { padding: 20px 18px; }
  .rp-photo { transform: none; border-radius: 26px; }

  .cta-text h3 { font-size: 1.6rem; }
  .cta-photo { min-height: 190px; }

  .entry-actions .btn { flex: 1 1 calc(50% - 10px); }
  .entry-actions .btn-primary { flex-basis: 100%; }
  .pantry-add .btn { flex: 1; }

  .htc-search-row { flex-wrap: wrap; }
  .htc-search-row input { flex-basis: 100%; }
  .htc-search-row .btn { flex: 1; }

  .modal-overlay { padding: 10px; align-items: flex-end; }
  .modal { max-height: 92vh; max-height: 92dvh; border-radius: 26px 26px 18px 18px; }
  .cook-step-text { font-size: 1.1rem; }
  .toast { width: calc(100% - 28px); text-align: center; bottom: 16px; }
}

/* Very small phones (older Androids, iPhone SE) */
@media (max-width: 380px) {
  .app-shell { padding: 0 10px 50px; }
  .rgrid { gap: 8px; }
  .explore-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .explore-card-label { font-size: 0.9rem; left: 10px; bottom: 8px; }
  .hero h2 { font-size: 1.8rem; }
  .rcard-btn span { font-size: 0.68rem; }
  .auth-left { padding: 64px 16px 30px; }
  .auth-inner h2 { font-size: 1.7rem; }
  .nutrition-grid { gap: 8px; }
}

/* Landscape phones: don't let the login/hero eat the whole screen */
@media (max-height: 480px) and (orientation: landscape) {
  .auth-left { align-items: flex-start; padding-top: 60px; }
  .hero-visual { min-height: 200px; }
}

/* Large desktop monitors: a little more breathing room */
@media (min-width: 1400px) {
  .app-shell { max-width: 1240px; }
  .rgrid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
}

/* Touch devices: no sticky hover lift after tapping a card */
@media (hover: none) {
  .rcard:hover, .explore-card:hover { transform: none; box-shadow: none; }
  .rcard:hover .rcard-img img { transform: none; }
}

/* ===========================================================
   Print (recipe page only)
   =========================================================== */
@media print {
  body * { visibility: hidden; }
  #panel-recipe, #panel-recipe * { visibility: visible; }
  #panel-recipe { position: absolute; top: 0; left: 0; width: 100%; }
  .back-link, .rp-actions, .sub-btn { display: none !important; }
  .rp-photo { transform: none; box-shadow: none; }
}
