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

body {
  background: #0a0a1a;
  background-image: 
    radial-gradient(ellipse at 50% 0%, #1a1a3e 0%, #0a0a1a 70%);
  color: #e0e0e0;
  font-family: 'VT323', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

#app {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 10px;
}

/* ROM Loader */
#rom-loader {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 90vh;
}

.loader-content {
  text-align: center;
  width: 100%;
  max-width: 700px;
}

#ascii-logo {
  font-family: monospace;
  font-size: 5px;
  line-height: 1.1;
  color: #85d4dc;
  white-space: pre;
  overflow: hidden;
  margin-bottom: 10px;
  text-shadow: 0 0 10px #85d4dc44;
}

@media (max-width: 600px) {
  #ascii-logo { font-size: 3px; }
}

.loader-content h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 32px;
  color: #c5ffff;
  text-shadow: 0 0 20px #85d4dc88, 0 0 40px #85d4dc44;
  margin-bottom: 5px;
}

.subtitle {
  font-size: 18px;
  color: #7e70ca;
  letter-spacing: 4px;
  margin-bottom: 30px;
}

.rom-slots {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 30px;
}

.rom-slot {
  background: #12122a;
  border: 1px solid #2a2a5a;
  border-radius: 8px;
  padding: 15px;
  transition: border-color 0.3s;
}

.rom-slot.loaded {
  border-color: #559e4a;
  background: #0f1f0f;
}

.rom-slot label {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 15px;
  cursor: pointer;
}

.rom-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: #bdcc71;
  min-width: 120px;
}

.rom-file {
  font-size: 16px;
  color: #7e70ca;
  flex: 1;
  min-width: 200px;
}

.rom-addr {
  font-size: 14px;
  color: #559e4a;
}

.rom-slot input[type="file"] {
  display: none;
}

.rom-status {
  font-size: 14px;
  color: #a85fb4;
  width: 100%;
  text-align: center;
  margin-top: 5px;
}

.rom-slot.loaded .rom-status {
  color: #92df87;
}

#btn-power-on {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  padding: 18px 40px;
  background: linear-gradient(180deg, #772d26 0%, #3d1510 100%);
  color: #555;
  border: 3px solid #4a1a15;
  border-radius: 12px;
  cursor: not-allowed;
  transition: all 0.3s;
  text-shadow: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

#btn-power-on:not(:disabled) {
  background: linear-gradient(180deg, #559e4a 0%, #2a5022 100%);
  color: #c5ffff;
  border-color: #92df87;
  cursor: pointer;
  text-shadow: 0 0 10px #92df8788;
  box-shadow: 0 0 20px #559e4a44;
  animation: pulse-glow 2s infinite;
}

#btn-power-on:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: 0 0 30px #559e4a88;
}

#btn-power-on:not(:disabled):active {
  transform: scale(0.98);
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 20px #559e4a44; }
  50% { box-shadow: 0 0 30px #559e4a88; }
}

.power-icon {
  font-size: 22px;
}

.hint {
  font-size: 14px;
  color: #555;
  margin-top: 12px;
}

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #1a1a2e;
  border: 1px solid #2a2a4a;
  border-radius: 8px 8px 0 0;
  flex-wrap: wrap;
}

#toolbar button {
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 6px 14px;
  background: #2a2a4a;
  color: #c5ffff;
  border: 1px solid #3a3a6a;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

#toolbar button:hover {
  background: #3a3a6a;
}

#toolbar button:active {
  transform: scale(0.95);
}

#status-bar {
  font-size: 14px;
  color: #559e4a;
  flex: 1;
  text-align: center;
}

/* Monitor */
#monitor-bezel {
  background: #1c1c1c;
  border: 3px solid #333;
  border-top: none;
  border-radius: 0 0 12px 12px;
  padding: 20px;
  box-shadow: 
    0 0 40px #00000088,
    inset 0 0 60px #00000044;
}

#monitor-inner {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 
    0 0 20px #85d4dc22,
    inset 0 0 30px #00000088;
}

#canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

#scanlines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
}

#monitor-label {
  text-align: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: #555;
  margin-top: 10px;
  letter-spacing: 3px;
}

/* Keyboard */
#keyboard-container {
  margin-top: 15px;
  padding: 15px;
  background: #2a2520;
  border-radius: 12px;
  border: 2px solid #3d3327;
  box-shadow: 0 4px 20px #00000066;
}

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 4px;
  user-select: none;
  -webkit-user-select: none;
}

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

