/*
 * Global design tokens, typography, and shared UI patterns.
 *
 * Propshaft serves each stylesheet individually — no bundling. This file
 * is loaded globally in the application layout alongside navshell.css and
 * print.css (plus mirabel.css when AI is configured). Page sheets — editor,
 * settings, menu, groceries, ingredients, nutrition, recipe — load per-page
 * via content_for(:head).
 *
 * Conventions:
 * - Color tokens: all in :root below — check before inventing new names
 * - Icons: IconHelper#icon(name, size:) / JS buildIcon(name, size) — never raw SVG
 * - Inputs: .input-base + modifiers
 * - Buttons: .btn + modifiers
 * - Page titles: <header class="page-header"> on non-document pages — never
 *   style bare header/section/footer; document typography (header/section/
 *   footer/ingredients/instructions families) is :where()-scoped to its
 *   document roots — per-rule root lists vary by consumer (#1876, complete)
 * - Collapse: <details class="collapse-header"> pattern
 * - Editor classes: editor- prefix
 * - [hidden]: a global `[hidden] { display: none !important }` (below the
 *   box-sizing reset) guarantees the attribute always hides, overriding any
 *   author `display`. An element that must stay in layout while inert uses a
 *   visibility class instead of the attribute (see `.scale-reset.is-hidden`).
 *
 * Responsive: page chrome uses @media queries (pantry.css's
 * @media (max-width: 640px) is the worked example).
 *
 * Collaborators: fonts.css (@font-face faces — linked before this sheet),
 *   navshell.css + print.css (global peers), the per-page sheets
 *   (editor, settings, menu, ...), IconHelper, base layout (application.html.erb)
 */

