/*
 * Recipe page only (templates/recipes/detail.html; loaded after site.css and tools.css):
 * the action row (Save · Share · Print), «Готовить по шагам», the thin sticky bar, ingredient
 * check-off, «Не выключать экран» and cooking mode. Paper: recipe_print.css.
 * Site tokens only; logical properties (Arabic is right-to-left).
 */

:root {
  /* Thin sticky bar: 48 px controls + 2 × 4 px padding + 1 px line. */
  --cook-bar-h: 57px;
}

.recipe-actions [hidden],
.recipe-cook-bar[hidden],
.recipe-wake[hidden],
.ingredient-check-bar [hidden],
.ingredient-check-bar[hidden],
.cook [hidden] {
  display: none !important;
}

/* ---------- Sticky UI budget ----------
   Phones: the header scrolls away on this page (the section links are not sticky either), so
   while reading only the thin bar (57 px) and the tab bar (61 px) stay: 118 px.
   Computers (no tab bar): the header and the thin bar under it. */
html:has(.recipe-cook-bar) {
  scroll-padding-top: calc(var(--sticky-top) + var(--cook-bar-h) + var(--space-2));
}

@media (max-width: 860px) {
  html:has(.recipe-cook-bar) .topbar {
    position: relative;
    top: auto;
  }

  html:has(.recipe-cook-bar) {
    scroll-padding-top: calc(var(--cook-bar-h) + var(--space-2));
  }
}

/* ---------- Action row: three equal buttons, icon above the label (mockup .actions) ---------- */
.recipe-actions {
  display: grid;
  gap: var(--space-3);
}

.recipe-action-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.recipe-actions .recipe-detail-like-form {
  display: grid;
  margin: 0;
}

.recipe-act {
  appearance: none;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  width: 100%;
  min-height: 56px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.recipe-act__icon {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 24px;
}

.recipe-act__count {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
}

/* One line per label (shortened per language where needed); never hyphenated. */
.recipe-act__label {
  max-width: 100%;
  hyphens: manual;
  overflow-wrap: anywhere;
}

.recipe-act.is-active,
.recipe-cook-bar__save.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.recipe-act.is-active .icon,
.recipe-cook-bar__save.is-active .icon {
  fill: currentColor;
}

.recipe-act:disabled,
.recipe-cook-bar__save:disabled {
  cursor: progress;
}

@media (hover: hover) {
  .recipe-act:hover,
  .recipe-cook-bar__save:hover {
    border-color: var(--field);
    background: var(--surface-2);
  }

  .recipe-act.is-active:hover,
  .recipe-cook-bar__save.is-active:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
  }
}

.recipe-actions .recipe-like-note {
  margin: 0;
}

.recipe-cook-start {
  width: 100%;
}

@media (min-width: 861px) {
  .recipe-actions {
    max-width: 480px;
  }
}

/* Narrow phones: room for «Поделиться» / «Compartilhar» on one line at 320 px. */
@media (max-width: 400px) {
  .recipe-detail-hero__body {
    padding-inline: var(--space-3);
  }

  .recipe-action-row {
    gap: 6px;
  }

  .recipe-act {
    padding-inline: 2px;
  }
}

/* ---------- Thin sticky bar (after the action row scrolls away) ---------- */
.recipe-cook-bar {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--cook-bar-h);
  padding-block: calc(4px + env(safe-area-inset-top, 0px)) 4px;
  padding-inline: calc(var(--space-3) + max(var(--safe-left), var(--safe-right)));
  border-block-end: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  transform: translateY(-100%);
  visibility: hidden;
  transition: transform 180ms ease, visibility 0s linear 180ms;
}

.recipe-cook-bar.is-visible {
  transform: none;
  visibility: visible;
  transition: transform 180ms ease;
}

.recipe-cook-bar__title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recipe-cook-bar__save {
  appearance: none;
  flex: none;
  display: grid;
  place-items: center;
  width: var(--target);
  height: var(--target);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.recipe-cook-bar__cook {
  flex: none;
  padding-inline: var(--space-4);
  white-space: nowrap;
}

@media (min-width: 861px) {
  /* Under the sticky header, as wide as the page. */
  .recipe-cook-bar {
    inset-block-start: var(--sticky-top);
    width: min(1080px, 100% - 28px);
    margin-inline: auto;
    padding-inline: var(--space-4) var(--space-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transform: translateY(-8px);
    opacity: 0;
    transition: transform 180ms ease, opacity 180ms ease, visibility 0s linear 180ms;
  }

  .recipe-cook-bar.is-visible {
    opacity: 1;
    transition: transform 180ms ease, opacity 180ms ease;
  }

  .recipe-cook-bar__title {
    font-size: var(--fs-md);
  }
}

@media (prefers-reduced-motion: reduce) {
  .recipe-cook-bar,
  .recipe-cook-bar.is-visible {
    transition: none;
  }
}

/* ---------- «Не выключать экран» (mockup .wake) ---------- */
.recipe-wake {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--target);
  margin: 0 0 var(--space-4);
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1.3;
  text-align: start;
  cursor: pointer;
}

.recipe-wake__switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--field);
  transition: background-color 150ms ease;
}

