* {
  box-sizing: border-box;
}

:root {
  --bg0: #070b14;
  --bg1: #10182a;
  --panel: #141c2e;
  --ink: #e8eef8;
  --muted: #8592a8;
  --accent: #ff8a4a;
  --accent2: #5ec8ff;
  --danger: #ff6b6b;
  --line: #2a3548;
  --flip: #7ef0d4;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(ellipse 60% 35% at 50% -8%, #2a1a18 0%, transparent 55%),
    radial-gradient(ellipse 45% 28% at 85% 95%, #152038 0%, transparent 45%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  color: var(--ink);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.1rem 0.85rem 1.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
}

.top {
  text-align: center;
}

.top h1 {
  margin: 0;
  font-size: clamp(1.45rem, 4vw, 1.9rem);
  letter-spacing: 0.06em;
  font-weight: 800;
}

.subtitle {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

#stage {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  width: 100%;
  justify-content: center;
}

.hud {
  width: 96px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.7rem 0.45rem;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--line);
  border-radius: 6px;
}

.hud-block {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.hud-label {
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
}

.level-num,
.score,
.targets {
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.lives {
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  color: var(--danger);
}

.hud-legend {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.68rem;
  color: var(--muted);
}

.leg {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid #1d1c1c;
  flex-shrink: 0;
}

.s-drop { background: #5ec8ff; }
.s-bump { background: #ff6b6b; border-radius: 50%; }
.s-rol { background: #ffc857; border-radius: 50%; }

.canvas-wrap {
  position: relative;
  flex-shrink: 0;
  border: 3px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  background: #0a1020;
}

#game {
  display: block;
  width: 100%;
  max-width: 400px;
  height: auto;
  vertical-align: middle;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 20, 0.78);
  backdrop-filter: blur(4px);
  z-index: 2;
}

.overlay[hidden] {
  display: none;
}

.panel {
  width: min(88%, 300px);
  padding: 1.35rem 1.2rem 1.2rem;
  text-align: center;
  background: linear-gradient(160deg, #1a2438, #121a2c);
  border: 2px solid var(--line);
  border-radius: 10px;
}

.panel h2 {
  margin: 0 0 0.55rem;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
}

.panel-desc {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.controls-help {
  margin-top: 0.9rem;
  text-align: left;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.55;
}

.controls-help p {
  margin: 0.2rem 0;
}

.controls-help strong {
  color: var(--accent2);
  font-weight: 700;
}

.end-score {
  margin: 0.4rem 0 1rem;
  font-size: 1.05rem;
  color: var(--accent);
  font-weight: 700;
}

.btn {
  display: block;
  width: 100%;
  margin: 0.4rem 0 0;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(180deg, #ff9a5c, #e86a2a);
  color: #1a0e08;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-secondary {
  background: #243048;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--ink);
}

.toast {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  padding: 0.45rem 0.9rem;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent2);
  z-index: 3;
  pointer-events: none;
}

.toast[hidden] {
  display: none;
}

.hint {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.hint a {
  color: var(--accent2);
  text-decoration: none;
}

.hint a:hover {
  text-decoration: underline;
}

@media (max-width: 560px) {
  #stage {
    flex-direction: column;
    align-items: center;
  }

  .hud {
    width: 100%;
    max-width: 400px;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-around;
    gap: 0.5rem 0.75rem;
    padding: 0.55rem 0.6rem;
  }

  .hud-legend {
    width: 100%;
    flex-direction: row;
    justify-content: center;
    margin-top: 0;
    gap: 0.75rem;
  }

  .hud-block {
    align-items: center;
  }
}
