:root {
  color-scheme: dark;
  --ink: #f7fbff;
  --muted: #9fbfd1;
  --panel: rgba(5, 23, 35, 0.74);
  --panel-strong: rgba(4, 16, 26, 0.88);
  --line: rgba(215, 241, 255, 0.18);
  --gold: #ffd166;
  --coral: #ff7a66;
  --teal: #31c6b4;
  --deep: #061825;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 105%, rgba(18, 147, 126, 0.42), transparent 42%),
    linear-gradient(160deg, #092b3e 0%, #0d5560 45%, #132f44 100%);
}

button {
  font: inherit;
}

.game-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  width: min(1180px, 100vw);
  height: 100dvh;
  margin: 0 auto;
  padding: 16px;
}

.hud {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4.4vw, 3.8rem);
  line-height: 0.92;
  letter-spacing: 0;
  text-transform: uppercase;
}

.target-panel,
.score-panel {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(16px);
}

.target-panel {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 12px;
  min-width: 284px;
  padding: 12px 16px;
}

.target-panel .hud-label {
  grid-column: 2;
}

.target-image {
  grid-row: 1 / 3;
  width: 86px;
  height: 86px;
  object-fit: contain;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  padding: 8px;
}

.target-name {
  display: block;
  max-width: 164px;
  overflow: hidden;
  font-size: 1.55rem;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(74px, 1fr));
  gap: 1px;
  overflow: hidden;
  min-width: 172px;
}

.score-panel > div {
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
}

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

.score-panel strong {
  color: var(--gold);
  font-size: 1.85rem;
  line-height: 1;
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(215, 241, 255, 0.2);
  border-radius: 8px;
  background: #0b3548;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.34);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.toast {
  position: absolute;
  left: 50%;
  top: 18px;
  min-width: 120px;
  max-width: min(420px, calc(100% - 32px));
  min-height: 36px;
  transform: translateX(-50%) translateY(-12px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 8px 14px;
  opacity: 0;
  color: #061825;
  background: rgba(255, 209, 102, 0.92);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
  font-weight: 900;
  text-align: center;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.dpad {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 6px;
}

.dpad-button {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-strong);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: 900;
  line-height: 1;
}

.dpad-button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.dpad-button:active,
.dpad-button.is-active {
  color: #03141f;
  background: var(--gold);
}

.dpad-up {
  grid-column: 2;
  grid-row: 1;
}

.dpad-left {
  grid-column: 1;
  grid-row: 2;
}

.dpad-right {
  grid-column: 3;
  grid-row: 2;
}

.dpad-down {
  grid-column: 2;
  grid-row: 3;
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .game-shell {
    min-height: 100dvh;
    height: auto;
    padding: 10px;
  }

  .hud {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: clamp(2rem, 12vw, 3.25rem);
  }

  .target-panel,
  .score-panel {
    min-width: 0;
  }

  .stage {
    aspect-ratio: 9 / 13;
    min-height: 520px;
  }

  .dpad {
    right: 12px;
    bottom: 12px;
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(3, 42px);
  }

  .dpad-button {
    width: 42px;
    height: 42px;
  }
}

@media (max-width: 420px) {
  .score-panel {
    grid-template-columns: 1fr 1fr;
  }

  .target-name {
    max-width: 180px;
  }
}
