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

:root {
  --accent: #9b5de5;
  --yellow: #ffe66d;
  --bg: #0d0a1a;
  --panel: #16112b;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: #fff;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#frame {
  width: min(96vw, 92vh * (640 / 480));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#screen {
  position: relative;
  width: 100%;
  aspect-ratio: 640 / 480;
  background: var(--panel);
  border: 4px solid #2c2350;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(155, 93, 229, 0.3);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.18) 3px
  );
}

/* ---- overlays ---- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  text-align: center;
  background: rgba(13, 10, 26, 0.88);
  z-index: 2;
}

.overlay.hidden { display: none; }

h1 {
  font-size: clamp(28px, 6vw, 48px);
  line-height: 1.3;
  color: var(--accent);
  text-shadow: 4px 4px 0 #4dd7ff, 8px 8px 0 rgba(0, 0, 0, 0.6);
}

h2 {
  font-size: clamp(20px, 4vw, 30px);
  color: var(--yellow);
}

.blink {
  font-size: clamp(10px, 2vw, 14px);
  animation: blink 1s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

button {
  font-family: inherit;
  font-size: clamp(12px, 2.4vw, 18px);
  color: #fff;
  background: var(--accent);
  border: 3px solid #fff;
  border-radius: 4px;
  padding: 14px 26px;
  cursor: pointer;
  box-shadow: 0 5px 0 #4e2d91;
}

button:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #4e2d91;
}

button.mini {
  font-size: clamp(8px, 1.6vw, 12px);
  padding: 8px 14px;
  background: #3d2b6b;
  box-shadow: 0 4px 0 #241844;
  margin-top: 10px;
}
button.mini:active { box-shadow: 0 1px 0 #241844; }

.hint {
  font-size: clamp(7px, 1.4vw, 10px);
  color: #9a8fc4;
  line-height: 1.8;
}

#res-grade {
  font-size: clamp(50px, 10vw, 90px);
  color: var(--yellow);
  text-shadow: 5px 5px 0 rgba(0, 0, 0, 0.6);
}

#res-score { font-size: clamp(16px, 3.4vw, 26px); }

#res-detail {
  font-size: clamp(8px, 1.8vw, 12px);
  line-height: 2.1;
  color: #cfc6ee;
}

#res-detail b { color: #fff; }

/* ---- touch pads ---- */

#pads {
  display: none;
  gap: 8px;
}

.pad {
  flex: 1;
  font-size: 22px;
  padding: 18px 0;
  background: #241b3d;
  border-color: #4a3d7a;
  box-shadow: 0 4px 0 #120d24;
  user-select: none;
  -webkit-user-select: none;
}

.pad:nth-child(1) { color: #ff5c8a; }
.pad:nth-child(2) { color: #4dd7ff; }
.pad:nth-child(3) { color: #7dff6e; }
.pad:nth-child(4) { color: #ffb84d; }

@media (pointer: coarse), (max-width: 700px) {
  #pads { display: flex; }
  #frame { width: min(98vw, 70vh * (640 / 480)); }
  /* the 4:3 screen is short on phones — tighten the overlay stack so it fits */
  .overlay { gap: clamp(6px, 2.2vw, 14px); padding: 10px; overflow-y: auto; }
  /* keep content centered when it fits, scrollable from the top when it doesn't */
  .overlay > :first-child { margin-top: auto; }
  .overlay > :last-child { margin-bottom: auto; }
  h1 { font-size: clamp(16px, 7vw, 34px); }
  button { padding: 10px 18px; }
  button.mini { padding: 6px 12px; margin-top: 4px; }
  .hint { line-height: 1.5; }
}

/* ---- leaderboard ---- */
.name-row, .import-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.name-row label { font-size: clamp(8px, 1.6vw, 12px); color: #9a8fc4; }
input {
  font-family: inherit;
  font-size: clamp(8px, 1.6vw, 12px);
  color: #fff;
  background: #241844;
  border: 3px solid #3d2b6b;
  border-radius: 4px;
  padding: 8px 10px;
  width: 12ch;
  text-transform: uppercase;
}
input:focus { outline: none; border-color: var(--accent); }
#import-input { width: 24ch; text-transform: none; }
#board-list {
  list-style: none;
  margin: 14px 0 4px;
  padding: 0;
  font-size: clamp(8px, 1.6vw, 12px);
  line-height: 2.1;
  min-width: 64%;
}
#board-list li {
  display: flex;
  gap: 10px;
  justify-content: space-between;
}
#board-list .rank { color: #9a8fc4; }
#board-list .who { flex: 1; text-align: left; }
#board-list li:first-child .who, #board-list li:first-child .pts { color: var(--yellow); }
#board-list .pts { font-variant-numeric: tabular-nums; }
#board-list .meta { color: #9a8fc4; }
#board-empty { color: #9a8fc4; }

/* ---- copyright notice ---- */
.notice-text {
  font-size: clamp(8px, 1.6vw, 12px);
  color: #cfc6ee;
  line-height: 2.1;
  max-width: 78%;
  text-transform: none;
}
.notice-text a { color: var(--accent); }

/* mobile: taps on the play area are game input, never scroll/zoom */
#game { touch-action: none; }

/* show the control hint that matches the device */
.touch-hint { display: none; }
@media (pointer: coarse) {
  .kb-hint { display: none; }
  .touch-hint { display: inline; }
}
