:root {
  --bg: #fafafa;
  --bg-editor: #ffffff;
  --text: #111111;
  --text-secondary: #888888;
  --text-tertiary: #aaaaaa;
  --border: #e5e5e5;
  --surface: #f5f5f5;
  --surface-hover: #ebebeb;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --accent: #111111;
  --font-mono: "Berkeley Mono", "SF Mono", "IBM Plex Mono", "JetBrains Mono", "Fira Code", monospace;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --radius: 6px;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-editor: #111111;
  --text: #eeeeee;
  --text-secondary: #777777;
  --text-tertiary: #555555;
  --border: #222222;
  --surface: #181818;
  --surface-hover: #252525;
  --error: #f87171;
  --error-bg: #1c0a0a;
  --accent: #eeeeee;
}

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

html {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-block-end: 1px solid var(--border);
  flex-shrink: 0;
}

.app-title {
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* Buttons */

.btn {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 450;
  padding: 0.3rem 0.625rem;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  line-height: 1.4;
  letter-spacing: 0;
}

.btn:hover {
  color: var(--text);
  border-color: var(--text-tertiary);
  background: var(--surface);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  padding: 0;
  color: var(--text-secondary);
  transition: color 0.12s, border-color 0.12s;
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--text-tertiary);
}

.theme-icon-dark {
  display: none;
}

[data-theme="dark"] .theme-icon-light {
  display: none;
}

[data-theme="dark"] .theme-icon-dark {
  display: block;
}

/* Layout */

.app-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 0;
}

/* Panels */

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-editor {
  border-inline-end: 1px solid var(--border);
}

.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-block-end: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 2.5rem;
}

.panel-label {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.toolbar-actions {
  display: flex;
  gap: 0.375rem;
}

/* Editor */

#editor-container {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#editor-container .CodeMirror {
  height: 100%;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  background: var(--bg-editor);
  color: var(--text);
  border: none;
}

#editor-container .CodeMirror-gutters {
  background: var(--bg-editor);
  border-right: 1px solid var(--border);
}

#editor-container .CodeMirror-linenumber {
  color: var(--text-tertiary);
  font-size: 0.6875rem;
}

#editor-container .CodeMirror-cursor {
  border-left-color: var(--text);
}

#editor-container .CodeMirror-selected {
  background: var(--surface);
}

.error-bar {
  background: var(--error-bg);
  color: var(--error);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  line-height: 1.5;
  border-block-start: 1px solid var(--border);
  flex-shrink: 0;
}

.error-bar-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.375rem 0.75rem;
  gap: 0.5rem;
}

.error-bar-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.error-bar-toggle {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  color: var(--error);
  border-color: transparent;
  transition: transform 0.15s;
}

.error-bar-toggle[aria-expanded="true"] {
  transform: rotate(180deg);
}

.error-bar-details {
  padding: 0 0.75rem 0.375rem;
  max-height: 8rem;
  overflow-y: auto;
  white-space: pre-wrap;
  border-block-start: 1px solid var(--border);
}

/* Tabs */

.tab-bar {
  display: flex;
  gap: 0;
  position: relative;
}

.tab {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 450;
  padding: 0.375rem 0.75rem;
  background: transparent;
  color: var(--text-tertiary);
  border: none;
  border-block-end: 1.5px solid transparent;
  cursor: pointer;
  transition: color 0.12s;
  position: relative;
}

.tab:hover {
  color: var(--text-secondary);
}

.tab.active {
  color: var(--text);
  border-block-end-color: var(--text);
}

/* Output */

#output-container {
  flex: 1;
  min-height: 0;
  position: relative;
}

.tab-content {
  display: none;
  position: absolute;
  inset: 0;
}

.tab-content.active {
  display: block;
}

.tab-content textarea {
  width: 100%;
  height: 100%;
  background: var(--bg-editor);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  border: none;
  padding: 0.75rem;
  resize: none;
  outline: none;
}

.tab-content .CodeMirror {
  height: 100%;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  background: var(--bg-editor);
}

.tab-content .CodeMirror-gutters {
  background: var(--bg-editor);
  border-right: 1px solid var(--border);
}

.tab-content .CodeMirror-linenumber {
  color: var(--text-tertiary);
  font-size: 0.6875rem;
}

/* Autocomplete hints */

.CodeMirror-hints {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--bg-editor);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 0.25rem 0;
  z-index: 100;
}

.CodeMirror-hint {
  padding: 0.25rem 0.625rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.5;
}

li.CodeMirror-hint-active {
  background: var(--surface);
  color: var(--text);
}

[data-theme="dark"] .CodeMirror-hints {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Responsive */

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .panel-editor {
    border-inline-end: none;
    border-block-end: 1px solid var(--border);
  }
}
