/* =================================================================== */
/*                           FONTS & GLOBALS                           */
/* =================================================================== */

@font-face {
  font-family: 'Rubik 80s Fade';
  src: url('fonts/Rubik80sFade-Regular.ttf') format('truetype');
  font-display: swap;
}

@font-face {
  font-family: 'Rubik Mono One';
  src: url('fonts/RubikMonoOne-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  --primary-color: #0f0;
  --secondary-color: #f00;
  --gold-color: gold;
  --skull-color: #09fdd3;
  --cross-color: #ff0;
  --star-color: #ed420f;
  --worm-segment-color: purple;
  --worm-head-color: magenta;
}

body {
  margin: 0;
  background: #000;
  overflow: hidden;
  font-family: 'Courier New', monospace;
  pointer-events: none;
}

/* =================================================================== */
/*                         CORE GAME LAYOUT & UI                       */
/* =================================================================== */

#matrix-effect { position: fixed; top: 0; left: 0; z-index: -1; opacity: 0.3; }
#game { position: fixed; top: 0; left: 0; width: 100%; height: 100%; }

#score, #health, #timer, #fps-counter { 
  position: fixed; 
  color: var(--primary-color); 
  font-size: 20px; 
  z-index: 1001;
}
#score { top: 80px; left: 20px; }
#health { top: 50px; left: 20px; }
#timer { top: 20px; left: 20px; }
#fps-counter { top: 10px; right: 10px; display: none; }

/* =================================================================== */
/*                       OVERLAYS & MENUS                              */
/* =================================================================== */

#startup-overlay, #game-over-overlay, #main-menu-overlay, 
#settings-menu-overlay, #pause-menu {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-in-out;
}

#startup-overlay {
    display: flex;
    opacity: 1;
    background: #000;
    transition: opacity 1s ease-in-out;
}

#game-over-overlay { background: #000; }
#settings-menu-overlay { justify-content: flex-start; }

#main-menu-overlay.visible, #settings-menu-overlay.visible, #pause-menu.visible {
  display: flex;
  opacity: 1;
  pointer-events: auto;
}

.menu-content { display: flex; flex-direction: column; align-items: center; }
.menu-buttons { display: flex; flex-direction: column; align-items: center; }

.matrix-text { font-family: 'Rubik 80s Fade'; font-size: 150px; text-align: center; color: var(--primary-color); text-shadow: 0 0 10px var(--primary-color); }
#game-over-overlay .matrix-text { color: var(--secondary-color); text-shadow: 0 0 10px var(--secondary-color); }
.random-chars { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; }
.random-chars span { position: absolute; color: var(--primary-color); font-size: 20px; opacity: 0.5; transform: translateZ(0); }


/* =================================================================== */
/*    MENU BUTTONS (GPU-ACCELERATED WITH FULL GLOW ANIMATION)         */
/* =================================================================== */

.text-btn {
  font-family: 'Rubik 80s Fade';
  font-size: 9rem;
  background: none;
  border: none;
  padding: 15px 20px;
  cursor: pointer;
  position: relative;
  transform: translateZ(0);
  will-change: transform;
}

#main-menu-overlay .text-btn {
  font-size: 9rem;
}

#play-btn, #settings-btn, #resume-btn, #pause-settings-btn {
  color: var(--primary-color);
  text-shadow: 0 0 8px var(--primary-color);
}
.danger-btn {
  color: var(--secondary-color);
  text-shadow: 0 0 8px var(--secondary-color);
}

.text-btn::before {
  content: attr(data-text);
  position: absolute;
  left: 0;
  right: 0;
  z-index: -1;
  text-shadow: 0 0 15px var(--primary-color), 0 0 25px var(--primary-color);
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  will-change: opacity;
}

.danger-btn::before {
  text-shadow: 0 0 15px var(--secondary-color), 0 0 25px var(--secondary-color);
}

.text-btn:hover:not(:disabled)::before {
  opacity: 1;
}

