:root {
  --bg-dark: #070913;
  --bg-panel: rgba(12, 16, 32, 0.85);
  --bg-card: rgba(16, 22, 45, 0.9);
  --neon-cyan: #00f0ff;
  --neon-pink: #ff007f;
  --neon-yellow: #ffe600;
  --neon-green: #00ff66;
  --neon-purple: #bd00ff;
  --neon-orange: #ff9900;
  --danger-red: #ff003c;
  --text-main: #e0f7fc;
  --text-muted: #6b8299;
  
  --font-display: 'Orbitron', -apple-system, sans-serif;
  --font-body: 'Rajdhani', -apple-system, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: var(--font-body);
  color: var(--text-main);
  background-image: 
    radial-gradient(circle at 50% 50%, rgba(0, 240, 255, 0.05) 0%, transparent 60%),
    radial-gradient(circle at 80% 20%, rgba(255, 0, 127, 0.04) 0%, transparent 50%);
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ================= PORTAL HEADER ================= */
.portal-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 50;
  background-color: rgba(5, 5, 10, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0, 240, 255, 0.15);
  font-family: 'Inter', -apple-system, sans-serif;
  height: 52px;
  pointer-events: auto;
}

.portal-header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.portal-logo a {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--neon-cyan);
  text-decoration: none;
  letter-spacing: -0.03em;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
  display: flex;
  align-items: center;
  gap: 6px;
}

.portal-nav {
  display: flex;
  gap: 20px;
}

.portal-nav a {
  color: rgba(255, 255, 255, 0.6);
  font-weight: 500;
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.portal-nav a:hover {
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

@media (max-width: 768px) {
  .portal-nav {
    display: none;
  }
}

canvas#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* ================= HUD ================= */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  font-family: var(--font-display);
}

#exp-container {
  position: absolute;
  top: 52px; /* right below portal header */
  left: 0;
  width: 100%;
  height: 18px;
  background: rgba(0, 0, 0, 0.65);
  border-bottom: 1px solid rgba(0, 240, 255, 0.3);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

#exp-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #00f0ff, #00ff66, #ffe600);
  box-shadow: 0 0 12px var(--neon-cyan);
  transition: width 0.15s ease-out;
}

#exp-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 0 4px #000, 0 0 8px var(--neon-cyan);
}

#top-info {
  position: absolute;
  top: 78px; /* adjusted for portal header */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  pointer-events: auto;
}

.hud-stat-box {
  background: var(--bg-panel);
  border: 1px solid rgba(0, 240, 255, 0.3);
  padding: 6px 16px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4), inset 0 0 8px rgba(0, 240, 255, 0.1);
}

.audio-toggle-box {
  flex-direction: row;
  gap: 8px;
  padding: 4px 8px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(0, 240, 255, 0.4);
  color: #fff;
  border-radius: 4px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(0, 240, 255, 0.25);
  box-shadow: 0 0 10px var(--neon-cyan);
}

.hud-label {
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
}

.hud-value {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1px;
}

/* Player Status HUD */
#player-status {
  position: absolute;
  bottom: 24px;
  left: 24px;
  width: 240px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-bar-wrapper {
  background: var(--bg-panel);
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
}

.bar-label {
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  letter-spacing: 1px;
}

.bar-outer {
  width: 100%;
  height: 10px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.hp-inner {
  height: 100%;
  background: linear-gradient(90deg, #ff0055, #00ff66);
  box-shadow: 0 0 8px var(--neon-green);
  transition: width 0.15s ease-out;
}

.shield-inner {
  height: 100%;
  background: linear-gradient(90deg, #0088ff, #00f0ff);
  box-shadow: 0 0 8px var(--neon-cyan);
  transition: width 0.15s ease-out;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.eq-badge {
  background: rgba(10, 15, 30, 0.9);
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 0 6px rgba(0, 240, 255, 0.2);
}

.eq-level {
  color: var(--neon-yellow);
}

/* Boss Warning & HP Bar */
#boss-hud {
  position: absolute;
  top: 140px; /* adjusted for portal header */
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  max-width: 600px;
  text-align: center;
}

#boss-warning {
  font-size: 14px;
  font-weight: 900;
  color: var(--neon-pink);
  margin-bottom: 4px;
  animation: pulse 1s infinite alternate;
  letter-spacing: 2px;
  text-shadow: 0 0 8px var(--neon-pink);
}

.boss-bar-outer {
  width: 100%;
  height: 14px;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid var(--neon-pink);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 0 12px rgba(255, 0, 127, 0.4);
}

.boss-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, #ff007f, #bd00ff, #ff003c);
  box-shadow: 0 0 10px var(--neon-pink);
  transition: width 0.1s linear;
}

/* ================= OVERLAYS & MODALS ================= */
.overlay-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  background: rgba(4, 6, 15, 0.75);
  backdrop-filter: blur(10px);
  transition: opacity 0.3s ease;
}

