:root {
  /* Dynamic themes using CSS variables */
  --primary: #84CC16;
  --primary-hover: #65A30D;
  --secondary: #A3E635;
  --accent: #E879F9;
  
  --success: #10B981;
  --danger: #F43F5E;
  
  /* Shared Base */
  --border-radius: 12px;
  --font-family: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-color: rgba(0, 0, 0, 0.3);
  
  /* Dark Mode Default */
  --bg-color: #0A1A08;
  --surface-color: rgba(16, 33, 14, 0.7);
  --surface-border: rgba(132, 204, 22, 0.15);
  --text-primary: #F8FAFC;
  --text-muted: #94A3B8;
  --input-bg: rgba(10, 26, 8, 0.8);
  --hover-bg: rgba(132, 204, 22, 0.1);
  --output-bg: #000000;
}

.light-mode {
  --bg-color: #F4F5F0;
  --surface-color: rgba(255, 255, 255, 0.9);
  --surface-border: rgba(132, 204, 22, 0.3);
  --text-primary: #1F2937;
  --text-muted: #6B7280;
  --input-bg: rgba(255, 255, 255, 1);
  --hover-bg: rgba(132, 204, 22, 0.1);
  --shadow-color: rgba(0, 0, 0, 0.05);
  --output-bg: #FFFFFF;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background-color var(--transition), color var(--transition);
  display: flex;
  flex-direction: column;
}

/* Utilities */
.hidden { display: none !important; }
.w-full { width: 100%; }
.mt-2 { margin-top: 0.5rem; }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.font-mono { font-family: var(--font-mono); }

/* Glassmorphism */
.glass-panel {
  background: var(--surface-color);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--surface-border);
  box-shadow: 0 8px 32px var(--shadow-color);
  border-radius: var(--border-radius);
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  border-radius: 0;
  border-top: none;
  border-left: none;
  border-right: none;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--primary);
}

.logo h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.export-group {
  display: flex;
  gap: 0.5rem;
}

/* Main Layout */
.container {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  flex: 1;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--surface-border); border-radius: 3px; }

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-group label {
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.control-group label span#valWidth,
.control-group label span#valBrightness,
.control-group label span#valContrast {
  font-family: var(--font-mono);
  color: var(--primary);
}

.upload-group {
  border: 2px dashed var(--surface-border);
  padding: 1.5rem 1rem;
  border-radius: 8px;
  text-align: center;
  transition: var(--transition);
}

.upload-group.dragover {
  border-color: var(--primary);
  background: var(--hover-bg);
}

.source-preview {
  max-width: 100%;
  max-height: 100px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid var(--surface-border);
}

/* Inputs */
.input-select, .input-text {
  background: var(--input-bg);
  border: 1px solid var(--surface-border);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 0.6rem;
  font-family: var(--font-family);
  font-size: 0.875rem;
  outline: none;
  transition: var(--transition);
}

.input-select:focus, .input-text:focus {
  border-color: var(--primary);
}

.input-range {
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
  padding: 0.5rem 0;
}

.input-range::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  background: var(--surface-border);
  border-radius: 2px;
}

.input-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  margin-top: -6px;
  box-shadow: 0 0 10px rgba(132, 204, 22, 0.5);
  transition: transform 0.1s;
}

.input-range::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Toggle Switch */
.toggle-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--input-bg);
  border: 1px solid var(--surface-border);
  transition: .4s;
  border-radius: 22px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px; width: 14px;
  left: 3px; bottom: 3px;
  background-color: var(--text-muted);
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
  border-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(18px);
  background-color: #000;
}

/* Workspace */
.workspace {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0; /* Let inner container handle padding for pan/zoom */
}

.output-container {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--input-bg);
  border-radius: var(--border-radius);
  position: relative;
}

.output-container::-webkit-scrollbar { width: 10px; height: 10px; }
.output-container::-webkit-scrollbar-thumb { background: var(--surface-border); border-radius: 5px; }
.output-container::-webkit-scrollbar-corner { background: transparent; }

.ascii-output {
  font-family: var(--font-mono);
  /* The line-height is crucial for proper aspect ratio. Standard terminal font is taller than wide (~2:1 aspect). */
  line-height: 1.1;
  letter-spacing: 0;
  white-space: pre;
  background-color: var(--output-bg);
  padding: 2rem;
  color: var(--text-primary);
  transform-origin: center center;
  transition: transform 0.1s;
  cursor: grab;
  /* Disable selection during drag */
  user-select: text;
}
.ascii-output:active { cursor: grabbing; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  opacity: 0.6;
}

.zoom-controls {
  position: absolute;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-color);
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px var(--shadow-color);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  font-family: var(--font-family);
  font-size: 0.875rem;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #000;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-outline {
  background: transparent;
  border-color: var(--surface-border);
  color: var(--text-primary);
}
.btn-outline:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--hover-bg);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.icon-btn:hover { background: var(--hover-bg); color: var(--text-primary); }

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #000;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 2000;
  transition: transform 0.3s, opacity 0.3s;
}

.toast.hidden {
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
}

/* Responsive */
@media (max-width: 900px) {
  .container { grid-template-columns: 1fr; }
  .sidebar { max-height: 400px; }
  .workspace { min-height: 500px; }
}
