:root {
  --bg: #080A10;
  --purple: #9945FF;
  --green: #14F195;
  --blue: #2875B9;
  --amethyst: #493078;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: #F8FAFC;
  font-family: 'Inter', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.selectable {
  user-select: text !important;
  -webkit-user-select: text !important;
}

.mono { font-family: 'JetBrains Mono', monospace; }

.ahu-scroll {
  scrollbar-width: thin;
  scrollbar-color: #9945FF #080A10;
}
.ahu-scroll::-webkit-scrollbar { width: 7px; height: 7px; }
.ahu-scroll::-webkit-scrollbar-track {
  background: #080A10;
  border-radius: 999px;
  border: 1px solid rgba(153, 69, 255, 0.22);
}
.ahu-scroll::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #9945FF 0%, #14F195 100%);
  border-radius: 999px;
  border: 1px solid rgba(8, 10, 16, 0.9);
}

canvas.layer {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}
#c1 { z-index: 1; }
#c2 { z-index: 2; pointer-events: none; }

/* ── HUD LAYER (PC: 2 Side Rails | Mobile/Tablet: Slim Top + Bottom Feed) ── */
#hudLayer {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

#leftRail {
  width: 410px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

#rightRail {
  width: 260px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

#topPill, #leftControls, #telemetryCard {
  background: rgba(8, 10, 16, 0.9);
  border: 1px solid rgba(73, 48, 120, 0.85);
  border-radius: 14px;
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

#topPill {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px 12px;
}

#leftControls {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#stageStatusBar {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(73, 48, 120, 0.35);
}

/* ── HIGH-VISIBILITY MENU CTA BUTTON ── */
@keyframes menuCtaGlow {
  0%, 100% {
    box-shadow: 0 0 12px rgba(153, 69, 255, 0.55), 0 0 6px rgba(20, 241, 149, 0.35);
  }
  50% {
    box-shadow: 0 0 22px rgba(153, 69, 255, 0.85), 0 0 12px rgba(20, 241, 149, 0.65);
  }
}

.menu-cta-btn {
  padding: 9px 15px !important;
  font-size: 11px !important;
  font-weight: 900 !important;
  letter-spacing: 0.08em !important;
  white-space: nowrap;
  border-radius: 11px !important;
  color: #FFFFFF !important;
  border: 1.5px solid #14F195 !important;
  background: linear-gradient(135deg, #A855F7 0%, #7C3AED 60%, #5B21B6 100%) !important;
  animation: menuCtaGlow 2.4s ease-in-out infinite;
}
.menu-cta-btn:hover {
  background: linear-gradient(135deg, #B975FF 0%, #9333EA 60%, #6D28D9 100%) !important;
  transform: translateY(-1px);
}
.menu-cta-btn[aria-expanded="true"] {
  background: rgba(20, 241, 149, 0.16) !important;
  color: #14F195 !important;
  animation: none;
}

#actionRow {
  display: flex;
  align-items: center;
  gap: 6px;
}

#telemetryCard {
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.prog-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(73, 48, 120, 0.32);
  overflow: hidden;
  border: 1px solid rgba(73, 48, 120, 0.45);
}
.prog-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #9945FF 0%, #14F195 100%);
  transition: width 0.45s ease;
}
.stat-mini {
  background: rgba(15, 19, 30, 0.82);
  border: 1px solid rgba(73, 48, 120, 0.45);
  border-radius: 8px;
  padding: 4px 6px;
  min-width: 0;
}

/* ── LIVE ACTIVITY FEED ── */
#buyFeed {
  width: 100%;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  background: rgba(8, 10, 16, 0.72);
  border: 1px solid rgba(73, 48, 120, 0.5);
  border-radius: 14px;
  padding: 8px 10px;
  backdrop-filter: blur(10px);
}
#buyFeed .feed-header {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(20, 241, 149, 0.78);
}
#buyFeedList {
  display: flex;
  flex-direction: column-reverse;
  gap: 5px;
  overflow: hidden;
  max-height: 220px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(73, 48, 120, 0.4);
}
#buyFeedList.hidden { display: none !important; }

