:root {
  --bg-box: rgba(12, 14, 18, 0.9);
  --border: #445566;
  --rad-green: #33ff55;
  --scrap-gold: #ffcc22;
  --portal-purple: #bb44ff;
  --enemy-red: #ff3344;
  --cyan: #00f0ff;
  --font-mono: 'Courier New', Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a0e;
  color: #f0f4f8;
  font-family: var(--font-mono);
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

.hidden {
  display: none !important;
}

/* World Programmer Labels & Floating Damage */
#world-labels, #damage-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}

.prog-label {
  position: absolute;
  transform: translate(-50%, -100%);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid currentColor;
  padding: 1px 5px;
  white-space: nowrap;
  pointer-events: none;
}

.dmg-num {
  position: absolute;
  font-family: var(--font-mono);
  font-weight: 900;
  font-size: 17px;
  color: #ffffff;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000;
  transform: translate(-50%, -50%);
  animation: popDmg 0.65s ease-out forwards;
  white-space: nowrap;
}

.dmg-num.crit {
  font-size: 23px;
  color: var(--scrap-gold);
}

.dmg-num.rad {
  font-size: 15px;
  color: var(--rad-green);
}

@keyframes popDmg {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.8); }
  25% { opacity: 1; transform: translate(-50%, -95%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -170%) scale(0.9); }
}

/* Screen Flash FX */
#screen-fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  transition: box-shadow 0.12s ease, background 0.2s ease;
}

#screen-fx.hit-flash {
  box-shadow: inset 0 0 110px rgba(255, 30, 50, 0.75);
}

#screen-fx.portal-flash {
  box-shadow: inset 0 0 150px rgba(187, 68, 255, 0.85);
}

/* Crosshair */
#crosshair-wrap {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 6;
}

#crosshair {
  position: relative;
  width: 28px;
  height: 28px;
}

.ch-line {
  position: absolute;
  background: #ffffff;
  box-shadow: 0 0 2px #000;
}

.ch-top { width: 2px; height: 7px; left: 13px; top: 1px; }
.ch-bottom { width: 2px; height: 7px; left: 13px; bottom: 1px; }
.ch-left { width: 7px; height: 2px; left: 1px; top: 13px; }
.ch-right { width: 7px; height: 2px; right: 1px; top: 13px; }
.ch-dot {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--rad-green);
  left: 12px;
  top: 12px;
}

#hitmarker {
  position: absolute;
  inset: 0;
}

.hm-line {
  position: absolute;
  width: 8px;
  height: 2px;
  background: var(--scrap-gold);
}
.hm-1 { top: 4px; left: 3px; transform: rotate(45deg); }
.hm-2 { top: 4px; right: 3px; transform: rotate(-45deg); }
.hm-3 { bottom: 4px; left: 3px; transform: rotate(-45deg); }
.hm-4 { bottom: 4px; right: 3px; transform: rotate(45deg); }

/* Top HUD */
#hud-top {
  position: fixed;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  z-index: 10;
  pointer-events: none;
}

.hud-left-stack, .hud-right-stack, .stage-panel {
  pointer-events: auto;
}

.currency-strip {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.stat-box {
  background: var(--bg-box);
  border: 2px solid var(--border);
  padding: 6px 10px;
  min-width: 135px;
}

.scrap-box { border-color: var(--scrap-gold); }
.rad-box { border-color: var(--rad-green); min-width: 200px; }

.stat-label {
  font-size: 11px;
  font-weight: 700;
  color: #aab8c8;
  margin-bottom: 3px;
}

.stat-val {
  font-size: 20px;
  font-weight: 900;
  color: var(--scrap-gold);
}

.stat-sub {
  font-size: 11px;
  color: var(--cyan);
  margin-top: 2px;
}

.rad-bar-bg {
  position: relative;
  height: 16px;
  background: #142218;
  border: 1px solid var(--rad-green);
  overflow: hidden;
}

#rad-bar-fill {
  height: 100%;
  width: 0%;
  background: #22aa3b;
  transition: width 0.15s ease;
}

#rad-bar-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}

/* Quick Upgrades */
#quick-upgrades {
  background: var(--bg-box);
  border: 2px solid var(--border);
  padding: 8px;
  width: 260px;
}

.quick-title {
  font-size: 11px;
  font-weight: 900;
  color: #99aabb;
  margin-bottom: 6px;
}

#quick-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.quick-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #141820;
  border: 1px solid #2c3545;
  padding: 5px 7px;
  cursor: pointer;
  font-size: 12px;
}

.quick-item.can-buy {
  border-color: var(--rad-green);
  background: #122818;
}

