/* The menu under the page: a plain cream sheet with a Menu button, lying on top of a dark menu. Opening, the script
   lifts the sheet off it, tips it back and slides it aside in 3D; the shadow it throws on the menu and the light on
   its face are worked out from the sheet's corners. */
:root {
  --page: #000000;          /* the page */
  --paper: #f4efe5;         /* the sheet over the menu */
  --ink: #1f1c17;           /* the Menu button */
  --accent: #c4623a;        /* the Menu button under the pointer, and its focus ring */
  --under: #15130f;         /* the menu under the page */
  --under-ink: #efe7d7;     /* the menu's words */
  --gold: #e3a659;          /* the arrows and the current page in the menu */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap */
html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family: 'Hanken Grotesk Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* the scene: the depth for the page's turn is here */
.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  perspective: 1500px;
  perspective-origin: 50% 42%;
  background: var(--page);
}

/* ---------------------------------------------------------------- the menu under the page */
.menu {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 0 0 max(28px, 7vw);
  /* a flat colour: a gradient as big as the window had to be painted again at every shot of the page in 3D */
  background: var(--under);
  color: var(--under-ink);
}

.menu__links {
  display: grid;
  gap: 0.2vh;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: none;
}

.link {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  gap: 18px;
  padding: 2px 0;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* the words move on their variable axes: heavier and softer under the pointer */
.link__word {
  display: inline-block;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: clamp(40px, 6.6vw, 92px);
  line-height: 1.04;
  letter-spacing: -0.02em;
  font-variation-settings: 'opsz' 144, 'wght' 330, 'SOFT' 0, 'WONK' 0;
  transform-origin: 0 100%;
  transition: font-variation-settings 0.45s cubic-bezier(0.2, 0.7, 0.2, 1), color 0.3s ease;
}

.link__arrow {
  width: 34px;
  height: 20px;
  align-self: center;
  fill: none;
  stroke: var(--gold);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  transform: translateX(-12px);
  transition: opacity 0.3s ease, transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* the current page: its name in gold */
.link[aria-current='page'] .link__word {
  color: var(--gold);
}

.link.is-here .link__word,
.link:focus-visible .link__word {
  font-variation-settings: 'opsz' 144, 'wght' 520, 'SOFT' 100, 'WONK' 1;
  color: #fff;
}

.link.is-here .link__arrow,
.link:focus-visible .link__arrow {
  opacity: 1;
  transform: none;
}

.menu__links.is-pointing .link:not(.is-here) .link__word {
  color: color-mix(in srgb, var(--under-ink) 42%, var(--under));
}

.link:focus-visible::after {
  content: '';
  position: absolute;
  left: 22px;
  right: -8px;
  bottom: 2px;
  height: 2px;
  background: var(--gold);
}

/* ---------------------------------------------------------------- the shadow of the page, and the page */
/* the menu waits in the dark under the page: the script lightens it as the page lifts */
.dark {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0.7;
  pointer-events: none;
}

.shadow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.sheet {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

/* the page clips its content to a plain rectangle (cheap to move in 3D); the paper itself, with its rounded corners
   once lifted, is a layer of its own underneath, so rounding the corners never repaints the page */
.page {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 24px;
  isolation: isolate;
}

.page::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--paper);
  border-radius: var(--round, 0px);
}

/* the light on the page: one flat veil over it, warm and light where the page faces the lamp, dark where it turns away.
   The script sets its colour and strength; a flat colour with no gradient and no inner border costs almost nothing
   to draw, even on a page turned in 3D */
.sheet__light {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: var(--round, 0px);
  background: var(--veil, transparent);
}

/* while the page moves, the layers that change are given to the compositor */
.is-moving .sheet {
  will-change: transform;
}

.is-moving .dark {
  will-change: opacity;
}

/* the lifted page is a button that lays it back down */
.sheet__cover {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--round, 0px);
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.is-open .sheet__cover {
  display: block;
}

.sheet__cover:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 5px var(--gold);
}

/* ---------------------------------------------------------------- the page: the Menu button */
.burger {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  padding: 0 8px 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.25s ease;
}

.burger__icon {
  display: grid;
  place-content: center;
  gap: 5px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--paper);
}

.burger__icon i {
  display: block;
  width: 12px;
  height: 1.6px;
  border-radius: 2px;
  background: var(--ink);
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (hover: hover) and (pointer: fine) {
  .burger:hover {
    background: color-mix(in srgb, var(--ink) 86%, var(--accent));
  }

  .burger:hover .burger__icon i:first-child {
    transform: translateX(-2px);
  }

  .burger:hover .burger__icon i:last-child {
    transform: translateX(2px);
  }
}

.burger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* ---------------------------------------------------------------- narrower screens */
@media (max-width: 900px) {
  .link {
    gap: 12px;
  }

  .link:focus-visible::after {
    left: 16px;
  }

  .link__arrow {
    display: none;
  }
}
