:root {
  color-scheme: dark;

  --bg: #0d1117;
  --panel: #161b22;
  --surface-2: #1c2129;
  /* Decoration only: panel outlines, list separators, the tuning bar edge.
     Editable controls use --control-border so their boundaries reach 3:1
     against the fields and panels around them. */
  --border: #30363d;
  --control-border: #636c76;
  --focus: #58a6ff;
  --fg: #e6edf3;
  --muted: #8b949e;
  /* Flasher's accent split: --accent fills actions (with light text), while
     --accent-text is the blue that stays legible as text on the dark
     surfaces. Success keeps its own green so met targets and saved states
     read as "ok", not as an action. */
  --accent: #1a5fd7;
  --accent-hover: #2f6fdd;
  --accent-soft: rgba(56, 139, 253, 0.14);
  --accent-text: #79b8ff;
  --ok: #3fb950;
  --bad: #f85149;

  --radius: 8px;
  /* The panel's own padding, also cancelled by the library list so its rows
     bleed out to the panel border (see `.list-panel > .list`). One token, so
     the two can never drift apart. */
  --panel-pad: 0.9rem;
  /* Sized to the labeled menu, not to a generic drawer preset. The same
     token also anchors the narrow-screen backdrop. */
  --side-nav-width: 11rem;
}

/* Shared recipe photo slots: fixed geometry, including failed loads. */
.recipe-photo {
  display: inline-flex;
  flex: none;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  vertical-align: middle;
}

.recipe-photo.thumb {
  width: 5rem;
  height: 5rem;
}

.recipe-photo.preview {
  width: 5rem;
  height: 5rem;
}

.recipe-photo.detail {
  width: 180px;
  max-width: 100%;
  height: 135px;
}

.recipe-photo img.hidden {
  display: none;
}

.recipe-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.recipe-photo.thumb img, .recipe-photo.preview img {
  height: 100%;
  object-fit: cover;
}

.photo-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.photo-placeholder svg {
  width: 58%;
  height: 58%;
}

.photo-placeholder svg rect {
  fill: var(--surface-2);
}

.photo-placeholder svg g {
  stroke: var(--muted);
}

.photo-placeholder svg ellipse {
  fill: var(--muted);
}

.list li.row-item > .list-row.open,
.list li.row-item > .list-row.edit {
  display: flex;
  flex-direction: row;
  /* Stretch, not center: the photo box keeps its square width and fills the
     row's height, so a row whose wrapped facts make it taller than the photo
     still shows a full-height image. */
  align-items: stretch;
  gap: .65rem;
}

.recipe-row-text {
  display: flex;
  flex-direction: column;
  /* Centred against the photo: stretching the column only moves its box, the
     name and facts stay together in the middle of the row. */
  justify-content: center;
  min-width: 0;
  overflow-wrap: anywhere;
}

.recipe-photo-editor {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .75rem;
  margin-block: .5rem;
}

.recipe-photo-editor .row-actions {
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}

.recipe-photo-editor p {
  flex-basis: 100%;
}

.recipe-title-fields {
  display: grid;
  gap: .5rem;
}

/* Share the title/name's existing height on a wide ingredient pane, so the
   photo does not push the editor footer below the desktop viewport. Narrow
   panes retain the full-width name and wrapping photo controls. */
@container (min-width: 24rem) {
  .ingredient-title-fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 14rem;
    align-items: start;
    gap: .75rem;
  }

  .ingredient-title-fields .recipe-photo-editor {
    margin-block: 0;
  }
}

@container (min-width: 34rem) {
  .recipe-title-fields {
    grid-template-columns: minmax(0, 1fr) 20rem;
    align-items: center;
  }

  .recipe-photo-editor {
    margin-block: 0;
    gap: .5rem;
  }

  .recipe-photo-editor .row-actions {
    flex-wrap: nowrap;
  }

  .recipe-photo-editor button {
    padding-inline: .5rem;
    font-size: .875rem;
  }

}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
}

