/* CSS Variables for theming - Midnight Code Theme */
:root {
  --neon-green: #61afef; /* Soft Blue - Primary text */
  --electric-blue: #98c379; /* Sage Green - Secondary */
  --magenta: #c678dd; /* Soft Purple - Accent */
  --black: #282c34; /* Deep Blue-Gray - Background */
  --dark-gray: #21252b; /* Slightly lighter background for sections */
  --white: #ffffff;
  --font-family: 'Courier New', 'Fira Code', monospace;
  --transition: all 0.3s ease;
}

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background-color: var(--black);
  color: var(--white);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Canvas Backgrounds */
#matrix, #starfield {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#matrix {
  z-index: 1;
}

#starfield {
  z-index: 2;
}

#matrix.hidden,
#starfield.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Background Toggle Button */
.bg-toggle-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
}

#bg-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  font-family: var(--font-family);
  font-size: 0.9rem;
  background: rgba(0, 0, 0, 0.8);
  color: var(--neon-green);
  border: 1px solid var(--neon-green);
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
  backdrop-filter: blur(10px);
}

#bg-toggle:hover {
  background: var(--neon-green);
  color: var(--black);
  box-shadow: 0 0 15px var(--neon-green);
  transform: translateY(-2px);
}

#bg-toggle .toggle-icon {
  font-size: 1.2rem;
}

@media (max-width: 640px) {
  .bg-toggle-container {
    top: 10px;
    right: 10px;
  }

  #bg-toggle {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }
}

/* CRT Overlay */
.crt-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 255, 65, 0.03) 2px,
    rgba(0, 255, 65, 0.03) 4px
  );
  animation: scanline 0.1s linear infinite;
}

@keyframes scanline {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100vh); }
}

/* Main Content */
main {
  position: relative;
  z-index: 10;
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

section {
  margin-bottom: 4rem;
  padding: 2rem;
  border: 1px solid var(--neon-green);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
}


/* Glitch Animation */
@keyframes glitch {
  0%, 100% { transform: translate(0); }
  20% { transform: translate(-2px, 2px); }
  40% { transform: translate(-2px, -2px); }
  60% { transform: translate(2px, 2px); }
  80% { transform: translate(2px, -2px); }
}

@keyframes glow {
  from { text-shadow: 0 0 20px var(--neon-green); }
  to { text-shadow: 0 0 30px var(--neon-green), 0 0 40px var(--neon-green); }
}

/* Story Section */
.story h2 {
  color: var(--electric-blue);
  margin-bottom: 1rem;
  font-size: 2rem;
}

.story p {
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

/* Decoder Section */
.decoder h2 {
  color: var(--magenta);
  margin-bottom: 1rem;
  font-size: 2rem;
}

.decoder-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 600px;
  margin: 0 auto;
}

#decoder-input {
  padding: 1rem;
  font-family: var(--font-family);
  font-size: 1.1rem;
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid var(--neon-green);
  border-radius: 4px;
  color: var(--white);
  transition: var(--transition);
}

#decoder-input:focus {
  outline: none;
  border-color: var(--electric-blue);
  box-shadow: 0 0 10px var(--electric-blue);
}

.toggle-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  font-size: 1.1rem;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--dark-gray);
  transition: var(--transition);
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: var(--white);
  transition: var(--transition);
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--neon-green);
}

input:checked + .slider:before {
  transform: translateX(26px);
}

.output-container {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#decoder-output {
  padding: 1rem;
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid var(--electric-blue);
  border-radius: 4px;
  font-family: var(--font-family);
  font-size: 1.1rem;
  min-height: 3rem;
  white-space: pre-wrap;
}

#copy-btn {
  min-width: 90px;
  width: fit-content;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-family);
  font-size: 0.9rem;
  background: var(--dark-gray);
  color: var(--white);
  border: 1px solid var(--electric-blue);
  border-radius: 4px;
  cursor: pointer;
  transition: min-width 0.3s ease;
  opacity: 0.7;
  text-align: center;
  white-space: nowrap;
  align-self: flex-end;
}

#copy-btn:hover {
  background: var(--electric-blue);
  opacity: 1;
  box-shadow: 0 0 10px var(--electric-blue);
}

#copy-btn.copied {
  min-width: 115px;
}

/* Next Section */
.next h2 {
  color: var(--magenta);
  margin-bottom: 1rem;
  font-size: 2rem;
}

.next ul {
  list-style: none;
  padding-left: 1rem;
}

.next li {
  margin-bottom: 0.5rem;
  position: relative;
}

.next li:before {
  content: "•";
  color: var(--neon-green);
  position: absolute;
  left: -1rem;
}

/* Footer */
footer {
  position: relative;
  z-index: 10;
  text-align: center;
  padding: 2rem;
  border-top: 1px solid var(--neon-green);
  background: rgba(0, 0, 0, 0.8);
}

#binary-hint {
  font-size: 0.9rem;
  color: var(--dark-gray);
  cursor: pointer;
  transition: var(--transition);
  margin-top: 1rem;
}

#binary-hint:hover {
  color: var(--neon-green);
}

/* Responsive Design */
@media (max-width: 1024px) {
}

/* Tablet and Mobile Styles */
@media (max-width: 1024px) {
  main {
    padding: 1rem;
  }
  section {
    padding: 1.25rem;
    margin-bottom: 2rem;
  }
}

/* Mobile Styles */
@media (max-width: 640px) {
  main {
    padding: 0.5rem;
  }
  section {
    padding: 0.75rem;
    margin-bottom: 1rem;
  }
  .story h2 {
    font-size: 1.5rem;
  }
  .decoder h2 {
    font-size: 1.5rem;
  }
  .decoder-container {
    gap: 0.5rem;
  }
  #decoder-input, #decoder-output {
    font-size: 1rem;
    padding: 0.6rem;
  }
  .toggle-container {
    font-size: 0.9rem;
  }
  .output-container {
    flex-direction: column;
    align-items: stretch;
  }
  #copy-btn {
    align-self: flex-end;
    width: fit-content;
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
  }
}

/* Compact toggle for smaller screens */
@media (max-width: 768px) {
  /* Hide toggle text on smaller screens, show only emoji */
  #bg-toggle .toggle-text {
    display: none;
  }
  #bg-toggle {
    padding: 0.5rem;
    min-width: auto;
  }
  #bg-toggle .toggle-icon {
    font-size: 1.5rem;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .crt-overlay {
    display: none;
  }
}

@media (prefers-contrast: high) {
  :root {
    --neon-green: #00ff00;
    --electric-blue: #ffffff;
    --magenta: #ff00ff;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  body {
    background-color: var(--black);
    color: var(--white);
  }
  section {
    border-color: var(--white);
  }
}