/* ==========================================================================
   CookInstruction — Design System
   Tokens + typography + shared components (Tailwind handles layout utilities)
   ========================================================================== */

:root {
  /* Color tokens */
  --paper:        #F8F4EC;   /* warm page background */
  --paper-raised: #FFFFFF;   /* cards / raised surfaces */
  --ink:          #2B2620;   /* primary text, near-black warm charcoal */
  --ink-soft:     #6B6255;   /* secondary text */
  --line:         #E7DFCF;   /* hairline borders/dividers */
  --basil:        #3F5A44;   /* primary brand — deep herb green */
  --basil-dark:   #2E4433;
  --sienna:       #B5502E;   /* accent — brick / roasted tomato */
  --sienna-dark:  #8F3E22;
  --mustard:      #D9A441;   /* highlight — turmeric / golden */
  --cream-shadow: rgba(43, 38, 32, 0.08);

  /* Type scale (major third-ish, tuned by hand) */
  --step--1: 0.875rem;
  --step-0:  1rem;
  --step-1:  1.25rem;
  --step-2:  1.75rem;
  --step-3:  2.5rem;
  --step-4:  3.4rem;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  background-color: var(--paper);
  color: var(--ink);
  font-family: 'Work Sans', ui-sans-serif, system-ui, sans-serif;
  font-size: var(--step-0);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.font-display {
  font-family: 'Fraunces', Georgia, 'Times New Roman', serif;
  font-optical-sizing: auto;
  letter-spacing: -0.01em;
}

h1, h2, h3, .heading {
  font-family: 'Fraunces', Georgia, 'Times New Roman', serif;
  color: var(--ink);
  line-height: 1.1;
  font-weight: 600;
}

h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }

@media (max-width: 640px) {
  h1 { font-size: 2.25rem; }
  h2 { font-size: 1.75rem; }
  h3 { font-size: 1.375rem; }
}

p { max-width: 68ch; }

a { color: inherit; }

/* Visible focus state everywhere — accessibility floor */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--basil);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 999px;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease;
  white-space: nowrap;
}
.btn-primary {
  background-color: var(--basil);
  color: var(--paper);
}
.btn-primary:hover { background-color: var(--basil-dark); }
.btn-secondary {
  background-color: transparent;
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.btn-secondary:hover { border-color: var(--ink); }
.btn-accent {
  background-color: var(--sienna);
  color: var(--paper);
}
.btn-accent:hover { background-color: var(--sienna-dark); }
.btn:active { transform: scale(0.98); }

/* ---------- Recipe card ---------- */
.recipe-card {
  display: block;
  background-color: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  transition: transform 220ms ease, box-shadow 220ms ease, border-color 220ms ease;
}
.recipe-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 32px -18px var(--cream-shadow);
  border-color: var(--basil);
}
.recipe-card figure {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background-color: var(--line);
}
.recipe-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 400ms ease;
}
.recipe-card:hover img { transform: scale(1.06); }

.badge {
  display: inline-block;
  padding: 0.25rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  background-color: rgba(63, 90, 68, 0.1);
  color: var(--basil-dark);
}
.badge-accent {
  background-color: rgba(181, 80, 46, 0.1);
  color: var(--sienna-dark);
}
.badge.chip-active {
  background-color: var(--basil);
  color: var(--paper);
}
button.badge {
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background-color 160ms ease, color 160ms ease;
}

.favorite-btn {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(248, 244, 236, 0.92);
  border-radius: 999px;
  transition: background-color 160ms ease, transform 160ms ease;
}
.favorite-btn:hover { transform: scale(1.08); }
.favorite-btn svg { width: 1.1rem; height: 1.1rem; stroke: var(--ink); fill: none; transition: fill 160ms ease, stroke 160ms ease; }
.favorite-btn.is-active svg { fill: var(--sienna); stroke: var(--sienna); }

.meta-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  color: var(--ink-soft);
  font-size: 0.875rem;
}
.meta-row .dot::before {
  content: "";
  display: inline-block;
  width: 3px;
  height: 3px;
  border-radius: 999px;
  background-color: var(--ink-soft);
  margin-right: 0.9rem;
  vertical-align: middle;
}

.rating-stars { color: var(--mustard); letter-spacing: 1px; }

/* ---------- Header / nav ---------- */
.site-header {
  background-color: var(--paper);
  border-bottom: 1px solid var(--line);
}
.nav-link {
  position: relative;
  padding-bottom: 4px;
  font-weight: 500;
  color: var(--ink-soft);
  transition: color 160ms ease;
}
.nav-link:hover, .nav-link[aria-current="page"] { color: var(--ink); }
.nav-link[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background-color: var(--sienna);
}