/* The sidebar owns navigation; the content column carries the page heading
   and stays the place where the work happens. */
.app {
  flex: 1 1 auto;
  width: min(100%, 1000px);
  max-width: 1000px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 1rem;
}

h1 {
  font-size: 1.4rem;
  margin: 0;
}

h2 {
  font-size: 1.05rem;
  margin: 0;
}

h3 {
  font-size: 0.95rem;
  margin: 1rem 0 0.4rem;
}

/* ------------------------------------------------------------------ */
/* Navigation: persistent sidebar on wide screens, drawer below 64rem. */
/* The menu pattern is Flasher's: brand and labeled links in a left      */
/* sidebar, an off-canvas labeled drawer with a backdrop on narrow       */
/* screens, and the toggle in the sticky header.                         */
/* ------------------------------------------------------------------ */

.side-nav {
  position: sticky;
  top: 0;
  z-index: 6;
  width: var(--side-nav-width);
  height: 100vh;
  height: 100dvh;
  flex: 0 0 var(--side-nav-width);
  display: flex;
  flex-direction: column;
  gap: 2rem;
  padding: 1.25rem 0.875rem;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.side-nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.5rem;
  padding: 0 0.625rem;
  color: var(--fg);
  font-size: 1.05rem;
  font-weight: 650;
}

.side-nav-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-nav-logo {
  width: 2rem;
  height: 2rem;
  flex: 0 0 2rem;
}

.nav-close {
  display: none;
  /* The brand row must shrink the name, never the close target. */
  flex-shrink: 0;
  margin-left: auto;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
}

.nav-close:not(:disabled):hover {
  background: var(--surface-2);
  color: var(--fg);
}

.side-nav-links {
  display: flex;
  flex-direction: column;
  /* The app's shared 0.5rem action rhythm (UX-11). */
  gap: 0.5rem;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 0.625rem 0.75rem;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  text-align: left;
}

.nav-item:not(:disabled):hover {
  background: var(--surface-2);
  color: var(--fg);
}

.nav-item.active,
.nav-item.active:not(:disabled):hover {
  background: var(--accent-soft);
  border-color: rgba(56, 139, 253, 0.4);
  color: var(--accent-text);
  /* The active destination must not read by color alone: weight carries it
     too (and `aria-current` exposes it programmatically). */
  font-weight: 600;
}

.side-nav-footer {
  margin-top: auto;
  padding: 0.75rem 0.75rem 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.side-nav-user {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-nav-footer #sign-out {
  align-self: flex-start;
}

.session-error {
  margin: 0;
  font-size: 0.8rem;
}

/* Rendered only while the drawer is open; the narrow layout styles it. */
.nav-backdrop {
  display: none;
}

/* The sticky page heading. Its measured height is exported to --top-h by
   the app, so the editor's sticky tuning bar parks below it. */
.top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
}

.nav-toggle {
  display: none;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--fg);
  font-size: 1.35rem;
  line-height: 1;
}

.nav-toggle:not(:disabled):hover {
  background: var(--surface-2);
}

.page-heading {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
  color: var(--fg);
}

.page-heading h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 1.35rem;
  font-weight: 650;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-logo {
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
}

/* Narrower screens use the same labeled off-canvas drawer rather than a
   compact icon rail. It is closed on every fresh render and closes after
   navigation. The breakpoint is px on purpose: it must match the JS threshold
   in `nav_is_narrow` exactly, and a rem media query follows the browser's
   default font size while `inner_width` does not. */
@media (max-width: 1024px) {
  .app-shell .app {
    width: 100%;
    max-width: none;
  }

  .side-nav {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 20;
    width: min(var(--side-nav-width), calc(100vw - 2rem));
    height: 100vh;
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform 160ms ease;
    box-shadow: 0 0 2rem rgba(0, 0, 0, 0.35);
  }

  .side-nav.open {
    transform: translateX(0);
  }

  .nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .nav-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* The close target (44 px) leaves no room for the full name beside the
     logo in the drawer; the wide sidebar keeps the visible wordmark. */
  .side-nav-name {
    display: none;
  }

  .nav-backdrop,
  .nav-backdrop:not(:disabled):hover {
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: min(var(--side-nav-width), calc(100vw - 2rem));
    z-index: 19;
    width: auto;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(1, 4, 9, 0.6);
  }
}

