/* Ken’s Online Recipes
 * A warm, editorial personal cookbook: paper-toned pages, quiet raised surfaces,
 * a serif for titles and headings, a clean sans for everything you operate. */

/* ================================================================
 * Fonts (self-hosted, SIL Open Font License — see fonts/README.md)
 * ================================================================ */

@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces-italic.woff2") format("woff2");
  font-weight: 300 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("fonts/DMSans.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("fonts/DMSans-italic.woff2") format("woff2");
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}

/* ================================================================
 * Design tokens
 * <html> carries data-palette (herb | blueberry | paprika | plum) and
 * data-scheme (light | dark), set before first paint in index.html.
 * Palettes only change the accent; everything else is shared.
 * ================================================================ */

:root {
  /* surfaces — warm ivory paper */
  --page: #f6f2ea;
  --surface: #fffdf8;
  --surface-raised: #ffffff;
  --surface-sunken: #f0eadf;
  /* text */
  --text: #211d18;
  --text-muted: #6b6257;
  --text-faint: #8f8679;
  /* lines */
  --border: #e7dfd2;
  --border-strong: #d4c8b6;
  /* accent — Herb Garden */
  --accent: #2f5d46;
  --accent-text: #2b5641;
  --accent-soft: #e3ece4;
  --on-accent: #ffffff;
  /* states */
  --danger: #a8321f;
  --danger-soft: #f8e5e0;
  --focus: #2f6fdb;
  --heart: #c9344f;
  --ok: #2f7a4b;
  /* dish thumbnails (tinted with each cuisine's hue) */
  --thumb-s: 36%;
  --thumb-l: 92%;
  --thumb-ink-s: 30%;
  --thumb-ink-l: 33%;
  /* cuisine dots */
  --dot-s: 45%;
  --dot-l: 47%;

  /* depth */
  --shadow-1: 0 1px 2px rgb(62 44 24 / 0.06), 0 1px 3px rgb(62 44 24 / 0.05);
  --shadow-2: 0 2px 4px rgb(62 44 24 / 0.05), 0 12px 28px rgb(62 44 24 / 0.10);
  --shadow-pop: 0 18px 50px rgb(40 28 14 / 0.20), 0 2px 6px rgb(40 28 14 / 0.08);

  /* shape */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;

  /* type */
  --font-serif: "Fraunces", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-sans: "DM Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --fs-wordmark: 1.4rem;
  --fs-intro: clamp(1.9rem, 1.4rem + 1.8vw, 2.6rem);
  --fs-card-title: 1.3rem;
  --fs-detail-title: clamp(2.1rem, 1.4rem + 3vw, 3.3rem);
  --fs-section: 1.4rem;
  --fs-body: 1rem;
  --fs-reading: 1.0625rem;
  --fs-meta: 0.875rem;
  --fs-eyebrow: 0.72rem;

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

:root[data-scheme="dark"] {
  /* softly layered warm charcoal, lightest surface on top */
  --page: #171513;
  --surface: #201d1a;
  --surface-raised: #2a2622;
  --surface-sunken: #1b1917;
  --text: #f1ebe2;
  --text-muted: #b3a99c;
  --text-faint: #8b8276;
  --border: #35302a;
  --border-strong: #4a433b;
  --accent: #9fcfb1;
  --accent-text: #a9d6ba;
  --accent-soft: #24322a;
  --on-accent: #0f2219;
  --danger: #f0907d;
  --danger-soft: #3a2420;
  --focus: #8db4ff;
  --heart: #ff7d93;
  --ok: #7fcf98;
  --dot-s: 55%;
  --dot-l: 66%;
  --thumb-s: 16%;
  --thumb-l: 24%;
  --thumb-ink-s: 38%;
  --thumb-ink-l: 76%;
  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.35);
  --shadow-2: 0 2px 4px rgb(0 0 0 / 0.3), 0 14px 30px rgb(0 0 0 / 0.35);
  --shadow-pop: 0 20px 56px rgb(0 0 0 / 0.55), 0 2px 6px rgb(0 0 0 / 0.3);
  color-scheme: dark;
}

