/* The candy wrapper menu: a sweet in ruby foil with twisted ends on a white page. Pressed, the wrapper untwists,
   unrolls and lies flat with its creases, and the menu is printed on the foil. */
:root {
  --page: #ffffff;          /* the page */
  --foil: #b0173f;          /* the coloured foil of the wrapper */
  --foil-shine: #ffd9c7;    /* the colour the foil takes in its brightest glints */
  --lining: #d9d4cc;        /* the silver paper inside the wrapper */
  --print: #fff1de;         /* the cream ink printed on the foil */
  --shade: #4a0717;         /* the shadow on the page, and the ink's own shadow */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--print);
  font-family: 'Fraunces Variable', Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

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

/* the stage: the menu in the middle of the page */
.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px 16px;
}

/* ---------------------------------------------------------------- the candy and its wrapper */
/* the box is as big as the flat wrapper; the candy sits in its middle */
.candy {
  position: relative;
  width: min(320px, calc(100vw - 32px));
  height: 440px;
  -webkit-tap-highlight-color: transparent;
}

/* the canvas reaches past the box, so the twisted ends and the glints are never cut */
.candy__gl {
  position: absolute;
  left: -40px;
  top: -40px;
  width: calc(100% + 80px);
  height: calc(100% + 80px);
  pointer-events: none;
}

/* the soft shadow on the page: the script gives it its size, place and softness */
.candy__shadow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 200px;
  height: 20px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--shade) 55%, transparent);
  filter: blur(10px);
  pointer-events: none;
}

/* the button: over the candy while it is wrapped, and the little cross in the corner of the flat wrapper */
.candy__toggle {
  position: absolute;
  z-index: 3;
  left: 40px;
  top: 188px;
  width: 240px;
  height: 64px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 32px;
  background: transparent;
  color: var(--print);
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.candy.is-open .candy__toggle:focus-visible {
  outline-color: var(--print);
  outline-offset: 0;
}

/* the word is printed on the foil by the script: here it is for screen readers only */
.candy__word {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.candy__cross {
  grid-area: 1 / 1;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  opacity: 0;
  filter: drop-shadow(0 1px 0 color-mix(in srgb, var(--shade) 45%, transparent));
}

/* ---------------------------------------------------------------- the menu printed on the flat wrapper */
.candy__nav {
  position: absolute;
  z-index: 2;
  inset: 10px;
  display: grid;
  align-content: center;
  padding: 56px 44px 48px;
  pointer-events: none;
}

.candy.is-open .candy__nav {
  pointer-events: auto;
}

.candy__list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sweet {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 1px;
  padding: 8px 10px 9px;
  border-radius: 14px;
  text-align: center;
  color: var(--print);
  /* the ink sits in the foil: a hair of shadow under it, the way print on foil catches the light */
  text-shadow: 0 1px 0 color-mix(in srgb, var(--shade) 50%, transparent);
}

.sweet__name {
  font-size: 26px;
  line-height: 1.1;
  font-weight: 460;
  font-variation-settings: 'opsz' 72, 'SOFT' 100, 'WONK' 1;
  letter-spacing: -0.005em;
  transition: font-weight 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), letter-spacing 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.sweet__note {
  font-size: 12.5px;
  font-style: italic;
  font-weight: 380;
  font-variation-settings: 'opsz' 9, 'SOFT' 50;
  opacity: 0.82;
}

/* the chosen page: its name is stamped in a thin oval of the same ink */
.sweet[aria-current='page']::before {
  content: '';
  position: absolute;
  inset: 2px 8px;
  border: 1px solid color-mix(in srgb, var(--print) 70%, transparent);
  border-radius: 40px;
  pointer-events: none;
}

.sweet[aria-current='page'] .sweet__name {
  font-weight: 640;
}

@media (hover: hover) and (pointer: fine) {
  .sweet:hover .sweet__name {
    font-weight: 620;
    letter-spacing: 0.01em;
  }
}

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

.sweet:focus-visible .sweet__name {
  font-weight: 620;
}

/* ---------------------------------------------------------------- without WebGL */
/* the wrapper is a flat gradient of foil: the menu still opens and closes */
.no-gl .candy__gl {
  display: none;
}

.no-gl .candy__toggle {
  background: linear-gradient(160deg, color-mix(in srgb, var(--foil) 70%, white), var(--foil) 45%, color-mix(in srgb, var(--foil) 70%, black));
  font-size: 20px;
  font-variation-settings: 'opsz' 72, 'SOFT' 100;
}

.no-gl .candy__word {
  grid-area: 1 / 1;
  position: static;
  width: auto;
  height: auto;
  clip-path: none;
}

.no-gl .candy.is-open .candy__toggle {
  background: transparent;
}

.no-gl .candy.is-open .candy__word {
  display: none;
}

.no-gl .candy.is-open .candy__cross {
  opacity: 1;
}

.no-gl .candy:not(.is-open) .candy__nav {
  visibility: hidden;
}

.no-gl .candy.is-open .candy__nav {
  border-radius: 6px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--foil) 75%, white), var(--foil) 40%, color-mix(in srgb, var(--foil) 70%, black));
}

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