/* A work: its photos, clips and embeds one at a time, fitted to the screen. Above them, small
   words: Index, and Prev / Next for the works either side. Under them, one line: the title,
   the year and where you are (2 / 6). A picture's caption sits under it; the work's text opens from the
   title (a small plus beside it says so) and shows in place of the pictures. */
:root {
  --col: clamp(600px, 65vw, 1240px); /* the widest a picture gets */
  --side: max(var(--pad), (100% - var(--col)) / 2); /* what is left on each side of it */
  --chevron-prev: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='16' fill='none' stroke='%232c2c2c' stroke-width='1.25'%3E%3Cpath d='M9.5.5 1 8l8.5 7.5'/%3E%3C/svg%3E");
  --chevron-next: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='16' fill='none' stroke='%232c2c2c' stroke-width='1.25'%3E%3Cpath d='M.5.5 9 8 .5 15.5'/%3E%3C/svg%3E");
}

/* The page is as tall as the screen and does not scroll: header, picture, line. It is held in
   place too, so a drag on a phone neither slides it nor stretches it past its edges. */
html, body { overflow: hidden; overscroll-behavior: none; }
body { display: flex; flex-direction: column; height: 100svh; }
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
article { flex: 1; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; }

/* ---- The picture ---- */
/* Everything in .prose shares one cell and only the current item is shown. The cell is a size
   container, so an item can be fitted to it (cqw, cqh) whatever its shape. The space beside the
   picture is part of .prose too: with a mouse, a click there turns the page like a click on the picture. */
.prose {
  container-type: size; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  padding: clamp(8px, 3vh, 28px) var(--side) clamp(16px, 5vh, 44px);
  user-select: none; -webkit-user-select: none;
  touch-action: pan-y pinch-zoom; /* a sideways drag is the page's own (work.ts), not the browser's */
}
.prose > * { display: none; grid-area: 1 / 1; margin: 0; }
/* Shown: the current item (.on), the one fading out under it (.out) and the one a drag is fading in
   (.near, its opacity set by work.ts as the drag goes); before the script runs, the first. */
.prose > figure:is(.on, .out, .near),
.prose:not(.ready) > figure:nth-child(1 of figure, iframe) { display: grid; place-items: center; min-width: 0; min-height: 0; }
.prose > iframe:is(.on, .out, .near),
.prose:not(.ready) > iframe:nth-child(1 of figure, iframe) { display: block; place-self: center; }
.prose > :is(.on, .out, .near) { transition: opacity .35s ease; }
.prose > .out { opacity: 0; }
@starting-style { .prose > .on { opacity: 0; } }

/* A figure is its frame with the caption under it, centred in the cell. The column is as wide as
   the frame, so the caption wraps to the picture's width and starts at its left edge. */
.prose > figure { --cap: 0px; grid-template-columns: min-content; justify-content: center; align-content: center; }
.prose > figure:has(figcaption) { --cap: 28px; } /* room for one line of caption under the picture */
figcaption { margin-top: 10px; font-size: 13px; line-height: 18px; color: var(--dim); justify-self: stretch; }

/* A frame is as large as fits the cell at its item's shape (--w and --h, from the publish step), never larger than the file. */
.frame {
  position: relative; aspect-ratio: var(--w) / var(--h);
  width: min(100cqw, calc((100cqh - var(--cap)) * var(--w) / var(--h)), calc(var(--w) * 1px));
}
.frame > :is(img, video) { display: block; width: 100%; height: 100%; object-fit: contain; background: var(--blank); -webkit-user-drag: none; }
.frame:not([style]) { width: 100cqw; height: calc(100cqh - var(--cap)); } /* shape unknown: the whole cell, the item fitted inside it */
.frame:not([style]) > * { background: none; }
.prose > iframe { width: min(100cqw, calc(100cqh * 16 / 9)); height: auto; aspect-ratio: 16 / 9; border: 0; background: var(--blank); }

/* The work's text (work.ts gathers it into .detail), over the pictures. Opening it fades the
   pictures out and the text in, slowly; closing it does the reverse. */
.prose > .detail {
  position: relative; display: flex; flex-direction: column; place-self: center;
  max-width: min(56ch, 100%); max-height: 100%;
  padding-bottom: 68px; /* as much under the text as the close button takes above it */
  user-select: text; -webkit-user-select: text; cursor: auto;
  opacity: 0; visibility: hidden; transition: opacity .8s ease, visibility 0s .8s;
}
article.reading .prose > .detail { opacity: 1; visibility: visible; transition: opacity 1s ease; }
article.reading .prose > :is(figure, iframe) { opacity: 0; visibility: hidden; transition: opacity .8s ease, visibility 0s .8s; }
article.closing .prose > .on { transition: opacity 1s ease; } /* the picture comes back as slowly as it left */
article.reading .prose[data-side] { cursor: auto; }
.count { transition: opacity .8s ease, visibility 0s; }
article.reading .count { opacity: 0; visibility: hidden; transition: opacity .8s ease, visibility 0s .8s; }
/* A small cross above the text's right edge closes it (so does the title, and Escape). */
.detail .close {
  align-self: flex-end; display: grid; place-items: center; width: 44px; height: 44px; margin: 0 -48px 24px 0;
  color: var(--dim); transition: color .2s ease;
}
.detail .close:hover { color: var(--fg); }
.detail .text { min-height: 0; overflow-y: auto; }
.detail .text > * { margin: 0; }
.detail .text > * + * { margin-top: 1em; }
.detail h2, .detail h3 { font: inherit; font-size: 20px; line-height: 26px; margin-top: 2em; }
.detail .text > :first-child { margin-top: 0; }

