/* The catering dishes (src/scripts/dishes.ts). The script opens a dish (data-open) when it is
   pointed at or tapped. */

/* A lid is hinged at the back of its pan, on the right of the picture: opening, it tips up on that
   edge and lifts. --lift and --turn are how far it goes when fully open; --rise and --tilt are how
   much of that it has now. Here a dish is simply open or shut. With motion on, the script sets
   --rise and --tilt on each lid itself and moves it like the heavy thing it is. */
.catered__lid {
  --lift: 34%;
  --turn: 7deg;
  --rise: 0;
  --tilt: 0;
  transform-origin: 88% 100%;
  transform: translateY(calc(var(--lift) * var(--rise) * -1))
    rotate(calc(var(--turn) * var(--tilt) * -1));
}
/* the first lid's picture has more empty room round it, so the same lift is a smaller share of it */
.catered__lid[data-dish='1'] {
  --lift: 24%;
  --turn: 6deg;
}
.catered__art[data-open='1'] .catered__lid[data-dish='1'],
.catered__art[data-open='2'] .catered__lid[data-dish='2'],
.catered__art[data-open='3'] .catered__lid[data-dish='3'] {
  --rise: 1;
  --tilt: 1;
}

/* The steam's canvas (src/scripts/steam.ts): as wide as the picture and tall enough for the steam
   to climb behind the heading. It lies over the lids, because steam that leaves a pan rolls up in
   front of its lid, and under the heading, so the words stay crisp. It stays hidden until the
   script has steam to draw. */
.catered__mist {
  position: absolute;
  z-index: 2;
  left: 0;
  top: -70%;
  width: 100%;
  height: 125%;
  pointer-events: none;
}
/* The menu's dish slider: a ring of dishes on a red band, the chosen one in the middle with its
   name standing behind it. The section's heading and tabs are in site.css with the rest of the page.

   The script only says where each dish is on the ring, in --at: 0 is the middle, 1 and 2 are to
   its right, -1 and -2 to its left, and anything in between while the ring turns. What a dish does
   with that (where it stands, how big it is, how it tips on the way) is worked out here, so the
   layout at rest and every frame of a turn come from the same few numbers. */

/* ---------- The stage ---------- */

.menu__stage {
  /* The numbers a screen size may change. Lengths inside the stage are in cqw, 1% of its width. */
  --zoom: 100%; /* the stage's width against the page's */
  --room: 90; /* the widest the big name may be, in % of the stage's width */
  /* where the dishes stand, up from the stage's lower edge: high enough for the longest shadow to
     end on the band */
  --ground: 4.2;
  --step-1: 24.5; /* from the middle to the dish beside it, in % of the stage's width */
  --step-2: 16.5; /* from that dish to the one after it */
  --size-1: 0.6; /* a dish beside the middle, against its size in the middle */
  --size-2: 0.52; /* and the one after it */
  --drop: 1.1; /* how much lower the dishes at the sides stand */
  --far: 2.5; /* the place where a dish has faded away: the back of the ring */
  --fall: 6; /* how far a dish of a new set drops on to the band */

  container: menu-stage / inline-size;
  position: relative;
  isolation: isolate;
  width: min(var(--zoom), 1512px);
  aspect-ratio: 1512 / 360;
  /* centred even when it is wider than the page, which an auto margin cannot do */
  margin: clamp(40px, 10cqw, 151px) calc((100% - min(var(--zoom), 1512px)) / 2) 0;
  cursor: grab;
  touch-action: pan-y; /* a sideways drag turns the ring; up and down still scrolls the page */
  user-select: none;
  -webkit-user-select: none;
}
.menu__stage[data-held] {
  cursor: grabbing;
}

/* ---------- The name behind the dishes ---------- */

/* Its foot is on the band's upper edge and it is cut off there, so a name sinks into the band and
   the next one rises out of it. Only the foot is cut: the letters are free to stand above the stage. */
