/* Artwork pages (vision §E3 painting, §E6 doodle): the painting hung on the wall on columns 1–7, its
   label, actions and "Order a print" on 9–12 (1–6 and 8–12 below 1280 px, where four columns are too
   narrow for the print options); About, details, strips and the catalogue neighbours below. Shared
   by the doodle page (doodle.html links this file, then doodle.css).
   Markup: templates/painting.html, templates/doodle.html (edge-rendered). Behaviour:
   js/v3/pages/{painting,doodle}.js. Light falls on the wall only: the hang's pool and cast shadow
   (components/hang.css) sit behind the canvas; nothing ever sits on top of the art. */
@layer pages {
  .artwork {
    display: block;
    /* Previous / next closes the page; the footer's own band follows after a short pause. */
    padding-block-end: var(--space-9);
  }

  /* ---------------------------------------------------------------- stage: hang + panel */
  .artwork__stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-5);
    padding-block: var(--space-4) var(--space-7);
  }
  .artwork__crumbs { min-inline-size: 0; }
  .artwork__crumbs .title { font-size: 1.06em; }
  /* The full title is the H1 just below: a long one ends in an ellipsis here instead of wrapping the
     trail onto a second line (the text itself, and so what screen readers hear, stays whole). */
  .artwork__crumbs li[aria-current] { flex: 1 1 8rem; min-inline-size: 0; }
  .artwork__crumbs li[aria-current] .title {
    display: block;
    flex: 0 1 auto;
    min-inline-size: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding-inline-end: 0.15em;
  }

  .artwork__hang {
    /* Never taller than the screen below the header (with a little wall above and below). --ar
       (set here by the renderer) is shared by the painting and the draft note under it. */
    --hang-limit: min(78svh, calc(100svh - var(--header-h) - 64px));
    display: grid;
    justify-items: center;
    align-content: center;
    gap: var(--space-3);
    min-inline-size: 0;
  }

  /* Never wider than the image's own pixels (--nat-w, set by the renderer), never taller than the screen. */
  .artwork__figure {
    --hang-max: var(--hang-limit);
    inline-size: min(100%, var(--hang-limit) * var(--ar, 1), var(--nat-w, 100vw));
  }
  .artwork__figure > picture {
    grid-area: 1 / 1;
    display: block;
    min-inline-size: 0;
  }
  .artwork__img {
    display: block;
    inline-size: 100%;
    block-size: auto;
    aspect-ratio: var(--ar, auto);
    box-shadow: 0 1px 2px var(--hang-contact-color);
    /* The walk-up placeholder (the cached grid image) has the canvas's own proportions. */
    background-size: 100% 100%;
    background-repeat: no-repeat;
  }
  /* Until the file has fully arrived (the inline script in the template sets data-pending), the
     picture is drawn outside its own box, so only its placeholder shows: never a half-decoded photo.
     Nothing fades: it appears whole, at once. */
  .artwork__img[data-pending] { object-position: -300vw 0; }
  /* A work newer than the last derive run: reserve a 4:3 box until the image tells its size. */
  .artwork__figure[data-size="unknown"] { --ar: 4 / 3; inline-size: 100%; }
  .artwork__figure[data-size="unknown"] .artwork__img { aspect-ratio: 4 / 3; object-fit: contain; box-shadow: none; }

  .artwork__note {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    max-inline-size: 60ch;
    font-size: var(--step--1);
    line-height: 1.45;
    color: var(--ink-2);
    justify-self: start;
  }
  /* Under the painting: left-aligned to the canvas, as wide as it. */
  .artwork__hang > .artwork__note {
    justify-self: center;
    inline-size: min(100%, var(--hang-limit) * var(--ar, 1), var(--nat-w, 100vw));
    min-inline-size: min(100%, 22rem);
    max-inline-size: none;
  }
  .artwork__note--tight { margin-block-start: calc(var(--space-1) * -1); }

  .artwork__panel {
    display: grid;
    align-content: start;
    gap: var(--space-6);
    min-inline-size: 0;
  }

  @media (min-width: 1024px) {
    .artwork__stage {
      --hang-cols: 1 / span 7;
      --panel-cols: 9 / -1;
      grid-template-columns: repeat(12, minmax(0, 1fr));
      grid-template-rows: auto 1fr;
      column-gap: var(--gutter);
      row-gap: var(--space-5);
      align-items: start;
      padding-block: 0 var(--space-8);
    }
    .artwork__crumbs { grid-column: var(--panel-cols); grid-row: 1; padding-block-start: var(--space-6); }
    .artwork__panel { grid-column: var(--panel-cols); grid-row: 2; }
    /* The wall is exactly one screen below the header, so the painting can stay beside the print
       options as they scroll (sticky, below). The hang line (vision §B3, layout.css .hang-line): the
       extra 8svh under the painting lifts its centre to ~45% of the space below the header (~42% of
       the screen once the wall has stuck to the top). It hangs at the inner edge of its wall so it
       always keeps the same distance from its label. */
    .artwork__hang {
      --hang-limit: min(78svh, calc(100svh - var(--header-h) - 2 * var(--space-5) - 8svh));
      grid-column: var(--hang-cols);
      grid-row: 1 / span 2;
      justify-items: end;
      block-size: calc(100svh - var(--header-h));
      min-block-size: 360px;
      padding-block: var(--space-5) calc(var(--space-5) + 8svh);
    }
    /* Local preview: room for the draft note under the painting inside the same screen. */
    .artwork__hang:has(> .artwork__note) {
      --hang-limit: min(78svh, calc(100svh - var(--header-h) - 2 * var(--space-5) - 8svh - 88px));
    }
    .artwork__hang > .artwork__note { justify-self: end; }
    /* js/v3/pages/painting.js measures: the panel is sticky only when it fits the screen; when it
       is longer (the print options), the painting stays on the wall beside it instead. */
    .artwork__stage[data-sticky="panel"] .artwork__panel { position: sticky; inset-block-start: var(--space-5); }
    .artwork__stage[data-sticky="hang"] .artwork__hang { position: sticky; inset-block-start: 0; }
  }
  /* Small desktops: a fifth column for the label and the print options. */
  @media (min-width: 1024px) and (max-width: 1279.98px) {
    .artwork__stage { --hang-cols: 1 / span 6; --panel-cols: 8 / -1; }
  }

  /* ---------------------------------------------------------------- label */
  .artwork__label {
    display: grid;
    gap: var(--space-3);
    justify-items: start;
  }
  .artwork__title {
    font-size: var(--step-4);
    font-weight: 400;
    line-height: 1.04;
    letter-spacing: -0.01em;
    text-wrap: balance;
    max-inline-size: 18ch;
  }
  @media (min-width: 1024px) {
    .artwork__title { max-inline-size: none; }
  }
  .artwork__meta {
    font: 450 var(--step--2)/1.4 var(--font-mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-variant-numeric: tabular-nums;
    color: var(--ink-2);
  }
  .artwork__mood {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    font-size: var(--step--1);
    line-height: 1.5;
    color: var(--ink-2);
  }
  .artwork__mood-label { margin-inline-end: 0.5em; color: var(--ink-2); }
  .artwork__mood a {
    color: var(--ink-2);
    text-decoration-color: transparent;
  }
  .artwork__mood a:is(:hover, :focus-visible) { color: var(--ink); text-decoration-color: var(--accent); }
  .artwork__mood-word + .artwork__mood-word::before {
    content: "·" / "";
    margin-inline: 0.55em;
    color: var(--ink-3);
  }

  /* ---------------------------------------------------------------- actions */
  .artwork__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-5);
  }
  .artwork__look { padding-inline: 18px 22px; }
  .artwork__links { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-5); }
  .artwork__actions .button--text { min-block-size: 44px; color: var(--ink-2); }
  .artwork__actions .button--text:is(:hover, :focus-visible) { color: var(--ink); }
  .artwork__share > svg { inline-size: 1.1em; block-size: 1.1em; }

  .artwork__describe { max-inline-size: var(--measure); }
  .artwork__describe > p { color: var(--ink-2); font-size: var(--step--1); line-height: 1.6; }
  .artwork__describe > p:first-of-type { color: var(--ink); font-size: var(--step-0); }
  .artwork__machine {
    font: 450 var(--step--2)/1.4 var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  /* ---------------------------------------------------------------- order a print */
  .artwork__order {
    display: grid;
    gap: var(--space-4);
    padding-block-start: var(--space-4);
    scroll-margin-block-start: var(--space-5);
  }
  .artwork__order-title { font-size: var(--step-3); }
  .artwork__fallback { display: grid; gap: var(--space-4); }
  .artwork__fallback-lede { font-size: var(--step-0); }
  .artwork__fallback-notes {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--step--1);
    color: var(--ink-2);
  }
  .artwork__fallback-links { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); }

  /* ---------------------------------------------------------------- about */
  .artwork__about { padding-block: var(--section) 0; }
  .artwork__about-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-7) var(--gutter);
  }
  @media (min-width: 1024px) {
    .artwork__about-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); align-items: start; }
    .artwork__about-text { grid-column: 1 / span 7; }
    .artwork__facts { grid-column: 9 / -1; }
  }
  .artwork__about-text { display: grid; gap: var(--space-5); align-content: start; }
  .artwork__lead {
    max-inline-size: 52ch;
    font-size: var(--step-1);
    line-height: 1.5;
    color: var(--ink);
    text-wrap: pretty;
  }
  .artwork__colours { display: grid; gap: var(--space-3); margin-block-start: var(--space-4); }
  .artwork__subhead {
    font: 600 var(--step--2)/1.3 var(--font-ui);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-2);
  }
  .artwork__daubs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .artwork__facts {
    display: grid;
    gap: 0;
    margin: 0;
  }
  .artwork__fact {
    display: grid;
    grid-template-columns: minmax(7.5rem, 0.8fr) minmax(0, 1.4fr);
    gap: var(--space-4);
    align-items: baseline;
    padding-block: var(--space-3);
    border-block-end: 1px solid var(--rule);
  }
  .artwork__fact:first-child { border-block-start: 1px solid var(--rule); }
  .artwork__fact dt {
    font: 600 var(--step--2)/1.4 var(--font-ui);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-2);
  }
  .artwork__fact dd {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    font-size: var(--step--1);
    color: var(--ink);
  }
  .artwork__fact-link {
    display: inline-flex;
    align-items: center;
    min-block-size: 24px;
  }
  .artwork__mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
  }

  /* ---------------------------------------------------------------- details on a lit wall */
  .artwork__details { padding-block: var(--section) 0; }
  .artwork__section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-3) var(--space-5);
  }
  .artwork__wall {
    position: relative;
    isolation: isolate;
    margin-block-start: var(--space-6);
    padding-block: var(--space-6) var(--space-5);
  }
  /* The CSS lamp: a pool on the wall behind the crops (light falls on the wall, never on the art).
     Its centre follows --lamp-x (the lamp sweeps across with scroll, js/v3/features/lamp.js) at the
     height of the row; the gradient fades to nothing inside its own box (closest-side), so the pool
     never shows an edge, wherever the lamp is. */
  .artwork__wall::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset-inline: 0;
    inset-block-start: 50%;
    margin-inline: auto;          /* painted once, centred on the wall … */
    inline-size: min(1120px, 92%);
    block-size: 150%;
    /* … and moved by translate only (compositor; no layout shift as the lamp follows scroll). */
    translate: calc((clamp(-0.2, var(--lamp-x, 0.2), 1.2) - 0.5) * 100%) -50%;
    will-change: translate;
    background: radial-gradient(closest-side,
      var(--pool) 0 30%,
      color-mix(in oklab, var(--pool) 58%, transparent) 56%,
      color-mix(in oklab, var(--pool) 22%, transparent) 78%,
      transparent);
    pointer-events: none;
  }
  .artwork__detail-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-7) clamp(var(--space-5), 3vw, var(--space-8));
    margin: 0;
    padding: 0;
    list-style: none;
  }
  /* Each window at its own pixel size (--detail-w, ≤ 360 px, set on the item): never enlarged. The
     item carries the size, so the box is reserved before the crop's file is attached (painting.js
     attaches it only when it comes near). */
  .artwork__detail-list > li { inline-size: min(var(--detail-w, 360px), 100%); }
  .artwork__detail { display: grid; gap: var(--space-3); margin: 0; inline-size: 100%; }
  .artwork__detail-img {
    display: block;
    inline-size: 100%;
    block-size: auto;
    aspect-ratio: 1;
    background: var(--sunken);
    box-shadow:
      0 1px 2px var(--hang-contact-color),
      clamp(-18px, var(--cast-x), 18px) clamp(-18px, var(--cast-y), 18px) 36px 0 var(--hang-cast-color);
  }
  .artwork__detail-label {
    font: 450 var(--step--2)/1.4 var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-2);
  }

  /* ---------------------------------------------------------------- strips */
  .artwork__more { display: grid; gap: var(--space-8); padding-block-start: var(--section); }
  .rail {
    --rail-h: clamp(150px, 13vw + 40px, 220px);
    display: grid;
    gap: var(--space-4);
    min-inline-size: 0;
  }
  .rail__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-5);
  }
  .rail__title { font-size: var(--step-2); font-weight: 420; letter-spacing: -0.005em; }
  .rail__all { margin-inline-start: auto; }
  /* Scroll buttons for mouse users only (touch swipes; keyboard tabs through the tiles). */
  .rail__nav { display: none; gap: var(--space-1); }
  @media (hover: hover) and (pointer: fine) {
    .rail[data-scrolls] .rail__nav { display: inline-flex; }
  }
  .rail__list {
    --tile-glow: 36px;
    display: flex;
    gap: var(--gutter);
    margin: calc(var(--space-6) * -1) calc(var(--margin) * -1);
    padding: var(--space-6) var(--margin) var(--space-5);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scroll-padding-inline: var(--margin);
    scrollbar-width: thin;
    scrollbar-color: var(--edge) transparent;
    list-style: none;
  }
  .rail__item { flex: none; scroll-snap-align: start; }
  .rail .tile { inline-size: calc(var(--rail-h) * var(--ar, 1)); max-inline-size: 78vw; }
  .rail .tile__img { block-size: auto; }
  .rail__list--doodles { --rail-h: clamp(140px, 11vw + 40px, 190px); }
  .rail .label__title { font-size: var(--step--1); }

  .artwork__studio {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-4) var(--space-5);
    padding-block: var(--space-5);
    border-block: 1px solid var(--rule);
  }
  .artwork__palette { display: inline-flex; flex: none; }
  .artwork__swatch {
    inline-size: 28px;
    block-size: 40px;
    box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ink) 12%, transparent);
    forced-color-adjust: none;
  }
  .artwork__studio-body { display: grid; gap: var(--space-1); min-inline-size: 0; }
  .artwork__studio-name {
    font: 450 var(--step--2)/1.4 var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-2);
  }
  .artwork__studio-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-3); }
  .artwork__studio-note { font-size: var(--step--1); color: var(--ink-2); }

  /* ---------------------------------------------------------------- previous / next */
  .artwork__sequence {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-5) var(--gutter);
    padding-block-start: var(--space-8);
  }
  .artwork__step {
    display: inline-flex;
    align-items: center;
    gap: var(--space-4);
    min-block-size: 44px;
    max-inline-size: min(100%, 34rem);
    color: var(--ink-2);
    text-decoration: none;
  }
  .artwork__step--next { margin-inline-start: auto; justify-content: flex-end; text-align: end; }
  .artwork__step-img {
    flex: none;
    block-size: 96px;
    inline-size: auto;
    aspect-ratio: var(--ar, 1);
    box-shadow: 0 1px 2px var(--hang-contact-color);
  }
  .artwork__step-text {
    display: inline;
    font-size: var(--step--1);
    line-height: 1.45;
  }
  .artwork__step .title { font-size: var(--step-0); color: var(--ink); }
  .artwork__step:is(:hover, :focus-visible) { color: var(--ink); --rewet: 0; }
  .artwork__step:is(:hover, :focus-visible) .title { text-decoration: underline 1px var(--accent); text-underline-offset: 0.2em; }

  @media (max-width: 599.98px) {
    .artwork__sequence { flex-direction: column; align-items: stretch; }
    .artwork__step { max-inline-size: none; }
    .artwork__step-img { block-size: 72px; }
  }

  /* ---------------------------------------------------------------- the original photo dialog */
  /* The dialog takes the photograph's own width (a narrow upright photo gets a narrow dialog), and
     the photograph is as large as the screen allows below the title and caption. It is a document of
     the painting on its wall, so it is shown flat: no pool, no cast shadow. */
  .dialog.artwork-photo {
    inline-size: fit-content;
    min-inline-size: min(26rem, 100% - 2 * var(--margin));
    max-inline-size: calc(100% - 2 * var(--margin));
    max-block-size: calc(100% - 2 * var(--space-4));
  }
  .artwork-photo .dialog__body { display: grid; justify-items: center; }
  .artwork-photo__figure { display: table; margin: 0; }
  .artwork-photo__img {
    display: block;
    inline-size: auto;
    block-size: auto;
    max-inline-size: min(1072px, 100vw - 2 * var(--margin) - 2 * var(--space-5));
    max-block-size: max(240px, 100svh - 220px);
    background: var(--sunken);
  }
  /* table-caption: the words wrap to the photograph's width instead of widening the dialog. */
  .artwork-photo__caption {
    display: table-caption;
    caption-side: bottom;
    padding-block-start: var(--space-3);
    font-size: var(--step--1);
    line-height: 1.5;
    color: var(--ink-2);
  }
  .artwork-photo__size {
    display: block;
    margin-block-start: var(--space-1);
    font-family: var(--font-mono);
    font-size: var(--step--2);
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
  }
  @media (max-width: 599.98px) {
    .artwork-photo__img { max-inline-size: calc(100vw - 2 * var(--margin) - 2 * var(--space-5)); }
  }

  @media (forced-colors: active) {
    .artwork__wall::before { content: none; }
    .artwork__swatch { border: 1px solid CanvasText; }
  }
  @media print {
    .artwork__actions, .artwork__order, .artwork__more, .artwork__sequence { display: none; }
  }
}
