:root {
  color-scheme: dark;
  --bg: #070713;
  --panel: rgba(16, 16, 40, 0.92);
  --neon: #37f2ff;
  --neon-2: #ff3ec9;
  --text: #d7e7ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(1200px 700px at 50% 20%, #14142e 0%, var(--bg) 65%);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.stage {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.wrap {
  position: relative;
  /* Fit 800x600 into both viewport axes, preserving the 4:3 ratio. */
  width: min(800px, 100%);
  width: min(800px, 100%, (100vh - 32px) * 4 / 3);
  width: min(800px, 100%, (100dvh - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 4 / 3);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 800 / 600;
  background: #05050e;
  border-radius: 10px;
  box-shadow: 0 0 22px rgba(55, 242, 255, 0.35), 0 0 80px rgba(255, 62, 201, 0.18);
  image-rendering: pixelated;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

#hud-controls {
  position: absolute;
  top: 0;
  right: 0;
  top: env(safe-area-inset-top, 0px);
  right: env(safe-area-inset-right, 0px);
  display: flex;
  flex-direction: row;
  gap: 8px;
  z-index: 5; /* above the canvas, below overlay panels */
  padding: 10px;
}

#hud-controls.hidden { display: none; }

#btn-pause,
#btn-mute {
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--neon);
  background: rgba(10, 12, 32, 0.72);
  border: 1px solid rgba(55, 242, 255, 0.45);
  border-radius: 12px;
  box-shadow: 0 0 12px rgba(55, 242, 255, 0.25);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#btn-pause:hover,
#btn-mute:hover {
  transform: none;
  box-shadow: 0 0 18px rgba(55, 242, 255, 0.55);
}

#btn-pause:active,
#btn-mute:active {
  transform: scale(0.92);
  background: rgba(55, 242, 255, 0.22);
  box-shadow: 0 0 22px rgba(55, 242, 255, 0.7);
}

#btn-mute[aria-pressed="true"] {
  color: var(--neon-2);
  border-color: rgba(255, 62, 201, 0.55);
  box-shadow: 0 0 12px rgba(255, 62, 201, 0.3);
}

#rotate-hint {
  display: none;
  position: relative;
  z-index: 11;
  pointer-events: none;
  margin-top: 10px;
  padding: 7px 12px;
  text-align: center;
  font-size: 0.82rem;
  letter-spacing: 0.5px;
  color: #a9c2e6;
  background: rgba(16, 16, 40, 0.7);
  border: 1px solid rgba(55, 242, 255, 0.25);
  border-radius: 999px;
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(5, 5, 14, 0.72);
  backdrop-filter: blur(3px);
}

.overlay.hidden { display: none; }

.panel {
  display: none;
  max-width: 560px;
  margin: 0 18px;
  padding: 28px 34px;
  text-align: center;
  background: var(--panel);
  border: 1px solid rgba(55, 242, 255, 0.45);
  border-radius: 14px;
  box-shadow: 0 0 30px rgba(55, 242, 255, 0.25);
}

.panel.active { display: block; }

.panel button {
  min-height: 48px;
  padding: 13px 26px;
}

h1, h2 {
  margin: 0 0 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--neon);
  text-shadow: 0 0 12px rgba(55, 242, 255, 0.8), 0 0 32px rgba(255, 62, 201, 0.5);
}

h1 { font-size: 2.1rem; }
h2 { font-size: 1.5rem; }

.hint {
  margin: 8px 0 14px;
  line-height: 1.5;
}

.keys {
  margin: 0 0 18px;
  line-height: 2;
  color: #a9c2e6;
  font-size: 0.92rem;
}

kbd {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid rgba(55, 242, 255, 0.5);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: rgba(55, 242, 255, 0.12);
  color: var(--neon);
  font-size: 0.85em;
}

button {
  padding: 11px 26px;
  font: inherit;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #05121a;
  background: linear-gradient(135deg, var(--neon), #6ef7c0);
  border: none;
  border-radius: 9px;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(55, 242, 255, 0.55);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

button:hover { transform: translateY(-2px); box-shadow: 0 0 28px rgba(55, 242, 255, 0.8); }
button:focus-visible { outline: 2px solid var(--neon-2); outline-offset: 3px; }

@media (max-width: 520px) {
  .panel { padding: 20px 18px; }
  h1 { font-size: 1.5rem; }
  .panel button {
    min-height: 48px;
    margin: 6px 0;
    padding: 13px 18px;
    width: 100%;
    max-width: 320px;
  }
  .panel { margin: 0 10px; }
}
