@font-face {
  font-family: "Press Start 2P";
  src: url("/assets/press-start-2p-v16-42769995.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #071016;
  --paper: #fffdf1;
  --sky: #25b3fa;
  --blue: #0164b2;
  --deep-blue: #06466d;
  --orange: #e86f2d;
  --orange-dark: #963412;
  --lime: #e8ff4f;
  --red: #b51f31;
  --pixel-font: "Press Start 2P", "Courier New", monospace;
  --body-font: "Trebuchet MS", Arial, sans-serif;
  font-family: var(--body-font);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  color: var(--paper);
  background: var(--deep-blue);
  overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button:focus {
  outline: none;
}

button:focus-visible,
canvas:focus-visible,
a:focus-visible {
  outline: 4px solid var(--lime);
  outline-offset: 4px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.8rem 1rem;
  border: 4px solid var(--ink);
  color: var(--ink);
  background: var(--lime);
  font-family: var(--pixel-font);
  font-size: 0.62rem;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(100%, 80rem);
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.65rem;
  margin-inline: auto;
  padding: clamp(0.4rem, 1.6vw, 1.15rem);
}

.game-card {
  width: 100%;
  overflow: hidden;
  border: clamp(4px, 0.6vw, 7px) solid var(--ink);
  background: var(--ink);
  box-shadow: 10px 10px 0 rgb(3 21 32 / 55%);
}

.stage-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--sky);
  isolation: isolate;
  touch-action: none;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
  image-rendering: pixelated;
}

.sound-button {
  position: absolute;
  z-index: 6;
  top: clamp(0.55rem, 1.8vw, 1.1rem);
  left: clamp(0.55rem, 1.8vw, 1.1rem);
  width: clamp(2.75rem, 5.8vw, 4.35rem);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: clamp(3px, 0.45vw, 5px) solid var(--ink);
  color: var(--paper);
  background: var(--orange);
  box-shadow: inset 0 0 0 5px var(--paper), inset 0 0 0 9px var(--orange-dark), 0 5px 0 var(--ink);
  font-family: var(--pixel-font);
  font-size: clamp(0.42rem, 0.95vw, 0.7rem);
  cursor: pointer;
}

.sound-button:hover {
  background: #f28643;
}

.sound-button:active {
  transform: translateY(4px);
  box-shadow: inset 0 0 0 5px var(--paper), inset 0 0 0 9px var(--orange-dark), 0 1px 0 var(--ink);
}

.sound-button[aria-pressed="true"] {
  color: var(--ink);
  background: #b8c3c4;
  box-shadow: inset 0 0 0 5px var(--paper), inset 0 0 0 9px #667578, 0 5px 0 var(--ink);
  text-decoration: line-through;
}

.hud {
  position: absolute;
  z-index: 4;
  top: clamp(0.55rem, 1.65vw, 1rem);
  left: 50%;
  width: min(73%, 44rem);
  display: grid;
  grid-template-columns: 1fr minmax(10rem, 1.7fr) 1fr;
  align-items: start;
  pointer-events: none;
  text-transform: uppercase;
  transform: translateX(-50%);
}

.hud-stat {
  display: flex;
  flex-direction: column;
  color: var(--paper);
  text-shadow: -3px 0 var(--ink), 0 3px var(--ink), 3px 0 var(--ink), 0 -3px var(--ink);
}

.hud-stat-right {
  align-items: flex-end;
}

.hud-stat span,
.clearance-chip span {
  font-family: var(--pixel-font);
  font-size: clamp(0.35rem, 0.75vw, 0.56rem);
  letter-spacing: 0.04em;
}

.hud-stat strong {
  margin-top: 0.3rem;
  font-family: var(--pixel-font);
  font-size: clamp(0.72rem, 1.8vw, 1.35rem);
  font-variant-numeric: tabular-nums;
}

.hud-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28rem;
  padding: clamp(0.38rem, 1vw, 0.62rem) 0.55rem;
  border: clamp(3px, 0.4vw, 5px) solid var(--ink);
  color: var(--paper);
  background: rgb(7 16 22 / 88%);
  box-shadow: 4px 4px 0 rgb(255 255 255 / 78%);
  text-align: center;
}

.hud-status strong {
  color: var(--lime);
  font-family: var(--pixel-font);
  font-size: clamp(0.42rem, 0.9vw, 0.64rem);
  line-height: 1.45;
}

