.flip-art {
  --fa-tile: #e9e7cf;
  --fa-grout: #cecfaf;
  --fa-counter: #f3deb2;
  --fa-counter-line: #c4af86;
  display: grid;
  position: relative;
  isolation: isolate;
  width: 100%;
  min-width: 0;
  aspect-ratio: 28 / 15;
  overflow: hidden;
  background: var(--fa-tile);
  -webkit-user-select: none;
  user-select: none;
}

.flip-art[data-stage="freezer"] {
  --fa-tile: #e4e9d9;
  --fa-grout: #c8d4c2;
  --fa-counter: #e0d7b4;
}

.flip-art[data-stage="microwave"] {
  --fa-tile: #f2e5ca;
  --fa-grout: #decfb1;
}

.flip-art[data-stage="butter"] {
  --fa-tile: #f4e8c8;
  --fa-grout: #dfd2ad;
  --fa-butter: clamp(0, var(--butter-progress, 0), 1);
  touch-action: none;
}

.flip-art[data-stage="butter"].is-buttered {
  --fa-butter: 1;
}

.flip-art[data-stage="pan"] {
  --fa-tile: #e8e8d6;
  --fa-grout: #cdd3bc;
  --fa-pan-heat: clamp(0, var(--toast-level, 0), 1);
  --fa-surface-heat: var(--fa-pan-heat);
  --fa-raw-crust: #e7bd83;
  --fa-raw-crumb: #fff1ce;
  --fa-flip-time: 1380ms;
}

.flip-art[data-stage="served"] {
  --fa-tile: #f4e4c5;
  --fa-grout: #dfccac;
  --fa-counter: #eccea1;
}

.flip-art .fa-scene {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  pointer-events: none;
}

