:root {
  --bg: #070b14;
  --bg-2: #0c1220;
  --panel: rgba(16, 24, 39, 0.92);
  --line: rgba(90, 214, 255, 0.18);
  --text: #e8eefc;
  --muted: #8b97b8;
  --cyan: #3ee0d6;
  --green: #5cff9d;
  --gold: #ffcc4d;
  --magenta: #ff5ad5;
  --red: #ff5c6a;
  --orange: #ff8a4c;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(62, 224, 214, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 100%, rgba(255, 90, 213, 0.08), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px 12px 12px;
  user-select: none;
  -webkit-user-select: none;
}

.app {
  width: min(100%, 720px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 40px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--cyan), var(--green) 45%, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 24px rgba(62, 224, 214, 0.15);
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  letter-spacing: 0.28em;
  font-size: 11px;
  text-transform: uppercase;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  flex: 1;
  min-width: min(100%, 420px);
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.stat.level {
  border-color: rgba(92, 255, 157, 0.35);
  box-shadow: 0 0 18px rgba(92, 255, 157, 0.08);
}

.stat.magnet.active {
  border-color: rgba(255, 90, 213, 0.55);
  box-shadow: 0 0 18px rgba(255, 90, 213, 0.18);
  animation: magnetPulse 1s ease-in-out infinite;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stat strong {
  font-variant-numeric: tabular-nums;
  display: block;
  margin-top: 3px;
  font-size: 18px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.magnet-bar {
  margin-top: 6px;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 90, 213, 0.15);
  overflow: hidden;
  visibility: hidden;   /* always reserve the space so the HUD never changes height */
}

.stat.magnet.active .magnet-bar { visibility: visible; }

.magnet-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--magenta), #ffb3ea);
  border-radius: inherit;
}

.board-wrap {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  touch-action: none;
  user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  background: #071018;
  border: 1px solid rgba(62, 224, 214, 0.28);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 0 40px rgba(62, 224, 214, 0.08),
    var(--shadow);
  touch-action: none;
}

.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.015),
    rgba(255, 255, 255, 0.015) 1px,
    transparent 3px,
    transparent 4px
  );
  mix-blend-mode: overlay;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  border-radius: var(--radius);
  background: rgba(5, 8, 16, 0.78);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  text-align: center;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.overlay.levelup {
  background: rgba(8, 22, 18, 0.55);
  pointer-events: none;
}

.overlay h2 {
  margin: 0 0 8px;
  letter-spacing: 0.16em;
  font-size: clamp(28px, 6vw, 42px);
}

.overlay p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.overlay .final {
  margin-top: 14px;
  font-size: 18px;
  color: var(--text);
}

.overlay button {
  margin-top: 18px;
}