.menu__word {
  position: absolute;
  inset: auto 0 54.2%;
  height: 0; /* a line on the band's edge: names of different sizes come and go without moving it */
  color: var(--maroon);
  clip-path: inset(-100vmax -100vmax 0);
  pointer-events: none;
}
/* A short name is as tall as the design draws it; a long one is as large as fits the room, worked
   out from its number of letters (a letter of this face is about a third of its height wide). */
.menu__line {
  position: absolute;
  left: 50%;
  bottom: 0;
  translate: -50% 0;
  font-size: min(17.2cqw, calc(var(--room) * 1cqw / (var(--chars, 10) * 0.345)));
  line-height: 0.8;
  white-space: nowrap;
}

/* the band runs edge to edge even when the stage is capped at 1512 px */
.menu__band {
  position: absolute;
  inset: 45.8% -1% auto;
  height: 50.8%;
  background: #ed1d24;
  box-shadow: 0 0 0 100vmax #ed1d24;
  clip-path: inset(0 -100vmax);
}

/* ---------- The dishes ---------- */

.menu__dish {
  --w: 29.5; /* its width in the middle, in % of the stage's width */
  /* how far above the picture's lower edge the dish itself stands, against the picture's width:
     the room a plate's own shadow takes */
  --sink: 0.095;
  --lift: 1.5; /* how high it is carried on the way between the middle and the place beside it */
  --tilt: 7deg; /* how far it tips on that way */

  /* Read off --at */
  --a: max(var(--at), -1 * var(--at)); /* how far from the middle, on either side */
  --side: clamp(-1, var(--at) * 1000, 1); /* -1 left of the middle, 1 right of it */
  --swing: sin(var(--at) * 180deg); /* 0 in a place, 1 or -1 half-way between two */
  --busy: clamp(0, 1.6 - var(--a), 1); /* 1 for the two dishes changing places in the middle */
  --foot: calc(var(--w) * var(--sink) * 1cqw);

  position: absolute;
  left: 50%;
  bottom: calc(var(--ground) * 1cqw - var(--foot));
  z-index: calc(20 - 4 * var(--a)); /* the nearer the middle, the further in front */
  width: calc(var(--w) * 1cqw);
  margin-left: calc(var(--w) * -0.5cqw);
  /* it grows, shrinks and tips about the spot it stands on */
  transform-origin: 50% calc(100% - var(--foot));
  translate: calc(
      var(--side) * (var(--step-1) * min(var(--a), 1) + var(--step-2) * max(var(--a) - 1, 0)) * 1cqw
    )
    calc(
      (var(--drop) * min(var(--a), 1) - var(--lift) * var(--busy) * var(--swing) * var(--swing)) *
        1cqw
    );
  scale: calc(
    1 - (1 - var(--size-1)) * min(var(--a), 1) - (var(--size-1) - var(--size-2)) *
      clamp(0, var(--a) - 1, 1)
  );
  rotate: calc(var(--swing) * var(--tilt) * (0.4 + 0.6 * var(--busy)));
  opacity: clamp(0, (var(--far) - var(--a)) * 2.5, 1);
  pointer-events: none; /* the stage takes the drags; its pictures reach over the arrows below */
}
.menu__dish[data-kind='box'] {
  --w: 25.2;
  --sink: 0;
}
/* a bucket is tall: beside the middle it stands smaller, to stay clear of the name */
.menu__dish[data-kind='bucket'] {
  --w: 19;
  --sink: 0.012;
  --size-1: 0.52;
  --size-2: 0.45;
}
/* A set that goes round twice shows one dish on either side; the fourth is at the back. */
.menu__dish[data-set='packs'] {
  --far: 1.8;
}

/* Where a dish is when the ring is at rest. While it turns, the script sets --at itself. */
.menu__dish[data-slot='-2'] {
  --at: -2;
}
.menu__dish[data-slot='-1'] {
  --at: -1;
}
.menu__dish[data-slot='0'] {
  --at: 0;
}
.menu__dish[data-slot='1'] {
  --at: 1;
}
.menu__dish[data-slot='2'] {
  --at: 2;
}
.menu__dish[data-slot='out'] {
  --at: 0;
  visibility: hidden;
}
.menu__stage[data-turning] .menu__dish {
  will-change: translate, scale, rotate, opacity;
}

