@import url("https://fonts.googleapis.com/css2?family=M+PLUS+1p:wght@400;600;700;800&family=Oxanium:wght@500;700&display=swap");

:root {
  --bg: #0b100f;
  --hud: #ecf8ef;
  --accent: #56c271;
  --accent-2: #59a6ff;
  --danger: #ff6868;
  --card: rgba(10, 20, 16, 0.7);
  --card-border: rgba(140, 255, 190, 0.25);
  --glow: rgba(86, 194, 113, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(1200px 800px at 15% 10%, #13211c 0%, #0a0f0e 45%, #070b0a 100%);
  font-family: "M PLUS 1p", "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  overflow: hidden;
  touch-action: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 500px at 80% 20%, rgba(89, 166, 255, 0.12), transparent 60%),
    radial-gradient(700px 600px at 20% 80%, rgba(86, 194, 113, 0.15), transparent 65%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.02), rgba(255,255,255,0.02) 1px, transparent 1px, transparent 4px);
  pointer-events: none;
  mix-blend-mode: screen;
}

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

#touch-ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 12;
}

#touch-ui .pad {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: 170px;
  height: 170px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 10px;
  pointer-events: none;
}

.pad-btn {
  border: 1px solid rgba(140, 255, 190, 0.25);
  background: rgba(10, 20, 16, 0.75);
  color: var(--hud);
  border-radius: 16px;
  font-size: 20px;
  font-weight: 700;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  box-shadow: 0 10px 20px rgba(0,0,0,0.35), inset 0 0 16px rgba(86, 194, 113, 0.15);
}

.pad-btn:active {
  background: rgba(86, 194, 113, 0.25);
  transform: translateY(1px);
}

.pad-btn.up { grid-area: 1 / 2; }
.pad-btn.left { grid-area: 2 / 1; }
.pad-btn.right { grid-area: 2 / 3; }
.pad-btn.down { grid-area: 3 / 2; }

#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  color: var(--hud);
  z-index: 10;
  user-select: none;
}

#hud .row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
}

.hud-card {
  padding: 14px 16px 12px;
  min-width: 260px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--card-border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4), inset 0 0 30px rgba(20, 40, 30, 0.25);
  backdrop-filter: blur(10px);
  animation: hud-in 700ms ease-out both;
}

.hud-title {
  font-family: "Oxanium", "M PLUS 1p", sans-serif;
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 13px;
  text-transform: uppercase;
  color: rgba(236, 248, 239, 0.75);
  margin-bottom: 8px;
}

.stat {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(6, 15, 11, 0.6);
  border: 1px solid rgba(140, 255, 190, 0.12);
  min-width: 120px;
}

.stat .label {
  font-size: 11px;
  color: rgba(236, 248, 239, 0.65);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.stat .value {
  font-family: "Oxanium", "M PLUS 1p", sans-serif;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.04em;
  text-shadow: 0 0 12px rgba(86, 194, 113, 0.25);
}

.meter {
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 10px var(--glow);
  transition: width 200ms ease;
}

.message {
  margin-top: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--accent);
  background: rgba(10, 20, 16, 0.6);
  border: 1px solid rgba(86, 194, 113, 0.25);
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.controls {
  margin-top: 8px;
  font-size: 11px;
  color: rgba(236, 248, 239, 0.5);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 10%, rgba(12, 28, 20, 0.7), rgba(0,0,0,0.85));
  display: grid;
  place-items: center;
  z-index: 20;
  color: #fff;
}

#overlay.hidden { display: none; }

.overlay-card {
  padding: 28px 32px 24px;
  border-radius: 20px;
  background: rgba(6, 14, 10, 0.85);
  border: 1px solid rgba(140, 255, 190, 0.25);
  box-shadow: 0 20px 40px rgba(0,0,0,0.5), inset 0 0 30px rgba(20, 40, 30, 0.2);
  text-align: center;
  animation: overlay-in 500ms ease-out both;
}

#overlay-title {
  font-family: "Oxanium", "M PLUS 1p", sans-serif;
  font-size: 46px;
  font-weight: 700;
  letter-spacing: 6px;
  margin-bottom: 8px;
  text-shadow: 0 0 20px rgba(86, 194, 113, 0.4);
}

#overlay-sub {
  margin-bottom: 18px;
  font-size: 14px;
  color: rgba(236, 248, 239, 0.7);
}

#restart {
  padding: 10px 18px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #0b1c0f;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(0,0,0,0.35);
  transition: transform 140ms ease, filter 140ms ease;
}

#restart:hover { filter: brightness(1.1); transform: translateY(-1px); }
#restart:active { transform: translateY(0); }

@keyframes hud-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes overlay-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 640px) {
  #hud {
    left: 12px;
    right: 12px;
  }

  .hud-card {
    width: calc(100vw - 24px);
  }

  #hud .row {
    gap: 10px;
    flex-wrap: wrap;
  }

  .stat {
    flex: 1 1 45%;
  }

  #touch-ui .pad {
    left: 10px;
    bottom: 10px;
    width: 150px;
    height: 150px;
    gap: 8px;
  }
}

@media (pointer: fine) {
  #touch-ui { display: none; }
}
