:root {
  --sky-1: #0f2337;
  --sky-2: #214463;
  --sky-3: #2f6a85;
  --ink: #e9edf3;
  --muted: #b9c7d8;
  --panel: rgba(8, 20, 34, 0.85);
  --panel-edge: rgba(247, 200, 105, 0.45);
  --accent: #f2c766;
  --danger: #ff6f61;
  --font-head: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  --font-main: "Trebuchet MS", "Lucida Sans Unicode", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  background:
    radial-gradient(circle at 12% 15%, rgba(255, 201, 110, 0.22) 0, rgba(255, 201, 110, 0) 32%),
    radial-gradient(circle at 85% 2%, rgba(108, 189, 219, 0.25) 0, rgba(108, 189, 219, 0) 28%),
    linear-gradient(165deg, var(--sky-1), var(--sky-2) 56%, var(--sky-3));
  color: var(--ink);
  font-family: var(--font-main);
  padding: clamp(10px, 2vw, 24px);
}

.game-shell {
  width: min(1100px, 100%);
  display: grid;
  gap: 12px;
}

.hud-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  border-radius: 14px;
  border: 1px solid var(--panel-edge);
  background: linear-gradient(140deg, rgba(16, 38, 61, 0.92), rgba(12, 26, 45, 0.86));
  backdrop-filter: blur(4px);
  padding: 10px 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

.hud-bar h1 {
  margin: 0;
  font-family: var(--font-head);
  font-size: clamp(1.2rem, 2.2vw, 1.6rem);
  letter-spacing: 0.04em;
  color: #fff2cc;
}

.hud-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.95rem;
}

.hud-stats strong {
  color: #fff;
}

.canvas-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(236, 210, 145, 0.48);
  box-shadow:
    0 20px 34px rgba(2, 8, 16, 0.48),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  background: #080d15;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 2rem;
  text-align: center;
  font-family: var(--font-head);
  font-size: clamp(1rem, 2vw, 1.5rem);
  line-height: 1.45;
  white-space: pre-line;
  color: #fff7de;
  background: linear-gradient(180deg, rgba(7, 17, 31, 0.55), rgba(7, 17, 31, 0.72));
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.overlay.show {
  opacity: 1;
  transform: translateY(0);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.mobile-controls {
  position: fixed;
  inset-inline: 0;
  bottom: max(10px, env(safe-area-inset-bottom));
  padding-inline: 14px;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 20;
}

.dpad,
.actions {
  pointer-events: auto;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 56px);
  gap: 8px;
  align-items: center;
}

.dpad .btn[data-key="ArrowUp"] {
  grid-column: 2;
}

.dpad .btn[data-key="ArrowLeft"] {
  grid-column: 1;
  grid-row: 2;
}

.dpad .btn[data-key="ArrowDown"] {
  grid-column: 2;
  grid-row: 2;
}

.dpad .btn[data-key="ArrowRight"] {
  grid-column: 3;
  grid-row: 2;
}

.actions {
  display: grid;
  gap: 10px;
}

.btn {
  width: 56px;
  height: 56px;
  border: 1px solid rgba(255, 233, 185, 0.45);
  border-radius: 14px;
  color: #fef3d8;
  background: linear-gradient(160deg, rgba(34, 66, 98, 0.9), rgba(13, 29, 49, 0.9));
  font: 600 0.82rem var(--font-main);
  letter-spacing: 0.02em;
  transition: transform 80ms ease, filter 80ms ease;
  touch-action: manipulation;
}

.btn.action {
  width: 76px;
  border-radius: 18px;
}

.btn.active {
  transform: translateY(1px) scale(0.96);
  filter: brightness(1.15);
}

@media (max-width: 760px) {
  .hud-stats {
    gap: 8px;
    font-size: 0.88rem;
  }

  .legend {
    font-size: 0.82rem;
  }
}

@media (pointer: coarse) {
  body {
    padding-bottom: 180px;
  }

  .legend {
    display: none;
  }

  .mobile-controls {
    display: flex;
  }
}