/* The picture and its shadow. They take the exits and entrances, so those never fight the place
   the dish itself is given above. */
.menu__art {
  position: relative;
  display: block;
  transform-origin: 50% calc(100% - var(--foot));
}
.menu__art img {
  position: relative;
  width: 100%;
}
/* The plates bring their shadow in the picture. The box has its own, cut to its shape, and a bucket
   gets a soft round one. A shadow thins while its dish is carried. */
.menu__art::before {
  position: absolute;
  opacity: calc(1 - 0.45 * var(--busy) * var(--swing) * var(--swing));
}
.menu__dish[data-kind='box'] .menu__art::before {
  content: '';
  left: -5.3%;
  bottom: calc(var(--w) * -0.122cqw);
  width: 118.4%;
  aspect-ratio: 667 / 237;
  background: url('/_astro/menu-cut-box-shadow.s3wkHd25.webp') center / 100% 100% no-repeat;
}
.menu__dish[data-kind='bucket'] .menu__art::before {
  content: '';
  left: -14%;
  bottom: -4.5%;
  width: 128%;
  height: 17%;
  background: radial-gradient(closest-side, rgb(74 4 8 / 0.7), rgb(74 4 8 / 0.4) 55%, transparent);
}

/* ---------- The pager ---------- */

.menu__pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding-block: var(--space-3) clamp(64px, 10cqw, 150px);
  color: var(--maroon);
}
/* Every name is in here, unseen, one on top of the other: the longest sets the width, so the
   arrows stay where they are whichever name shows. */