.feed-item {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(8, 10, 16, 0.82);
  border: 1px solid rgba(73, 48, 120, 0.35);
  border-radius: 8px;
  padding: 5px 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  line-height: 1.3;
  animation: feedSlide 0.35s ease forwards;
}
.feed-item.buy { border-color: rgba(20, 241, 149, 0.32); }
.feed-item.sell { border-color: rgba(153, 69, 255, 0.32); }
@keyframes feedSlide {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.feed-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.feed-dot.buy { background: #14F195; box-shadow: 0 0 6px rgba(20, 241, 149, 0.7); }
.feed-dot.sell { background: #9945FF; box-shadow: 0 0 6px rgba(153, 69, 255, 0.7); }
.feed-addr { color: rgba(244, 246, 251, 0.55); font-size: 9px; }
.feed-amt.buy { color: #14F195; font-weight: 700; }
.feed-amt.sell { color: #9945FF; font-weight: 700; }

/* ── PERSISTENT SIDE DRAWER MENU ── */
#sideDrawer {
  position: fixed;
  top: 14px;
  left: 14px;
  bottom: 14px;
  width: min(330px, calc(100vw - 28px));
  z-index: 40;
  border-radius: 16px;
  padding: 14px;
  background: rgba(8, 10, 16, 0.97);
  border: 1px solid rgba(153, 69, 255, 0.72);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.85), 0 0 28px rgba(153, 69, 255, 0.16);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  transform: translateX(calc(-100% - 28px));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.18s ease, visibility 0.18s ease;
}
#sideDrawer.open {
  transform: translateX(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#stageGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

/* ── BUTTONS & MODALS ── */
.btn {
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 10px;
  padding: 6px 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid rgba(73, 48, 120, 0.75);
  background: rgba(8, 10, 16, 0.88);
  color: #E2E8F0;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.btn:hover { border-color: #9945FF; background: rgba(153, 69, 255, 0.16); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-green { background: rgba(20, 241, 149, 0.14); border-color: rgba(20, 241, 149, 0.65); color: #14F195; }
.btn-purple { background: rgba(153, 69, 255, 0.18); border-color: #9945FF; color: #FFFFFF; }

.icon-btn {
  cursor: pointer;
  touch-action: manipulation;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(73, 48, 120, 0.7);
  background: rgba(8, 10, 16, 0.85);
  transition: transform 0.12s, border-color 0.15s;
}
.icon-btn:hover { border-color: #9945FF; transform: scale(1.08); }

.stage-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 8.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid;
}

.unlock-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 9px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  font-weight: 800;
  border: 1px solid rgba(73, 48, 120, 0.45);
  background: rgba(15, 19, 30, 0.82);
  color: #E2E8F0;
  cursor: pointer;
  touch-action: manipulation;
  text-align: left;
  transition: all 0.15s;
}
.unlock-btn.unlocked { border-color: rgba(20, 241, 149, 0.55); background: rgba(20, 241, 149, 0.1); color: #14F195; }
.unlock-btn.unlocked:hover { border-color: #14F195; background: rgba(20, 241, 149, 0.2); }
.unlock-btn.locked { opacity: 0.45; cursor: not-allowed; }

.modal-doc {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  z-index: 50;
  background: rgba(8, 10, 16, 0.92);
  backdrop-filter: blur(16px);
}
.modal-doc-mono { font-family: 'JetBrains Mono', monospace; }
.modal-box {
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  border-radius: 16px;
  padding: 16px 18px;
  border: 1px solid #9945FF;
  background: rgba(8, 10, 16, 0.98);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-box::-webkit-scrollbar { display: none; }
.modal-box { -ms-overflow-style: none; scrollbar-width: none; }

#coreGameCanvas {
  touch-action: none;
  aspect-ratio: 2 / 1;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.secret-shimmer {
  background: linear-gradient(90deg, transparent 25%, rgba(153, 69, 255, 0.13) 50%, transparent 75%);
  background-size: 200% 100%;
  animation: shimmer 2.6s ease infinite;
}

/* ── CHAOTIC DEGEN MODE ── */
@keyframes rainbowCycle {
  0% { filter: hue-rotate(0deg) saturate(2.3) contrast(1.2); }
  50% { filter: hue-rotate(180deg) saturate(2.7) contrast(1.3); }
  100% { filter: hue-rotate(360deg) saturate(2.3) contrast(1.2); }
}
@keyframes degenStrobeOverlay {
  0% { background: rgba(255, 0, 90, 0.12); }
  25% { background: rgba(255, 230, 0, 0.11); }
  50% { background: rgba(0, 255, 150, 0.11); }
  75% { background: rgba(0, 210, 255, 0.12); }
  100% { background: rgba(255, 0, 90, 0.12); }
}
@keyframes degenBorderStrobe {
  0% { border-color: #ff0055; box-shadow: 0 0 18px rgba(255, 0, 85, 0.75); }
  33% { border-color: #ffee00; box-shadow: 0 0 18px rgba(255, 238, 0, 0.75); }
  66% { border-color: #00ff88; box-shadow: 0 0 18px rgba(0, 255, 136, 0.75); }
  100% { border-color: #ff0055; box-shadow: 0 0 18px rgba(255, 0, 85, 0.75); }
}
@keyframes degenFlashBtn {
  0%, 100% { background: #ff0055; color: #ffffff; scale: calc(var(--btn-scale, 1) * 1.03); }
  25% { background: #ffee00; color: #080a10; scale: calc(var(--btn-scale, 1) * 1.08); }
  50% { background: #00ff88; color: #080a10; scale: calc(var(--btn-scale, 1) * 1.02); }
  75% { background: #00e5ff; color: #080a10; scale: calc(var(--btn-scale, 1) * 1.09); }
}

body.degen-mode #c1 { animation: rainbowCycle 0.8s linear infinite; }
body.degen-mode #topPill,
body.degen-mode #leftControls,
body.degen-mode #telemetryCard,
body.degen-mode .feed-item { animation: degenBorderStrobe 0.4s linear infinite; background: rgba(14, 4, 28, 0.9); }
body.degen-mode .degen-hype-btn { animation: degenFlashBtn 0.42s ease-in-out infinite; font-weight: 900; border-color: #ffffff !important; }

#degenLayer {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  display: none;
  animation: degenStrobeOverlay 0.38s linear infinite;
}
body.degen-mode #degenLayer { display: block; }

.degen-float-pill, .degen-float-meme {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9;
  pointer-events: auto;
  will-change: transform;
}
.degen-float-pill {
  cursor: pointer;
  border-radius: 999px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-decoration: none;
  border: 2px solid #ffffff;
  white-space: nowrap;
  animation: degenFlashBtn var(--flash-dur, 0.44s) ease-in-out infinite;
  box-shadow: 0 0 22px rgba(255, 255, 255, 0.55);
}
.degen-ca-pill { background: #080A10 !important; color: #14F195 !important; border-color: #14F195 !important; }
.degen-float-meme {
  width: 92px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid #ffee00;
  box-shadow: 0 0 18px rgba(255, 238, 0, 0.6);
  background: #080A10;
  cursor: pointer;
}
.degen-float-meme img { width: 100%; height: 100%; object-fit: cover; display: block; }

.degen-sz-xs { --btn-scale: 1.0; padding: 4px 9px; font-size: 8.5px; }
.degen-sz-sm { --btn-scale: 1.0; padding: 5px 12px; font-size: 10px; }
.degen-sz-md { --btn-scale: 1.03; padding: 8px 16px; font-size: 12px; }
.degen-sz-lg { --btn-scale: 1.05; padding: 10px 21px; font-size: 14.5px; }
.degen-sz-xl { --btn-scale: 1.08; padding: 13px 26px; font-size: 17px; }

/* ── TABLET & MOBILE RESPONSIVE OVERHAUL (MAX SPACE FOR PLASMA ORB) ── */
@media (max-width: 900px) {
  #hudLayer {
    padding: 8px;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 5px;
  }
  #leftRail, #rightRail {
    width: 100%;
    gap: 5px;
  }
  #topPill {
    padding: 7px 9px;
    border-radius: 11px;
    gap: 4px;
  }
  #leftControls {
    padding: 7px 9px;
    border-radius: 11px;
    gap: 0;
  }
  #stageStatusBar {
    padding-bottom: 0;
    border-bottom: none;
    gap: 8px;
  }
  .menu-cta-btn {
    padding: 8px 13px !important;
    font-size: 10.5px !important;
  }
  /* Evolution / Verify / Whitepaper live cleanly inside ☰ Menu on mobile */
  #actionRow {
    display: none;
  }
  #telemetryCard {
    padding: 6px 8px;
    border-radius: 11px;
    gap: 4px;
  }
  .telemetry-meta {
    display: none !important;
  }
  .stat-mini {
    padding: 3px 6px;
  }
  /* Pin Live Activity cleanly to the bottom on mobile */
  #buyFeed {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    padding: 6px 10px;
    border-radius: 11px;
    z-index: 15;
    background: rgba(8, 10, 16, 0.88);
  }
  #buyFeedList {
    max-height: 98px;
  }
  #sideDrawer {
    top: 8px;
    left: 8px;
    bottom: 8px;
    width: min(330px, calc(100vw - 16px));
  }
  .degen-float-meme { width: 64px; height: 46px; }
}

@media (max-width: 640px) {
  #coreGameCanvas {
    aspect-ratio: 4 / 3;
  }
  .btn { font-size: 9.5px; padding: 6px 8px; }
  .modal-box { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  body.degen-mode #c1,
  #degenLayer,
  .degen-float-pill,
  .menu-cta-btn { animation: none !important; }
}