@media (prefers-reduced-motion: reduce) {
  .side-nav {
    transition: none;
  }
}

button,
select,
input {
  font: inherit;
  /* Editable-field text is a comfortable ~16 px: a control inside a .fact
     label would otherwise inherit its 12.8 px label type. */
  font-size: 1rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  /* Common actions are practical 44 px touch targets: the painted box is the
     hit area, so what looks tappable is tappable. The .pin checkbox opts out
     below (its wrapping label is the target) and the gram steppers keep their
     own 44 px square sizing. */
  min-height: 2.75rem;
  max-width: 100%;
  min-width: 0;
}

/* A checkbox is a mark, not a field: keep its own box. */
input[type="checkbox"] {
  min-height: 0;
}

button {
  cursor: pointer;
  /* A long label wraps inside the button rather than overflowing its row. */
  overflow-wrap: anywhere;
}

/* The sticky header must not cover an interactive control the browser
   scrolls into view (focus or programmatic scrolling); the editor's fields
   add the taller tuning-bar clearance on top of this (see .detail below). */
button,
input,
select,
textarea,
a,
summary {
  scroll-margin-top: calc(var(--top-h, 3.25rem) + 0.5rem);
}

/* One clear primary action per task (Save, sign in, create passkey): a filled
   accent control while secondary actions stay outlined. Flasher's blue needs
   white text (both dark text and the muted --fg miss 4.5:1 on the hover
   shade); the dark --bg edge keeps the filled boundary at least 3:1 against
   its own fill (UX-10). */
.primary,
#save-ingredient,
.save-recipe {
  background: var(--accent);
  border-color: var(--bg);
  color: #fff;
  font-weight: 600;
}

.primary:not(:disabled):hover,
#save-ingredient:not(:disabled):hover,
.save-recipe:not(:disabled):hover {
  background: var(--accent-hover);
}

/* A pending/unavailable primary drops the fill and reads as a quiet, legible
   disabled control instead of a live primary action ("saving…"). */
.primary:disabled,
#save-ingredient:disabled,
.save-recipe:disabled {
  opacity: 1;
  background: var(--bg);
  border-color: var(--control-border);
  color: var(--muted);
}

/* Keyboard focus is its own colour channel, so a focused control is
   distinguishable from the invalid (--bad) and pinned/met (--accent) states.
   Text fields match :focus-visible whenever they are focused. The opened
   editors' and detail's h2 headings join the ring (issue #22): a heading
   focused by a keyboard activation keeps :focus-visible, while a pointer or
   touch open leaves it off, so touch users see no box. Only h2 carries the
   programmatic tabindex="-1" landing points, so no other heading level is
   selected. Nothing suppresses the outline globally. */
button:focus-visible,
select:focus-visible,
input:focus-visible,
h2:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* A button disabled while it works (a save in flight) reads as unavailable. */
button:disabled {
  opacity: 0.55;
  cursor: default;
}

