:root {
  --bg-pitch: #050505;
  --bg-surface: #0c0c0c;
  --bg-panel: #141414;
  --bg-hover: #1f1f1f;
  --border-subtle: #242424;
  --border-active: #404040;
  --fg-muted: #737373;
  --fg-default: #d4d4d4;
  --fg-bright: #ffffff;
  --accent-mono: #ffffff;

  --font-mono: "Geist Mono", "JetBrains Mono", "SF Mono", monospace;
  --font-sans: "Geist", "Inter", -apple-system, sans-serif;
  --header-height: 52px;
  --footer-height: 48px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-pitch);
  color: var(--fg-default);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  height: 100vh;
}

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.app-workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.panel-controls {
  width: 320px;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stage-viewport {
  flex: 1;
  position: relative;
  background: var(--bg-pitch);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.app-export-bar {
  height: var(--footer-height);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-family: var(--font-mono);
}

/* UI Elements */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-panel);
  color: var(--fg-bright);
  border: 1px solid var(--border-subtle);
  padding: 6px 12px;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-active);
}

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

.btn:focus-visible,
.control-slider:focus-visible,
.text-input:focus-visible,
.modal-textarea:focus-visible {
  outline: 1px solid var(--fg-bright);
  outline-offset: 2px;
}

.btn-icon {
  padding: 4px;
}

.btn-primary {
  background: var(--fg-bright);
  color: var(--bg-pitch);
  font-weight: 600;
  border-color: var(--fg-bright);
}

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

.btn-primary:disabled {
  background: var(--fg-muted);
  border-color: var(--fg-muted);
  color: var(--bg-pitch);
}

.tag-version {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--border-subtle);
  border-radius: 2px;
  color: var(--fg-muted);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  justify-content: space-between;
}

.control-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border-subtle);
  outline: none;
}

.control-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  background: var(--fg-bright);
  cursor: pointer;
  border-radius: 0;
}

.control-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--fg-bright);
  border: none;
  border-radius: 0;
  cursor: pointer;
}

.control-slider::-moz-range-track {
  height: 4px;
  background: var(--border-subtle);
}

.text-input {
  width: 100%;
  background: var(--bg-pitch);
  border: 1px solid var(--border-subtle);
  color: var(--fg-bright);
  font-family: var(--font-sans);
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 2px;
  outline: none;
}

.text-input:focus {
  border-color: var(--border-active);
}

.btn-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.engine-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 7px 10px;
  border: 1px solid var(--border-active);
  background: var(--bg-panel);
  color: var(--fg-default);
}

.engine-chip .dot {
  width: 6px;
  height: 6px;
  background: var(--fg-bright);
  border-radius: 50%;
  display: inline-block;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-active);
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-textarea {
  width: 100%;
  height: 180px;
  background: var(--bg-pitch);
  border: 1px solid var(--border-subtle);
  color: var(--fg-bright);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 12px;
  resize: vertical;
  outline: none;
}

.modal-textarea:focus {
  border-color: var(--border-active);
}

.modal-error {
  color: #ff4d4d;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* Viewport Canvas Styles */
.svg-render-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.viewport-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, #111111 1px, transparent 1px),
    linear-gradient(to bottom, #111111 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
}

.viewport-grid.grid-off {
  display: none;
}

.viewport-grid-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
}

.svg-stage-element {
  max-width: 80%;
  max-height: 80%;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
}

.viewport-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--font-mono);
  color: var(--fg-muted);
  text-align: center;
  pointer-events: none;
}

.viewport-empty-state[hidden] {
  display: none;
}

.empty-title {
  letter-spacing: 2px;
  color: var(--fg-default);
  font-size: 13px;
}

.empty-hint {
  font-size: 11px;
  line-height: 1.7;
}

.viewport-status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: calc(100% - 24px);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-muted);
  background: rgba(5, 5, 5, 0.85);
  border: 1px solid var(--border-subtle);
  padding: 4px 8px;
  pointer-events: none;
}

.viewport-status[hidden] {
  display: none;
}

/* Export bar */
.export-status {
  color: var(--fg-muted);
  font-size: 11px;
}

/* Toasts */
.toast-host {
  position: fixed;
  right: 12px;
  bottom: calc(var(--footer-height) + 12px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}

.toast {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 8px 12px;
  max-width: 360px;
  background: var(--bg-panel);
  border: 1px solid var(--border-active);
  color: var(--fg-default);
  opacity: 0;
  transform: translateX(8px);
  transition: opacity 0.25s, transform 0.25s;
}

.toast-visible {
  opacity: 1;
  transform: none;
}

.toast-error {
  border-color: #ff4d4d;
  color: #ff6b6b;
}

.toast-success {
  border-color: #4dff88;
  color: #6bff9e;
}

.toast-warning {
  border-color: #ffc44d;
  color: #ffd479;
}

/* Responsive */
@media (max-width: 760px) {
  .app-workspace {
    flex-direction: column;
  }

  .panel-controls {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }

  .app-header {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-height);
    padding: 8px 12px;
    gap: 8px;
  }
}