/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #050510;
  --panel: rgba(10, 12, 30, 0.92);
  --cyan: #00f0ff;
  --magenta: #ff2bd6;
  --yellow: #ffe600;
  --green: #39ff14;
  --orange: #ff6b00;
  --purple: #b44aff;
  --text: #e8f0ff;
  --muted: #7a8aaa;
  --danger: #ff3355;
  --glow-cyan: 0 0 12px #00f0ff, 0 0 28px rgba(0, 240, 255, 0.45);
  --glow-magenta: 0 0 12px #ff2bd6, 0 0 28px rgba(255, 43, 214, 0.45);
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
}

#game-root {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #050510;
}

/* ===== Screens ===== */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}
.screen.active {
  display: flex;
  pointer-events: auto;
}
#screen-hud.active { pointer-events: none; }
#screen-hud .hud-top,
#screen-hud .hud-power,
#screen-hud .hud-stumble { pointer-events: none; }

/* ===== Menu ===== */
#screen-menu {
  background: radial-gradient(ellipse at 50% 30%, rgba(0, 80, 120, 0.35), transparent 60%),
              linear-gradient(180deg, rgba(5, 5, 16, 0.55), rgba(5, 5, 16, 0.85));
  flex-direction: column;
}
.menu-bg-glow {
  position: absolute;
  width: 60vmin;
  height: 60vmin;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 240, 255, 0.12), transparent 70%);
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  animation: pulse-glow 3s ease-in-out infinite;
  pointer-events: none;
}
@keyframes pulse-glow {
  0%, 100% { opacity: 0.6; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.12); }
}
.menu-content {
  position: relative;
  text-align: center;
  padding: 2rem 1.5rem;
  max-width: 420px;
  width: 92%;
}
.neon-title {
  font-size: clamp(2rem, 8vw, 3.2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--cyan);
  text-shadow: var(--glow-cyan), 0 0 60px rgba(0, 240, 255, 0.3);
  position: relative;
  line-height: 1.2;
  animation: title-flicker 4s linear infinite;
}
.neon-title::after {
  content: attr(data-text);
  position: absolute;
  left: 2px;
  top: 0;
  width: 100%;
  color: var(--magenta);
  opacity: 0.45;
  z-index: -1;
  text-shadow: var(--glow-magenta);
  animation: glitch 3.5s infinite;
}
@keyframes title-flicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.75; }
  98% { opacity: 1; }
  99% { opacity: 0.85; }
}
@keyframes glitch {
  0%, 90%, 100% { transform: translate(0); }
  92% { transform: translate(-2px, 1px); }
  94% { transform: translate(2px, -1px); }
  96% { transform: translate(-1px, 0); }
}
.menu-sub {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  letter-spacing: 0.35em;
  color: var(--magenta);
  text-shadow: 0 0 10px rgba(255, 43, 214, 0.6);
  font-weight: 600;
}
.menu-stats {
  display: flex;
  justify-content: center;
  gap: 1.2rem;
  margin: 1.4rem 0 1.6rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--muted);
}
.menu-stats b {
  color: var(--yellow);
  text-shadow: 0 0 8px rgba(255, 230, 0, 0.5);
  margin-left: 0.25rem;
}
.menu-btns {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: stretch;
}
.menu-hint {
  margin-top: 1.4rem;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.btn-icon {
  position: absolute;
  top: 0;
  right: 0;
  background: rgba(0, 240, 255, 0.08);
  border: 1px solid rgba(0, 240, 255, 0.35);
  color: var(--cyan);
  width: 42px;
  height: 42px;
  border-radius: 10px;
  font-size: 1.15rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-icon:hover {
  background: rgba(0, 240, 255, 0.2);
  box-shadow: var(--glow-cyan);
}
.btn-icon.muted { opacity: 0.5; }

/* ===== Buttons ===== */
.btn {
  appearance: none;
  border: 1px solid rgba(0, 240, 255, 0.45);
  background: rgba(0, 30, 50, 0.7);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 0.85rem 1.5rem;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s, border-color 0.2s;
}
.btn:hover {
  transform: translateY(-1px);
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
  background: rgba(0, 50, 70, 0.85);
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, rgba(0, 200, 220, 0.35), rgba(180, 40, 200, 0.35));
  border-color: var(--cyan);
  color: #fff;
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.6);
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.25);
}
.btn-primary:hover {
  background: linear-gradient(135deg, rgba(0, 220, 240, 0.5), rgba(200, 50, 220, 0.5));
  box-shadow: var(--glow-cyan);
}
.neon-btn { position: relative; overflow: hidden; }
.neon-btn::before {
  content: "";
  position: absolute;
  top: 0; left: -100%;
  width: 60%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent);
  transition: left 0.45s;
}
.neon-btn:hover::before { left: 120%; }