.text-btn:hover:not(:disabled) { transform: scale(1.1) translateZ(0); }
.text-btn:active:not(:disabled) { transform: scale(1.05) translateZ(0); }
.text-btn:disabled { color: #444; text-shadow: none; cursor: not-allowed; }


/* =================================================================== */
/*                        GAME ENTITIES & PLAYER                       */
/* =================================================================== */

#player {
  position: absolute; width: 20px; height: 20px; background-color: #0f0;
  left: calc(50% - 10px); top: calc(50% - 10px);
  transition: background-color 0.3s;
}

/* Base style for all entities that are positioned by JS */
.data-packet, .obstacle, .powerup, .enemy-skull, .enemy-cross, .enemy-star,
.enemy-worm-segment, .enemy-worm-head, .enemy-spitter, .dash-trail, .attack-animation,
.enemy-red-skull, .enemy-shocker {
  position: absolute;
  /* 
    This is the key fix: The transform uses CSS variables that JS will update.
    This allows CSS animations (like scaling) to be ADDED without overriding position.
    A default rotation is included for entities that might use it.
  */
  transform: translate(var(--tx, 0px), var(--ty, 0px)) rotate(var(--rot, 0rad));
}

.data-packet { color: var(--primary-color); text-shadow: 0 0 5px var(--primary-color); font-size: 20px; }
.obstacle { color: var(--secondary-color); text-shadow: 0 0 5px var(--secondary-color); font-size: 20px; }
.powerup { font-size: 24px; color: var(--gold-color); text-shadow: 0 0 10px var(--gold-color); }
.enemy-skull { color: var(--skull-color); text-shadow: 0 0 5px var(--skull-color); font-size: 20px; }
.enemy-star { font-size: 24px; color: var(--star-color); text-shadow: 0 0 10px var(--star-color); }
.enemy-spitter { color: #b1fc03; font-size: 40px; }
.enemy-worm-segment { color: var(--worm-segment-color); font-size: 20px; }
.enemy-worm-head { font-weight: bold; font-size: 28px; color: var(--worm-head-color); text-shadow: 0 0 7px var(--worm-head-color); display: inline-block; transform-origin: center; }
.enemy-cross { color: var(--cross-color); transform: rotate(var(--rotation)); font-size: 1.4em; }
.cross-charging { animation: vibrate 0.05s infinite; }
@keyframes vibrate { 0% { transform: translateX(0); } 25% { transform: translateX(-2px); } 50% { transform: translateX(2px); } 75% { transform: translateX(-2px); } 100% { transform: translateX(0); } }

/* =================================================================== */
/*                     ANIMATIONS & VISUAL EFFECTS                     */
/* =================================================================== */

#lightning-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

.lightning-line {
    stroke: #5d9dff;
    stroke-width: 3px;
    filter: drop-shadow(0 0 5px #5d9dff) drop-shadow(0 0 10px #5d9dff);
    animation: fade-out 0.4s ease-out forwards;
}

@keyframes fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

.player-glow { box-shadow: 0 0 20px var(--gold-color) }
.spitter-shake { animation: shake 0.5s; }
.slow-blink { animation: slow-blink 1s infinite; }

.dash-trail { width: 20px; height: 20px; background-color: #0f0; filter: blur(9px); opacity: 0.3; pointer-events: none; transition: opacity 0.5s linear; }
.attack-animation { width: 20px; height: 20px; border-radius: 50%; border: 3px solid #ff0; opacity: 0.8; pointer-events: none; transition: transform 0.5s ease-out, opacity 0.5s ease-out, filter 0.5s ease-out; transform-origin: center; transform: scale(1); }

#dash-aiming-overlay { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 999; }

@keyframes vibrate { 0% { transform: translateX(0); } 25% { transform: translateX(-2px); } 50% { transform: translateX(2px); } 75% { transform: translateX(-2px); } 100% { transform: translateX(0); } }
@keyframes shake { 0%{transform:translate(1px, 1px) rotate(0deg)}10%{transform:translate(-1px,-2px) rotate(-1deg)}20%{transform:translate(-3px,0px) rotate(1deg)}30%{transform:translate(3px,2px) rotate(0deg)}40%{transform:translate(1px,-1px) rotate(1deg)}50%{transform:translate(-1px,2px) rotate(-1deg)}60%{transform:translate(-3px,1px) rotate(0deg)}70%{transform:translate(3px,1px) rotate(-1deg)}80%{transform:translate(-1px,-1px) rotate(1deg)}90%{transform:translate(1px,2px) rotate(1deg)}100%{transform:translate(1px,-2px) rotate(-1deg)} }
@keyframes slow-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes grid-pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.6; } }
@keyframes text-flicker { 0%,18%,22%,25%,53%,57%,100% { text-shadow:0 0 10px var(--primary-color); opacity:1; } 20%,24%,55% { text-shadow:none; opacity:0.9; } }

/* =================================================================== */
/*                       UI: IN-GAME SKILL MENU                        */
/* =================================================================== */

#skill-menu { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; display: flex; justify-content: flex-start; align-items: flex-end; z-index: 1000; pointer-events: auto; }
.button-container { display: flex; gap: 2rem; padding: 20px; }

.matrix-btn {
  width: 100px; height: 100px; background: #000; border: 2px solid #0f0;
  cursor: pointer; position: relative; transition: all 0.3s ease;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; box-shadow: inset 0 0 10px #0f03;
}
.matrix-btn i {
  color: #0f0; font-size: 2.5rem; transition: all 0.3s ease;
  position: relative; z-index: 2; filter: drop-shadow(0 0 2px #0f0);
  animation: float 2s ease-in-out infinite;
}
.matrix-btn::before {
  content: ''; position: absolute; width: 100%; height: 100%;
  background: repeating-linear-gradient(0deg, transparent 0 9px, #0f02 9px 10px), repeating-linear-gradient(90deg, transparent 0 9px, #0f02 9px 10px);
  animation: grid-pulse 1.5s infinite; opacity: 0.3; pointer-events: none;
}
.matrix-btn:hover { box-shadow: 0 0 25px #0f06, inset 0 0 15px #0f03; transform: scale(1.1); }
.matrix-btn:active { transform: scale(0.95); filter: brightness(1.2); }

/* =================================================================== */
/*                          UI: SETTINGS PANEL                         */
/* =================================================================== */

.settings-panel {
  position: relative; width: min(720px, 92vw); margin-left: 5vw;
  color: var(--primary-color); padding: 28px 28px 24px 28px;
  border: 1px solid rgba(0,255,0,0.35); border-left-width: 3px; border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(0,18,0,0.92), rgba(0,12,0,0.88)),
    radial-gradient(1200px 400px at -10% -10%, rgba(0,255,0,0.10), transparent 60%),
    radial-gradient(800px 300px at 120% 110%, rgba(0,255,120,0.07), transparent 70%),
    repeating-linear-gradient(90deg, rgba(0,255,0,0.03) 0 1px, transparent 1px 14px);
  box-shadow: 0 0 24px rgba(0,255,0,0.18), inset 0 0 0 1px rgba(0,255,0,0.08);
  display: grid; grid-auto-rows: max-content; gap: 18px;
  max-height: min(86vh, 980px); overflow: auto;
  scrollbar-width: thin; scrollbar-color: rgba(0,255,0,0.5) transparent;
}
.settings-panel::-webkit-scrollbar { width: 10px; }
.settings-panel::-webkit-scrollbar-track { background: transparent; }
.settings-panel::-webkit-scrollbar-thumb { background: rgba(0,255,0,0.45); border-radius: 10px; }

.settings-panel::before, .settings-panel::after { content: ""; position: absolute; pointer-events: none; }
.settings-panel::before {
    left: 14px; top: 12px; bottom: 12px; width: 6px;
    background: linear-gradient(180deg, transparent, rgba(0,255,0,0.8) 15%, rgba(0,255,0,0.2) 50%, rgba(0,255,0,0.8) 85%, transparent);
    filter: drop-shadow(0 0 12px rgba(0,255,0,0.6));
}
.settings-panel::after {
    right: 14px; top: 12px; height: 6px; width: 120px;
    background: linear-gradient(90deg, rgba(0,255,0,0.0), rgba(0,255,0,0.6), rgba(0,255,0,0.0));
    box-shadow: 0 0 12px rgba(0,255,0,0.3);
}

.settings-title {
  position: sticky; top: 0; z-index: 2; margin: -28px -28px 8px -28px;
  padding: 0px 28px 10px 28px; font-family: 'Rubik 80s Fade';
  font-size: clamp(2.2rem, 3.2vw, 3.6rem); text-align: center; letter-spacing: 1px;
  color: var(--primary-color); background: linear-gradient(180deg, rgba(0,18,0,0.92), rgba(0,18,0,0));
  text-shadow: 0 0 10px var(--primary-color); border-bottom: 1px solid rgba(0,255,0,0.25);
  backdrop-filter: blur(2px); animation: text-flicker 5s infinite;
}

.settings-section {
  position: relative; margin: 0; padding: 18px 16px 14px 16px;
  border: 1px solid rgba(0,255,0,0.22); border-radius: 14px;
  background: linear-gradient(180deg, rgba(0,20,0,0.45), rgba(0,12,0,0.25)), repeating-linear-gradient(0deg, rgba(0,255,0,0.04) 0 1px, transparent 1px 18px);
  box-shadow: inset 0 0 0 1px rgba(0,255,0,0.06);
}
.settings-section::before {
    content: ""; position: absolute; left: 10px; right: 10px; top: 10px; height: 6px;
    background: radial-gradient(10px 6px at left, rgba(0,255,0,0.45), transparent 70%), radial-gradient(10px 6px at right, rgba(0,255,0,0.45), transparent 70%);
    opacity: 0.6;
}
.settings-section h3 {
  font-family: 'Rubik Mono One'; font-size: 1.15rem; margin: 0 0 14px 0;
  padding: 0 0 6px 0; letter-spacing: .6px; color: var(--gold-color);
  text-shadow: 0 0 8px rgba(255,215,0,0.35); border-bottom: 1px dashed rgba(0,255,0,0.22);
}

.setting-item {
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: 18px; font-family: 'Rubik Mono One'; font-size: 1.02rem;
  padding: 8px 6px; border-radius: 10px;
  transition: background-color .15s ease, box-shadow .15s ease;
  justify-self: end;
}
.setting-item:hover { background-color: rgba(0,255,0,0.06); box-shadow: inset 0 0 0 1px rgba(0,255,0,0.06); }
.setting-item:has(.matrix-checkbox:checked) { background-color: rgba(0,255,0,0.10); box-shadow: inset 0 0 0 1px rgba(0,255,0,0.16), 0 0 16px rgba(0,255,0,0.10); }

.controls-grid {
  display: grid; grid-template-columns: 1fr auto; gap: 12px 24px;
  align-items: center; font-family: 'Rubik Mono One'; font-size: 1rem;
}

.settings-actions {
  display: flex; justify-content: flex-end; align-items: center;
  margin-top: 6px; padding-top: 14px;
  border-top: 1px solid rgba(0, 255, 0, 0.18); gap: 12px;
}

.rebind-btn, .settings-actions .text-btn.small-btn {
  font-family: 'Rubik Mono One'; font-size: 0.95rem; line-height: 1;
  padding: 12px 18px; min-width: 132px; text-align: center; cursor: pointer;
  color: var(--primary-color);
  background: linear-gradient(180deg, rgba(0,25,0,0.65), rgba(0,18,0,0.55));
  border: 1px solid rgba(0,255,0,0.6);
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(0,255,0,0.25) inset, 0 2px 10px rgba(0,255,0,0.15);
  transition: transform .12s ease, box-shadow .15s ease, background-color .15s ease, color .15s ease, border-color .15s ease;
  text-shadow: 0 0 2px var(--primary-color);
}

.rebind-btn:hover, .settings-actions .text-btn.small-btn:hover:not(:disabled) {
  background: var(--primary-color);
  color: #000;
  border-color: rgba(0,255,0,0.9);
  box-shadow: 0 0 18px rgba(0,255,0,0.6), 0 0 2px rgba(0,0,0,0.6) inset;
}

.rebind-btn:active, .settings-actions .text-btn.small-btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 0 10px rgba(0,255,0,0.45) inset;
}

.matrix-checkbox {
  appearance: none; width: 22px; height: 22px;
  border: 2px solid var(--primary-color); background: #000;
  cursor: pointer; position: relative; border-radius: 4px;
  transition: box-shadow 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
  justify-self: end;
}
.matrix-checkbox:hover { box-shadow: 0 0 10px rgba(0,255,0,0.6); }
.matrix-checkbox:active { transform: scale(0.96); }
.matrix-checkbox:checked { background-color: var(--primary-color); box-shadow: 0 0 14px rgba(0,255,0,0.7); }
.matrix-checkbox:checked::before {
  content: 'X'; font-family: 'Rubik Mono One'; position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -52%);
  font-size: 14px; font-weight: 900; color: #000;
}

.rebind-btn:focus-visible, .settings-actions .text-btn.small-btn:focus-visible, .matrix-checkbox:focus-visible {
  outline: 2px solid var(--gold-color);
  outline-offset: 2px;
}

/* =================================================================== */
/*                       UI: DEBUG CONSOLE                             */
/* =================================================================== */

#debug-console {
  position: fixed; bottom: 20px; right: 20px; width: 650px;
  background: black; color: #0f0; padding: 10px;
  border: 1px solid #0f0; display: none;
  box-shadow: 0 0 10px rgba(0, 255, 0, 0.3);
  z-index: 1002; pointer-events: auto;
}
#console-output { height: 280px; overflow-y: auto; width: 100%; background: black; color: #0f0; border: none; resize: none; padding: 5px; }
#console-input { width: 100%; background: black; color: #0f0; border: none; outline: none; font-size: 14px; padding: 5px; }


/* =================================================================== */
/*                           RESPONSIVE TWEAKS                         */
/* =================================================================== */

@media (max-width: 720px) {
  .settings-panel { width: 95vw; padding: 22px; border-radius: 14px; }
  .settings-title { font-size: 2.2rem; }
  .settings-section { padding: 14px; }
  .setting-item, .controls-grid { grid-template-columns: 1fr; gap: 10px; }
  .rebind-btn, .settings-actions .text-btn.small-btn { min-width: 112px; padding: 10px 14px; }
}

/* =================================================================== */
/*                           SETTINGS VOLUME SLIDER                        */
/* =================================================================== */

.matrix-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--primary-color);
  border-radius: 6px;
  outline: none;
  cursor: pointer;
}