.fa-drawing {
  stroke: #3b382b;
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fa-flippable,
.fa-spatula,
.fa-turntable {
  transform-box: fill-box;
  transform-origin: center;
}

.fa-turntable {
  animation: fa-turntable 1.9s ease-in-out infinite alternate;
}

.flip-art[data-stage="microwave"].is-ready .fa-turntable { animation-play-state: paused; }

@keyframes fa-turntable {
  from { transform: translateX(-4px) scaleX(.93); }
  to { transform: translateX(4px) scaleX(1.04); }
}

.fa-pat {
  opacity: calc(1 - var(--fa-butter, 0));
  translate: calc(var(--fa-butter, 0) * 9px) calc(var(--fa-butter, 0) * 4px);
}

.flip-art.is-buttered .fa-knife { opacity: 0; transition: opacity .25s ease-out; }

.flip-butter-meter { display: flex; align-items: center; gap: 10px; margin-top: 12px; color: #64573f; font-size: 12px; font-weight: 700; }
.flip-butter-meter progress { width: min(155px, 40%); height: 10px; accent-color: #ac6c21; }
.flip-butter-meter span { font-variant-numeric: tabular-nums; }
.flip-dialog[data-game-stage="butter"]:not([data-butter-ready]) .flip-primary {
  min-height: 36px; padding: 4px 0; background: transparent; color: var(--flip-green);
  border: 0; box-shadow: none; font-size: 13px; text-decoration: underline; text-underline-offset: 3px;
}
.flip-dialog[data-game-stage="butter"]:not([data-butter-ready]) .flip-primary:disabled { text-decoration: none; }

.flip-art[data-stage="pan"] .fa-sandwich {
  /* The scoring window ends at .89 on each face. Only then does char appear. */
  --fa-char: clamp(0, (var(--fa-surface-heat, 0) - .89) * 9.1, 1);
}
.fa-toast-colour { opacity: clamp(0, (var(--fa-surface-heat, 0) - .02) * 2.2, 1); }
.fa-toast-amber { opacity: clamp(0, (var(--fa-surface-heat, 0) - .38) * 1.96, 1); }
.fa-toast-dark { opacity: var(--fa-char, 0); }
.fa-grill-reveal {
  opacity: 0;
  color: color-mix(in srgb, #c08a46, #81502e calc(var(--fa-char, 0) * 100%));
}
.fa-underside-sample { opacity: 0; }

.fa-overdone-puff { opacity: 0; }

/* The upper slice retains the colour it had at the flip. The crust in
   contact with the pan and the enlarged lower face follow the new timer. */
.flip-art[data-stage="pan"].is-face-up { --fa-surface-heat: var(--first-heat, .73); }
.flip-art.is-face-up .fa-grill-reveal { opacity: 1; }
.flip-art.is-second-side .fa-underside-sample {
  --fa-surface-heat: var(--fa-pan-heat);
  opacity: 1;
}

.flip-art.is-second-side .fa-underside-sample .fa-grill-reveal {
  opacity: clamp(0, (var(--fa-pan-heat) - .39) * 2.15, 1);
}

.flip-art.is-second-side .fa-lower-crust {
  fill: color-mix(in srgb, #edc48d, #bb8545 calc(var(--fa-pan-heat) * 100%));
}

.fa-cooking-wisps { display: none; }
.flip-dialog:is([data-pan-state="warming"], [data-pan-state="golden"], [data-pan-state="perfect"]) .fa-cooking-wisps {
  display: inline;
  opacity: clamp(0, calc(var(--fa-pan-heat) * 5), .85);
}
.fa-cooking-wisps path { animation: fa-pan-wisp 2.2s ease-in-out infinite; }
.fa-cooking-wisps path + path { animation-delay: -1.15s; }

@keyframes fa-pan-wisp {
  0% { opacity: 0; transform: translate(0, 4px); }
  30% { opacity: .76; }
  72% { opacity: .5; }
  100% { opacity: 0; transform: translate(4px, -14px); }
}

.flip-art.is-underdone:not(.is-face-up) .fa-grill-reveal { opacity: 0; }

.flip-art.is-overdone .fa-overdone-puff { opacity: .95; }

.fa-flight, .fa-flip-edge, .fa-toast-shadow { transform-box: fill-box; transform-origin: center; }
.fa-spatula { transform-origin: 13% 88%; }
.fa-flip-edge { opacity: 0; }

/* A half turn projects the slice from full width, through its edge, to
   negative width. Keep that reflected orientation when the animation ends. */
.flip-art.is-face-up .fa-flippable { transform: scaleX(-1); }
.flip-art.is-flipping .fa-flight { animation: fa-flight var(--fa-flip-time) both; }
.flip-art.is-flipping .fa-flippable { animation: fa-roll var(--fa-flip-time) linear both; }
.flip-art.is-flipping .fa-flip-edge { animation: fa-edge-on var(--fa-flip-time) linear both; }
.flip-art.is-flipping .fa-flippable .fa-grill-reveal { animation: fa-reveal-face var(--fa-flip-time) step-end both; }
.flip-art.is-flipping .fa-spatula { animation: fa-lift var(--fa-flip-time) both; }
.flip-art.is-flipping .fa-toast-shadow { animation: fa-pan-shadow var(--fa-flip-time) both; }

@keyframes fa-flight {
  0%, 19% { transform: translate(0,0) rotate(0); }
  30% { transform: translate(3px,-12px) rotate(-6deg); }
  46% { transform: translate(11px,-72px) rotate(2deg); }
  54% { transform: translate(13px,-81px) rotate(5deg); }
  65% { transform: translate(12px,-68px) rotate(8deg); }
  82% { transform: translate(4px,2px) rotate(2deg); }
  91% { transform: translate(1px,-4px) rotate(-1deg); }
  100% { transform: translate(0,0) rotate(0); }
}

@keyframes fa-roll {
  0%, 24% { transform: scaleX(1); }
  36% { transform: scaleX(.86); }
  46% { transform: scaleX(.46); }
  54% { transform: scaleX(0); }
  62% { transform: scaleX(-.46); }
  72% { transform: scaleX(-.87); }
  82%, 100% { transform: scaleX(-1); }
}

@keyframes fa-edge-on {
  0%, 44%, 65%, 100% { opacity: 0; }
  51%, 57% { opacity: 1; }
}

@keyframes fa-reveal-face {
  0% { opacity: 0; }
  54%, 100% { opacity: 1; }
}

@keyframes fa-lift {
  0% { transform: translate(0,0) rotate(0); }
  19% { transform: translate(39px,-19px) rotate(2deg); }
  31% { transform: translate(42px,-21px) rotate(-6deg); }
  43% { transform: translate(43px,-30px) rotate(-18deg); }
  62% { transform: translate(19px,-13px) rotate(-4deg); }
  84%, 100% { transform: translate(0,0) rotate(0); }
}

@keyframes fa-pan-shadow {
  0%, 23%, 84%, 100% { transform: scale(1); opacity: .55; }
  50%, 58% { transform: scale(.70,.65); opacity: .23; }
}

.fa-steam { animation: fa-steam-rise 2.8s ease-in-out infinite alternate; }

.fa-cheese-drape {
  transform-box: fill-box;
  transform-origin: center top;
  animation: fa-cheese-settle 1.7s cubic-bezier(.23,.63,.32,1) both;
}

@keyframes fa-cheese-settle {
  from { transform: scaleY(.85); }
  to { transform: scaleY(1); }
}

@keyframes fa-steam-rise {
  from { transform: translateY(1px); opacity: .73; }
  to { transform: translateY(-3px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .fa-cooking-wisps path { animation: none; opacity: .6; }
  .flip-art *,
  .flip-art *::before,
  .flip-art *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