/* ===== HUD ===== */
#screen-hud {
  align-items: flex-start;
  justify-content: stretch;
  background: transparent;
}
.hud-top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  gap: 0.5rem;
  background: linear-gradient(180deg, rgba(5, 5, 16, 0.75), transparent);
}
.hud-stat {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  font-variant-numeric: tabular-nums;
}
.hud-label {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.hud-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--cyan);
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}
.hud-unit {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: 0.1rem;
}
.coin-color { color: var(--yellow) !important; text-shadow: 0 0 10px rgba(255, 230, 0, 0.55) !important; }
.combo-color { color: var(--magenta) !important; text-shadow: 0 0 10px rgba(255, 43, 214, 0.55) !important; }

.hud-power {
  position: absolute;
  top: 4.2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(10, 12, 30, 0.75);
  border: 1px solid rgba(0, 240, 255, 0.35);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  min-width: 180px;
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.2);
}
.power-icon { font-size: 1.1rem; }
.power-bar-track {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}
.power-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  border-radius: 4px;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.6);
}
.power-name {
  font-size: 0.7rem;
  color: var(--cyan);
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.hud-stumble {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 51, 85, 0.18);
  border: 1px solid var(--danger);
  color: #fff;
  padding: 0.9rem 1.4rem;
  border-radius: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-shadow: 0 0 12px rgba(255, 51, 85, 0.8);
  animation: stumble-pulse 0.6s ease-in-out infinite;
  box-shadow: 0 0 24px rgba(255, 51, 85, 0.35);
}
@keyframes stumble-pulse {
  0%, 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 0.85; transform: translate(-50%, -50%) scale(1.04); }
}

/* ===== Panels ===== */
.panel {
  background: var(--panel);
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 18px;
  padding: 1.6rem 1.4rem;
  width: min(420px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.15), inset 0 0 40px rgba(0, 240, 255, 0.04);
  backdrop-filter: blur(12px);
  text-align: center;
}
.neon-panel {
  position: relative;
}
.neon-panel::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 18px;
  padding: 1px;
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.6), transparent 40%, transparent 60%, rgba(255, 43, 214, 0.5));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
.panel-title {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
  margin-bottom: 1.1rem;
}
.panel-btns {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 1.2rem;
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
  gap: 0.5rem;
}
.panel-header .panel-title { margin-bottom: 0; }

