:root {
  --bg-primary: #0a0a14;
  --bg-secondary: #12121f;
  --bg-tertiary: #1a1a2e;
  --text-primary: #e0e0e0;
  --text-dim: #666680;
  --accent-green: #39ff14;
  --accent-cyan: #00e5ff;
  --accent-blue: #7c83ff;
  --accent-orange: #ffab40;
  --accent-magenta: #ff4081;
  --accent-yellow: #ffd740;
  --glow-color: rgba(57, 255, 20, 0.08);
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'IBM Plex Mono', monospace;
}

#root {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: #333355; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #444477; }

/* CRT Effect */
.crt-on .editor-wrapper::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.12) 0px,
    rgba(0, 0, 0, 0.12) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  z-index: 10;
}

/* Editor wrapper - the container for line numbers + code area */
.editor-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Line numbers column */
.line-numbers {
  flex-shrink: 0;
  width: 56px;
  overflow: hidden;
  background: rgba(10,10,20,0.5);
  border-right: 1px solid #222244;
  user-select: none;
  padding: 8px 0;
}

.line-num {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  gap: 4px;
  color: #444466;
}

.line-num.active {
  color: var(--accent-green);
}

.gutter-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Code area - contains both the highlight layer and textarea */
.code-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.code-highlight {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  padding: 8px 12px;
  margin: 0;
  white-space: pre;
  font-family: 'IBM Plex Mono', monospace;
  line-height: 1.6;
  overflow: auto;
  pointer-events: none;
  z-index: 1;
  color: var(--text-primary);
  border: none;
  outline: none;
}

.code-textarea {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  padding: 8px 12px;
  margin: 0;
  white-space: pre;
  font-family: 'IBM Plex Mono', monospace;
  line-height: 1.6;
  background: transparent;
  color: transparent;
  caret-color: var(--accent-green);
  border: none;
  outline: none;
  resize: none;
  overflow: auto;
  z-index: 2;
  tab-size: 4;
}

.code-textarea::selection {
  background: rgba(57, 255, 20, 0.2);
  color: transparent;
}

