:root {
  color-scheme: dark;
  --bg: #050712;
  --panel: #0d1022;
  --line: #21f2ff;
  --line-soft: rgba(33, 242, 255, 0.2);
  --pink: #ff3df2;
  --gold: #ffd166;
  --text: #f6fbff;
  --muted: #8fa6b8;
  --danger: #ff4d6d;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  align-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 61, 242, 0.16), transparent 28%),
    radial-gradient(circle at 80% 5%, rgba(33, 242, 255, 0.14), transparent 26%),
    linear-gradient(180deg, #050712 0%, #090b18 58%, #02030a 100%);
  color: var(--text);
  display: flex;
  font-family: "Trebuchet MS", Arial, sans-serif;
  justify-content: center;
  min-height: 100%;
  overflow: hidden;
  padding: max(10px, env(safe-area-inset-top)) 12px max(96px, env(safe-area-inset-bottom));
}

.game-shell {
  display: grid;
  gap: 10px;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  width: min(100%, 1120px);
}

.hud {
  background: rgba(13, 16, 34, 0.86);
  border: 1px solid var(--line-soft);
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(5, 1fr);
  padding: 10px;
}

.hud div {
  min-width: 0;
  text-align: center;
}

.hud span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  letter-spacing: 0;
}

.hud strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.canvas-wrap {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 0;
  position: relative;
}

canvas {
  aspect-ratio: 672 / 528;
  background: #03040c;
  border: 1px solid rgba(33, 242, 255, 0.36);
  box-shadow: 0 0 28px rgba(33, 242, 255, 0.18), inset 0 0 30px rgba(255, 61, 242, 0.08);
  display: block;
  image-rendering: pixelated;
  height: min(100%, calc((100vw - 24px) * 0.7857));
  max-height: 100%;
  max-width: min(100%, 1120px);
  touch-action: none;
  width: auto;
}

.overlay {
  align-items: center;
  background: rgba(3, 4, 12, 0.6);
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  justify-content: center;
  left: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0;
  pointer-events: none;
  position: absolute;
  right: 0;
  text-align: center;
  top: 0;
  transition: opacity 150ms ease;
}

.overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay h1 {
  display: none;
}

.overlay-art {
  height: 100%;
  inset: 0;
  object-fit: cover;
  opacity: 1;
  position: absolute;
  width: 100%;
  z-index: 0;
}

.overlay-copy {
  align-items: center;
  background: linear-gradient(180deg, rgba(3, 4, 12, 0.06), rgba(3, 4, 12, 0.88));
  display: flex;
  flex-direction: column;
  gap: 0;
  inset: auto 0 0;
  justify-content: flex-end;
  padding: 20px 22px 24px;
  position: absolute;
  z-index: 1;
}

button {
  background: #111633;
  border: 1px solid rgba(33, 242, 255, 0.56);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

button:active {
  transform: translateY(1px);
}

#startButton {
  color: var(--gold);
  font-size: 18px;
  min-height: 44px;
  padding: 10px 28px;
  text-transform: uppercase;
}

.touch-pad {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 48px);
  justify-content: center;
  left: 50%;
  position: fixed;
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
}

.touch-pad button {
  border-radius: 4px;
  color: var(--line);
  font-size: 20px;
  min-height: 48px;
  width: 56px;
}

.touch-pad [data-dir="up"] {
  grid-column: 2;
}

.touch-pad [data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.touch-pad [data-dir="down"] {
  grid-column: 2;
  grid-row: 3;
}

.touch-pad [data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.zoom-control {
  display: none;
}

.zoom-control div {
  align-items: center;
  display: flex;
  gap: 2px;
  justify-content: center;
}

.zoom-control button {
  border-color: rgba(57, 255, 136, 0.48);
  color: #39ff88;
  font-size: 17px;
  height: 28px;
  line-height: 1;
  padding: 0;
  width: 30px;
}

.zoom-control output {
  color: var(--gold);
  display: inline-block;
  font-size: 13px;
  min-width: 42px;
  text-align: center;
}

@media (max-width: 760px), (pointer: coarse) {
  body {
    align-items: flex-start;
    overflow: hidden;
    padding: max(6px, env(safe-area-inset-top)) 8px max(6px, env(safe-area-inset-bottom));
  }

  .game-shell {
    gap: 6px;
    grid-template-rows: auto minmax(0, 1fr);
    height: calc(100dvh - max(6px, env(safe-area-inset-top)) - max(6px, env(safe-area-inset-bottom)));
    width: 100%;
  }

  .hud {
    gap: 4px;
    grid-template-columns: repeat(3, 1fr);
    padding: 7px;
  }

  .hud span {
    font-size: 10px;
  }

  .hud strong {
    font-size: 15px;
  }

  .canvas-wrap {
    align-items: stretch;
    height: 100%;
    min-height: 0;
    width: 100%;
  }

  canvas {
    aspect-ratio: auto;
    height: 100%;
    max-width: 100%;
    width: 100%;
  }

  .touch-pad {
    display: none;
    gap: 10px;
    grid-template-columns: repeat(3, 74px);
    grid-template-rows: repeat(3, 58px);
    justify-self: center;
    left: auto;
    position: static;
    transform: none;
    z-index: 5;
  }

  .touch-pad button {
    background: rgba(17, 22, 51, 0.82);
    border-color: rgba(57, 255, 136, 0.76);
    color: #39ff88;
    font-size: 28px;
    min-height: 58px;
    width: 74px;
  }

  .zoom-control {
    align-items: center;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  body {
    padding: max(4px, env(safe-area-inset-top)) 8px max(4px, env(safe-area-inset-bottom));
  }

  .game-shell {
    display: block;
    height: calc(100dvh - max(4px, env(safe-area-inset-top)) - max(4px, env(safe-area-inset-bottom)));
    position: relative;
    width: 100%;
  }

  .hud {
    background: rgba(13, 16, 34, 0.66);
    grid-template-columns: 1fr;
    grid-template-rows: repeat(5, minmax(0, 1fr));
    left: 0;
    max-width: 82px;
    min-height: 100%;
    position: absolute;
    top: 0;
    z-index: 4;
    padding: 6px;
  }

  .hud span {
    font-size: 9px;
  }

  .hud strong {
    font-size: 13px;
  }

  .canvas-wrap {
    height: 100%;
    width: 100%;
  }

  canvas {
    height: 100%;
    width: 100%;
  }

  .touch-pad {
    display: none;
  }

  .zoom-control {
    display: flex;
    background: rgba(8, 12, 28, 0.9);
    border: 1px solid rgba(57, 255, 136, 0.52);
    border-radius: 7px;
    bottom: max(8px, env(safe-area-inset-bottom));
    flex-direction: column;
    gap: 2px;
    padding: 4px;
    position: fixed;
    right: 10px;
    z-index: 6;
  }
}
