:root {
  --bg-dark: #050507;
  --bg-panel: #0a0a12;
  --text-green: #39ff14;
  --text-amber: #ffcc00;
  --text-cyan: #00ffff;
  --text-red: #ff3333;
  --text-purple: #cc44ff;
  --text-dim: #556655;
  --glow-green: 0 0 10px rgba(57, 255, 20, 0.5);
  --glow-amber: 0 0 10px rgba(255, 204, 0, 0.5);
  --glow-cyan: 0 0 10px rgba(0, 255, 255, 0.5);
  --font-main: 'VT323', monospace;
}

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

body {
  background: var(--bg-dark);
  font-family: var(--font-main);
  color: var(--text-green);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

#game-wrapper {
  position: relative;
  width: 1000px;
  max-width: 100vw;
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 2px solid var(--text-green);
  box-shadow: var(--glow-green);
  background: var(--bg-dark);
  image-rendering: pixelated;
}

/* Scanline overlay */
#game-wrapper::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.15) 2px,
    rgba(0, 0, 0, 0.15) 4px
  );
  pointer-events: none;
  z-index: 10;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 8px 16px;
  font-size: 22px;
  z-index: 5;
  pointer-events: none;
}

#hud-left, #hud-right {
  display: flex;
  gap: 20px;
}

#hud-score {
  color: var(--text-amber);
  text-shadow: var(--glow-amber);
}

#hud-lives {
  color: var(--text-red);
  letter-spacing: 4px;
}

#hud-rank {
  color: var(--text-cyan);
  text-shadow: var(--glow-cyan);
}

#hud-session {
  color: var(--text-dim);
  font-size: 16px;
}

#logout-btn {
  font-family: var(--font-main);
  font-size: 14px;
  background: transparent;
  color: var(--text-red, #ff3333);
  border: 1px solid var(--text-red, #ff3333);
  padding: 2px 10px;
  margin-left: 12px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 1px;
}

#logout-btn:hover {
  background: rgba(255, 51, 51, 0.15);
  box-shadow: 0 0 8px rgba(255, 51, 51, 0.4);
}

/* Mission text */
#mission-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 36px;
  color: var(--text-amber);
  text-shadow: var(--glow-amber);
  text-align: center;
  z-index: 6;
  pointer-events: none;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Controls legend */
#controls-legend {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 20px;
  font-size: 16px;
  color: var(--text-dim);
  z-index: 5;
  pointer-events: none;
}

/* Log export button */
#log-export {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
}

#export-btn {
  font-family: var(--font-main);
  font-size: 16px;
  background: var(--bg-panel);
  color: var(--text-cyan);
  border: 1px solid var(--text-cyan);
  padding: 4px 14px;
  cursor: pointer;
  transition: all 0.2s;
}

#export-btn:hover {
  background: rgba(0, 255, 255, 0.1);
  box-shadow: var(--glow-cyan);
}

#log-count-badge {
  background: var(--text-red);
  color: #000;
  font-size: 13px;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 6px;
}

/* Terminal overlay */
#terminal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
}

#terminal-content {
  background: var(--bg-panel);
  border: 2px solid var(--text-green);
  box-shadow: var(--glow-green);
  width: 80%;
  max-height: 80%;
  overflow-y: auto;
  padding: 20px;
}

#terminal-header {
  font-size: 28px;
  color: var(--text-amber);
  text-shadow: var(--glow-amber);
  border-bottom: 1px solid var(--text-dim);
  padding-bottom: 10px;
  margin-bottom: 15px;
}

#terminal-body {
  font-size: 20px;
  line-height: 1.6;
  color: var(--text-green);
  white-space: pre-wrap;
}

#terminal-footer {
  margin-top: 15px;
  padding-top: 10px;
  border-top: 1px solid var(--text-dim);
  color: var(--text-dim);
  font-size: 18px;
  text-align: center;
}

/* Touch controls */
#touch-controls {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40vh;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 16px 24px;
  z-index: 15;
  pointer-events: none;
}

/* Joystick */
#joystick-zone {
  width: 160px;
  height: 160px;
  position: relative;
  pointer-events: auto;
  touch-action: none;
}

#joystick-base {
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(57, 255, 20, 0.08);
  border: 2px solid rgba(57, 255, 20, 0.3);
  display: flex;
  justify-content: center;
  align-items: center;
}

#joystick-knob {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(57, 255, 20, 0.35);
  border: 2px solid rgba(57, 255, 20, 0.7);
  box-shadow: 0 0 12px rgba(57, 255, 20, 0.4);
  transition: transform 0.05s ease-out;
}

/* Action buttons */
#touch-actions {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  pointer-events: auto;
}

.touch-btn {
  font-family: var(--font-main);
  font-size: 20px;
  background: rgba(57, 255, 20, 0.12);
  color: var(--text-green);
  border: 2px solid rgba(57, 255, 20, 0.4);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.touch-fire {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  font-size: 20px;
  font-weight: bold;
  background: rgba(255, 51, 51, 0.15);
  border-color: rgba(255, 51, 51, 0.5);
  color: var(--text-red);
  box-shadow: 0 0 15px rgba(255, 51, 51, 0.2);
}

.touch-small {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 18px;
}

.touch-btn.touch-active,
.touch-btn:active {
  background: rgba(57, 255, 20, 0.4);
  box-shadow: 0 0 20px rgba(57, 255, 20, 0.5);
}

.touch-fire.touch-active,
.touch-fire:active {
  background: rgba(255, 51, 51, 0.4);
  box-shadow: 0 0 20px rgba(255, 51, 51, 0.5);
}

.touch-pause {
  background: rgba(255, 204, 0, 0.1);
  border-color: rgba(255, 204, 0, 0.4);
  color: var(--text-amber);
  font-size: 14px;
  width: 44px;
  height: 44px;
}

/* Login Screen */
#login-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  width: 100%;
}

