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

:root {
  --bg: #0a0a1a;
  --bg2: #12122a;
  --text: #c8c8d0;
  --text-dim: #6a6a80;
  --accent: #d70000;
  --border-col: #2a2a4a;
  --rainbow-1: #d70000;
  --rainbow-2: #d76800;
  --rainbow-3: #d7d700;
  --rainbow-4: #00d700;
  --rainbow-5: #00d7d7;
  --rainbow-6: #0000d7;
}

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

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px;
}

/* Header */
#header {
  text-align: center;
  padding: 8px 0;
}

.title {
  font-family: 'Press Start 2P', cursive;
  font-size: 18px;
  color: #fff;
  margin: 6px 0 2px;
  letter-spacing: 1px;
}

.subtitle {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.rainbow-bar {
  height: 4px;
  background: linear-gradient(90deg,
    var(--rainbow-1) 0%, var(--rainbow-1) 16.6%,
    var(--rainbow-2) 16.6%, var(--rainbow-2) 33.2%,
    var(--rainbow-3) 33.2%, var(--rainbow-3) 49.8%,
    var(--rainbow-4) 49.8%, var(--rainbow-4) 66.4%,
    var(--rainbow-5) 66.4%, var(--rainbow-5) 83%,
    var(--rainbow-6) 83%, var(--rainbow-6) 100%
  );
  border-radius: 2px;
}

/* Screen */
#screen-wrapper {
  display: flex;
  justify-content: center;
  padding: 8px 0;
}

#crt-bezel {
  position: relative;
  border-radius: 12px;
  background: #111;
  padding: 8px;
  box-shadow:
    0 0 30px rgba(0,0,0,0.8),
    inset 0 0 20px rgba(0,0,0,0.5),
    0 0 60px rgba(50,50,120,0.15);
  border: 2px solid #222;
}

#canvas {
  display: block;
  width: 640px;
  height: 480px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 4px;
}

#scanline-overlay {
  position: absolute;
  top: 8px; left: 8px; right: 8px; bottom: 8px;
  border-radius: 4px;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 1px,
    rgba(0,0,0,0.15) 1px,
    rgba(0,0,0,0.15) 2px
  );
  opacity: 0;
  transition: opacity 0.3s;
}

#scanline-overlay.active {
  opacity: 1;
}

#drop-overlay {
  position: absolute;
  top: 8px; left: 8px; right: 8px; bottom: 8px;
  background: rgba(0, 0, 50, 0.85);
  border: 3px dashed #fff;
  border-radius: 4px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#drop-overlay.active {
  display: flex;
}

.drop-text {
  font-family: 'Press Start 2P', cursive;
  font-size: 16px;
  color: #fff;
  text-shadow:
    2px 0 var(--rainbow-1),
    4px 0 var(--rainbow-2),
    6px 0 var(--rainbow-3),
    8px 0 var(--rainbow-4);
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

/* Controls */
#controls {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px 0;
}

#controls button {
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  background: linear-gradient(180deg, #3a3a5a 0%, #2a2a4a 100%);
  color: var(--text);
  border: 1px solid #4a4a6a;
  border-radius: 4px;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  box-shadow: 0 2px 0 #1a1a2a;
}

#controls button:hover {
  background: linear-gradient(180deg, #4a4a6a 0%, #3a3a5a 100%);
  border-color: #6a6a8a;
}

#controls button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #1a1a2a;
}

#controls button.active-btn {
  background: linear-gradient(180deg, #2a5a2a 0%, #1a4a1a 100%);
  border-color: #4a8a4a;
}

.btn-icon { font-style: normal; }

#speed-indicator {
  font-size: 10px;
  color: #0f0;
  padding: 4px 8px;
  background: #0a0a0a;
  border-radius: 3px;
  border: 1px solid #1a1a2a;
  min-width: 70px;
  text-align: center;
}

/* Status bar */
#status-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 6px;
  background: var(--bg2);
  border: 1px solid var(--border-col);
  border-radius: 4px;
  font-size: 10px;
  color: var(--text-dim);
}

#status-bar span {
  white-space: nowrap;
}

#border-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1px solid #444;
  vertical-align: middle;
  border-radius: 2px;
}

/* Keyboard */
#keyboard-section {
  margin-top: 8px;
}

.kb-toggle {
  font-family: 'Press Start 2P', cursive;
  font-size: 9px;
  background: var(--bg2);
  color: var(--text-dim);
  border: 1px solid var(--border-col);
  width: 100%;
  padding: 6px;
  cursor: pointer;
  border-radius: 4px 4px 0 0;
  text-align: center;
}

.kb-toggle:hover { color: var(--text); }

#keyboard-container {
  background: var(--bg2);
  border: 1px solid var(--border-col);
  border-top: none;
  border-radius: 0 0 4px 4px;
  padding: 8px;
  overflow: hidden;
  transition: max-height 0.3s, padding 0.3s;
  max-height: 300px;
}

#keyboard-container.collapsed {
  max-height: 0;
  padding: 0 8px;
}

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

.kb-key {
  font-family: 'Press Start 2P', cursive;
  font-size: 7px;
  min-width: 42px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #3a3a3a 0%, #2a2a2a 100%);
  color: #ccc;
  border: 1px solid #555;
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 0 #111;
  transition: all 0.1s;
  text-align: center;
  line-height: 1.2;
  padding: 2px;
}

.kb-key:hover {
  background: linear-gradient(180deg, #4a4a4a 0%, #3a3a3a 100%);
}

.kb-key.pressed {
  background: linear-gradient(180deg, #d70000 0%, #a00 100%);
  color: #fff;
  transform: translateY(1px);
  box-shadow: 0 1px 0 #111;
}

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

/* Footer */
#footer {
  text-align: center;
  padding: 12px;
  font-size: 9px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
}

#footer a {
  color: var(--rainbow-5);
  text-decoration: none;
}

#footer a:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 700px) {
  #canvas {
    width: 320px;
    height: 240px;
  }
  .title { font-size: 12px; }
  #status-bar { font-size: 8px; gap: 4px; }
  #controls button { font-size: 7px; padding: 6px 8px; }
  .kb-key { font-size: 5px; min-width: 28px; height: 24px; }
  .kb-key.wide { min-width: 44px; }
  .kb-key.extra-wide { min-width: 60px; }
  #keyboard-container.collapsed { max-height: 0; }
  .drop-text { font-size: 10px; }
}