.layout {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

@media (min-width: 820px) {
  .layout {
    /* The editor gets the larger share: its row controls need the width to
       keep ingredient names identifiable, while the list stays usable
       (UX-16). */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
    align-items: start;
  }
}

/* The ingredient manager is a single list: use the full width. */
.layout.single {
  grid-template-columns: 1fr;
}

/* With a form or confirmation open, a wide screen gets a real detail pane
   beside the list (like the recipe editor), so the ingredient form is at the
   top of the page instead of below the whole list. Phones keep the
   detail-takes-over behavior below. */
@media (min-width: 820px) {
  .layout.single.detail-open {
    /* The list gets the larger share: its rows carry names and facts, while
       the ingredient form stays comfortable in the rest. */
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    align-items: start;
  }
}

/* On a phone the detail (an opened recipe or form) takes over the screen:
   hide the list so the detail starts at the top. On wider screens both the
   list and the detail are shown side by side, so this never applies. */
@media (max-width: 819px) {
  .layout.detail-open .list-panel {
    display: none;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--panel-pad);
}

.detail {
  min-width: 0;
  /* The recipe row layout below is chosen by this pane's usable width, not
     the viewport: at 820 px the two-column page leaves the editor narrower
     than its phone-width counterpart, which used to truncate ingredient
     names to about 99 px (UX-16). */
  container-type: inline-size;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

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

/* Library rows spend the panel's inline padding on their own card instead: the
   list bleeds out to the panel border so the photo can sit closer to the edge,
   while the heading and the library tools keep the `.panel` inset so they stay
   aligned with the list's own text. The negative margin only cancels that
   padding (`--panel-pad`), so nothing overflows the panel. */
.list-panel > .list {
  margin-inline: calc(var(--panel-pad) * -1);
}

/* Library tools (UX-16): a lightweight text filter and the visible item
   count. The count is deliberately not a live region (UX-07: typing must not
   announce on every keystroke). */
.list-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 0.4rem 0;
}

.filter-field {
  display: flex;
  flex: 1 1 12rem;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.filter-field input {
  flex: 1 1 auto;
  /* A definite width keeps the input's intrinsic control size out of the
     panel's min-content width; without it the search field stretched the
     320 px list panel (UX-16). */
  width: 100%;
  min-width: 0;
}

.item-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* A filter that matches nothing is its own state: not the empty library and
   not a failure. */
.list-state.no-matches {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.6rem;
}

.list-state.no-matches p {
  margin: 0 0 0.4rem;
}

.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}

/* A library row is one full-width native button: the whole name-and-summary
   surface opens the recipe or edits the ingredient, so no width goes to a
   separate action column. The painted box is a compact row with a 44 px
   minimum target, not a form button; list rows (including the account's
   passkey rows) keep the layout above. */
.list li.row-item {
  display: block;
  padding: 0;
}

.list li.row-item > .list-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-size: 1rem;
  text-align: left;
}

/* Hover paints the row surface and its outline; the title keeps the row's own
   text colour, so a row's name never changes hue under the pointer. */
.list li.row-item > .list-row:not(:disabled):hover {
  background: var(--surface-2);
  border-color: var(--border);
}

.list li > div:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* The account's passkey actions keep their size while its details shrink, so
   "rename"/"remove" never wrap letter by letter (UX-16). */
.list li > .row-actions {
  flex-shrink: 0;
}

/* List lifecycle states: loading, genuinely empty, and failed. A failed load
   must read as an error, never as an empty account. */
.list-state {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.4rem 0;
}

.list-state.failure {
  border: 1px solid var(--bad);
  border-radius: 8px;
  padding: 0.6rem;
  margin: 0.5rem 0 0.6rem;
}

.list-state.failure p {
  margin: 0 0 0.5rem;
  color: var(--bad);
}

