:root {
  color-scheme: dark;
  --bg: #0b0909;
  --panel: #181416;
  --panel-2: #241d1e;
  --ink: #e8e2d4;
  --muted: #9a948a;
  --acid: #9cc94e;
  --alarm: #ff6f61;
  --blood: #8a1c1c;
  --blood-dark: #4e0f0f;
  --wire: #4d8ba8;
  --skin: #d5a375;
  --gold: #ffcb69;
  --shadow: rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 16% 8%, rgba(138, 28, 28, 0.18), transparent 24rem),
    radial-gradient(circle at 90% 20%, rgba(156, 201, 78, 0.07), transparent 22rem),
    radial-gradient(circle at 50% 110%, rgba(78, 15, 15, 0.25), transparent 30rem),
    linear-gradient(135deg, #0c0a0a 0%, #16120f 46%, #100b0d 100%);
}

button {
  min-height: 42px;
  border: 1px solid rgba(232, 226, 212, 0.16);
  border-radius: 8px;
  color: var(--ink);
  background: #221c1d;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 30px var(--shadow);
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

button:hover,
button:focus-visible {
  border-color: rgba(196, 60, 48, 0.85);
  background: #2e2224;
  outline: none;
}

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

.app-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 28px);
  display: grid;
  place-items: center;
}

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

.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.hud > div,
.toolbar {
  border: 1px solid rgba(232, 226, 212, 0.1);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(46, 36, 37, 0.92), rgba(26, 20, 21, 0.94));
  box-shadow: 0 18px 50px var(--shadow);
}

.hud > div {
  min-height: 72px;
  padding: 12px 14px;
  display: grid;
  align-content: center;
  gap: 4px;
}

.hud-label {
  color: var(--muted);
  font-size: 13px;
}

.hud strong {
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1;
}

#target {
  color: var(--gold);
}

#buffs {
  color: var(--acid);
  font-size: clamp(13px, 2vw, 17px);
  line-height: 1.3;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(138, 28, 28, 0.4);
  border-radius: 8px;
  aspect-ratio: 1;
  background:
    linear-gradient(135deg, rgba(138, 28, 28, 0.12), transparent 34%),
    #0e0c0b;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.6),
    inset 0 0 90px rgba(0, 0, 0, 0.45);
}

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

.overlay {
  position: absolute;
  inset: 0;
  padding: clamp(18px, 5vw, 54px);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  text-align: center;
  background:
    linear-gradient(rgba(10, 8, 8, 0.55), rgba(10, 8, 8, 0.8)),
    radial-gradient(circle at 50% 42%, rgba(138, 28, 28, 0.16), transparent 20rem),
    repeating-linear-gradient(90deg, transparent 0 28px, rgba(196, 60, 48, 0.05) 28px 30px);
}

.overlay.is-hidden {
  display: none;
}

.overlay h1 {
  max-width: 12em;
  margin: 0;
  font-size: clamp(34px, 8vw, 74px);
  line-height: 1.02;
  color: #efe7d3;
  text-shadow:
    0 0 18px rgba(138, 28, 28, 0.85),
    0 2px 4px rgba(0, 0, 0, 0.8);
  animation: title-flicker 4.2s infinite;
}

.overlay p {
  max-width: 30em;
  margin: 0;
  color: var(--muted);
  font-size: clamp(15px, 2.6vw, 18px);
  line-height: 1.7;
}

.overlay.is-death {
  background:
    linear-gradient(rgba(46, 6, 6, 0.62), rgba(14, 4, 4, 0.88)),
    radial-gradient(circle at 50% 30%, rgba(196, 40, 30, 0.28), transparent 22rem);
  animation: death-flash 700ms ease-out;
}

.overlay.is-death h1 {
  color: #ff8d7d;
  text-shadow:
    0 0 26px rgba(196, 40, 30, 0.9),
    0 2px 4px rgba(0, 0, 0, 0.9);
}

@keyframes title-flicker {
  0%,
  100% {
    opacity: 1;
  }
  71% {
    opacity: 1;
  }
  72% {
    opacity: 0.55;
  }
  74% {
    opacity: 1;
  }
  76% {
    opacity: 0.7;
  }
  78% {
    opacity: 1;
  }
}

@keyframes death-flash {
  0% {
    background-color: rgba(160, 20, 12, 0.75);
  }
  100% {
    background-color: transparent;
  }
}

#startButton {
  min-width: 172px;
  padding: 0 22px;
  color: #f6ebe6;
  border-color: rgba(196, 60, 48, 0.85);
  background: linear-gradient(180deg, #a32b22, #6d1512);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

#startButton:hover,
#startButton:focus-visible {
  background: linear-gradient(180deg, #bb352a, #7e1a16);
}

.toolbar {
  min-height: 60px;
  padding: 9px;
  display: grid;
  grid-template-columns: 88px 88px 96px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.status {
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.touch-pad {
  display: none;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 48px);
  justify-content: center;
  gap: 8px;
}

.touch-pad button {
  min-height: 48px;
  padding: 0;
  font-size: 19px;
}

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

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

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

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

@media (max-width: 680px) {
  .app-shell {
    align-items: start;
  }

  .hud > div {
    min-height: 60px;
    padding: 10px;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud > div:last-child {
    grid-column: 1 / -1;
    min-height: 48px;
  }

  .toolbar {
    grid-template-columns: repeat(3, 1fr);
  }

  .status {
    grid-column: 1 / -1;
    min-height: 20px;
    text-align: center;
  }

  .touch-pad {
    display: grid;
  }
}
