/* ==========================================================================
   usual.red — layout: header (menu + list), grid, sheet.

   Every page has the same header: "About me" and "Index" over the list of
   cases, all of them buttons in .ts-button (33/33), the three views in
   .ts-button-italic; the page you are on glows red. The sheet carries the
   same header.

   Vertical rhythm (web 1470 / mobile 393):
     menu top ............ 24 / 8      (--pad-top)
     list top ............ 134 / 12 under the menu
     list → content ...... 82 / 121    (--after-list; every page)
     case head → columns . 24 / 24     (--after-head)
   Grid sizing как было на pasha.rehab: 80vw frame, three equal columns
   --col-gap apart (369px each at 1470), one column at ≤768px with 12px
   side margins.
   ========================================================================== */

/* ---- menu: "About me" over "Index" ---- */

.menu {
  display: flex;
  flex-direction: column;
  padding: var(--pad-top) var(--pad-x) 0;
}

.menu__line {
  display: flex;
  align-items: baseline;
  white-space: nowrap;
}

/* --rest: its ink when not glowing (--ink-visited once viewed, css/base.css). */
.item__name {
  --rest: var(--ink);
  font: var(--type-button);
  color: var(--rest);
}

/* "Index", "Timeline" and "Type" share the second line, 12px apart, in
   .ts-button-italic. */
.menu__pair {
  gap: 12px;
}

.menu__pair .item__name {
  font: var(--type-button-italic);
}

.menu__btn {
  display: inline-flex;
  align-items: baseline;
}

/* Timeline is a button dressed as the other menu items. */
button.item__name {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

/* Micro comments of the Timeline and Type views: the years and the types
   by the cases (js/timeline.js), styled as "(Next one)" (css/base.css).
   Empty, they take no room. */
.item__year,
.item__type {
  margin-left: var(--note-gap);
  font: var(--type-micro);
  color: var(--ink-micro);
  align-self: flex-start;
}

.item__year:empty,
.item__type:empty {
  margin-left: 0;
}

/* ---- frame: the 80vw column everything below the menu lines up to ---- */

.frame {
  width: var(--frame);
  margin-inline: auto;
}

/* ---- list of cases ---- */

/* On the web the list keeps its old top (134px) in the first column; the
   menu is 2 × 33px tall from 24px, so 44px between them. Its names start
   on the frame's left edge, in line with the columns and the copy under
   them. */
.list {
  display: flex;
  flex-direction: column;
  margin-top: 44px;
}

/* Relative: a comment going is pinned in it (js/timeline.js). */
.item {
  position: relative;
  display: flex;
  align-items: baseline;
  white-space: nowrap;
  transition: transform 450ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Timeline view: present → past as an even staircase, the oldest case
   --timeline-shift to the right; js/timeline.js swaps the notes for the
   years. */
.is-timeline .item {
  transform: translateX(calc(var(--step) / var(--steps) * var(--timeline-shift)));
}

/* Type view: a loose scatter on the same scale, each case --type-at of
   --timeline-shift to the right (typeAt in pages/data.js); js/timeline.js
   swaps the notes for the types. A case on the same spot in both views
   stays put between them. */
.is-type .item {
  transform: translateX(calc(var(--type-at) * var(--timeline-shift)));
}


@media (prefers-reduced-motion: reduce) {
  .item {
    transition: none;
  }
}

/* ---- the case's first line: tagline and links across the full grid,
   where the columns used to start; the columns follow --after-head below ---- */

.case-head {
  margin-top: var(--after-list);
}

.case-head + .grid {
  margin-top: var(--after-head);
}

/* ---- wide blocks (pages/data.js wide): across the grid, between the
   case's first line and the columns, --after-head from each. 100cqi in
   them is the grid's width (the typing block's size, css/blocks.css). ---- */

.wide {
  container-type: inline-size;
  margin-top: var(--after-list);
}

.case-head + .wide,
.wide + .wide,
.wide + .grid {
  margin-top: var(--after-head);
}

/* ---- text coming in ----
   Quickly and lightly: from clear and --intro-blur to whole over --intro
   (.is-intro). The header once, on a real page load (js/site.js); a page's
   own text each time the page comes in, waiting unseen for its turn in the
   queue the blocks come in by (.is-queued, js/loader.js). */

.is-queued {
  opacity: 0;
  visibility: hidden;
}

.is-intro {
  animation: intro-in var(--intro) ease backwards;
}

@keyframes intro-in {
  from {
    opacity: 0;
    filter: blur(var(--intro-blur));
  }
}

/* ---- a page going (js/router.js) ----
   Moving to another page of the site, all of the old one but its header
   blurs to --leave-blur and fades out over --leave; then the next page
   takes its place and comes in as above. Text still coming in is cut
   short and goes with the rest. */
#feed.is-leaving .case__page > :not(.top) {
  animation: none;
}

#feed.is-leaving .case__page > :not(.top),
#feed.is-leaving .sheet {
  opacity: 0;
  filter: blur(var(--leave-blur));
  transition: opacity var(--leave) ease, filter var(--leave) ease;
}