/* Universal border-box — every element sizes width/height inclusive of
   padding + border. Modern default; makes design-tool-generated components
   predictable. The per-element `box-sizing: border-box` patches elsewhere
   (.input-base, .pill, .editor-textarea, …) are now redundant but harmless. */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The hidden attribute MEANS display:none — but a UA stylesheet rule is the
   lowest cascade origin, so any author `display:` on a class (e.g. .pantry-row
   { display:flex }) silently outranks it and the element stays visible (#1737).
   Forcing it !important here makes `hidden` reliably hide app-wide, so JS that
   toggles the attribute never needs a per-selector escape hatch. An element that
   must stay in layout while inert must NOT use the attribute — toggle a
   visibility class instead (see .scale-reset.is-hidden). */
[hidden] {
  display: none !important;
}

:root {
  --font-display: "Instrument Serif", "Instrument Serif Fallback", Georgia, serif;
  --font-body: "Outfit", "Outfit Fallback", system-ui, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;

  /* Canonical color tokens */
  --ground: #faf8f5;
  --text: #2d2a26;
  --text-soft: #706960;
  --text-light: #a09788;
  --text-faint: #c8bfb2; /* faintest text rung — struck-off groceries, meta counts */
  --red: #b33a3a;
  --red-light: rgba(179, 58, 58, 0.08);
  --tag-filter-active-bg: rgba(179, 58, 58, 0.15);
  --rule: #e4dfd8;
  --rule-faint: #eee9e3;

  --surface-alt: #f7f5f1;
  --hover-bg: var(--red-light);
  --hover-bg-strong: rgba(179, 58, 58, 0.15);

  --input-bg: white;
  --accent-hover: #993030;
  --scaled-highlight: rgba(255, 243, 205, 0.6);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-dialog: 0 4px 24px rgba(0, 0, 0, 0.15);
  --dialog-backdrop: rgba(0, 0, 0, 0.5);
  --aisle-renamed-bg: #fff8e1;
  --aisle-renamed-border: #ffe082;
  --aisle-new-bg: #e8f5e9;
  --aisle-new-border: #a5d6a7;
  --broken-reference-bg: #fdf6f0;
  --aisle-row-border: #e0e0e0;
  --danger-hover-bg: rgba(204, 0, 0, 0.08);

  /* Notification bar — upward-facing nav shadow */
  --shadow-nav-up: 0 -2px 4px rgba(0, 0, 0, 0.08), 0 -1px 2px rgba(0, 0, 0, 0.04);

  /* Tag/category pill colors */
  --tag-bg: #e8e3db;
  --tag-text: #4a4540;
  --cat-bg: #dde7d8;
  --cat-text: #3a4a35;

  /* Smart tag color groups */
  --smart-green-bg: #d4edda;    --smart-green-text: #1b5e20;
  --smart-amber-bg: #fff3cd;    --smart-amber-text: #7a5d00;
  --smart-blue-bg: #d6eaf8;     --smart-blue-text: #1a4a6e;
  --smart-rose-bg: #f5e0d0;     --smart-rose-text: #6e3222;
  --smart-purple-bg: #e8daf5;   --smart-purple-text: #4a2080;
  --smart-cuisine-bg: #f5ddd0;  --smart-cuisine-text: #6e3a22;

  /* Design-system semantic roles — kept neutral so the brand red carries
   * focus. --danger is the canonical danger role. */
  --positive: #4a7a4a;
  --warning:  #b8862a;
  --danger:   #c00;
  --info:     #4a6e8a;

  /* "Her" jewel-tone pigments — sparing use for tag color + illustration. */
  --pigment-rose:  #e6a896;
  --pigment-clay:  #c87a5a;
  --pigment-amber: #d9a847;
  --pigment-leaf:  #6b8a5a;
  --pigment-mint:  #a8c5a8;
  --pigment-sky:   #8aa7c0;
  --pigment-plum:  #a87c8c;
  --pigment-stone: #b8a995;

  /* Transition timing — use these instead of bare durations */
  --duration-fast: 0.12s;
  --duration-normal: 0.2s;
  --duration-slow: 0.35s;
  --duration-bloop: 0.25s;

  /* Page gutter — sole survivor of the gingham-tablecloth tokens (the
     tablecloth gradient is inlined in html{}, not token-driven). */
  --gingham-gap: 1.5rem;
  --content-card-bg: rgb(255, 252, 249);
  --paper-opacity: 0.06;
  --noise-tile: 200px;   /* paper-noise overlay tile size */

  /* Pantry v2 design tokens — see docs/superpowers/specs/2026-05-03-ph2-background-tokens-design.md */

  /* Spacing scale */
  --space-0: 0;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;
  --space-9: 6rem;
  --gutter: 1.5rem;   /* design-system page gutter */

  /* Radius scale */
  --radius-xs: 2px;
  --radius-sm: 3px;
  --radius-md: 0.4rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1.25rem;
  --radius-pill: 999px;

  /* Keyboard focus ring — one shorthand for the hand-copied `2px solid var(--red)`
     outline. Value is identical in dark mode, so it lives in the light :root only. */
  --focus-ring: 2px solid var(--red);
  --focus-ring-offset: 2px;

  /* Stacking order, low -> high. Global chrome only; page-local stacks stay literal. */
  --z-raised: 10;
  --z-nav: 30;
  --z-nav-overflow: 80;
  --z-overlay: 90;
  --z-toast: 100;
  --z-progress: 2147483647;

  /* Type scale (root font-size = 18px) */
  --type-xs: 0.72rem;
  --type-sm: 0.85rem;
  --type-base: 1rem;
  --type-lg: 1.15rem;
  --type-xl: 1.3rem;
  --type-2xl: 1.4rem;
  --type-3xl: 2.6rem;
  --type-4xl: 3.8rem;
  --type-5xl: 5.6rem;       /* curtain-rise hero (rare) */

  /* Line-height scale — typographic leading tokens */
  --leading-flat: 1;        /* UI resets, single-line chrome */
  --leading-tight: 1.2;     /* large/display headings */
  --leading-snug: 1.35;     /* section headings */
  --leading-body: 1.4;      /* body default */
  --leading-relaxed: 1.5;   /* long-form copy */
  --leading-prose: 1.75;    /* recipe instructions / long prose */

  /* Letter-spacing scale */
  --tracking-normal: 0;
  --tracking-tight: -0.01em;
  --tracking-wide: 0.12em;  /* uppercase eyebrows */

  /* Easing curves */
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-bloop: cubic-bezier(0.16, 0.75, 0.40, 1);
  --ease-whisk: cubic-bezier(0.5, 1.35, 0.4, 1);

  /* Paper shadow — 3-layer with directional offset */
  --shadow-paper:
    0 1px 3px rgba(0, 0, 0, 0.07),
    0 4px 8px rgba(0, 0, 0, 0.05),
    3px 8px 14px rgba(0, 0, 0, 0.08);

  /* Pressed-state inset — recipe cards / pressable surfaces */
  --shadow-press: inset 0 1px 2px rgba(0, 0, 0, 0.06);

  /* ── Pantry surfaces (Ph3) ─────────────────────────────────── */
  --editor-panel-bg: #faf6ef;

  /* Nav button vocabulary — lifted from Mirepoix_Design_System-2026-05-27/colors_and_type.css.
   * Aliases first: design-system names mapped to existing tokens of the same value.
   * The originals stay where they are; aliases let nav CSS use design-system names.
   */
  --red-deep:    var(--accent-hover);             /* #993030 */
  --red-soft:    var(--red-light);                /* rgba(179, 58, 58, 0.08) */
  --red-soft-2:  var(--hover-bg-strong);          /* rgba(179, 58, 58, 0.15) */

  /* Genuinely new colors */
  --ground-deep: #f3ede4;
  --red-glow:    rgba(179, 58, 58, 0.42);

  /* Button vocabulary — interactive shadow recipes */
  --shadow-deboss:
    inset 0 1px 3px rgba(0, 0, 0, 0.12),
    inset 0 -1px 0 rgba(255, 255, 255, 0.30);
  --shadow-deboss-deep:
    inset 0 2px 5px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(0, 0, 0, 0.04),
    inset 0 -1px 0 rgba(255, 255, 255, 0.40);
  --shadow-deboss-modal:
    inset 0 1px 3px rgba(0, 0, 0, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -1px 0 rgba(0, 0, 0, 0.02),
    0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-emboss:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 1px 2px rgba(0, 0, 0, 0.06),
    0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-emboss-bordered:
    inset 0 0 0 1px rgba(0, 0, 0, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 1px 2px rgba(0, 0, 0, 0.06),
    0 2px 4px rgba(0, 0, 0, 0.04);

  /* Halos — backlit-paper hover glow */
  --halo-text: 0 0 5px var(--red-glow);
  --halo-icon: drop-shadow(0 0 5px var(--red-glow));
  /* Padded-master ratio of the committed wordmark SVG (docs/brand/README.md).
   * Regenerating the wordmark (docs/brand/build_wordmark_svg.py) prints the
   * replacement value for this constant. */
  --wordmark-aspect: 2632 / 993;
  /* Optical-centring nudge: how far DOWN to translate the wordmark glyph so its
   * ink centre of mass — not its geometric box centre — lands on a flexbox
   * centre line beside the coral mark. Derived from the glyph's area-weighted
   * centroid and printed by build_wordmark_svg.py. Applied only where the
   * wordmark sits next to the mark (nav pill, help topbar); a standalone
   * heading needs none. */
  --wordmark-optical-shift: 7.50%;

  /* Pill chrome — opaque paper capsule */
  --pill-bg:     rgb(255, 252, 249);
  --pill-border: rgba(0, 0, 0, 0.07);
  --pill-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.65),
    inset 0 -1px 0 rgba(0, 0, 0, 0.04),
    0 1px 3px rgba(0, 0, 0, 0.08),
    0 6px 14px rgba(0, 0, 0, 0.10),
    3px 12px 28px rgba(0, 0, 0, 0.14);

  /* Popovers — brand menu, search sheet */
  --shadow-popover:
    0 1px 3px rgba(0, 0, 0, 0.08),
    0 4px 10px rgba(0, 0, 0, 0.06),
    3px 8px 22px rgba(0, 0, 0, 0.14);
  --shadow-popover-lg:
    0 1px 3px rgba(0, 0, 0, 0.08),
    0 8px 24px rgba(0, 0, 0, 0.14),
    3px 14px 36px rgba(0, 0, 0, 0.16);

  /* Additional motion */
  --ease-curtain:     cubic-bezier(0.22, 0.61, 0.36, 1);
  --duration-curtain: 0.6s;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Canonical dark-mode color tokens */
    --ground: #1e1b18;
    --text: #dcd7d0;
    --text-soft: #a09788;
    --text-light: #706960;
    --text-faint: #4a443d;
    --red: #c85050;
    --red-light: rgba(200, 80, 80, 0.12);
    --tag-filter-active-bg: rgba(200, 80, 80, 0.2);
    --rule: #3a3530;
    --rule-faint: #2e2a26;

    --surface-alt: #2a2724;
    --danger: #d05050;
    --hover-bg: rgba(255, 255, 255, 0.04);
    --hover-bg-strong: rgba(200, 80, 80, 0.22);

    --input-bg: #1a1816;
    --accent-hover: #a03838;
    --scaled-highlight: rgba(180, 140, 60, 0.2);

    /* Shadows — reduced opacity for dark backgrounds */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.16), 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-dialog: 0 4px 24px rgba(0, 0, 0, 0.3);
    --dialog-backdrop: rgba(0, 0, 0, 0.65);
    --shadow-nav-up: 0 -2px 4px rgba(0, 0, 0, 0.16), 0 -1px 2px rgba(0, 0, 0, 0.08);

    /* Status indicators */
    --aisle-renamed-bg: rgba(180, 140, 40, 0.15);
    --aisle-renamed-border: rgba(180, 140, 40, 0.3);
    --aisle-new-bg: rgba(60, 140, 70, 0.15);
    --aisle-new-border: rgba(60, 140, 70, 0.3);
    --broken-reference-bg: rgb(42, 36, 32);
    --aisle-row-border: rgb(55, 52, 48);
    --danger-hover-bg: rgba(220, 60, 50, 0.12);

    /* Tag/category pill colors */
    --tag-bg: #3a3530;
    --tag-text: #c8c0b5;
    --cat-bg: #2e3a2b;
    --cat-text: #a8c8a0;

    /* Smart tag color groups */
    --smart-green-bg: #1a3a1e;    --smart-green-text: #a8d8a0;
    --smart-amber-bg: #3a3018;    --smart-amber-text: #d8c070;
    --smart-blue-bg: #1a2e3e;     --smart-blue-text: #90c0e0;
    --smart-rose-bg: #3a2420;     --smart-rose-text: #d8a890;
    --smart-purple-bg: #2a1e3a;   --smart-purple-text: #c0a8e0;
    --smart-cuisine-bg: #3a2820;  --smart-cuisine-text: #d8b0a0;

    --content-card-bg: rgb(30, 27, 24);
    --paper-opacity: 0.03;

    /* ── Pantry surfaces (Ph3) ─────────────────────────────────── */
    --editor-panel-bg: #1d1a14;

    /* Nav button vocabulary — dark counterparts (verbatim from
     * Mirepoix_Design_System-2026-05-27/colors_and_type.css:224-298). */
    --ground-deep: #181512;
    --red-glow:    rgba(200, 80, 80, 0.55);

    /* Aliases — point at the dark variants of existing tokens */
    --red-deep:    var(--accent-hover);              /* dark: #a03838 */
    --red-soft:    var(--red-light);                 /* dark: rgba(200, 80, 80, 0.12) */
    --red-soft-2:  var(--hover-bg-strong);           /* dark: rgba(200, 80, 80, 0.22) */

    /* Button vocabulary — white counter-highlights drop to warm-white at
     * lower opacity; black inset shadows deepen for paper depth. */
    --shadow-deboss:
      inset 0 1px 3px rgba(0, 0, 0, 0.45),
      inset 0 -1px 0 rgba(255, 252, 249, 0.04);
    --shadow-deboss-deep:
      inset 0 2px 5px rgba(0, 0, 0, 0.50),
      inset 0 1px 0 rgba(0, 0, 0, 0.30),
      inset 0 -1px 0 rgba(255, 252, 249, 0.06);
    --shadow-deboss-modal:
      inset 0 1px 3px rgba(0, 0, 0, 0.45),
      inset 0 1px 0 rgba(255, 252, 249, 0.04),
      inset 0 -1px 0 rgba(255, 252, 249, 0.02),
      0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-emboss:
      inset 0 1px 0 rgba(255, 252, 249, 0.08),
      0 1px 2px rgba(0, 0, 0, 0.35),
      0 2px 4px rgba(0, 0, 0, 0.25);
    --shadow-emboss-bordered:
      inset 0 0 0 1px rgba(255, 252, 249, 0.06),
      inset 0 1px 0 rgba(255, 252, 249, 0.08),
      0 1px 2px rgba(0, 0, 0, 0.35),
      0 2px 4px rgba(0, 0, 0, 0.25);

    /* Halos — the light values (0 0 5px var(--red-glow)) inherit via the
     * cascade; --red-glow's dark value gives a brighter halo against dark. */

    /* Pill chrome — warm-dark fill + low-opacity warm-white top highlight
     * (much subtler than the light recipe's 0.65 white). */
    --pill-bg:     rgb(34, 31, 28);
    --pill-border: rgba(255, 252, 249, 0.08);
    --pill-shadow:
      inset 0 1px 0 rgba(255, 252, 249, 0.06),
      inset 0 -1px 0 rgba(0, 0, 0, 0.30),
      0 1px 3px rgba(0, 0, 0, 0.30),
      0 6px 14px rgba(0, 0, 0, 0.35),
      3px 12px 28px rgba(0, 0, 0, 0.45);

    /* Popovers — deeper shadows against the darker tablecloth. */
    --shadow-popover:
      0 1px 3px rgba(0, 0, 0, 0.40),
      0 4px 10px rgba(0, 0, 0, 0.30),
      3px 8px 22px rgba(0, 0, 0, 0.45);
    --shadow-popover-lg:
      0 1px 3px rgba(0, 0, 0, 0.40),
      0 8px 24px rgba(0, 0, 0, 0.40),
      3px 14px 36px rgba(0, 0, 0, 0.50);

    /* Paper/press shadows need more opacity to read on the dark surface */
    --shadow-paper:
      0 1px 3px rgba(0, 0, 0, 0.22),
      0 4px 8px rgba(0, 0, 0, 0.18),
      3px 8px 14px rgba(0, 0, 0, 0.26);
    --shadow-press: inset 0 1px 2px rgba(0, 0, 0, 0.22);
  }
}

