@layer reset, base, layout, components, pages, utilities;

/*
 * The recipe page. Its layout follows the width of the content area, not the
 * window, so it works beside the sidebar on a laptop or an iPad as well as
 * on a phone: one column when narrow, a compact header beside a small photo
 * from 560px, and the full two-column page from 860px.
 */
@layer pages {
  .recipe-page { container: recipe / inline-size; display: flex; flex-direction: column; gap: 28px; min-width: 0; }

  /* Working on a cookbook ------------------------------------------------ */

  .working-on {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 10px 12px 10px 16px;
    border-radius: 14px;
    background: var(--ink);
    color: var(--bg);
  }
  .working-on .mini-cover { width: 26px; height: 34px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .2); }
  .working-on__text { flex: 1 1 220px; min-width: 0; }
  .working-on__see {
    padding: 0;
    border: 0;
    background: none;
    color: #F3C3AE;
    font: 600 15px var(--sans);
    cursor: pointer;
  }
  .working-on__see:hover { text-decoration: underline; }
  .working-on__back { background: var(--bg); border-color: var(--bg); }

  /* Header: photo, title, facts and actions ------------------------------ */

  .recipe-hero { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: start; }
  .recipe-hero__info { display: flex; flex-direction: column; gap: 16px; padding: 0; min-width: 0; }
  .recipe-title { font-size: 32px; line-height: 1.08; overflow-wrap: break-word; }
  .recipe-description { font-size: 16px; }

  .recipe-page .gallery__main { position: relative; height: auto; aspect-ratio: 4 / 3; }
  .recipe-page .gallery__slide .media { height: 100%; }
  .recipe-page .gallery__thumbs { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
  .recipe-page .gallery__thumb { height: 52px; border-radius: 10px; }

  .recipe-page .stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); }
  .recipe-page .stat-row > div, .recipe-page .stat-row > div:first-child { padding: 10px 0 10px 12px; border-left: 1px solid var(--rule); }
  .recipe-page .stat-row > div:first-child { border-left: 0; padding-left: 0; }
  .recipe-page .stat-row__made { display: none; }

  /* The Photos menu sits on the photo. */
  .photo-menu { position: absolute; right: 12px; bottom: 12px; z-index: 2; }
  .photo-menu__button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 40px;
    padding: 0 12px;
    border-radius: 12px;
    background: rgba(255, 253, 248, .96);
    color: var(--ink);
    font: 600 14px var(--sans);
    box-shadow: 0 2px 8px rgba(35, 30, 25, .18);
    cursor: pointer;
  }
  .photo-menu .menu__items { top: auto; bottom: calc(100% + 6px); min-width: 240px; }
  .menu__items .menu__file, .menu__items button { display: flex; align-items: center; gap: 10px; }
  .menu__file {
    padding: 10px 12px;
    border-radius: 8px;
    font: 500 14px var(--sans);
    cursor: pointer;
  }
  .menu__file:hover, .menu__file:focus-within { background: var(--sunken); }
  .menu__items .menu__danger { color: var(--accent-ink); }

  /* Actions: Start cooking, then a row of labelled buttons. On a narrow
     screen they become a grid of icons with short labels. */
  .recipe-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
  .recipe-actions__cook { width: 100%; }
  .recipe-actions__more { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .recipe-actions__more > form, .dialog-wrap { display: contents; }
  .recipe-action {
    flex-direction: column;
    gap: 2px;
    min-height: 60px;
    width: 100%;
    padding: 6px 4px;
    font-size: 12px;
    white-space: normal;
  }
  .recipe-action__menu { display: flex; }
  .recipe-action__menu > summary { flex-grow: 1; }
  .recipe-action__long { display: none; }
  .recipe-action__short { display: inline; }

  /* Ingredients and method ---------------------------------------------- */

  .recipe-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; align-items: start; }
  .ingredients-panel { position: static; }
  .ingredient-list label { align-items: center; gap: 12px; width: 100%; }
  .ingredient-list__text { flex-grow: 1; min-width: 0; }
  .ingredient-list__amount { min-width: 0; margin-right: 4px; font-weight: 700; }
  .ingredient-tick {
    appearance: none;
    width: 24px;
    height: 24px;
    margin: 0;
    flex-shrink: 0;
    border: 1.5px solid var(--dashed);
    border-radius: 50%;
    background: var(--surface) center / 14px no-repeat;
    cursor: pointer;
  }
  .ingredient-tick:checked {
    border-color: var(--green);
    background-color: var(--green);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5 9-10'/%3E%3C/svg%3E");
  }
  .ingredient-tick:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
  .ingredient-list li:has(.ingredient-tick:checked) .ingredient-list__text { text-decoration: line-through; color: var(--faint); }
  .ingredient-list__hint { font-size: 13px; color: var(--muted); }

  /* About this recipe, under the method ----------------------------------- */

  .recipe-about { display: flex; flex-direction: column; gap: 16px; padding-top: 24px; border-top: 1px solid var(--rule); }
  .recipe-about__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; align-items: start; }
  .recipe-about__part { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
  .eyebrow-label { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
  .recipe-tags { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; gap: 6px; }

  .recipe-about .source-box { flex-wrap: wrap; }
  .recipe-about .source-box__text { flex: 1 1 160px; }

  .in-book {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
  }
  .in-book + .in-book { margin-top: -2px; }
  .in-book--empty { background: none; border: 1.5px dashed var(--border-strong); }
  .in-book .mini-cover { width: 30px; height: 39px; }
  .in-book__text { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; font-size: 13px; }
  .in-book__title { font-size: 15px; font-weight: 700; color: var(--ink); text-decoration: none; }
  .in-book__title:hover { text-decoration: underline; }
  .in-book__status { color: var(--accent-ink); }

  /* Compact: a small photo beside the header, ingredients and method side by side. */
  @container recipe (min-width: 560px) {
    .recipe-hero { grid-template-columns: 200px minmax(0, 1fr); gap: 22px; }
    .recipe-title { font-size: 34px; }
    .recipe-page .stat-row__made { display: flex; }
    .recipe-page .gallery__main { aspect-ratio: 1; border-radius: var(--radius-lg); }
    .recipe-page .gallery__caption { display: none; }
    .photo-menu { right: 8px; bottom: 8px; }
    .photo-menu__button { height: 34px; padding: 0 10px; font-size: 13px; }
    .recipe-actions { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
    .recipe-actions__cook { width: auto; }
    .recipe-actions__more { display: flex; flex-wrap: wrap; gap: 8px; }
    .recipe-action { flex-direction: row; gap: 8px; min-height: 44px; width: auto; padding: 0 14px; font-size: 14px; white-space: nowrap; }
    .recipe-action__short { display: none; }
    .recipe-action__long { display: inline; }
    .recipe-body { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 26px; }
  }

  /* Full: the large photo beside the title. */
  @container recipe (min-width: 860px) {
    .recipe-hero { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 40px; }
    .recipe-title { font-size: 46px; }
    .recipe-description { font-size: 17px; }
    .recipe-page .gallery__main { aspect-ratio: 4 / 3; border-radius: var(--radius-xl); }
    .recipe-page .gallery__caption { display: flex; }
    .recipe-page .gallery__thumbs { grid-template-columns: repeat(auto-fill, 84px); }
    .recipe-page .gallery__thumb { height: 62px; }
    .photo-menu { right: 14px; bottom: 14px; }
    .photo-menu__button { height: 40px; padding: 0 14px; font-size: 14px; }
    .recipe-actions { flex-direction: column; align-items: flex-start; gap: 10px; }
    .recipe-body { grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 40px; }
    .ingredients-panel { position: sticky; top: 24px; }
  }

  /* Dialogs (sheets) ------------------------------------------------------
     Add to folder, Add to cookbook, Share, Delete and See the page. On a
     phone they rise from the bottom of the screen. */

  .sheet {
    width: min(440px, calc(100vw - 32px));
    max-height: calc(100dvh - 48px);
    padding: 0;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow);
  }
  .sheet::backdrop { background: rgba(35, 30, 25, .45); }
  .sheet--wide { width: min(760px, calc(100vw - 32px)); padding: 20px; }
  .sheet__form { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
  .sheet__head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
  .sheet__title { font: 500 22px/1.2 var(--serif); }
  .sheet__options { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; border: 0; }
  .sheet__option, .sheet__option-form .sheet__option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    padding: 8px 10px;
    border: 0;
    border-radius: 10px;
    background: none;
    color: var(--ink);
    font: 500 15px var(--sans);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
  }
  .sheet__option:hover { background: var(--sunken); color: var(--ink); }
  .sheet__option--done { cursor: default; color: var(--muted); }
  .sheet__option--done:hover { background: none; color: var(--muted); }
  .sheet__option-form { display: block; margin: 0; }
  .sheet__option-text { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }
  .sheet__option-text .muted { font-size: 13px; }
  .sheet__swatch { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; }
  .sheet__new { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
  .sheet__new-row { display: flex; gap: 8px; }
  .sheet__new-row .input { flex-grow: 1; min-width: 0; width: auto; }
  .sheet__foot { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding-top: 4px; }
  .btn--delete { background: var(--accent); border-color: transparent; color: var(--surface); }
  .btn--delete:hover { background: var(--accent-hover); color: var(--surface); }

  .book-pages { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); grid-auto-flow: column; box-shadow: 0 6px 18px rgba(35, 30, 25, .14); }
  .book-pages__page { width: 100%; height: auto; display: block; background: #fff; }
  .book-pages__page + .book-pages__page { border-left: 1px solid var(--line); }

  @media (max-width: 600px) {
    .sheet:modal { width: 100%; max-width: none; margin: auto 0 0; border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom); }
    .book-pages { grid-auto-flow: row; }
  }
}
