:root {
  --ink: #02040a;
  --panel: #080d1a;
  --line: rgba(120, 220, 255, 0.18);
  --cyan: #63f7ee;
  --magenta: #ff3d9a;
  --amber: #ffd166;
  --violet: #9d8bff;
  --text: #dbe9ff;
  --muted: #6f86aa;
  --font-display: "Bahnschrift SemiCondensed", "Bahnschrift", "DIN Condensed", "Franklin Gothic Medium", "Arial Narrow", sans-serif;
  --font-mono: "Cascadia Mono", "Cascadia Code", Consolas, "SFMono-Regular", monospace;
  --font-body: "Cascadia Mono", Consolas, "Microsoft YaHei", monospace;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  overflow-x: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(60% 50% at 80% 10%, rgba(255, 61, 154, 0.14), transparent 70%),
    radial-gradient(55% 45% at 12% 88%, rgba(61, 247, 238, 0.11), transparent 70%),
    radial-gradient(45% 45% at 50% 45%, rgba(120, 90, 255, 0.08), transparent 70%),
    #02040a;
}

.scene::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(120, 200, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 200, 255, 0.045) 1px, transparent 1px);
  background-size: 64px 64px;
  -webkit-mask-image: radial-gradient(circle at 50% 32%, #000 0%, transparent 76%);
  mask-image: radial-gradient(circle at 50% 32%, #000 0%, transparent 76%);
}

.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.28) 0 1px, transparent 1px 3px);
  opacity: 0.22;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1100px, 100%);
  display: grid;
  gap: 14px;
}

/* ---------- top bar ---------- */

.topbar {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 26px;
  padding: 0 2px 14px;
  border-bottom: 1px solid var(--line);
  animation: riseIn 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 140px;
  height: 1px;
  background: linear-gradient(90deg, var(--cyan), transparent);
  box-shadow: 0 0 14px var(--cyan);
}

.brand {
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 0;
}

.brand-sigil {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(99, 247, 238, 0.5);
  border-radius: 50%;
  box-shadow: 0 0 20px rgba(99, 247, 238, 0.22), inset 0 0 14px rgba(99, 247, 238, 0.12);
}

.brand-sigil::before {
  content: "";
  width: 22px;
  height: 1px;
  background: var(--cyan);
  box-shadow: 0 0 9px var(--cyan);
}

.brand-sigil::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px dashed rgba(255, 61, 154, 0.5);
  border-radius: 50%;
  animation: spin 18s linear infinite;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(24px, 3.4vw, 38px);
  font-weight: 700;
  font-stretch: condensed;
  line-height: 0.9;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #edfaff;
}

.brand h1 b {
  color: var(--cyan);
  font-weight: 700;
  text-shadow: 0 0 20px rgba(99, 247, 238, 0.6);
}

.brand p {
  margin: 7px 0 0;
  font-size: 9.5px;
  letter-spacing: 0.28em;
  color: var(--muted);
  text-transform: uppercase;
  white-space: nowrap;
}

.hud {
  display: flex;
  align-items: stretch;
}

.stat {
  min-width: 84px;
  padding: 2px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-left: 1px solid rgba(120, 220, 255, 0.12);
}

.stat:first-child { border-left: 0; }

.stat .label {
  font-size: 8.5px;
  letter-spacing: 0.26em;
  color: var(--muted);
}

.stat strong {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.05em;
  color: #eaf8ff;
}

.stat.best strong { color: var(--amber); }

#combo { color: var(--amber); font-size: 16px; }

.lives {
  color: var(--magenta);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-shadow: 0 0 12px rgba(255, 61, 154, 0.65);
}

.lives.low { animation: softPulse 0.9s ease-in-out infinite; color: #ff5a72; }

/* ---------- stage ---------- */

.stage {
  position: relative;
  border: 1px solid rgba(110, 220, 255, 0.22);
  background: #03060e;
  box-shadow:
    0 30px 90px rgba(0, 0, 0, 0.68),
    0 0 0 1px rgba(0, 0, 0, 0.65),
    inset 0 0 90px rgba(3, 10, 24, 0.9);
  animation: riseIn 0.7s 0.06s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.stage canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  cursor: crosshair;
}

.corner {
  position: absolute;
  z-index: 5;
  width: 16px;
  height: 16px;
  border: 0 solid var(--cyan);
  filter: drop-shadow(0 0 6px rgba(99, 247, 238, 0.6));
  pointer-events: none;
}

.corner.tl { top: -1px; left: -1px; border-top-width: 2px; border-left-width: 2px; }
.corner.tr { top: -1px; right: -1px; border-top-width: 2px; border-right-width: 2px; }
.corner.bl { bottom: -1px; left: -1px; border-bottom-width: 2px; border-left-width: 2px; }
.corner.br { bottom: -1px; right: -1px; border-bottom-width: 2px; border-right-width: 2px; }

.crt {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
  opacity: 0.5;
}

.crt::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 100% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}