:root[data-palette="blueberry"] { --accent: #34508f; --accent-text: #2f4882; --accent-soft: #e4e9f4; --on-accent: #fff; }
:root[data-palette="blueberry"][data-scheme="dark"] { --accent: #a9bdf0; --accent-text: #b3c5f2; --accent-soft: #232b3d; --on-accent: #101a33; }

:root[data-palette="paprika"] { --accent: #a4441f; --accent-text: #973d1b; --accent-soft: #f5e3d8; --on-accent: #fff; }
:root[data-palette="paprika"][data-scheme="dark"] { --accent: #f0a07f; --accent-text: #f3ad90; --accent-soft: #3a2820; --on-accent: #2b1007; }

:root[data-palette="plum"] { --accent: #74396f; --accent-text: #6a3466; --accent-soft: #f0e3ed; --on-accent: #fff; }
:root[data-palette="plum"][data-scheme="dark"] { --accent: #dcaad3; --accent-text: #e2b6da; --accent-soft: #352533; --on-accent: #2a0f27; }

/* ================================================================
 * Base
 * ================================================================ */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--page);
  color: var(--text);
  font: var(--fs-body) / 1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p, figure { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2.5px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

svg.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.88em;
  background: var(--surface-sunken);
  padding: 0.05em 0.35em;
  border-radius: 4px;
}

.wrap {
  width: 100%;
  max-width: 1760px; /* room for up to 5 cards across on wide screens */
  margin: 0 auto;
  /* Stay clear of the notch on phones held sideways. */
  padding: 0 max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left));
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: 20;
  background: var(--surface-raised);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-pop);
}
.skip-link:focus { top: 12px; }

/* Small uppercase label used for cuisines and settings groups. */
.eyebrow, .kicker {
  font-size: var(--fs-eyebrow);
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ================================================================
 * Buttons
 * ================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  font-weight: 600;
  font-size: 0.93rem;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-1);
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
}
.btn-secondary:hover { border-color: var(--text-muted); }

.btn-ghost { color: var(--text); }
.btn-ghost:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }

.btn-small { min-height: 36px; padding: 0 10px; font-size: 0.86rem; font-weight: 500; color: var(--text-muted); }
.btn-small:hover { color: var(--text); }

.btn-icon { width: 42px; padding: 0; }
.btn-icon.btn-small { width: 36px; }

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

.btn-toggle[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent-text);
}
.btn-toggle[aria-pressed="true"] .icon { fill: var(--heart); stroke: var(--heart); }

.count-pill {
  min-width: 1.5em;
  padding: 0 0.4em;
  border-radius: 6px;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  font-size: 0.75rem;
  line-height: 1.6;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, transform 0.2s var(--ease);
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--text); }
.icon-btn[aria-disabled="true"] { opacity: 0.35; cursor: not-allowed; }

