:root {
  --bg: #ffffff;            /* the page */
  --ink: #161513;           /* the words and the button */
  --muted: #8b867d;         /* the notes on the right */
  --paper: rgba(245, 240, 229, 0.74); /* the tissue paper: thin, so the sheet below shows through */
  --edge: rgba(22, 21, 19, 0.2);    /* the hairline edge of every sheet */
  --fold: #e2dccf;          /* the folded corner of the sheet under the pointer */
  --accent: #e2482c;        /* the vermilion corner of the page you are on */
  --focus: #161513;         /* the keyboard focus ring */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
}

body {
  font-family: 'Fraunces Variable', Georgia, serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.stage {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
}

/* the frame: its size is set by the script from the window (--w, --step, --sheet-h), so the whole menu, open and
   closed, always fits; the button stays on top, the sheets fall under it */
.pad {
  position: relative;
  width: var(--w, 360px);
  height: var(--frame-h, 380px);
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- the button */
.toggle {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 54px;
  margin: 0 auto;
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.toggle:focus-visible {
  outline: 1.5px solid var(--focus);
  outline-offset: 2px;
}

.toggle__icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 18px;
}

.toggle__icon svg { overflow: visible; }

.toggle__sheet {
  fill: var(--paper);
  stroke: var(--ink);
  stroke-width: 1.2;
}

.toggle__words {
  position: relative;
  display: grid;
  height: 26px;
  overflow: hidden;
}

.toggle__word {
  grid-area: 1 / 1;
  font-size: 21px;
  line-height: 26px;
  letter-spacing: -0.01em;
  font-variation-settings: 'wght' var(--wght, 380), 'opsz' 24, 'SOFT' 50;
}

.toggle__word[data-word-close] { transform: translateY(100%); }

/* ---------------------------------------------------------------- the sheets */
.menu {
  position: absolute;
  left: 0;
  right: 0;
  top: 70px;
  perspective: 900px;
  perspective-origin: 50% 0%;
}

.menu[inert] { pointer-events: none; }

.sheets {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
  height: calc(var(--step, 56px) * 4 + var(--sheet-h, 66px));
  transform-style: preserve-3d;
}

/* every sheet hangs from its top edge, like a page of a pad: GSAP moves and turns the li, the CSS styles what is
   inside it */
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: var(--sheet-h, 66px);
  transform-origin: 50% 0%;
  opacity: 0;
}

.sheet__link {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--step, 56px) * 0.2) 20px 0 20px;
  color: var(--ink);
  text-decoration: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.sheet__paper {
  position: absolute;
  inset: 0;
  border-radius: 2px;
  background-color: var(--paper);
  /* the fibres of the tissue: a little turbulence, very faint */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='80'><filter id='f'><feTurbulence type='fractalNoise' baseFrequency='0.9 0.08' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0.45  0 0 0 0 0.42  0 0 0 0 0.36  0 0 0 0.11 0'/></filter><rect width='100%' height='100%' filter='url(%23f)'/></svg>");
  box-shadow: inset 0 0 0 1px var(--edge), 0 12px 16px -16px rgba(22, 21, 19, 0.45);
}

.sheet__word {
  position: relative;
  font-size: var(--word, 28px);
  line-height: 1;
  letter-spacing: -0.015em;
  font-variation-settings: 'wght' var(--wght, 330), 'opsz' 72, 'SOFT' var(--soft, 30);
  white-space: nowrap;
}

.sheet__note {
  position: relative;
  margin-top: 0.45em;
  font-size: 13px;
  line-height: 1.2;
  color: var(--muted);
  font-style: italic;
  font-variation-settings: 'wght' 360, 'opsz' 12;
  white-space: nowrap;
}

/* the dog-ear in the top right corner: a triangle of folded paper; vermilion on the page you are on */
.sheet__fold {
  position: absolute;
  top: 0;
  right: 0;
  width: 20px;
  height: 20px;
  background: linear-gradient(225deg, var(--bg) 0 50%, var(--fold) 50% 100%);
  box-shadow: -1px 1px 0 var(--edge);
  clip-path: polygon(0 0, 100% 100%, 0 100%);
  transform-origin: 100% 0%;
  transform: scale(0);
}

.sheet__link[aria-current='page'] .sheet__fold {
  background: linear-gradient(225deg, var(--bg) 0 50%, var(--accent) 50% 100%);
}

.sheet__link:focus-visible .sheet__paper {
  box-shadow: inset 0 0 0 1.5px var(--focus), 0 12px 16px -16px rgba(22, 21, 19, 0.45);
}

@media (max-width: 380px) {
  .sheet__note { display: none; }
}