.menu__name {
  display: grid;
  justify-items: center;
  overflow: clip;
  padding-block: 0.06em;
  font-size: var(--fs-4xl);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.menu__name > * {
  grid-area: 1 / 1;
}
.menu__name-size {
  visibility: hidden;
}

/* ---------- Screen sizes ---------- */

/* Tablets and phones see the stage larger than the page, so the dish in the middle reads at their
   size; the dishes at the sides run off the edges like a carousel's. The name keeps to the page. */
@container page (max-width: 1100px) {
  .menu__stage {
    --zoom: 170%;
    --room: 54;
    aspect-ratio: 1512 / 400;
  }
}
@container page (max-width: 600px) {
  .menu__stage {
    --zoom: 230%;
    --room: 40;
    --step-1: 21;
    --fall: 4; /* the tabs are close above: a tall dish must not drop through them */
  }
  .menu__pager {
    gap: 12px;
  }
}

/* ---------- Motion ---------- */

/* A new name rises out of the band letter by letter while the old one sinks into it. Letters follow
   each other far more closely than the blocks of a group do, so they have a gap of their own. */
.menu__word {
  --letter-gap: 18ms;
}
[data-motion='on'] .menu__word[data-seen] [data-state='in'] .menu__letter {
  animation: menu-letter-in var(--dur-enter) var(--ease-out)
    calc(var(--dur-press) + var(--i) * var(--letter-gap)) backwards;
}
[data-motion='on'] .menu__word [data-state='out'] .menu__letter {
  animation: menu-letter-out var(--dur-hover) var(--ease-in-out)
    calc(var(--i) * var(--letter-gap) / 2) forwards;
}
/* A letter cannot simply be moved. A transform needs it in a box of its own, which undoes the kerning
   with its neighbours (the T and A of TANDOORI drift apart), and moving it with `top` counts as a
   layout shift. So while it travels the letter itself is not drawn and its shadow is, sharp and in
   the name's own colour: a shadow can be anywhere and costs the layout nothing. */
@keyframes menu-letter-in {
  from {
    color: transparent;
    text-shadow: 0 0.9em var(--maroon);
  }
  to {
    color: transparent;
    text-shadow: 0 0 var(--maroon);
  }
}
@keyframes menu-letter-out {
  from {
    color: transparent;
    text-shadow: 0 0 var(--maroon);
  }
  to {
    color: transparent;
    text-shadow: 0 0.9em var(--maroon);
  }
}

/* The name between the arrows rolls on the way the ring turned. */
.menu__pager {
  --way: 1;
}
.menu__pager[data-way='back'] {
  --way: -1;
}
[data-motion='on'] .menu__name [data-state='in'] {
  animation: menu-roll-in var(--dur-short) var(--ease-out) var(--stagger) backwards;
}
[data-motion='on'] .menu__name [data-state='out'] {
  animation: menu-roll-out var(--dur-hover) var(--ease-in-out) forwards;
}
@keyframes menu-roll-in {
  from {
    transform: translateY(calc(var(--way) * 105%));
  }
}
@keyframes menu-roll-out {
  to {
    transform: translateY(calc(var(--way) * -105%));
  }
}

/* The dish that was asked for touches down: it gives a little under its own weight, and the dishes
   beside it feel it a moment later, the nearer ones first. */
[data-motion='on']
  .menu__stage[data-landed]
  .menu__dish[data-slot='0']:not([data-phase])
  .menu__art {
  animation: menu-land var(--dur-short) var(--ease-in-out);
}
[data-motion='on']
  .menu__stage[data-landed]
  .menu__dish:not([data-slot='0'], [data-slot='out'], [data-phase])
  .menu__art {
  animation: menu-nudge var(--dur-short) var(--ease-in-out) calc(var(--a) * var(--stagger));
}
@keyframes menu-land {
  30% {
    transform: scale(1.03, 0.96);
  }
}
@keyframes menu-nudge {
  40% {
    transform: translateY(-4%);
  }
}

/* A tab swaps the sets: the dishes on the band shrink away from the outside in, then the new ones
   are set down from the middle out. Each falls, gives a little as it lands and settles. */
[data-motion='on'] .menu__dish[data-phase='leaving'] .menu__art {
  animation: menu-leave var(--dur-hover) var(--ease-in-out)
    calc((2 - min(var(--a), 2)) * var(--stagger) / 2) forwards;
}
[data-motion='on'] .menu__dish[data-phase='arriving'] .menu__art {
  animation: menu-arrive var(--dur-enter) linear calc(var(--dur-hover) + var(--a) * var(--stagger))
    backwards;
}
@keyframes menu-leave {
  to {
    opacity: 0;
    transform: translateY(8%) scale(0.8);
  }
}
@keyframes menu-arrive {
  from {
    opacity: 0;
    transform: translateY(calc(var(--fall) * -1cqw)) rotate(-5deg);
    animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.5);
  }
  30% {
    opacity: 1;
  }
  52% {
    transform: translateY(0) rotate(0deg) scale(1.04, 0.94);
    animation-timing-function: cubic-bezier(0.2, 0.7, 0.3, 1);
  }
  76% {
    transform: translateY(-3%) scale(0.99, 1.015);
    animation-timing-function: cubic-bezier(0.5, 0, 0.8, 0.5);
  }
  to {
    transform: translateY(0) scale(1);
  }
}
/* The live fire under "Since 1998" (src/scripts/fire.ts). The photo and the canvas share a hearth,
   which makes the entrance, so whichever of the two shows arrives the same way. The canvas carries the
   photo's class, so the same rules size and crop it, and it lies exactly over the photo. It stays
   hidden until the script lights it, so without the script the photo is the fire. */
.since__hearth {
  position: relative;
}
.since__flames {
  position: absolute;
  left: 0;
  bottom: 0;
  opacity: 0;
  pointer-events: none;
}
/* The canvas has its box's own pixels and crops the fire's picture itself, the way the photo's class crops the
   photo: the class must not crop the canvas a second time. */
canvas.since__flames {
  object-fit: fill;
}
.since__flames:not([hidden]) {
  display: block;
}

/* Lit while the section is off the screen, the canvas simply takes the photo's place, unseen. Lit
   on the screen (reached before the page had the fire ready, or motion switched back on), the fire
   fades in over the photo. */
.since[data-burning] .since__flames {
  opacity: 1;
}
.since[data-burning] img.since__fire {
  opacity: 0;
}
.since[data-catching] :is(img.since__fire, .since__flames) {
  transition: opacity var(--dur-long) var(--ease-in-out);
}
