:root {
  --bg: #0d1117; --panel: #161b22; --border: #30363d; --text: #e6edf3; --muted: #8b949e;
  --accent: #58a6ff; --ok: #3fb950; --warn: #d29922;
  --term-bg: #0b0f14; --term-fg: #d4d8de;
  --c0: #1f2329; --c1: #f2594b; --c2: #3fb950; --c3: #e3b341; --c4: #58a6ff; --c5: #c678dd; --c6: #39c5cf; --c7: #d4d8de;
  --c8: #6e7681; --c9: #ff7b72; --c10: #56d364; --c11: #f2cc60; --c12: #79c0ff; --c13: #d2a8ff; --c14: #56d4dd; --c15: #ffffff;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --fs: 14px; --lh: 1.4;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); display: flex; flex-direction: column;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; overflow: hidden;
}
button {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: #238636; border-color: #2ea043; color: #fff; }
button.primary:hover { background: #2ea043; }
button.ghost { background: transparent; }
.spacer { flex: 1; }

.bar {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--border); flex: none; min-height: 44px;
}
.brand { letter-spacing: .02em; }
.user { color: var(--muted); font-family: var(--mono); font-size: 13px; }
.runstatus {
  display: inline-flex; align-items: center; gap: 8px; padding: 2px 4px 2px 10px; border-radius: 999px;
  background: rgba(63, 185, 80, .15); color: var(--ok); font-size: 13px; min-width: 0;
}
.runstatus[hidden] { display: none; }
.runstatus .label { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30vw; }
.runstatus button { padding: 1px 10px; border-radius: 999px; color: #fff; background: #b62324; border-color: #da3633; }

.layout { flex: 1; display: flex; min-height: 0; }

/* ---------- Terminal ---------- */
.term {
  position: relative; flex: 1 1 0; min-width: 0; overflow-y: auto; overflow-x: hidden;
  background: var(--term-bg); color: var(--term-fg); padding: 6px 10px 0; cursor: text;
  font: var(--fs)/var(--lh) var(--mono); outline: none;
}
.term.running { box-shadow: inset 0 0 0 2px rgba(63, 185, 80, .35); }
.term.bell { box-shadow: inset 0 0 0 2px var(--warn); }
.term-lines { font: inherit; }
.term .row { white-space: pre; min-height: calc(var(--fs) * var(--lh)); font: inherit; }
.term-probe { position: absolute; left: -9999px; top: 0; visibility: hidden; white-space: pre; font: inherit; }
.term-input {
  position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; padding: 0; border: 0;
  font-size: 16px; resize: none; pointer-events: none;
}
.term .cursor { outline: 1px solid var(--term-fg); outline-offset: -1px; }
.term.focused .cursor { background: var(--term-fg) !important; color: var(--term-bg) !important; animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .term.focused .cursor { animation: none; } }

.runner-host { position: fixed; width: 0; height: 0; overflow: hidden; left: -10px; top: -10px; }
.runner-frame { width: 1px; height: 1px; border: 0; }

/* ---------- Editor ---------- */
.editor {
  display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; background: var(--bg);
  border-left: 1px solid var(--border);
}
.editor[hidden] { display: none; }
.ed-head, .ed-foot { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); flex: none; }
.ed-head { border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.ed-foot { border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.ed-title { font-family: var(--mono); font-weight: 600; }
.ed-state { font-size: 12px; color: var(--ok); }
.ed-state.dirty { color: var(--warn); }
.ed-body { flex: 1; display: flex; min-height: 0; background: #0d1117; }
.ed-gutter, .ed-hlwrap, .ed-text {
  font: var(--fs)/var(--lh) var(--mono); tab-size: 2; margin: 0; white-space: pre; letter-spacing: 0;
}
.ed-gutter {
  flex: none; overflow: hidden; padding: 10px 8px 24px 10px; text-align: right; color: var(--c8);
  background: #0d1117; user-select: none; min-width: 3.2em; border-right: 1px solid var(--border);
}
.ed-wrap { position: relative; flex: 1; min-width: 0; }
.ed-hlwrap, .ed-text { position: absolute; inset: 0; padding: 10px 24px 24px 10px; border: 0; }
.ed-hlwrap { overflow: hidden; pointer-events: none; color: #d4d8de; }
.ed-hl { font: inherit; }
.ed-text {
  overflow: auto; background: transparent; color: transparent; caret-color: #fff; resize: none; outline: none;
  -webkit-text-fill-color: transparent;
}
.ed-text::selection { background: rgba(88, 166, 255, .35); -webkit-text-fill-color: transparent; }
.tk-com { color: #7d8590; font-style: italic; }
.tk-str { color: #a5d6ff; }
.tk-num { color: #79c0ff; }
.tk-kw { color: #ff7b72; }
.tk-lit { color: #d2a8ff; }
.tk-api { color: #7ee787; }

/* Schmale Bildschirme: Editor über dem Terminal */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  body.editing .term { flex: 0 0 38%; }
  .editor { border-left: 0; border-top: 1px solid var(--border); }
  .runstatus .label { max-width: 24vw; }
  .ed-foot { display: none; }
}
