/* ===== CSS Variables ===== */
/* Dark theme (default) */
:root,
[data-theme="dark"] {
  /* Backgrounds - Warm dark greys (Factorio-inspired) */
  --bg-darkest: #1a1a1a;
  --bg-dark: #212121;
  --bg-medium: #2a2a2a;
  --bg-light: #363636;
  --bg-lighter: #454545;
  
  /* Primary - Factorio yellow/orange */
  --primary: #f5a623;
  --primary-hover: #ffbe45;
  --primary-dark: #e09000;
  --primary-glow: rgba(245, 166, 35, 0.2);
  
  /* Accents */
  --accent-green: #7cb342;
  --accent-green-dark: #558b2f;
  --accent-red: #e57373;
  --accent-red-dark: #d32f2f;
  --accent-blue: #64b5f6;
  --accent-yellow: #f5a623;
  --accent-purple: #ba68c8;
  --accent-orange: #ff8f00;
  
  /* Text - Warm tones */
  --text-primary: #f5f5f5;
  --text-secondary: #b0b0b0;
  --text-muted: #6b6b6b;
  
  /* Borders - Subtle warm */
  --border-color: #3a3a3a;
  --border-highlight: #f5a623;
  
  /* Shadows - Minimal */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
  
  /* Spacing */
  --header-height: 48px;
  --footer-height: 28px;
  --panel-gap: 12px;
  --controls-width: 220px;
  
  /* Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  
  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-normal: 200ms ease;
}

/* Light theme */
[data-theme="light"] {
  /* Backgrounds - Clean light greys */
  --bg-darkest: #ffffff;
  --bg-dark: #f8f8f8;
  --bg-medium: #f0f0f0;
  --bg-light: #e8e8e8;
  --bg-lighter: #d8d8d8;
  
  /* Primary - Slightly darker for contrast on light bg */
  --primary: #e09000;
  --primary-hover: #f5a623;
  --primary-dark: #c07800;
  --primary-glow: rgba(224, 144, 0, 0.15);
  
  /* Accents - Adjusted for light background */
  --accent-green: #558b2f;
  --accent-green-dark: #33691e;
  --accent-red: #d32f2f;
  --accent-red-dark: #b71c1c;
  --accent-blue: #1976d2;
  --accent-yellow: #e09000;
  --accent-purple: #7b1fa2;
  --accent-orange: #e65100;
  
  /* Text - Dark tones */
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #8a8a8a;
  
  /* Borders */
  --border-color: #d0d0d0;
  --border-highlight: #e09000;
  
  /* Shadows - Lighter */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* System preference default when no explicit theme is set */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    /* Backgrounds - Clean light greys */
    --bg-darkest: #ffffff;
    --bg-dark: #f8f8f8;
    --bg-medium: #f0f0f0;
    --bg-light: #e8e8e8;
    --bg-lighter: #d8d8d8;
    
    /* Primary */
    --primary: #e09000;
    --primary-hover: #f5a623;
    --primary-dark: #c07800;
    --primary-glow: rgba(224, 144, 0, 0.15);
    
    /* Accents */
    --accent-green: #558b2f;
    --accent-green-dark: #33691e;
    --accent-red: #d32f2f;
    --accent-red-dark: #b71c1c;
    --accent-blue: #1976d2;
    --accent-yellow: #e09000;
    --accent-purple: #7b1fa2;
    --accent-orange: #e65100;
    
    /* Text */
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --text-muted: #8a8a8a;
    
    /* Borders */
    --border-color: #d0d0d0;
    --border-highlight: #e09000;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
  }
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* Mobile: allow scrolling */
@media (max-width: 768px) {
  html, body {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-darkest);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== App Container ===== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Mobile: allow container to scroll */
@media (max-width: 768px) {
  .app-container {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-darkest);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  width: 22px;
  height: 22px;
  color: var(--primary);
}

.logo-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.tagline {
  color: var(--text-muted);
  font-size: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--border-color);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.backend-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.status-label {
  font-weight: 500;
}

.status-indicator {
  display: flex;
  align-items: center;
  cursor: help;
}

.status-indicator .status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all var(--transition-normal);
}

.status-indicator .status-dot.connected {
  background: var(--accent-green);
  box-shadow: 0 0 10px rgba(124, 179, 66, 0.6);
}

.status-indicator .status-dot.connecting {
  background: var(--accent-yellow);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-indicator .status-dot.disconnected {
  background: var(--accent-red);
  box-shadow: 0 0 8px rgba(229, 115, 115, 0.5);
}

.header-separator {
  color: var(--text-muted);
  margin: 0 8px;
}

.header-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.header-link:hover {
  color: var(--primary);
  background: var(--bg-light);
}

.header-link svg {
  width: 16px;
  height: 16px;
}

/* ===== Main Content ===== */
.main-content {
  display: flex;
  flex: 1;
  padding: var(--panel-gap);
  gap: var(--panel-gap);
  overflow: hidden;
}

/* ===== Panels ===== */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.editor-panel,
.output-panel {
  flex: 1;
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel-title svg {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.panel-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.example-dropdown {
  position: relative;
}

.example-select {
  min-width: 150px;
  padding: 5px 28px 5px 10px !important;
  font-size: 11px !important;
  cursor: pointer;
}

/* ===== Editor ===== */
.editor-container {
  flex: 1;
  overflow: hidden;
}

.CodeMirror {
  height: 100% !important;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  font-size: 13px;
  line-height: 1.65;
  background: var(--bg-darkest) !important;
}

.CodeMirror-gutters {
  background: var(--bg-darkest) !important;
  border-right: 1px solid var(--border-color) !important;
  padding-right: 8px;
}

.CodeMirror-linenumber {
  color: var(--text-muted) !important;
  font-size: 11px;
}

.CodeMirror-activeline-background {
  background: rgba(245, 166, 35, 0.05) !important;
}

.CodeMirror-selected {
  background: rgba(245, 166, 35, 0.15) !important;
}

.CodeMirror-cursor {
  border-left: 2px solid var(--primary) !important;
}

/* Syntax highlighting - Factorio-inspired (dark theme) */
.cm-s-facto .cm-keyword { color: var(--primary); font-weight: 500; }
.cm-s-facto .cm-type { color: var(--accent-orange); }
.cm-s-facto .cm-variable { color: var(--text-primary); }
.cm-s-facto .cm-variable-2 { color: #90caf9; }
.cm-s-facto .cm-string { color: var(--accent-green); }
.cm-s-facto .cm-string-2 { color: var(--accent-green); }
.cm-s-facto .cm-number { color: #ffcc80; }
.cm-s-facto .cm-comment { color: var(--text-muted); font-style: italic; }
.cm-s-facto .cm-operator { color: var(--text-secondary); }
.cm-s-facto .cm-builtin { color: #ce93d8; }
.cm-s-facto .cm-property { color: #90caf9; }
.cm-s-facto .cm-punctuation { color: var(--text-muted); }
.cm-s-facto .cm-bracket { color: var(--text-secondary); }
.cm-s-facto .cm-error { color: var(--accent-red); }

/* Syntax highlighting - Light theme */
.cm-s-facto-light .cm-keyword { color: #c75000; font-weight: 500; }
.cm-s-facto-light .cm-type { color: #bf5600; }
.cm-s-facto-light .cm-variable { color: #1a1a1a; }
.cm-s-facto-light .cm-variable-2 { color: #1565c0; }
.cm-s-facto-light .cm-string { color: #2e7d32; }
.cm-s-facto-light .cm-string-2 { color: #2e7d32; }
.cm-s-facto-light .cm-number { color: #e65100; }
.cm-s-facto-light .cm-comment { color: #757575; font-style: italic; }
.cm-s-facto-light .cm-operator { color: #37474f; }
.cm-s-facto-light .cm-builtin { color: #7b1fa2; }
.cm-s-facto-light .cm-property { color: #1565c0; }
.cm-s-facto-light .cm-punctuation { color: #757575; }
.cm-s-facto-light .cm-bracket { color: #37474f; }
.cm-s-facto-light .cm-error { color: #c62828; }

/* Light theme CodeMirror overrides */
[data-theme="light"] .CodeMirror {
  background: #ffffff !important;
}

[data-theme="light"] .CodeMirror-gutters {
  background: #f8f8f8 !important;
  border-right: 1px solid #d0d0d0 !important;
}

[data-theme="light"] .CodeMirror-linenumber {
  color: #8a8a8a !important;
}

[data-theme="light"] .CodeMirror-activeline-background {
  background: rgba(224, 144, 0, 0.08) !important;
}

[data-theme="light"] .CodeMirror-selected {
  background: rgba(224, 144, 0, 0.2) !important;
}

[data-theme="light"] .CodeMirror-cursor {
  border-left: 2px solid #e09000 !important;
}

/* ===== Controls Panel ===== */
.controls-panel {
  display: flex;
  flex-direction: column;
  width: var(--controls-width);
  flex-shrink: 0;
}

.options-section {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 12px;
}

.options-title {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

.option-group {
  margin-bottom: 14px;
}

.option-group:last-child {
  margin-bottom: 0;
}

.option-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.option-input,
.option-select {
  width: 100%;
  padding: 7px 10px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-darkest);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

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

.option-input::placeholder {
  color: var(--text-muted);
}

.option-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 32px;
}

/* Checkboxes */
.option-checkbox {
  margin-top: 16px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  user-select: none;
}

.checkbox-label input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.checkbox-custom {
  width: 16px;
  height: 16px;
  background: var(--bg-darkest);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  position: relative;
}

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

.checkbox-custom::after {
  content: '';
  position: absolute;
  display: none;
  left: 5px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid var(--bg-darkest);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.checkbox-label input:checked + .checkbox-custom::after {
  display: block;
}

.checkbox-label:hover .checkbox-custom {
  border-color: var(--primary);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

.btn-small {
  padding: 6px 10px;
  font-size: 12px;
}

.btn-primary {
  color: var(--bg-darkest);
  background: var(--primary);
  font-weight: 600;
}

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

.btn-primary:active:not(:disabled) {
  background: var(--primary-dark);
}

.btn-secondary {
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-light);
  border-color: var(--bg-lighter);
}

.btn-compile {
  width: 100%;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  position: relative;
  gap: 10px;
}

.btn-compile .btn-icon {
  width: 16px;
  height: 16px;
}

.btn-compile .btn-spinner {
  display: none;
}

.btn-compile.compiling .btn-icon {
  display: none;
}

.btn-compile.compiling .btn-spinner {
  display: flex;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all var(--transition-fast);
}

.status-dot.connected {
  background: var(--accent-green);
  box-shadow: 0 0 8px rgba(124, 179, 66, 0.5);
}

.status-dot.connecting {
  background: var(--accent-yellow);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.disconnected {
  background: var(--accent-red);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.btn-spinner {
  display: flex;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--bg-dark);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.keyboard-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 12px;
  font-size: 11px;
  color: var(--text-muted);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 2px 5px;
  font-family: inherit;
  font-size: 9px;
  color: var(--text-muted);
  background: var(--bg-medium);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

/* ===== Output Panel ===== */
.panel-tabs {
  display: flex;
  gap: 4px;
}

.tab-btn {
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-light);
}

.tab-btn.active {
  color: var(--text-primary);
  background: var(--bg-light);
}

.output-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.output-tab {
  display: none;
  position: absolute;
  inset: 0;
  overflow: auto;
}

.output-tab.active {
  display: flex;
  flex-direction: column;
}

/* Log output */
.log-container {
  flex: 1;
  padding: 12px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.7;
  overflow: auto;
}

.log-placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.log-line {
  margin: 2px 0;
  word-break: break-all;
}

.log-line.log-error {
  color: var(--accent-red);
}

.log-line.log-warning {
  color: var(--accent-yellow);
}

.log-line.log-info {
  color: var(--text-secondary);
}

.log-line.log-success {
  color: var(--accent-green);
}

.log-line.log-status {
  color: var(--primary);
  font-weight: 500;
}

/* Blueprint output */
.blueprint-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.blueprint-status {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
}

.blueprint-status.hidden {
  display: none;
}

.blueprint-status svg {
  margin-bottom: 16px;
  opacity: 0.3;
}

.blueprint-status p {
  margin: 4px 0;
}

.blueprint-output {
  flex: 1;
  display: none;
  flex-direction: column;
  gap: 12px;
}

.blueprint-output.visible {
  display: flex;
}

.blueprint-output textarea {
  flex: 1;
  width: 100%;
  padding: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--bg-darkest);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  resize: none;
}

.blueprint-output textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.blueprint-actions {
  display: flex;
  gap: 8px;
}

.text-muted {
  color: var(--text-muted);
  font-size: 12px;
}

/* ===== Footer ===== */
.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--footer-height);
  padding: 0 16px;
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-darkest);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.footer a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

.separator {
  color: var(--border-color);
}

/* ===== Toast Notifications ===== */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-medium);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.2s ease;
  backdrop-filter: blur(8px);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast.toast-success {
  border-color: var(--accent-green-dark);
}

.toast.toast-success .toast-icon {
  color: var(--accent-green);
}

.toast.toast-error {
  border-color: var(--accent-red-dark);
}

.toast.toast-error .toast-icon {
  color: var(--accent-red);
}

.toast-message {
  font-size: 13px;
  color: var(--text-primary);
}

/* Warning toast style */
.toast.toast-warning {
  border-color: var(--accent-yellow);
}

.toast.toast-warning .toast-icon {
  color: var(--accent-yellow);
}

/* ===== Theme Toggle ===== */
#theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
}

.theme-icon-dark,
.theme-icon-light {
  width: 18px;
  height: 18px;
  transition: opacity var(--transition-fast);
}

.theme-icon-dark.hidden,
.theme-icon-light.hidden {
  display: none;
}

/* ===== Mobile Accordion ===== */
.accordion-wrapper {
  width: 100%;
}

.accordion-toggle {
  display: none;
  width: 100%;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  align-items: center;
  justify-content: space-between;
}

.accordion-toggle:hover {
  background: var(--bg-medium);
}

.accordion-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform var(--transition-normal);
}

.accordion-toggle.expanded .accordion-chevron {
  transform: rotate(180deg);
}

.accordion-content {
  transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

/* ===== Confirmation Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: modalFadeIn 0.2s ease;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-title {
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
}

.modal-message {
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.btn-danger {
  background: var(--accent-red);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: var(--accent-red-dark);
}

/* ===== JSON Tab ===== */
.json-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.json-status {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
}

.json-status.hidden {
  display: none;
}

.json-status svg {
  margin-bottom: 16px;
  opacity: 0.3;
}

.json-status p {
  margin: 4px 0;
}

.json-output {
  flex: 1;
  display: none;
  flex-direction: column;
  gap: 12px;
}

.json-output.visible {
  display: flex;
}

.json-output textarea {
  flex: 1;
  width: 100%;
  padding: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--bg-darkest);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  resize: none;
}

.json-output textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.json-actions {
  display: flex;
  gap: 8px;
}

/* ===== Responsive ===== */

/* Tablet (med-large screens) */
@media (max-width: 1200px) {
  .tagline {
    display: none;
  }
  
  :root {
    --controls-width: 200px;
  }
}

/* Tablet/Mobile transition */
@media (max-width: 900px) {
  .header-right {
    gap: 8px;
  }
  
  /* Keep "Backend:" label visible, only hide on small phones */
  
  .header-separator {
    display: none;
  }
  
  /* Replace "GitHub" text with just icon */
  .header-link svg {
    margin-right: 0;
  }
}

/* Mobile optimizations */
@media (max-width: 768px) {
  /* Stack layout vertically */
  .main-content {
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    overflow-x: hidden;
  }
  
  /* Editor panel - expands to fit content */
  .editor-panel {
    flex: none;
    height: auto;
    min-height: 300px;
    max-height: none; /* Allow expansion */
  }
  
  .editor-container {
    height: auto !important;
    min-height: 300px;
    max-height: none;
  }
  
  /* CodeMirror should auto-grow */
  .CodeMirror {
    height: auto !important;
    min-height: 300px;
  }
  
  /* Controls - full width, horizontal layout */
  .controls-panel {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 0px; /* Reduced padding, closer to edges */
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
  }
  
  /* Accordion for mobile */
  .accordion-wrapper {
    width: 100%;
    min-width: 100%;
  }
  
  .accordion-toggle {
    display: flex;
    border-radius: var(--radius-lg);
  }
  
  .accordion-toggle.expanded {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: none;
  }
  
  .accordion-content {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    padding: 0;
    margin: 0;
    border: none;
    background: var(--bg-dark);
  }
  
  .accordion-content.expanded {
    max-height: 600px;
    overflow: visible;
    opacity: 1;
    padding: 14px;
    margin-top: 0;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }
  
  /* Options in two columns */
  .options-section {
    flex: 1;
    min-width: 100%;
    margin-bottom: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px; /* Reduced gap */
  }
  
  .options-title {
    grid-column: 1 / -1;
    font-size: 13px;
    margin-bottom: 2px; /* Reduced margin */
  }
  
  .option-group {
    margin-bottom: 0;
  }
  
  .option-checkbox {
    grid-column: 1 / -1;
    margin: 0; /* Remove all margin */
  }
  
  /* Reduce checkbox spacing significantly */
  .option-checkbox .checkbox-label {
    padding: 4px 0; /* Minimal padding */
    min-height: 36px; /* Smaller but still tappable */
  }
  
  /* Compile button - full width below options */
  .btn-compile {
    width: 100%;
    min-width: 100%;
    order: 10;
    padding: 14px;
  }
  
  /* Hide keyboard hint on mobile - doesn't make sense */
  .keyboard-hint {
    display: none;
  }
  
  /* Output panel - scrollable */
  .output-panel {
    flex: 1;
    min-height: 300px;
    height: auto;
  }
  
  .output-content {
    height: auto;
    min-height: 300px;
    max-height: none;
  }
  
  .log-container,
  .blueprint-container {
    height: auto;
    min-height: 280px;
  }
  
  /* Ensure blueprint is visible */
  .blueprint-container {
    display: flex;
    flex-direction: column;
  }
  
  .blueprint-output textarea {
    min-height: 200px;
    flex: 1;
  }
  
  /* Make tabs easier to tap */
  .panel-tabs .tab-btn {
    padding: 10px 20px;
    font-size: 14px;
  }
  
  /* Larger touch targets for buttons */
  .btn {
    min-height: 44px;
  }
  
  .btn-small {
    min-height: 36px;
    padding: 6px 12px;
  }
  
  /* Header adjustments */
  .header {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-height);
    padding: 8px 12px;
  }
  
  .header-left,
  .header-right {
    flex: 1;
    min-width: 0;
  }
  
  /* Show only icons in header links on mobile, except Docs */
  .header-link {
    font-size: 0; /* Hide text */
    padding: 8px;
  }
  
  .header-link:last-child {
    font-size: 12px; /* Keep "Docs" text visible */
    padding: 6px 10px;
  }
  
  .header-link svg {
    display: block; /* Ensure SVG shows */
    width: 20px;
    height: 20px;
    margin: 0;
  }
  
  .header-link:last-child svg {
    display: none; /* Docs doesn't have an icon */
  }
  
  /* Footer */
  .footer {
    font-size: 10px;
    padding: 10px 12px;
    height: auto; /* Allow footer to expand */
    min-height: var(--footer-height);
    flex-wrap: wrap; /* Wrap items on multiple lines */
    justify-content: center;
    line-height: 1.6;
  }
  
  .footer .separator {
    margin: 0 4px;
  }
  
  /* Make footer items wrap nicely */
  .footer > span {
    white-space: nowrap;
  }
}

/* Very small mobile */
@media (max-width: 480px) {
  /* Single column options on very small screens */
  .options-section {
    grid-template-columns: 1fr;
  }
  
  .option-checkbox {
    grid-column: 1;
  }
  
  /* Smaller header */
  .logo-text {
    font-size: 14px;
  }
  
  .header-link {
    padding: 6px 8px;
  }
  
  /* Show only icons, hide text */
  .header-link {
    font-size: 0; /* Hide text */
  }
  
  .header-link svg {
    display: block; /* Keep icon */
    margin: 0;
  }
  
  /* Stack header items */
  .header {
    gap: 8px;
  }
  
  .header-left {
    flex: 0 0 auto;
  }
  
  .header-right {
    flex: 1;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  
  /* Footer stacks vertically on tiny screens */
  .footer {
    flex-direction: column;
    gap: 6px;
    text-align: center;
    padding: 12px;
  }
  
  .footer .separator {
    display: none;
  }
  
  .footer > span {
    display: block;
    width: 100%;
  }
}

/* Landscape mobile - different approach */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .editor-container {
    height: 35vh !important;
    min-height: 200px;
  }
  
  .output-content {
    min-height: 35vh;
  }
  
  .controls-panel {
    padding: 12px;
  }
  
  .options-section {
    gap: 8px;
  }
  
  .btn-compile {
    padding: 10px;
  }
}

/* Touch-friendly improvements for all mobile */
@media (hover: none) and (pointer: coarse) {
  /* Larger tap targets */
  .option-select,
  .option-input {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom */
  }
  
  .checkbox-label {
    min-height: 44px;
    padding: 12px 0;
  }
  
  /* Better touch feedback */
  .btn:active {
    transform: scale(0.98);
  }
  
  .tab-btn:active {
    transform: scale(0.95);
  }
}