/* Page background colour — set on the root element so the browser paints it
   across the entire CSS canvas, including iOS Safari's overscroll regions and
   behind the status bar. Only the *colour* reaches those regions; no CSS can
   paint an image there, so the crosshatch texture lives on body::before. */
html {
  color-scheme: light dark;
  font-size: 18px;
  /* Keep focused or anchored elements clear of the sticky .navshell (top:0)
     when scrolled into view — WCAG 2.4.11 Focus Not Obscured. 3.5rem matches
     the nav offset used elsewhere for anchor targets. */
  scroll-padding-top: 3.5rem;
  touch-action: manipulation;
  scrollbar-gutter: stable;
  background-color: var(--ground-deep);
}

/* Crosshatch texture — a fixed-position pseudo-element, deliberately NOT
   `background-attachment: fixed` on html. iOS WebKit caches a fixed-attachment
   gradient as a composited GPU texture and, on a zoom/viewport-resize event
   (pinch, dynamic-toolbar show/hide, rotation), scales the stale texture
   instead of repainting it — the fine 3px crosshatch blows up into a blurry
   smear that clears only on the next repaint (WebKit #125118; #2117). A
   position: fixed layer recomputes the gradient to fill the viewport on every
   paint, so it stays crisp. z-index keeps it behind page content; html's
   background-color still covers the overscroll regions beneath it. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(135deg,
      rgba(179, 58, 58, 0.05) 0,
      rgba(179, 58, 58, 0.05) 1.5px,
      transparent 1.5px,
      transparent 3px),
    repeating-linear-gradient(45deg,
      rgba(179, 58, 58, 0.05) 0,
      rgba(179, 58, 58, 0.05) 1.5px,
      transparent 1.5px,
      transparent 3px);
}

/* Dark-mode overrides — the gradient colours are inlined (Track B owns those
   values); the base colour uses --ground. */
@media (prefers-color-scheme: dark) {
  html {
    background-color: var(--ground);
  }

  body::before {
    background-image:
      repeating-linear-gradient(135deg,
        rgba(200, 80, 80, 0.06) 0,
        rgba(200, 80, 80, 0.06) 1.5px,
        transparent 1.5px,
        transparent 3px),
      repeating-linear-gradient(45deg,
        rgba(200, 80, 80, 0.06) 0,
        rgba(200, 80, 80, 0.06) 1.5px,
        transparent 1.5px,
        transparent 3px);
  }
}



/* Turbo Drive progress bar — base styles defined here because Turbo's
   dynamic <style> injection is blocked by our strict CSP. The JS-driven
   width/opacity changes via CSSOM are not blocked. */
.turbo-progress-bar {
  position: fixed;
  display: block;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--text);
  z-index: var(--z-progress);
  transition: width 300ms ease-out, opacity 150ms 150ms ease-in;
  transform: translate3d(0, 0, 0);
}

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

body {
  padding: env(safe-area-inset-top, 0px) var(--gingham-gap) 0;
  font-family: var(--font-body);
  color: var(--text);
  line-height: var(--leading-relaxed);  /* was 1.65 — fold per fonts audit */
}


.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.wordmark { display: inline-block; line-height: 0; }
.wordmark__glyph {
  display: block;
  aspect-ratio: var(--wordmark-aspect);
  background-color: currentColor;
  -webkit-mask-image: url("/assets/wordmark-e4669a4f.svg"); mask-image: url("/assets/wordmark-e4669a4f.svg");
  -webkit-mask-repeat: no-repeat;          mask-repeat: no-repeat;
  -webkit-mask-position: center;           mask-position: center;
  -webkit-mask-size: contain;              mask-size: contain;
}

/* Skip link: the first focusable element in the body, letting keyboard users
   jump past the nav shell straight to <main> (WCAG 2.4.1 Bypass Blocks).
   Off-screen until focused, then slides in above the sticky nav. <main> carries
   tabindex="-1" so activating the link moves focus there, not just the scroll. */
.skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: var(--z-overlay);
  padding: 0.5rem 0.875rem;
  background: var(--ground);
  color: var(--text);
  border: 1.5px solid var(--rule);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transform: translateY(calc(-100% - 0.75rem));
  transition: transform 120ms ease-out;
}
.skip-link:focus {
  transform: translateY(0);
}

/* Grandfather policy banner — non-modal consent prompt rendered in the app shell
   (layouts/application) for users whose terms_accepted_at is still NULL. Sized to
   the content card: 41rem outer width (matches main), centered, full border so it
   reads as a sibling notice card, with a bottom gap equal to the navshell→banner
   gap (the navshell's gingham-gap padding). The button_to renders a <form>, so
   it's the second flex child. */
.policy-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  max-width: 41rem;
  margin: 0 auto var(--gingham-gap);
  padding: var(--space-3) var(--space-4);
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--rule);
}
.policy-banner p {
  margin: 0;
  flex: 1 1 20rem;
}

/* Read-only lapse banner — same app-shell placement/sizing contract as
   .policy-banner (41rem card, centered, gingham-gap bottom margin) but with a
   warning-toned left accent since a lapsed plan is a caution, not routine
   chrome. Static markup keyed off current_kitchen.read_only? — no client
   state, so it survives a broadcast layout morph unattended. */
.read-only-banner {
  max-width: 41rem;
  margin: 0 auto var(--gingham-gap);
  padding: var(--space-3) var(--space-4);
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--warning);
}
.read-only-banner p {
  margin: 0;
}

/* Custom checkbox — shared base for menu and grocery pages */
.custom-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 1rem;
  height: 1rem;
  border: 1.5px solid var(--rule);
  border-radius: var(--radius-xs);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
}

.custom-checkbox:checked {
  background-color: var(--red);
  border-color: var(--red);
}

.custom-checkbox:checked::after {
  content: '\2713';
  color: white;
  font-size: 0.75rem;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Buttons — the one shared interactive style across the site */
.btn {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-body);
  font-size: 0.85rem;
  background: var(--ground);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.75rem;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  line-height: var(--leading-relaxed);
  transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease, color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

@media (hover: hover) {
  .btn:hover {
    color: var(--text);
    border-color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }
}

/* Shared focus ring — one source of truth for .btn, .btn-ghost, .btn-link,
   and bare <button>. .btn-link is listed explicitly: its `all: unset` strips
   the outline, and it rides on <a> too, so neither button:focus-visible nor
   main a:focus-visible can be relied on to reach every call site. */
.btn:focus-visible,
.btn-ghost:focus-visible,
.btn-link:focus-visible,
button:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

.btn-primary {
  background: var(--red);
  color: white;
  border-color: var(--red);
}

@media (hover: hover) {
  .btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
  }
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}

@media (hover: hover) {
  .btn-danger:hover {
    background: var(--danger-hover-bg);
    color: var(--danger);
    border-color: var(--danger);
  }
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
}

.btn-link {
  all: unset;
  cursor: pointer;
  color: var(--red);
  text-decoration: underline dotted;
  font-family: var(--font-body);
}

@media (hover: hover) {
  .btn-link:hover {
    text-decoration-style: solid;
  }
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  padding: 0.3rem 0.6rem;
  border: none;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-light);
  cursor: pointer;
  text-decoration: none;
  transition: color var(--duration-fast) ease, background var(--duration-fast) ease;
}

@media (hover: hover) {
  .btn-ghost:hover {
    color: var(--red);
    background: var(--hover-bg);
  }
}

.btn-icon-round {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 1rem;
  line-height: var(--leading-flat);
  transition: color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

@media (hover: hover) {
  .btn-icon-round:hover {
    color: var(--text-soft);
    border-color: var(--rule);
  }
}

.btn-icon-round:disabled {
  opacity: 0.3;
  cursor: default;
}

@media (hover: hover) {
  .btn-icon-round.btn-danger:hover {
    color: var(--danger);
    border-color: var(--danger);
  }
}

@media (hover: hover) {
  .btn-icon-round.btn-primary:hover {
    color: var(--red);
    border-color: var(--red);
  }
}

.btn-icon-round-lg {
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
}

.btn-pill {
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 0.85rem;
  font-family: var(--font-body);
  color: var(--text);
  cursor: pointer;
  transition: background var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

@media (hover: hover) {
  .btn-pill:hover {
    background: var(--hover-bg);
    border-color: var(--red);
  }
}

.btn-pill.active,
.btn-pill[data-active] {
  background: var(--red);
  color: white;
  border-color: var(--red);
}

/* ── Input base ────────────────────────────────────────────── */

.input-base {
  font-family: var(--font-body);
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--rule-faint);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  box-sizing: border-box;
  outline: none;
}

.input-base:focus {
  outline: var(--focus-ring);
  outline-offset: -1px;
  border-color: var(--red);
}

.input-base::placeholder {
  color: var(--text-light);
}

.input-lg {
  font-size: 1rem;
  padding: 0.5rem 0.75rem;
}

.input-sm {
  width: 4.5rem;
  text-align: right;
}

.input-inline {
  padding: 0.25rem 0.4rem;
  font-size: 0.85rem;
}

.form-helper {
  color: var(--text-light);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* iOS/iPadOS Safari auto-zooms — and never zooms back out — when a focused
   text control computes below 16px. Floor text-entry controls at 16px on touch
   devices so focus never triggers a zoom; desktop keeps the compact type scale.
   Scoped by pointer (not a width breakpoint) so it also covers landscape phones
   and iPad, which the old max-width patch missed. :not(.input-lg) keeps the
   deliberately larger onboarding inputs (login, invite code) at their size, and
   its 0-2-0 specificity lets the floor win regardless of source order. The
   bare-element rule nets unclassed controls (e.g. category <select>). */
@media (pointer: coarse) {
  input,
  select,
  textarea,
  .input-base:not(.input-lg),
  .input-inline:not(.input-lg) {
    font-size: 16px;
  }
}

/* ── Collapse ──────────────────────────────────────────────── */

.collapse-header {
  margin: 0;
  padding: 0;
  list-style: none;
}

.collapse-header summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  list-style: none;
  user-select: none;
}

.collapse-header summary::before {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0.3rem 0 0.3rem 0.45rem;
  border-color: transparent transparent transparent var(--text-light);
  transition: transform var(--duration-fast) ease;
  flex-shrink: 0;
}

.collapse-header[open] summary::before {
  transform: rotate(90deg);
}

.collapse-header summary::-webkit-details-marker {
  display: none;
}

.collapse-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--duration-normal) ease;
}

.collapse-header[open] + .collapse-body,
.collapse-header[open] ~ .collapse-body {
  grid-template-rows: 1fr;
}

.collapse-inner {
  min-height: 0;
  overflow: hidden;
}

/* Disclosure controllers (grocery aisles, pantry Well-stocked band) toggle this
   to suppress the .collapse-body grid-rows transition while restoring a saved
   open state on load/morph — otherwise the band animates on every paint. */
.no-transition { transition: none !important; }
main a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--rule-faint);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--duration-normal) ease, text-decoration-color var(--duration-normal) ease;
}

@media (hover: hover) {
  main a:hover {
    color: var(--red);
    text-decoration-color: var(--red);
  }
}

main a:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--radius-xs);
}

main {
  position: relative;
  /* Under the universal border-box reset, max-width is the outer extent. 41rem
     keeps main's visible card edges where the nav strip is calibrated to them
     (navshell.css .navshell__top); content area is ~35rem after 3rem padding. */
  max-width: 41rem;
  margin: 0 auto var(--gingham-gap);
  padding: 3rem 3rem 5rem;
  background: var(--content-card-bg);
  border: 1px solid var(--rule-faint);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.07),
    0 4px 8px rgba(0, 0, 0, 0.05),
    3px 8px 14px rgba(0, 0, 0, 0.08);
  min-height: calc(100vh - 2 * var(--gingham-gap) - 3rem);
}

