.pop-howto {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-width: 900px;
  margin: 28px 0 0;
  padding: 0;
  list-style: none;
}
.pop-howto li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  border: 1.5px solid rgba(251, 248, 241, 0.25);
  border-radius: 12px;
  font-size: 15px;
}
.pop-howto b {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #ffd23f;
  color: #000;
  font: 600 14px var(--mono);
}
.pop-keys {
  margin: 10px 0 0;
  font: 500 12px var(--mono);
  letter-spacing: 0.06em;
  opacity: 0.7;
}
.pop-game {
  --toy-red: #e3322b;
  --toy-blue: #1f5fd6;
  --toy-navy: #0c2a6b;
  --toy-yellow: #ffd23f;
  display: grid;
  grid-template-columns: minmax(0, 520px) minmax(0, 1fr);
  gap: 32px;
  margin-top: 40px;
  align-items: start;
}

/* The machine: red case, blue control strip and board */
.pop-machine {
  position: relative;
  width: 100%;
  max-width: 520px;
  padding: 14px;
  border: 1.5px solid #000;
  border-radius: 24px;
  background: linear-gradient(165deg, #ff5b4d, var(--toy-red) 40%, #b9231d);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 22px 46px rgba(0, 0, 0, 0.5);
}
.pop-header {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: center;
  padding: 12px 14px;
  border: 1.5px solid #000;
  border-radius: 12px;
  background: var(--toy-blue);
}
.pop-dial {
  position: relative;
  width: 104px;
  height: 104px;
}
.pop-dial svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.dial-face {
  fill: #fff;
  stroke: #000;
  stroke-width: 2;
}
.dial-ticks line {
  stroke: var(--toy-navy);
  stroke-width: 3;
  stroke-linecap: round;
}
.dial-track {
  fill: none;
  stroke: #dfe7f7;
  stroke-width: 16;
}
.dial-time {
  fill: none;
  stroke: var(--toy-blue);
  stroke-width: 16;
  stroke-dasharray: 100;
  stroke-dashoffset: 0;
}
.pop-machine.urgent .dial-time {
  stroke: var(--toy-red);
}
.dial-seconds {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--toy-navy);
  font: 600 30px var(--serif);
}
.pop-machine.urgent .dial-seconds {
  color: var(--toy-red);
  animation: throb 1s ease-in-out infinite;
}
.pop-name {
  margin: 0;
  color: var(--toy-yellow);
  font: italic 600 clamp(26px, 3.2vw, 36px) / 1 var(--serif);
  letter-spacing: -0.02em;
  text-shadow: 2px 2px 0 #000;
}
.pop-tag {
  margin: 4px 0 10px;
  font-size: 14px;
}
.pop-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pop-controls button {
  padding: 7px 12px;
  border-color: #000;
  font-size: 14px;
}
.pop-hint {
  padding: 7px 0;
  color: var(--toy-yellow);
  font: 500 12px var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  animation: throb 1.6s ease-in-out infinite;
}
.arcade .pop-start {
  background: var(--toy-yellow);
  color: #000;
  border-color: #000;
}
.arcade .pop-start:disabled {
  opacity: 0.75;
  cursor: default;
}
.arcade .pop-controls button:disabled:not(.pop-start) {
  opacity: 0.45;
  cursor: default;
}

