/* The origami menu: a menu folded into a little square of indigo washi, on a white page. Pressed, it unfolds in 3D,
   sideways and then down like an accordion, into a sheet of paper with the menu printed on it. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #1d2a4d;           /* text and the indigo of the paper's outside */
  --muted: #5d6679;
  --paper: #f8f6ef;         /* the inside of the paper */
  --fold: #c9c3b4;          /* the creases on the inside */
  --wave: #2c3f6e;          /* the waves printed on the outside */
  --seal: #c8432f;          /* the red seal */
  --hover: #ece6d6;         /* under an entry pointed at */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Zen Kaku Gothic New', 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 stage: the menu in the middle of the page */
.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px 16px;
  /* piegato, il quadratino sta al centro e la scatola grande come il foglio aperto scende più giù della pagina: non
     deve allungarla */
  overflow-y: clip;
}

/* the red seal at the head of the sheet */
.seal {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--seal);
  color: #fff6ee;
  font-family: 'Shippori Mincho', serif;
  font-size: 17px;
  line-height: 1;
}

/* ---------------------------------------------------------------- the folded square and its sheet */
/* the box is as big as the open sheet; the folded square sits in its top right corner, and the sheet unfolds from
   there to the left and down */
.origami {
  position: relative;
  width: var(--sheet-w, 280px);
  height: var(--sheet-h, 560px);
  perspective: 1400px;
  perspective-origin: 50% 45%;
  -webkit-tap-highlight-color: transparent;
}

.origami__stage {
  position: absolute;
  right: 0;
  top: 0;
  transform-style: preserve-3d;
  transform-origin: 100% 0;
  pointer-events: none;
}

/* each face of the paper, placed by the script with a matrix from its top left corner; it has two sides */
.face {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  transform-style: preserve-3d;
}

.face__side {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.face__side--back {
  transform: rotateY(180deg);
  /* the outside of the paper: indigo, with waves */
  background:
    radial-gradient(circle at 50% 100%, var(--ink) 0 5px, var(--wave) 5px 7px, var(--ink) 7px 10px, var(--wave) 10px 12px, var(--ink) 12px 15px, var(--wave) 15px 17px, var(--ink) 17px 19.5px, transparent 20px) 0 0 / 40px 20px,
    radial-gradient(circle at 50% 100%, var(--ink) 0 5px, var(--wave) 5px 7px, var(--ink) 7px 10px, var(--wave) 10px 12px, var(--ink) 12px 15px, var(--wave) 15px 17px, var(--ink) 17px 19.5px, transparent 20px) 20px 10px / 40px 20px,
    var(--ink);
}

/* the menu printed on the inside, the whole sheet, moved so this face shows its own piece; the script says how far
   this face has opened (--show), and its entries come up with it */
.face__print {
  position: absolute;
  left: 0;
  top: 0;
}

.face__print .sheet__head,
.face__print .leaf {
  opacity: var(--show, 1);
  transform: translateY(calc((1 - var(--show, 1)) * 8px));
}

/* light and shade: the script sets how dark or bright each side is, from where it faces */
.face__shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* the soft shadow the paper casts on the page */
.origami__shadow {
  position: absolute;
  left: 0;
  top: 0;
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: rgba(20, 28, 48, 0.32);
  filter: blur(14px);
  pointer-events: none;
}

/* the button is the folded square: invisible, over it, and over the corner of the open sheet */
.origami__toggle {
  position: absolute;
  right: 0;
  top: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--paper);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.3s ease;
}

.origami__toggle.is-printed {
  color: var(--ink);
}

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

.origami__glyph {
  width: 22px;
  height: 22px;
  overflow: visible;
}

.origami__glyph line {
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* ---------------------------------------------------------------- the sheet with the menu */
.sheet {
  width: var(--sheet-w, 280px);
  height: var(--sheet-h, 560px);
  padding: 0 22px 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--paper);
  /* washi: long soft fibres (painted once by the script on a canvas), and the creases the folds have left */
  background-image:
    linear-gradient(90deg, transparent calc(50% - 6px), rgba(70, 60, 40, 0.07) 50%, rgba(255, 255, 255, 0.5) calc(50% + 1px), transparent calc(50% + 7px)),
    repeating-linear-gradient(180deg, transparent 0 calc(var(--cell, 140px) - 5px), rgba(70, 60, 40, 0.06) calc(var(--cell, 140px) - 1px), rgba(255, 255, 255, 0.6) var(--cell, 140px), transparent calc(var(--cell, 140px) + 5px)),
    var(--fibre, none);
  color: var(--ink);
}

.origami__nav {
  position: absolute;
  right: 0;
  top: 0;
  z-index: 2;
  visibility: hidden;
}

/* the head of the sheet is as tall as the folded square, so the button's cross sits in line with it */
.sheet__head {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  margin: 4px 0 18px;
  font-family: 'Shippori Mincho', serif;
  font-size: 22px;
  font-weight: 500;
}

.sheet__head .seal {
  width: 26px;
  height: 26px;
  font-size: 15px;
}

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

.leaf {
  display: grid;
  grid-template-columns: 40px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-items: center;
  padding: 10px 10px 10px 8px;
  border-radius: 8px;
  transition: background-color 0.25s ease;
}

.leaf__icon {
  grid-row: 1 / 3;
  width: 40px;
  height: 40px;
  padding: 9px;
  border: 1px solid color-mix(in srgb, var(--ink) 22%, transparent);
  border-radius: 50%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  transition: transform 0.5s cubic-bezier(0.34, 1.5, 0.5, 1), background-color 0.25s ease, color 0.25s ease;
}

.leaf__name {
  font-family: 'Shippori Mincho', serif;
  font-size: 21px;
  font-weight: 500;
  line-height: 1.15;
}

.leaf__note {
  font-size: 12.5px;
  color: var(--muted);
}

@media (hover: hover) and (pointer: fine) {
  .origami__nav .leaf:hover {
    background: var(--hover);
  }

  .origami__nav .leaf:hover .leaf__icon {
    background: var(--ink);
    color: var(--paper);
    transform: rotate(-12deg);
  }
}

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

.leaf[aria-current='page'] .leaf__icon {
  background: var(--seal);
  border-color: var(--seal);
  color: #fff6ee;
}

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