main::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("/assets/paper-noise-4ecbafa7.svg");
  background-size: var(--noise-tile) var(--noise-tile);
  opacity: var(--paper-opacity);
  pointer-events: none;
}

/* Lifts content children above main's ::before paper-noise overlay. <dialog>
   is excluded so the UA-default `:modal { position: fixed }` keeps applying —
   otherwise the modal's layout box stays anchored inside <main> (top-layer
   only relocates the paint), and scroll-into-view-on-focus scrolls the page
   to wherever that layout box sits. */
main > *:not(dialog) {
  position: relative;
}

/* Page-title chrome: recipe / recipe-listing document headers, plus any page opting in
   via .page-header. Scoped per #1876 — bare `header` leaked this app-wide. */
:where(.recipe, .recipe-listing) > header,
.page-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

:where(.recipe, .recipe-listing) > header h1,
.page-header h1 {
  font-family: var(--font-display);
  font-size: 3.8rem;
  font-weight: 400;
  line-height: 1.05; /* named exception: display heading at 3.8rem needs tight leading */
  letter-spacing: -0.01em;
  margin: 0 0 0.5rem 0;
}

:where(.recipe, .recipe-listing) > header p,
.page-header p {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.3rem;
  margin-top: 0;
  color: var(--text-soft);
}

:where(.recipe) > header .recipe-meta {
  font-style: normal;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 1rem;
  color: var(--text-light);
  text-align: center;
}

:where(.recipe) > header .recipe-yield {
  font-family: var(--font-body);
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-light);
  text-align: center;
  margin-top: 0.25rem;
}

:where(.recipe) > header .recipe-meta a {
  color: inherit;
  text-decoration: none;
}

@media (hover: hover) {
  :where(.recipe) > header .recipe-meta a:hover {
    text-decoration: underline;
  }
}

.recipe-tags {
  margin-top: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
}

.recipe-tag-pill {
  border: none;
  cursor: pointer;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
}

@media (hover: hover) {
  .recipe-tag-pill:hover { opacity: 0.8; }
}

/* Scale bar — centered disclosure toggle + vertical reveal */
.scale-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 0.6rem;
}

.scale-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-light);
  text-decoration: none;
  /* <button> (disclosure, #1545) reset — keep the plain-link appearance */
  background: none;
  border: 0;
  font-family: inherit;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-md);
  user-select: none;
  transition: color var(--duration-normal) ease, background-color var(--duration-slow) ease-out;
}

@media (hover: hover) {
  .scale-toggle:hover {
    color: var(--red);
    background-color: var(--hover-bg);
  }
}

.scale-toggle::before {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0.3rem 0 0.3rem 0.45rem;
  border-color: transparent transparent transparent currentColor;
  transition: transform var(--duration-fast) ease;
}

.scale-bar.open .scale-toggle::before {
  transform: rotate(90deg);
}

/* Recipe actions row — variable-count button group with middot dividers.
   Flex wraps gracefully for 1 button (just Edit) up to 5 (Share · Edit · Scale on
   the recipe page). Center-justified so it reads as a balanced toolbar regardless
   of count. */
.recipe-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
}

:where(.recipe, .recipe-listing) > header > .recipe-actions,
.page-header > .recipe-actions {
  margin-top: 0.6rem;
}

.recipe-actions-dot {
  color: var(--text-light);
  font-size: 0.85rem;
  line-height: var(--leading-flat);
}


/* Scale controls — animated vertical expand/collapse */
.scale-controls {
  display: grid;
  grid-template-rows: 0fr;
  overflow: hidden;
  transition: grid-template-rows var(--duration-normal) ease;
}

.scale-bar.open .scale-controls {
  grid-template-rows: 1fr;
}

.scale-controls-inner {
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.scale-controls-center {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  min-height: 0;
  padding: 0.5rem 0.25rem;
}

.scale-controls-center > :first-child {
  justify-self: end;
}

.scale-controls-center > :last-child {
  justify-self: start;
}

.scale-input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.scale-presets {
  display: flex;
  gap: 0.25rem;
}

.scale-preset {
  line-height: var(--leading-flat);
}

@keyframes pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.scale-preset.active {
  background: var(--red);
  border-color: var(--red);
  color: white;
  animation: pulse var(--duration-bloop) var(--ease-bounce);
}

.scale-divider {
  width: 1px;
  height: 1.25rem;
  background: var(--rule);
}

.scale-input {
  text-align: center;
}

.scale-input.invalid,
.scale-input.invalid:focus {
  outline: 2px solid var(--danger);
  outline-offset: -1px;
  border-color: var(--danger);
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, var(--input-bg));
}

/* Reserve the Reset button's slot in the flex row so revealing it never shifts
   the input. It must stay in layout when inert, so it can't use the `hidden`
   attribute (that means display:none) — scale_panel_controller toggles this
   class. visibility:hidden also takes it out of tab order + the a11y tree. */
.scale-reset.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.scalable.scaled {
  background-color: var(--scaled-highlight);
  border-radius: var(--radius-xs);
  padding: 0 1px;
}

.recipe-meta .scalable.scaled,
.recipe-yield .scalable.scaled {
  background-color: transparent;
}

:where(.recipe, .recipe-listing) > header::after,
.page-header::after {
  content: "";
  display: block;
  width: 40px;
  height: 1px;
  background: var(--red);
  margin: 1.5rem auto 0;
}

/* The history frame wraps the recipe body inline (#2076); it must contribute no
   box so the body lays out exactly as before. Selector matching still sees the
   frame in the DOM, so the body-level child combinators below are relaxed too. */
#recipe-history { display: contents; }

/* Document section rhythm — scoped per #1876; non-document pages own their spacing. */
:where(.recipe, .embedded-recipe, .recipe-listing) section {
  margin-top: 2.5rem;
  break-inside: avoid;
}

:where(.recipe, .embedded-recipe, .recipe-listing) section > ul {
  column-count: 2;
  column-gap: 2.5rem;
  list-style: none;
  padding-left: 0;
}

:where(.recipe, .embedded-recipe, .recipe-listing) section > ul li {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

:where(.recipe, .embedded-recipe, .recipe-listing) section > ul li a {
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 400;
  transition: color var(--duration-normal);
}

:where(.recipe, .embedded-recipe, .recipe-listing) section > ul li a:hover {
  color: var(--red);
}

:where(.recipe, .embedded-recipe, .recipe-listing) section h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 400;
  line-height: var(--leading-snug);
  text-transform: none;
  letter-spacing: normal;
  margin-top: 3.5rem;
  margin-bottom: 1.25rem;
  border-bottom: none;
  padding-bottom: 0;
}

:where(.recipe, .embedded-recipe, .recipe-listing) section:first-of-type h2 {
  margin-top: 0;
}

.recipe-listing section h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  margin: 3rem 0 0;
  padding-bottom: 0;
  border-bottom: none;
}