.hidden {
  display: none !important;
}

.cyber-card {
  background: var(--bg-panel);
  border: 1px solid rgba(0, 240, 255, 0.4);
  box-shadow: 0 0 30px rgba(0, 240, 255, 0.2), inset 0 0 20px rgba(0, 240, 255, 0.05);
  border-radius: 8px;
  padding: 36px 48px;
  text-align: center;
  position: relative;
  max-width: 680px;
  width: 90%;
  animation: modalAppear 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes modalAppear {
  0% { transform: scale(0.9) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.title-logo-container {
  margin-bottom: 24px;
}

.sub-title {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 4px;
  color: var(--neon-cyan);
  margin-bottom: 6px;
  text-shadow: 0 0 8px var(--neon-cyan);
}

.glitch-title {
  font-family: var(--font-display);
  font-size: 46px;
  font-weight: 900;
  letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 0 15px var(--neon-cyan), 0 0 30px var(--neon-cyan);
  position: relative;
}

.red-glow {
  text-shadow: 0 0 15px var(--danger-red), 0 0 30px var(--neon-pink);
}

.neon-line {
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--neon-cyan), transparent);
  margin: 16px 0 24px;
}

.high-score-display {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 1.5px;
  margin-bottom: 30px;
  color: #a0aec0;
}

.high-score-display .divider {
  margin: 0 12px;
  color: rgba(255, 255, 255, 0.2);
}

.cyber-btn {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 14px 36px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
  outline: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-btn {
  background: linear-gradient(135deg, #00f0ff, #0088ff);
  color: #070913;
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
}

.primary-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 0 30px var(--neon-cyan);
  background: linear-gradient(135deg, #33f3ff, #00aaff);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
}

.portal-return-btn {
  background: rgba(0, 240, 255, 0.1);
  color: var(--neon-cyan);
  border: 1px solid rgba(0, 240, 255, 0.4);
}

.portal-return-btn:hover {
  background: rgba(0, 240, 255, 0.25);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.4);
}

.danger-btn {
  background: linear-gradient(135deg, #ff0055, #bd00ff);
  color: #fff;
  box-shadow: 0 0 20px rgba(255, 0, 127, 0.4);
}

.danger-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px var(--neon-pink);
}

.controls-guide {
  margin-top: 32px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 16px;
  text-align: left;
}

.guide-title {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--neon-yellow);
  margin-bottom: 12px;
}

.guide-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.guide-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.key-badge {
  display: inline-block;
  background: rgba(0, 240, 255, 0.15);
  border: 1px solid rgba(0, 240, 255, 0.4);
  color: var(--neon-cyan);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  width: fit-content;
}

.guide-desc {
  font-size: 13px;
  color: #94a3b8;
}

/* ================= LEVEL UP MODAL ================= */
#level-up-modal .modal-content {
  max-width: 900px;
  width: 95%;
  text-align: center;
  animation: modalAppear 0.25s ease-out;
  z-index: 101;
}

.modal-header {
  margin-bottom: 24px;
}

.modal-sub {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--neon-cyan);
}

.neon-glow-text {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 15px var(--neon-yellow), 0 0 30px var(--neon-yellow);
}

.modal-hint {
  font-size: 15px;
  color: #cbd5e1;
  margin-top: 4px;
}