#mobile-menu {
  max-height: 0;
  overflow: hidden;
  transition: max-height 320ms ease;
}
#mobile-menu.is-open { max-height: 32rem; }

#search-overlay {
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease;
}
#search-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

/* ---------- Category card ---------- */
.category-card {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: flex-end;
  color: #fff;
}
.category-card img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform 400ms ease;
}
.category-card::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(20,17,13,0.75) 0%, rgba(20,17,13,0.05) 60%);
}
.category-card:hover img { transform: scale(1.08); }
.category-card .cat-label {
  position: relative;
  z-index: 1;
  padding: 1rem;
}

/* ---------- Ingredients ---------- */
.ingredient-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px dashed var(--line);
}
.ingredient-row:last-child { border-bottom: none; }
.ingredient-check {
  width: 1.15rem;
  height: 1.15rem;
  border: 1.5px solid var(--ink-soft);
  border-radius: 5px;
  flex-shrink: 0;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease;
}
.ingredient-check.is-checked {
  background-color: var(--basil);
  border-color: var(--basil);
}
.ingredient-row.is-checked .ingredient-name { color: var(--ink-soft); text-decoration: line-through; }

.stepper {
  display: inline-flex;
  align-items: center;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.stepper button {
  width: 2.5rem; height: 2.5rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  transition: background-color 160ms ease;
}
.stepper button:hover { background-color: var(--line); }
.stepper input {
  width: 2.75rem;
  text-align: center;
  border: none;
  background: transparent;
  font-weight: 600;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---------- Steps ---------- */
.step-item {
  display: flex;
  gap: 1.25rem;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--line);
}
.step-item:last-child { border-bottom: none; }
.step-number {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  background-color: var(--basil);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.15rem;
}

/* ---------- Tip cards ---------- */
.tip-card {
  background-color: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.5rem;
}

/* ---------- Nutrition ---------- */
.nutrition-bar {
  height: 6px;
  border-radius: 999px;
  background-color: var(--line);
  overflow: hidden;
}
.nutrition-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background-color: var(--basil);
}

/* ---------- Review stars (input) ---------- */
.star-input { display: inline-flex; gap: 0.25rem; }
.star-input button { font-size: 1.5rem; color: var(--line); transition: color 120ms ease; }
.star-input button.is-filled,
.star-input button:hover,
.star-input button:hover ~ button { color: var(--mustard); }

/* ---------- Accordion ---------- */
.accordion-item { border-bottom: 1px solid var(--line); }
.accordion-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 0;
  text-align: left;
  font-weight: 600;
  font-size: 1.05rem;
}
.accordion-trigger .chev { transition: transform 220ms ease; flex-shrink: 0; }
.accordion-item.is-open .accordion-trigger .chev { transform: rotate(180deg); }
.accordion-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 280ms ease;
  color: var(--ink-soft);
}
.accordion-item.is-open .accordion-panel { max-height: 20rem; padding-bottom: 1.25rem; }

/* ---------- Toast ---------- */
#toast-region {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}
.toast {
  background-color: var(--ink);
  color: var(--paper);
  padding: 0.7rem 1.25rem;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 12px 28px -12px rgba(0,0,0,0.35);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 220ms ease, transform 220ms ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

/* ---------- Skip link ---------- */
.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  background-color: var(--ink);
  color: var(--paper);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  transition: top 160ms ease;
  z-index: 100;
}
.skip-link:focus { top: 1rem; }

/* ---------- Utility ---------- */
.divider { border-color: var(--line); }
.text-soft { color: var(--ink-soft); }
.bg-basil { background-color: var(--basil); }
.text-basil { color: var(--basil); }
.text-sienna { color: var(--sienna); }
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.container-page {
  max-width: 80rem;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}
@media (min-width: 640px) {
  .container-page { padding-left: 2rem; padding-right: 2rem; }
}

/* ==========================================================================
   ADDITIONS FOR THE LIVE SITE
   Everything above this line is the original design system, untouched.
   Nothing below changes an existing rule — these are new classes and two
   containment fixes.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. MOBILE HORIZONTAL OVERFLOW FIX
   --------------------------------------------------------------------------
   The "All / Most popular / country" filter row was widening the whole page
   on small screens. The cause is a CSS default rather than anything in the
   design: a flex item's `min-width` is `auto`, so it refuses to shrink below
   its content width — which means `overflow-x: auto` on that item can never
   engage, and the row pushes the page wider instead of scrolling inside it.

   `.filter-scroll` sets `min-width: 0` (so the item may shrink) together with
   `max-width: 100%` (so it never exceeds its parent). The row then scrolls
   inside itself exactly like the category strip already did, and the page
   stops moving sideways. No spacing, colour or layout value changes.
   -------------------------------------------------------------------------- */
