* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}
body {
  display: grid;
  place-items: center;
  background: #282a23;
  color: #38281c;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}
body:before {
  content: "";
  position: fixed;
  inset: -32px;
  background:
    linear-gradient(#211f19a8, #211f19ad),
    url(assets/packing-counter.webp) center/cover;
  filter: blur(20px);
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible {
  outline: 3px solid #fff;
  box-shadow: 0 0 0 5px #6b4025;
}
#scene {
  position: relative;
  width: min(100vw, 66.6667vh);
  width: min(100vw, 66.6667dvh);
  aspect-ratio: 2/3;
  container-type: inline-size;
  background: #c4ad87 url(assets/packing-counter.webp) center/100% 100%;
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 0 60px #100d09aa;
  user-select: none;
}
nav {
  position: absolute;
  right: 2.5%;
  top: 1.5%;
  display: flex;
  gap: 1cqw;
}
nav button {
  background: #352c22e8;
  color: #fff7e8;
  border: 1px solid #fff5;
  border-radius: 30px;
  padding: 1.2cqw 1.9cqw;
  font-size: 2.8cqw;
  min-height: 6.2cqw;
}
#ticket {
  position: absolute;
  top: 8.4%;
  left: 50%;
  translate: -50% 0;
  padding: 2cqw 3cqw;
  background: #fff3d9;
  box-shadow: 1px 4px 6px #412a1a55;
  transform: rotate(3deg);
  display: grid;
  gap: 0.5cqw;
  text-align: center;
  font-size: 3.7cqw;
}
#ticket:before {
  content: "";
  height: 2.3cqw;
  width: 3cqw;
  border-radius: 3px;
  background: linear-gradient(90deg, #68533a, #dfc18d, #6c563c);
  position: absolute;
  left: 44%;
  top: -1.5cqw;
}
#ticket small,
#vip {
  font-size: 2.2cqw;
}
#vip:empty {
  display: none;
}
.cell {
  position: absolute;
  border: 1px solid #4f534151;
  border-radius: 1.3cqw;
  background: #fff7db0c;
  display: grid;
  place-items: center;
  padding: 0;
  touch-action: none;
}
.cell.tutorial,
.cell.aim {
  background: #ffd37b52;
  outline: 2px dashed #975714;
  outline-offset: -3px;
}
.cell.match {
  box-shadow: inset 0 0 0 2px #ffe29c;
}
.ice {
  background: linear-gradient(140deg, #ecffffdb, #abdaedc9 55%, #ecffffcb);
  font-size: 5cqw;
  color: #45869c;
} /* The sprite and cup seats share normalized coordinates on the same plane. */
.holder {
  position: relative;
  background: url(assets/pulp-side.webp) center/100% 100% no-repeat;
  filter: drop-shadow(0.18cqw 0.5cqw 0.32cqw #49331c59);
  pointer-events: none;
}
.holder .cup {
  position: absolute;
  height: auto;
  top: var(--seat);
  transform: translate(-50%, -83%);
  clip-path: inset(0 0 17% round 0 0 48% 48% / 0 0 18% 18%);
  pointer-events: none;
}
.slot {
  position: relative;
  width: 28%;
  height: 90%;
  padding: 0;
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
  touch-action: none;
}
.slot[aria-pressed="true"] .holder {
  outline: 0.65cqw solid #f4b84c;
  outline-offset: 0.7cqw;
}
.slot:disabled {
  opacity: 0.2;
}
#hand {
  position: absolute;
  inset: 79% 3% 5%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#hint {
  position: absolute;
  top: 73.2%;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 97%;
  background: #3c3026ed;
  color: #fff7df;
  border-radius: 2cqw;
  padding: 1.2cqw 2.8cqw;
  font-size: 3cqw;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}
.parcel {
  position: absolute;
  background: #b38651;
  color: #fff3ce;
  border: 2px solid #d6b587;
  border-radius: 15%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 3cqw;
  box-shadow: 0 4px 6px #51381a66;
  z-index: 4;
  pointer-events: none;
}
.ghost {
  position: fixed;
  z-index: 6;
  pointer-events: none;
  opacity: 0.9;
}
.flying {
  position: fixed;
  pointer-events: none;
  z-index: 5;
  object-fit: contain;
}
dialog {
  width: min(86%, 380px);
  padding: 24px;
  border: 1px solid #ac8b61;
  border-radius: 14px;
  background: #fff5df;
  color: #3d3022;
  box-shadow: 0 14px 50px #18120966;
}
dialog::backdrop {
  background: #2c261fcc;
}
dialog h2 {
  margin: 0 0 12px;
  font-size: 23px;
}
#message {
  line-height: 1.7;
  font-size: 15px;
  white-space: pre-line;
}
#actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}
#actions button {
  background: #3c5146;
  color: white;
  border: 0;
  border-radius: 6px;
  padding: 9px 15px;
}
#actions button:disabled {
  background: #d2c9b4;
  color: #665f52;
}
/* Preserve the photographed viewing angle across both counter surfaces. */
.cell,
.slot {
  container-type: size;
}
.cell > .holder,
.slot > .holder {
  position: absolute;
  left: 50%;
  bottom: 6%;
  transform: translateX(-50%);
  width: min(94cqw, 145cqh);
  aspect-ratio: 1/0.365;
  filter: drop-shadow(1px 2px 1px #42301955);
}
.slot > .holder {
  bottom: 10%;
}
.slot:disabled:has(.holder) {
  opacity: 0.7;
}
.cell:not(.ice):not(.tutorial):not(.aim) {
  border: 0;
  background: transparent;
}
.cell:not(.ice):not(.tutorial):not(.aim):not(:has(.holder))::before {
  content: "";
  position: absolute;
  inset: 5% 4%;
  pointer-events: none;
  --tick: linear-gradient(#534f3570, #534f3570);
  background:
    var(--tick) left top/12% 1px,
    var(--tick) left top/1px 14%,
    var(--tick) right top/12% 1px,
    var(--tick) right top/1px 14%,
    var(--tick) left bottom/12% 1px,
    var(--tick) left bottom/1px 14%,
    var(--tick) right bottom/12% 1px,
    var(--tick) right bottom/1px 14%;
  background-repeat: no-repeat;
}
.slot[aria-pressed="true"] .holder {
  outline: 0;
  filter: drop-shadow(0 0 0.38cqw #ffbd46)
    drop-shadow(0 0.55cqw 0.3cqw #54391c99);
}
.slot[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  bottom: 2%;
  width: 25%;
  height: 0.65cqw;
  background: #f7cd75;
  border-radius: 8px;
  box-shadow: 0 1px 2px #563e20;
}
#hint {
  font-size: 2.75cqw;
  background: #3b3025d9;
  border-radius: 0.8cqw;
}

.holder.loaded {
  background: none;
}
.cell > .holder.loaded,
.slot > .holder.loaded {
  width: 98cqw;
  height: 98%;
  bottom: 3%;
  aspect-ratio: auto;
}
.slot > .holder.loaded {
  height: 95%;
  bottom: 3%;
}
.loaded img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
}

.cell.ice {
  border: 0;
  background: transparent;
  color: #44757c;
  font-size: 2.9cqw;
  isolation: isolate;
}
.cell.ice::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 14% 10%;
  border-radius: 12%;
  background: linear-gradient(135deg, #ebfaf4bd, #a6cfd07d 55%, #edf2e4ad);
  border: 1px solid #f1f9e4a6;
  box-shadow:
    0 2px 1px #56665b59,
    inset 2px 2px 5px #ffffff80;
}

/* The phone plate has a 642px window, an elastic mat and a 392px serving shelf. */
@media (orientation: portrait) and (max-width: 767px) {
  body::before {
    display: none;
  }
  #scene {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
    background: #bbae8e;
    --window-height: min(75.71vw, 35%);
    --shelf-height: min(46.23vw, 22%);
  }
  #scene::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    border-style: solid;
    border-color: transparent;
    border-width: 0;
    border-image: url(assets/phone-window.webp) 642 0 392 fill /
      var(--window-height) 0 var(--shelf-height) stretch;
  }
  #board {
    position: absolute;
    top: var(--window-height);
    bottom: var(--shelf-height);
    left: 0;
    right: 0;
  }
  #board .cell {
    top: var(--row-top) !important;
    height: var(--row-height) !important;
    left: var(--column-left) !important;
    width: var(--column-width) !important;
  }
  nav {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    gap: 4px;
    z-index: 2;
  }
  nav button {
    min-height: 44px;
    min-width: 44px;
    font-size: 14px;
    padding: 0 9px;
  }
  #ticket {
    top: calc(var(--window-height) * 0.51);
    font-size: clamp(16px, 4.3vw, 24px);
  }
  #ticket small,
  #vip {
    font-size: clamp(11px, 2.8vw, 16px);
  }
  #hint {
    top: calc(100% - var(--shelf-height) + 2px);
    font-size: clamp(12px, 3.2vw, 17px);
    line-height: 1.3;
    padding: 4px 10px;
    z-index: 1;
  }
  #hand {
    inset: calc(100% - var(--shelf-height) + 30px) 2%
      max(8px, env(safe-area-inset-bottom));
  }
  .slot {
    width: 31%;
    height: 100%;
  }
  .slot > .holder.loaded {
    height: 94%;
    bottom: 5%;
    width: 97cqw;
  }
}