.cards-container {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-bottom: 24px;
}

.upgrade-card {
  flex: 1;
  max-width: 270px;
  background: var(--bg-card);
  border: 2px solid rgba(0, 240, 255, 0.3);
  border-radius: 8px;
  padding: 24px 18px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.upgrade-card:hover {
  transform: translateY(-8px) scale(1.03);
  border-color: var(--neon-cyan);
  box-shadow: 0 12px 35px rgba(0, 240, 255, 0.4), inset 0 0 15px rgba(0, 240, 255, 0.2);
}

.upgrade-card.rarity-common {
  border-color: rgba(0, 240, 255, 0.5);
}
.upgrade-card.rarity-rare {
  border-color: rgba(189, 0, 255, 0.7);
  box-shadow: 0 8px 25px rgba(189, 0, 255, 0.2);
}
.upgrade-card.rarity-rare:hover {
  border-color: var(--neon-purple);
  box-shadow: 0 12px 35px rgba(189, 0, 255, 0.5);
}
.upgrade-card.rarity-epic {
  border-color: rgba(255, 0, 127, 0.8);
  box-shadow: 0 8px 25px rgba(255, 0, 127, 0.3);
}
.upgrade-card.rarity-epic:hover {
  border-color: var(--neon-pink);
  box-shadow: 0 12px 35px rgba(255, 0, 127, 0.6);
}
.upgrade-card.rarity-legendary {
  border-color: rgba(255, 230, 0, 0.9);
  box-shadow: 0 8px 30px rgba(255, 230, 0, 0.4);
}
.upgrade-card.rarity-legendary:hover {
  border-color: var(--neon-yellow);
  box-shadow: 0 12px 40px rgba(255, 230, 0, 0.7);
}

.card-tag {
  position: absolute;
  top: 10px;
  right: 10px;
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
}

.card-tag.new {
  background: var(--neon-green);
  color: #070913;
  box-shadow: 0 0 8px var(--neon-green);
}

.card-icon {
  font-size: 36px;
  margin: 12px 0 14px;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
}

.card-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #fff;
}

.card-desc {
  font-size: 13px;
  line-height: 1.4;
  color: #94a3b8;
  margin-bottom: 12px;
  flex: 1;
}

.card-level-info {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: var(--neon-cyan);
  background: rgba(0, 0, 0, 0.4);
  padding: 4px 10px;
  border-radius: 4px;
  width: 100%;
}

.modal-footer {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--text-muted);
}

/* ================= GAME OVER MODAL ================= */
.gameover-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 24px 0;
}

.stat-card {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.stat-lbl {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.stat-val {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 900;
}

.new-record {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 900;
  color: var(--neon-yellow);
  text-shadow: 0 0 10px var(--neon-yellow);
  margin-top: 10px;
  animation: pulse 0.8s infinite alternate;
}

.build-recap {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 24px;
  text-align: left;
}

.recap-title {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--neon-cyan);
  margin-bottom: 8px;
}

.recap-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.modal-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ================= COLORS & UTILITIES ================= */
.neon-cyan { color: var(--neon-cyan); text-shadow: 0 0 8px var(--neon-cyan); }
.neon-pink { color: var(--neon-pink); text-shadow: 0 0 8px var(--neon-pink); }
.neon-yellow { color: var(--neon-yellow); text-shadow: 0 0 8px var(--neon-yellow); }
.neon-green { color: var(--neon-green); text-shadow: 0 0 8px var(--neon-green); }
.neon-purple { color: var(--neon-purple); text-shadow: 0 0 8px var(--neon-purple); }
.danger-text { color: var(--danger-red); text-shadow: 0 0 8px var(--danger-red); }

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.05); opacity: 1; }
}

@media (max-width: 768px) {
  .cards-container {
    flex-direction: column;
    align-items: center;
  }
  .upgrade-card {
    max-width: 100%;
    width: 100%;
  }
  .glitch-title {
    font-size: 32px;
  }
  .cyber-card {
    padding: 24px 20px;
  }
  #player-status {
    bottom: 12px;
    left: 12px;
    width: 180px;
  }
}
