:root {
  --vh: 1vh;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #efe8dc;
  font-family: Arial, "Helvetica Neue", sans-serif;
  touch-action: none;
}

button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
}

.puzzle-stage {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(100vw, calc(var(--vh) * 100 * 1500 / 2667));
  aspect-ratio: 1500 / 2667;
  overflow: hidden;
  transform: translate(-50%, -50%);
  background: #f7efdf url("./assets/puzzle/bg.png") center / 100% 100% no-repeat;
  container-type: inline-size;
}

.puzzle-info {
  position: absolute;
  right: 10%;
  top: 5%;
  z-index: 30;
  width: 10%;
  aspect-ratio: 94 / 99;
}

.puzzle-info img,
.puzzle-start img {
  width: 100%;
  height: 100%;
  display: block;
}

.puzzle-board {
  position: absolute;
  left: 17%;
  top: 15.9%;
  z-index: 5;
  width: 66%;
  aspect-ratio: 529 / 847;
}

.puzzle-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  z-index: 8;
}

.piece-layer {
  position: absolute;
  inset: 0;
  z-index: 12;
}

.puzzle-piece {
  position: absolute;
  z-index: 35;
  left: var(--x);
  top: var(--y);
  width: var(--piece-w);
  height: var(--piece-h);
  object-fit: contain;
  touch-action: none;
  cursor: grab;
  filter: drop-shadow(0 1.3cqw 0.9cqw rgba(84, 54, 30, 0.18));
  transform: rotate(var(--r));
  transition: filter 140ms ease;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  will-change: left, top, transform;
}

.is-scrambling .puzzle-piece {
  pointer-events: none;
  transition:
    left 940ms cubic-bezier(0.2, 0.86, 0.22, 1),
    top 940ms cubic-bezier(0.2, 0.86, 0.22, 1),
    transform 940ms cubic-bezier(0.2, 0.86, 0.22, 1),
    filter 140ms ease;
}

.is-ready .puzzle-piece {
  pointer-events: none;
}

.puzzle-piece.is-dragging {
  z-index: 80;
  cursor: grabbing;
  filter: drop-shadow(0 2cqw 1.4cqw rgba(84, 54, 30, 0.24));
  transition: none;
}

.puzzle-piece.is-correct {
  z-index: 6;
}

.puzzle-start {
  position: absolute;
  left: 24%;
  bottom: 12%;
  z-index: 60;
  width: 52%;
  aspect-ratio: 310 / 99;
  filter: drop-shadow(0 1.1cqw 0 rgba(90, 44, 20, 0.18));
}

.is-scrambling .puzzle-start {
  pointer-events: none;
}

.help-card {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 90;
  width: 68%;
  display: none;
  padding: 4.8% 5.4% 5.2%;
  border: 0.55cqw solid rgba(244, 119, 52, 0.22);
  border-radius: 4.5cqw;
  color: #794321;
  background:
    linear-gradient(rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0) 38%),
    #fff7dc;
  box-shadow:
    0 2.4cqw 0 rgba(169, 91, 39, 0.13),
    0 4cqw 7cqw rgba(95, 55, 26, 0.2);
  transform: translate(-50%, -50%);
}

.show-help .puzzle-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 85;
  background: rgba(255, 247, 232, 0.34);
  backdrop-filter: blur(1.2px);
}

.show-help .help-card {
  display: block;
}

.help-title {
  color: #f47734;
  font-size: 4.1cqw;
  font-weight: 950;
  line-height: 1;
  text-align: center;
  text-shadow: 0 0.28cqw 0 white;
  margin-bottom: 1.6cqw;
}

.help-steps {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1.15cqw;
  list-style: none;
}

.help-steps li {
  min-height: 6.6cqw;
  display: flex;
  align-items: center;
  padding: 1.45cqw 1.8cqw;
  border-radius: 2.2cqw;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: inset 0 0 0 0.25cqw rgba(244, 119, 52, 0.12);
  color: #794321;
  font-size: 2.35cqw;
  font-weight: 850;
  line-height: 1.24;
}

.help-close {
  position: absolute;
  right: -2.8cqw;
  top: -2.8cqw;
  width: 7.2cqw;
  aspect-ratio: 1;
  border-radius: 50%;
  color: white;
  background:
    linear-gradient(rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 45%),
    #f47734;
  box-shadow: 0 0.9cqw 0 rgba(174, 80, 30, 0.24);
  font-size: 4.4cqw;
  font-weight: 950;
  line-height: 1;
}