.link-btn {
  border: 0;
  background: none;
  padding: 4px 2px;
  color: var(--accent-text);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* Favorite heart */
.fav .icon { width: 20px; height: 20px; transition: transform 0.25s var(--ease); }
.fav[aria-pressed="true"] { color: var(--heart); }
.fav[aria-pressed="true"] .icon { fill: currentColor; }
.fav:active .icon { transform: scale(0.85); }

/* ================================================================
 * Header and appearance popover
 * ================================================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--page) 94%, transparent);
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-serif);
  font-size: var(--fs-wordmark);
  font-weight: 600;
  font-variation-settings: "opsz" 48;
  letter-spacing: -0.015em;
  line-height: 1;
  color: var(--text);
}
.wordmark-owner { font-style: italic; font-weight: 500; color: var(--accent-text); }
.wordmark-icon {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--accent-text);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-tools { display: flex; align-items: center; gap: 6px; }

.popover-anchor { position: relative; }
#appearance-btn[aria-expanded="true"] { background: color-mix(in srgb, var(--text) 8%, transparent); }

.popover {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 15;
  width: min(330px, calc(100vw - 32px));
  padding: 18px;
  display: grid;
  gap: 18px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  transform-origin: top right;
  animation: pop-in 0.18s var(--ease);
}
.popover[hidden] { display: none; }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.setting { border: 0; margin: 0; padding: 0; min-width: 0; }
.setting legend { padding: 0; margin-bottom: 10px; }
.setting .hint { margin-top: 8px; }

.theme-options { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.theme-option, .segmented label { position: relative; display: flex; }
.theme-option input, .segmented input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; opacity: 0; cursor: pointer;
}
.theme-face {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  font-weight: 500;
  pointer-events: none;
  transition: border-color 0.15s, background-color 0.15s;
}
.theme-swatch {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--sw-light);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.12);
}
:root[data-scheme="dark"] .theme-swatch { background: var(--sw-dark); }
.theme-option:hover .theme-face { border-color: var(--border-strong); }
.theme-option input:checked + .theme-face {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}
.theme-option input:focus-visible + .theme-face,
.segmented input:focus-visible + span { outline: 2.5px solid var(--focus); outline-offset: 2px; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
}
.segmented span {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 38px;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
  pointer-events: none;
}
.segmented input:checked + span {
  background: var(--surface-raised);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}

.hint { color: var(--text-muted); font-size: 0.84rem; }

/* ================================================================
 * Collection: intro, toolbar, filters
 * ================================================================ */

main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

.intro { padding: 30px 0 16px; }
.intro-sub { color: var(--text-muted); font-size: 0.98rem; }

.notice {
  margin-bottom: 18px;
  padding: 12px 16px;
  border-radius: var(--r);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  background: var(--danger-soft);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.search-field { position: relative; flex: 1 1 340px; max-width: 560px; }
.search-field .icon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:hover, select:hover, textarea:hover { border-color: var(--text-faint); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent);
}
textarea { resize: vertical; line-height: 1.5; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }

.search-field input {
  min-height: 48px;
  padding-left: 44px;
  border-color: var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  font-size: 1rem;
}

.toolbar-controls { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.sort { display: flex; align-items: center; gap: 8px; }
.sort-label { font-size: var(--fs-meta); color: var(--text-muted); }
.sort select { width: auto; min-height: 42px; padding: 0 34px 0 12px; font-size: 0.92rem; font-weight: 500; background-color: var(--surface); }

/* Cuisine filters as quiet text tabs; the selected one gets an accent underline. */
.filters { border: 0; margin: 22px 0 0; padding: 0; min-width: 0; }
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0 26px;
  border-bottom: 1px solid var(--border);
}
.tab { position: relative; display: inline-flex; }
.tab input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.tab-face {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 12px 0 11px;
  font-size: 0.93rem;
  font-weight: 500;
  color: var(--text-muted);
  pointer-events: none;
  transition: color 0.15s;
}
.tab-count { font-size: 0.78rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.tab:hover .tab-face { color: var(--text); }
.tab-face::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 0.2s var(--ease);
}
.tab input:checked + .tab-face { color: var(--text); font-weight: 600; }
.tab input:checked + .tab-face::after { transform: scaleX(1); }
.tab input:focus-visible + .tab-face { outline: 2.5px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.results-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 16px 0 18px;
}
.result-count { font-size: var(--fs-meta); color: var(--text-muted); }
.utilities { display: flex; gap: 2px; }

/* ================================================================
 * Recipe cards
 * ================================================================ */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 20px;
}
.grid:focus { outline: none; }

.card {
  --h: 150;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), border-color 0.25s;
}
@media (hover: hover) {
  .card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--border); }
  .card:hover .card-open { color: var(--accent-text); }
}