#login-box {
  background: var(--bg-panel);
  border: 2px solid var(--text-green);
  box-shadow: var(--glow-green);
  padding: 40px 50px;
  width: 450px;
  max-width: 95vw;
}

#login-title {
  font-size: 48px;
  color: var(--text-green);
  text-shadow: var(--glow-green);
  text-align: center;
  margin-bottom: 5px;
}

#login-subtitle {
  font-size: 20px;
  color: var(--text-amber);
  text-shadow: var(--glow-amber);
  text-align: center;
  margin-bottom: 30px;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 20px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.login-field input {
  width: 100%;
  font-family: var(--font-main);
  font-size: 22px;
  padding: 8px 12px;
  background: #0d0d1a;
  color: var(--text-green);
  border: 1px solid #334433;
  outline: none;
  caret-color: var(--text-green);
}

.login-field input:focus {
  border-color: var(--text-green);
  box-shadow: 0 0 6px rgba(57, 255, 20, 0.3);
}

#login-error {
  font-size: 18px;
  color: var(--text-red);
  background: rgba(255, 51, 51, 0.1);
  border: 1px solid rgba(255, 51, 51, 0.3);
  padding: 8px 12px;
  margin-bottom: 12px;
}

#login-success {
  font-size: 18px;
  color: var(--text-green);
  background: rgba(57, 255, 20, 0.1);
  border: 1px solid rgba(57, 255, 20, 0.3);
  padding: 8px 12px;
  margin-bottom: 12px;
}

#login-btn {
  width: 100%;
  font-family: var(--font-main);
  font-size: 24px;
  padding: 10px;
  background: rgba(57, 255, 20, 0.1);
  color: var(--text-green);
  border: 2px solid var(--text-green);
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

#login-btn:hover {
  background: rgba(57, 255, 20, 0.25);
  box-shadow: var(--glow-green);
}

#login-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#login-hint {
  font-size: 15px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 14px;
}

/* ─── Credits button + modal ─────────────────────────────────────── */
#credits-btn {
  width: 100%;
  font-family: var(--font-main);
  font-size: 14px;
  padding: 8px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 16px;
  letter-spacing: 1px;
}

#credits-btn:hover {
  color: var(--text-green);
  border-color: var(--text-green);
  box-shadow: var(--glow-green);
}

#credits-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: credits-fade 0.2s ease-out;
}

@keyframes credits-fade { from { opacity: 0; } to { opacity: 1; } }

#credits-box {
  background: #020817;
  border: 2px solid var(--text-green);
  box-shadow: var(--glow-green);
  padding: 28px 32px;
  width: min(620px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  font-family: var(--font-main);
  color: var(--text-green);
}

#credits-title {
  font-size: 28px;
  letter-spacing: 2px;
  margin-bottom: 4px;
}

#credits-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 22px;
  letter-spacing: 1px;
}

.credit-row {
  border-top: 1px dashed rgba(57, 255, 20, 0.3);
  padding: 10px 0;
}

.credit-row:first-of-type { border-top: 1px solid var(--text-green); }

.credit-name {
  font-size: 18px;
  color: #fff;
  letter-spacing: 2px;
  margin-bottom: 2px;
}

.credit-role {
  font-size: 13px;
  color: var(--text-green);
  margin-bottom: 2px;
}

.credit-task {
  font-size: 12px;
  color: var(--text-dim);
}

#credits-footer {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid rgba(57, 255, 20, 0.3);
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 2px;
}

#credits-close {
  display: block;
  width: 100%;
  margin-top: 14px;
  font-family: var(--font-main);
  font-size: 14px;
  padding: 8px;
  background: rgba(57, 255, 20, 0.08);
  color: var(--text-green);
  border: 1px solid var(--text-green);
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.15s;
}

#credits-close:hover {
  background: rgba(57, 255, 20, 0.2);
  box-shadow: var(--glow-green);
}

.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 1024px) {
  #game-wrapper {
    width: 100vw;
  }
}

@media (max-width: 768px) {
  body {
    align-items: flex-start;
  }

  #game-wrapper {
    width: 100vw;
    height: 60vh;
  }

  #game-canvas {
    height: 60vh;
    width: 100vw;
    object-fit: contain;
  }

  #hud {
    font-size: 14px;
    padding: 2px 8px;
  }

  #hud-left, #hud-right {
    gap: 10px;
  }

  #hud-session {
    display: none;
  }

  #controls-legend { display: none !important; }
  #touch-controls.visible { display: flex !important; }
  #mission-text { font-size: 22px; }

  #log-export {
    top: auto;
    bottom: 42vh;
    font-size: 13px;
  }

  #export-btn {
    font-size: 13px;
    padding: 3px 10px;
  }

  /* Adjust terminal overlay for mobile */
  #terminal-content {
    width: 95%;
    max-height: 50vh;
    padding: 14px;
  }

  #terminal-header { font-size: 22px; }
  #terminal-body { font-size: 16px; }
  #terminal-footer { font-size: 14px; }

  /* Login screen mobile */
  #login-box {
    padding: 30px 24px;
  }

  #login-title {
    font-size: 36px;
  }

  #login-subtitle {
    font-size: 16px;
  }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  #game-wrapper {
    height: 100vh;
  }

  #game-canvas {
    height: 100vh;
  }

  #touch-controls.visible {
    height: 50vh;
    padding-bottom: 10px;
  }

  .touch-fire {
    width: 64px;
    height: 64px;
  }

  .touch-small {
    width: 44px;
    height: 44px;
  }

  #joystick-zone {
    width: 130px;
    height: 130px;
  }
}