/* ---------- overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 44px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: radial-gradient(90% 80% at 50% 30%, rgba(6, 14, 30, 0.74), rgba(2, 4, 10, 0.95));
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.overlay[hidden] { display: none; }

.panel {
  width: min(560px, 100%);
  padding: 8px 12px;
  text-align: center;
  animation: panelIn 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.eyebrow {
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 9.5px;
  letter-spacing: 0.36em;
  color: var(--cyan);
  text-transform: uppercase;
}

.eyebrow::before,
.eyebrow::after {
  content: "";
  width: 34px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(99, 247, 238, 0.7));
}

.eyebrow::after { transform: scaleX(-1); }

.panel h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(40px, 8vw, 76px);
  font-weight: 700;
  font-stretch: condensed;
  line-height: 0.86;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #f2fbff;
  text-shadow: 0 0 34px rgba(99, 247, 238, 0.28);
}

.panel h2 span {
  display: block;
  margin-top: 0.22em;
  font-size: 0.66em;
  letter-spacing: 0.24em;
  color: transparent;
  -webkit-text-stroke: 1px rgba(255, 61, 154, 0.9);
  text-shadow: 0 0 38px rgba(255, 61, 154, 0.4);
}

.lede {
  max-width: 44ch;
  margin: 20px auto 26px;
  font-size: 12.5px;
  line-height: 1.95;
  letter-spacing: 0.02em;
  color: #9db3d4;
}

.cta {
  position: relative;
  border: 0;
  padding: 16px 38px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: #031019;
  background: linear-gradient(100deg, #8ffff7, #40e0d6 46%, var(--amber));
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px));
  cursor: pointer;
  filter: drop-shadow(0 12px 26px rgba(64, 224, 214, 0.24));
  transition: transform 0.18s ease, filter 0.18s ease;
}

.cta:hover {
  transform: translateY(-2px);
  filter: drop-shadow(0 16px 34px rgba(64, 224, 214, 0.42));
}

.cta:active { transform: translateY(0); }

.cta:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 4px;
}

.cta span { margin-left: 10px; }

.tips {
  margin-top: 28px;
  padding-top: 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 20px;
  border-top: 1px solid rgba(120, 220, 255, 0.14);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
}

.tips span::before {
  content: "▸";
  margin-right: 7px;
  color: var(--magenta);
}

.result {
  margin: 24px 0 28px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  border: 1px solid rgba(120, 220, 255, 0.12);
  background: rgba(120, 220, 255, 0.12);
}

.result div {
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: rgba(4, 9, 20, 0.9);
}

.result span {
  font-size: 8.5px;
  letter-spacing: 0.24em;
  color: var(--muted);
}

.result strong {
  font-family: var(--font-mono);
  font-size: 20px;
  color: #eaf7ff;
}

.result strong.accent { color: var(--amber); }

.record {
  display: inline-block;
  margin-bottom: 18px;
  padding: 5px 13px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: #031019;
  background: var(--amber);
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
  animation: badgeGlow 1.6s ease-in-out infinite;
}

/* ---------- footer ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 24px;
  padding: 2px 2px 0;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
  animation: riseIn 0.7s 0.12s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.ctrl {
  display: flex;
  align-items: center;
  gap: 6px;
}

kbd {
  min-width: 22px;
  padding: 3px 6px;
  font-family: var(--font-mono);
  font-size: 9px;
  text-align: center;
  color: #bfe9ff;
  border: 1px solid rgba(120, 220, 255, 0.24);
  border-bottom-color: rgba(120, 220, 255, 0.08);
  background: rgba(10, 22, 40, 0.8);
}

.hint {
  margin-left: auto;
  color: rgba(120, 150, 190, 0.62);
  letter-spacing: 0.18em;
}

/* ---------- toast ---------- */

.toast {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 15%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -10px);
}

.toast.show { animation: toastShow 1.9s cubic-bezier(0.2, 0.8, 0.2, 1) both; }

.toast strong {
  font-family: var(--font-display);
  font-size: clamp(26px, 4.2vw, 42px);
  font-weight: 700;
  font-stretch: condensed;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #f4feff;
  text-shadow: 0 0 24px rgba(99, 247, 238, 0.6), 0 0 60px rgba(99, 247, 238, 0.25);
}

.toast span {
  font-size: 9.5px;
  letter-spacing: 0.3em;
  color: var(--cyan);
  text-transform: uppercase;
}

/* ---------- motion ---------- */

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes riseIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastShow {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.96); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  76% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -20px) scale(1); }
}

@keyframes softPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes badgeGlow {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 209, 102, 0)); }
  50% { filter: drop-shadow(0 0 14px rgba(255, 209, 102, 0.65)); }
}

/* ---------- status buffs ---------- */

.buffbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
}

.buffbar:empty { display: none; }

.buff {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border: 1px solid rgba(120, 220, 255, 0.16);
  background: rgba(8, 16, 30, 0.72);
  font-size: 9px;
  letter-spacing: 0.12em;
  color: #bfe9ff;
  text-transform: uppercase;
  white-space: nowrap;
}