/* ===== Game Over ===== */
.go-title { color: var(--danger); text-shadow: 0 0 14px rgba(255, 51, 85, 0.7); }
.new-record {
  color: var(--yellow);
  font-weight: 900;
  letter-spacing: 0.18em;
  margin-bottom: 0.9rem;
  text-shadow: 0 0 14px rgba(255, 230, 0, 0.7);
  animation: record-blink 0.8s ease-in-out infinite;
}
@keyframes record-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.go-stats {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0.4rem 0 0.6rem;
}
.go-row {
  display: flex;
  justify-content: space-between;
  padding: 0.45rem 0.7rem;
  background: rgba(0, 240, 255, 0.05);
  border-radius: 8px;
  border: 1px solid rgba(0, 240, 255, 0.12);
  font-size: 0.95rem;
  color: var(--muted);
}
.go-row b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ===== Shop ===== */
.shop-panel { width: min(480px, 94vw); }
.shop-balance {
  display: flex;
  gap: 0.8rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.shop-balance b { color: var(--yellow); }
.shop-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}
.tab {
  flex: 1;
  appearance: none;
  border: 1px solid rgba(0, 240, 255, 0.25);
  background: rgba(0, 20, 40, 0.5);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 0.55rem 0.4rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.tab.active, .tab:hover {
  color: var(--cyan);
  border-color: var(--cyan);
  background: rgba(0, 240, 255, 0.12);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.2);
}
.shop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-bottom: 1rem;
  max-height: 48vh;
  overflow-y: auto;
  padding: 0.15rem;
}
.shop-item {
  background: rgba(0, 30, 50, 0.55);
  border: 1px solid rgba(0, 240, 255, 0.22);
  border-radius: 12px;
  padding: 0.85rem 0.6rem;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.shop-item:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.25);
  transform: translateY(-2px);
}
.shop-item.owned {
  border-color: rgba(57, 255, 20, 0.45);
}
.shop-item.equipped {
  border-color: var(--magenta);
  box-shadow: 0 0 16px rgba(255, 43, 214, 0.35);
  background: rgba(80, 20, 80, 0.35);
}
.shop-item.locked { opacity: 0.75; }
.shop-item-icon {
  font-size: 2rem;
  margin-bottom: 0.35rem;
  filter: drop-shadow(0 0 6px rgba(0, 240, 255, 0.5));
}
.shop-item-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
}
.shop-item-price {
  font-size: 0.75rem;
  color: var(--yellow);
}
.shop-item-status {
  font-size: 0.7rem;
  color: var(--green);
  margin-top: 0.2rem;
}

/* ===== Achievements ===== */
.ach-panel { width: min(460px, 94vw); }
.ach-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 1rem;
  max-height: 55vh;
  overflow-y: auto;
  text-align: left;
}
.ach-item {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  background: rgba(0, 30, 50, 0.45);
  border: 1px solid rgba(0, 240, 255, 0.18);
  border-radius: 12px;
  transition: border-color 0.2s;
}
.ach-item.unlocked {
  border-color: rgba(57, 255, 20, 0.45);
  background: rgba(20, 50, 30, 0.4);
}
.ach-icon {
  font-size: 1.6rem;
  width: 2.2rem;
  text-align: center;
  filter: grayscale(1) brightness(0.6);
}
.ach-item.unlocked .ach-icon {
  filter: none;
  drop-shadow: 0 0 6px rgba(57, 255, 20, 0.5);
}
.ach-info { flex: 1; min-width: 0; }
.ach-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
}
.ach-desc {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
}
.ach-reward {
  font-size: 0.75rem;
  color: var(--purple);
  white-space: nowrap;
}
.ach-progress {
  margin-top: 0.3rem;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}
.ach-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--green));
  border-radius: 2px;
}

/* ===== Toast ===== */
.toast {
  position: absolute;
  bottom: 12%;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(10, 12, 30, 0.92);
  border: 1px solid var(--cyan);
  color: var(--cyan);
  padding: 0.7rem 1.3rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--glow-cyan);
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.ach {
  border-color: var(--yellow);
  color: var(--yellow);
  box-shadow: 0 0 16px rgba(255, 230, 0, 0.45);
}

/* ===== Scrollbar ===== */
.panel::-webkit-scrollbar,
.shop-grid::-webkit-scrollbar,
.ach-list::-webkit-scrollbar {
  width: 6px;
}
.panel::-webkit-scrollbar-thumb,
.shop-grid::-webkit-scrollbar-thumb,
.ach-list::-webkit-scrollbar-thumb {
  background: rgba(0, 240, 255, 0.35);
  border-radius: 3px;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .hud-value { font-size: 1.1rem; }
  .shop-grid { grid-template-columns: 1fr 1fr; }
  .menu-stats { gap: 0.7rem; font-size: 0.78rem; }
  .panel { padding: 1.2rem 1rem; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .neon-title { font-size: 1.6rem; }
  .menu-btns { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .menu-btns .btn { flex: 1 1 140px; padding: 0.6rem 1rem; font-size: 0.9rem; }
  .shop-grid { max-height: 40vh; }
  .ach-list { max-height: 40vh; }
}
