@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

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

:root {
  --nes-gray-dark: #3a3a3a;
  --nes-gray: #8B8B8B;
  --nes-gray-light: #BCBCBC;
  --nes-red: #CC0000;
  --nes-red-dark: #8B0000;
  --bg-dark: #1a1a1a;
  --bg-darker: #0d0d0d;
  --green-glow: #00ff00;
  --text-primary: #e0e0e0;
}

body {
  font-family: 'VT323', monospace;
  background: var(--bg-darker);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

body.light-mode {
  --bg-dark: #c0c0c0;
  --bg-darker: #a0a0a0;
  --text-primary: #1a1a1a;
}

.hidden {
  display: none !important;
}

/* Boot Screen */
#boot-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s;
}

#boot-screen.fade-out {
  opacity: 0;
}

.boot-content {
  text-align: center;
}

.boot-logo {
  font-size: 4rem;
  animation: pulse 1s infinite;
}

.boot-text {
  font-family: 'Press Start 2P', cursive;
  font-size: 1rem;
  color: var(--green-glow);
  margin: 1rem 0;
  animation: blink 0.5s infinite;
}

.boot-bar {
  width: 200px;
  height: 10px;
  background: #333;
  border: 2px solid #555;
  margin: 0 auto;
}

.boot-progress {
  height: 100%;
  background: var(--green-glow);
  animation: loadProgress 2s forwards;
}

@keyframes loadProgress {
  from { width: 0; }
  to { width: 100%; }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

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

.fade-in {
  animation: fadeIn 0.5s forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Header */
#header {
  background: linear-gradient(180deg, var(--nes-gray) 0%, var(--nes-gray-dark) 100%);
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  border-bottom: 4px solid var(--nes-red);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.power-led {
  width: 12px;
  height: 12px;
  background: var(--nes-red);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--nes-red), 0 0 20px var(--nes-red);
  animation: ledPulse 2s infinite;
}

@keyframes ledPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 10px var(--nes-red), 0 0 20px var(--nes-red); }
  50% { opacity: 0.7; box-shadow: 0 0 5px var(--nes-red); }
}

#header h1 {
  font-family: 'Press Start 2P', cursive;
  font-size: clamp(0.6rem, 2.5vw, 1.2rem);
  color: #fff;
  text-shadow: 2px 2px 0 var(--nes-red-dark), 4px 4px 0 #000;
  letter-spacing: 2px;
}

.header-controls {
  position: absolute;
  right: 1rem;
}

#theme-toggle {
  background: var(--nes-gray-dark);
  border: 3px solid #555;
  border-radius: 4px;
  padding: 0.5rem;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.2s;
}

#theme-toggle:hover {
  transform: scale(1.1);
}

/* Main App */
#app {
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  gap: 1.5rem;
}

section {
  background: var(--bg-dark);
  border: 3px solid var(--nes-gray-dark);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3), 0 4px 10px rgba(0, 0, 0, 0.5);
}

section h2 {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.7rem;
  color: var(--nes-red);
  margin-bottom: 1rem;
  text-align: center;
  text-transform: uppercase;
}

/* Chip Section */
#chip-section {
  display: flex;
  justify-content: center;
}

#chip-visual {
  position: relative;
}

#chip-canvas {
  border: 2px solid var(--nes-gray-dark);
  border-radius: 4px;
}

.chip-info {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1rem;
  font-family: 'Press Start 2P', cursive;
  font-size: 0.5rem;
  color: var(--nes-gray-light);
}

/* Channels */
#channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.channel {
  background: linear-gradient(180deg, #2a2a2a 0%, #1a1a1a 100%);
  border: 3px solid var(--nes-gray-dark);
  border-radius: 8px;
  padding: 1rem;
  transition: all 0.3s;
}

.channel:hover {
  border-color: var(--nes-red);
  box-shadow: 0 0 15px rgba(204, 0, 0, 0.3);
}

.channel-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--nes-gray-dark);
}

.channel-name {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.6rem;
  color: var(--nes-gray-light);
  flex: 1;
}

.channel-led {
  width: 10px;
  height: 10px;
  background: #333;
  border-radius: 50%;
  border: 2px solid #555;
  transition: all 0.3s;
}

.channel-led.active {
  background: var(--green-glow);
  box-shadow: 0 0 10px var(--green-glow);
}

/* Toggle Switch */
.switch {
  position: relative;
  width: 50px;
  height: 24px;
}

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

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #333;
  border: 2px solid #555;
  border-radius: 4px;
  transition: 0.3s;
}

.switch .slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background: var(--nes-gray);
  border-radius: 2px;
  transition: 0.3s;
}

.switch input:checked + .slider {
  background: var(--nes-red-dark);
}

.switch input:checked + .slider:before {
  transform: translateX(22px);
  background: var(--nes-red);
}

/* Channel Controls */
.channel-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.duty-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.duty-selector span {
  font-size: 0.8rem;
  color: var(--nes-gray);
  min-width: 50px;
}

.duty-buttons {
  display: flex;
  gap: 4px;
}

.duty-buttons button {
  font-family: 'VT323', monospace;
  font-size: 0.8rem;
  padding: 4px 8px;
  background: var(--nes-gray-dark);
  border: 2px solid #555;
  color: var(--nes-gray-light);
  cursor: pointer;
  transition: all 0.2s;
}

.duty-buttons button:hover {
  background: var(--nes-gray);
}

.duty-buttons button.active {
  background: var(--nes-red);
  border-color: var(--nes-red-dark);
  color: #fff;
}

