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

:root {
  --bg-primary: #1e1e2e;
  --bg-secondary: #181825;
  --bg-surface: #11111b;
  --text-primary: #cdd6f4;
  --text-secondary: #a6adc8;
  --text-muted: #6c7086;
  --accent: #89b4fa;
  --accent-hover: #74c7ec;
  --border: #313244;
  --error: #f38ba8;
  --success: #a6e3a1;
  --warning: #f9e2af;
  --header-height: 48px;
  --pane-header-height: 36px;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Consolas, monospace;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ── Header ────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.3px;
}

.header-right {
  display: flex;
  gap: 8px;
}

/* ── Filename Input ────────────────────────────────────────── */
.header-center {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

#filename {
  width: 180px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.15s;
}

#filename:focus {
  border-color: var(--accent);
}

#filename::placeholder {
  color: var(--text-muted);
}

/* ── Buttons ───────────────────────────────────────────────── */
button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

button:hover {
  background: var(--border);
  border-color: var(--text-muted);
}

button:active {
  transform: scale(0.97);
}

/* ── Main Layout ───────────────────────────────────────────── */
main {
  display: flex;
  height: calc(100vh - var(--header-height));
}

#editor-pane {
  display: flex;
  flex-direction: column;
  width: 50%;
  min-width: 200px;
  background: var(--bg-primary);
}

#resize-handle {
  width: 4px;
  cursor: col-resize;
  background: var(--border);
  transition: background 0.15s;
  flex-shrink: 0;
}

#resize-handle:hover,
#resize-handle.active {
  background: var(--accent);
}

#preview-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 200px;
  background: var(--bg-surface);
}

/* ── Pane Headers ──────────────────────────────────────────── */
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--pane-header-height);
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.status-ok {
  color: var(--success);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.status-error {
  color: var(--error);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.status-rendering {
  color: var(--warning);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

/* ── Editor ────────────────────────────────────────────────── */
#code {
  flex: 1;
  width: 100%;
  padding: 16px;
  border: none;
  outline: none;
  resize: none;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

#code::placeholder {
  color: var(--text-muted);
}

#code::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

#code::-webkit-scrollbar-track {
  background: transparent;
}

#code::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

#code::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Preview ───────────────────────────────────────────────── */
.preview-controls {
  display: flex;
  gap: 4px;
  align-items: center;
}

.preview-controls button {
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 4px;
}

#zoom-level {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: center;
  text-transform: none;
  letter-spacing: 0;
}

#preview-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  cursor: grab;
}

#preview-container.panning {
  cursor: grabbing;
}

#preview-container.panning * {
  pointer-events: none;
}

#preview {
  position: absolute;
  transform-origin: 0 0;
  will-change: transform;
}

#preview svg {
  max-width: none;
  display: block;
}

/* ── Editor Controls ───────────────────────────────────────── */
.editor-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.editor-controls button {
  padding: 2px 10px;
  font-size: 11px;
  border-radius: 4px;
}

/* ── 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;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 20px;
  padding: 4px 8px;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text-primary);
  background: none;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
}

.example-item {
  padding: 12px 16px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.example-item:hover {
  background: var(--bg-surface);
  border-color: var(--accent);
}

.example-item h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

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

/* ── Drag/Drop Overlay ─────────────────────────────────────── */
.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(137, 180, 250, 0.1);
  border: 3px dashed var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  pointer-events: none;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  main {
    flex-direction: column;
  }

  #editor-pane {
    width: 100%;
    height: 50%;
  }

  #resize-handle {
    width: 100%;
    height: 4px;
    cursor: row-resize;
  }

  #preview-pane {
    flex: 1;
  }

  .header-right {
    gap: 4px;
  }

  .header-right button {
    padding: 4px 8px;
    font-size: 11px;
  }

  .filename-label {
    display: none;
  }

  #filename {
    width: 100px;
  }
}
