* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: #14121f;
  background-image:
    radial-gradient(ellipse at 50% 0%, #241f38 0%, #14121f 70%);
  color: #cfc9e8;
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

#frame {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

#bezel {
  position: relative;
  padding: 18px;
  background: linear-gradient(160deg, #2c2745 0%, #1c1830 60%, #171327 100%);
  border-radius: 18px;
  box-shadow:
    0 0 0 2px #3d3660,
    0 24px 60px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

#game {
  display: block;
  /* pick the largest 3:2 size that fits — never stretch */
  width: min(960px, calc(100vw - 80px), calc((100vh - 180px) * 1.5));
  height: auto;
  aspect-ratio: 3 / 2;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0a0a12;
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px #0a0a12;
}

#scanlines {
  position: absolute;
  inset: 18px;
  border-radius: 6px;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 3px,
    rgba(0, 0, 0, 0.07) 3px,
    rgba(0, 0, 0, 0.07) 4px
  );
  mix-blend-mode: multiply;
}

#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  justify-content: center;
  font-size: 13px;
  color: #8f87b8;
  letter-spacing: 0.03em;
}

.key {
  display: inline-block;
  padding: 2px 7px;
  background: #262040;
  border: 1px solid #3d3660;
  border-bottom-width: 3px;
  border-radius: 5px;
  color: #e8e3ff;
  font-family: Consolas, monospace;
  font-size: 12px;
}

#credits {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: #565073;
}

/* ------------------- mobile / PWA ------------------- */

#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #14121f;
  color: #e8e3ff;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  letter-spacing: 0.12em;
}
#rotate .rot-icon { font-size: 64px; animation: spin 2.4s ease-in-out infinite; }
#rotate p { font-size: 16px; font-weight: 700; }
#rotate span { font-size: 12px; color: #8f87b8; }
@keyframes spin {
  0%, 60%, 100% { transform: rotate(0deg); }
  20%, 40% { transform: rotate(-90deg); }
}

#touch {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}
.tbtn {
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  border: 2px solid rgba(232, 227, 255, 0.35);
  background: rgba(38, 32, 64, 0.55);
  color: rgba(232, 227, 255, 0.85);
  font-family: Consolas, monospace;
  font-size: 18px;
  font-weight: 700;
  border-radius: 12px;
  padding: 0;
}
.tbtn.on { background: rgba(120, 104, 200, 0.7); }
#dpad {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-areas: ". u ." "l . r" ". d .";
  grid-template-columns: 52px 52px 52px;
  grid-template-rows: 52px 52px 52px;
  gap: 2px;
}
#abtns {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(26px, env(safe-area-inset-bottom));
  display: flex;
  gap: 14px;
  align-items: flex-end;
}
#abtns .round { width: 62px; height: 62px; border-radius: 50%; font-size: 22px; }
#abtns .round[data-k="b"] { margin-bottom: 26px; }
#btn-start {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  top: max(12px, env(safe-area-inset-top));
  width: 76px;
  height: 34px;
  font-size: 13px;
  border-radius: 17px;
}

@media (pointer: coarse) {
  #touch { display: block; }
  #controls, #credits { display: none; }
  #frame { gap: 0; }
  #bezel { padding: 6px; border-radius: 10px; }
  #scanlines { inset: 6px; }
  #game {
    width: min(calc(100vw - 12px), calc((100vh - 12px) * 1.5));
    width: min(calc(100dvw - 12px), calc((100dvh - 12px) * 1.5));
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  #rotate { display: flex; }
}