.recipe-wake__switch::after {
  content: "";
  position: absolute;
  inset-block-start: 3px;
  inset-inline-start: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--on-scrim);
  box-shadow: var(--shadow-sm);
  transition: inset-inline-start 150ms ease;
}

.recipe-wake[aria-checked="true"] .recipe-wake__switch {
  background: var(--ok);
}

.recipe-wake[aria-checked="true"] .recipe-wake__switch::after {
  inset-inline-start: 21px;
}

/* ---------- Ingredient sections: a small heading above each section's lines (not a checkable line) ---------- */
.ingredient-group__title {
  margin: var(--space-4) 0 0;
  padding-block: var(--space-1);
  padding-inline: var(--space-2) 0;
  border-inline-start: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--ink);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.ingredient-group__title:first-child {
  margin-block-start: var(--space-2);
}

/* ---------- Ingredient check-off: a round box before each line, struck through when done ---------- */
.ingredient-list li.is-checkable {
  padding: 0;
}

.ingredient-check {
  appearance: none;
  display: block;
  width: 100%;
  min-height: var(--target);
  margin: 0;
  padding-block: 15px;
  padding-inline: 32px 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  line-height: inherit;
  text-align: start;
  cursor: pointer;
}

.ingredient-check:focus-visible {
  outline-offset: -3px;
  border-radius: var(--radius-sm);
}

.ingredient-list li.is-checkable::before {
  top: calc(15px + 0.81em - 10px);
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--field);
  background: transparent;
  pointer-events: none;
}

.ingredient-list li.is-checked::before {
  border-color: var(--ok);
  background: var(--ok);
}

.ingredient-list li.is-checked::after {
  content: "";
  position: absolute;
  top: calc(15px + 0.81em - 6px);
  inset-inline-start: 7px;
  width: 6px;
  height: 11px;
  border: solid var(--surface);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  pointer-events: none;
}

.ingredient-list li.is-checked .ingredient-check {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.ingredient-list li.is-checked .ing-q {
  color: inherit;
}

.ingredient-check-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 var(--space-3);
  min-height: var(--target);
  margin: var(--space-1) 0 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.4;
}

.ingredient-check-bar__reset {
  appearance: none;
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  margin-inline-end: calc(-1 * var(--space-2));
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--accent-deep);
  font: inherit;
  font-weight: var(--fw-bold);
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
}

/* ---------- Cooking mode: full screen, one step at a time ---------- */
html.is-cooking {
  overflow: hidden;
}

.cook {
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: contain;
}

.cook::backdrop {
  background: var(--bg);
}

.cook__inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 760px;
  margin-inline: auto;
  padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px);
  padding-inline: max(var(--safe-left), var(--safe-right));
}

.cook__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
}

.cook__close {
  appearance: none;
  flex: none;
  display: grid;
  place-items: center;
  width: var(--target);
  height: var(--target);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.cook__heading {
  flex: 1;
  min-width: 0;
}

.cook__title {
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cook__progress {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.cook__meter {
  position: relative;
  height: 4px;
  margin-inline: var(--space-4);
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}

.cook__meter span {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 200ms ease;
}

.cook__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-5) var(--space-4);
}

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

.cook-step {
  display: grid;
  gap: var(--space-4);
}

.cook-step:focus {
  outline: none;
}

.cook-step:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 6px;
  border-radius: var(--radius-sm);
}

.cook-step__section {
  margin: 0;
  color: var(--accent-deep);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  letter-spacing: 0.06em;
  line-height: 1.3;
  text-transform: uppercase;
}

.cook-step__text {
  margin: 0;
  font-size: var(--fs-xl);
  line-height: 1.5;
  overflow-wrap: break-word;
}

.cook-timer {
  appearance: none;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--target);
  padding: 0 var(--space-4);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-family: inherit;
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.cook-timer[data-state="running"] {
  background: var(--surface);
}

.cook-timer[data-state="done"] {
  border-color: var(--wait);
  background: var(--wait-soft);
  color: var(--wait);
}

.cook-step__photos {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}

.cook-step__photos > picture {
  flex: 0 0 min(80%, 360px);
  scroll-snap-align: start;
}

.cook-step__photos > picture:only-child {
  flex-basis: min(100%, 420px);
}

.cook-step__photos img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 45vh;
  border-radius: var(--radius-md);
  object-fit: cover;
}

.cook__ings {
  border-block-start: 1px solid var(--line);
  background: var(--surface);
}

.cook__ings-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--target);
  padding: 0 var(--space-4);
  font-weight: var(--fw-bold);
  list-style: none;
  cursor: pointer;
}

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

.cook__ings-summary::after {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  margin-inline-start: auto;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: translateY(-2px) rotate(45deg);
}

.cook__ings[open] .cook__ings-summary::after {
  transform: translateY(2px) rotate(-135deg);
}

.cook__ings-section {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-weight: var(--fw-semibold);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cook__ings-section:not(:empty)::before {
  content: "· ";
}

.cook__ings-body {
  max-height: 40vh;
  max-height: 40dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--space-4) var(--space-3);
}

.cook__ings-list li {
  font-size: var(--fs-md);
}

