/* Recipes, as koda's recipe extension renders them. */

@layer layout {
  /* Stack layout, as post.css gives articles and sections */
  :is(.recipe, .recipe section, .step-body, .ingredients) > * + * {
    margin-block-start: var(--flow-space, 1em);
  }

  /* Headings inside a recipe divide it into sections, but the recipe sits
     in the post column already, so its sections don't join the article grid */
  .recipe section {
    display: block;
  }

  .ingredients {
    --flow-space: var(--space-m);

    & + * {
      --flow-space: var(--space-m);
    }

    /* The space above sets the card apart; inside it, the title and
       each group's name sit close to what they head, and groups sit apart
       from each other */
    & > * {
      --flow-space: var(--space-3xs);
    }

    & > .heading + * {
      --flow-space: var(--space-2xs);
    }

    & > ul + .group {
      --flow-space: var(--space-s);
    }
  }

  .step {
    --flow-space: var(--space-m);
  }
}

@layer components {
  /* -- Serves, makes, equipment -- */
  .recipe-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2xs) var(--space-l);

    & dt {
      color: var(--theme-foreground-alt);
      font-size: var(--step--1);
      font-weight: bold;
      letter-spacing: 0.06em;
      text-transform: uppercase;
    }

    & dd {
      margin: 0;
    }
  }

  /* -- Ingredient lists -- */
  .ingredients {
    background-color: var(--theme-background-alt);
    border-radius: 0.25rem;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    padding: var(--space-s) var(--space-m);

    & .heading {
      font-family: var(--font-display);
      font-size: var(--step-1);
      font-weight: bold;
    }

    & .group {
      color: var(--theme-accent);
      font-family: var(--font-display);
      font-weight: bold;
    }

    & ul {
      list-style: none;
      padding-inline-start: 0;
    }

    & li {
      --flow-space: 0;
      break-inside: avoid;
      padding-block: var(--space-3xs);
      /* Wrapped lines start under the text, not under the checkbox */
      padding-inline-start: 1.3em;
      text-indent: -1.3em;
    }

    & li.optional {
      color: var(--theme-foreground-alt);
    }

    /* Ticking a line off greys it out, so what's left to gather stands out */
    & label {
      cursor: pointer;
    }

    & input[type="checkbox"] {
      accent-color: var(--theme-accent);
      margin: 0 0.4em 0 0;
      vertical-align: -0.1em;
    }

    & li:has(:checked) label {
      color: var(--theme-foreground-dim);
      text-decoration: line-through;
    }

    /* On its own line, under the ingredient's text */
    & .uses {
      display: block;
      color: var(--theme-foreground-dim);
      font-size: var(--step--1);
      text-indent: 0;

      & a {
        color: inherit;
      }
    }

    & .quantity {
      font-variant-numeric: tabular-nums;
      font-weight: 600;
    }

    & :is(.equivalent, .prep, .optional-marker) {
      color: var(--theme-foreground-alt);
    }
  }

  /* -- Steps -- */
  .step {
    border-left: 2px solid var(--theme-border);
    padding-inline-start: var(--space-s);
    scroll-margin-block-start: var(--space-l);

    &.optional {
      border-left-style: dashed;

      & .step-number::after {
        content: " · optional";
        color: var(--theme-foreground-dim);
      }
    }

    &:target {
      border-left-color: var(--theme-accent);
    }
  }

  .step-number {
    display: block;
    color: var(--theme-accent);
    font-size: var(--step--1);
    font-variant-numeric: tabular-nums;
    font-weight: bold;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .step-body {
    margin-block-start: var(--space-3xs);
  }

  /* A substep sits in its step's text, with a lighter rule */
  .step.substep {
    border-left-width: 1px;
  }

  /* Text between steps lines up with the steps' text */
  :is(.recipe, .recipe section) > p {
    color: var(--theme-foreground-alt);
    padding-inline-start: calc(2px + var(--space-s));
  }

  /* -- In step text -- */
  :is(.ingredient, .cookware) {
    text-decoration: underline dotted var(--theme-foreground-dim);
    text-underline-offset: 0.2em;

    & .quantity {
      font-variant-numeric: tabular-nums;
      font-weight: 600;
    }

    & .equivalent {
      color: var(--theme-foreground-alt);
    }
  }

  .ingredient.optional {
    text-decoration-style: dashed;
  }

  .temperature {
    white-space: nowrap;

    & .quantity {
      font-variant-numeric: tabular-nums;
      font-weight: 600;
    }

    & .equivalent {
      color: var(--theme-foreground-alt);
    }
  }

  .timer {
    background-color: var(--theme-background-alt);
    border: 1px solid var(--theme-border);
    border-radius: 0.25em;
    font-variant-numeric: tabular-nums;
    padding-inline: 0.3em;
    white-space: nowrap;
  }
}

/* A printed recipe is the recipe: light on white whatever the theme, no
   site chrome, empty tick boxes, and no step or heading split from what
   follows it. The theme toggles sit outside the layers, as theme.css does. */
@media print {
  :root:has(.recipe),
  :root[data-theme]:has(.recipe) {
    color-scheme: light;
    --theme-light: initial;
    --theme-dark: ;
  }

  @layer components {
    body:has(.recipe) :is(.navbar, #scroll-to-top) {
      display: none;
    }

    .ingredients {
      background: none;
      border: 1px solid var(--theme-border);
      box-shadow: none;

      /* Paper is wider than the screen column and costs more to scroll */
      & ul {
        columns: 2 14rem;
        column-gap: var(--space-l);
      }
    }

    .ingredients li:has(:checked) label {
      color: inherit;
      text-decoration: none;
    }

    .step,
    .recipe-meta {
      break-inside: avoid;
    }

    :is(.recipe h2, .recipe h3, .ingredients .group, .step-number) {
      break-after: avoid;
    }

    .recipe p {
      orphans: 2;
      widows: 2;
    }

    .ingredients .uses a,
    .step-number {
      color: inherit;
    }
  }
}