/* Board: 25 sunken holes */
.pop-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 12px;
  padding: 12px;
  border: 1.5px solid #000;
  border-radius: 12px;
  background: var(--toy-blue);
  box-shadow: inset 0 6px 14px rgba(0, 0, 0, 0.35);
}
.arcade .hole {
  position: relative;
  aspect-ratio: 1;
  padding: 12%;
  border: 0;
  border-radius: 10px;
  background: #2c6ce6;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.3);
  display: grid;
  place-items: center;
}
.hole svg {
  width: 100%;
  height: 100%;
  fill: var(--toy-navy);
  filter: drop-shadow(0 -1px 0 rgba(0, 0, 0, 0.6));
}
.hole .seated {
  position: absolute;
  inset: 12%;
}
.hole .seated svg,
.piece svg,
.pop-ghost svg {
  fill: var(--toy-yellow);
  stroke: #c79400;
  stroke-width: 2;
  filter: drop-shadow(0 3px 0 #a87b00);
}
.hole.nope {
  animation: shake 0.35s;
}

/* Tray of loose pieces */
.pop-tray {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: calc(5 * var(--cell, 86px) + 4 * 8px + 2 * 12px + 3px);
  gap: 8px;
  padding: 12px;
  border: 1.5px solid rgba(251, 248, 241, 0.25);
  border-radius: 12px;
  background: #22221f;
}
/* Same box as a hole (12% inset, square) so a piece is exactly the size of its hole */
.arcade .piece {
  min-width: 0;
  aspect-ratio: 1;
  padding: calc(12% - 1.5px);
  display: grid;
  line-height: 0;
  border: 1.5px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  touch-action: none;
  cursor: grab;
}
.arcade .piece:hover {
  border-color: rgba(251, 248, 241, 0.4);
}
.arcade .piece[aria-pressed="true"] {
  border-color: var(--toy-yellow);
  background: rgba(255, 210, 63, 0.15);
  box-shadow: 0 0 18px rgba(255, 210, 63, 0.45);
}
.piece svg {
  display: block;
  width: 100%;
  height: 100%;
  transition: transform 0.15s;
}
.piece.lifted {
  opacity: 0.25;
}
.arcade .piece.used {
  visibility: hidden;
}
.pop-tray.waiting .piece {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}
.pop-ghost {
  position: fixed;
  z-index: 50;
  aspect-ratio: 1;
  padding: 10px;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.12);
}
.pop-ghost svg {
  width: 100%;
  height: 100%;
}

/* Side panel */
.pop-side .arcade-label {
  margin-top: 0;
}
.pop-modes {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}
.pop-modes button {
  padding: 10px 14px;
  text-align: left;
}
.pop-modes button span {
  display: block;
  font: 500 12px var(--mono);
  letter-spacing: 0.06em;
  opacity: 0.75;
}
.pop-modes button[aria-pressed="true"] {
  background: var(--paper);
  color: var(--ink);
}
.pop-modes button:disabled {
  cursor: default;
}
.pop-best {
  min-height: 1em;
  margin: 0 0 20px;
  color: var(--lime);
  font: 500 12px var(--mono);
  letter-spacing: 0.1em;
}