.buff i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.buff b { margin-left: 2px; color: #fff; font-weight: 600; }
.buff.shield { color: #8fffb0; }
.buff.laser { color: #ff6b81; }
.buff.slow { color: #9d8bff; }
.buff.wide { color: #ffd166; }
.buff.plasma { color: #63f7ee; }

/* ---------- upgrades ---------- */

.upgrade-panel { width: min(880px, 100%); }
.upgrade-panel h2 { font-size: clamp(30px, 5.4vw, 54px); }

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 22px 0 18px;
}

.ucard {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 16px 14px 14px;
  text-align: left;
  font-family: var(--font-body);
  color: var(--text);
  background: rgba(7, 14, 28, 0.92);
  border: 1px solid rgba(120, 220, 255, 0.18);
  cursor: pointer;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.ucard:hover,
.ucard:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(99, 247, 238, 0.62);
  background: rgba(10, 22, 42, 0.96);
  outline: none;
}

.ucard .rarity { font-size: 8px; letter-spacing: 0.26em; color: var(--cyan); }
.ucard strong {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
  color: #f2fbff;
}
.ucard em { font-style: normal; font-size: 10.5px; letter-spacing: 0.12em; color: var(--cyan); }
.ucard .desc { display: block; margin: 0; font-size: 11px; line-height: 1.65; color: #9db3d4; }
.ucard .stacks { margin-top: auto; font-size: 8.5px; letter-spacing: 0.16em; color: var(--amber); }
.ucard kbd { position: absolute; right: 10px; top: 10px; }
.ucard.r2 { border-color: rgba(255, 209, 102, 0.3); }
.ucard.r2 .rarity, .ucard.r2 em { color: var(--amber); }
.ucard.r3 { border-color: rgba(255, 61, 154, 0.42); background: rgba(22, 8, 24, 0.92); }
.ucard.r3 .rarity, .ucard.r3 em { color: var(--magenta); }

.upgrade-hint { margin: 0; font-size: 9.5px; letter-spacing: 0.16em; color: var(--muted); }
.upgrade-hint kbd { margin: 0 2px; }

/* ---------- run summary ---------- */

.build {
  margin: 0 0 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(120, 220, 255, 0.14);
}

.build-label {
  display: block;
  margin-bottom: 10px;
  font-size: 8.5px;
  letter-spacing: 0.24em;
  color: var(--muted);
  text-transform: uppercase;
}

.bchips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }

.bchip {
  padding: 4px 9px;
  font-size: 8.5px;
  letter-spacing: 0.1em;
  color: #bfe9ff;
  border: 1px solid rgba(120, 220, 255, 0.16);
}
.bchip.r2 { color: var(--amber); border-color: rgba(255, 209, 102, 0.24); }
.bchip.r3 { color: var(--magenta); border-color: rgba(255, 61, 154, 0.3); }

.run-meta { margin: 0 0 18px; font-size: 9.5px; letter-spacing: 0.16em; color: var(--muted); }

/* ---------- footer buttons ---------- */

.footer-actions { display: flex; gap: 8px; margin-left: auto; }

.mini {
  padding: 5px 11px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #bfe9ff;
  background: rgba(10, 22, 40, 0.8);
  border: 1px solid rgba(120, 220, 255, 0.24);
  cursor: pointer;
}
.mini:hover, .mini:focus-visible { color: #fff; border-color: var(--cyan); outline: none; }

@media (max-width: 720px) {
  .overlay { align-items: flex-start; }
  .cards { grid-template-columns: 1fr; margin: 14px 0 12px; }
  .ucard { padding: 12px; }
  .ucard strong { font-size: 18px; }
  .ucard .desc { font-size: 10.5px; }
  .upgrade-panel h2 { font-size: clamp(28px, 9vw, 42px); }
}

@media (max-width: 620px) {
  .footer-actions { width: 100%; margin-left: 0; }
  .mini { flex: 1; }
}

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  body { padding: 12px; align-items: flex-start; }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .hud { justify-content: space-between; }

  .stat {
    flex: 1;
    min-width: 0;
    padding: 0 9px;
  }

  .stat strong { font-size: 16px; }

  .hint { display: none; }
}

@media (max-width: 620px) {
  .brand p { display: none; }

  .stat.best { display: none; }

  .stat .label { font-size: 8px; }

  .panel h2 { font-size: clamp(38px, 12vw, 56px); }

  .lede { font-size: 11.5px; }

  .tips { display: none; }

  .cta { width: 100%; padding: 15px 24px; }

  .controls { gap: 8px 16px; font-size: 8.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  /* Keep toast feedback readable when animations are suppressed:
     without this the 0.001ms animation jumps to its 0%-opacity end state. */
  .toast.show {
    animation: none !important;
    opacity: 1;
    transform: translate(-50%, 0);
  }
}
