* { box-sizing: border-box }
html, body { height: 100%; margin: 0 }
body {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #020607;
}
#game {
  position: relative;
  width: min(88vw, calc(100vh - 100px), 560px);
  display: grid;
  gap: 10px;
}
h1 {
  justify-self: center;
  width: max-content;
  margin: 0 0 6px;
  color: #50ffe1;
  font: 900 clamp(28px, 7vmin, 46px)/.8 "Arial Black", Impact, sans-serif;
  letter-spacing: .08em;
  -webkit-text-stroke: 1px #020607;
  text-shadow:
    -1px -1px 0 #bafff4, 1px 1px 0 #148577,
    2px 2px 0 #0a4b49, 3px 3px 0 #ff3558,
    5px 5px 0 #4f1020, 0 0 10px #50ffe1;
}
#sound {
  position: absolute;
  top: -4px;
  right: 0;
  z-index: 3;
}
#sound-toggle {
  width: 30px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #0a4b49;
  background: #020607;
  color: #50ffe1;
  cursor: pointer;
}
#sound-toggle:hover, #sound-toggle:focus-visible {
  border-color: #50ffe1;
  outline: 0;
  box-shadow: 0 0 7px #50ffe1;
}
.speaker {
  position: relative;
  width: 19px;
  height: 14px;
}
.speaker::before {
  content: "";
  position: absolute;
  inset: 0 5px 0 0;
  background: currentColor;
  clip-path: polygon(
    0 36%, 32% 36%, 32% 28%, 48% 28%, 48% 20%,
    64% 20%, 64% 12%, 80% 12%, 80% 88%, 64% 88%,
    64% 80%, 48% 80%, 48% 72%, 32% 72%, 32% 64%, 0 64%
  );
}
.speaker::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 0;
  width: 2px;
  height: 2px;
  background: currentColor;
  box-shadow:
    2px 2px 0 currentColor, 2px 4px 0 currentColor,
    2px 6px 0 currentColor, 0 8px 0 currentColor;
}
#sound-toggle.muted { opacity: .45 }
#sound-toggle.muted .speaker::after { display: none }
#volume-menu {
  position: absolute;
  top: 32px;
  right: 0;
  width: 132px;
  padding: 12px;
  border: 1px solid #0a4b49;
  background: #020607;
  box-shadow: 4px 4px 0 #0a2325, 0 0 10px #0a2325;
}
#volume-menu[hidden] { display: none }
#volume { width: 100%; margin: 0; accent-color: #50ffe1; cursor: pointer }
#hud {
  display: flex;
  justify-content: space-between;
  font: 600 10px Arial, sans-serif;
  letter-spacing: .12em;
  color: #50ffe1;
}
#hud div { display: flex; gap: 8px }
#hud output { color: #50ffe1; text-shadow: 0 0 5px #50ffe1 }
#hud span { opacity: .55 }
#board {
  --n: 10;
  --line: 1px;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template: repeat(var(--n), 1fr) / repeat(var(--n), 1fr);
  gap: var(--line);
  padding: var(--line);
  position: relative;
  background: #0d3032;
  box-shadow: 0 0 0 var(--line) #123c3e, 0 0 12px rgba(80,255,225,.14);
}
#controls { display: none }
.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border: 0;
  outline: 0;
  background: #010506;
  cursor: pointer;
}
.wall {
  background: #061516 url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAQCAYAAAAMJL+VAAAANklEQVR4nGMQMrf8TwxmExUDY14dPaIwTD3DqAWjFlBuAYxBK8yAy2Zq+WzUglELqGABrfMBAJUBEfPGSXUSAAAAAElFTkSuQmCC") repeat;
  box-shadow: inset 2px 2px 0 #164143, inset -2px -2px 0 #041012;
  image-rendering: pixelated;
  cursor: default;
}
.open { box-shadow: inset 0 0 0 1px #0d3032 }
.kill { box-shadow: inset 0 0 0 1px #50ffe1 }
.danger { box-shadow: inset 0 0 0 1px #ff3558 }
.open:hover, .kill:hover { background: #0a2325 }
.danger:hover { background: #ff3558 }
.cube, .pyramid { position: relative; width: 64%; aspect-ratio: 1 }
.cube {
  filter:
    drop-shadow(0 0 2px rgba(89,255,140,.75))
    drop-shadow(0 0 5px rgba(23,201,91,.55));
}
.cube i, .pyramid i { position: absolute; inset: 0 }
.cube i:nth-child(1) {
  background: #baffcb;
  clip-path: polygon(
    0 24%, 8% 24%, 8% 16%, 16% 16%, 16% 8%, 24% 8%,
    24% 0, 100% 0, 100% 8%, 92% 8%, 92% 16%, 84% 16%,
    84% 24%, 76% 24%
  );
}
.cube i:nth-child(2) {
  background: #34e875;
  clip-path: polygon(0 24%, 76% 24%, 76% 100%, 0 100%);
}
.cube i:nth-child(3) {
  background: #118c4d;
  clip-path: polygon(
    76% 24%, 84% 24%, 84% 16%, 92% 16%, 92% 8%, 100% 8%,
    100% 76%, 92% 76%, 92% 84%, 84% 84%, 84% 92%,
    76% 92%, 76% 100%
  );
}
.pyramid {
  filter:
    drop-shadow(0 0 1px rgba(255,53,88,.55))
    drop-shadow(0 1px 1px rgba(80,255,225,.35));
}
.pyramid i:nth-child(1) {
  background: #55ffe1;
  clip-path: polygon(
    32% 0, 32% 8%, 40% 8%, 40% 24%, 48% 24%, 48% 48%,
    56% 48%, 56% 72%, 64% 72%, 64% 96%, 0 96%, 0 72%,
    8% 72%, 8% 48%, 16% 48%, 16% 24%, 24% 24%, 24% 8%, 32% 8%
  );
}
.pyramid i:nth-child(2) {
  background: #126f6d;
  clip-path: polygon(
    32% 0, 40% 0, 40% 8%, 48% 8%, 48% 16%, 56% 16%,
    56% 24%, 64% 24%, 64% 32%, 72% 32%, 72% 40%, 80% 40%,
    80% 48%, 88% 48%, 88% 56%, 96% 56%, 96% 64%, 88% 64%,
    88% 72%, 80% 72%, 80% 80%, 72% 80%, 72% 88%, 64% 88%,
    64% 96%, 64% 72%, 56% 72%, 56% 48%, 48% 48%, 48% 24%,
    40% 24%, 40% 8%, 32% 8%
  );
}
.pyramid::before, .pyramid::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}
.pyramid::before {
  background: #ff6b82;
  clip-path: polygon(32% 0, 32% 8%, 40% 8%, 40% 24%, 24% 24%, 24% 8%, 32% 8%);
}
.pyramid::after {
  background: #a81733;
  clip-path: polygon(
    32% 0, 40% 0, 40% 8%, 48% 8%, 48% 16%,
    48% 24%, 40% 24%, 40% 8%, 32% 8%
  );
}
.burst {
  position: absolute;
  z-index: 3;
  width: 4px;
  height: 4px;
  pointer-events: none;
  background: #fff;
  box-shadow:
    -7px -5px #ff3558, 7px -6px #50ffe1,
    -9px 6px #50ffe1, 8px 7px #ff3558,
    0 -10px #75ffe8, 10px 1px #a81733;
  animation: disintegrate .24s steps(4) forwards;
}
.burst.player {
  background: #baffcb;
  box-shadow:
    -7px -5px #34e875, 7px -6px #baffcb,
    -9px 6px #118c4d, 8px 7px #59ff8c,
    0 -10px #34e875, 10px 1px #baffcb;
  animation-duration: .28s;
}
.cube.popped { animation: pop .28s steps(4) forwards }
#board.dead { animation: hit .35s steps(2) }
@keyframes hit { 50% { filter: invert(1) } }
@keyframes disintegrate {
  0% { transform: scale(.6); opacity: 1 }
  50% { transform: scale(1) }
  100% { transform: scale(2); opacity: 0 }
}
@keyframes pop {
  0% { transform: scale(1) }
  25% { transform: scale(1.25); filter: brightness(2) }
  50% { transform: scale(.8) }
  100% { transform: scale(0); opacity: 0 }
}

@media (max-width: 700px), (pointer: coarse) {
  body {
    display: block;
    place-items: normal;
    overflow: auto;
    background: #020607;
  }

  #game {
    --deck-aspect: 1080 / 476;
    --deck-scale: calc(100vw / 1080);
    width: 100vw;
    justify-self: stretch;
    gap: 8px;
    padding-top: 10px;
  }

  #sound { right: 4.166667vw }
  #hud,
  #board {
    width: min(91.666667vw, 560px);
    justify-self: center;
  }

  #controls {
    position: relative;
    display: block;
    width: 100vw;
    height: auto;
    aspect-ratio: var(--deck-aspect);
    margin-top: 0;
    overflow: hidden;
    background:
      linear-gradient(180deg, #d6d1d5 0%, #d8cfd8 52%, #d1cdd1 100%);
    box-shadow:
      inset 0 1px 0 rgba(255,255,255,.50),
      inset 0 -10px 18px rgba(86,84,88,.08);
  }

  .control {
    position: absolute;
    z-index: 4;
    padding: 0;
    border: 0;
    background: transparent;
    touch-action: manipulation;
    user-select: none;
    cursor: pointer;
  }

  .control:disabled {
    opacity: .44;
    cursor: default;
  }

  .dpad {
    position: absolute;
    left: 8.240741%;
    top: 15.126050%;
    width: 24.907407%;
    height: 58.403361%;
    filter: drop-shadow(0 3px 4px rgba(0,0,0,.42));
  }

  .dpad::before,
  .dpad::after {
    content: "";
    position: absolute;
    background: linear-gradient(160deg,#09090b,#000);
    box-shadow:
      inset 0 5px 0 rgba(255,255,255,.16),
      inset 0 -6px 0 rgba(0,0,0,.45);
  }

  .dpad::before {
    left: 32.156134%;
    top: 0;
    width: 35.687732%;
    height: 100%;
    border-radius: 6%;
  }

  .dpad::after {
    left: 0;
    top: 32.733813%;
    width: 100%;
    height: 34.532374%;
    border-radius: 6%;
  }

  .dpad-center {
    position: absolute;
    z-index: 2;
    left: 50%;
    top: 50%;
    width: 11.895911%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle at 38% 30%, #fff, #9ea2a4 34%, #111 62%);
    transform: translate(-50%,-50%);
  }

  .dpad .control {
    width: max(35.687732%, 48px);
    height: max(34.532374%, 48px);
    transform: translate(-50%,-50%);
  }

  .control-up { left: 50%; top: 17.266187% }
  .control-left { left: 17.843866%; top: 50% }
  .control-right { left: 82.156134%; top: 50% }
  .control-down { left: 50%; top: 82.733813% }

  .wait-mount {
    position: absolute;
    left: 72.5%;
    top: 12.394958%;
    width: 23.333333%;
    height: 35.294118%;
    border-radius: 22%;
    background: linear-gradient(150deg,rgba(255,255,255,.32),rgba(173,168,174,.18));
    box-shadow: inset 0 1px 2px rgba(255,255,255,.28), 0 5px 10px rgba(99,93,100,.10);
    transform: rotate(-12deg);
  }

  .wait-button-visual {
    position: absolute;
    left: 88.055556%;
    top: 30.882353%;
    width: 12.962963%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle at 36% 28%, #d12a51 0 17%, #a7002d 60%, #590019 100%);
    box-shadow:
      inset 0 5px 6px rgba(255,255,255,.24),
      inset 0 -8px 8px rgba(0,0,0,.32),
      0 5px 8px rgba(0,0,0,.35);
    transform: translate(-50%,-50%);
  }

  .wait-control {
    left: 88.055556%;
    top: 30.882353%;
    width: max(12.962963vw,48px);
    aspect-ratio: 1;
    border-radius: 50%;
    transform: translate(-50%,-50%);
  }

  .wait-label,
  .reset-label {
    position: absolute;
    color: #050505;
    font: 900 4.166667vw/1 Arial, sans-serif;
    white-space: nowrap;
    transform-origin: center;
  }

  .wait-label {
    left: 92.5%;
    top: 53.151261%;
    transform: translate(-50%,-50%) rotate(-22deg);
  }

  .reset-pill {
    position: absolute;
    left: 47.037037%;
    top: 67.016807%;
    width: 14.629630%;
    height: 7.983193%;
    border-radius: 999px;
    background: linear-gradient(145deg,#f6f5fb,#9c99a1);
    box-shadow:
      inset 0 3px 3px rgba(255,255,255,.72),
      inset 0 -3px 4px rgba(56,52,58,.24),
      0 3px 5px rgba(0,0,0,.20);
    transform: translate(-50%,-50%) rotate(-28deg);
  }

  .reset-control {
    left: 47.037037%;
    top: 67.016807%;
    width: max(14.629630vw,48px);
    height: 48px;
    border-radius: 999px;
    transform: translate(-50%,-50%) rotate(-28deg);
  }

  .reset-label {
    left: 48.703704%;
    top: 83.193277%;
    transform: translate(-50%,-50%) rotate(-28deg);
  }

  .dpad .control:active,
  .wait-control:active,
  .reset-control:active {
    margin-top: 2px;
  }

  @media (min-width: 700px) and (pointer: coarse) {
    .wait-label,
    .reset-label { font-size: 29px }
  }
}