.flash-eat .board-wrap canvas { animation: eatFlash 0.28s ease; }
.flash-magnet .board-wrap canvas { animation: magnetFlash 0.45s ease; }
.flash-level .board-wrap canvas { animation: levelFlash 0.7s ease; }
.flash-dead .board-wrap canvas { animation: deadFlash 0.55s ease; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

button {
  appearance: none;
  border: 1px solid rgba(62, 224, 214, 0.3);
  background: linear-gradient(180deg, rgba(62, 224, 214, 0.16), rgba(16, 24, 39, 0.9));
  color: var(--text);
  border-radius: 999px;
  padding: 10px 18px;
  font: inherit;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 44px;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

button:hover:not(:disabled) {
  border-color: var(--cyan);
  transform: translateY(-1px);
}

button:active:not(:disabled) { transform: translateY(1px) scale(0.98); }
button:disabled { opacity: 0.4; cursor: default; }

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 16px;
  color: var(--muted);
  font-size: 12px;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

.hint.mobile { display: none; }

.dpad-wrap {
  display: none;
  justify-content: center;
  padding-bottom: 8px;
}

.dpad {
  display: grid;
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  gap: 8px;
  touch-action: none;
  user-select: none;
}

.dpad button {
  width: clamp(44px, 6.5vh, 72px);
  height: clamp(44px, 6.5vh, 72px);
  border-radius: 18px;
  font-size: 22px;
  padding: 0;
  background: rgba(16, 24, 39, 0.95);
}

.dpad [data-dir="up"] { grid-area: up; }
.dpad [data-dir="left"] { grid-area: left; }
.dpad [data-dir="right"] { grid-area: right; }
.dpad [data-dir="down"] { grid-area: down; }

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
}

@media (max-width: 800px), (pointer: coarse) {
  .dpad-wrap { display: flex; }
  .hint.desktop { display: none; }
  .hint.mobile { display: block; }
}

@media (max-width: 620px) {
  .hud { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .stat { padding: 6px 7px; }
  .stat span { font-size: 9px; letter-spacing: 0.08em; }
  .brand { width: 100%; }
  body { padding: 10px 8px 14px; }
  .app { gap: 10px; }
  .stat strong { font-size: 14px; }
  .legend { font-size: 11px; gap: 8px 12px; }
}

.devbadge {
  position: fixed;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  z-index: 15;
  pointer-events: none;
  font: 700 11px system-ui, sans-serif;
  padding: 4px 10px;
  border-radius: 999px;
  background: #ffc93c;
  color: #1c2541;
  white-space: nowrap;
}



@keyframes magnetPulse {
  0%, 100% { box-shadow: 0 0 12px rgba(255, 90, 213, 0.12); }
  50% { box-shadow: 0 0 22px rgba(255, 90, 213, 0.35); }
}

@keyframes eatFlash {
  0% { filter: brightness(1.35) saturate(1.2); }
  100% { filter: none; }
}

@keyframes magnetFlash {
  0% { filter: drop-shadow(0 0 18px #ff5ad5) brightness(1.2); }
  100% { filter: none; }
}

@keyframes levelFlash {
  0% { filter: drop-shadow(0 0 22px #5cff9d) brightness(1.25); }
  100% { filter: none; }
}

@keyframes deadFlash {
  0% { filter: drop-shadow(0 0 24px #ff5c6a) brightness(1.3); }
  100% { filter: none; }
}

@keyframes popIn {
  from { transform: scale(0.86); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.overlay .card { animation: popIn 0.28s ease; }

@media (max-height: 720px) {
  .legend, .hint, .brand p { display: none; }
  .brand h1 { font-size: 22px; }
  .app { gap: 8px; }
  body { padding-top: 8px; }
  .dpad { gap: 4px; }
}

.mute { min-width: 44px; padding: 10px 14px; }

.power-pills {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  pointer-events: none;
  z-index: 3;
}

.pill {
  display: none;
  position: relative;
  overflow: hidden;
  padding: 4px 10px;
  border-radius: 999px;
  font: 700 11px/1.2 system-ui, sans-serif;
  letter-spacing: 0.08em;
  background: rgba(7, 11, 20, 0.85);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pill.on { display: block; }
.pill::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: var(--p, 0%);
  background: currentColor;
}

.pill.ghost { color: #8fdcff; border: 1px solid #6ad0ff; }
.pill.smash { color: #ffd36a; border: 1px solid #ff5c6a; }
.pill.warn { animation: pillBlink 0.3s steps(2) infinite; }

.boss-bar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  height: 18px;
  border-radius: 99px;
  background: rgba(7, 11, 20, 0.8);
  border: 1px solid rgba(255, 92, 106, 0.6);
  overflow: hidden;
  pointer-events: none;
  z-index: 3;
  visibility: hidden;
}

.boss-bar.show { visibility: visible; }
.boss-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--hp, 0%);
  background: linear-gradient(90deg, #8a1230, #ff5c6a);
  opacity: 0.75;
}

.boss-bar span {
  position: relative;
  z-index: 1;
  display: block;
  text-align: center;
  font: 700 11px/16px system-ui, sans-serif;
  letter-spacing: 0.12em;
  color: #fff;
}

.banner {
  position: absolute;
  left: 0;
  right: 0;
  top: 18%;
  text-align: center;
  font: 800 clamp(20px, 6vw, 32px)/1.2 "Trebuchet MS", system-ui, sans-serif;
  letter-spacing: 0.16em;
  color: #ff5c6a;
  text-shadow: 0 0 18px rgba(255, 92, 106, 0.7);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

.banner.show { animation: bannerIn 1.6s ease both; }

@keyframes pillBlink { 50% { opacity: 0.35; } }
@keyframes bannerIn {
  0% { opacity: 0; transform: scale(0.8); }
  15%, 75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.05); }
}
