:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #181b1f;
  --panel-alt: #20252a;
  --editor-output: #15181c;
  --text: #e7ecef;
  --muted: #9ba8af;
  --border: #30383f;
  --border-strong: #46525b;
  --accent: #2da6b8;
  --accent-strong: #49bfd0;
  --accent-text: #071518;
  --ok: #72c799;
  --warn: #e0b35b;
  --error: #ff7f73;
  --shadow: 0 10px 30px rgb(0 0 0 / 0.32);
  --syntax-comment: #7f8c93;
  --syntax-red: #ff7f73;
  --syntax-orange: #e8a15a;
  --syntax-yellow: #e6c45d;
  --syntax-green: #9ecb6f;
  --syntax-blue: #7bb7ee;
  --syntax-purple: #c19bf5;
  --syntax-aqua: #6bcbd0;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-alt: #fbfcfd;
  --editor-output: #fbfbfc;
  --text: #17212b;
  --muted: #5d6b78;
  --border: #d7dde4;
  --border-strong: #a9b5c1;
  --accent: #176b87;
  --accent-strong: #0f4f66;
  --accent-text: #ffffff;
  --ok: #246b45;
  --warn: #8a5a00;
  --error: #b42318;
  --shadow: 0 8px 26px rgb(23 33 43 / 0.08);
  --syntax-comment: #8e908c;
  --syntax-red: #c82829;
  --syntax-orange: #f5871f;
  --syntax-yellow: #eab700;
  --syntax-green: #718c00;
  --syntax-blue: #4271ae;
  --syntax-purple: #8959a8;
  --syntax-aqua: #3e999f;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
textarea {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  font-weight: 700;
}

.app-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  min-height: 34px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-alt);
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--panel);
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

button.primary:hover:not(:disabled) {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.theme-toggle {
  display: inline-grid;
  grid-template-columns: auto 38px;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 2px 0 8px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.theme-toggle input {
  appearance: none;
  position: relative;
  width: 38px;
  height: 22px;
  margin: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--panel-alt);
  cursor: pointer;
  transition:
    background 140ms ease,
    border-color 140ms ease;
}

.theme-toggle input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition:
    background 140ms ease,
    transform 140ms ease;
}

.theme-toggle input:checked {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 28%, var(--panel-alt));
}

.theme-toggle input:checked::after {
  background: var(--accent-strong);
  transform: translateX(16px);
}

.theme-toggle input:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  height: calc(100vh - 112px);
  min-height: 560px;
  padding: 14px;
}

.pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.pane-header h2 {
  margin: 0;
  font-size: 13px;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0;
}

.pane-header span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.editor-shell {
  width: 100%;
  min-width: 0;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--panel);
}

.editor-shell .CodeMirror {
  height: 100%;
  background: var(--panel);
  color: var(--text);
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, ui-monospace,
    monospace;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}

.editor-shell .CodeMirror-lines {
  padding: 12px 0;
}

.editor-shell .CodeMirror pre.CodeMirror-line,
.editor-shell .CodeMirror pre.CodeMirror-line-like {
  padding: 0 14px;
}

.editor-shell .CodeMirror-gutters {
  border-right: 1px solid var(--border);
  background: var(--editor-output);
}

.editor-shell .CodeMirror-linenumber {
  color: var(--muted);
}

.editor-shell .CodeMirror-cursor {
  border-left: 1px solid var(--text);
}

.editor-shell .CodeMirror-selected {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

.editor-shell .CodeMirror-focused .CodeMirror-selected {
  background: color-mix(in srgb, var(--accent) 36%, transparent);
}

.editor-shell .CodeMirror-placeholder {
  color: var(--muted);
}

.statusbar {
  display: flex;
  align-items: center;
  min-height: 36px;
  padding: 0 18px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

#status[data-tone="ok"] {
  color: var(--ok);
}

#status[data-tone="warn"] {
  color: var(--warn);
}

#status[data-tone="error"] {
  color: var(--error);
}

.cm-s-sbexml-dark,
.cm-s-sbexml-light {
  color: var(--text);
}

.cm-s-sbexml-dark .cm-comment,
.cm-s-sbexml-light .cm-comment {
  color: var(--syntax-comment);
}

.cm-s-sbexml-dark .cm-variable,
.cm-s-sbexml-dark .cm-variable-2,
.cm-s-sbexml-dark .cm-attribute,
.cm-s-sbexml-dark .cm-tag,
.cm-s-sbexml-light .cm-variable,
.cm-s-sbexml-light .cm-variable-2,
.cm-s-sbexml-light .cm-attribute,
.cm-s-sbexml-light .cm-tag {
  color: var(--syntax-red);
}

.cm-s-sbexml-dark .cm-number,
.cm-s-sbexml-dark .cm-builtin,
.cm-s-sbexml-dark .cm-atom,
.cm-s-sbexml-light .cm-number,
.cm-s-sbexml-light .cm-builtin,
.cm-s-sbexml-light .cm-atom {
  color: var(--syntax-orange);
}

.cm-s-sbexml-dark .cm-string,
.cm-s-sbexml-dark .cm-string-2,
.cm-s-sbexml-light .cm-string,
.cm-s-sbexml-light .cm-string-2 {
  color: var(--syntax-green);
}

.cm-s-sbexml-dark .cm-def,
.cm-s-sbexml-dark .cm-property,
.cm-s-sbexml-light .cm-def,
.cm-s-sbexml-light .cm-property {
  color: var(--syntax-blue);
}

.cm-s-sbexml-dark .cm-keyword,
.cm-s-sbexml-light .cm-keyword {
  color: var(--syntax-purple);
}

.cm-s-sbexml-dark .cm-meta,
.cm-s-sbexml-light .cm-meta {
  color: var(--syntax-aqua);
}

@media (max-width: 820px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    width: 100%;
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .pane {
    min-height: 440px;
  }
}
