:root {
  color-scheme: light dark;
  --paper: light-dark(#f4f6fa, #10151f);
  --surface: light-dark(#fff, #171f2d);
  --text: light-dark(#17243b, #e1e9f6);
  --muted: light-dark(#536279, #a7b6cd);
  --line: light-dark(#d8dfea, #344258);
  --accent: light-dark(#1758a8, #98c7ff);
  --accent-hover: light-dark(#104788, #bedbff);
  --on-accent: light-dark(#fff, #111c2d);
  --hover: light-dark(#edf2fa, #243247);
  --gutter: light-dark(#f8faff, #1c2636);
  --active-line: light-dark(#eef6ff, #24354c);
  --error: light-dark(#ab2a25, #ffaaa4);
  --error-surface: light-dark(#fff6f4, #38252d);
  --syntax-keyword: light-dark(#770088, #d7a8ff);
  --syntax-literal: light-dark(#164b87, #a5caff);
  --syntax-string: light-dark(#a11, #ffa69e);
  --syntax-comment: var(--muted);
  --syntax-type: light-dark(#815200, #f1ce8f);
  --syntax-function: light-dark(#145e57, #91ded0);
  --mono: ui-monospace, Menlo, Consolas, monospace;
  --inset: .625rem;
  --border: 1px solid var(--line);
  font: 16px/1.5 system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--text); }
h1, h2, p, pre { margin: 0; }
h1 { font-size: 1.125rem; }
kbd { font-family: var(--mono); }
:is(button, a, pre):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main, .workspace { display: grid; gap: 1rem; }
main { grid-template-columns: minmax(0, 1fr); max-width: 88rem; margin: auto; padding: clamp(1rem, 4vw, 3.5rem); }
.workspace { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
/* Match the text inset of panels, including their border. */
main > header, footer { padding-inline: calc(var(--inset) + 1px); }

.panel, .notice { background: var(--surface); border: var(--border); border-radius: .75rem; }
.panel { display: flex; flex-direction: column; height: clamp(19rem, 62vh, 42rem); overflow: hidden; }
.panel-bar, .actions, footer { display: flex; align-items: center; gap: var(--inset); }
.panel-bar, .actions { flex-wrap: wrap; }
.panel-bar { justify-content: space-between; padding: var(--inset); border-bottom: var(--border); }
.panel-bar h2, #editor .cm-scroller, #output { font: .875rem/1.6 var(--mono); }
.panel-bar h2 { font-weight: 600; }

button {
  font: 600 1rem/1.35 system-ui, sans-serif;
  color: var(--text);
  background: var(--surface);
  border: var(--border);
  border-radius: .55rem;
  padding: .45rem var(--inset);
  cursor: pointer;
  white-space: nowrap;
}
button:disabled { opacity: .55; cursor: default; }
.primary { color: var(--on-accent); background: var(--accent); border-color: transparent; --button-hover: var(--accent-hover); }
.panel-bar button:enabled:hover { background: var(--button-hover, var(--hover)); }
/* Reserve space for the original label while showing clipboard feedback. */
[data-copy-label] { display: inline-grid; place-items: center; }
[data-copy-label] > span, [data-copy-label]::after { grid-area: 1 / 1; }
[data-copy-label]::after { content: attr(data-copy-label); visibility: hidden; }

#editor, #output { flex: 1; min-height: 0; }
#editor .cm-editor { height: 100%; }
#editor .cm-focused { outline: none; }
/* Hide the native caret until CodeMirror restores focus and selection. */
#editor .cm-editor:not(.cm-focused) .cm-content { caret-color: transparent; }
/* CodeMirror uses content padding to position gutter entries. */
#editor .cm-content { padding-block: var(--inset); }
#editor .cm-line { padding-inline-start: var(--inset); }
#editor .cm-gutters { background: var(--gutter); border-color: var(--line); color: var(--muted); }
#editor .cm-lineNumbers .cm-gutterElement {
  padding-inline: var(--inset);
  text-align: start;
  /* Reserve two digits and round up to avoid a gutter shift at line 10. */
  min-inline-size: calc(2ch + 2 * var(--inset));
  min-inline-size: round(up, calc(2ch + 2 * var(--inset)), 1px);
}
#editor .cm-activeLineGutter { background: transparent; }
#editor .cm-focused .cm-activeLineGutter { background: var(--active-line); }

#output { padding: var(--inset); overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
#output:focus-visible { outline-offset: -2px; }
#output .stderr, .diagnostics button { color: var(--error); }
#output .system, .placeholder, footer { color: var(--muted); }
.diagnostics { max-height: 7rem; overflow: auto; border-bottom: var(--border); padding: .45rem var(--inset); background: var(--error-surface); }
.diagnostics button { display: block; max-width: 100%; padding: .2rem 0; border: 0; background: none; white-space: normal; text-align: start; font: .8rem/1.4 var(--mono); text-decoration: underline; }

.notice, footer { font-size: .85rem; }
.notice { padding: var(--inset); }
footer { white-space: nowrap; }
#godot-version { margin-inline-start: auto; overflow: hidden; text-overflow: ellipsis; }
footer a { display: flex; flex: none; color: var(--text); }
.runner-frame { position: fixed; width: 1px; height: 1px; bottom: 0; right: 0; border: 0; opacity: 0; pointer-events: none; }

@media (max-width: 48rem) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .panel { height: 26rem; }
  .panel:last-child { height: 14rem; }
}
