:root {
  --ink: #1f2328;
  --muted: #6a737d;
  --paper: #fff8ef;
  --panel: #fffdf7;
  --field: #f5ead9;
  --field-dark: #ecd8bb;
  --accent: #087ea4;
  --accent-strong: #046887;
  --pill: #1589d1;
  --skin: #e9ad8d;
  --skin-dark: #d98c6d;
  --danger: #b83d58;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 18%, rgba(8, 126, 164, 0.15), transparent 28rem),
    linear-gradient(135deg, #fff9ed, #e7f4ef 46%, #f8e5dd);
}

button {
  font: inherit;
}

.game-shell {
  width: min(94vw, 860px);
  display: grid;
  gap: 14px;
  padding: clamp(12px, 2.5vw, 22px);
}

.game-topbar {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr);
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border: 2px solid rgba(31, 35, 40, 0.12);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.86);
  box-shadow: 0 16px 42px rgba(70, 44, 25, 0.15);
  backdrop-filter: blur(10px);
}

.game-topbar div:last-child {
  text-align: right;
}

h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

strong {
  display: block;
  min-width: 3ch;
  font-size: 1.5rem;
  line-height: 1.1;
}

.stage {
  position: relative;
  width: min(94vw, 74vh, 800px);
  aspect-ratio: 1;
  justify-self: center;
  overflow: hidden;
  border: 3px solid rgba(31, 35, 40, 0.16);
  border-radius: 8px;
  background: var(--field);
  box-shadow: 0 24px 70px rgba(82, 54, 35, 0.23);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 248, 239, 0.58);
  transition: opacity 160ms ease;
}

.overlay.is-hidden {
  pointer-events: none;
  opacity: 0;
}

.main-action {
  width: clamp(72px, 14vw, 108px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: white;
  background: var(--accent);
  box-shadow: 0 18px 36px rgba(4, 104, 135, 0.28);
  cursor: pointer;
}

.main-action span {
  transform: translateX(0.08em);
  font-size: 2.7rem;
  line-height: 1;
}

.main-action:hover,
.mobile-pad button:hover {
  background: var(--accent-strong);
}

.main-action:active,
.mobile-pad button:active {
  transform: translateY(1px);
}

.mobile-pad {
  display: none;
  grid-template-columns: repeat(3, 58px);
  grid-template-areas:
    ". up ."
    "left down right";
  justify-content: center;
  gap: 10px;
}

.mobile-pad button {
  width: 58px;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  color: white;
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(4, 104, 135, 0.18);
  cursor: pointer;
  touch-action: manipulation;
}

.mobile-pad [data-dir="up"] {
  grid-area: up;
}

.mobile-pad [data-dir="left"] {
  grid-area: left;
}

.mobile-pad [data-dir="down"] {
  grid-area: down;
}

.mobile-pad [data-dir="right"] {
  grid-area: right;
}

@media (max-width: 720px), (pointer: coarse) {
  body {
    align-items: start;
  }

  .game-shell {
    width: 100%;
    min-height: 100vh;
    align-content: start;
  }

  .stage {
    width: min(94vw, 72vh);
  }

  .mobile-pad {
    display: grid;
  }
}

@media (max-width: 420px) {
  .game-topbar {
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
  }

  h1 {
    font-size: 1.25rem;
  }

  strong {
    font-size: 1.2rem;
  }
}