/* Recipes index: unified navigation (categories + tag filters) */
.index-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.index-nav-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.index-nav-categories {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.index-nav-tags {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* Inline edit affordance — small ghost-text "edit X" zone button (recipe
   index nav, quick-bites). Hover guarded so touch devices don't stick. */
.btn-inline-edit {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 0.7rem;
  font-family: var(--font-body);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius-sm);
}

@media (hover: hover) {
  .btn-inline-edit:hover {
    color: var(--red);
    background: var(--hover-bg);
  }
}

.index-nav-link a {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0.2rem 0.5rem;
  border-radius: 0.3rem;
  transition: color var(--duration-normal) ease,
              background-color var(--duration-slow) ease-out;
}

.index-nav-link a:hover {
  color: var(--red);
  background-color: var(--hover-bg);
}

.index-nav-link:not(:last-child)::after {
  content: " \00b7";
  color: var(--text-light);
}

.index-nav-divider {
  height: 1px;
  background: var(--rule-faint);
}

/* Recipes index: category heading with back-to-top */
.category-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4rem;
}

.category-heading h2 {
  margin: 0;
}

.category-top-link {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-light);
  text-decoration: none;
  padding-bottom: 0.25rem;
  white-space: nowrap;
}

.category-top-link:hover {
  color: var(--red);
}

.category-permalink-wrap {
  font-size: 0.85em;
  font-weight: normal;
  color: var(--text-light);
}

@media (hover: hover) {
  .category-permalink-wrap {
    opacity: 0;
    transition: opacity 0.15s ease;
  }

  .category-heading:hover .category-permalink-wrap,
  .category-heading:focus-within .category-permalink-wrap {
    opacity: 1;
  }
}

.category-permalink {
  color: var(--text-light);
  text-decoration: none;
}

.category-permalink:hover {
  color: var(--red);
  text-decoration: underline;
}

/* Recipes index: recipe card grid.
 * A real <ul> for list semantics (sem-4). The list reset + `column-count`
 * override neutralize the `section > ul` index-column rules, which would
 * otherwise multi-column this grid since it's a direct child of <section>. */
.recipe-card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
  column-count: initial;
}

@media (max-width: 599px) {
  .recipe-card-grid {
    grid-template-columns: 1fr;
  }

  .index-nav {
    gap: 0.3rem;
  }
}

/* Recipes index: recipe cards — elevated paper card (#1385), typography-first
 * interior with a footer rail (#2697). Each card is an <li> (sem-4).
 * `white-space`/`text-overflow` reset the single-line ellipsis the
 * `section > ul li` index rule would otherwise impose. */
.recipe-card {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  min-height: 2.75rem;
  background: var(--content-card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-paper);
  color: var(--text);
  text-decoration: none;
  white-space: normal;
  text-overflow: clip;
  transition: background var(--duration-normal),
              box-shadow var(--duration-normal),
              transform var(--duration-fast) var(--ease-bloop);
}

/* Top-align so the title sits in a consistent slot regardless of whether the
 * optional description/meta render. Cards stretch to the tallest in their grid
 * row; centering floated the title of a description-less card down out of line
 * with its neighbours (#2415). */
.recipe-card__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: var(--space-2);
  padding: var(--space-4);
}

/* Heading wrapper (headings-1): semantics only. All visual styling stays on
 * the inner .recipe-card__title link, so the rendered title is unchanged.
 * Reset the UA heading margins/weight/size the <h3> would otherwise add. */
.recipe-card__heading {
  margin: 0;
  font-weight: inherit;
  font-size: inherit;
}

.recipe-card__title {
  font-family: var(--font-display);
  font-style: italic;        /* the italic is the voice */
  font-weight: 400;
  font-size: var(--type-xl);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
  color: var(--text);
  text-decoration: none;
}

/* Stretched link: the whole card is the title link's hit area */
.recipe-card__title::after {
  content: "";
  position: absolute;
  inset: 0;
}

/* Single focus indicator: ring the card boundary, and suppress the link's
 * own outline (main a:focus-visible) so we don't draw two concentric rings. */
.recipe-card .recipe-card__title:focus-visible {
  outline: none;
}

.recipe-card:has(.recipe-card__title:focus-visible) {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

/* Two rendered lines, width-responsive; the full text stays in the DOM, so
 * screen readers still get it all (#2697). */
.recipe-card__desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--type-sm);
  line-height: var(--leading-snug);
  color: var(--text-soft);
}

/* Footer rail (#2697): hairline-anchored bottom line — time left, add-to-menu
 * action right. margin-top:auto pins it to the grid-stretched bottom edge so
 * cards in a row share a baseline. Rendered only when it has content. */
.recipe-card__rail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-2);
  border-top: 1px solid var(--rule-faint);
  font-family: var(--font-body);
  font-size: var(--type-sm);
  color: var(--text-soft);
}

.recipe-card__time {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.recipe-card__time svg {
  flex-shrink: 0;
}

/* Pressed state — pure CSS; fires via the title link on pointer/touch/keyboard.
 * Navigation activates on release (native anchor); this is press-in feedback. */
.recipe-card:has(.recipe-card__title:active) {
  transform: translateY(1px);
  box-shadow: var(--shadow-press);
}

/* Recipes-index add-to-menu toggle (#2048; #2697 dropped the bordered chip) —
   a quiet text action in the card's footer rail: soft ink, no chrome. State is
   never hue-only: .is-on swaps the glyph AND the visible words, plus the
   --positive color. The z-index lifts the button above the recipe card's
   stretched title link (.recipe-card__title::after, inset:0) so a tap lands on
   the toggle, not the link. Padding builds the 44px hit target; inside the rail
   a negative margin keeps the row visually slim — QuickBite rows apply the
   same trick in .menu-qb-row__rail. */
.menu-toggle {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-soft);
  font-family: var(--font-body);
  font-size: var(--type-sm);
  cursor: pointer;
  padding: 0.75rem 0.5rem;
  transition: color var(--duration-fast) ease;
}
.menu-toggle:hover {
  color: var(--text);
}
.recipe-card__rail > .menu-toggle {
  margin: -0.75rem -0.5rem;
  margin-left: auto;   /* right-aligns a toggle-only rail; harmless beside time */
}
.menu-toggle__off { display: inline-flex; align-items: center; gap: 0.3rem; }
.menu-toggle__on  { display: none; align-items: center; gap: 0.3rem; }
.menu-toggle.is-on .menu-toggle__off { display: none; }
.menu-toggle.is-on .menu-toggle__on  { display: inline-flex; }
.menu-toggle.is-on {
  color: var(--positive);
}

/* --positive (#4a7a4a) reads ~3.2:1 on the dark card — under WCAG 1.4.3 for a
   text-only control. Brightened locally; other --positive consumers carry
   fills/borders and are out of scope (#2697). */
@media (prefers-color-scheme: dark) {
  .menu-toggle.is-on {
    color: #7aa87a;
  }
}

/* QuickBite zone (#2698): flat hairline tiles in a mini-grid — deliberately
   quieter than the shadowed recipe cards above them. The rail pins to the tile
   bottom (margin-top: auto) so a row of stretched tiles shares a baseline,
   mirroring .recipe-card__rail. */
.menu-qb-zone {
  border-left: 2px solid var(--rule-faint);
  padding-left: var(--space-3);
  margin-top: var(--space-3);
}
.menu-qb-zone__label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
  margin-bottom: var(--space-2);
}
.menu-qb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr));
  gap: var(--space-2);
  align-items: stretch;
}
.menu-qb-row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--rule-faint);
  border-radius: var(--radius-md);
  background: var(--content-card-bg);
}
.menu-qb-row__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
}
.menu-qb-row__title {
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--text);
}
.menu-qb-row__edit {
  border: none;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  border-radius: var(--radius-md);
  padding: 0.75rem 0.5rem;
  margin: -0.75rem -0.5rem;
  flex-shrink: 0;
  transition: color var(--duration-fast) ease;
}
.menu-qb-row__edit:hover {
  color: var(--text);
}
.menu-qb-row__ings {
  font-size: var(--type-sm);
  color: var(--text-soft);
}
.menu-qb-row__rail {
  display: flex;
  justify-content: flex-end;
  margin-top: auto;
  padding-top: 0.45rem;
}
.menu-qb-row__rail > .menu-toggle {
  margin: -0.75rem -0.5rem;
  margin-left: auto;
}
.menu-qb-new-item {
  display: flex;
}
.menu-qb-new {
  flex: 1;
  min-height: 4.25rem;
  border: 1px dashed var(--rule);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-soft);
  font-family: var(--font-body);
  font-size: var(--type-sm);
  cursor: pointer;
  transition: color var(--duration-fast) ease;
}
.menu-qb-new:hover {
  color: var(--text);
}

