* {
  box-sizing: border-box;
}

:root {
  --bg-a: #050615;
  --bg-b: #0f1140;
  --hud-bg: rgba(11, 13, 38, 0.72);
  --hud-border: rgba(128, 223, 255, 0.52);
  --text: #f4f8ff;
  --accent-a: #69d8ff;
  --accent-b: #f86bff;
  --accent-c: #ffd166;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 10% 0%, #21318f 0%, transparent 65%),
    radial-gradient(900px 500px at 95% 90%, #5a1f83 0%, transparent 70%),
    linear-gradient(140deg, var(--bg-a), var(--bg-b));
}

.app {
  width: min(1100px, 100%);
  height: 100dvh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
.hud { width: 100%; flex: 0 0 auto; }

.hud {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.chip {
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  border-radius: 12px;
  padding: 8px 10px;
  display: grid;
  gap: 2px;
  backdrop-filter: blur(6px);
}

.chip span {
  font-size: 12px;
  letter-spacing: 0.06em;
  color: #c8d5ff;
}

.chip strong {
  font-size: 20px;
  color: #ffffff;
}

.stage {
  position: relative;
  flex: 0 0 auto;
  max-width: 100%;
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid rgba(127, 225, 255, 0.45);
  box-shadow:
    0 18px 50px rgba(2, 2, 15, 0.6),
    inset 0 0 35px rgba(103, 169, 255, 0.08);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.touch-pad { display: none; width: 100%; min-height: 52px; flex: 0 0 52px; touch-action: none; user-select: none; border: 1px solid #6693b9; border-radius: 12px; background: #14263f; color: #c6eaff; align-items: center; justify-content: center; font-size: 13px; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  text-align: center;
  padding: 16px;
  background: rgba(3, 3, 18, 0.56);
}

.overlay.hidden {
  display: none;
}

.overlay h1 {
  margin: 0;
  font-size: clamp(32px, 4.4vw, 52px);
  letter-spacing: 0.05em;
  text-shadow:
    0 0 10px rgba(105, 216, 255, 0.8),
    0 0 20px rgba(248, 107, 255, 0.5);
}

.overlay p {
  max-width: 640px;
  margin: 0;
  font-size: clamp(14px, 1.6vw, 19px);
  color: #d7e3ff;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

button {
  min-height: 44px;
  touch-action: manipulation;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 700;
  color: #04071f;
  background: linear-gradient(90deg, var(--accent-a), var(--accent-c));
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

button:hover {
  transform: translateY(-1px) scale(1.02);
  filter: brightness(1.04);
}

button.ghost {
  color: #e6eeff;
  background: rgba(125, 146, 255, 0.2);
  border: 1px solid rgba(194, 215, 255, 0.6);
}

.controls {
  flex: 0 0 auto;
  display: flex;
  gap: 6px 14px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  font-size: 14px;
  color: #d6e2ff;
}

.controls p {
  margin: 0;
}

kbd {
  display: inline-block;
  min-width: 26px;
  text-align: center;
  margin: 0 2px;
  padding: 2px 7px;
  border-radius: 7px;
  border: 1px solid rgba(210, 225, 255, 0.5);
  background: rgba(7, 10, 26, 0.75);
  font-size: 12px;
}

@media (max-width: 800px) {
  .hud {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }
  .chip { padding: 5px; border-radius: 8px; }
  .chip span { font-size: 10px; }
  .chip strong { font-size: 16px; }
  .overlay { padding: 12px; gap: 10px; }
  .overlay h1 { font-size: clamp(24px, 5vw, 36px); }

  .controls {
    justify-content: center;
    padding-inline: 4px;
    font-size: 11px;
  }
  .controls p:last-child { display: none; }
}
@media (any-pointer: coarse), (max-width: 800px), (max-height: 480px) { .touch-pad { display: flex; } }
@media (max-height: 480px) {
  .app { gap: 5px; padding-block: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-bottom)); }
  .hud { max-width: 800px; }
  .chip { padding: 2px 8px; display: flex; align-items: center; justify-content: center; gap: 6px; }
  .chip span { font-size: 10px; }
  .chip strong { font-size: 15px; }
  .controls p { display: none; }
  .touch-pad { min-height: 44px; flex-basis: 44px; max-width: 600px; }
  .overlay h1 { font-size: 24px; }
  .overlay p { font-size: 12px; }
}
button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
