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

:root {
  --night: #0b1f3a;
  --night-2: #13315c;
  --grass: #2f8f3a;
  --dirt: #b86b3c;
  --chalk: #f4f1e6;
  --gold: #ffd23f;
  --red: #d7263d;
  --ink: #081426;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night);
  color: var(--chalk);
  font: 16px/1.6 system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

.screen {
  max-width: 34rem;
  margin: 0 auto;
  padding: max(2rem, env(safe-area-inset-top)) 16px 3rem;
  text-align: center;
}

.logo {
  font: 2.6rem/1.1 var(--pixel);
  margin: 2rem 0 1rem;
  color: var(--chalk);
  text-shadow: 4px 4px 0 var(--red);
  letter-spacing: 0.05em;
}
.logo b { color: var(--gold); text-shadow: 4px 4px 0 var(--ink); }
.tag { margin: 0 auto 2rem; max-width: 26rem; }
h2 { font: 1.2rem/1.4 var(--pixel); color: var(--gold); }

.btn {
  display: inline-block;
  font: 1rem/1 var(--pixel);
  background: var(--chalk);
  color: var(--ink);
  border: 0;
  padding: 1rem 1.4rem;
  margin: 0.4rem;
  box-shadow: 0 6px 0 #9c9686, 0 6px 0 4px var(--ink);
  cursor: pointer;
  user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #9c9686, 0 2px 0 4px var(--ink); }
.btn:focus-visible { outline: 4px solid var(--gold); outline-offset: 4px; }
.btn.big { font-size: 1.5rem; padding: 1.3rem 2rem; background: var(--gold); box-shadow: 0 6px 0 #b8901c, 0 6px 0 4px var(--ink); }
.link { background: none; border: 0; color: var(--gold); text-decoration: underline; cursor: pointer; padding: 0.3rem; }

.small { font-size: 0.85rem; opacity: 0.8; }
.error { color: #ff8a8a; font-weight: 600; min-height: 1.6em; }

.panel {
  text-align: left;
  background: var(--night-2);
  border: 4px solid var(--ink);
  margin: 1.5rem 0 0;
  padding: 0.8rem 1rem;
}
.panel summary { cursor: pointer; font-weight: 700; }
.panel fieldset { border: 0; padding: 0; margin: 0.6rem 0; }
.panel label { display: block; margin: 0.2rem 0; }

.credits { margin-top: 2.5rem; font-size: 0.75rem; opacity: 0.7; text-align: left; }
.credits a { color: var(--gold); }

.resume {
  display: flex; gap: 1rem; align-items: center; justify-content: center;
  background: var(--night-2); border: 4px solid var(--ink); padding: 0.8rem; margin-bottom: 1.2rem;
}
.resume img { width: 128px; image-rendering: pixelated; border: 2px solid var(--ink); }
.resume p { margin: 0.3rem 0 0; }

.loading { font: 1.2rem var(--pixel); margin-top: 30vh; }
.loading span { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---- Stage ------------------------------------------------------------- */

#stage {
  position: fixed; inset: 0;
  background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;             /* no long-press magnifier or menu */
}
.menu, .menu-btn { touch-action: manipulation; }   /* taps without double-tap zoom */
#screen {
  /* SNES pictures were shown 4:3 on a TV. */
  aspect-ratio: 4 / 3;
  width: min(100vw, calc(100dvh * 4 / 3 - 3rem));
  max-height: 100dvh;
  background: #000;
}
#canvas { display: block; image-rendering: pixelated; outline: none; }
.keys { font-size: 0.75rem; opacity: 0.6; margin: 0.6rem 16px 0; text-align: center; }

.menu-btn {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right));
  font: 0.8rem var(--pixel); background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.3);
  width: 44px; height: 44px; border-radius: 8px; z-index: 3;
}
.menu {
  position: absolute; inset: 0; z-index: 4;
  background: rgba(8, 20, 38, 0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.6rem;
}
.menu .btn { min-width: 16rem; }

.toast {
  position: fixed; left: 50%; bottom: max(1.5rem, env(safe-area-inset-bottom)); z-index: 10;
  transform: translate(-50%, 200%);
  background: var(--gold); color: var(--ink); font: 0.8rem/1.4 var(--pixel);
  padding: 0.8rem 1rem; border: 4px solid var(--ink);
  transition: transform 0.25s steps(4);
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.on { transform: translate(-50%, 0); }

/* ---- Touch controller ---------------------------------------------------- */

.pad { --size: min(42vw, 190px); width: 100%; position: relative; flex: 1; max-height: 340px; }
.pad button {
  border: 0; color: rgba(255, 255, 255, 0.85); font: 0.75rem var(--pixel);
  touch-action: none;
}
.dpad {
  position: absolute; left: 6%; top: 50%; transform: translateY(-50%);
  width: calc(var(--size) * 0.8); aspect-ratio: 1;
  background:
    linear-gradient(#3a3a46, #3a3a46) center / 34% 100% no-repeat,
    linear-gradient(#3a3a46, #3a3a46) center / 100% 34% no-repeat;
  touch-action: none;
}
.dpad.up { box-shadow: inset 0 6px 0 -2px var(--gold); }
.dpad.down { box-shadow: inset 0 -6px 0 -2px var(--gold); }
.dpad.left { box-shadow: inset 6px 0 0 -2px var(--gold); }
.dpad.right { box-shadow: inset -6px 0 0 -2px var(--gold); }
.face {
  position: absolute; right: 6%; top: 50%; transform: translateY(-50%);
  width: var(--size); aspect-ratio: 1;
}
.face button {
  position: absolute; width: 34%; aspect-ratio: 1; border-radius: 50%;
  font-size: 0.9rem; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.5);
}
.face .x { left: 33%; top: 0; background: #3b5bdb; }
.face .y { left: 0; top: 33%; background: #2f9e44; }
.face .a { right: 0; top: 33%; background: #e03131; }
.face .b { left: 33%; bottom: 0; background: #f2c200; color: var(--ink); }
.pad .on { filter: brightness(1.5); transform: translateY(3px); box-shadow: none; }
.sh {
  position: absolute; top: 0; width: 28%; height: 40px; background: #3a3a46; border-radius: 10px;
}
.sh.l { left: 4%; }
.sh.r { right: 4%; }
.mid { position: absolute; left: 50%; bottom: 8%; transform: translateX(-50%); display: flex; gap: 12px; }
.mid button { background: #3a3a46; padding: 10px 12px; border-radius: 16px; font-size: 0.55rem; }

/* Phones held sideways: the picture in the middle, the pad on both sides. */
@media (orientation: landscape) {
  #stage.touch #screen { width: auto; height: 100dvh; }
  #stage.touch .pad { position: absolute; inset: 0; max-height: none; pointer-events: none; }
  #stage.touch .pad > * { pointer-events: auto; }
  #stage.touch .pad { --size: min(20vw, 30vh, 190px); }
  #stage.touch .dpad { left: max(2%, env(safe-area-inset-left)); top: 60%; }
  #stage.touch .face { right: max(2%, env(safe-area-inset-right)); top: 60%; }
  #stage.touch .sh { top: 12px; width: 14%; }
  /* Select under the D-pad, Start under the face buttons, off the picture. */
  #stage.touch .mid { display: contents; }
  #stage.touch .mid button { position: absolute; bottom: max(12px, env(safe-area-inset-bottom)); }
  #stage.touch .mid [data-btn=select] { left: calc(max(2%, env(safe-area-inset-left)) + var(--size) * 0.4 - 2.5rem); }
  #stage.touch .mid [data-btn=start] { right: calc(max(2%, env(safe-area-inset-right)) + var(--size) * 0.5 - 2.3rem); }
  #stage.touch .menu-btn { right: auto; left: 50%; transform: translateX(-50%); top: 6px; opacity: 0.6; }
}
/* Upright: the picture on top, the pad below, like a handheld. */
@media (orientation: portrait) {
  #stage.touch { justify-content: flex-start; padding-top: env(safe-area-inset-top); }
  #stage.touch .pad { margin-top: 1rem; }
  #stage.touch .menu-btn { top: auto; bottom: max(10px, env(safe-area-inset-bottom)); }
}