.slider-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.slider-control span {
  font-size: 0.8rem;
  color: var(--nes-gray);
  min-width: 50px;
}

.slider-control input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 8px;
  background: linear-gradient(90deg, #333, #555);
  border-radius: 4px;
  outline: none;
}

.slider-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 24px;
  background: linear-gradient(180deg, var(--nes-gray-light), var(--nes-gray));
  border: 2px solid #555;
  border-radius: 2px;
  cursor: pointer;
}

.freq-value {
  font-size: 0.75rem;
  color: var(--green-glow);
  min-width: 60px;
  text-align: right;
}

.wave-display {
  width: 100%;
  height: 60px;
  background: #0a0a0a;
  border: 2px solid var(--nes-gray-dark);
  border-radius: 4px;
  margin-top: 0.5rem;
}

/* DMC Channel */
.dmc-channel {
  display: flex;
  flex-direction: column;
}

.dmc-info {
  text-align: center;
  padding: 1rem;
  color: var(--nes-gray);
}

.dmc-indicator {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.5rem;
  margin-top: 0.5rem;
  color: var(--nes-red);
}

/* Oscilloscope */
#oscilloscope-section {
  position: relative;
}

.scope-container {
  position: relative;
  width: 100%;
  height: 200px;
  background: #001100;
  border: 4px solid var(--nes-gray-dark);
  border-radius: 8px;
  overflow: hidden;
}

#oscilloscope {
  width: 100%;
  height: 100%;
}

.scope-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: 
    repeating-linear-gradient(
      transparent,
      transparent 2px,
      rgba(0, 0, 0, 0.1) 2px,
      rgba(0, 0, 0, 0.1) 4px
    );
  border-radius: 8px;
}

/* Presets */
#preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.preset-btn {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.6rem;
  padding: 1rem 1.5rem;
  background: linear-gradient(180deg, var(--nes-gray) 0%, var(--nes-gray-dark) 100%);
  border: 3px solid #555;
  border-bottom-width: 5px;
  color: #fff;
  cursor: pointer;
  transition: all 0.1s;
  text-shadow: 1px 1px 0 #000;
}

.preset-btn:hover {
  background: linear-gradient(180deg, var(--nes-red) 0%, var(--nes-red-dark) 100%);
}

.preset-btn:active,
.preset-btn.pressed {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

/* PPU Section */
.ppu-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

#ppu-canvas {
  border: 4px solid var(--nes-gray-dark);
  border-radius: 4px;
  image-rendering: pixelated;
  max-width: 100%;
  height: auto;
}

.ppu-info {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.5rem;
  color: var(--nes-gray);
}

/* Keyboard Section */
#keyboard-display {
  display: flex;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
}

.key {
  width: 50px;
  height: 60px;
  background: linear-gradient(180deg, #fff 0%, #ddd 100%);
  border: 3px solid #999;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', cursive;
  font-size: 0.5rem;
  color: #333;
  cursor: pointer;
  transition: all 0.1s;
  user-select: none;
}

.key:hover {
  background: linear-gradient(180deg, #eee 0%, #ccc 100%);
}

.key.active {
  background: linear-gradient(180deg, var(--nes-red) 0%, var(--nes-red-dark) 100%);
  color: #fff;
  transform: translateY(2px);
}

/* Info Ticker */
#info-section {
  overflow: hidden;
  padding: 0.5rem 0;
}

#info-ticker {
  white-space: nowrap;
  animation: ticker 30s linear infinite;
}

.ticker-content {
  display: inline-block;
}

.ticker-content span {
  margin-right: 3rem;
  font-size: 1rem;
  color: var(--nes-gray-light);
}

@keyframes ticker {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

/* Footer */
#footer {
  background: var(--nes-gray-dark);
  padding: 1rem;
  border-top: 4px solid var(--nes-red);
  position: relative;
  overflow: hidden;
}

.footer-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.pixel-text {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.6rem;
  color: var(--nes-gray-light);
}

.berrry-link {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.6rem;
  color: var(--nes-red);
  text-decoration: none;
  transition: all 0.3s;
}

.berrry-link:hover {
  color: #fff;
  text-shadow: 0 0 10px var(--nes-red);
}

#walking-sprite {
  position: absolute;
  bottom: 10px;
  left: 0;
  width: 16px;
  height: 16px;
  background: var(--nes-red);
  border-radius: 2px;
}

#walking-sprite::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 4px;
  width: 8px;
  height: 8px;
  background: #fff;
  border-radius: 50%;
}

/* Konami Flash */
.konami-flash {
  animation: flashEffect 0.5s;
}

@keyframes flashEffect {
  0%, 100% { filter: none; }
  25%, 75% { filter: invert(1); }
  50% { filter: hue-rotate(180deg); }
}

/* Responsive */
@media (max-width: 768px) {
  #header h1 {
    font-size: 0.5rem;
  }
  
  .header-controls {
    position: static;
  }
  
  #header {
    flex-wrap: wrap;
  }
  
  #channels-grid {
    grid-template-columns: 1fr;
  }
  
  .preset-btn {
    padding: 0.75rem 1rem;
    font-size: 0.5rem;
  }
  
  .key {
    width: 35px;
    height: 45px;
    font-size: 0.4rem;
  }
  
  .scope-container {
    height: 150px;
  }
}

/* Scan line overlay for CRT effect */
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: repeating-linear-gradient(
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
  z-index: 9998;
}