:root {
  color-scheme: dark;
  --bg: #0e1016;
  --panel: #1c2030;
  --line: #3a4258;
  --text: #f2f4f8;
  --muted: #b7c0d4;
  --gold: #e6c15a;
  --touch: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, "Courier New", monospace;
  touch-action: manipulation;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
}

#frame {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
  background: #161822;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #161822;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#hud {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

#hud[hidden] { display: none !important; }

.neon {
  --glow: #3df0ff;
  position: absolute;
  pointer-events: auto;
  margin: 0;
  padding: 8px 12px;
  min-width: 96px;
  border: 2px solid var(--glow);
  background: rgba(5, 8, 16, 0.88);
  color: var(--glow);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  text-shadow: 0 0 8px var(--glow);
  box-shadow: 0 0 10px var(--glow), inset 0 0 12px color-mix(in srgb, var(--glow) 35%, transparent);
}

.neon.cyan { --glow: #3df0ff; top: 10px; left: 10px; text-align: left; }
.neon.pink { --glow: #ff3d9a; top: 10px; right: 10px; }
.neon.violet { --glow: #c06bff; bottom: 10px; left: 10px; }
.neon.lime { --glow: #c6ff3d; bottom: 10px; right: 10px; color: #e9ffb0; }

.neon span {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-shadow: 0 0 6px var(--glow);
}

.neon:hover,
.neon:active {
  background: color-mix(in srgb, var(--glow) 18%, #070910);
}

.neon:focus-visible {
  outline: 2px solid var(--glow);
  outline-offset: 2px;
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 10, 16, 0.72);
}

#overlay.open { display: flex; }

.panel {
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 26px 22px 22px;
  text-align: center;
}

.panel h1 {
  margin: 0;
  font-size: 64px;
  letter-spacing: 0.14em;
  line-height: 1;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 28px;
}

.sub {
  margin: 10px 0 18px;
  color: var(--muted);
  line-height: 1.4;
}

.panel button {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 12px 14px;
  border: 2px solid var(--line);
  background: #262b3d;
  color: var(--text);
  font: inherit;
  font-weight: 650;
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
}

.panel button:hover:not(:disabled),
.panel button:active:not(:disabled) {
  border-color: var(--gold);
}

.panel button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.panel button:disabled {
  opacity: 0.4;
  cursor: default;
}

.panel button.primary {
  background: #3a3420;
  border-color: var(--gold);
  color: #ffe7a3;
}

.panel button.frontier {
  border-color: var(--gold);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin: 10px 0 12px;
}

.level-grid button {
  margin: 0;
  padding: 10px 0;
  font-size: 14px;
}

.tiny {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#touch {
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
}

.side {
  display: flex;
  gap: 8px;
  align-items: center;
}

#touch .side:first-child { flex: 1; }

#touch button {
  width: 68px;
  height: 68px;
  border-radius: 16px;
  border: 2px solid #3a4258;
  background: #262b3d;
  color: var(--text);
  font-size: 26px;
  font-weight: 700;
  touch-action: none;
}

#touch button:active,
#touch button.held {
  background: var(--gold);
  color: #1a1c24;
  border-color: var(--gold);
}

@media (max-width: 900px), (pointer: coarse) {
  #touch { display: flex; }
}

@media (max-width: 700px) {
  #touch button { width: 58px; height: 58px; }
  .panel h1 { font-size: 48px; }
  .neon { font-size: 11px; min-width: 76px; padding: 6px 8px; letter-spacing: 0.08em; }
  .level-grid { grid-template-columns: repeat(5, 1fr); }
}

#touch .jump { margin-left: auto; }

body.tablet #hud,
body.tablet #overlay {
  position: fixed;
  z-index: 6;
  inset: auto;
}

body.tablet #overlay { z-index: 7; }

body.tablet #touch {
  display: none;
  position: fixed;
  z-index: 4;
  margin: 0;
  padding: 0;
  pointer-events: none;
  background: transparent;
}

body.tablet.playing #touch { display: block; }

body.tablet #touch .side {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

body.tablet #touch button {
  position: absolute;
  pointer-events: auto;
  width: 76px;
  height: 76px;
  margin: 0;
  bottom: 72px;
  font-size: 30px;
}

body.tablet #touch .left { left: 18px; }
body.tablet #touch .right { left: 106px; }
body.tablet #touch .up { right: 18px; left: auto; }

body.fullscreen,
body.fullscreen #frame {
  width: 100%;
  height: 100%;
  margin: 0;
}

body.fullscreen #frame {
  position: fixed;
  inset: 0;
}

body.fullscreen #stage {
  box-shadow: none;
}