.quick-item.can-buy:hover {
  background: #1c3d25;
}

.quick-cost {
  color: var(--scrap-gold);
  font-weight: 900;
}

/* Center Stage Panel */
.stage-panel {
  flex: 1;
  max-width: 440px;
  background: var(--bg-box);
  border: 2px solid #fff;
  padding: 8px 12px;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 900;
  margin-bottom: 6px;
}

.stage-bar-bg {
  height: 10px;
  background: #222;
  border: 1px solid #555;
}

#stage-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--enemy-red);
  transition: width 0.2s ease;
}

#portal-banner {
  margin-top: 8px;
  padding: 6px;
  background: #3a1255;
  border: 2px solid var(--portal-purple);
  color: #f0d0ff;
  font-weight: 900;
  font-size: 12px;
  text-align: center;
  animation: pulsePortal 0.9s infinite alternate;
}

@keyframes pulsePortal {
  from { background: #3a1255; }
  to { background: #681f99; }
}

/* Minimap */
.minimap-box {
  background: var(--bg-box);
  border: 2px solid #fff;
  padding: 6px;
  margin-bottom: 8px;
}

.minimap-header {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 900;
  margin-bottom: 4px;
  color: var(--cyan);
}

#minimap {
  display: block;
  background: #080a0f;
  border: 1px solid #334;
}

.top-buttons {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.top-icon-row {
  display: flex;
  gap: 5px;
}

.top-icon-row .prog-btn {
  flex: 1;
  text-align: center;
  padding: 5px 4px;
  font-size: 10px;
}

/* Real-Time WebGL & Scene Debug Telemetry Panel */
#debug-panel {
  margin-top: 8px;
  background: rgba(8, 11, 18, 0.92);
  border: 2px solid var(--cyan);
  padding: 7px 9px;
  width: 192px;
  font-size: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.65);
}

#debug-panel.hidden {
  display: none;
}

.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 900;
  color: var(--cyan);
  margin-bottom: 5px;
  font-size: 10px;
}

.dbg-badge {
  padding: 1px 5px;
  font-weight: 900;
  font-size: 10px;
  border: 1px solid #000;
  color: #051008;
}

.dbg-badge.good {
  background: var(--rad-green);
}

.dbg-badge.warn {
  background: var(--scrap-gold);
}

.dbg-badge.bad {
  background: var(--enemy-red);
  color: #fff;
}

#debug-fps-graph {
  display: block;
  width: 100%;
  height: 34px;
  background: #05070c;
  border: 1px solid #1e2b3c;
  margin-bottom: 6px;
}

.debug-grid {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.dbg-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #8fa3bd;
  border-bottom: 1px dotted rgba(255, 255, 255, 0.08);
  padding-bottom: 2px;
}

.dbg-row strong {
  color: #eef5ff;
  font-weight: 800;
}

/* Mobile / Touch Controls Overlay */
#target-lock-box {
  position: fixed;
  width: 58px;
  height: 58px;
  border: 2px dashed var(--rad-green);
  box-shadow: 0 0 12px rgba(51, 255, 85, 0.55);
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 6;
}

.tl-label {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--rad-green);
  color: #000;
  font-size: 9px;
  font-weight: 900;
  padding: 0 4px;
}

#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  touch-action: none;
}

#touch-joy-zone {
  position: absolute;
  left: 0;
  top: 110px;
  bottom: 72px;
  width: 46vw;
  pointer-events: auto;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 0 0 14px 18px;
}

#touch-joy-base {
  position: relative;
  width: 122px;
  height: 122px;
  border: 2px solid var(--rad-green);
  background: rgba(12, 24, 16, 0.55);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.1s;
}

#touch-joy-stick {
  width: 50px;
  height: 50px;
  background: rgba(51, 255, 85, 0.78);
  border: 2px solid #ffffff;
  border-radius: 50%;
  transform: translate(0px, 0px);
  pointer-events: none;
}

#touch-look-zone {
  position: absolute;
  top: 90px;
  right: 0;
  bottom: 72px;
  width: 54vw;
  pointer-events: auto;
  touch-action: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 12px;
}

#touch-aim-reticle {
  position: fixed;
  width: 64px;
  height: 64px;
  border: 2px solid var(--scrap-gold);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.touch-zone-label {
  font-size: 10px;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.5);
  margin-top: 4px;
  pointer-events: none;
}

#touch-actions {
  position: absolute;
  right: 16px;
  bottom: 82px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
  touch-action: none;
}

.touch-sub-actions {
  display: flex;
  gap: 8px;
}