.facts {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

/* A recipe row's summary is the ingredient list, not nutrition: the amounts are
   the part a cook reads at a glance, so they carry the accent and the tabular
   figures while the names stay muted like the other row facts. */
.row-ingredients {
  line-height: 1.35;
}

.row-grams {
  color: var(--accent-text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.row-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

/* Destructive record actions live in a separated footer of the saved record's
   detail or editor, never in a list row or the sticky tuning bar. */
.item-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.fact {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.4rem 0;
}

.fact input {
  width: 100%;
  min-width: 0;
}

/* The recipe row: a narrow detail pane gives the selector its own full row
   so long ingredient names stay identifiable; once the pane is wide enough
   the controls share one row again. The 36 rem container threshold keeps the
   820 px two-column editor wrapped while 1280 px keeps the single row. */
.line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin: 0.4rem 0;
}

.line .ingredient-choice {
  flex: 1 1 100%;
  min-width: 0;
}

.line .grams {
  min-width: 0;
}

@container (min-width: 36rem) {
  .line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 4.5rem auto auto auto;
  }

  .line .ingredient-choice {
    flex: none;
  }
}

/* A text field with a numeric keypad hint: unlike `type="number"` it keeps a
   typed `.` visible while editing, so decimals can round instead of being
   silently dropped and appended to. The visible gram unit sits inside the
   field's own box (UX-20), so the row keeps its pre-unit geometry. */
.grams-field {
  position: relative;
  display: inline-block;
  width: 4.5rem;
  min-width: 0;
}

.line .grams {
  width: 100%;
  text-align: center;
  /* Space for the unit inside the field's right edge. */
  padding-right: 1.1rem;
}

/* The visible gram unit: assistive tech reads the field's “Grams for line N”
   name, so the visual suffix is hidden from the tree. */
.grams-unit {
  position: absolute;
  top: 50%;
  right: 0.45rem;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
  pointer-events: none;
}

/* Thumb-friendly step buttons (44 px square). */
.stepper {
  display: flex;
  gap: 0.4rem;
}

.stepper button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  /* A press must not select text or open a long-press callout; the button
     handles the hold itself. */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.stepper button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Pin: hold this line's amount fixed when optimizing. The row marks itself so
   the state is visible at a glance; the label is a 44 px tap target. The pin
   glyph is the visual, so the native checkbox only carries semantics
   (keyboard, screen readers): visually hidden but focusable, with the glyph
   mirroring its checked state and showing the keyboard focus ring. */
.line .pin {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer;
  /* The glyph alone is narrow; the label stays the 44 px square tap target. */
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0 0.25rem;
}

.line .pin input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.line .pin .pin-glyph {
  width: 1.25rem;
  height: 1.25rem;
}

/* Unchecked is an outlined pin, checked a filled one: the state is a shape,
   not a hue swap, so it survives without colour and under forced colors. */
.line .pin .pin-glyph-fill {
  display: none;
}

.line .pin input:checked + .pin-glyph {
  color: var(--accent);
}

.line .pin input:checked + .pin-glyph .pin-glyph-fill {
  display: inline;
}

.line .pin input:checked + .pin-glyph .pin-glyph-outline {
  display: none;
}

/* Keyboard focus keeps its own colour channel, distinct from --accent. */
.line .pin input:focus-visible + .pin-glyph {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* A valid pinned amount carries the accent, but validity wins: an invalid
   pinned amount keeps the error boundary (UX-01/UX-10) while the checked pin
   still marks the pinned state. */
.line.pinned .ingredient-choice:not([aria-invalid="true"]),
.line.pinned .grams:not([aria-invalid="true"]) {
  border-color: var(--accent);
}

/* Validation belongs beneath the complete control row, so it never steals a
   grid column from the selector, grams, stepper, pin, or remove controls. */
.line > .field-error {
  grid-column: 1 / -1;
  flex: 1 0 100%;
  width: 100%;
}

/* Per-line floors stay optional, with a full-size action beside the amounts. */
.floors-edit {
  min-height: 2.75rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.9rem;
}

.floors-edit[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent-text);
}

.floors {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.6rem;
  flex: 1 0 100%;
  min-width: 0;
}

@container (min-width: 36rem) {
  .floors {
    grid-column: 1 / -1;
  }
}

.floors-label {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.floor-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.8rem;
  min-width: 0;
}

.floor-field .floor {
  width: 3.6rem;
  min-width: 0;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.floor-field .field-error {
  flex: 1 0 100%;
}

.floor-unit {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
}

/* On a phone the controls do not fit on one row: the base `.line` flex
   layout above already gives the select its own row. */

/* Compact tuning feedback (UX-08): the whole-recipe result and its distance to
   the targets sits next to the amounts being edited and sticks to the top of
   the viewport, so a long recipe never hides the result or the primary
   actions. The scroll margins below keep a focused amount and its validation
   message clear of the bar when the browser scrolls them into view. */
.tuning {
  position: sticky;
  /* Parks directly below the sticky header; --top-h is the header's measured
     height (JavaScript), and the fallback only covers the first frames. */
  top: var(--top-h, 3.25rem);
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  margin: 0.4rem -0.9rem;
  padding: 0.45rem 0.9rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.tuning-readout {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  margin-right: auto;
}

.tuning-facts {
  margin: 0;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

/* The scope/denominator cue sits under the compact totals so a phone user
   does not have to reach the full Nutrition panel to know what the numbers
   describe. It stays subordinate to the numbers and wraps within the bar. */
.tuning-scope {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.2;
}

.tuning-split {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 0.6rem;
  list-style: none;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.tuning-split li {
  padding: 0;
  white-space: nowrap;
}

.tuning .note,
.tuning .status,
.tuning .save-error {
  flex-basis: 100%;
  margin: 0;
}

/* A failed save and its retry: the alert region holds the message only
   (UX-06 pattern), the retry control sits outside it, and both stay next to
   the action they belong to so a scrolled editor still shows them (UX-17). */
.save-error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  flex-basis: 100%;
}

.save-error .error {
  flex: 1 1 14rem;
  margin: 0;
}

.save-error .retry {
  flex: 0 0 auto;
}

/* The editor publishes the sticky bar's measured height as
   `--tuning-bar-height` (see `track_tuning_bar_height`) because the note and
   status lines wrap the bar to several rows on a phone, more than any fixed
   margin can cover. The fallback is a floor: it covers the first paint before
   the measurement lands. The longest optimizer-note bar measured on a phone
   is about 229 px at 320 px; the live measurement raises the margin above
   this floor once it lands, and the measured value is what keeps focused
   amounts clear for taller bars. */
.detail input,
.detail select {
  scroll-margin-top: calc(
    var(--top-h, 3.25rem) + max(var(--tuning-bar-height, 5rem), 5rem) + 0.5rem
  );
  scroll-margin-bottom: 4rem;
}

@media (max-width: 819px) {
  .detail input,
  .detail select {
    scroll-margin-top: calc(
      var(--top-h, 3.25rem) + max(var(--tuning-bar-height, 13rem), 13rem) + 0.5rem
    );
  }
}

/* Target heading and its optional explanation. */
.target-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 1rem;
  margin: 1rem 0 0.4rem;
}

.target-head h3 {
  margin: 0;
}

.targets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
}

.targets .fact {
  margin: 0.3rem 0;
}

/* On a wide editor the five target fields fit three to a row, keeping the
   target section compact enough for the Nutrition panel to stay in view at
   1280x900 while every field keeps its 44 px control. */
@media (min-width: 820px) {
  .targets {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.split {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  font-size: 0.85rem;
}

.split li {
  padding: 0.15rem 0;
}

.delta.ok {
  color: var(--ok);
}

.delta.bad,
.error {
  color: var(--bad);
}

.field-error {
  display: block;
  color: var(--bad);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

input[aria-invalid="true"] {
  border-color: var(--bad);
}

.error {
  margin-top: 0.6rem;
}

/* Destructive actions read as destructive wherever they appear: list rows
   and the named confirmation that guards them. In a confirmation the red
   choice is pushed clear of the quieter cancel that precedes it. */
button.delete {
  color: var(--bad);
  border-color: var(--bad);
}

.discard .row-actions button.delete {
  margin-left: auto;
}

/* Result of a deliberate action (a completed delete), announced with
   role=status. */
.status {
  color: var(--muted);
  margin-top: 0.6rem;
}

/* The one list-level message (a refused delete, a saved record): a single,
   persistent toast, never a stack. It is fixed to the viewport so a message
   that used to sit under a long list stays in view wherever the user is.
   The card and its text never intercept clicks -- only the small dismiss
   control does -- so a toast can never make a row action unclickable. */
.toasts {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 10;
  display: flex;
  justify-content: flex-end;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: min(100%, 26rem);
  padding: 0.75rem 0.9rem;
  background: var(--panel);
  border: 1px solid var(--control-border);
  border-left: 3px solid var(--ok);
  border-radius: var(--radius);
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.toast.error {
  border-left-color: var(--bad);
}

.toast p {
  flex: 1 1 auto;
  margin: 0;
}

.toast .error,
.toast .status {
  margin: 0;
}

#dismiss-toast {
  flex: 0 0 auto;
  pointer-events: auto;
}

/* Short helper copy and the discard decision that guards a replacement. */
.draft-hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.2rem 0 0.4rem;
}

.discard {
  border-color: var(--bad);
}

.discard p {
  margin: 0 0 0.4rem;
}

.note {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
}

.note.success {
  color: var(--ok);
}

.note.error {
  color: var(--bad);
}

/* Cooking view: large, uncluttered, readable from a step away. */
.cook .panel-head h2 {
  font-size: 1.4rem;
  overflow-wrap: anywhere;
}

.cook-total {
  color: var(--muted);
  margin: 0.2rem 0 0.8rem;
}

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

.cook-list li {
  display: flex;
  gap: 0.9rem;
  align-items: baseline;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.cook-grams {
  min-width: 5.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent-text);
}

.cook-nutrition {
  margin-top: 0.9rem;
  font-size: 1.02rem;
}

button.big {
  font-size: 1.05rem;
  padding: 0.5rem 0.9rem;
}

.hidden {
  display: none;
}

/* Auth screen: a centered card; first-run register or one-button sign-in. */
.auth-screen {
  min-height: 100vh;
  max-width: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 22rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.auth-card h1 {
  text-align: center;
}

.auth-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
  text-align: center;
}

.auth-label {
  color: var(--muted);
  font-size: 0.8rem;
}

.auth-card input,
.auth-card button {
  width: 100%;
}

.form-ok {
  color: var(--ok);
  margin: 0;
  text-align: center;
}

/* Account screen: passkey rows reuse `.list`; the hint reads left. */
.account-hint {
  text-align: left;
  margin: 0.2rem 0 0.6rem;
}

/* A passkey row leads with the user's label (UX-18); the provider and dates
   stay secondary and the credential id sits in optional detail, so the
   technical identity never dominates the row. */
.passkey-main {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.passkey-name {
  overflow-wrap: anywhere;
}

.passkey-tech {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.passkey-tech summary {
  cursor: pointer;
}

.passkey-tech code {
  overflow-wrap: anywhere;
  word-break: break-all;
}

/* The inline rename form and remove confirmation take over the row. */
.passkey-rename,
.passkey-confirm {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.passkey-rename input {
  width: 100%;
}

.passkey-confirm p {
  margin: 0;
}

.passkey-confirm .draft-hint {
  margin: 0;
}

/* Issue 9 spike: explanations live in nonmodal native popovers. The top
   layer keeps opening help from moving values or changing the sticky bar. */
.help-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
}

.help-heading h2,
.help-heading h3 {
  margin: 0;
  min-width: 0;
}

.info-button {
  flex: 0 0 2.75rem;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border-radius: 50%;
  color: var(--muted);
  font-family: Georgia, serif;
  font-weight: 700;
  font-size: 1.1rem;
}

.info-popover {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(28rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  padding: 1rem;
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--fg);
  box-shadow: 0 0.5rem 2rem #0008;
  font-size: 1rem;
  line-height: 1.5;
}

.info-popover p:last-child {
  margin-bottom: 0;
}

.info-popover .help-heading button {
  flex-shrink: 0;
}

/* A small action popover (barcode/nutrition-label photo) reuses the centered
   help popover geometry so it stays inside a phone viewport and scrolls. */
.info-popover.action-popover {
  width: min(22rem, calc(100vw - 2rem));
}

.info-popover.action-popover .file-button {
  width: 100%;
  justify-content: center;
}

/* The facts heading carries two actions (help and the label source control),
   so it wraps instead of pushing the title off a phone viewport. */
.facts-heading {
  flex-wrap: wrap;
  align-items: center;
}

.heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
  /* Once the actions wrap onto their own line they stay on the right, so the
     control reads as belonging to the heading above it. */
  margin-left: auto;
}

.amount-heading {
  margin-top: 0.6rem;
}

.floor-help-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.ingredient-facts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.25rem 0.75rem;
  margin-bottom: 0.75rem;
}

/* Nutrition values form one readout. Paragraph defaults add large gaps and
   push the calorie result below the desktop viewport after Optimize. */
#nutrition-total,
#nutrition-delta {
  margin: 0.35rem 0;
}

.ingredient-picker { position: relative; min-width: 0; }
.ingredient-picker .ingredient-choice { width: 100%; min-width: 0; }
.line .ingredient-picker { flex: 1 1 100%; }
.ingredient-results {
  position: absolute; top: 100%; left: 0; width: 100%; z-index: 3;
  max-height: 16rem; overflow-y: auto; background: var(--panel);
  border: 1px solid var(--border); border-radius: .35rem;
  box-shadow: 0 .4rem 1rem #0006;
}
.ingredient-results[hidden] { display: none; }
.ingredient-results button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; white-space: normal; }
.ingredient-results button[aria-selected="true"] { background: var(--border); }
.ingredient-results p { padding: .5rem; margin: 0; }

/* Barcode entry: the code field shares one row with its actions; the scan
   panel and the sticky lookup report sit inside the editor so the report
   stays on screen while the facts are edited. */
.barcode-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
}

.barcode-row .fact {
  flex: 1 1 12rem;
  margin-bottom: 0;
}

.barcode-actions {
  flex: 0 0 auto;
  padding-bottom: 0.45rem;
}

/* A source-first control: one primary action plus an arrow that opens its
   photo fallback. The two halves are one control visually (shared radius,
   adjacent borders, no gap) and each still gets its own focus ring. */
.split-control {
  display: inline-flex;
  align-items: stretch;
  min-height: 2.75rem;
  max-width: 100%;
}

.split-control button {
  min-height: 2.75rem;
  margin: 0;
}

.split-main {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.split-more {
  flex: 0 0 2.75rem;
  width: 2.75rem;
  padding: 0;
  border-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.split-main:focus-visible,
.split-more:focus-visible {
  position: relative;
  z-index: 1;
}

/* The image fallback is a label wrapping a visually-hidden file input: the
   label is the visible, button-styled control, and :focus-within keeps the
   input's keyboard focus visible on it. */
.file-button {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  font-size: 1rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  min-height: 2.75rem;
}

.file-button:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* A file picker whose lookup is in flight is disabled: the wrapper carries the
   visible state because the input itself is visually hidden. */
.file-button.disabled {
  cursor: not-allowed;
  color: var(--muted);
  background: var(--surface-2);
  border-color: var(--border);
  opacity: 0.65;
}

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

.panel.scan video {
  display: block;
  width: 100%;
  max-width: 28rem;
  margin: 0.4rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #000;
}

.panel.lookup {
  border-color: var(--accent-text);
}

.lookup-steps {
  list-style: none;
  margin: 0.2rem 0 0.6rem;
  padding: 0;
  font-size: 0.85rem;
}

.lookup-steps li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.6rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

.lookup-steps li:last-child {
  border-bottom: 0;
}

.lookup-service {
  font-weight: 600;
  color: var(--accent-text);
}

.lookup-status {
  color: var(--muted);
}

.lookup-fields,
.lookup-note {
  flex-basis: 100%;
  color: var(--muted);
}

.lookup-note {
  font-style: italic;
}


/* Nutrition-label report: the normalisation notes (scaling, kJ conversion,
   refused fields) and the replacement list stay secondary to the facts. */
.lookup-notes {
  margin: 0.2rem 0 0.6rem;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.lookup-notes li {
  margin: 0.15rem 0;
}
