@font-face {
  font-family: 'OldStyle 1';
  src: url('fonts/oldstyle1.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --vw: 1vw;                                /* 1% of the page's width and height; turned round on sideways phones */
  --vh: 1vh;
  --serif: 'OldStyle 1', Georgia, "Times New Roman", Times, serif;
  --side: clamp(240px, calc(18 * var(--vw)), 300px);        /* left column, just wide enough for the menu */
  --top: calc(18 * var(--vh));                              /* the menu's resting top edge (the script then centres it) */
  --stage-h: calc(100 * var(--vh));                         /* the height the big image is centred in */
  --cw: calc(calc(100 * var(--vw)) - 2 * var(--side) - 64px); /* big image max width: stays clear of the side column when centred */
  --ch: calc(72 * var(--vh));                               /* big image max height */
  --tw: clamp(80px, calc(7.5 * var(--vw)), 130px);          /* preview width, either side of the big image */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #fff;
  color: #000;
  font-family: var(--serif);
  font-weight: 400;
}

body {
  overflow: hidden;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

/* ------------------------------------------------------------ left column */

.side {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--side);
  padding: var(--top) 0 32px clamp(24px, calc(3 * var(--vw)), 40px);
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto minmax(0, 1fr);
  column-gap: clamp(16px, calc(1.6 * var(--vw)), 26px);
  z-index: 2;
  /* the menu is the first thing in the row: --menu-p (0 to 1, set by the script) slides it away,
     and --menu-dy centres it on the big image */
  transform: translate3d(calc(var(--menu-p, 0) * -100%), var(--menu-dy, 0px), 0);
  will-change: transform, opacity;
  opacity: calc(1 - var(--menu-p, 0));
}

body[data-start="false"] .side {
  pointer-events: none;
}

/* back to the start of the row, once the menu has gone */
.menu-button {
  position: fixed;
  top: clamp(20px, calc(3 * var(--vh)), 32px);
  right: clamp(24px, calc(3 * var(--vw)), 48px);
  z-index: 3;
  font-size: clamp(13px, calc(0.95 * var(--vw)), 16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.menu-button:hover {
  text-decoration: underline;
}

body[data-start="false"] .menu-button {
  opacity: 1;
  pointer-events: auto;
}

/* name, links, list and bio all share the .side grid so the list lines up under the name */
.side__head,
.side__panel {
  display: contents;
}

.name {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  margin: 0;
  font-size: clamp(24px, calc(2.1 * var(--vw)), 34px);
  font-weight: 400;
  line-height: 0.92;
  text-align: right;
  letter-spacing: 0.01em;
}

.name span {
  display: block;
}

.links {
  grid-column: 1;
  grid-row: 2;
  justify-self: end;
  margin-top: 0.9em;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-size: clamp(13px, calc(0.95 * var(--vw)), 16px);
}

.links__about {
  margin-top: 0.1em;
}

.links__contact {
  margin: 1.5em 0 0 3.2em;
  text-decoration: none;
}

.links__about:hover,
.links__contact:hover {
  text-decoration: underline;
}

.project-list {
  grid-column: 1;
  grid-row: 3;
  justify-self: end;
  align-self: start;
  list-style: none;
  margin: clamp(28px, calc(6 * var(--vh)), 56px) 0 0;
  padding: 0;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: clamp(12px, calc(0.9 * var(--vw)), 15px);
  line-height: 1.12;
}

.project-list button {
  text-align: right;
  white-space: nowrap;
}

.project-list button:hover,
.project-list button[aria-current="true"] {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

/* the script sets its height so it ends at the big image's bottom edge.
   the text fades out at the top and bottom instead of being cut off; the padding
   lets the first and last lines sit clear of the fades when scrolled to an end */
.bio {
  --fade: 28px;
  grid-column: 1 / -1;
  grid-row: 3;
  align-self: start;
  margin: max(0px, clamp(28px, calc(6 * var(--vh)), 56px) - var(--fade)) 12px 0 0;
  padding: var(--fade) 0;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(transparent, #000 var(--fade), #000 calc(100% - var(--fade)), transparent);
  mask-image: linear-gradient(transparent, #000 var(--fade), #000 calc(100% - var(--fade)), transparent);
  font-size: 13px;
  line-height: 1.4;
}

.bio::-webkit-scrollbar {
  display: none;
}

.bio p,
.bio ul {
  margin: 0 0 0.9em;
}

.bio ul {
  padding-left: 1.1em;
}

.bio__lead {
  font-size: 14px;
}

.bio__more {
  margin-top: 1.6em !important;
}

/* ------------------------------------------------------------ centre: slides */

.center {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
}

.stage {
  position: absolute;
  inset: 0 0 auto 0;
  height: var(--stage-h);
}

/* each slide knows its image's aspect ratio (--ar), so width alone sets its size.
   the role classes below are the wheel's slots; the script measures them and
   places each slide between slots as the wheel turns */
.slide {
  position: absolute;
  top: var(--top);
  aspect-ratio: var(--ar, 1.5);
  margin: 0;
  transform-origin: 0 0;
  will-change: transform, opacity;
}

.slide img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 300ms ease;
}

/* a video sits over its still; touches pass through to the slide beneath */
.slide iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 300ms ease;
}

/* the still shows until the video is really playing, and in the small previews,
   which keeps YouTube's paused-video buttons out of sight */
.slide--current iframe.is-playing {
  opacity: 1;
}

.slide__sound {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.slide--current .slide__sound {
  opacity: 0.5;
  pointer-events: auto;
}

/* the hidden copy the script measures the slots with */
.slide--probe {
  visibility: hidden;
  pointer-events: none;
  will-change: auto;
}

/* centred both ways: across the page and down it */
.slide--current {
  left: calc((calc(100 * var(--vw)) - min(var(--cw), calc(var(--ch) * var(--ar, 1.5)))) / 2);
  top: calc((var(--stage-h) - min(var(--cw), calc(var(--ch) * var(--ar, 1.5))) / var(--ar, 1.5)) / 2);
  width: min(var(--cw), calc(var(--ch) * var(--ar, 1.5)));
  opacity: 1;
  z-index: 1;
}

.slide--next {
  left: calc(calc(100 * var(--vw)) - var(--tw) - clamp(24px, calc(3 * var(--vw)), 48px));
  width: var(--tw);
  opacity: 1;
  cursor: pointer;
}

/* the previous project, small on the left where the menu was */
.slide--before {
  left: clamp(24px, calc(3 * var(--vw)), 48px);
  width: var(--tw);
  opacity: 1;
  cursor: pointer;
}

.slide--prev {
  left: calc(var(--cw) * -1.2);
  width: min(var(--cw), calc(var(--ch) * var(--ar, 1.5)));
  opacity: 0;
  pointer-events: none;
}

.slide--later {
  left: calc(calc(100 * var(--vw)) + calc(4 * var(--vw)));
  width: var(--tw);
  opacity: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------ centre: description + extras */

/* sits directly under the big image; --cur-ar is the current image's aspect ratio */
.detail {
  position: relative;
  margin: calc((var(--stage-h) + min(var(--cw), calc(var(--ch) * var(--cur-ar, 1.5))) / var(--cur-ar, 1.5)) / 2 + 18px) 0 0 calc((calc(100 * var(--vw)) - min(var(--cw), calc(var(--ch) * var(--cur-ar, 1.5)))) / 2);
  width: min(var(--cw), calc(var(--ch) * var(--cur-ar, 1.5)));
  padding-bottom: calc(18 * var(--vh));
  opacity: 0;
  pointer-events: none;
}

.detail__desc {
  margin: 0;
  max-width: 34rem;
  font-size: clamp(13px, calc(0.95 * var(--vw)), 15px);
  line-height: 1.4;
}

.detail__desc strong {
  display: block;
}

.detail__desc:has(.detail__row) {
  max-width: none;
}

.detail__row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  column-gap: 2em;
}

.detail__extras {
  display: none;
}

.detail__extras img {
  display: block;
  width: 100%;
  margin-top: 28px;
}

/* ------------------------------------------------------------ browsing: hover description */

.slide--current {
  cursor: pointer;
}

.detail {
  transition: opacity 300ms ease;
}

@media (hover: hover) {
  body[data-mode="browse"].is-hovering .detail {
    opacity: 1;
  }
}

/* ------------------------------------------------------------ project mode: scroll down */

body[data-mode="project"] .center {
  overflow-x: hidden;
  overflow-y: auto;
}

body[data-mode="project"] .slide--next,
body[data-mode="project"] .slide--before {
  pointer-events: none;
}

body[data-mode="project"] .slide--next img,
body[data-mode="project"] .slide--before img {
  opacity: 0;
}

body[data-mode="project"] .detail {
  opacity: 1;
  pointer-events: auto;
}

body[data-mode="project"] .detail__extras {
  display: block;
}

/* ------------------------------------------------------------ about <-> work */

.project-list:not([hidden]),
.bio:not([hidden]) {
  animation: panel-in 300ms ease;
}

/* the hidden list still holds the name column's width, so the name doesn't jump */
.project-list[hidden] {
  display: inline-flex;
  visibility: hidden;
}

.bio[hidden] {
  display: none;
}

@keyframes panel-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ------------------------------------------------------------ narrow windows on a computer */

@media (max-width: 1024px) and (pointer: fine) {
  :root {
    --side: 0px;
    --bar: 112px;
    --top: 20px;
    --stage-h: calc(100 * var(--vh));                       /* images centre on the whole screen, not the space under the bar */
    --cw: calc(calc(100 * var(--vw)) - 52px);
    --ch: min(calc(58 * var(--vh)), calc(calc(100 * var(--vh)) - 2 * var(--bar) - 16px)); /* centred, this keeps them clear of the bar */
    --tw: calc(60 * var(--vw));
  }

  /* on phones 100vh runs past the visible screen; dvh is what's actually showing */
  @supports (height: 100dvh) {
    :root {
      --stage-h: 100dvh;
      --ch: min(58dvh, calc(100dvh - 2 * var(--bar) - 16px));
    }
  }

  /* the name and about/contact sit centred as one group */
  .side {
    right: 0;
    bottom: auto;
    width: auto;
    height: var(--bar);
    padding: 20px 16px 0;
    grid-template-columns: auto auto;
    grid-template-rows: auto;
    justify-content: center;
    background: #fff;
  }

  .name {
    font-size: 24px;
  }

  /* on phones about/contact sit beside the name to keep the bar short */
  .links {
    grid-column: 2;
    grid-row: 1;
    justify-self: start;
    margin-top: 0;
    font-size: 16px;
  }

  /* the list doesn't fit on a phone; swiping steps through projects instead */
  .project-list,
  .project-list[hidden] {
    display: none;
  }

  .bio {
    position: fixed;
    top: var(--bar);
    left: 0;
    right: 0;
    bottom: 0;
    height: auto !important;
    align-self: stretch;
    margin: 0;
    padding: 12px 16px 40px;
    -webkit-mask-image: none;
    mask-image: none;
    background: #fff;
    z-index: 3;
  }

  .center {
    top: 0;
    left: 0;
    touch-action: none;
  }

  body[data-mode="project"] .center {
    touch-action: pan-y;
  }



  /* a sliver of the next project at the right edge */
  .slide--next {
    left: calc(calc(100 * var(--vw)) - 20px);
  }

  .slide--later {
    left: calc(calc(100 * var(--vw)) + 8px);
  }

  /* and a sliver of the previous one at the left edge */
  .slide--before {
    left: calc(20px - var(--tw));
  }

  /* the phone bar stays put; there's no room for it in the row */
  .side,
  body[data-start="false"] .side {
    transform: none;
    will-change: auto; /* otherwise the bar traps the fixed bio inside itself */
    opacity: 1;
    pointer-events: auto;
  }

  .menu-button {
    display: none;
  }
}


/* ------------------------------------------------------------ phones and tablets */

@media (pointer: coarse) {
  /* browsing, the script turns the wheel; inside a project the page scrolls */
  .center {
    touch-action: none;
  }

  body[data-mode="project"] .center {
    touch-action: pan-x pan-y;
  }

  /* room past the description, so it doesn't end against the screen's edge */
  .detail {
    padding-bottom: 20px;
  }
}

/* small touch screens: smaller text, and the side columns take only what the menu needs,
   because browser bars can leave much less room than the phone's screen size suggests */
@media (pointer: coarse) and (max-width: 1024px),
       (pointer: coarse) and (max-height: 600px) {
  :root {
    --side: 146px;
    --cw: calc(calc(100 * var(--vw)) - 2 * var(--side) - 16px);
    --ch: calc(84 * var(--vh));
    --tw: 56px;
  }

  .side {
    padding-left: 12px;
    column-gap: 12px;
  }

  .name {
    font-size: 20px;
  }

  .links,
  .menu-button {
    font-size: 11px;
  }

  .project-list {
    font-size: 10px;
  }

  .bio {
    font-size: 11px;
  }

  .bio__lead {
    font-size: 12px;
  }

  .detail__desc {
    font-size: 11px;
  }
}

/* held sideways, the web layout just fits */
@media (pointer: coarse) and (orientation: landscape) {
  @supports (height: 100dvh) {
    :root {
      --vh: 1dvh;
    }
  }
}

/* held upright, the web layout turns 90 degrees clockwise: its left edge runs along the
   top of the screen, and the page's width and height swap. The script needs to know
   this too, for swipes: its `sideways` matches this same query */
@media (pointer: coarse) and (orientation: portrait) and (max-width: 1024px) {
  :root {
    --vw: 1vh;
    --vh: 1vw;
  }

  @supports (height: 100dvh) {
    :root {
      --vw: 1dvh;
    }
  }

  body {
    position: fixed;
    top: 0;
    left: 0;
    width: calc(100 * var(--vw));
    height: calc(100 * var(--vh));
    transform-origin: 0 0;
    transform: translateX(calc(100 * var(--vh))) rotate(90deg);
  }
}

.slide:focus-visible {
  outline: 1px solid #000;
  outline-offset: 6px;
}