.touch-action-btn {
  font-family: var(--font-mono);
  font-weight: 900;
  color: #fff;
  background: rgba(16, 20, 28, 0.84);
  border: 2px solid #fff;
  cursor: pointer;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.touch-action-btn.fire-btn {
  width: 148px;
  height: 74px;
  padding: 6px;
  border-color: var(--enemy-red);
  background: rgba(140, 20, 35, 0.72);
  border-radius: 12px;
}

.fire-main {
  font-size: 11px;
  font-weight: 900;
  color: #fff;
}

.fire-sub {
  font-size: 9px;
  color: var(--scrap-gold);
  margin-top: 3px;
}

.touch-action-btn.fire-btn.active {
  background: var(--enemy-red);
  border-color: #fff;
  box-shadow: 0 0 18px rgba(255, 51, 68, 0.75);
}

.touch-action-btn.fire-btn.latched {
  background: rgba(34, 150, 60, 0.85);
  border-color: var(--rad-green);
  box-shadow: 0 0 16px rgba(51, 255, 85, 0.65);
}

.touch-action-btn.dash-btn {
  width: 70px;
  height: 44px;
  font-size: 11px;
  border-color: var(--cyan);
  color: var(--cyan);
}

.touch-action-btn.jump-btn {
  width: 70px;
  height: 44px;
  font-size: 11px;
  border-color: var(--scrap-gold);
  color: var(--scrap-gold);
}

/* Responsive Mobile Layout */
@media (max-width: 900px) {
  #hud-top {
    top: 6px;
    left: 6px;
    right: 6px;
    gap: 6px;
  }

  .stat-box {
    padding: 4px 6px;
    min-width: 90px;
  }

  .rad-box {
    min-width: 130px;
  }

  .stat-val {
    font-size: 15px;
  }

  #quick-upgrades {
    width: 195px;
    padding: 5px;
  }

  .quick-item {
    font-size: 10px;
    padding: 3px 5px;
  }

  .stage-panel {
    max-width: 240px;
    padding: 5px 8px;
  }

  .stage-header {
    font-size: 11px;
  }

  #minimap {
    width: 108px;
    height: 108px;
  }

  .prog-btn {
    padding: 5px 7px;
    font-size: 10px;
  }

  #hud-bottom {
    bottom: 6px;
    left: 6px;
    right: 6px;
  }

  .vitals-panel {
    width: 155px;
    padding: 5px 8px;
  }

  .controls-hint {
    display: none;
  }

  .weapons-dock {
    overflow-x: auto;
    max-width: 55vw;
  }

  .weapon-slot {
    min-width: 82px;
    padding: 4px 6px;
  }

  .w-name, .w-meta {
    font-size: 9px;
  }

  .mutations-strip {
    display: none;
  }
}

.prog-btn {
  background: var(--bg-box);
  border: 2px solid #8899aa;
  color: #fff;
  padding: 7px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  text-align: left;
}

.prog-btn:hover {
  border-color: #fff;
  background: #1f2633;
}

.prog-btn.active {
  border-color: var(--rad-green);
  color: var(--rad-green);
}

.prog-btn.accent {
  border-color: var(--scrap-gold);
  color: var(--scrap-gold);
}

/* Lock Prompt */
#lock-prompt {
  position: fixed;
  top: 105px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  pointer-events: none;
  transition: opacity 0.2s;
}

.lock-card {
  background: rgba(0, 0, 0, 0.88);
  border: 2px solid var(--rad-green);
  padding: 8px 18px;
  text-align: center;
  font-weight: 900;
  font-size: 13px;
  color: var(--rad-green);
}

.lock-sub {
  font-size: 11px;
  color: #ccc;
  margin-top: 2px;
}

/* Bottom HUD */
#hud-bottom {
  position: fixed;
  bottom: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  z-index: 10;
  pointer-events: none;
}

.vitals-panel, .weapons-dock, .mutations-strip {
  pointer-events: auto;
}

.vitals-panel {
  background: var(--bg-box);
  border: 2px solid #fff;
  padding: 8px 12px;
  width: 280px;
}

.vital-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.vital-label {
  font-weight: 900;
  font-size: 13px;
  color: var(--enemy-red);
}

.vital-bar-bg {
  flex: 1;
  height: 14px;
  background: #2a1014;
  border: 1px solid var(--enemy-red);
}

.vital-fill.hp {
  height: 100%;
  width: 100%;
  background: var(--enemy-red);
  transition: width 0.12s;
}

.vital-num {
  font-size: 12px;
  font-weight: 900;
}

.controls-hint {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
  color: #aaa;
}