/* With a mouse, the pointer is a chevron: left on the left half, right on the right half (work.ts
   says which). Clips and embeds keep the ordinary pointer, since a click there is theirs. */
.prose[data-side="prev"] { cursor: var(--chevron-prev) 5 8, w-resize; }
.prose[data-side="next"] { cursor: var(--chevron-next) 5 8, e-resize; }
.prose :is(video, iframe) { cursor: auto; }

/* What a photo was taken with, along its bottom edge while the pointer is over the photo; on a
   touch screen, a tap on a photo turns it on and off (work.ts).
   White with a whisper of shadow, as on the home page. */
.exif {
  position: absolute; bottom: 0; left: 0; width: 100%;
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 2px 24px;
  padding: 60px 18px 14px; color: #f3f3f3; font-size: 13px; line-height: 18px; font-variant-numeric: tabular-nums;
  text-shadow: var(--shadow); background: linear-gradient(0deg, rgba(0, 0, 0, .32), rgba(0, 0, 0, 0));
  pointer-events: none; opacity: 0; transition: opacity .25s ease;
}
.exif .settings { display: flex; gap: 18px; }
@media (hover: hover) { .frame > img:hover + .exif { opacity: 1; } }
.prose.exif-on .exif { opacity: 1; }

/* ---- The top line: Index (the works page) on the left; Prev and Next on the right, greyed where there is no such work ---- */
.top { font-size: 14px; }
.index, .pager > * { padding: var(--tap) 0; } /* as tall to tap as the top line's links on the other pages */
.pager { display: flex; gap: 24px; }
.pager span { color: var(--dim); opacity: .7; }

/* ---- The line under the picture: the title, its plus and the year on the left, the count on the right ---- */
/* The count is level with the last line, so it stays put however many lines a title takes. */
.line {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 32px;
  padding: 0 var(--side) max(clamp(16px, 3.5vh, 30px), env(safe-area-inset-bottom));
}
/* The title runs on as text, so when it wraps the plus stays after its last word. */
.intro { min-width: 0; }
.intro :is(h1, .meta) { display: inline; }
.intro .meta { margin-left: 14px; color: var(--dim); }
.intro .meta:empty { display: none; }
/* A work with text: its title opens the text, and says so with a small plus that turns into a cross while it is open. */
.intro.has-detail h1 { cursor: pointer; }
.more {
  display: inline-grid; place-items: center; vertical-align: middle;
  width: 26px; height: 44px; margin: -11px -8px -11px -4px; color: var(--dim);
}
.more svg { display: block; transition: transform .3s ease-in-out; }
@media (hover: hover) { .intro.has-detail:hover .more svg { transform: rotate(90deg); } }
.intro.has-detail .more[aria-expanded="true"] svg { transform: rotate(45deg); }

/* The count is one line tall, level with the last line of the title or year; the buttons reach past it. */
.count { flex: none; display: flex; align-items: center; gap: 6px; height: 1lh; font-variant-numeric: tabular-nums; }
.count p { min-width: 3.2em; text-align: center; }
.count p span { color: var(--dim); }
/* Previous and next as buttons: on a touch screen they sit either side of the count; with a mouse
   the pointer does their job, so they are out of the line and unseen until the keyboard reaches
   them, and the count sits flush with the right edge. */
.count button { display: grid; place-items: center; width: 44px; height: 44px; color: #2c2c2c; }
@media (hover: hover) {
  .count button:not(:focus-visible) { position: absolute; opacity: 0; pointer-events: none; }
  .count p { min-width: 0; }
}

@media (max-width: 640px) {
  .top { font-size: 13px; }
  .pager { gap: 20px; }
  /* phones: the arrows are smaller and closer to the count, so a title has room beside them; the right one's drawing meets the page edge */
  .line { gap: 12px; }
  .intro .meta { display: block; margin: 2px 0 0; } /* the year on a line of its own, under the title */
  .count { gap: 0; }
  .count button { width: 30px; }
  .count button:last-child { margin-right: -11px; }
  .count button svg { width: 7px; height: 11px; }
  .detail .close { margin-right: -17px; } /* no room beside the text */
  .exif { padding: 40px 12px 10px; font-size: 12px; line-height: 17px; }
  .exif .settings { gap: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .prose > :is(.on, .out, .near), .prose > :is(figure, iframe), .prose > .detail,
  .exif, .count, .more svg { transition: none !important; }
}
