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

body {
  background: #111;
  color: #ccc;
  font-family: 'VT323', monospace;
  font-size: 16px;
  overflow-x: hidden;
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

header {
  width: 100%;
  background: #1a1a1a;
  text-align: center;
  padding: 12px 0 0 0;
}

header h1 {
  font-family: 'Press Start 2P', monospace;
  color: #fff;
  font-size: 24px;
  letter-spacing: 4px;
  text-shadow: 2px 2px 0 #333;
}

.rainbow-bar {
  height: 6px;
  background: linear-gradient(
    to right,
    #0000D7 0%, #0000D7 14.28%,
    #D70000 14.28%, #D70000 28.57%,
    #D700D7 28.57%, #D700D7 42.85%,
    #00D700 42.85%, #00D700 57.14%,
    #00D7D7 57.14%, #00D7D7 71.42%,
    #D7D700 71.42%, #D7D700 85.71%,
    #D7D7D7 85.71%, #D7D7D7 100%
  );
  width: 100%;
  margin-top: 8px;
}

#toolbar {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #1a1a1a;
  border-bottom: 1px solid #333;
}

.btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  background: #2a2a2a;
  color: #ddd;
  border: 2px solid #555;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.1s;
  user-select: none;
  white-space: nowrap;
}

.btn:hover { background: #3a3a3a; border-color: #888; }
.btn:active { background: #555; transform: scale(0.95); }
.btn.active { background: #D70000; border-color: #ff4444; color: #fff; }
.btn-sm { font-size: 8px; padding: 4px 8px; }

#file-name-display {
  font-family: 'VT323', monospace;
  color: #0f0;
  font-size: 14px;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: #aaa;
}

.speed-control select {
  font-family: 'VT323', monospace;
  font-size: 16px;
  background: #2a2a2a;
  color: #ddd;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 2px 4px;
}

#main-area {
  display: flex;
  gap: 12px;
  padding: 16px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

#tv-frame {
  background: linear-gradient(145deg, #c4b08a, #a08860);
  border-radius: 20px;
  padding: 20px;
  box-shadow:
    0 0 0 3px #8a7550,
    0 0 30px rgba(0,0,0,0.6),
    inset 0 0 20px rgba(0,0,0,0.3);
}

#canvas-wrapper {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.8);
}

#screen {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 640px;
  height: 480px;
}

#crt-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.15) 0px,
    rgba(0,0,0,0.15) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: multiply;
}

#crt-overlay.hidden { display: none; }

#debug-panel {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 12px;
  font-family: 'VT323', monospace;
  font-size: 14px;
  width: 280px;
  max-height: 480px;
  overflow-y: auto;
}

#debug-panel.hidden { display: none; }

#debug-panel h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: #0f0;
  margin: 8px 0 4px 0;
}

#debug-panel pre {
  color: #0f0;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre;
}

#debug-panel input[type="text"] {
  background: #000;
  color: #0f0;
  border: 1px solid #333;
  font-family: 'VT323', monospace;
  font-size: 14px;
  width: 50px;
  padding: 2px 4px;
}

.breakpoint-ctrl {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}

#keyboard {
  max-width: 700px;
  width: 100%;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.kb-row {
  display: flex;
  gap: 3px;
  justify-content: center;
}

.kb-key {
  width: 60px;
  height: 42px;
  background: #333;
  border: 2px solid #555;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: all 0.05s;
  position: relative;
}

.kb-key:hover { background: #444; }
.kb-key:active, .kb-key.pressed {
  background: #D70000;
  border-color: #ff4444;
  transform: scale(0.93);
}

.kb-key .main {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: #fff;
}

.kb-key .kw {
  font-family: 'VT323', monospace;
  font-size: 10px;
  color: #888;
  margin-top: 1px;
}

/* Tape Deck */
#tape-deck {
  width: 100%;
  max-width: 900px;
  background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
  border: 2px solid #444;
  border-radius: 8px;
  padding: 10px 16px;
  margin: 0 auto;
}

#tape-deck.hidden { display: none; }

.tape-deck-inner {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tape-icon {
  font-size: 28px;
  animation: tape-spin 2s linear infinite paused;
}

#tape-deck.playing .tape-icon {
  animation-play-state: running;
}

@keyframes tape-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.tape-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tape-info span {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: #0f0;
}

.tape-progress-bar {
  width: 100%;
  height: 8px;
  background: #111;
  border: 1px solid #555;
  border-radius: 4px;
  overflow: hidden;
}

.tape-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #D70000, #D700D7, #00D7D7);
  transition: width 0.3s;
  border-radius: 4px;
}

.tape-status-text {
  color: #888 !important;
  font-size: 8px !important;
}

#tape-deck.playing .tape-status-text {
  color: #0f0 !important;
}

.tape-counter {
  font-family: 'VT323', monospace;
  font-size: 24px;
  color: #D70000;
  background: #000;
  padding: 4px 8px;
  border: 1px solid #333;
  border-radius: 4px;
  min-width: 50px;
  text-align: center;
}

#tape-play-btn:not([disabled]):hover { background: #006600; border-color: #0f0; }
#tape-stop-btn:not([disabled]):hover { background: #660000; border-color: #f00; }

#status-bar {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 8px 16px;
  background: #1a1a1a;
  border-top: 1px solid #333;
  font-family: 'VT323', monospace;
  font-size: 14px;
  color: #888;
}

#status-emu { color: #0f0; }

footer {
  width: 100%;
  margin-top: auto;
  background: #1a1a1a;
}

.footer-content {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  font-family: 'VT323', monospace;
  font-size: 14px;
}

.footer-content a {
  color: #00D7D7;
  text-decoration: none;
}

.footer-content a:hover { text-decoration: underline; }

.berry-badge {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #ff6b9d;
}

.disclaimer { color: #555; font-size: 12px; }

@media (max-width: 700px) {
  #screen { width: 320px; height: 240px; }
  #tv-frame { padding: 10px; border-radius: 12px; }
  .kb-key { width: 30px; height: 34px; }
  .kb-key .main { font-size: 7px; }
  .kb-key .kw { display: none; }
  header h1 { font-size: 14px; }
  #toolbar { font-size: 9px; }
  #debug-panel { width: 100%; }
}