/*
 * Calculators (/tools/), the recipe page's pan sheet and portion scale, the «Расчёты»
 * block in search results. Mobile first; every control is at least 48 px tall.
 * Colours come from the site.css design tokens (--ink, --line ...), so the dark theme
 * applies here too; the fallbacks are the approved mockup's light values.
 */
.tools-page,
.tool,
.tool-sheet,
.recipe-scale,
.recipe-pan-note,
.recipe-scale-banner,
.tools-search-hits {
  --t-accent: var(--a-accent, var(--accent, #d62839));
  --t-accent-deep: var(--a-accent-deep, var(--accent-deep, #be122c));
  --t-accent-soft: var(--a-accent-soft, var(--accent-soft, #fff1f2));
  --t-surface: var(--a-surface, var(--surface, #ffffff));
  --t-ink: var(--a-ink, var(--ink, #111827));
  --t-muted: var(--a-muted, var(--muted, #5b616b));
  --t-line: var(--a-line, var(--line, #e5e7eb));
  --t-field: var(--a-field, var(--field, #868b94));
  --t-error: var(--a-error, var(--accent-deep, #b42318));
  --t-radius: 18px;
}

.tool [hidden],
.tool-sheet [hidden],
.recipe-scale[hidden],
.recipe-scale-banner[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------------ pages */
.tools-page {
  display: grid;
  gap: 16px;
  max-width: 1040px;
  margin: 8px auto 0;
  color: var(--t-ink);
}

.tools-head h1 {
  margin: 0 0 6px;
  font-size: clamp(28px, 7vw, 42px);
  line-height: 1.08;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.tools-lead {
  margin: 0;
  max-width: 60ch;
  color: var(--t-muted);
  font-size: 16px;
  line-height: 1.5;
}

.tools-grid {
  display: grid;
  gap: 16px;
  align-items: start;
}

@media (min-width: 900px) {
  .tools-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.tool-card {
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 16px;
  border-radius: var(--t-radius);
  background: var(--t-surface);
  box-shadow: inset 0 0 0 1px var(--t-line);
}

.tool-card__title {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.tool-card__more,
.tools-other a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-self: start;
  min-height: 48px;
  color: var(--t-accent-deep);
  font-weight: 700;
  text-decoration: none;
}

.tools-text {
  max-width: 70ch;
  line-height: 1.6;
}

.tools-text h2 {
  margin: 8px 0;
  font-size: 22px;
}

.tools-text ul {
  margin: 0;
  padding-inline-start: 20px;
  display: grid;
  gap: 8px;
}

.tools-other {
  margin: 0;
}

/* ------------------------------------------------------------------ calculator */
.tool {
  display: grid;
  gap: 14px;
  min-width: 0;
  margin: 0;
  color: var(--t-ink);
}

.tool-units {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}

.tool-units__label {
  color: var(--t-muted);
  font-size: 14px;
  font-weight: 600;
}

.tool-seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--t-accent-soft);
}

.tool-seg button,
.recipe-scale button {
  min-width: 48px;
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--t-ink);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.tool-seg button[aria-pressed="true"],
.recipe-scale button[aria-pressed="true"] {
  background: var(--t-surface);
  color: var(--t-accent-deep);
  box-shadow: 0 1px 4px rgba(20, 10, 15, 0.16);
}

.tool-set {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.tool-set legend {
  margin-bottom: 6px;
  padding: 0;
  font-size: 15px;
  font-weight: 800;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

/* Shape select a bit wider than the size field; a rectangle puts the select on its own row. */
.tool-set[data-shape] .tool-grid {
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
}

.tool-set[data-shape="rect"] .tool-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tool-set[data-shape="rect"] .tool-field--shape,
.tool-field--wide {
  grid-column: 1 / -1;
}

.tool-field {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
}

/* Label, field and error of neighbours share rows: a label that wraps to two lines (e.g.
   Arabic) does not push its field lower than the one next to it. */
@supports (grid-template-rows: subgrid) {
  .tool-field {
    grid-row: span 3;
    grid-template-rows: subgrid;
    row-gap: 4px;
  }

  .tool-field label {
    align-self: end;
  }
}

.tool-field label {
  color: var(--t-muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.tool-field input,
.tool-field select {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 0 12px;
  border: 1.5px solid var(--t-field);
  border-radius: 12px;
  background: var(--t-surface);
  color: var(--t-ink);
  font: inherit;
  /* 16px+ keeps iOS from zooming into the field */
  font-size: 17px;
  font-weight: 700;
}

.tool-field select {
  font-size: 16px;
  font-weight: 600;
  text-overflow: ellipsis;
}

.tool-field input:focus-visible,
.tool-field select:focus-visible,
.tool-seg button:focus-visible,
.recipe-scale button:focus-visible,
.tool-btn:focus-visible,
.tool-more summary:focus-visible,
.tool-sheet__close:focus-visible,
.recipe-scale-banner button:focus-visible {
  outline: 3px solid var(--t-accent);
  outline-offset: 2px;
}

.tool-field input[aria-invalid="true"] {
  border-color: var(--t-error);
}

.tool-error {
  color: var(--t-error);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

/* Fields for another shape / powder: hidden only when JavaScript drives the form. */
.tool-js [data-off] {
  display: none;
}

.tool-more summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  color: var(--t-accent-deep);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

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

.tool-more summary::after {
  content: "";
  width: 8px;
  height: 8px;
  /* physical sides: a down chevron in both directions */
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 150ms ease;
}

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

.tool-hint {
  margin: 0 0 10px;
  color: var(--t-muted);
  font-size: 14px;
  line-height: 1.45;
}

.tool-result {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--t-accent-soft);
  font-size: 14px;
  line-height: 1.4;
}

.tool-result__main {
  color: var(--t-accent-deep);
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}

.tool-result__prompt {
  color: var(--t-muted);
  font-weight: 600;
}

.tool-warn {
  margin: 0;
  color: var(--t-muted);
  font-size: 13px;
  line-height: 1.45;
}

.tool-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  max-width: 100%;
  padding: 8px 18px;
  border: 1.5px solid var(--t-line);
  border-radius: 999px;
  background: var(--t-surface);
  color: var(--t-ink);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.tool-btn--primary {
  border-color: var(--t-accent);
  background: var(--t-accent);
  color: #fff;
}

.tool-btn--block {
  width: 100%;
}

.tool-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Without JavaScript the form is sent with this button; it is the first submit button in
   the markup (the one Enter uses) but shown after the fields. */
.tool-submit {
  order: 99;
  justify-self: start;
}

.tool-js .tool-submit {
  display: none;
}

/* ------------------------------------------------------------------ recipe page */
.recipe-scale {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: -8px 0 12px;
}

.recipe-scale__label {
  color: var(--t-muted);
  font-size: 14px;
  font-weight: 600;
}

.recipe-scale .tool-seg {
  background: var(--t-accent-soft);
}

.recipe-pan-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 12px;
  margin: 0 0 12px;
  color: var(--t-ink);
  font-size: 15px;
  line-height: 1.5;
}

.recipe-pan-note a {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  color: var(--t-accent-deep);
  font-weight: 700;
}

.recipe-scale-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin: 0 0 12px;
  padding: 6px 6px 6px 14px;
  padding-inline: 14px 6px;
  border-radius: 12px;
  background: var(--t-accent-soft);
  color: var(--t-accent-deep);
  font-weight: 700;
}

.recipe-scale-banner button {
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--t-surface);
  color: var(--t-accent-deep);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.recipe-scale-banner__note {
  flex-basis: 100%;
  color: var(--t-muted);
  font-size: 13px;
  font-weight: 600;
}

.recipe-scale-note {
  margin: 0 0 12px;
  color: var(--a-muted, var(--muted, #5b616b));
  font-size: 14px;
  line-height: 1.45;
}

.recipe-section--ingredients.is-scaled .ing-q {
  color: var(--a-accent-deep, var(--accent-deep, #be122c));
  font-weight: 700;
}

/* US cups are computed for the original amounts: hidden while the recipe is scaled. */
.recipe-section--ingredients.is-scaled .ingredient-us,
.recipe-section--ingredients.is-scaled .ingredient-us-note {
  display: none;
}

/* Bottom sheet on phones, a centred dialog on wide screens. */
.tool-sheet {
  width: 100%;
  max-width: 560px;
  max-height: min(92dvh, 820px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--t-surface);
  color: var(--t-ink);
  box-shadow: 0 -12px 40px rgba(20, 10, 15, 0.25);
}

.tool-sheet::backdrop {
  background: rgba(20, 10, 15, 0.45);
}

.tool-sheet__inner {
  display: grid;
  gap: 12px;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}

.tool-sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tool-sheet__head h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.tool-sheet__close {
  flex: none;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 999px;
  background: var(--t-accent-soft);
  color: var(--t-ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

html:has(.tool-sheet[open]) {
  overflow: hidden;
}

@media (min-width: 700px) {
  .tool-sheet {
    margin: auto;
    border-radius: 20px;
  }
}

/* ------------------------------------------------------------------ search results */
.tools-search-hits {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
  padding: 14px 16px;
  border-radius: var(--t-radius);
  background: var(--t-accent-soft);
}

.tools-search-hits h2 {
  margin: 0;
  color: var(--t-accent-deep);
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tools-search-hits a {
  display: grid;
  gap: 2px;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--t-surface);
  color: var(--t-ink);
  text-decoration: none;
}

.tools-search-hits a b {
  font-size: 16px;
}

.tools-search-hits a span {
  color: var(--t-muted);
  font-size: 14px;
}
