:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #d9dde5;
  --text: #1b1f27;
  --muted: #5b6475;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --accent-soft: #e7ecfd;
  --ok: #2b8a3e;
  --warn: #b35c00;
  --err: #c92a2a;
  --code: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --radius: 8px;
  --active-line: rgb(59 91 219 / 0.05);
  --selection: rgb(59 91 219 / 0.22);
  --selection-match: rgb(59 91 219 / 0.12);
  --search-match: rgb(255 196 0 / 0.35);

  /* Syntax highlighting */
  --hl-comment: #6a737d;
  --hl-string: #0a7c3a;
  --hl-escape: #b35c00;
  --hl-number: #0b6bcb;
  --hl-keyword: #a626a4;
  --hl-type: #c2185b;
  --hl-operator: #5b6475;
  --hl-builtin: #3b5bdb;
  --hl-constant: #986801;
  --hl-function: #1b1f27;
  --hl-event: #0e7c86;
  --hl-label: #b35c00;
  --hl-deprecated: #8a8f98;
  --hl-invalid: #c92a2a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #232834;
    --border: #2f3542;
    --text: #e3e6ec;
    --muted: #9aa3b5;
    --accent: #7b95f5;
    --accent-text: #0e1220;
    --accent-soft: #252d4a;
    --ok: #69db7c;
    --warn: #ffa94d;
    --err: #ff8787;
    --active-line: rgb(123 149 245 / 0.07);
    --selection: rgb(123 149 245 / 0.3);
    --selection-match: rgb(123 149 245 / 0.16);
    --search-match: rgb(255 196 0 / 0.28);

    --hl-comment: #7f8796;
    --hl-string: #8fd18f;
    --hl-escape: #ffb86b;
    --hl-number: #79c0ff;
    --hl-keyword: #d79bf5;
    --hl-type: #ff8fb7;
    --hl-operator: #aab3c5;
    --hl-builtin: #8fa8ff;
    --hl-constant: #e5c07b;
    --hl-function: #f2f4f8;
    --hl-event: #5fd4dc;
    --hl-label: #ffb86b;
    --hl-deprecated: #7a8190;
    --hl-invalid: #ff8787;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

code, kbd, pre { font-family: var(--code); }

code {
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 0.05em 0.3em;
  border-radius: 4px;
}

h1, h2 { margin: 0; }

/* Header */
.top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 14px;
  flex: 1 1 420px;
  min-width: 0;
}
.brand h1 { font-size: 1.35rem; letter-spacing: -0.01em; }
.brand h1 span { color: var(--accent); font-weight: 600; }
.brand p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
}
.status .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
}
.status.loading .dot { background: var(--warn); animation: pulse 1s ease-in-out infinite alternate; }
.status.ready .dot { background: var(--ok); }
.status.busy .dot { background: var(--accent); animation: pulse 0.5s ease-in-out infinite alternate; }
.status.error .dot { background: var(--err); }
@keyframes pulse { to { opacity: 0.3; } }

main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px 24px;
  display: grid;
  gap: 20px;
}

/* Editors */
.editors {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}
.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.pane-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.pane-head .title { font-weight: 600; }
.pane-head .meta { color: var(--muted); font-size: 0.85rem; flex: 1; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 6px; }

.editor {
  height: 60vh;
  min-height: 160px;
  resize: vertical;
  overflow: hidden;
  background: var(--surface);
}
.pane:focus-within { border-color: var(--accent); }

.run { display: flex; align-items: center; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 4px 10px;
  font-size: 0.85rem;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { cursor: not-allowed; opacity: 0.5; }
button.ghost { background: transparent; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-size: 1rem;
  padding: 10px 18px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.primary kbd {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0 4px;
  border-radius: 3px;
  background: rgb(255 255 255 / 0.18);
}
button.primary kbd + kbd { margin-left: 2px; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Messages */
.messages {
  border: 1px solid var(--border);
  border-left: 4px solid var(--warn);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px 14px;
}
.messages.error { border-left-color: var(--err); }
.messages h2 { font-size: 0.95rem; margin-bottom: 6px; }
.messages.error h2 { color: var(--err); }
.messages pre {
  margin: 0;
  font-size: 13px;
  white-space: pre;
  overflow-x: auto;
}

/* Options */
.options {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.options-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.options-head h2 { font-size: 1.1rem; }

.option-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px 28px;
}
.option-group h3 {
  margin: 0 0 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.opt { margin: 0 0 10px; }
.opt.child { margin-left: 26px; }
.opt.grandchild { margin-left: 52px; }
.opt label {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 2px 8px;
  cursor: pointer;
}
.opt input[type="checkbox"] { margin: 3px 0 0; accent-color: var(--accent); }
.opt .name { font-weight: 600; }
.opt .desc { grid-column: 2; color: var(--muted); font-size: 0.85rem; }
.opt.disabled { opacity: 0.45; }
.opt.disabled label { cursor: not-allowed; }
.opt.text label { display: block; }
.opt.text .desc { display: block; }
.opt.text input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  font: 13px var(--code);
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
.opt.text input[type="text"]:focus { outline: none; border-color: var(--accent); }

.cmdline { margin-top: 14px; }
.cmdline summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.cmdline pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-all;
}

footer {
  max-width: 1500px;
  margin: 0 auto;
  padding: 8px 24px 32px;
  color: var(--muted);
  font-size: 0.85rem;
}
footer p { margin: 4px 0; }

@media (max-width: 900px) {
  .editors { grid-template-columns: minmax(0, 1fr); }
  .run { justify-content: center; }
  button.primary { flex-direction: row; width: 100%; justify-content: center; }
  .editor { height: 45vh; }
}

@media (max-width: 600px) {
  .top, main, footer { padding-left: 16px; padding-right: 16px; }
  .option-groups { grid-template-columns: minmax(0, 1fr); }
}