/* Square thumbnails: a framed photo, or a dish icon on a soft cuisine-tinted tile. */
.thumb {
  --size: 76px;
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  overflow: hidden;
  border-radius: 14px;
  background: hsl(var(--h) var(--thumb-s) var(--thumb-l));
  color: hsl(var(--h) var(--thumb-ink-s) var(--thumb-ink-l));
}
.thumb.has-photo { background: var(--surface-sunken); }
.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
}
.dish-icon {
  width: 48%;
  height: 48%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.thumb-detail { --size: 168px; border-radius: 20px; }
.thumb-detail .dish-icon { stroke-width: 1.3; }

.card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 16px;
}
.card-heading { display: grid; gap: 8px; min-width: 0; }

.card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 22px 14px;
  flex: 1;
}

.card .kicker { display: flex; align-items: center; gap: 7px; }
.cuisine-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: hsl(var(--h) var(--dot-s) var(--dot-l));
  flex: none;
}

.card-title {
  font-family: var(--font-serif);
  font-size: var(--fs-card-title);
  font-weight: 560;
  font-variation-settings: "opsz" 36;
  line-height: 1.22;
  letter-spacing: -0.01em;
}
.card-open {
  all: unset;
  cursor: pointer;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  overflow-wrap: anywhere;
  transition: color 0.15s;
}
/* The title button covers the card, so anywhere on it opens the recipe. */
.card-open::after { content: ""; position: absolute; inset: 0; z-index: 0; }
.card-open:focus-visible { outline: none; }
.card:has(.card-open:focus-visible) { outline: 2.5px solid var(--focus); outline-offset: 3px; }

.card-preview {
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.card-tags { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.card-tags li { font-size: 0.8rem; color: var(--text-faint); }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 22px;
  padding: 8px 0 10px;
  border-top: 1px solid var(--border);
}
.card-foot .fav { position: relative; z-index: 1; margin-right: -8px; }

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  color: var(--text-muted);
  font-size: var(--fs-meta);
  font-variant-numeric: tabular-nums;
}
.meta > span { display: inline-flex; align-items: center; gap: 6px; }
.meta .icon { width: 15px; height: 15px; color: var(--text-faint); }

/* Empty and no-results states */
.empty {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 64px 20px 72px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
}
.empty[hidden] { display: none; }
.empty-title { font-family: var(--font-serif); font-size: 1.6rem; font-weight: 500; letter-spacing: -0.01em; }
.empty-text { color: var(--text-muted); max-width: 42ch; }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 10px; }
.empty-actions [hidden] { display: none; }

/* ================================================================
 * Toast (import / export feedback)
 * ================================================================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: min(520px, calc(100vw - 32px));
  padding: 8px 8px 8px 14px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-pop);
  font-size: 0.9rem;
  transform: translateX(-50%);
  animation: toast-in 0.25s var(--ease);
}
.toast[hidden] { display: none; }
.toast p { flex: 1; }
.toast-icon { color: var(--ok); }
.toast.error .toast-icon { color: var(--danger); }
.toast.error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ================================================================
 * Dialogs (shared)
 * ================================================================ */

.dialog {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}
.dialog::backdrop { background: rgb(20 15 10 / 0.5); }
.dialog[open] { animation: dialog-in 0.22s var(--ease); }
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ================================================================
 * Recipe reading view
 * ================================================================ */

.detail {
  width: min(1060px, calc(100vw - 48px));
  max-height: calc(100dvh - 48px);
  overflow: hidden;
  background: var(--surface);
}
.detail-inner { max-height: calc(100dvh - 48px); overflow-y: auto; overscroll-behavior: contain; }

.detail-topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px 0;
  pointer-events: none;
}
.detail-close {
  pointer-events: auto;
  background: color-mix(in srgb, var(--surface-raised) 90%, transparent);
  box-shadow: var(--shadow-1);
  color: var(--text);
}

