:root {
  /* Dracula palette */
  --bg: #282a36;
  --panel: #282a36;
  --panel-header: #21222c;
  --border: #44475a;
  --text: #f8f8f2;
  --text-dim: #6272a4;
  --accent: #bd93f9;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --tok-comment: #6272a4;
  --tok-string: #f1fa8c;
  --tok-keyword: #ff79c6;
  --tok-number: #bd93f9;
  --tok-tag: #ff79c6;
  --tok-attr: #50fa7b;
  --tok-property: #8be9fd;
  --tok-atrule: #ff79c6;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--panel-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.02em;
}

.btn {
  background: var(--accent);
  color: #282a36;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.btn:active {
  opacity: 0.8;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.editors {
  flex: 1 1 40%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.tabs {
  display: flex;
  background: var(--panel-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 0.55rem 0.75rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.pane {
  flex: 1;
  min-height: 0;
  display: none;
  flex-direction: column;
}

.pane.active {
  display: flex;
}

.pane-header {
  padding: 0.35rem 0.75rem;
  background: var(--panel-header);
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.CodeMirror {
  flex: 1;
  min-height: 0;
  height: 100%;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
}

.CodeMirror-activeline-background {
  background: rgba(255, 255, 255, 0.05);
}

.theme-select {
  background: var(--panel-header);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font-size: 0.8rem;
}

.preview-wrap {
  flex: 1 1 60%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.preview {
  flex: 1;
  border: none;
  background: #fff;
  width: 100%;
}

/* Mobile: stack editors, preview becomes an overlay toggled by button */
@media (max-width: 800px) {
  .workspace {
    position: relative;
  }

  .editors {
    flex: 1 1 auto;
    width: 100%;
    border-right: none;
  }

  .preview-wrap {
    position: fixed;
    inset: 0;
    top: 48px;
    z-index: 10;
    background: var(--bg);
    transform: translateX(100%);
    transition: transform 0.2s ease;
  }

  body.preview-open .preview-wrap {
    transform: translateX(0);
  }

  body.preview-open .editors {
    display: none;
  }
}