.packed-tray {
  object-position: center bottom;
}

.cell > .demo-tray {
  z-index: 3;
  opacity: 1;
  pointer-events: none;
}
.demo-tray img {
  transform-origin: center bottom;
  animation: demo-delivery 3.6s ease-in-out infinite both;
}
@keyframes demo-delivery {
  0%,
  12% {
    opacity: 0;
    transform: translate(var(--demo-x), var(--demo-y)) scale(var(--demo-scale));
  }
  20% {
    opacity: 0.8;
    transform: translate(var(--demo-x), var(--demo-y)) scale(var(--demo-scale));
  }
  58%,
  70% {
    opacity: 0.8;
    transform: none;
  }
  82%,
  100% {
    opacity: 0;
    transform: none;
  }
}
#scene:has(dialog[open]) .demo-tray {
  visibility: hidden;
}
@media (prefers-reduced-motion: reduce) {
  .demo-tray {
    display: none;
  }
}

/* Light crosses the counter; the shower is confined to the glass behind it. */
.window-light,
.window-rain {
  position: absolute;
  pointer-events: none;
}
.window-light {
  inset: 0;
  overflow: hidden;
}
.window-light::before {
  content: "";
  position: absolute;
  inset: -12%;
  background: linear-gradient(
    116deg,
    transparent 28%,
    #fff0b529 44%,
    transparent 59%
  );
  animation: window-sun 16s ease-in-out infinite alternate;
}
[data-weather="cloud"] .window-light::before,
[data-weather="shower"] .window-light::before {
  background: linear-gradient(
    112deg,
    transparent 8%,
    #49627a33 48%,
    transparent 86%
  );
  animation-duration: 12s;
}
.window-rain {
  display: none;
  top: 0;
  left: 43%;
  right: 0;
  height: 24%;
  overflow: hidden;
  mask-image: linear-gradient(#0009, #000 65%, transparent);
}
[data-weather="shower"] .window-rain {
  display: block;
}
.window-rain::after {
  content: "";
  position: absolute;
  top: -35px;
  left: 0;
  width: 1px;
  height: 10px;
  background: #edf7ff88;
  box-shadow:
    3cqw 5cqw #edf7ff77,
    9cqw 13cqw #edf7ff66,
    16cqw 4cqw #edf7ff88,
    21cqw 19cqw #edf7ff77,
    28cqw 8cqw #edf7ff88,
    32cqw 22cqw #edf7ff66,
    39cqw 4cqw #edf7ff99,
    43cqw 14cqw #edf7ff77,
    51cqw 21cqw #edf7ff88,
    57cqw 8cqw #edf7ff66,
    60cqw 17cqw #edf7ff77;
  animation: window-rain 1.35s linear infinite;
}
@keyframes window-sun {
  from {
    transform: translateX(-12%);
    opacity: 0.25;
  }
  to {
    transform: translateX(12%);
    opacity: 1;
  }
}
@keyframes window-rain {
  0% {
    opacity: 0;
    transform: skewX(-11deg);
  }
  20%,
  75% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform: translate(-8px, 42px) skewX(-11deg);
  }
}
#ticket {
  transform-origin: 50% 0;
}
@media (orientation: portrait) and (max-width: 767px) {
  .window-rain {
    left: 33%;
    height: calc(var(--window-height) * 0.66);
  }
}
@media (prefers-reduced-motion: reduce) {
  .window-light::before,
  .window-rain::after {
    animation: none;
  }
}

.slot[data-caption]:not([data-caption=""])::after {
  content: attr(data-caption);
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  height: auto;
  background: #453627;
  color: #fff2da;
  border-radius: 4px;
  padding: 2px 6px;
  line-height: 1.3;
  font-size: clamp(11px, 2.5vw, 15px);
}
.slot[data-caption]:not([data-caption=""]) > .holder {
  bottom: 17%;
}
.slot[data-caption="下一托"] {
  opacity: 0.78;
}

.last-cup #hint,
.last-cup .slot:nth-child(3) {
  display: none;
}
.last-cup #hand {
  justify-content: space-evenly;
}
.last-cup .slot:nth-child(2) {
  align-self: flex-start;
  height: 72%;
  width: 23%;
}
.last-cup .slot img {
  transform-origin: center bottom;
}
nav a {
  display: grid;
  place-items: center;
  min-width: 34px;
  min-height: 34px;
  padding: 0 6px;
  background: #352c22e8;
  border: 1px solid #fff5;
  border-radius: 30px;
  color: #fff7e8;
  text-decoration: none;
  font-size: 20px;
}
@media (orientation: portrait) and (max-width: 767px) {
  nav a {
    min-width: 44px;
    min-height: 44px;
  }
}