kbd {
  background: #222;
  border: 1px solid #666;
  padding: 0 4px;
  color: #fff;
}

/* Weapons Dock */
.weapons-dock {
  display: flex;
  gap: 6px;
}

.weapon-slot {
  background: var(--bg-box);
  border: 2px solid #556;
  padding: 6px 10px;
  min-width: 115px;
  cursor: pointer;
}

.weapon-slot.active {
  border-color: var(--rad-green);
  background: #142818;
  transform: translateY(-4px);
}

.weapon-slot.locked {
  opacity: 0.55;
  border-style: dashed;
}

.w-name {
  font-size: 11px;
  font-weight: 900;
}

.w-meta {
  font-size: 11px;
  color: var(--scrap-gold);
  margin-top: 2px;
}

/* Mutations Strip */
.mutations-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 260px;
  justify-content: flex-end;
}

.mut-badge {
  background: var(--bg-box);
  border: 2px solid var(--rad-green);
  padding: 4px 7px;
  font-size: 12px;
  font-weight: 900;
}

/* Portal / Upgrade Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 4, 15, 0.86);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-window {
  width: 100%;
  max-width: 960px;
  max-height: 88vh;
  background: #0e1218;
  border: 3px solid var(--portal-purple);
  padding: 20px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  border-bottom: 2px solid #2a3342;
  padding-bottom: 10px;
}

.modal-header h2 {
  color: #e299ff;
  font-size: 20px;
}

.modal-sub {
  font-size: 12px;
  color: #99aabb;
}

.next-level-cta {
  background: var(--rad-green);
  color: #000;
  border: 2px solid #fff;
  padding: 12px 20px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
}

.next-level-cta:hover {
  background: #66ff88;
}

.mutation-section {
  background: #142218;
  border: 2px solid var(--rad-green);
  padding: 12px;
  margin-bottom: 14px;
}

.sec-title {
  font-size: 14px;
  font-weight: 900;
  color: var(--rad-green);
  margin-bottom: 10px;
}

.mutation-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.mut-card {
  background: #0b140e;
  border: 2px solid var(--rad-green);
  padding: 10px;
  cursor: pointer;
}

.mut-card:hover {
  background: #1b3822;
}

.shop-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.shop-tab {
  background: #161c24;
  border: 2px solid #445566;
  color: #aaa;
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-weight: 900;
  cursor: pointer;
}

.shop-tab.active {
  border-color: var(--scrap-gold);
  color: var(--scrap-gold);
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 10px;
  overflow-y: auto;
}

.upg-card {
  background: #141922;
  border: 2px solid #334455;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.upg-card.affordable {
  border-color: var(--scrap-gold);
}

.upg-head {
  display: flex;
  justify-content: space-between;
  font-weight: 900;
  font-size: 13px;
}

.upg-desc {
  font-size: 12px;
  color: #99aabb;
}

.upg-effect {
  font-size: 12px;
  color: var(--rad-green);
  font-weight: 900;
}

.upg-buy-btn {
  background: #222b38;
  border: 2px solid #667788;
  color: #fff;
  padding: 8px;
  font-family: var(--font-mono);
  font-weight: 900;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}

.upg-card.affordable .upg-buy-btn {
  border-color: var(--scrap-gold);
  color: var(--scrap-gold);
}

.modal-footer {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid #2a3342;
  display: flex;
  justify-content: space-between;
}

.danger-btn {
  background: #331118;
  border: 2px solid var(--enemy-red);
  color: #ff8899;
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-weight: 900;
  cursor: pointer;
}

/* Quake-Style Demo Recorder & Crash Repro Controls */
.demo-recorder-box {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed rgba(255, 255, 255, 0.16);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.demo-rec-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 9.5px;
  font-family: var(--font-mono);
  color: #aab8c8;
}

.demo-rec-live {
  color: #ff6677;
  font-weight: 900;
}

.demo-rec-replay {
  color: #33ff55;
  font-weight: 900;
}

.demo-btn-row {
  display: grid;
  grid-template-columns: 1.25fr 1.25fr 0.65fr 0.85fr;
  gap: 3px;
}

.demo-btn {
  padding: 3px 4px !important;
  font-size: 9px !important;
  font-weight: 900;
  text-align: center;
}

#demo-banner {
  margin-top: 6px;
  background: rgba(15, 28, 18, 0.92);
  border: 1.5px solid #33ff55;
  color: #33ff55;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.5px;
  text-align: center;
}

#demo-banner.crash {
  background: rgba(45, 10, 16, 0.95);
  border-color: #ff3355;
  color: #ff8899;
}
