@font-face {
  font-family: "Press Start 2P";
  src: url("../assets/PressStart2P.ttf") format("truetype");
  font-display: swap;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: #000;
  color: #fff;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: "Press Start 2P", monospace;
}

body {
  position: fixed;
  inset: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
}

#screen {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  background: #fff;
}

/* ---------------------------------------------------------------- touch pad
   --u is the size of one d-pad arm. Portrait: pad below the game.
   Landscape: pad floats over the black side margins. */
#pad {
  display: none;
  --u: clamp(38px, 11vw, 50px);
  --btn: clamp(52px, 15vw, 64px);
  width: 100%;
  max-width: 480px;
  padding: 10px 20px calc(12px + env(safe-area-inset-bottom));
  justify-content: space-between;
  align-items: center;
  flex: 1 1 auto;
  max-height: 260px;
}
body.touch #pad { display: flex; }
body.touch.portrait #stage { flex: 0 0 auto; padding-top: env(safe-area-inset-top); }

#dpad {
  position: relative;
  width: calc(var(--u) * 3);
  height: calc(var(--u) * 3);
  flex: 0 0 auto;
}
#dpad .d, #dpad .hub {
  position: absolute;
  width: var(--u);
  height: var(--u);
  background: #1a1a1a;
  border: 2px solid #fff;
  border-radius: 0;
  padding: 0;
}
#dpad .hub { left: var(--u); top: var(--u); border: 0; }
#dpad .up { left: var(--u); top: 0; border-bottom: 0; }
#dpad .down { left: var(--u); top: calc(var(--u) * 2); border-top: 0; }
#dpad .left { left: 0; top: var(--u); border-right: 0; }
#dpad .right { left: calc(var(--u) * 2); top: var(--u); border-left: 0; }
#dpad .d.on, .btn.on { background: #fff; }

#ab {
  display: flex;
  gap: 14px;
  transform: rotate(-18deg);
  flex: 0 0 auto;
}
.btn {
  width: var(--btn);
  height: var(--btn);
  border: 2px solid #fff;
  border-radius: 0;
  background: #1a1a1a;
  color: #fff;
  font: 14px "Press Start 2P", monospace;
  padding: 0;
}
.btn.a { margin-top: calc(var(--btn) * -0.4); }
.btn.on { color: #000; }

#rotate {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(4px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 7px;
  color: #6e6e6e;
  pointer-events: none;
}
body.touch.portrait #rotate { display: block; }

/* landscape phones: game uses the full height, controls sit on the sides */
body.touch.landscape #pad {
  position: fixed;
  inset: 0;
  max-width: none;
  max-height: none;
  padding: 0 calc(10px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
  align-items: flex-end;
  pointer-events: none;
  --u: clamp(34px, 11vh, 46px);
  --btn: clamp(46px, 15vh, 58px);
}
body.touch.landscape #dpad, body.touch.landscape #ab { pointer-events: auto; opacity: 0.8; }
body.touch.landscape #ab { transform: rotate(-18deg) translateY(-8px); }

#mute {
  position: fixed;
  z-index: 5;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  background: #000;
  color: #fff;
  border: 2px solid #fff;
  border-radius: 0;
  font: 8px "Press Start 2P", monospace;
  padding: 6px 8px;
  opacity: 0.7;
  cursor: pointer;
}
#mute:hover { opacity: 1; }
body.touch.portrait #mute { top: auto; bottom: calc(22px + env(safe-area-inset-bottom)); right: 50%; transform: translateX(50%); }

/* ---------------------------------------------------------------- brand overlays */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #fff;
  color: #000;
  font-family: Inter, system-ui, sans-serif;
}
#overlay.hidden { display: none; }

#overlay.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4vh;
}
#overlay.boot img {
  width: min(28vw, 34vh);
  animation: drop 0.9s steps(8) both 0.2s;
}
#overlay.boot p {
  margin: 0;
  font: 500 clamp(12px, 1.6vw, 22px) "JetBrains Mono", monospace;
  letter-spacing: 0.6em;
  color: #6e6e6e;
  animation: appear 0.01s both 1.5s;
}
@keyframes drop { from { transform: translateY(-60vh); } to { transform: none; } }
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }

#overlay.end {
  overflow: auto;
  touch-action: pan-y;
  padding: clamp(20px, 5vw, 72px);
  display: flex;
  flex-direction: column;
  animation: appear 0.4s both;
  -webkit-user-select: text;
  user-select: text;
}
#overlay.end .rail {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: clamp(16px, 3vw, 36px);
  border-bottom: 1px solid #000;
}
#overlay.end .rail img { height: clamp(40px, 6vw, 84px); }
#overlay.end .rail span, #overlay.end h3, #overlay.end .foot {
  font: 500 clamp(10px, 1.1vw, 16px) "JetBrains Mono", monospace;
  letter-spacing: 0.08em;
  color: #6e6e6e;
}
#overlay.end .grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: clamp(24px, 5vw, 80px);
  padding: clamp(24px, 4vw, 56px) 0;
  flex: 1 0 auto;
}
#overlay.end h1 {
  margin: 0;
  font-weight: 800;
  font-size: clamp(40px, 7vw, 112px);
  line-height: 1.05;
  letter-spacing: -0.03em;
}
#overlay.end .lead {
  font-weight: 300;
  font-size: clamp(16px, 1.9vw, 30px);
  line-height: 1.5;
  margin: clamp(16px, 2.5vw, 36px) 0;
  color: #3c3c3c;
}
#overlay.end .right { border-left: 1px solid #000; padding-left: clamp(20px, 3vw, 48px); }
#overlay.end h3 { margin: 0 0 12px; font-weight: 500; }
#overlay.end ul {
  list-style: none;
  padding: 0;
  margin: 0 0 clamp(20px, 3vw, 40px);
  font-size: clamp(16px, 1.8vw, 28px);
  line-height: 1.6;
}
#overlay.end ul.two { columns: 2; column-gap: 24px; }
#overlay.end .actions { display: flex; flex-wrap: wrap; gap: 12px; }
#overlay.end .btn {
  display: inline-block;
  border: 2px solid #000;
  border-radius: 0;
  background: #fff;
  color: #000;
  text-decoration: none;
  font: 500 clamp(11px, 1.1vw, 15px) "JetBrains Mono", monospace;
  letter-spacing: 0.06em;
  padding: 12px 16px;
  cursor: pointer;
}
#overlay.end .btn.primary { background: #000; color: #fff; }
#overlay.end .btn:hover { background: #000; color: #fff; }
#overlay.end .foot {
  display: flex;
  justify-content: space-between;
  padding-top: 16px;
  border-top: 1px solid #000;
}
#overlay.end .foot a { color: #000; text-decoration: none; }
@media (max-width: 720px) {
  #overlay.end .grid { grid-template-columns: 1fr; }
  #overlay.end .right { border-left: 0; padding-left: 0; border-top: 1px solid #000; padding-top: 24px; }
  #overlay.end .rail span { display: none; }
}