/* A menu comment (js/timeline.js) comes in as text does: whole, from
   clear and --intro-blur over --intro; it goes the same way back, and
   stays gone until the script empties it. Going, it is out of the line,
   pinned where it stood (left and top set by the script), so the comment
   coming in takes its spot at the same time. */
.is-coming {
  animation: note-in var(--intro) ease backwards;
}

.is-going {
  animation: note-out var(--intro) ease forwards;
}

.item > .is-going {
  position: absolute;
  margin-left: 0;
}

@keyframes note-in {
  from {
    opacity: 0;
    filter: blur(var(--intro-blur));
  }
}

@keyframes note-out {
  to {
    opacity: 0;
    filter: blur(var(--intro-blur));
  }
}

@media (prefers-reduced-motion: reduce) {
  .is-intro,
  .is-coming,
  .is-going {
    animation: none;
  }
}

/* ---- grid: three equal columns, как было ---- */

.grid {
  display: flex;
  align-items: flex-start;
  gap: var(--col-gap);
  margin-top: var(--after-list);
}

.col {
  flex: 1;
  /* Keeps the three columns exactly equal: without it a wide child could
     push its column past a third (как было). */
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--stack);
}

/* Two projects (blocks with years: signs, raw) stand --project-gap apart. */
.col > .block--project + .block--project {
  margin-top: calc(var(--project-gap) - var(--stack));
}

/* ---- case page + sheet (шторка) ----
   .case holds the page and the sheet that follows it. Everything above the
   sheet (.case__page) is sticky: it scrolls normally until its bottom meets
   the bottom of the screen, then stays put while the sheet climbs over it.
   "The screen" is 100lvh, the tallest it gets (iOS Safari's toolbar folded
   away), which does not change while scrolling: with the toolbar out, the
   last of the page's empty tail stays under it, and the page is already
   still when the sheet shows. With 100svh it kept scrolling along with the
   sheet whenever the toolbar was folded.
   --h is the page's own height, kept current by js/site.js.
   min(0px, …) covers a page shorter than the screen: it pins at once instead
   of being pushed down. */

.case {
  position: relative;
}

.case__page {
  position: sticky;
  top: min(0px, calc(100lvh - var(--h, 100lvh)));
  /* Room under the columns before the sheet: the old footer's 134px plus
     --page-tail, so the sheet first slides over empty space. */
  padding-bottom: calc(134px + var(--page-tail));
  /* Opaque, so a case opened from a sheet covers the frozen strip of the
     case above it until that one is removed (js/sheet.js). */
  background: var(--bg);
}

/* The credit (Figma 3781:4125), on every page: micro, in --accent, on the
   left of the frame, 24px above the page's bottom edge (the sticky page
   holds it). It shows once the page is scrolled to its end, where the page
   stops, and the sheet then rises over it with the rest of the page. */
.credit {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 24px;
}

.sheet {
  position: relative;
  z-index: 1;
  /* Exactly the screen as it is now (dvh follows iOS Safari's toolbar): at
     the end of the page its top stops at the top edge. Taller (lvh), it
     could be pushed on up under the status bar while the toolbar is out. */
  min-height: 100vh;
  min-height: 100dvh;
  /* --sheet-overhang wider than the screen each side (body clips it), its
     content put back in place: tilted as it comes in (js/fall.js), round the
     middle of its top edge, it never shows the page beside it. */
  margin-inline: calc(-1 * var(--sheet-overhang));
  padding-inline: var(--sheet-overhang);
  transform-origin: 50% 0;
  background: var(--sheet-bg);
  /* Above its top, outside it: the grey strip, the white edge over it
     (css/base.css). Shadows, so they take no room: the sheet closes on its
     own top, and they go up off the screen. */
  box-shadow: var(--sheet-rim), var(--sheet-edge);
}