.detail-header {
  display: grid;
  gap: 12px;
  padding: 0 56px 26px;
  margin-top: 4px;
}
.detail-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 32px;
}
.detail-heading-text { display: grid; gap: 12px; min-width: 0; }
.detail .kicker { display: flex; align-items: center; gap: 8px; color: var(--accent-text); }
.detail-title {
  font-family: var(--font-serif);
  font-size: var(--fs-detail-title);
  font-weight: 450;
  font-variation-settings: "opsz" 144;
  line-height: 1.04;
  letter-spacing: -0.025em;
  max-width: 20ch;
  overflow-wrap: anywhere;
}
.detail-title:focus { outline: none; }
/* Long names step down a size so the title stays elegant instead of towering. */
.detail-title.is-long {
  font-size: clamp(1.8rem, 1.25rem + 1.9vw, 2.45rem);
  line-height: 1.1;
  letter-spacing: -0.012em;
  max-width: 30ch;
}
.detail .meta { font-size: 0.95rem; gap: 6px 20px; }

.tags { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li {
  padding: 2px 10px;
  border-radius: 6px;
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.detail-actions .btn { min-height: 40px; padding: 0 12px; font-weight: 500; }
.detail-actions .btn-danger { margin-left: auto; }
.detail-actions .awake[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }
.detail-actions .awake[aria-pressed="true"] .icon { fill: currentColor; }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.35fr);
  gap: 52px;
  align-items: start;
  padding: 8px 56px 56px;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 12px;
}
.section-title {
  font-family: var(--font-serif);
  font-size: var(--fs-section);
  font-weight: 560;
  font-variation-settings: "opsz" 36;
  letter-spacing: -0.01em;
}

.ingredients-panel {
  position: sticky;
  top: 58px;
  /* A long list scrolls inside the panel, so the bottom of it is never out of reach. */
  max-height: calc(100dvh - 48px - 74px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 22px 14px;
  background: var(--surface-sunken);
  border-radius: var(--r-lg);
}

.servings { display: flex; align-items: center; gap: 8px; }
.servings label { font-size: var(--fs-meta); color: var(--text-muted); }
.stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
}
.stepper .icon-btn { width: 36px; height: 36px; font-size: 1.15rem; color: var(--text); }
.stepper input {
  width: 3.2ch;
  min-width: 2.6rem;
  min-height: 36px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  box-shadow: none;
  -moz-appearance: textfield;
  appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.servings-reset { margin: -4px 0 6px; }
.servings-reset[hidden] { display: none; }

.ingredients { list-style: none; margin: 0; padding: 0; }
.ingredients li {
  padding: 10px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border-strong) 55%, transparent);
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.ingredients li:last-child { border-bottom: 0; }
.qty { font-weight: 600; font-variant-numeric: tabular-nums; }
.scaled .qty { color: var(--accent-text); }

.method-panel { padding-top: 22px; }
.method {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: step;
  display: grid;
  gap: 24px;
  max-width: 64ch;
}
.method li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 2.4rem 1fr;
  gap: 12px;
  font-size: var(--fs-reading);
  line-height: 1.7;
}
.method li::before {
  content: counter(step);
  font-family: var(--font-serif);
  font-size: 1.7rem;
  font-weight: 400;
  font-variation-settings: "opsz" 72;
  line-height: 1.05;
  color: var(--accent-text);
}
.no-method { color: var(--text-muted); font-size: var(--fs-reading); }

/* ================================================================
 * Add / edit form
 * ================================================================ */

.editor {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
}
.editor form { display: flex; flex-direction: column; max-height: calc(100dvh - 34px); }