.kb-key {
  font-family: 'VT323', monospace;
  font-size: 13px;
  min-width: 36px;
  height: 36px;
  padding: 2px 4px;
  background: linear-gradient(180deg, #4a4038 0%, #3d3327 50%, #332a20 100%);
  color: #e8e0d0;
  border: 1px solid #5a5040;
  border-bottom: 3px solid #1a1510;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.1;
  transition: all 0.05s;
  flex-shrink: 0;
}

.kb-key:hover {
  background: linear-gradient(180deg, #5a5048 0%, #4d4337 50%, #433a30 100%);
}

.kb-key:active, .kb-key.pressed {
  background: linear-gradient(180deg, #332a20 0%, #3d3327 50%, #4a4038 100%);
  border-bottom: 1px solid #1a1510;
  border-top: 3px solid #1a1510;
  transform: translateY(2px);
}

.kb-key.modifier {
  background: linear-gradient(180deg, #3a3530 0%, #2d2820 50%, #221e18 100%);
  color: #bdcc71;
  border-color: #4a4530;
}

.kb-key.modifier:hover {
  background: linear-gradient(180deg, #4a4540 0%, #3d3830 50%, #322e28 100%);
}

.kb-key.modifier.active {
  background: linear-gradient(180deg, #559e4a 0%, #3a7030 100%);
  color: #fff;
  border-color: #92df87;
}

.kb-key.fn-key {
  background: linear-gradient(180deg, #42348b 0%, #2a2060 100%);
  color: #c5ffff;
  border-color: #5a4aaa;
  height: 36px;
}

.kb-key.fn-key:hover {
  background: linear-gradient(180deg, #5244ab 0%, #3a3080 100%);
}

.kb-key.space-key {
  flex: 1;
  min-width: 200px;
}

.kb-key.return-key {
  min-width: 70px;
}

.kb-key.wide {
  min-width: 56px;
}

.kb-key.extra-wide {
  min-width: 70px;
}

/* Storage Panel */
#storage-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.storage-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000000aa;
}

.storage-content {
  position: relative;
  background: #12122a;
  border: 2px solid #3a3a6a;
  border-radius: 12px;
  padding: 25px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.storage-content h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: #c5ffff;
  margin-bottom: 20px;
  text-align: center;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: #777;
  font-size: 24px;
  cursor: pointer;
}

.close-btn:hover {
  color: #fff;
}

.storage-section {
  margin-bottom: 25px;
  padding: 15px;
  background: #1a1a3a;
  border-radius: 8px;
  border: 1px solid #2a2a5a;
}

.storage-section h3 {
  font-family: 'VT323', monospace;
  font-size: 20px;
  color: #bdcc71;
  margin-bottom: 12px;
}

.drive-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.file-btn {
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 8px 14px;
  background: #2a2a5a;
  color: #c5ffff;
  border: 1px solid #3a3a7a;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
}

.file-btn:hover {
  background: #3a3a7a;
}

.file-btn input {
  display: none;
}

.file-name {
  font-size: 14px;
  color: #7e70ca;
  flex: 1;
  min-width: 100px;
}

.drive-controls button {
  font-family: 'VT323', monospace;
  font-size: 16px;
  padding: 6px 12px;
  background: #2a2a4a;
  color: #c5ffff;
  border: 1px solid #3a3a6a;
  border-radius: 4px;
  cursor: pointer;
}

.drive-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tape-controls {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  justify-content: center;
}

.tape-controls button {
  font-family: 'VT323', monospace;
  font-size: 22px;
  width: 44px;
  height: 40px;
  background: #2a2a4a;
  color: #c5ffff;
  border: 1px solid #3a3a6a;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tape-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tape-controls button:hover:not(:disabled) {
  background: #3a3a6a;
}

/* Cassette visual */
.cassette-visual {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.cassette-body {
  width: 200px;
  height: 80px;
  background: linear-gradient(180deg, #4a4540, #3a3530);
  border-radius: 8px;
  border: 2px solid #5a5040;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 30px;
  position: relative;
}

.reel {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid #8a7a60;
  background: #2a2520;
  position: relative;
}

.reel::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  background: #5a5040;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.cassette-body.playing .reel {
  animation: spin-reel 1s linear infinite;
}

@keyframes spin-reel {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.tape-window {
  width: 60px;
  height: 20px;
  background: #1a1510;
  border-radius: 3px;
  border: 1px solid #5a5040;
}

/* Footer */
footer {
  margin-top: 30px;
  padding: 15px;
  text-align: center;
}

footer a {
  font-family: 'VT323', monospace;
  font-size: 16px;
  color: #42348b;
  text-decoration: none;
  transition: color 0.2s;
}

footer a:hover {
  color: #7e70ca;
}

@media (max-width: 700px) {
  #keyboard-container {
    padding: 8px;
  }
  .kb-key {
    min-width: 24px;
    height: 30px;
    font-size: 10px;
  }
  .kb-key.wide {
    min-width: 38px;
  }
  .kb-key.extra-wide {
    min-width: 48px;
  }
  .kb-key.return-key {
    min-width: 48px;
  }
  #monitor-bezel {
    padding: 10px;
  }
}