:root {
  --bg: #1a1030;
  --panel: rgba(20, 12, 40, 0.92);
  --accent: #ffd23f;
  --accent2: #4cc9f0;
  --text: #f4f0ff;
  --danger: #ff5d73;
  --ok: #5dd39e;
}

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

html, body {
  height: 100%;
  background: #0c0818;
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* The stage holds the canvas and gives it whatever space is left over after
   the controls. The canvas keeps its 640:440 ratio (no stretching). */
#stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

canvas#game {
  display: block;
  /* exact pixel size is set by JS (resizeCanvas) to fit the stage while
     preserving the 640:440 ratio — scales up on desktop, down on mobile. */
  max-width: 100%;
  max-height: 100%;
  background: #0c0818;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* ---- Touch controls: retro keyboard-style arrow keys, below the field ---- */
/* Controls take roughly the lower third of the screen on mobile. */
#touch-controls {
  flex: 0 0 auto;
  width: 100%;
  min-height: 33vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
}
#touch-controls.hidden { display: none; }

/* Inverted-T arrow cluster like a real keyboard:  . ↑ ❚❚  /  ← ↓ →
   Keys are sized to fill the lower third and stay big enough for fingers. */
.keyboard {
  --key: min(30vw, 15.5vh);
  display: grid;
  grid-template-columns: repeat(3, var(--key));
  grid-template-rows: repeat(2, var(--key));
  grid-template-areas:
    ".    up    pause"
    "left down  right";
  gap: clamp(8px, 2.5vw, 16px);
  padding: clamp(10px, 3vw, 18px);
  border-radius: 16px;
  background: linear-gradient(#2b2545, #16122a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 6px 16px rgba(0, 0, 0, 0.55);
}
.key.up    { grid-area: up; }
.key.left  { grid-area: left; }
.key.down  { grid-area: down; }
.key.right { grid-area: right; }
.key.pause { grid-area: pause; }

/* Each button looks like a physical, retro keycap */
.key {
  width: var(--key);
  height: var(--key);
  font-family: "Courier New", monospace;
  font-size: calc(var(--key) * 0.4);
  font-weight: bold;
  line-height: 1;
  color: #2b2b33;
  border: none;
  border-radius: 11px;
  background: linear-gradient(#f6f3ea 0%, #ddd8c8 60%, #ccc6b4 100%);
  box-shadow:
    0 4px 0 #8d8a7e,
    0 6px 8px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 #ffffff;
  pointer-events: auto;
  transition: transform 0.04s ease, box-shadow 0.04s ease;
}
.key:active {
  transform: translateY(4px);
  box-shadow:
    0 0 0 #8d8a7e,
    0 2px 4px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 #ffffff;
}

/* Pause keycap tinted amber so it reads as a function key */
.key.pause {
  font-size: calc(var(--key) * 0.3);
  color: #5a3d00;
  background: linear-gradient(#ffe9a8 0%, #f5d57a 60%, #e6c25a 100%);
  box-shadow:
    0 4px 0 #a8841f,
    0 6px 8px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 #fffefb;
}
.key.pause:active { box-shadow: 0 0 0 #a8841f, 0 2px 4px rgba(0,0,0,0.4), inset 0 1px 0 #fffefb; }

/* ---- In-app high-score name entry ---- */
#name-entry {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 5, 18, 0.82);
  backdrop-filter: blur(3px);
  padding: 16px;
}
#name-entry.hidden { display: none; }

.ne-card {
  width: min(92vw, 360px);
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 18px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.ne-title {
  color: var(--accent);
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 8px;
}
.ne-score {
  color: var(--accent2);
  font-size: 17px;
  margin-bottom: 18px;
}
#ne-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 20px;
  text-align: center;
  border-radius: 10px;
  border: 2px solid rgba(76, 201, 240, 0.5);
  background: rgba(76, 201, 240, 0.10);
  color: var(--text);
  outline: none;
  margin-bottom: 16px;
}
#ne-input:focus { border-color: var(--accent); }
#ne-ok {
  width: 100%;
  padding: 13px;
  font-size: 19px;
  font-weight: bold;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #2a1c00;
  cursor: pointer;
}
#ne-ok:active { transform: scale(0.97); }
