:root {
  --bg: #fbfbfa;
  --panel: #ffffff;
  --text: #1d1f21;
  --muted: #6a6f75;
  --line: #d9dcdf;
  --accent: #2563a6;
  --error: #b42318;
  --warning: #a15c07;
  --note: #2563a6;
  --code-bg: #f3f4f5;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17191c;
    --panel: #1f2226;
    --text: #e4e6e8;
    --muted: #9aa0a6;
    --line: #34383d;
    --accent: #7ab3ef;
    --error: #f97066;
    --warning: #fdb022;
    --note: #7ab3ef;
    --code-bg: #262a2f;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #17191c;
  --panel: #1f2226;
  --text: #e4e6e8;
  --muted: #9aa0a6;
  --line: #34383d;
  --accent: #7ab3ef;
  --error: #f97066;
  --warning: #fdb022;
  --note: #7ab3ef;
  --code-bg: #262a2f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

h1 { margin: 0; font-size: 18px; }
h1 span { font-weight: 400; color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.muted { color: var(--muted); }

button, .button {
  font: inherit;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }

select, input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
}

.field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.field.block { display: flex; flex-direction: column; align-items: stretch; margin-top: 8px; }
.field.block textarea { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

main {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1.2fr);
  min-height: 0;
}

.editor-pane {
  display: grid;
  grid-template-rows: 1fr minmax(90px, 30%);
  min-height: 0;
  border-right: 1px solid var(--line);
}

.editor {
  display: flex;
  min-height: 0;
  background: var(--panel);
  font: 13px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
}

#gutter {
  margin: 0;
  padding: 8px 8px 8px 12px;
  min-width: 3.5em;
  text-align: right;
  color: var(--muted);
  background: var(--code-bg);
  overflow: hidden;
  user-select: none;
  font: inherit;
}

#source {
  flex: 1;
  margin: 0;
  padding: 8px;
  border: 0;
  border-radius: 0;
  resize: none;
  outline: none;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
  font: inherit;
}

.diagnostics {
  overflow: auto;
  border-top: 1px solid var(--line);
  padding: 6px 12px;
}

.summary { color: var(--muted); margin-bottom: 4px; }

#diagnostics { list-style: none; margin: 0; padding: 0; }
#diagnostics li {
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12.5px;
}
#diagnostics li:hover { background: var(--code-bg); }
.sev-error { color: var(--error); }
.sev-warning { color: var(--warning); }
.sev-note { color: var(--note); }

.output-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  min-width: 0;
}

.tabs { display: flex; gap: 2px; padding: 6px 12px 0; border-bottom: 1px solid var(--line); }
.tabs button { border-radius: 6px 6px 0 0; border-bottom: 0; }
.tabs button[aria-selected="true"] { border-color: var(--accent); color: var(--accent); }

.panel { overflow: auto; padding: 12px; min-height: 0; }
.panel[hidden] { display: none; }

.diagram { background: #ffffff; border-radius: 6px; padding: 8px; min-height: 100%; }
.diagram svg { max-width: 100%; height: auto; display: block; }
.diagram.stale { opacity: 0.45; }

.viewer { height: calc(100vh - 160px); min-height: 360px; background: #ffffff; border-radius: 6px; }

.output {
  white-space: pre-wrap;
  background: var(--code-bg);
  border-radius: 6px;
  padding: 10px;
  min-height: 3em;
  font: 12.5px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.files { list-style: none; padding: 0; }
.files li { padding: 3px 0; }
.files a { color: var(--accent); }

footer { padding: 6px 16px; border-top: 1px solid var(--line); font-size: 12px; }
footer a { color: var(--accent); }
code { background: var(--code-bg); padding: 0 4px; border-radius: 4px; }

@media (max-width: 860px) {
  main { grid-template-columns: 1fr; grid-template-rows: 60vh auto; }
  .editor-pane { border-right: 0; border-bottom: 1px solid var(--line); }
  .viewer { height: 60vh; }
}