.dialog-head, .dialog-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 14px 26px;
}
.dialog-head { justify-content: space-between; border-bottom: 1px solid var(--border); }
.dialog-head h2 {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 500;
  font-variation-settings: "opsz" 48;
  letter-spacing: -0.01em;
}
.dialog-head .icon-btn { font-size: 1.5rem; }
.dialog-foot { justify-content: flex-end; border-top: 1px solid var(--border); background: var(--surface); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.dialog-foot .btn:not(.btn-primary) { border-color: var(--border-strong); background: var(--surface-raised); }

.dialog-body { overflow-y: auto; padding: 18px 26px 26px; display: grid; gap: 18px; }

.form-note { color: var(--text-muted); font-size: 0.85rem; }

.field { display: grid; gap: 6px; min-width: 0; }
.field label, .time-field legend { font-weight: 600; font-size: 0.92rem; }
.req { color: var(--danger); }
.field-error { color: var(--danger); font-size: 0.86rem; font-weight: 600; }
.field-error:empty { display: none; }

.field-row { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; align-items: start; }
.new-cuisine { grid-column: 1 / -1; }
.new-cuisine[hidden] { display: none; }

/* Choosing from the photos folder */
.photo-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.photo-actions .btn-secondary { color: var(--text); }
.photo-actions [hidden] { display: none; }
.upload-status:empty { display: none; }
.upload-status { color: var(--accent-text); font-weight: 600; }

/* Problem saving (hosted mode) */
.form-error {
  margin: 0 26px 14px;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  border-radius: var(--r);
  background: color-mix(in srgb, var(--danger) 9%, var(--surface-raised));
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
}
.form-error[hidden] { display: none; }
.dialog-foot .btn:disabled { opacity: 0.65; cursor: progress; }

/* ================================================================
 * Sign in (hosted mode)
 * ================================================================ */

.btn-account .icon-unlocked, .btn-account.is-signed-in .icon-locked { display: none; }
.btn-account.is-signed-in .icon-unlocked { display: block; }
.btn-account.is-signed-in { color: var(--accent-text); }
.btn-account[hidden] { display: none; }

.leftovers { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.leftovers[hidden] { display: none; }
.leftovers-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.signin { width: min(440px, calc(100vw - 32px)); }
.signin-intro { color: var(--text-muted); line-height: 1.5; }
.signin .field[hidden], .signin .btn[hidden] { display: none; }
.signin .signout { margin-right: auto; }

.photo-browser {
  display: grid;
  gap: 10px;
  margin-top: 6px;
  padding: 14px;
  border-radius: var(--r);
  background: var(--surface-sunken);
}
.photo-browser[hidden] { display: none; }
.photo-browser-head { display: flex; gap: 8px; align-items: center; }
.photo-search { flex: 1; }
.photo-search input { min-height: 40px; }
.photo-connect { display: flex; }
.photo-connect[hidden] { display: none; }

.photo-grid {
  list-style: none;
  margin: 0;
  padding: 2px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
}
.photo-grid:empty { display: none; }
.photo-option {
  all: unset;
  box-sizing: border-box;
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 6px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background-color 0.15s;
}
.photo-option:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.photo-option:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 1px; }
.photo-option-img {
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
}
.photo-option-img img { display: block; width: 100%; height: 100%; object-fit: cover; }
.photo-option[aria-current="true"] .photo-option-img { box-shadow: 0 0 0 2.5px var(--accent); }
.photo-option-name {
  font-size: 0.78rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Photo framing */
.cropper {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px 20px;
  align-items: start;
  margin-top: 6px;
  padding: 14px;
  border-radius: var(--r);
  background: var(--surface-sunken);
}
.cropper[hidden] { display: none; }
.crop-stage {
  --size: 168px;
  --h: 40;
  cursor: grab;
  touch-action: none;
  box-shadow: inset 0 0 0 1px var(--border-strong);
}
.crop-stage.is-dragging { cursor: grabbing; }
.crop-stage:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 3px; }
.crop-controls { display: grid; gap: 10px; align-content: start; }
.crop-zoom { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; }
.crop-zoom label { font-weight: 500; font-size: 0.88rem; color: var(--text-muted); }
.crop-zoom input { min-height: 0; padding: 0; border: 0; background: none; box-shadow: none; accent-color: var(--accent); }
.crop-controls .btn { justify-self: start; }
.crop-status:empty { display: none; }

.time-field { border: 0; margin: 0; padding: 0; }
.time-field legend { padding: 0; margin-bottom: 6px; }
.time-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 360px; }
.time-inputs label { font-weight: 500; font-size: 0.86rem; color: var(--text-muted); }

/* ================================================================
 * Responsive
 * ================================================================ */

