:root {
  --bg-color: #0F0A1A;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-hover: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.1);
  --text-primary: #FFFFFF;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --primary: #8A2BE2;
  --primary-hover: #9D4EDD;
  --danger: #FF4D4D;
  --danger-hover: #FF6666;
  --highlight: #00E5FF;
  --highlight-hover: #33EEFF;
  
  --grid-size: 20px;
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px;
  gap: 20px;
}

.app-header h1 {
  font-weight: 600;
  font-size: 24px;
  letter-spacing: -0.5px;
}

.app-header p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(10px);
}

.spacer {
  flex: 1;
}

.glass-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.glass-btn:hover {
  background: var(--surface-hover);
}

.glass-btn.primary {
  background: var(--primary);
  border-color: var(--primary);
}

.glass-btn.primary:hover {
  background: var(--primary-hover);
}

.glass-btn.danger {
  color: var(--danger);
}

.glass-btn.danger:hover {
  background: rgba(255, 77, 77, 0.1);
  border-color: var(--danger);
}

.glass-btn.highlight {
  background: var(--highlight);
  border-color: var(--highlight);
  color: #0F0A1A;
}

.glass-btn.highlight:hover {
  background: var(--highlight-hover);
}

.glass-btn.active {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 0 2px var(--primary);
}

.canvas-container {
  flex: 1;
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #0A0710;
}

.grid-bg {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-image: radial-gradient(var(--border) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
}

#connections-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.draw-line {
  stroke: var(--text-secondary);
  stroke-width: 2;
  fill: none;
}

.draw-line.drawing {
  stroke: var(--primary);
  stroke-dasharray: 4;
}

/* Node Styles */
.node {
  position: absolute;
  background: rgba(20, 15, 30, 0.8);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  min-width: 80px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  user-select: none;
  backdrop-filter: blur(4px);
  transition: box-shadow 0.2s;
  /* Snap to grid logic is handled in JS, but let's make sure it looks monospace-friendly */
  font-family: monospace;
  font-size: 14px;
  color: #FFF;
}

.node.dragging {
  cursor: grabbing;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

.node.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(138, 43, 226, 0.3);
}

.node .node-text {
  outline: none;
  min-width: 20px;
  text-align: center;
  cursor: text;
  white-space: pre;
}

.node .delete-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.node:hover .delete-btn {
  opacity: 1;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.2s;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: var(--bg-color);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 800px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
}

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

#ascii-output {
  width: 100%;
  height: 400px;
  background: #000;
  color: #0F0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  line-height: 1.2;
  resize: none;
  white-space: pre;
  overflow: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
}