/* Tag filter (recipe-filter controller): show only matches, hide emptied
 * categories. These two rules were referenced by the controller but never
 * existed in CSS — filtering used to only highlight matches. */
.recipe-card.filtered-out {
  display: none;
}

.filtered-empty {
  display: none;
}

.recipe-tag {
  display: inline-block;
  padding: 0.06rem 0.44rem;
  border-radius: 0.625rem;
  font-size: 0.68rem;
  color: var(--text-light);
}

.recipe-listing section:first-of-type h2 {
  margin-top: 0;
}

#export-actions {
  margin-top: 1.5rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--rule);
  text-align: center;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
}

.loading-placeholder {
  color: var(--text-soft);
  font-style: italic;
  padding: 2rem;
  text-align: center;
}

:where(.recipe, .embedded-recipe) section > div:has(.ingredients):has(.instructions) {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 0 2.5rem;
}

/* Recipe ingredient/instruction typography — scoped per #1876 (final family). */
:where(.recipe, .embedded-recipe) .instructions p {
  margin: 0 0 0.85rem 0;
  font-size: 0.95rem;
  line-height: 1.75; /* named exception: long-form recipe instructions, generous leading */
}

:where(.recipe, .embedded-recipe) .instructions {
  border-left: 1px solid var(--rule-faint);
  padding-left: 2rem;
}

:where(.recipe, .embedded-recipe) .ingredients ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

:where(.recipe, .embedded-recipe) .ingredients li {
  break-inside: avoid;
  padding: 0.3rem 0;
  font-size: 0.84rem;
  line-height: var(--leading-body);
}

.quantity {
  color: var(--text-light);
  font-weight: 300;
  white-space: nowrap;
}

/* .ingredients ul li small::before 	{ content: "↳ "; } */

:where(.recipe, .embedded-recipe) .ingredients ul li small {
  display: block;
  font-style: italic;
  font-size: 0.95em;
  line-height: var(--leading-snug);  /* was 1.3 — fold per fonts audit */
  padding-left: 1rem;
}

/* Document footer chrome — scoped per #1876 to the document footer only: a direct
   child of the recipe article, or of the inline history frame / its diff wrapper
   (#2076, which interposes a box). Nested component footers (.nutrition-label's)
   stay exempt by the child combinator. */
:where(.recipe, .embedded-recipe) > footer,
:where(#recipe-history, #recipe-history > .recipe--history) > footer {
  font-family: var(--font-display);
  font-style: italic;
  text-align: center;
  font-size: 1rem;
  margin-top: 3.5rem;
  padding-top: 2rem;
  color: var(--text-light);
  position: relative;
}

:where(.recipe, .embedded-recipe) > footer::after,
:where(#recipe-history, #recipe-history > .recipe--history) > footer::after {
  content: "";
  display: block;
  width: 40px;
  height: 1px;
  background: var(--rule);
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}

:where(.recipe, .embedded-recipe) > footer small,
:where(#recipe-history, #recipe-history > .recipe--history) > footer small {
  text-align: right;
  display: block;
}

@media (prefers-color-scheme: dark) {
  .smart-icon--crossout::after {
    border-color: rgba(220, 80, 80, 0.85);
    background: linear-gradient(
      to top left,
      transparent calc(50% - 1px),
      rgba(220, 80, 80, 0.85) calc(50% - 1px),
      rgba(220, 80, 80, 0.85) calc(50% + 1px),
      transparent calc(50% + 1px)
    );
  }
}
/******************************************************/
/* Styles for interactivity, applies to screen media */
/*****************************************************/

@media screen {
  /* switch to hand pointer for interactive elements */
  .recipe section h2,
  .recipe .instructions p,
  .recipe .ingredients li {
    cursor: pointer;
  }

  /* Strike a recipe step's h2 once all its crossable items are crossed off.
     The :has(...crossed-off) guard is load-bearing: without it, :not(:has(...))
     is vacuously true for a section with no crossable items, striking an empty
     section's heading (e.g. Photos) by accident (#2080). .recipe-scoped so
     other pages' <section> + <h2> are unaffected. */
  .crossed-off,
  .recipe section:has(.ingredients li.crossed-off, .instructions p.crossed-off):not(:has(.ingredients li:not(.crossed-off), .instructions p:not(.crossed-off))) h2 {
    text-decoration: line-through;
    color: var(--text-light);
    border-color: var(--text-light);
  }

  /* Fade the embedded card when the parent step is crossed off — same vacuous-truth
     guard as above so an item-less section never dims its embedded card. */
  :where(.recipe) section:has(.ingredients li.crossed-off, .instructions p.crossed-off):not(:has(.ingredients li:not(.crossed-off), .instructions p:not(.crossed-off))) .embedded-recipe {
    opacity: 0.4;
  }
}

/* Authored focus ring for the JS-focusable recipe cross-off controls (#1552):
   cross-off items (focus-3) and the section-heading togglers keyboard-enabled
   in #1551. Outside the hover query above — keyboard focus needs an indicator
   regardless of pointer type. Matches the app's 2px red :focus-visible ring. */
.recipe .ingredients li:focus-visible,
.recipe .instructions p:focus-visible,
.recipe section :is(h2, h3):focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

/****************************************/
/* Styles for mobiles and small screens */
/****************************************/

/* small mobiles only */
@media screen and (max-width: 720px) and (pointer: coarse) {
  html {
    font-size: 16px;
  }
}