.matrix-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  background: var(--primary-color);
  border: 2px solid #000;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(0,255,0,0.7);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.matrix-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--primary-color);
  border: 2px solid #000;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(0,255,0,0.7);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.matrix-slider:hover::-webkit-slider-thumb {
  box-shadow: 0 0 18px var(--primary-color);
}
.matrix-slider:active::-webkit-slider-thumb {
  transform: scale(1.1);
}
.matrix-slider:hover::-moz-range-thumb {
  box-shadow: 0 0 18px var(--primary-color);
}
.matrix-slider:active::-moz-range-thumb {
  transform: scale(1.1);
}

/* =================================================================== */
/*                     HARDMODE ENEMIES & EFFECTS                      */
/* =================================================================== */

.enemy-red-skull {
  font-size: 20px;
  color: #ff4d4d;
  font-weight: bold;
  text-shadow: 0 0 8px #ff1a1a, 0 0 12px #ff1a1a;
}

.enemy-shocker {
  font-size: 24px;
  color: #5d9dff;
  text-shadow: 0 0 10px #0055ff, 0 0 15px #0055ff;
}

.shocker-explosion {
  position: absolute;
  width: 10px;
  height: 10px;
  background-color: #5d9dff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: shocker-explode 0.5s ease-out forwards;
  pointer-events: none;
  z-index: 100;
}

@keyframes shocker-explode {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    box-shadow: 0 0 15px 5px #5d9dff;
  }
  100% {
    transform: translate(-50%, -50%) scale(12);
    opacity: 0;
    box-shadow: 0 0 40px 20px rgba(93, 157, 255, 0);
  }
}