/* ==========================================================================
   Interactive Cookbook (/healthy-recipes.html and /ar/healthy-recipes.html).

   Extends base.css, components.css, trust.css and calculator.css. The page is
   a normal long-form document first: every recipe, weight and nutrition table
   is in the raw HTML. The 3D book is presentation only -- the cover and the
   page turns are additive, and with JavaScript off the spreads read as a
   stack of cards (see the <noscript> block in the page).

   Mechanics follow docs/adr/0002: perspective 2000px, preserve-3d,
   backface-visibility hidden, a -15deg cover hover tilt and a
   rotateY(-180deg) turn on the ADR's cubic-bezier. The same tilt and turn are
   mirrored in RTL, where the spine sits on the right.
   ========================================================================== */

.recipes-page {
  --accent: #0f766e;
  --accent-ink: #0b5f57;
  --accent-soft: rgba(15, 118, 110, 0.10);
  --accent-ring: rgba(15, 118, 110, 0.30);
  background: var(--bg, #fbfcfb);
}

/* ------------------------------------------------------------------- hero */

.recipes-hero {
  padding: clamp(2.5rem, 6vw, 4.5rem) 0 clamp(1.75rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--line, #e5e7e5);
  background: linear-gradient(180deg, #eef7f3 0%, #fbfcfb 100%);
}

.recipes-hero h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.9rem, 5vw, 2.75rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-weight: 800;
  color: var(--ink, #14201d);
}

.recipes-hero h1 em {
  font-style: normal;
  color: var(--accent-ink);
}

.recipes-lede {
  margin: 0;
  max-width: 66ch;
  font-size: clamp(1.02rem, 2.2vw, 1.16rem);
  line-height: 1.6;
  color: var(--ink-2, #46564f);
}

.recipes-source {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.recipes-source .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.recipes-body {
  padding: clamp(1.75rem, 3vw, 2.5rem) 0 clamp(3rem, 6vw, 4.5rem);
}

.recipes-noscript,
.recipes-notice {
  margin: 0 0 1.75rem;
  padding: 0.9rem 1.1rem;
  max-width: 76ch;
  border: 1px solid var(--line-2, #cfe0d8);
  border-inline-start: 4px solid var(--accent);
  border-radius: var(--r-sm, 12px);
  background: var(--surface-2, #f6faf8);
  color: var(--ink-2, #42606f);
  font-size: 0.92rem;
  line-height: 1.55;
}

.recipes-noscript {
  margin-bottom: 1.5rem;
}

/* ------------------------------------------------------------------ book */

.cookbook {
  position: relative;
  perspective: 2000px;
  margin: 0 auto clamp(2rem, 4vw, 3rem);
}

.book3d {
  position: relative;
  transform-style: preserve-3d;
}

/* ---- closed cover ---- */

.book3d__cover {
  position: relative;
  display: block;
  width: min(400px, 82vw);
  margin-inline: auto;
  padding: 0;
  aspect-ratio: 3 / 4;
  border: 0;
  border-radius: 4px 14px 14px 4px;
  background: #0d2b26;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.18) inset,
    0 24px 60px -18px rgba(8, 32, 27, 0.55),
    0 4px 14px rgba(8, 32, 27, 0.25);
  cursor: pointer;
  overflow: hidden;
  transform-origin: left center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  transition:
    transform 0.9s cubic-bezier(0.645, 0.045, 0.355, 1),
    box-shadow 0.35s ease,
    opacity 0.9s ease;
}

[dir="rtl"] .book3d__cover {
  border-radius: 14px 4px 4px 14px;
  transform-origin: right center;
}

/* The spine: a narrow shaded strip on the bound edge. */
.book3d__cover::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 14px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.05));
  z-index: 2;
  pointer-events: none;
}

[dir="rtl"] .book3d__cover::before {
  background: linear-gradient(270deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.05));
}

.book3d__cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book3d__cover-copy {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 2.5rem 1.5rem 1.5rem;
  text-align: start;
  color: #fdfbf4;
  background: linear-gradient(0deg, rgba(6, 24, 20, 0.88) 12%, rgba(6, 24, 20, 0) 100%);
}

.book3d__kicker {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #bfe8da;
}

.book3d__title {
  font-size: clamp(1.35rem, 4.4vw, 1.7rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.015em;
}

.book3d__sub {
  font-size: 0.82rem;
  color: rgba(253, 251, 244, 0.78);
}

.book3d__open {
  align-self: flex-start;
  margin-top: 0.7rem;
  padding: 0.55rem 0.95rem;
  border: 1px solid rgba(253, 251, 244, 0.55);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Hover tilt: only the closed cover, and only where a pointer can hover. */
@media (hover: hover) and (pointer: fine) {
  .cookbook:not(.is-open) .book3d__cover:hover,
  .cookbook:not(.is-open) .book3d__cover:focus-visible {
    transform: rotateY(-15deg) rotateX(2deg) translateZ(8px);
    box-shadow:
      0 2px 0 rgba(255, 255, 255, 0.18) inset,
      0 34px 70px -20px rgba(8, 32, 27, 0.6),
      0 6px 18px rgba(8, 32, 27, 0.3);
  }

  [dir="rtl"] .cookbook:not(.is-open) .book3d__cover:hover,
  [dir="rtl"] .cookbook:not(.is-open) .book3d__cover:focus-visible {
    transform: rotateY(15deg) rotateX(2deg) translateZ(8px);
  }
}

/* Open state: the cover swings back and gets out of the way. */
.cookbook.is-open .book3d__cover {
  transform: rotateY(-180deg);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    transform 0.9s cubic-bezier(0.645, 0.045, 0.355, 1),
    opacity 0.9s ease,
    visibility 0s linear 0.9s;
}

[dir="rtl"] .cookbook.is-open .book3d__cover {
  transform: rotateY(180deg);
}

/* ---- stage and spreads ---- */

.book3d__stage {
  position: relative;
  transform-style: preserve-3d;
}

.book3d__stage:focus {
  outline: none;
}

.book3d__spreads {
  transform-style: preserve-3d;
}

.spread {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  background: var(--surface, #fff);
  border: 1px solid var(--line, #e1ede7);
  border-radius: var(--r-lg, 22px);
  box-shadow: var(--sh-lg, 0 28px 64px rgba(14, 42, 61, 0.11));
  transform-style: preserve-3d;
  transform-origin: left center;
}

[dir="rtl"] .spread {
  transform-origin: right center;
}

.spread[hidden] {
  display: none;
}

.spread.is-turning-next {
  animation: bookFlipNext 0.62s cubic-bezier(0.645, 0.045, 0.355, 1) both;
}

.spread.is-turning-prev {
  animation: bookFlipPrev 0.62s cubic-bezier(0.645, 0.045, 0.355, 1) both;
}

@keyframes bookFlipNext {
  from {
    opacity: 0.3;
    transform: rotateY(-68deg);
  }
  to {
    opacity: 1;
    transform: rotateY(0deg);
  }
}

@keyframes bookFlipPrev {
  from {
    opacity: 0.3;
    transform: rotateY(68deg);
  }
  to {
    opacity: 1;
    transform: rotateY(0deg);
  }
}

/* ---- left page: the dish ---- */

.page {
  min-width: 0;
}

.page--left {
  display: flex;
  flex-direction: column;
  background: var(--surface-2, #f6faf8);
  border-start-start-radius: var(--r-lg, 22px);
  border-end-start-radius: var(--r-lg, 22px);
  overflow: hidden;
}

.page__figure {
  margin: 0;
  background: var(--surface-3, #eff6f2);
}

.page__figure img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.page__meta {
  padding: 1.1rem 1.25rem 1.35rem;
}

.page__kcal {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.page__kcal b {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent-ink);
}

.page__facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0;
}

.page__facts dt {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.page__facts dd {
  margin: 0.15rem 0 0;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.page__facts dd span {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
}

/* ---- right page: the recipe ---- */

.page--right {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: clamp(1.25rem, 3vw, 2rem);
  border-inline-start: 1px solid var(--line, #e1ede7);
  border-start-end-radius: var(--r-lg, 22px);
  border-end-end-radius: var(--r-lg, 22px);
  box-shadow: inset 14px 0 22px -22px rgba(14, 42, 61, 0.5);
}

[dir="rtl"] .page--right {
  box-shadow: inset -14px 0 22px -22px rgba(14, 42, 61, 0.5);
}

.page__number {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-ink);
}

.page__title {
  margin: 0;
  font-size: clamp(1.2rem, 2.6vw, 1.5rem);
  line-height: 1.25;
  letter-spacing: -0.015em;
  font-weight: 800;
  color: var(--ink);
}

.page__title:focus-visible {
  outline: 3px solid var(--accent-ring);
  outline-offset: 3px;
  border-radius: 4px;
}

.page__summary {
  margin: 0;
  color: var(--ink-2);
  font-size: 0.92rem;
  line-height: 1.55;
}

.page__h {
  margin: 0.5rem 0 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.ing {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ing li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 0.75rem;
  align-items: baseline;
  padding-block-end: 0.55rem;
  border-block-end: 1px dashed var(--line, #e1ede7);
  font-size: 0.88rem;
}

.ing li:last-child {
  border-block-end: 0;
  padding-block-end: 0;
}

.ing__name {
  font-weight: 600;
  color: var(--ink);
}

.ing__amount {
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ing__record {
  grid-column: 1 / -1;
  margin-top: 0.15rem;
  font-size: 0.74rem;
  line-height: 1.45;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.ing__record a {
  color: var(--accent-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.steps {
  margin: 0;
  padding-inline-start: 1.15rem;
  display: grid;
  gap: 0.35rem;
}

.steps li {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink-2);
}

.steps li::marker {
  color: var(--accent);
  font-weight: 700;
}

.page__nutrition {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.page__nutrition caption {
  text-align: start;
}

.page__nutrition th,
.page__nutrition td {
  padding: 0.45rem 0.5rem;
  text-align: end;
  border-block-end: 1px solid var(--line, #e1ede7);
}

.page__nutrition thead th {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-block-end-color: var(--line-2, #cfe0d8);
}

.page__nutrition th:first-child {
  text-align: start;
  font-weight: 600;
  color: var(--ink);
}

.page__nutrition tbody tr:last-child th,
.page__nutrition tbody tr:last-child td {
  border-block-end: 0;
}

.page__unit {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
}

.page__note {
  margin: 0.35rem 0 0;
  padding: 0.7rem 0.85rem;
  border-radius: var(--r-xs, 8px);
  background: var(--surface-2, #f6faf8);
  color: var(--ink-2);
  font-size: 0.76rem;
  line-height: 1.5;
}

.page__load {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  align-self: flex-start;
  margin-top: 0.35rem;
  min-height: 44px;
  padding: 0.55rem 1.05rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.84rem;
  font-weight: 700;
  text-decoration: none;
  transition: background 0.2s ease;
}

.page__load:hover {
  background: var(--accent-ink);
}

.page__load svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

[dir="rtl"] .page__load svg {
  transform: scaleX(-1);
}

/* ---- controls ---- */

.book3d__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.1rem;
}

.book3d__btn {
  min-height: 44px;
  padding: 0.55rem 1rem;
  border: 1px solid var(--line-2, #cfe0d8);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.book3d__btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.book3d__btn--ghost {
  background: transparent;
  border-style: dashed;
  font-weight: 600;
  color: var(--ink-2);
}

.book3d__position {
  margin: 0;
  padding-inline: 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ narrow */

@media (max-width: 760px) {
  .book3d__cover {
    width: min(320px, 78vw);
  }

  .spread {
    grid-template-columns: minmax(0, 1fr);
  }

  .page--left {
    border-start-end-radius: var(--r-lg, 22px);
    border-end-start-radius: 0;
  }

  .page__figure img {
    aspect-ratio: 4 / 3;
  }

  .page--right {
    border-inline-start: 0;
    border-start-start-radius: 0;
    border-start-end-radius: 0;
    border-block-start: 1px solid var(--line, #e1ede7);
    box-shadow: none;
  }

  .book3d__controls {
    justify-content: center;
  }

  .book3d__position {
    flex-basis: 100%;
    text-align: center;
    order: -1;
    margin-bottom: 0.15rem;
  }
}

/* ------------------------------------------------------------ reduced motion */

@media (prefers-reduced-motion: reduce) {
  .book3d__cover {
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
  }

  .cookbook:not(.is-open) .book3d__cover:hover,
  .cookbook:not(.is-open) .book3d__cover:focus-visible {
    transform: none;
  }

  .spread.is-turning-next,
  .spread.is-turning-prev {
    animation: none;
  }
}
