/* Works: every work as a small tile on a light page, or as a list of titles.
   The page is as tall as the window and doesn't scroll: the grid or list takes the room the rest
   leaves, and works.ts fills it with as many works as fit. */
html, body { overflow: hidden; overscroll-behavior: none; } /* nor does a drag pull or bounce it, as on a work's page */
body { display: flex; flex-direction: column; height: 100svh; }
#empty { padding: 0 var(--pad); color: var(--dim); }

/* ---- Head: the title with the Grid/List switch beside it, and under the switch the tags, five to
   a column. The choice made (the view, the tag) is underlined, as the page you are on is in the
   top line. The list shows every work, so it has no tags. ---- */
main { flex: 1; min-height: 0; position: relative; z-index: 1; display: flex; flex-direction: column; }
.top { position: relative; z-index: 1; }
.head {
  display: grid; grid-template-columns: max-content 1fr; gap: 16px 32px;
  padding: clamp(20px, 4vh, 36px) var(--pad) 0; font-size: 13px; line-height: 20px;
}
.head h1 { letter-spacing: .12em; text-transform: uppercase; }
.head button, .pages button { white-space: nowrap; }
.head button:hover, .head [aria-pressed="true"] { text-decoration-line: underline; text-underline-offset: 4px; }
.views { display: flex; gap: 16px; }
.words { grid-column: 2; display: grid; grid-template-rows: repeat(5, auto); grid-auto-flow: column; justify-content: start; column-gap: 36px; }
main:has(#grid[hidden]) .words { display: none; }
.pages button { color: var(--dim); transition: color .2s ease; }
.pages button:hover, .pages [aria-current] { color: var(--fg); }
#grid, #list { flex: 1; min-height: 0; margin-top: clamp(20px, 4vh, 36px); }

/* Grid: as many 4:3 tiles as fit; the row gap leaves room for the title that appears on hover,
   and the padding underneath does the same for the last row. */
#grid {
  display: grid; align-content: start; gap: 30px 4px; padding: 0 4px 18px;
  grid-template-columns: repeat(auto-fill, minmax(clamp(104px, 10vw, 168px), 1fr));
}
.tile { position: relative; display: block; }
.tile .m { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #e4e4e4; }
.tile .t {
  position: absolute; left: 0; right: 0; top: 100%; padding: 4px 2px 0;
  font-size: 11px; line-height: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity .2s ease;
}
.tile:hover .t, .tile:focus-visible .t { opacity: 1; }

/* List: plain titles. Pointing at one fills the page with its cover, and the text turns white. */
#list { padding: 0 var(--pad); }
#list a { display: inline-block; transition: opacity .25s ease; }
/* Pages: numbers along the foot, under the works, with the one showing underlined. The line keeps
   its height when it is empty (one page), so what fits above doesn't depend on it. */
.pages {
  display: flex; align-items: baseline; gap: 16px; min-height: 60px; padding: 14px var(--pad) 26px;
  font-size: 13px; line-height: 20px; color: var(--dim);
}
.pages [aria-current] { text-decoration-line: underline; text-underline-offset: 4px; }
.pages .next { margin-left: 12px; }
.pages :disabled { opacity: .4; pointer-events: none; }

/* Behind the list: the cover of the work whose title is being pointed at. */
#bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
#bg img, #bg video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .45s ease; }
#bg .on { opacity: 1; }
/* A soft shade down the left and across the top, behind the rail, the titles and the header,
   so white text stays readable over bright covers (sky, snow) without darkening the whole photo.
   Each shade eases in and out over many steps: a fade drawn as one or two straight lines leaves a
   visible edge where they meet, which reads as a panel on a flat sky. --side is how far the left one reaches. */
#bg::after {
  --side: clamp(420px, 50vw, 840px);
  content: ""; position: absolute; inset: 0; z-index: 1; opacity: 0; transition: opacity .45s ease;
  background:
    linear-gradient(90deg,
      rgba(0, 0, 0, .35) 0,
      rgba(0, 0, 0, .34) calc(var(--side) * .1),
      rgba(0, 0, 0, .314) calc(var(--side) * .2),
      rgba(0, 0, 0, .274) calc(var(--side) * .3),
      rgba(0, 0, 0, .227) calc(var(--side) * .4),
      rgba(0, 0, 0, .175) calc(var(--side) * .5),
      rgba(0, 0, 0, .123) calc(var(--side) * .6),
      rgba(0, 0, 0, .076) calc(var(--side) * .7),
      rgba(0, 0, 0, .036) calc(var(--side) * .8),
      rgba(0, 0, 0, .01) calc(var(--side) * .9),
      rgba(0, 0, 0, 0) var(--side)),
    linear-gradient(180deg,
      rgba(0, 0, 0, .2) 0,
      rgba(0, 0, 0, .169) 30px,
      rgba(0, 0, 0, .1) 60px,
      rgba(0, 0, 0, .031) 90px,
      rgba(0, 0, 0, 0) 120px);
}
body.lit #bg::after { opacity: 1; }
:root, body { transition: color .3s ease; }
body.lit { --fg: #fff; --dim: rgba(255, 255, 255, .78); text-shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 0 12px rgba(0, 0, 0, .35); }
body.lit #list a { opacity: .78; }
body.lit #list a:hover { opacity: 1; }

@media (max-width: 640px) {
  /* phones: the tags are one row under the title, which scrolls sideways when it is long */
  .head { gap: 6px 18px; padding-top: 24px; }
  .words { grid-column: 1 / -1; display: flex; gap: 18px; overflow-x: auto; }
  #grid, #list { margin-top: 20px; }
  #grid { gap: 3px; padding: 0 var(--pad); grid-template-columns: repeat(3, 1fr); } /* the tiles start under the words above them */
  .tile .t { display: none; }
  /* the numbers sit in the middle, each tall and wide enough to tap; the next number does for Next */
  .pages { justify-content: center; align-items: center; gap: 4px; min-height: calc(44px + max(18px, env(safe-area-inset-bottom))); padding: 0 var(--pad) max(18px, env(safe-area-inset-bottom)); }
  .pages button { min-width: 40px; padding: 12px 0; text-align: center; }
  .pages span { min-width: 24px; text-align: center; }
  .pages .next { display: none; }
}
@media (prefers-reduced-motion: reduce) { .tile .t, .pages button, #bg img, #bg video, #bg::after, #list a { transition: none; } }