/* Tablets held upright (768 px and wider) keep ingredients beside the method. */
@media (max-width: 760px) {
  .detail-header { padding: 0 32px 22px; }
  .detail-grid { grid-template-columns: 1fr; gap: 8px; padding: 4px 32px 40px; }
  .ingredients-panel { position: static; max-height: none; overflow: visible; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); }
  .wordmark { font-size: 1.2rem; gap: 8px; }
  .wordmark-icon { width: 22px; height: 22px; }
  .add-word { display: none; }
  .account-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .btn-account { padding: 0 10px; }
  .form-error { margin: 0 18px 12px; }
  .intro { padding: 26px 0 16px; }
  .toolbar-controls { width: 100%; margin-left: 0; }
  .sort { flex: 1; }
  .sort select { flex: 1; width: 100%; }
  .filters { margin-top: 16px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 0 22px; margin: 0 -16px; padding: 0 16px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: none; }
  .grid { gap: 14px; }
  .card-body { padding: 18px 18px 12px; }
  .card-foot { margin: 0 18px; }
  .field-row { grid-template-columns: 1fr 1fr; }
  .field-row .field:first-child { grid-column: 1 / -1; }
  .cropper { grid-template-columns: 1fr; justify-items: start; }
  .thumb-card { --size: 64px; border-radius: 12px; }

  .detail, .editor {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .detail-inner { height: 100%; max-height: 100dvh; }
  .detail-header { padding: 0 20px 20px; }
  .detail-heading { gap: 16px; }
  .thumb-detail { --size: 92px; border-radius: 16px; }
  .detail-close { margin-top: 0; }
  .detail-grid { padding: 4px 16px 32px; }
  .ingredients-panel { padding: 18px 16px 10px; border-radius: var(--r); }
  .method-panel { padding: 22px 4px 0; }
  .detail-actions { gap: 0; }
  .detail-actions .btn { padding: 0 9px; gap: 6px; }
  .detail-actions .btn-danger { margin-left: auto; }
  .editor form { height: 100%; max-height: 100dvh; }
  .dialog-body { flex: 1; padding: 16px 18px 22px; }
  .dialog-foot { border-radius: 0; }
  .dialog-foot .btn { flex: 1; }
  .toast { bottom: calc(14px + env(safe-area-inset-bottom)); }
}

