*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg-0: #08131d;
  --bg-1: #0e1d2b;
  --panel: rgba(9, 18, 29, 0.88);
  --line: rgba(255, 204, 0, 0.34);
  --line-strong: rgba(255, 204, 0, 0.74);
  --text: #ecf4ff;
  --muted: #9fb8cc;
  --accent: #ffcc00;
  --accent-2: #ffbe6e;
  --radius: 16px;
  --control-size: 64px;
  --stick-size: 138px;
}

html {
  height: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100dvh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 16% 12%, rgba(255, 204, 0, 0.1), transparent 28%),
    linear-gradient(165deg, var(--bg-0), #040910 46%, var(--bg-1));
  color: var(--text);
  font-family: "Nunito", "Space Grotesk", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.bg-pixel {
  opacity: 0.5;
  background:
    linear-gradient(180deg, rgba(3, 6, 11, 0.92), rgba(4, 9, 16, 0.98)),
    repeating-linear-gradient(0deg, rgba(255, 204, 0, 0.08) 0 1px, transparent 1px 20px),
    repeating-linear-gradient(90deg, rgba(255, 204, 0, 0.08) 0 1px, transparent 1px 20px);
  background-size: 100% 100%, 20px 20px, 20px 20px;
}

.bg-stars {
  background-image:
    radial-gradient(circle at 20% 20%, rgba(255, 204, 0, 0.12), transparent 34%),
    radial-gradient(circle at 80% 80%, rgba(255, 204, 0, 0.08), transparent 26%);
}

.app-shell {
  width: 100%;
  height: 100%;
  max-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.game-wrapper {
  position: relative;
  width: 100%;
  max-width: min(920px, 100vw);
  height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 0;
  flex-shrink: 0;
}

.brand-mark {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.game-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.action-btn {
  border: 1px solid rgba(255, 204, 0, 0.44);
  border-radius: 12px;
  min-width: 88px;
  padding: 8px 11px;
  background: linear-gradient(170deg, rgba(21, 31, 45, 0.9), rgba(8, 14, 23, 0.95));
  color: var(--accent);
  font-family: "Space Grotesk", sans-serif;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.action-btn:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.action-btn[aria-pressed="true"] {
  border-color: var(--line-strong);
}

.game-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.canvas-shell {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(8px, 1.5vw, 14px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 22px 34px rgba(0, 0, 0, 0.38);
}

#canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border: 2px solid rgba(242, 249, 255, 0.85);
  background: #000;
  touch-action: none;
}

.sprite-cache {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.touch-controls {
  display: none;
  margin-top: 10px;
  grid-template-columns: repeat(3, var(--control-size));
  grid-template-areas:
    ". up ."
    "left down right";
  gap: 10px;
  touch-action: none;
}

.touch-btn {
  width: var(--control-size);
  height: var(--control-size);
  border-radius: 14px;
  border: 1px solid rgba(255, 204, 0, 0.6);
  background: rgba(7, 16, 26, 0.95);
  color: var(--accent);
  font-size: clamp(18px, calc(var(--control-size) * 0.36), 28px);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.touch-btn:active {
  transform: scale(0.97);
}

.touch-up { grid-area: up; }
.touch-left { grid-area: left; }
.touch-right { grid-area: right; }
.touch-down { grid-area: down; }

.virtual-stick {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 10px;
  gap: 8px;
}

.stick-base {
  width: var(--stick-size);
  height: var(--stick-size);
  border-radius: 50%;
  border: 1px solid rgba(255, 204, 0, 0.64);
  background: radial-gradient(circle at 35% 30%, rgba(255, 204, 0, 0.2), rgba(7, 15, 23, 0.94));
  position: relative;
  touch-action: none;
}

.stick-knob {
  width: calc(var(--stick-size) * 0.4);
  height: calc(var(--stick-size) * 0.4);
  border-radius: 50%;
  position: absolute;
  left: calc(var(--stick-size) * 0.3);
  top: calc(var(--stick-size) * 0.3);
  border: 1px solid rgba(255, 255, 255, 0.58);
  background: rgba(255, 204, 0, 0.95);
  pointer-events: none;
}

.stick-help {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: rgba(8, 19, 29, 0.92);
  backdrop-filter: blur(6px);
  border-radius: var(--radius);
}

.overlay-brand {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.overlay h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 800;
  color: #ffee95;
  text-shadow: 0 0 20px rgba(255, 204, 0, 0.35);
}

.overlay-desc {
  margin: 0;
  max-width: 28ch;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

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

.overlay-hint kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.3);
  font-family: inherit;
  font-size: 12px;
}

.mobile-hint {
  display: none;
}

.btn-start {
  margin-top: 8px;
  padding: 14px 36px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffdd55, #ffcc00);
  color: #08131d;
  font-family: inherit;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 204, 0, 0.35);
  transition: transform 0.15s ease;
}

.btn-start:hover {
  transform: scale(1.04);
}

body.reduced-motion,
body.reduced-motion * {
  animation: none !important;
  transition: none !important;
}

@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: grid;
  }

  .mobile-hint {
    display: block;
  }

  .overlay-hint:not(.mobile-hint) {
    display: none;
  }
}

@media (max-width: 640px) {
  .action-btn {
    min-width: 72px;
    padding: 7px 9px;
    font-size: 11px;
  }

  .touch-controls {
    gap: 8px;
    --control-size: 56px;
  }
}