/* anything with a narrow window */
@media screen and (max-width: 720px) {
  :root {
    --gingham-gap: 0.75rem;
  }

  main {
    padding: 1.5rem 1.25rem 3rem;
  }

  :where(.recipe, .embedded-recipe) section > div:has(.ingredients):has(.instructions) {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  /* On small screens, switch to two ingredient columns */
  :where(.recipe, .embedded-recipe) .ingredients ul {
    column-count: 2;
    column-gap: 0.5rem;
  }

  /* Switch to two index columns as well */
  :where(.recipe, .embedded-recipe, .recipe-listing) section > ul {
    column-count: 2;
  }

  :where(.recipe, .recipe-listing) > header h1,
  .page-header h1 { font-size: 2.6rem; }


  :where(.recipe, .embedded-recipe) .instructions {
    border-left: none;
    padding-left: 0;
    padding-top: 0.5rem;
    border-top: 1px solid var(--rule-faint);
  }

}

/* Touch viewport: top nav fixed, destinations bar pinned to bottom */
@media (pointer: coarse) and (hover: none) {
  main {
    padding-top: 2rem;
  }

  #recipe-listings,
  [data-recipe-filter-target="category"] {
    scroll-margin-top: 0.5rem;
  }

  body {
    padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
  }
}

html:has(dialog[open]) {
  overflow: hidden;
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes bloop {
  0%   { transform: scale(0.95);  opacity: 0; }
  40%  { transform: scale(1.02);  opacity: 1; }
  70%  { transform: scale(0.992); opacity: 1; }
  100% { transform: scale(1);     opacity: 1; }
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: default;
}
.tag-pill--tag { background: var(--tag-bg); color: var(--tag-text); }
.tag-pill--category { background: var(--cat-bg); color: var(--cat-text); }

/* Smart tag color variants. The --c-bg/--c-text custom props let filter chips
   derive resting/selected states from a tag's category color (#2179); display
   pills keep using background/color directly. */
.tag-pill--green   { background: var(--smart-green-bg);   color: var(--smart-green-text);   --c-bg: var(--smart-green-bg);   --c-text: var(--smart-green-text); }
.tag-pill--amber   { background: var(--smart-amber-bg);   color: var(--smart-amber-text);   --c-bg: var(--smart-amber-bg);   --c-text: var(--smart-amber-text); }
.tag-pill--blue    { background: var(--smart-blue-bg);     color: var(--smart-blue-text);    --c-bg: var(--smart-blue-bg);     --c-text: var(--smart-blue-text); }
.tag-pill--rose    { background: var(--smart-rose-bg);     color: var(--smart-rose-text);    --c-bg: var(--smart-rose-bg);     --c-text: var(--smart-rose-text); }
.tag-pill--purple  { background: var(--smart-purple-bg);   color: var(--smart-purple-text);  --c-bg: var(--smart-purple-bg);   --c-text: var(--smart-purple-text); }
.tag-pill--cuisine { background: var(--smart-cuisine-bg);  color: var(--smart-cuisine-text); --c-bg: var(--smart-cuisine-bg);  --c-text: var(--smart-cuisine-text); }

/* Smart tag icon wrapper */
.smart-icon {
  position: relative;
  margin-right: 0.3em;
  font-size: 0.85em;
  display: inline-flex;
  align-items: center;
}

/* Crossout circle+slash overlay on the icon */
.smart-icon--crossout::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1.5px solid rgba(180, 40, 40, 0.85);
  border-radius: 50%;
  background: linear-gradient(
    to top left,
    transparent calc(50% - 1px),
    rgba(180, 40, 40, 0.85) calc(50% - 1px),
    rgba(180, 40, 40, 0.85) calc(50% + 1px),
    transparent calc(50% + 1px)
  );
  pointer-events: none;
}

/* Recipe-index tag FILTER chips (#2179, semantics reworked by #2695). Pills
   are actions, not status lamps: resting chips recede (category tint, faded
   label, sepia-muted emoji); selecting lights the chip to full category color
   with a dark ring + bold and narrows the list to recipes carrying every
   selected tag. While filtering, unselected chips carry a live count and go
   inert at zero (dead-end prevention); the summary line below the row owns
   the global state. Category color comes from the --c-bg/--c-text props the
   .tag-pill--<color> classes publish; plain (non-registry) tags fall back to
   neutral resting and the red accent when active. The on/off signal is shape +
   luminance (ring + weight), never hue — paired with aria-pressed for
   CVD/screen-reader users. */
.tag-filter-pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: var(--radius-xl);
  font-size: 0.78rem;
  font-family: var(--font-body);
  background: color-mix(in srgb, var(--c-bg, var(--tag-bg)) 42%, var(--tag-bg));
  color: color-mix(in srgb, var(--tag-text) 85%, transparent);
  border: 2px solid transparent;
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast);
}

.tag-filter-pill:not(.active) .smart-icon {
  filter: sepia(0.6) saturate(0.85) brightness(0.95);
  opacity: 0.55;
}

.tag-filter-pill:not([aria-disabled="true"]):hover {
  background: color-mix(in srgb, var(--c-bg, var(--tag-bg)) 65%, var(--tag-bg));
  border-color: color-mix(in srgb, var(--c-text, var(--tag-text)) 35%, transparent);
}

.tag-filter-pill.active {
  background: var(--c-bg, var(--tag-filter-active-bg));
  color: var(--c-text, var(--red));
  border-color: var(--c-text, var(--red));
  font-weight: 600;
}

.tag-filter-pill.active .smart-icon {
  filter: none;
  opacity: 1;
}

.tag-filter-pill[aria-disabled="true"] {
  opacity: 0.35;
  cursor: default;
}

.tag-filter-pill__count {
  margin-left: 0.2rem;
  font-size: 0.65rem;
  opacity: 0.65;
}

.tag-filter-summary {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--text-light);
}

.tag-filter-summary__clear {
  margin-left: 0.4rem;
  padding: 0;
  border: none;
  background: none;
  color: var(--red);
  font-size: inherit;
  font-family: var(--font-body);
  text-decoration: underline;
  cursor: pointer;
}

.tag-pill__remove {
  position: relative;
  font-size: 0.6rem;
  opacity: 0.5;
  cursor: pointer;
  line-height: var(--leading-flat);
  border: none;
  background: none;
  color: inherit;
  padding: 0;
}
/* WCAG 2.5.8: the visible × stays ~10px to keep the pill dense; a transparent
   overlay extends only the clickable area to the 24×24 minimum without
   enlarging the glyph or disturbing the inline-flex pill layout. */
.tag-pill__remove::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  transform: translate(-50%, -50%);
}
.tag-pill__remove:hover { opacity: 1; }
/************************/
/* Notification toast   */
/************************/

.notify-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: var(--ground);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--rule);
  box-shadow: var(--shadow-nav-up);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  transform: translateY(100%);
  opacity: 0;
  transition: transform var(--duration-slow) ease, opacity var(--duration-slow) ease;
}

@keyframes slide-in {
  0%   { transform: translateY(100%); opacity: 0; }
  60%  { transform: translateY(-8%);  opacity: 1; }
  100% { transform: translateY(0);    opacity: 1; }
}

.notify-bar.notify-visible {
  transform: translateY(0);
  opacity: 1;
  animation: slide-in var(--duration-slow) var(--ease-bounce);
}

.notify-dismiss {
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--rule);
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  line-height: var(--leading-flat);
  flex-shrink: 0;
}

.notify-dismiss:hover {
  color: var(--text-soft);
}
.app-version {
  text-align: center;
  margin: -0.75rem auto 0;
  padding: 0 0 0.25rem;
  max-width: 35rem;
  font-size: 0.7rem;
  font-style: normal;
  /* #1876 transfer: the display family came from base's bare `footer` rule (now document-scoped). */
  font-family: var(--font-display);
  /* Faint via --text-soft, NOT opacity: a parent opacity composites the whole
     footer subtree (incl. the made-by credit links) below WCAG AA regardless of
     each child's own color (#2171 ship a11y gate). */
  color: var(--text-soft);
}

/* The footer sits outside <main>, so `main a` never colors these links and the
   UA `a:link` rule would render them bright blue. Inherit the footer's
   --text-soft instead (the opacity:0.3 that used to mute the UA blue is gone). */
.app-version a {
  color: inherit;
}

/* Author + build-tool credit. Self-contained: sets its own font/size/color
   rather than inheriting from a parent footer. Rendered only via
   `content_for :footer_credit`, which only the app layout's footer yields. */
.made-by {
  margin: 0.35rem 0 0;
  text-align: center;
  font-family: var(--font-display);
  font-size: 0.7rem;
  color: var(--text-soft);
}

.made-by a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (hover: hover) {
  .made-by a:hover {
    color: var(--text);
  }
}

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

  .recipe-card:has(.recipe-card__title:active) {
    transform: none; /* keep the --shadow-press feedback, drop the positional shift */
  }
}