.cook__ings-body .recipe-scale-note {
  margin: var(--space-2) 0 0;
}

/* Scaled (½× / 2× / another pan): the same highlight as on the page; US cups are for 1×. */
html:has(.recipe-section--ingredients.is-scaled) .cook .ing-q {
  color: var(--accent-deep);
  font-weight: var(--fw-bold);
}

html:has(.recipe-section--ingredients.is-scaled) .cook .u-us-q {
  color: var(--accent-deep);
  font-weight: var(--fw-bold);
}

.cook__nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-block-start: 1px solid var(--line);
  background: var(--surface);
}

.cook__nav .btn {
  gap: var(--space-1);
  min-height: 56px;
  padding-inline: var(--space-3);
  overflow-wrap: normal;
}

.cook__prev[aria-disabled="true"] {
  opacity: 0.45;
  cursor: default;
}

.cook__next.is-finish .icon {
  display: none;
}

@media (min-width: 861px) {
  .cook__body {
    padding: var(--space-7) var(--space-6);
  }

  .cook-step__text {
    font-size: var(--fs-2xl);
  }

  .cook__head,
  .cook__ings-summary,
  .cook__ings-body,
  .cook__nav {
    padding-inline: var(--space-6);
  }

  .cook__meter {
    margin-inline: var(--space-6);
  }
}

/* ---------- Screen only ---------- */
.recipe-print-source {
  display: none;
}

/* «Что такое масса нуаз? → статья» under the ingredients (templates/recipes/_article_links.html). */
.recipe-article-links {
  display: grid;
  gap: var(--space-2);
}

.recipe-article-link {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--target);
  padding: var(--space-3) var(--space-4);
  border: 1px solid color-mix(in srgb, var(--ok) 30%, var(--line));
  border-radius: var(--radius-md);
  background: var(--ok-soft);
  color: var(--ink);
  text-decoration: none;
}

.recipe-article-link__label {
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--ok);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
}

.recipe-article-link__text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.recipe-article-link__question {
  font-weight: var(--fw-bold);
  overflow-wrap: anywhere;
}

.recipe-article-link__title {
  color: var(--muted);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.recipe-article-link__arrow {
  color: var(--ok);
  font-size: var(--fs-xl);
}

@media (hover: hover) {
  .recipe-article-link:hover .recipe-article-link__question {
    color: var(--accent-deep);
  }
}

.recipe-article-link:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- Units switch: grams · °C or cups · °F (apps/recipes/units.py) ----------
   Both sets are in the page: «<u-us>1 cup (</u-us><u-mq>200 g</u-mq><u-us>)</u-us>».
   The recipe containers carry .units-us / .units-metric from the server (no flash, no JS);
   static/js/units_boot.js and the switch set <html data-units>, which wins. Print follows it. */
.u-us,
.u-us-block {
  display: none;
}

.units-us .u-us,
html[data-units="us"] .u-us {
  display: inline;
}

.units-us .u-us-block,
html[data-units="us"] .u-us-block {
  display: block;
}

.units-us .u-m,
html[data-units="us"] .u-m,
html[data-units="metric"] .u-us,
html[data-units="metric"] .u-us-block {
  display: none;
}

html[data-units="metric"] .u-m {
  display: inline;
}

/* In US units the grams in brackets are the secondary value: muted, kept on one line. */
.u-par,
.units-us .u-mq,
html[data-units="us"] .u-mq {
  color: var(--muted);
}

.units-us .u-mq,
html[data-units="us"] .u-mq {
  white-space: nowrap;
}

html[data-units="metric"] .u-mq {
  color: inherit;
  white-space: normal;
}

.units-switch {
  margin: 0 0 var(--space-3);
}

/* «Порции ½× 1× 2×» and the units switch share a row where they fit, else wrap. */
.recipe-ing-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  margin: -8px 0 var(--space-3);
}

.recipe-ing-controls > .recipe-scale,
.recipe-ing-controls > .units-switch {
  margin: 0;
}

.units-switch__set {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.units-switch__seg {
  display: inline-flex;
  flex-wrap: wrap;
  max-width: 100%;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
}

.units-switch__opt {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  color: var(--ink);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  unicode-bidi: isolate;
}

/* The radio stays in the accessibility tree and takes the clicks of its label. */
.units-switch__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

/* The chosen option follows the page's units (right before any script runs). */
.units-metric .units-switch__opt--metric,
.units-us .units-switch__opt--us,
html[data-units="metric"] .units-switch__opt--metric,
html[data-units="us"] .units-switch__opt--us {
  background: var(--surface);
  color: var(--accent-deep);
  box-shadow: var(--shadow-sm);
}

html[data-units="metric"] .units-switch__opt--us,
html[data-units="us"] .units-switch__opt--metric {
  background: transparent;
  color: var(--ink);
  box-shadow: none;
}

.units-switch__opt:has(.units-switch__input:focus-visible) {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.units-switch__apply {
  min-height: 44px;
  margin-inline-start: var(--space-2);
  padding: 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: var(--fw-bold);
}

.cook__ings-body .units-switch {
  margin: 0 0 var(--space-2);
}
