:root {
  --bg: #fbf7f1;
  --surface: #ffffff;
  --surface-2: #f5efe6;
  --text: #2c2925;
  --muted: #716a62;
  --line: #e8ded1;
  --accent: #2e6650;
  --accent-soft: #e2eee8;
  --shadow: 0 12px 35px rgba(70, 52, 35, 0.09);
  --radius: 22px;
  --max: 1120px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.shell { max-width: var(--max); margin: 0 auto; padding: 30px 20px 56px; }

.hero {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:26px 30px;
  margin-bottom:20px;
}
.hero h1 {
  font-size:clamp(2rem, 4.5vw, 3.6rem);
  line-height:1.05;
  margin:0;
  letter-spacing:-.04em;
}
.hero-stat {
  flex:0 0 auto;
  display:inline-flex;
  align-items:center;
  gap:6px;
  background:var(--accent-soft);
  color:var(--accent);
  border-radius:999px;
  padding:7px 11px;
  white-space:nowrap;
  font-size:.85rem;
  font-weight:650;
}
.hero-stat strong { font-size:inherit; line-height:inherit; }

.filters { background:var(--surface); border:1px solid var(--line); border-radius:18px; padding:16px; margin-bottom:18px; }
.search-row { display:grid; grid-template-columns:1fr 220px auto; gap:12px; align-items:center; }
.search, .select, .tag-filter-button {
  width:100%;
  border:1px solid var(--line);
  background:#fff;
  color:var(--text);
  border-radius:14px;
  padding:13px 15px;
  outline:none;
  min-height:49px;
}
.search:focus, .select:focus, .tag-filter-button:focus-visible { border-color:var(--accent); box-shadow:0 0 0 3px var(--accent-soft); }

.tag-filter { position:relative; min-width:150px; }
.tag-filter-button {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  text-align:right;
  white-space:nowrap;
}
.tag-filter-button::after {
  content:"⌄";
  color:var(--muted);
  font-size:.95rem;
  transform:translateY(-1px);
}
.tag-filter-button.has-active-tag {
  background:var(--accent-soft);
  color:var(--accent);
  border-color:#c9ded4;
}
.tag-popover {
  position:absolute;
  z-index:20;
  top:calc(100% + 8px);
  inset-inline-end:0;
  width:min(360px, calc(100vw - 32px));
  max-height:330px;
  overflow:auto;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:16px;
  box-shadow:var(--shadow);
  padding:10px;
}
.tag-popover[hidden] { display:none; }
.tag-popover-title { margin:2px 4px 9px; color:var(--muted); font-size:.8rem; }
.tag-options { display:flex; flex-wrap:wrap; gap:7px; }
.chip { border:1px solid var(--line); border-radius:999px; padding:7px 11px; background:#fff; color:var(--muted); }
.chip.active { background:var(--accent); color:#fff; border-color:var(--accent); }

.results-head { display:flex; justify-content:space-between; align-items:center; gap:12px; margin:22px 2px 12px; }
.results-head h2 { margin:0; font-size:1.25rem; }
.results-head span { color:var(--muted); font-size:.9rem; }

.recipe-grid { display:grid; grid-template-columns:repeat(3, 1fr); gap:16px; }
.recipe-card { border:1px solid var(--line); border-radius:20px; background:var(--surface); padding:19px; text-align:right; min-height:210px; box-shadow:0 5px 18px rgba(70,52,35,.05); transition:.18s ease; }
.recipe-card:hover { transform:translateY(-3px); box-shadow:var(--shadow); border-color:#d8cab8; }
.card-category { display:inline-block; color:var(--accent); background:var(--accent-soft); border-radius:999px; padding:5px 9px; font-size:.78rem; margin-bottom:12px; }
.recipe-card-title { display:block; margin:0 0 8px; font-size:1.2rem; line-height:1.25; font-weight:700; }
.card-meta { display:block; color:var(--muted); font-size:.88rem; min-height:24px; }
.card-tags { display:flex; flex-wrap:wrap; gap:6px; margin-top:16px; }
.card-tag { background:var(--surface-2); border-radius:999px; padding:4px 8px; color:var(--muted); font-size:.75rem; }

.back { border:0; background:none; color:var(--accent); padding:7px 0; font-weight:600; }
.recipe-head { background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); padding:28px; box-shadow:var(--shadow); margin:12px 0 18px; }
.recipe-head h1 { margin:0 0 10px; font-size:clamp(2rem,4vw,3.2rem); line-height:1.08; }
.recipe-sub { display:flex; gap:10px; flex-wrap:wrap; color:var(--muted); }
.recipe-tag-list { display:flex; gap:7px; flex-wrap:wrap; margin-top:16px; }
.recipe-layout { display:grid; grid-template-columns:.85fr 1.35fr; gap:18px; align-items:start; }
.panel { background:var(--surface); border:1px solid var(--line); border-radius:20px; padding:22px; }
.panel h2 { margin:0 0 16px; font-size:1.28rem; }
.ingredient-group + .ingredient-group { margin-top:20px; }
.ingredient-group h3 { font-size:1rem; margin:0 0 9px; color:var(--muted); }
.ingredients { list-style:none; margin:0; padding:0; }
.ingredients li { padding:8px 0; border-bottom:1px solid #f1ebe3; }
.ingredients li:last-child { border-bottom:0; }
.ingredient-note { display:block; color:var(--muted); font-size:.82rem; margin-top:2px; }
.steps { list-style:none; padding:0; margin:0; }
.step { display:grid; grid-template-columns:42px 1fr; gap:12px; padding:13px 0; border-bottom:1px solid #f1ebe3; }
.step:last-child { border-bottom:0; }
.step-num { width:36px; height:36px; display:grid; place-items:center; background:var(--accent-soft); color:var(--accent); border-radius:50%; font-weight:700; }
.step h3 { margin:0 0 4px; font-size:1rem; }
.step p { margin:0; }
.variation { background:var(--surface-2); border-radius:14px; padding:12px 14px; margin-top:10px; }
.variation strong { display:block; margin-bottom:3px; }
.actions { display:flex; gap:10px; flex-wrap:wrap; margin-top:18px; }
.primary { border:0; background:var(--accent); color:#fff; border-radius:14px; padding:12px 16px; font-weight:650; }
.secondary { border:1px solid var(--line); background:#fff; border-radius:14px; padding:12px 16px; }
.secondary:disabled { opacity:.45; cursor:default; }

.cook-shell { min-height:100vh; display:grid; place-items:center; padding:20px; }
.cook-card { width:min(720px, 100%); background:var(--surface); border:1px solid var(--line); border-radius:28px; padding:28px; box-shadow:var(--shadow); }
.cook-top { display:flex; justify-content:space-between; align-items:center; gap:12px; }
.cook-top small { color:var(--muted); }
.progress { height:7px; background:var(--surface-2); border-radius:99px; overflow:hidden; margin:18px 0 26px; }
.progress > div { height:100%; background:var(--accent); transition:width .2s ease; }
.cook-card h1 { font-size:clamp(1.65rem,4vw,2.6rem); margin:0 0 10px; line-height:1.15; }
.cook-instruction { font-size:clamp(1.15rem,3vw,1.55rem); line-height:1.6; margin:0; }
.cook-ingredients { background:var(--surface-2); border-radius:16px; padding:14px; margin:22px 0; }
.cook-ingredients strong { display:block; margin-bottom:7px; }
.cook-ingredients ul { margin:0; padding-right:20px; }
.cook-nav { display:flex; justify-content:space-between; gap:10px; margin-top:24px; }
.cook-nav button { flex:1; }
.empty { text-align:center; padding:60px 10px; color:var(--muted); }
.loading { display:grid; place-items:center; min-height:70vh; color:var(--muted); }

@media (max-width: 850px) {
  .search-row { grid-template-columns:1fr 190px auto; }
  .recipe-layout { grid-template-columns:1fr; }
  .recipe-grid { grid-template-columns:repeat(2, 1fr); }
}
/* v3: mobile density + timers */
.tag-icon { font-weight:800; opacity:.75; }
.tag-label { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.timer-button {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  margin-top:12px;
  border:1px solid #c9ded4;
  background:var(--accent-soft);
  color:var(--accent);
  border-radius:12px;
  padding:9px 12px;
  font-weight:700;
  min-height:40px;
}
.timer-button.is-active { background:var(--accent); color:#fff; border-color:var(--accent); }
.active-timer {
  position:fixed;
  z-index:50;
  left:50%;
  bottom:14px;
  transform:translateX(-50%);
  width:min(520px, calc(100vw - 26px));
  display:grid;
  grid-template-columns:auto 1fr auto;
  align-items:center;
  gap:10px;
  background:#252f2b;
  color:#fff;
  border-radius:16px;
  padding:10px 12px;
  box-shadow:0 12px 30px rgba(0,0,0,.22);
}
.active-timer-icon { font-size:1.15rem; }
.active-timer-copy { min-width:0; display:flex; align-items:baseline; gap:8px; }
.active-timer-copy strong { font-variant-numeric:tabular-nums; font-size:1.05rem; }
.active-timer-copy span { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:#d7ddd9; font-size:.82rem; }
.timer-cancel { border:0; background:rgba(255,255,255,.12); color:#fff; border-radius:10px; padding:7px 9px; }
.notes-panel .variation { margin-top:8px; }

@media (max-width: 650px) {
  .shell { padding:10px 13px 40px; }
  .recipe-head, .cook-card { padding:21px; }
  .recipe-grid { grid-template-columns:1fr; }
  .recipe-layout { gap:12px; }
  .hero {
    align-items:center;
    flex-wrap:nowrap;
    padding:14px 15px;
    margin-bottom:10px;
    border-radius:16px;
    gap:8px;
  }
  .hero h1 {
    flex:1 1 auto;
    min-width:0;
    font-size:clamp(1.55rem, 7vw, 2rem);
    line-height:1.05;
    white-space:nowrap;
  }
  .hero-stat {
    flex:0 0 auto;
    margin:0;
    padding:5px 8px;
    font-size:.74rem;
  }
  .filters { padding:10px; margin-bottom:10px; border-radius:16px; }
  .search-row {
    grid-template-columns:minmax(0, 1fr) auto;
    grid-template-areas:
      "search search"
      "category tags";
    gap:8px;
  }
  .search { grid-area:search; min-height:44px; padding:10px 12px; }
  .select { grid-area:category; min-height:42px; padding:8px 10px; }
  .tag-filter { grid-area:tags; min-width:0; max-width:46vw; }
  .tag-filter-button {
    width:auto;
    max-width:46vw;
    min-height:42px;
    padding:8px 11px;
    justify-content:center;
    background:#fff;
  }
  .tag-filter-button::after { display:none; }
  .tag-popover {
    position:fixed;
    z-index:60;
    inset-inline:13px;
    bottom:13px;
    top:auto;
    width:auto;
    max-height:min(58vh, 420px);
    border-radius:20px;
    padding:14px;
    box-shadow:0 18px 50px rgba(0,0,0,.2);
  }
  .tag-popover-title { font-size:.9rem; margin-bottom:12px; }
  .chip { padding:8px 12px; }
  .results-head { margin:14px 2px 9px; }
  .recipe-card { min-height:0; padding:16px; }
  .active-timer { bottom:9px; width:calc(100vw - 18px); }
  .cook-shell { padding:10px; align-items:start; }
  .cook-card { margin-top:0; }
}

@media (max-width: 430px) {
  .hero { flex-wrap:nowrap; }
  .hero h1 { flex-basis:auto; }
  .hero-stat { width:auto; }
  .active-timer-copy span { display:none; }
}

.recipe-source { margin-top:10px; color:var(--muted); font-size:.86rem; }
.recipe-source a { color:var(--accent); font-weight:650; text-decoration:none; }
.recipe-source a:hover { text-decoration:underline; }

/* v6: cooking-mode timing + prepared components */
.timer-controls {
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:7px;
  margin-top:12px;
}
.timer-controls .timer-button { margin-top:0; }
.timer-button-alt {
  background:#fff;
  color:var(--accent);
}
.timer-hint {
  flex-basis:100%;
  color:var(--muted);
  font-size:.78rem;
  line-height:1.35;
}
.prepared-need {
  color:var(--accent);
  font-weight:650;
}
.prepared-need::marker { color:var(--accent); }

@media (max-width: 650px) {
  .timer-controls { gap:6px; }
  .timer-controls .timer-button { min-height:38px; padding:8px 10px; }
  .timer-hint { font-size:.74rem; }
  .cook-ingredients { margin:16px 0; }
}

/* v7: modern visual refresh */
:root {
  --bg: #f6f2ec;
  --surface: #fffdf9;
  --surface-2: #f1ebe3;
  --surface-3: #e8e0d5;
  --text: #202b27;
  --muted: #6e746f;
  --line: #e5ddd2;
  --accent: #245344;
  --accent-strong: #183b30;
  --accent-soft: #e3eee8;
  --warm: #c96d4f;
  --warm-soft: #f5e4dc;
  --gold: #d8a25d;
  --shadow-sm: 0 6px 18px rgba(54, 45, 36, .055);
  --shadow: 0 16px 44px rgba(54, 45, 36, .10);
  --radius: 24px;
}

body {
  font-family: "Rubik", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at 92% -10%, rgba(216,162,93,.11), transparent 31rem),
    radial-gradient(circle at -8% 18%, rgba(36,83,68,.07), transparent 26rem),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

.shell { padding-top: 26px; }

.hero {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 7px 4px 18px;
  margin-bottom: 4px;
}
.hero h1 {
  font-weight: 700;
  color: var(--accent-strong);
  letter-spacing: -.045em;
}
.hero-stat {
  background: rgba(255,253,249,.72);
  color: var(--accent);
  border: 1px solid rgba(36,83,68,.13);
  box-shadow: 0 3px 12px rgba(54,45,36,.04);
  backdrop-filter: blur(8px);
}

.filters {
  background: rgba(255,253,249,.82);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
  border-color: rgba(229,221,210,.9);
}
.search, .select, .tag-filter-button {
  background: rgba(255,255,255,.9);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.search:hover, .select:hover, .tag-filter-button:hover { border-color:#d4c8ba; }
.search:focus, .select:focus, .tag-filter-button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(36,83,68,.10);
}

.results-head h2 { color:var(--accent-strong); font-weight:650; }

.recipe-grid { gap:18px; }
.recipe-card {
  position:relative;
  overflow:hidden;
  display:flex;
  flex-direction:column;
  padding:0;
  min-height:320px;
  border-radius:24px;
  background:var(--surface);
  box-shadow:var(--shadow-sm);
  border-color:rgba(229,221,210,.88);
  transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
}
.recipe-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow);
  border-color: rgba(201,109,79,.22);
}
.recipe-card:focus-visible {
  outline:none;
  box-shadow:0 0 0 4px rgba(36,83,68,.13), var(--shadow);
}
.recipe-card-body {
  display:flex;
  flex:1;
  flex-direction:column;
  align-items:flex-start;
  width:100%;
  padding:17px 18px 18px;
  text-align:right;
}
.card-category {
  margin-bottom:10px;
  background:var(--accent-soft);
  color:var(--accent);
  font-weight:600;
  letter-spacing:-.01em;
}
.recipe-card-title {
  font-size:1.24rem;
  font-weight:650;
  letter-spacing:-.025em;
  color:var(--text);
}
.card-meta { min-height:0; font-size:.84rem; }
.card-tags { margin-top:auto; padding-top:15px; }
.card-tag { background:#f2ede6; color:#626961; }

.recipe-visual {
  position:relative;
  overflow:hidden;
  display:block;
  isolation:isolate;
}
.recipe-visual-card { width:100%; height:142px; }
.recipe-visual-large { width:300px; min-height:230px; align-self:stretch; border-radius:20px; }
.recipe-visual.has-image img { width:100%; height:100%; object-fit:cover; display:block; }
.recipe-visual-icon {
  position:absolute;
  z-index:2;
  inset:0;
  display:grid;
  place-items:center;
  font-size:3.4rem;
  filter:drop-shadow(0 7px 14px rgba(0,0,0,.09));
  transform:rotate(-4deg);
}
.recipe-visual-large .recipe-visual-icon { font-size:5.2rem; }
.recipe-visual-shape {
  position:absolute;
  z-index:1;
  width:155px;
  height:155px;
  border-radius:46% 54% 62% 38% / 47% 38% 62% 53%;
  background:rgba(255,255,255,.42);
  top:-35px;
  left:-24px;
  transform:rotate(17deg);
}
.recipe-visual::after {
  content:"";
  position:absolute;
  z-index:0;
  width:105px;
  height:105px;
  border-radius:50%;
  background:rgba(255,255,255,.20);
  bottom:-38px;
  right:18px;
}
.visual-chicken { background:linear-gradient(135deg,#f2c9a8,#e99e76); }
.visual-meat { background:linear-gradient(135deg,#dba08a,#bd725d); }
.visual-fish { background:linear-gradient(135deg,#b9d9d6,#78b3ae); }
.visual-dessert { background:linear-gradient(135deg,#e9c6d3,#d99caf); }
.visual-side { background:linear-gradient(135deg,#d9d9a6,#b7c889); }
.visual-sauce { background:linear-gradient(135deg,#bcd5b3,#82ad79); }
.visual-bake { background:linear-gradient(135deg,#ead0a6,#d9a96e); }
.visual-default { background:linear-gradient(135deg,#d8d2c8,#b9b0a3); }

.back {
  color:var(--accent);
  font-weight:600;
  border-radius:10px;
  transition:background .16s ease;
}
.back:hover { background:rgba(36,83,68,.06); }
.recipe-head {
  display:grid;
  grid-template-columns:minmax(0, 1fr) 300px;
  gap:24px;
  padding:22px;
  align-items:stretch;
  background:rgba(255,253,249,.9);
  backdrop-filter:blur(10px);
}
.recipe-head-copy { padding:7px 5px; display:flex; flex-direction:column; align-items:flex-start; }
.recipe-head h1 {
  color:var(--accent-strong);
  font-weight:700;
  letter-spacing:-.045em;
  margin-top:2px;
}
.recipe-sub { font-size:.92rem; }
.recipe-tag-list { margin-top:14px; }
.actions { margin-top:auto; padding-top:22px; }
.primary {
  background:linear-gradient(135deg,var(--accent),#326a57);
  box-shadow:0 7px 17px rgba(36,83,68,.18);
  transition:transform .16s ease, box-shadow .16s ease;
}
.primary:hover { transform:translateY(-1px); box-shadow:0 9px 21px rgba(36,83,68,.23); }
.secondary:hover { border-color:#cfc3b5; background:#fcfaf7; }

.panel {
  background:rgba(255,253,249,.94);
  box-shadow:var(--shadow-sm);
  border-color:rgba(229,221,210,.9);
}
.panel h2 { color:var(--accent-strong); font-weight:650; letter-spacing:-.02em; }
.ingredient-group h3 { color:#73766f; font-weight:600; }
.ingredients li, .step { border-bottom-color:#efe8df; }
.step-num { background:var(--warm-soft); color:var(--warm); }
.variation { background:#f3eee7; }
.recipe-source a { color:var(--warm); }

.cook-shell {
  background:
    radial-gradient(circle at 85% 5%, rgba(216,162,93,.13), transparent 28rem),
    var(--bg);
}
.cook-card {
  background:rgba(255,253,249,.97);
  border-color:rgba(229,221,210,.92);
  box-shadow:0 24px 60px rgba(54,45,36,.12);
}
.progress { background:#ebe5dd; }
.progress > div { background:linear-gradient(90deg,var(--warm),var(--gold)); }
.cook-card h1 { color:var(--accent-strong); letter-spacing:-.03em; }
.cook-ingredients { background:#f2ede6; }
.timer-button {
  border-color:rgba(36,83,68,.17);
  background:var(--accent-soft);
}
.active-timer { background:#1f302a; }

@media (max-width: 850px) {
  .recipe-head { grid-template-columns:minmax(0,1fr) 245px; }
  .recipe-visual-large { width:245px; }
}

@media (max-width: 650px) {
  body { background:var(--bg); }
  .shell { padding-top:10px; }
  .hero { padding:5px 2px 12px; }
  .hero h1 { color:var(--accent-strong); font-size:clamp(1.45rem,6.8vw,1.9rem); }
  .filters { box-shadow:none; background:var(--surface); }
  .recipe-grid { gap:12px; }
  .recipe-card {
    min-height:0;
    display:grid;
    grid-template-columns:104px minmax(0,1fr);
    align-items:stretch;
    border-radius:18px;
  }
  .recipe-visual-card { width:104px; height:100%; min-height:145px; }
  .recipe-visual-card .recipe-visual-icon { font-size:2.55rem; }
  .recipe-card-body { padding:13px 14px; }
  .card-category { margin-bottom:7px; padding:4px 8px; font-size:.72rem; }
  .recipe-card-title { font-size:1.08rem; margin-bottom:5px; }
  .card-meta { font-size:.79rem; }
  .card-tags { padding-top:10px; gap:4px; }
  .card-tag { font-size:.69rem; padding:3px 6px; }

  .recipe-head {
    display:flex;
    flex-direction:column-reverse;
    padding:14px;
    gap:14px;
    border-radius:20px;
  }
  .recipe-visual-large {
    width:100%;
    min-height:165px;
    max-height:190px;
    border-radius:15px;
  }
  .recipe-visual-large .recipe-visual-icon { font-size:4.3rem; }
  .recipe-head-copy { padding:2px 3px 4px; }
  .recipe-head h1 { font-size:clamp(1.75rem,8vw,2.45rem); }
  .actions { padding-top:17px; width:100%; }
  .actions .primary { width:100%; }
  .panel { border-radius:17px; box-shadow:none; }
  .cook-card { border-radius:21px; }
}
