.arcade-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(7px, 2vw, 15px);
}
.sound-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  min-height: 32px;
  padding: 5px 8px;
  border: 2px solid #17234e;
  border-radius: 8px;
  background: #fff8eb;
  color: #17234e;
  box-shadow: 0 2px #17234e;
  cursor: pointer;
  font: 850 clamp(10px, 2vw, 13px)/1 system-ui, sans-serif;
  touch-action: manipulation;
}
.sound-toggle:hover { background: #dcfaff; }
.sound-toggle:active { transform: translateY(1px); box-shadow: 0 1px #17234e; }
.sound-toggle:focus-visible { outline: 3px solid #2056e4; outline-offset: 3px; }
.sound-toggle[aria-pressed="true"] { background: #f2e8de; }
.sound-toggle[data-audio-state="needs-tap"] { background: #d8f6ff; }
.sound-toggle svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sound-toggle .sound-cross, .sound-toggle[aria-pressed="true"] .sound-waves { display: none; }
.sound-toggle[aria-pressed="true"] .sound-cross { display: inline; }
.hero > .sound-toggle { position: absolute; right: 8px; bottom: 13px; z-index: 2; }
.arcade-footer { padding: 22px 4px 0; text-align: center; font-size: 13px; font-weight: 650; }

.game-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 7px 0 8px; }
.game-title-row h1 { margin: 0; }
.more-games {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto; min-height: 34px; padding: .34em .7em;
  color: #15234f; background: #ffca6c; border: 2px solid #17234e; border-radius: 8px;
  box-shadow: 0 2px #17234e; text-decoration: none;
  font: 900 clamp(10px, 2.3vw, 15px)/1 system-ui, sans-serif; white-space: nowrap; text-transform: uppercase;
}
.more-games:hover { background: #ffe193; }
.more-games:active { transform: translateY(1px); box-shadow: 0 1px #17234e; }
.more-games:focus-visible { outline: 3px solid #2056e4; outline-offset: 3px; }

.keyboard-help {
  max-width: 76ch;
  margin: 12px auto;
  text-align: center;
  font: 650 clamp(12px, 1.8vw, 15px)/1.65 system-ui, sans-serif;
}
.keyboard-help kbd {
  padding: .04em .32em;
  border: 1px solid #17234e40;
  border-radius: 4px;
  background: #fffaf2;
  color: #17234e;
  font: 800 .95em/1.2 system-ui, sans-serif;
  white-space: nowrap;
}
.pause-keys { white-space: nowrap; }
.game-heading, .game-play-area, .game-viewport { display: contents; }
.game-play-area, .game-play-area * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.game-play-area canvas { -webkit-user-drag: none; }
.game-play-area :is(#jump-button, #controls button, #mobile-controls button, .steering-control) {
  touch-action: none;
}
.mobile-device .keyboard-help, .mobile-device button kbd { display: none; }
@media (hover: none) and (pointer: coarse) {
  .keyboard-help, button kbd { display: none; }
}
@media (hover: hover), (pointer: fine), (pointer: none) {
  html.desktop-device :is(#jump-button, #controls, #mobile-controls) { display: none; }
  html.desktop-device .game-page {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0 auto;
    padding: 6px 0 10px;
    width: min(960px, calc(100% - 32px), calc((100dvh - 92px) * 4 / 3));
    min-width: 0;
    height: 100dvh;
    container: arcade-game / inline-size;
  }
  html.desktop-device .game-heading {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "brand title back sound";
    align-items: center;
    gap: clamp(6px, 1.6cqi, 16px);
    padding: 2px 0 8px;
    border-bottom: 2px solid #17234e;
    flex: none;
  }
  html.desktop-device .game-heading > :is(header, .game-title-row) { display: contents; }
  html.desktop-device .game-heading header > a { grid-area: brand; }
  html.desktop-device .game-heading header img { width: clamp(86px, 20cqi, 170px); }
  html.desktop-device .game-heading h1 {
    grid-area: title;
    margin: 0;
    font-size: clamp(17px, 3.6cqi, 34px);
    overflow-wrap: anywhere;
  }
  html.desktop-device .game-heading .more-games { grid-area: back; }
  html.desktop-device .game-heading .arcade-tools { grid-area: sound; }
  /* The header and wrapped instructions take their natural height first. */
  html.desktop-device .game-viewport {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    flex: 0 1 75cqi;
    min-height: 0;
  }
  html.desktop-device .game-viewport > section {
    height: 100%;
    width: auto;
    aspect-ratio: 4 / 3;
    flex: none;
    min-width: 0;
  }
  html.desktop-device .game-page .keyboard-help { flex: none; margin: 0 auto; }
  @container arcade-game (max-width: 500px) {
    .game-heading .sound-label { display: none; }
  }
}

/* The header scrolls away on a phone. Reserve a full landscape screen for
   play, including the control strip even while a start/pause overlay is up. */
.mobile-device:is(.landscape-game, .embedded-landscape) .game-page {
  --play-height: var(--host-play-height, 100vh);
  --bottom-space: max(9px, env(safe-area-inset-bottom, 0px));
  --row-height: 44px;
  --strip-space: calc(8px + 14px + var(--row-height) + var(--bottom-space));
  width: min(calc(100% - 26px), 960px, calc((var(--play-height) - var(--strip-space)) * 4 / 3));
  min-width: 0;
  padding-bottom: 0;
}
@supports (height: 100lvh) {
  .mobile-device:is(.landscape-game, .embedded-landscape) .game-page {
    --play-height: var(--host-play-height, 100lvh);
  }
}
.mobile-device:is(.landscape-game, .embedded-landscape) .karate-page { --row-height: 64px; }
.mobile-device:is(.landscape-game, .embedded-landscape) .game-play-area {
  display: flow-root;
  min-height: var(--play-height);
  padding: 8px 0 var(--bottom-space);
}
.mobile-device:is(.landscape-game, .embedded-landscape) .game-play-area > :is(#controls, #mobile-controls, #jump-button) {
  margin: 14px 0 0;
}
.mobile-device:is(.landscape-game, .embedded-landscape) .game-play-area :is(.control, .strike, .jump-button, .mobile-control-row > button) {
  min-height: 44px;
}
.mobile-device:is(.landscape-game, .embedded-landscape) .control { font-size: 16px; }
.mobile-device:is(.landscape-game, .embedded-landscape) .steering-control {
  min-height: 44px;
  padding-block: 0;
}
.mobile-device:is(.landscape-game, .embedded-landscape) .steering-control input[type="range"] { height: 40px; }
/* Keep vertical aiming and dragging available in the two games that use it. */
.mobile-device:is(.landscape-game, .embedded-landscape) body:not([data-game="bank-shot"]):not([data-game="magnet-mayhem"]) :is(.stage, .screen, canvas) {
  touch-action: pan-y;
}