.filter-scroll {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}
.filter-scroll > * { scroll-snap-align: start; }

/* A thin, unobtrusive scrollbar rather than the OS default slab. */
.filter-scroll::-webkit-scrollbar { height: 4px; }
.filter-scroll::-webkit-scrollbar-track { background: transparent; }
.filter-scroll::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 999px;
}

/* The control group (Filters button, country select, sort select, Apply) is
   allowed to wrap on narrow screens instead of being pinned in one line. */
.filter-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}
.filter-controls > * { flex-shrink: 1; min-width: 0; }
.filter-controls select { text-overflow: ellipsis; }

@media (max-width: 640px) {
  .filter-controls { width: 100%; }
  .filter-controls select { flex: 1 1 8rem; max-width: 100%; }
  .filter-controls .btn { flex: 0 0 auto; }
}

/* The country checklist inside the filter panel can be long. */
.filter-country-list {
  max-height: 13rem;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding-right: 0.25rem;
}

/* Belt and braces: nothing may push the document sideways.
   `clip` rather than `hidden`, because `hidden` would turn <body> into a
   scroll container and break the sticky header. */
html { overflow-x: clip; }
body { overflow-x: clip; max-width: 100%; }

/* Anything that can carry long unbroken content stays inside its box. */
img, video, iframe, table, pre { max-width: 100%; }
.container-page { overflow-wrap: break-word; }

/* --------------------------------------------------------------------------
   2. NEW COMPONENTS
   -------------------------------------------------------------------------- */

/* Count badge on the "Filters" button. */
.filter-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  margin-left: 0.15rem;
  border-radius: 999px;
  background-color: var(--basil);
  color: var(--paper);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}

/* Chip links reuse .badge, so they need the same pointer affordance. */
a.badge { cursor: pointer; text-decoration: none; }
a.badge:hover { background-color: rgba(63, 90, 68, 0.18); }
a.badge.chip-active:hover { background-color: var(--basil-dark); }

/* Search type-ahead panel. */
.suggest-panel {
  position: absolute;
  z-index: 55;
  left: 0;
  right: 0;
  margin-top: 0.5rem;
  background-color: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 40px -24px rgba(43, 38, 32, 0.35);
  overflow: hidden;
  max-height: 22rem;
  overflow-y: auto;
}
.suggest-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  transition: background-color 120ms ease;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover,
.suggest-item.is-active { background-color: rgba(63, 90, 68, 0.07); }
.suggest-item .s-label { font-weight: 500; }
.suggest-item .s-meta  { font-size: 0.75rem; color: var(--ink-soft); white-space: nowrap; }

/* The save button on a recipe card, when the recipe is already saved. */
.btn.is-active { border-color: var(--sienna); color: var(--sienna); }

/* Screen-reader-only helper (Tailwind supplies sr-only, this is the fallback
   for the compiled-CSS path). */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* --------------------------------------------------------------------------
   3. PRINT — a recipe should print as a recipe, not as a web page.
   -------------------------------------------------------------------------- */
@media print {
  .site-header, footer, #search-overlay, #auth-gate-modal, #toast-region,
  .favorite-btn, .skip-link, [data-share], [data-print], [data-save-toggle],
  #filter-panel, #filter-form, .suggest-panel, form[data-review-form] {
    display: none !important;
  }
  body { background: #fff; color: #000; font-size: 11pt; }
  .container-page { max-width: 100%; padding: 0; }
  .recipe-card, .tip-card { break-inside: avoid; border-color: #ccc; }
  .step-item { break-inside: avoid; }
  a[href]::after { content: ""; }
  .lg\:sticky { position: static !important; }
}

/* --------------------------------------------------------------------------
   4. FILE INPUTS
   A file input carries a large intrinsic width (~350–460px in Chromium,
   driven by the "Choose file / no file selected" text). Inside a grid or flex
   track that is sized to its content, that intrinsic width — not the CSS
   width — decides the track size, and the container is pushed past the
   viewport. Capping it here fixes it everywhere at once.
   -------------------------------------------------------------------------- */
input[type="file"] {
  max-width: 100%;
  min-width: 0;
  display: block;
}

/* The freshness pill on recipe cards. Same shape as the existing badges, in
   the mustard accent so "New" reads as a highlight rather than a category. */
.badge-new {
  background-color: var(--mustard);
  color: #4A3A12;
  box-shadow: 0 1px 3px rgba(43, 38, 32, 0.18);
}