/* Syntax highlighting spans */
.syn-misc { color: #8a8a9a; }
.syn-jump { color: #00e5ff; }
.syn-load { color: #9fa4ff; }
.syn-arith { color: #50ff30; }
.syn-shift { color: #ffab40; }
.syn-label { color: #ffd740; font-weight: 700; }
.syn-directive { color: #ff4081; }
.syn-hex { color: #ffab40; }
.syn-bin { color: #80deea; }
.syn-dec { color: #fff176; }
.syn-imm { color: #ff7043; font-weight: 700; }
.syn-comment { color: #4a6a4a; font-style: italic; }
.syn-string { color: #ff8a80; }
.syn-register { color: #ea80fc; font-weight: 600; }
.syn-paren { color: #80cbc4; }
.syn-comma { color: #666680; }

/* Opcode table */
.opcode-table {
  border-collapse: separate;
  border-spacing: 1px;
  font-size: 10px;
  width: max-content;
}

.opcode-table th {
  background: var(--bg-tertiary);
  color: var(--text-dim);
  padding: 4px 6px;
  font-weight: 600;
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
}

.opcode-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.opcode-table th.corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 3;
}

.opcode-table .row-header {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-tertiary);
}

.opcode-cell {
  padding: 3px 4px;
  min-width: 64px;
  max-width: 78px;
  vertical-align: top;
  cursor: pointer;
  transition: all 0.15s ease;
  border-radius: 2px;
  position: relative;
  font-family: 'IBM Plex Mono', monospace;
}

.opcode-cell:hover {
  transform: scale(1.05);
  z-index: 5;
  box-shadow: 0 0 12px rgba(255,255,255,0.15);
}

.opcode-cell.empty-cell {
  background: rgba(10, 10, 20, 0.6);
  cursor: default;
}
.opcode-cell.empty-cell:hover {
  transform: none;
  box-shadow: none;
}

.opcode-cell.highlighted {
  outline: 2px solid #fff;
  outline-offset: -1px;
  box-shadow: 0 0 15px rgba(255,255,255,0.25);
}

.opcode-cell.dimmed {
  opacity: 0.15;
}

.cell-mnemonic {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.cell-mode {
  font-size: 8px;
  opacity: 0.7;
  display: block;
  margin-top: 1px;
}

.cell-info {
  font-size: 8px;
  opacity: 0.55;
  margin-top: 2px;
}

.cell-flags {
  font-size: 7px;
  opacity: 0.45;
  letter-spacing: 1px;
}

/* Tooltip */
.opcode-tooltip {
  position: fixed;
  z-index: 100;
  background: #1e1e36;
  border: 1px solid #444466;
  border-radius: 6px;
  padding: 12px 16px;
  max-width: 320px;
  font-size: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  pointer-events: none;
  font-family: 'IBM Plex Mono', monospace;
}

/* Category badges */
.cat-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
  font-family: 'IBM Plex Mono', monospace;
  background: none;
  white-space: nowrap;
}
.cat-badge:hover {
  border-color: currentColor;
}
.cat-badge.active { opacity: 1; }
.cat-badge.inactive { opacity: 0.3; }

/* Drag handle */
.drag-handle {
  width: 6px;
  cursor: col-resize;
  background: var(--bg-tertiary);
  transition: background 0.2s;
  flex-shrink: 0;
  position: relative;
}
.drag-handle:hover, .drag-handle.dragging {
  background: var(--accent-green);
}
.drag-handle::after {
  content: '⋮';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #666;
  font-size: 14px;
}

/* Status bar */
.status-bar {
  background: var(--bg-tertiary);
  border-top: 1px solid #2a2a44;
  padding: 4px 12px;
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  gap: 16px;
  flex-shrink: 0;
  align-items: center;
  flex-wrap: wrap;
  font-family: 'IBM Plex Mono', monospace;
  min-height: 28px;
}

/* Notation guide */
.notation-guide {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.notation-guide.open {
  max-height: 400px;
}

/* Mobile tabs */
.mobile-tab {
  padding: 10px 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  font-family: 'IBM Plex Mono', monospace;
  flex: 1;
  text-align: center;
}
.mobile-tab.active {
  color: var(--accent-green);
  border-bottom-color: var(--accent-green);
}

/* Chip icon */
.chip-icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  background: linear-gradient(135deg, #333355, #555577);
  border: 2px solid #777799;
  border-radius: 3px;
  position: relative;
  flex-shrink: 0;
}
.chip-icon::before {
  content: '';
  position: absolute;
  top: 3px; left: 3px; right: 3px; bottom: 3px;
  border: 1px solid #999;
  border-radius: 1px;
}

/* Toolbar button */
.tb-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid #333355;
  border-radius: 4px;
  color: #aaa;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  transition: all 0.15s;
  white-space: nowrap;
  min-height: 28px;
}
.tb-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #ddd;
}
.tb-btn:active {
  background: rgba(255,255,255,0.15);
}

.tb-select {
  background: #1a1a2e;
  color: #aaa;
  border: 1px solid #333355;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
  min-height: 28px;
}

/* Theme: Amber */
.theme-amber { --accent-green: #ffab40; }
.theme-amber .code-textarea { caret-color: #ffab40; }
.theme-amber .syn-misc { color: #998866; }
.theme-amber .syn-jump { color: #ffcc80; }
.theme-amber .syn-load { color: #ffe082; }
.theme-amber .syn-arith { color: #ffab40; }
.theme-amber .syn-shift { color: #ff8f00; }
.theme-amber .syn-label { color: #ffffff; }
.theme-amber .syn-comment { color: #665533; }
.theme-amber .syn-hex { color: #ffd54f; }

/* Theme: C64 Blue */
.theme-c64 {
  --bg-primary: #40318d;
  --bg-secondary: #3a2d82;
  --bg-tertiary: #4a3d97;
  --accent-green: #7c71da;
}
.theme-c64 .code-textarea { caret-color: #7c71da; }
.theme-c64 .syn-misc { color: #9990cc; }
.theme-c64 .syn-arith { color: #71e871; }
.theme-c64 .syn-load { color: #8888ff; }
.theme-c64 .syn-comment { color: #6058a0; }

/* Theme: Modern Dark */
.theme-modern .syn-misc { color: #abb2bf; }
.theme-modern .syn-jump { color: #56b6c2; }
.theme-modern .syn-load { color: #c678dd; }
.theme-modern .syn-arith { color: #98c379; }
.theme-modern .syn-shift { color: #d19a66; }
.theme-modern .syn-label { color: #e5c07b; }
.theme-modern .syn-comment { color: #5c6370; font-style: italic; }

/* Header */
.app-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid #2a2a44;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  min-height: 48px;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Toolbar */
.app-toolbar {
  background: var(--bg-tertiary);
  border-bottom: 1px solid #222244;
  padding: 4px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
  min-height: 36px;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: #333355;
  flex-shrink: 0;
}

/* Footer */
.app-footer {
  background: var(--bg-secondary);
  border-top: 1px solid #2a2a44;
  padding: 6px 12px;
  font-size: 10px;
  color: #444466;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 28px;
}

.app-footer a {
  color: #666680;
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 900px) {
  .drag-handle { display: none; }
  
  .app-header {
    flex-wrap: wrap;
    padding: 6px 10px;
  }
  
  .header-title h1 {
    font-size: 14px !important;
  }
  
  .header-title .subtitle {
    display: none;
  }
  
  .app-toolbar {
    padding: 4px 8px;
    gap: 4px;
  }
  
  .tb-btn {
    padding: 4px 8px;
    font-size: 11px;
  }
  
  .status-bar {
    font-size: 10px;
    gap: 10px;
    padding: 4px 8px;
  }
  
  .opcode-cell {
    min-width: 56px;
    padding: 2px 3px;
  }
  
  .cell-mnemonic { font-size: 10px; }
  .cell-mode { font-size: 7px; }
  .cell-info { font-size: 7px; }
  .cell-flags { font-size: 6px; }
}