:root {
  --bg-primary: #0F0F23;
  --bg-panel: #1A1A2E;
  --bg-panel-dark: #141428;
  --border: #2D2D44;
  --border-light: #3D3D5C;
  --cyan: #00D4FF;
  --magenta: #FF00AA;
  --green: #39FF14;
  --amber: #FFB800;
  --red: #FF3E3E;
  --purple: #A855F7;
  --blue: #3B82F6;
  --orange: #F97316;
  --text-primary: #E2E8F0;
  --text-secondary: #94A3B8;
}

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

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

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-panel-dark); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--cyan); }

/* CRT Effect Overlay */
.crt-overlay {
  pointer-events: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
}

/* Block styles */
.block-item {
  cursor: grab;
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.block-item:hover {
  transform: translateY(-1px);
  filter: brightness(1.15);
}

.block-item:active {
  cursor: grabbing;
}

.block-item.dragging {
  opacity: 0.85;
  transform: scale(1.05) rotate(1deg);
  z-index: 1000;
  filter: brightness(1.2);
}

/* Block connector notch (top) */
.block-connector-top::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 20px;
  width: 20px;
  height: 6px;
  background: inherit;
  border-radius: 3px 3px 0 0;
}

/* Block connector bump (bottom) */
.block-connector-bottom::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 20px;
  width: 20px;
  height: 6px;
  background: inherit;
  border-radius: 0 0 3px 3px;
}

/* Snap animation */
@keyframes blockSnap {
  0% { transform: scale(1.06); }
  50% { transform: scale(0.97); }
  100% { transform: scale(1); }
}

.block-snapped {
  animation: blockSnap 0.25s ease;
}

/* Glow pulse for entry blocks */
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(0, 212, 255, 0.3); }
  50% { box-shadow: 0 0 20px rgba(0, 212, 255, 0.6); }
}

.entry-block {
  animation: glowPulse 2.5s ease-in-out infinite;
}

/* Workspace grid */
.workspace-grid {
  background-image: 
    radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* Code preview terminal */
.code-terminal {
  background: #0a0a1a;
  border: 1px solid var(--border);
  font-family: 'Fira Code', monospace;
  font-size: 11px;
  line-height: 1.6;
}

.code-line-number {
  color: var(--border-light);
  min-width: 32px;
  text-align: right;
  padding-right: 12px;
  user-select: none;
}

.code-keyword { color: var(--magenta); }
.code-instruction { color: var(--cyan); }
.code-register { color: var(--amber); }
.code-number { color: var(--green); }
.code-comment { color: #4a6a4a; font-style: italic; }
.code-label { color: var(--amber); font-weight: 600; }

/* Console log */
.console-panel {
  background: #080812;
  border-top: 2px solid var(--border);
  font-family: 'Fira Code', monospace;
  font-size: 11px;
}

.console-panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(0, 212, 255, 0.015) 3px,
    rgba(0, 212, 255, 0.015) 6px
  );
  pointer-events: none;
}

/* Pixel button style */
.pixel-btn {
  font-family: 'Press Start 2P', cursive;
  font-size: 8px;
  padding: 8px 12px;
  border: 2px solid;
  position: relative;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.1s ease;
  cursor: pointer;
}

.pixel-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.2);
}

.pixel-btn:active {
  transform: translateY(1px);
}

/* Category accordion */
.category-header {
  cursor: pointer;
  transition: background 0.15s ease;
}

.category-header:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Tile grid */
.tile-cell {
  image-rendering: pixelated;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s;
}

.tile-cell:hover {
  border-color: var(--cyan);
}

.tile-cell.selected {
  border-color: var(--cyan);
  box-shadow: 0 0 6px var(--cyan);
}

/* NES palette color cell */
.pal-color {
  width: 16px;
  height: 16px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.1);
  transition: transform 0.1s;
}

.pal-color:hover {
  transform: scale(1.4);
  z-index: 10;
  border-color: white;
}

/* Modal overlay */
.modal-overlay {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

/* Tab styles */
.tab-btn {
  font-family: 'Press Start 2P', cursive;
  font-size: 7px;
  padding: 6px 10px;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  cursor: pointer;
  color: var(--text-secondary);
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--cyan);
  border-bottom-color: var(--cyan);
}

/* Workspace block on canvas */
.workspace-block {
  position: absolute;
  cursor: grab;
  transition: box-shadow 0.15s;
}

.workspace-block:hover {
  z-index: 100;
}

.workspace-block.is-dragging {
  cursor: grabbing;
  z-index: 1000;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Right-click context menu */
.context-menu {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  min-width: 160px;
}

.context-menu-item {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 11px;
  transition: background 0.1s;
}

.context-menu-item:hover {
  background: rgba(0, 212, 255, 0.15);
  color: var(--cyan);
}

/* Press Start 2P headings */
.retro-heading {
  font-family: 'Press Start 2P', cursive;
}

/* Footer */
.app-footer {
  background: var(--bg-panel-dark);
  border-top: 1px solid var(--border);
}

.app-footer a {
  color: var(--cyan);
  text-decoration: none;
  font-family: 'Press Start 2P', cursive;
  font-size: 7px;
  border: 1px solid var(--cyan);
  padding: 4px 8px;
  transition: all 0.15s;
}

.app-footer a:hover {
  background: var(--cyan);
  color: var(--bg-primary);
}

/* Spinning cartridge loader */
@keyframes spinCartridge {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(360deg); }
}

.spin-cartridge {
  animation: spinCartridge 1s linear infinite;
  display: inline-block;
  font-size: 48px;
}

/* Drop zone highlight */
.workspace-drop-active {
  background: rgba(0, 212, 255, 0.05) !important;
  outline: 2px dashed var(--cyan);
  outline-offset: -4px;
}

/* Responsive */
@media (max-width: 768px) {
  .left-panel { display: none; }
  .right-panel { display: none; }
  .mobile-tab-bar { display: flex !important; }
}