@font-face {
  font-family: "Press Start 2P";
  src: url(press-start-2p.woff2) format("woff2");
  font-display: swap;
}

:root {
  color-scheme: light;
  --case-texture: url(case-grain.webp);
  --ivory: #fff0ce;
  --ink: #203708;
  --pixel-font: "Press Start 2P", "Courier New", monospace;
  font-family: system-ui, sans-serif;
  background: #faf1e2;
  color: #423b32;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-block-size: 100svh;
  margin: 0;
  display: grid;
  place-items: center;
  padding-block: 16px;
  background: radial-gradient(ellipse at 50% 24%, #fff8ec, #faf1e2 75%);
}

.game {
  width: min(1048px, calc(100% - 28px), max(520px, calc(100svh - 120px)));
  container-type: inline-size;
}

.game-nav { margin-block-end: 8px; }

.back-to-games {
  display: inline-flex;
  align-items: center;
  min-block-size: 44px;
  padding-inline: 14px;
  border: 1px solid #b9a78d;
  border-radius: 10px;
  color: inherit;
  background: #f6ead7;
  font-size: .875rem;
  font-weight: 650;
  text-decoration: none;
}

.back-to-games:hover { background: #ebdcc2; }
.back-to-games:focus-visible { outline: 2px solid #56452f; outline-offset: 2px; }

.console {
  border-radius: max(24px, 5.8cqi);
  padding: 3.8cqi 3.35cqi 3.1cqi;
  color: var(--ivory);
  background: var(--case-texture), linear-gradient(158deg, #3b3b3a, #2b2b2a 50%, #242423);
  box-shadow: inset 0 3px 10px #ffffff40, inset 0 -7px 15px #100f0d70, 0 2px 2px #33291c32;
}

h1 {
  margin: 0 0 2.5cqi;
  color: var(--ivory);
  font: 400 clamp(1.6rem, 8.5cqi, 5.6rem)/1 var(--pixel-font);
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 2px #100f0b;
  letter-spacing: -.065em;
}

.display-frame {
  padding: max(6px, 1.55cqi);
  border-radius: max(15px, 3.6cqi);
  background: linear-gradient(170deg, #23221f, #121210 60%, #20201c);
  box-shadow: inset 0 2px 5px #080806b0, 0 2px 5px #fff2;
}

.display {
  overflow: hidden;
  padding: 1.45cqi .85cqi 1.65cqi;
  border: 1px solid #1b240b;
  border-radius: max(10px, 2.3cqi);
  background: radial-gradient(ellipse at 57% 26%, #b3ce53, #a4c13c 71%, #95ae33);
  box-shadow: inset 0 2px 6px #233608b0, inset 0 -3px 9px #71852663;
  color: var(--ink);
}

.scoreboard {
  display: flex;
  justify-content: space-between;
  margin: 0 .5cqi 1.2cqi;
  padding: .7cqi 2.35cqi 1.6cqi;
  border-bottom: max(2px, .6cqi) solid currentColor;
  font: 400 clamp(.7rem, 3.95cqi, 2.5rem)/1.25 var(--pixel-font);
  white-space: nowrap;
  text-transform: uppercase;
}

.board { position: relative; }

canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  touch-action: none;
  user-select: none;
}

.board-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  color: var(--ink);
  background: #aec74ce6;
  font: 400 clamp(.85rem, 3.8cqi, 2.5rem)/1.5 var(--pixel-font);
  text-align: center;
  text-transform: uppercase;
  pointer-events: none;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 2.5cqi 6.3cqi 0;
}

.d-pad {
  --key: clamp(44px, 8.8cqi, 92px);
  display: grid;
  grid-template: repeat(3, var(--key)) / repeat(3, var(--key));
  gap: max(2px, .25cqi);
  position: relative;
  isolation: isolate;
}

.d-pad::before, .d-pad::after {
  position: absolute;
  z-index: -1;
  border-radius: max(12px, 2.45cqi);
  background: #1d1c1a;
  box-shadow: 0 0 0 max(3px, .52cqi) #191816, 0 2px 5px max(3px, .55cqi) #ffffff23;
  content: "";
}

.d-pad::before { inset: 0 calc(var(--key) + max(2px, .25cqi)); }
.d-pad::after { inset: calc(var(--key) + max(2px, .25cqi)) 0; }

.direction, .action {
  display: grid;
  place-items: center;
  border: 1px solid #1a1917;
  padding: 0;
  color: inherit;
  background: var(--case-texture), linear-gradient(#494947, #383837 65%, #30302e);
  box-shadow: inset 0 2px 5px #ffffff38, inset 0 -4px 6px #11100de6, 0 2px 3px #12110f;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.direction {
  border-radius: max(10px, 2.05cqi);
}

.direction::after {
  width: clamp(16px, 4.1cqi, 46px);
  aspect-ratio: 1.3;
  background: currentColor;
  color: var(--ivory);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  transform: rotate(var(--angle, 0deg));
  content: "";
}

.up { grid-area: 1 / 2; }
.left { --angle: -90deg; grid-area: 2 / 1; }
.right { --angle: 90deg; grid-area: 2 / 3; }
.down { --angle: 180deg; grid-area: 3 / 2; }

.action {
  width: 30.5cqi;
  min-width: 108px;
  min-height: max(48px, 10.5cqi);
  border-radius: 100px;
  padding-inline: 8px;
  font: 400 clamp(.7rem, 2.9cqi, 1.9rem)/1.3 var(--pixel-font);
  text-transform: uppercase;
  text-shadow: 0 2px #171510;
  box-shadow: inset 0 3px 6px #fff4, inset 0 -5px 8px #100f0c, 0 0 0 max(4px, .7cqi) #171614, 0 2px 4px max(5px, .83cqi) #fff2;
}

@media (hover: hover) {
  .direction:hover, .action:hover { background-color: #56544d; background-blend-mode: normal, screen; }
}

.direction:active, .action:active { transform: translateY(1px); }
button:focus-visible { position: relative; z-index: 1; outline: 2px solid var(--ivory); outline-offset: 3px; }

.game-footer {
  padding: 12px 8px 0;
  font-size: .875rem;
  line-height: 1.4;
  text-align: center;
}

.game-footer p, .script-message { margin: 0; }
.script-message { padding-top: 12px; text-align: center; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 520px) {
  .console { padding: 20px 11px 19px; }
  h1 { margin-bottom: 15px; }
  .display { padding: 7px 4px 5px; }
  .controls { padding: 16px 9px 0; }
}