/* As the sheet covers the page, all but the fall follows the scroll:
   - the page loses its colour, from nothing at --fade-from of the screen
     covered to --sheet-fade when the sheet fills it;
   - the sheet's grey fills in, from --sheet-fill-from opaque when its edge
     appears to solid when it covers the screen; under it, and only there,
     the page is blurred, --sheet-blur; its menu and list stay sharp;
   - once --fall-at is covered, the page falls back as on pizzapizza.io, at
     once over --fall — down to --fall-scale around a point a third of the
     screen from the top — and comes back the same way when the sheet goes
     below it (js/fall.js);
   - from --closing-from covered, the backdrop turns to --backdrop (the usual
     grey), the white edge over the sheet fades out (the grey strip under it
     stays; outside the sheet, neither takes room, so nothing moves) and the
     glow on the current case in its list fades too. All of it done when the
     sheet covers the screen.
   A named view timeline on the sheet drives the sheet and the backdrop; the
   sheet's movement is untouched. The page itself is set by js/fall.js: as a
   scroll-driven animation it was kept as one picture and went soft when
   zoomed in. Its grey lies on its veil (below). Without scroll-driven
   animations the sheet is solid and the page sharp. */
.case__page {
  transform-origin: 50% calc(100% - 66lvh);
  transition: transform var(--fall) var(--fall-ease);
}

@media (prefers-reduced-motion: reduce) {
  .case__page {
    transition: none;
  }
}

/* The veil: an empty layer over the page and under the sheet (z-index 1)
   that greys what lies under it on screen (backdrop-filter, set by
   js/fall.js). A filter on the page itself made Chrome (Arc) on a Retina
   screen redraw the whole page every frame: some 47 frames a second while
   the sheet moved, against 60 with the veil. */
.case__veil {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

@supports (animation-timeline: view()) and (timeline-scope: none) {
  .case {
    timeline-scope: --sheet;
    animation: backdrop-in linear both;
    animation-timeline: --sheet;
    animation-range: entry var(--closing-from) entry 100%;
  }

  .sheet {
    view-timeline: --sheet block;
    animation: sheet-fill linear both, sheet-edge-out linear both;
    animation-timeline: --sheet, --sheet;
    animation-range: entry 0% entry 100%, entry var(--closing-from) entry 100%;
    -webkit-backdrop-filter: blur(var(--sheet-blur));
    backdrop-filter: blur(var(--sheet-blur));
  }

  /* In the sheet, the glow on the page under it ("About me" or its case
     in the list) fades out on the same stretch, its letters back to their
     --rest ink: once the sheet covers that page it is a link like any
     other. Not the chosen view (Index or
     Timeline, [data-view]), not on hover, nor on a case just clicked there
     (js/sheet.js). */
  .sheet .is-current:not(.is-chosen) > .item__name:not([data-view], :hover) {
    animation: current-fade linear both;
    animation-timeline: --sheet;
    animation-range: entry var(--closing-from) entry 100%;
  }
}

@keyframes backdrop-in {
  from {
    background-color: transparent;
  }
  to {
    background-color: var(--backdrop);
  }
}

@keyframes sheet-fill {
  from {
    background-color: color-mix(in srgb, var(--sheet-bg) var(--sheet-fill-from), transparent);
  }
  to {
    background-color: var(--sheet-bg);
  }
}

@keyframes sheet-edge-out {
  from {
    box-shadow: var(--sheet-rim), var(--sheet-edge);
  }
  to {
    box-shadow: var(--sheet-rim), 0 var(--sheet-edge-lift) 0 0 transparent;
  }
}

@keyframes current-fade {
  to {
    color: var(--rest);
    text-shadow: 0 0 var(--glow-blur) transparent;
  }
}

/* ---- mobile ---- */

@media (max-width: 768px) {
  .frame {
    width: auto;
    margin-inline: var(--gutter);
  }

  /* On the web the list lines up with the columns; on a phone it stands
     12px in from them. */
  .list {
    margin-top: 12px;
    padding-left: 12px;
  }

  .grid {
    flex-direction: column;
    align-items: stretch;
    gap: var(--stack);
  }

  .col {
    flex: none;
  }

  /* The columns stack: a project opening one column stands --project-gap
     under a project closing the column above. */
  .col:has(> .block--project:last-child) + .col:has(> .block--project:first-child) {
    margin-top: calc(var(--project-gap) - var(--stack));
  }

  /* Rufa Press: one project to a column, without years; stacked, its
     columns stand --project-gap apart too. */
  .case[data-case="rufa-press"] .grid {
    gap: var(--project-gap);
  }

  .case__page {
    padding-bottom: calc(139px + var(--page-tail));
  }
}