.hud-status span {
  color: var(--paper);
  font-family: var(--pixel-font);
  font-size: clamp(0.28rem, 0.58vw, 0.42rem);
  line-height: 1.35;
}

.clearance-chip {
  position: absolute;
  top: clamp(3.5rem, 7vw, 5.35rem);
  left: 50%;
  min-width: clamp(8.5rem, 20vw, 12rem);
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.48rem 0.65rem;
  border: 4px solid var(--ink);
  color: var(--ink);
  background: var(--paper);
  box-shadow: 4px 4px 0 var(--ink);
  transform: translateX(-50%);
}

.clearance-chip strong {
  color: var(--red);
  font-family: var(--pixel-font);
  font-size: clamp(0.65rem, 1.45vw, 1rem);
  font-variant-numeric: tabular-nums;
}

.clearance-chip.is-live {
  color: var(--ink);
  background: var(--lime);
  transform: translateX(-50%) scale(1.04);
}

.game-panel {
  position: absolute;
  z-index: 7;
  top: 54%;
  left: clamp(0.85rem, 3.4vw, 2.3rem);
  width: min(28rem, calc(100% - clamp(1.7rem, 6.8vw, 4.6rem)));
  padding: clamp(0.8rem, 2vw, 1.45rem);
  border: clamp(4px, 0.55vw, 7px) solid var(--ink);
  color: var(--ink);
  background: rgb(255 253 241 / 94%);
  box-shadow: clamp(5px, 0.85vw, 9px) clamp(5px, 0.85vw, 9px) 0 var(--ink);
  transform: translateY(-50%);
  animation: panel-in 260ms steps(4, end) both;
}

.game-panel[hidden] {
  display: none;
}

.ready-panel {
  top: auto;
  bottom: 3.5%;
  left: 50%;
  width: auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  transform: translateX(-50%);
  animation: none;
}

.ready-panel .panel-kicker,
.ready-panel > p {
  display: none;
}

