.demo {
  --arcade-ink: #141323;
  --arcade-panel: #221d35;
  --arcade-mint: #91f4d8;
  --arcade-peach: #ffd1a1;
  --arcade-pink: #ff83a5;
  width: min(96vw, 43rem, calc((100dvh - 13rem) * 1.48 + 2rem));
  min-width: min(94vw, 23rem);
  padding: 0.75rem 1rem;
  color: #fff2e0;
  border-color: #775776;
  background: var(--arcade-ink);
  box-shadow: 0 0 0 3px #291b36, 0 1.25rem 4rem #080510;
  font-family: 'Courier New', monospace;
}

.demo form { margin: 0 0 0.55rem; }
.demo .audio-toggle,
.demo .close-dialog { min-height: 2.4rem; height: 2.4rem; border-color: #775776; border-radius: 0; background: var(--arcade-panel); }
.demo .audio-toggle:hover, .demo .close-dialog:hover { color: #fff; border-color: var(--arcade-pink); }
.demo .audio-mark, .demo .audio-state { color: var(--arcade-mint); }
.demo .audio-toggle[aria-pressed="false"] .audio-state { color: #dfbacf; }

.demo h2 {
  color: var(--arcade-peach);
  font: 900 clamp(1.35rem, 4.75vw, 2.15rem)/1 'Courier New', monospace;
  letter-spacing: -0.06em;
  text-transform: uppercase;
}

.demo h2 span {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--arcade-pink);
  font-size: 0.53em;
  letter-spacing: 0.09em;
}

.arcade-hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.15rem 0.65rem;
  margin-top: 0.75rem;
  padding: 0.4rem 0.55rem;
  color: var(--arcade-mint);
  background: var(--arcade-panel);
  border: 1px solid #544763;
  border-bottom: 0;
  text-align: left;
  font-size: 0.88rem;
}

#arcade-task { color: var(--arcade-peach); }
.arcade-screen { position: relative; isolation: isolate; container-type: inline-size; border: 1px solid #775776; background: #37243e; }
#arcade-field { display: block; width: 100%; height: auto; image-rendering: pixelated; }
#arcade-field:focus-visible { outline: 2px solid var(--arcade-mint); outline-offset: -2px; }

.arcade-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  padding: 0.7rem;
  background: linear-gradient(transparent 35%, #151324dd 78%);
}
.arcade-overlay p { max-width: 32ch; margin: 0; font-size: 0.9rem; font-weight: bold; text-shadow: 1px 2px #141323; }
.arcade-button {
  min-height: 2.75rem;
  padding: 0.4rem 0.85rem;
  border: 2px solid #ffc2b2;
  background: #ff967c;
  color: #24192d;
  box-shadow: inset -3px -3px #cd5e74, 3px 3px #291732;
  font: 900 0.95rem 'Courier New', monospace;
  text-transform: uppercase;
}
.arcade-button:hover, .arcade-button:active { background: #ffbe97; }

.arcade-screen:has(.arcade-result) { overflow: hidden; }
.arcade-overlay.arcade-result {
  inset: 7% 30% 8% 8%;
  justify-content: space-between;
  padding: 2.2cqw;
  border: 2px solid var(--arcade-pink);
  background: transparent;
  box-shadow: 0 0 0 100cqw #1512218f, inset 0 0 0 2px #704661;
}
#arcade-game-over {
  color: var(--arcade-peach);
  font: 900 clamp(1rem, 7.8cqw, 3.05rem)/1 'Courier New', monospace;
  text-shadow: 2px 2px #a84264;
  white-space: nowrap;
}
.arcade-result .arcade-button { min-height: clamp(2rem, 13cqw, 2.75rem); }
.demo:has(.arcade-result) :is(.arcade-touch, .arcade-keys) { display: none; }

.arcade-banner {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: repeating-linear-gradient(158deg, #21142b6e 0 2px, #21142b56 2px 8px);
  opacity: var(--intro-opacity, 0);
  pointer-events: none;
}

.arcade-portrait {
  position: absolute;
  left: 6%;
  bottom: 9%;
  width: 48%;
  aspect-ratio: 1;
  overflow: hidden;
  background: #743e58;
  border: 3px solid var(--arcade-peach);
  box-shadow: 5px 5px #241830, -5px -5px #e26e87;
  transform: translateX(calc(-1 * var(--intro-offset, 140%)));
}

.arcade-portrait img, .arcade-cast img {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 300%;
  max-width: none;
  height: auto;
}

.arcade-boss-name {
  position: absolute;
  left: 47%;
  right: 7%;
  top: 36%;
  display: grid;
  justify-items: center;
  padding: 1cqw 3cqw 0;
  color: #ffe6ad;
  background: repeating-linear-gradient(135deg, #64334f 0 6px, #462745 6px 12px);
  border-top: 3px solid #ff92a4;
  box-shadow: 4px 4px #241830;
  transform: translateX(var(--intro-offset, 140%)) skew(-8deg);
  font: 900 18cqw/0.95 'Arial Black', Impact, sans-serif;
  text-shadow: 3px 3px #a94062;
}
.arcade-boss-name small {
  width: calc(100% + 6cqw);
  padding: 0.45em 0.25em;
  color: #152f38;
  background: var(--arcade-mint);
  font: bold 4.2cqw/1 'Courier New', monospace;
  letter-spacing: 0.12em;
  text-shadow: none;
}

.arcade-mission {
  background: linear-gradient(110deg, #24203840, #242038cf);
}
.arcade-mission .arcade-portrait {
  left: 5%;
  bottom: 15%;
  width: 39%;
  border-color: var(--arcade-mint);
  box-shadow: 4px 4px #21172f, -4px -4px #589f9c;
}
.arcade-mission .arcade-portrait img { left: -100%; }
.arcade-mission-brief {
  position: absolute;
  inset: 12% 4% auto 47%;
  padding: 2cqw;
  color: #fff0d0;
  background: #253141;
  border-block: 2px solid #8bd6c6;
  box-shadow: 4px 4px #22172e;
  text-align: left;
  transform: translateX(var(--intro-offset, 140%));
}
.arcade-mission-brief strong {
  color: var(--arcade-mint);
  font: 900 8.5cqw/1 'Courier New', monospace;
  letter-spacing: 0.08em;
  text-shadow: 2px 2px #153632;
}
.demo .arcade-mission-brief p {
  margin: 1.4cqw 0 2cqw;
  font-size: 4.1cqw;
  font-weight: bold;
  line-height: 1.2;
}
.arcade-cast {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.2cqw;
  text-align: center;
  font-size: 3.2cqw;
}
.arcade-cast figure { margin: 0; }
.arcade-cast span {
  position: relative;
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  margin-bottom: 0.6cqw;
  border: 1px solid #8bd6c6;
}
.arcade-cast img { top: 0; left: calc(-100% * var(--tile)); }

.arcade-captions {
  display: grid;
  align-content: center;
  min-height: 2.6rem;
  padding: 0.25rem 0.45rem;
  background: #181426;
  border: 1px solid #544763;
  border-top: 0;
  font-size: 0.86rem;
}
.demo .arcade-captions p, .demo .arcade-keys { margin: 0; line-height: 1.2; }
#arcade-voice { color: #fff4de; font-weight: bold; }
#arcade-sfx { color: #edbddb; }
.arcade-keys { padding-top: 0.6rem; color: #e1c9df; font-size: 0.86rem; }
.arcade-keys span { color: var(--arcade-pink); }
.arcade-touch { display: none; }

.arcade-joystick {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: 5.65rem;
  aspect-ratio: 1;
  border: 2px solid #775776;
  border-radius: 50%;
  background: radial-gradient(circle, #302640 0 40%, #493951 41% 44%, #262038 45%);
  box-shadow: inset 0 3px 0 #1a162a, 0 3px 0 #2f203b;
  cursor: grab;
}
.arcade-joystick::before {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 1px;
  box-shadow: 0 -2.13rem #a78ca7, 2.13rem 0 #a78ca7, 0 2.13rem #a78ca7, -2.13rem 0 #a78ca7;
  pointer-events: none;
  content: '';
}
.arcade-joystick[data-active] { border-color: var(--arcade-mint); cursor: grabbing; }
#arcade-grab, #arcade-grab::before {
  -webkit-user-select: none;
  user-select: none;
}
#arcade-grab::before { content: attr(aria-label); pointer-events: none; }
.arcade-stick {
  position: relative;
  width: 2.45rem;
  aspect-ratio: 1;
  border: 2px solid var(--arcade-mint);
  border-radius: 50%;
  background: #5b4b70;
  box-shadow: inset 0 -5px 0 #3d3353, 0 3px 0 #1a162a;
  transform: translate(var(--stick-x, 0px), var(--stick-y, 0px));
  pointer-events: none;
}

@media (any-pointer: coarse), (max-width: 42rem) {
  .demo {
    width: min(96vw, 38rem, calc((100dvh - 18rem) * 1.48 + 1.5rem));
    padding: 0.55rem;
    -webkit-user-select: none;
    user-select: none;
  }
  .arcade-captions { min-height: 3.1rem; }
  .demo .arcade-keys { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }
  .arcade-touch { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding-top: 0.5rem; }
  .arcade-joystick, .arcade-touch button {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }
}

@media (max-height: 32rem) and (orientation: landscape) {
  .demo { width: min(96vw, 43rem); }
  .demo h2 { position: absolute; top: 0.65rem; inset-inline: 8rem 3.5rem; font-size: clamp(1rem, 3.4vw, 1.6rem); }
  .demo h2 span { margin-bottom: 0.15rem; }
  .arcade-hud { margin-top: 0.4rem; }
  .demo .arcade-screen { width: min(calc(100% - 13rem), calc((100dvh - 11rem) * 1.48)); margin-inline: auto; }
  .arcade-touch { position: absolute; inset: auto 0.55rem 3.3rem; pointer-events: none; }
  .arcade-joystick, .arcade-touch button { pointer-events: auto; }
}