/* Full-screen dialogs (phones, and phones held sideways) keep clear of the notch and home bar. */
@media (max-width: 640px), (max-height: 520px) and (orientation: landscape) {
  .detail-topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .detail-inner { padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .editor .dialog-head { padding-top: calc(14px + env(safe-area-inset-top)); }
  .editor .dialog-head, .editor .dialog-foot { padding-left: max(18px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .editor .dialog-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
}

/* Phones held sideways: little height, so the header scrolls away and dialogs fill the screen. */
@media (max-height: 520px) and (orientation: landscape) {
  .site-header { position: static; }
  .detail, .editor {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .detail-inner { height: 100%; max-height: 100dvh; }
  .ingredients-panel { position: static; max-height: none; overflow: visible; }
  .editor form { height: 100%; max-height: 100dvh; }
  .dialog-foot { border-radius: 0; }
  .detail-header { padding-top: 0; }
  .detail-title { font-size: 2.2rem; }
  .thumb-detail { --size: 104px; border-radius: 16px; }
}

/* Touch screens: bigger tap targets, no zooming into text boxes, and feedback on tap. */
@media (pointer: coarse) {
  html { -webkit-tap-highlight-color: transparent; }
  button, label, a, select { touch-action: manipulation; }
  /* iPhones zoom the whole page into any text box with text smaller than 16px. */
  input, select, textarea, .sort select, .photo-search input, .stepper input, .search-field input { font-size: 16px; }
  .btn-small { min-height: 44px; }
  .btn-icon.btn-small { width: 44px; }
  .icon-btn, .stepper .icon-btn { width: 44px; height: 44px; }
  .stepper input { min-height: 44px; }
  .detail-actions .btn { min-height: 44px; }
  .btn:active, .icon-btn:active { transform: scale(0.96); }
  .card:active { transform: scale(0.985); }
}

/* Touch screens have no pointer to rest on things, so don't leave buttons looking hovered after a tap. */
@media (hover: none) {
  .btn-ghost:not([aria-pressed="true"]):hover, .icon-btn:hover { background: transparent; }
  .btn-secondary:not([aria-pressed="true"]):hover { border-color: var(--border-strong); }
  .btn-primary:hover { background: var(--accent); }
  .btn-small:hover { color: var(--text-muted); }
  .photo-actions .btn-secondary:hover { color: var(--text); }
}

/* ================================================================
 * Printing
 * ================================================================ */

#print-area { display: none; }

@media print {
  @page { margin: 16mm 14mm; }

  :root, :root[data-palette][data-scheme] {
    --page: #fff; --surface: #fff; --surface-raised: #fff; --surface-sunken: #fff;
    --text: #000; --text-muted: #444; --text-faint: #666; --border: #bbb; --border-strong: #999;
    --accent: #000; --accent-text: #000; --accent-soft: #fff;
    color-scheme: light;
  }
  body { background: #fff; color: #000; font-size: 11pt; }

  /* Ctrl+P on the collection: a plain list of recipes without the controls. */
  .skip-link, .site-header, .toolbar, .filters, .results-head, .toast, .notice, .fav, .dialog, .empty-actions { display: none !important; }
  .grid { display: block; }
  .card { box-shadow: none; border: 0; border-bottom: 1px solid #ccc; border-radius: 0; margin-bottom: 6pt; break-inside: avoid; transform: none !important; }
  .thumb { display: none; }
  .card-open::after { display: none; }

  /* Print button in a recipe: only that recipe. */
  body.printing-recipe > *:not(#print-area) { display: none !important; }
  body.printing-recipe #print-area { display: block; }

  #print-area h1 { font-family: var(--font-serif); font-weight: 500; font-size: 24pt; line-height: 1.15; margin-bottom: 4pt; }
  .print-head { border-bottom: 2px solid #000; padding-bottom: 8pt; margin-bottom: 14pt; }
  .print-meta { font-size: 11pt; color: #333; }
  .print-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: 18pt; align-items: start; }
  #print-area h2 { font-size: 10pt; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6pt; }
  .print-ingredients ul { margin: 0; padding-left: 14pt; }
  .print-ingredients li { margin-bottom: 4pt; break-inside: avoid; }
  .print-ingredients .qty, .print-ingredients .scaled .qty { color: #000; }
  .print-method ol { margin: 0; padding-left: 16pt; }
  .print-method li { margin-bottom: 7pt; line-height: 1.45; break-inside: avoid; }
  .print-tags { margin-top: 16pt; color: #444; font-size: 9.5pt; }
  .print-foot { margin-top: 18pt; padding-top: 6pt; border-top: 1px solid #bbb; color: #666; font-size: 8.5pt; }
}

/* ================================================================
 * Preferences
 * ================================================================ */

@media (max-width: 420px) {
  .wordmark { font-size: 1.12rem; white-space: nowrap; }
  .wordmark-icon { display: none; }
  .detail-title { font-size: 2rem; }
  .detail-title.is-long { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  .tab input:checked + .tab-face { text-decoration: underline; }
  .theme-option input:checked + .theme-face, .segmented input:checked + span { border: 2px solid CanvasText; }
  .btn-toggle[aria-pressed="true"], .fav[aria-pressed="true"] { border: 2px solid CanvasText; }
  .card { border: 1px solid CanvasText; }
}

/* Favorite in the reading view: keep the label calm, color only the heart. */
.detail-actions .fav[aria-pressed="true"] { color: var(--text); }
.detail-actions .fav[aria-pressed="true"] .icon { color: var(--heart); }

/* Toast icons: check for success, alert for errors. */
.toast-icon-error { display: none; }
.toast.error .toast-icon:not(.toast-icon-error) { display: none; }
.toast.error .toast-icon-error { display: block; color: var(--danger); }