.ready-panel h1 {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.ready-panel .primary-button {
  min-height: 0;
  padding: clamp(0.55rem, 1.4vw, 0.95rem) clamp(0.75rem, 1.8vw, 1.25rem);
  border: 0;
  color: var(--paper);
  background: transparent;
  box-shadow: none;
  font-size: clamp(0.72rem, 1.8vw, 1.25rem);
  text-shadow: -3px 0 var(--ink), 0 3px var(--ink), 3px 0 var(--ink), 0 -3px var(--ink), 5px 5px 0 var(--ink);
}

.ready-panel .primary-button:hover {
  color: var(--lime);
  background: transparent;
}

.ready-panel .primary-button:active {
  transform: translateY(3px);
  box-shadow: none;
}

.panel-kicker {
  margin: 0 0 clamp(0.35rem, 0.9vw, 0.65rem);
  color: var(--red);
  font-family: var(--pixel-font);
  font-size: clamp(0.42rem, 0.82vw, 0.6rem);
  line-height: 1.5;
  text-transform: uppercase;
}

.game-panel h1,
.game-panel h2 {
  margin: 0;
  font-family: var(--pixel-font);
  font-weight: 400;
  line-height: 1.18;
  text-transform: uppercase;
}

.game-panel h1 {
  color: var(--paper);
  font-size: clamp(1.75rem, 5vw, 3.8rem);
  text-shadow: -4px 0 var(--ink), 0 4px var(--ink), 4px 0 var(--ink), 0 -4px var(--ink), 7px 7px 0 var(--orange);
}

.game-panel h2 {
  max-width: 17ch;
  color: var(--ink);
  font-size: clamp(1.15rem, 2.6vw, 2.15rem);
}

.game-panel > p:not(.panel-kicker):not(.control-hint) {
  max-width: 42ch;
  margin: clamp(0.45rem, 1.2vw, 0.85rem) 0 clamp(0.55rem, 1.45vw, 1rem);
  color: #26383e;
  font-size: clamp(0.68rem, 1.3vw, 0.92rem);
  font-weight: 700;
  line-height: 1.45;
}

.primary-button {
  min-height: clamp(2.6rem, 5vw, 3.5rem);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1rem;
  border: 4px solid var(--ink);
  color: var(--paper);
  background: var(--orange);
  box-shadow: 0 6px 0 var(--orange-dark), 0 10px 0 var(--ink);
  font-family: var(--pixel-font);
  font-size: clamp(0.52rem, 1vw, 0.74rem);
  line-height: 1.3;
  text-transform: uppercase;
  cursor: pointer;
}

.primary-button:hover {
  background: #f28643;
}

.primary-button:active {
  transform: translateY(6px);
  box-shadow: 0 1px 0 var(--orange-dark), 0 4px 0 var(--ink);
}

.control-hint {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: clamp(0.75rem, 1.5vw, 1rem) 0 0;
}

.control-hint span {
  padding: 0.3rem 0.42rem;
  border: 3px solid var(--ink);
  color: var(--ink);
  background: #d8eef2;
  font-family: var(--pixel-font);
  font-size: clamp(0.3rem, 0.58vw, 0.43rem);
  line-height: 1.4;
  text-transform: uppercase;
}

.result-panel {
  width: min(36rem, calc(100% - clamp(1.7rem, 6.8vw, 4.6rem)));
}

.result-copy {
  margin-bottom: 0.65rem !important;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(8rem, 1.5fr) 1fr 1fr;
  gap: clamp(0.4rem, 1vw, 0.7rem);
  margin-bottom: clamp(0.7rem, 1.5vw, 1rem);
}

.result-primary,
.result-score {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(0.48rem, 1vw, 0.75rem);
  border: 3px solid var(--ink);
  color: var(--ink);
  background: #d8eef2;
}

.result-primary strong,
.result-score strong {
  overflow: hidden;
  font-family: var(--pixel-font);
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.result-primary strong {
  color: var(--red);
  font-size: clamp(1rem, 2.8vw, 2.1rem);
}

.result-score strong {
  margin-top: 0.32rem;
  font-size: clamp(0.65rem, 1.4vw, 1rem);
}

.result-primary span,
.result-score span {
  margin-top: 0.34rem;
  font-family: var(--pixel-font);
  font-size: clamp(0.27rem, 0.5vw, 0.37rem);
  line-height: 1.45;
  text-transform: uppercase;
}

.control-deck {
  display: flex;
  align-items: center;
  gap: clamp(0.65rem, 1.7vw, 1rem);
  padding: clamp(0.65rem, 1.4vw, 0.9rem);
  border-top: clamp(4px, 0.6vw, 7px) solid var(--ink);
  background: var(--blue);
}

.game-card:not(.is-running) .control-deck {
  display: none;
}

.tap-button {
  min-height: clamp(3.2rem, 6.5vw, 4.2rem);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  border: 4px solid var(--ink);
  color: var(--paper);
  background: var(--orange);
  box-shadow: 0 6px 0 var(--orange-dark), 0 10px 0 var(--ink);
  font-family: var(--pixel-font);
  font-size: clamp(0.68rem, 1.65vw, 1rem);
  line-height: 1.3;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: none;
  user-select: none;
}

.tap-button:not(:disabled):hover {
  background: #f28643;
}

.tap-button:not(:disabled):active,
.tap-button.is-kicked {
  transform: translateY(6px);
  box-shadow: 0 1px 0 var(--orange-dark), 0 4px 0 var(--ink);
}

.tap-button:disabled {
  color: #536268;
  background: #9caeb1;
  box-shadow: 0 6px 0 #526267, 0 10px 0 var(--ink);
  cursor: default;
}

.control-deck p {
  flex: 0 0 auto;
  margin: 0;
  color: var(--paper);
  font-family: var(--pixel-font);
  font-size: clamp(0.35rem, 0.68vw, 0.5rem);
  line-height: 1.65;
  text-transform: uppercase;
}

kbd {
  padding: 0.15rem 0.35rem;
  border: 3px solid var(--ink);
  color: var(--ink);
  background: var(--paper);
  font: inherit;
}

.game-toast {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: 6%;
  max-width: 84%;
  padding: 0.65rem 0.8rem;
  border: 4px solid var(--ink);
  color: var(--ink);
  background: var(--lime);
  box-shadow: 5px 5px 0 var(--ink);
  font-family: var(--pixel-font);
  font-size: clamp(0.42rem, 0.8vw, 0.6rem);
  line-height: 1.45;
  text-align: center;
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 0.75rem);
}

.game-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.screen-reader-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.stage-shell.is-shaking {
  animation: screen-shake 240ms steps(4, end);
}

.site-footer {
  color: #c4dbe1;
  font-family: var(--pixel-font);
  font-size: clamp(0.3rem, 0.55vw, 0.42rem);
  line-height: 1.5;
  text-align: center;
  text-transform: uppercase;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(calc(-50% + 1rem));
  }

  to {
    opacity: 1;
    transform: translateY(-50%);
  }
}