/* The pop! */
.pop-machine.popped .pop-board {
  animation: spring 0.9s ease-out;
}
.arcade .piece.spilled {
  visibility: hidden;
}
/* Pieces flying across the whole page after the pop */
.pop-spill {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow: hidden;
  pointer-events: none;
}
.spill-piece {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}
.spill-piece svg {
  width: 100%;
  height: 100%;
  fill: var(--toy-yellow, #ffd23f);
  stroke: #c79400;
  stroke-width: 2;
  filter: drop-shadow(0 4px 0 #a87b00);
}
.pop-flash {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: #fff7d1;
  pointer-events: none;
  animation: flash 0.45s ease-out forwards;
}
/* Comic-book burst */
.pop-burst {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 80;
  width: min(80vw, 560px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: #e3322b;
  clip-path: polygon(
    50% 0%,
    61% 18%,
    82% 7%,
    79% 30%,
    100% 33%,
    85% 50%,
    100% 67%,
    79% 70%,
    82% 93%,
    61% 82%,
    50% 100%,
    39% 82%,
    18% 93%,
    21% 70%,
    0% 67%,
    15% 50%,
    0% 33%,
    21% 30%,
    18% 7%,
    39% 18%
  );
  animation: burst 1.7s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}
.pop-burst span {
  color: #ffd23f;
  font: italic 700 clamp(64px, 16vw, 150px) / 1 var(--serif);
  letter-spacing: -0.03em;
  text-shadow:
    4px 4px 0 #000,
    -2px -2px 0 #000,
    2px -2px 0 #000,
    -2px 2px 0 #000;
  transform: rotate(-8deg);
}
.arcade.quake {
  animation: quake 0.65s;
}
.pop-machine.won .pop-board {
  box-shadow:
    inset 0 6px 14px rgba(0, 0, 0, 0.35),
    0 0 0 4px var(--toy-yellow),
    0 0 40px rgba(255, 210, 63, 0.6);
}
.pop-result {
  position: absolute;
  inset: auto 24px 24px;
  z-index: 10;
  padding: 22px;
  border: 1.5px solid #000;
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.45);
}
.pop-result-big {
  margin: 0;
  font: italic 600 48px/1 var(--serif);
  color: var(--toy-red);
}
.pop-machine.won .pop-result-big {
  color: var(--toy-blue);
}
.pop-result-small {
  margin: 8px 0 16px;
  font-size: 16px;
}
.arcade .pop-again {
  padding: 10px 18px;
  border-color: #000;
  background: var(--toy-yellow);
  color: #000;
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}
@keyframes throb {
  50% {
    transform: scale(1.12);
  }
}
@keyframes spring {
  12% {
    transform: translateY(-56px) scale(1.07) rotate(-3deg);
  }
  32% {
    transform: translateY(10px) scale(0.97) rotate(2deg);
  }
  52% {
    transform: translateY(-16px) rotate(-1deg);
  }
  72% {
    transform: translateY(4px);
  }
}
@keyframes flash {
  from {
    opacity: 0.85;
  }
  to {
    opacity: 0;
  }
}
@keyframes burst {
  0% {
    transform: translate(-50%, -50%) scale(0.1) rotate(-30deg);
    opacity: 1;
  }
  22% {
    transform: translate(-50%, -50%) scale(1.15) rotate(6deg);
  }
  34% {
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
  }
  80% {
    transform: translate(-50%, -50%) scale(1.02);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.4);
    opacity: 0;
  }
}
@keyframes quake {
  10%,
  50%,
  90% {
    transform: translate(-10px, 6px) rotate(-0.4deg);
  }
  30%,
  70% {
    transform: translate(10px, -6px) rotate(0.4deg);
  }
}

/* Mid-size windows: split the space evenly so pieces can still match the holes */
@media (max-width: 1100px) {
  .pop-game {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
  }
}
@media (max-width: 900px) {
  .pop-game {
    grid-template-columns: 1fr;
  }
  .pop-howto {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}
/* Phones: while playing, pieces dock in a two-row strip at the bottom of the
   screen so the board and pieces are both in reach. Swipe sideways to browse. */
@media (max-width: 900px) {
  .pop-game.playing .pop-tray {
    max-width: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    grid-template-columns: none;
    grid-template-rows: repeat(2, var(--cell, 58px));
    grid-auto-flow: column;
    grid-auto-columns: var(--cell, 58px);
    overflow-x: auto;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    border-width: 1.5px 0 0;
    border-radius: 0;
    background: rgba(28, 28, 26, 0.97);
    box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.45);
  }
  .pop-game.playing .piece {
    touch-action: pan-x;
  }
  .arcade .pop-game.playing .piece.used {
    display: none;
  }
  .pop-game.playing .pop-side {
    padding-bottom: 160px;
  }
}
@media (max-width: 480px) {
  .pop-machine {
    padding: 10px;
    border-radius: 18px;
  }
  .pop-header {
    gap: 12px;
    padding: 10px;
  }
  .pop-dial {
    width: 80px;
    height: 80px;
  }
  .dial-seconds {
    font-size: 24px;
  }
  .pop-board,
  .pop-tray {
    gap: 6px;
    padding: 8px;
  }
  .pop-tray {
    max-width: calc(5 * var(--cell, 52px) + 4 * 6px + 2 * 8px + 3px);
  }
}