@keyframes screen-shake {
  0%, 100% { transform: translate(0); }
  20% { transform: translate(-5px, 2px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, -1px); }
  80% { transform: translate(2px, 2px); }
}

@media (max-width: 620px) {
  .app-shell {
    justify-content: flex-start;
    padding: 0;
  }

  .game-card {
    border-width: 4px;
    box-shadow: none;
  }

  .sound-button {
    box-shadow: inset 0 0 0 3px var(--paper), inset 0 0 0 6px var(--orange-dark), 0 3px 0 var(--ink);
  }

  .hud {
    top: 0.4rem;
    width: 70%;
    grid-template-columns: 1fr 1.4fr 1fr;
  }

  .hud-status {
    padding: 0.28rem 0.3rem;
    box-shadow: 2px 2px 0 rgb(255 255 255 / 78%);
  }

  .hud-status span,
  .hud-stat span {
    display: none;
  }

  .hud-stat strong {
    margin-top: 0.15rem;
  }

  .clearance-chip {
    top: 2.4rem;
    min-width: 7.5rem;
    padding: 0.3rem 0.4rem;
    border-width: 3px;
    box-shadow: 3px 3px 0 var(--ink);
  }

  .game-panel {
    top: 57%;
    left: 0.55rem;
    width: calc(100% - 1.1rem);
    padding: 0.55rem 0.65rem;
    border-width: 4px;
    box-shadow: 4px 4px 0 var(--ink);
  }

  .ready-panel {
    top: auto;
    bottom: 3%;
    left: 50%;
    width: auto;
    padding: 0;
    border: 0;
    box-shadow: none;
    transform: translateX(-50%);
  }

  .ready-panel > p:not(.panel-kicker):not(.control-hint),
  .control-hint {
    display: none;
  }

  .panel-kicker {
    margin-bottom: 0.28rem;
  }

  .primary-button {
    min-height: 2.25rem;
    margin-top: 0.48rem;
    padding: 0.45rem 0.65rem;
    border-width: 3px;
    box-shadow: 0 4px 0 var(--orange-dark), 0 7px 0 var(--ink);
  }

  .result-panel {
    top: 54%;
  }

  .result-copy {
    display: none;
  }

  .result-grid {
    gap: 0.28rem;
    margin-block: 0.4rem 0.3rem;
  }

  .result-primary,
  .result-score {
    padding: 0.3rem;
    border-width: 2px;
  }

  .control-deck {
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.65rem;
    border-top-width: 4px;
  }

  .tap-button {
    width: 100%;
    min-height: 3.4rem;
  }

  .control-deck p {
    text-align: center;
  }

  .site-footer {
    padding: 0.4rem 0.75rem;
  }
}

@media (max-width: 390px) {
  .hud-status {
    display: none;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .hud-stat-right {
    grid-column: 2;
  }

  .game-panel h1 {
    font-size: 1.55rem;
  }

  .game-panel h2 {
    font-size: 0.9rem;
  }
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  min-width: 0;
  padding: 0;
  background: var(--sky);
}

.app-shell {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  min-height: 100svh;
  gap: 0;
  padding: 0;
}

.game-card {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  border: 0;
  background: var(--blue);
  box-shadow: none;
}

.stage-shell {
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  aspect-ratio: auto;
  background: var(--sky);
  container-type: size;
}

.stage-shell::after {
  position: absolute;
  z-index: 0;
  inset: 50% 0 0;
  content: "";
  background: var(--blue);
  pointer-events: none;
}

#game-canvas {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: min(100cqw, calc(100cqh * 16 / 9));
  height: auto;
  transform: translate(-50%, -50%);
}

.sound-button {
  top: max(0.55rem, env(safe-area-inset-top));
}

.hud {
  top: max(0.45rem, env(safe-area-inset-top));
}

.ready-panel {
  bottom: max(4%, env(safe-area-inset-bottom));
}

.control-deck {
  z-index: 10;
  flex: 0 0 auto;
  padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
}

.site-footer {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
