:root {
  --bg: #111318;
  --panel: #171a21;
  --panel-2: #1d2129;
  --line: #2a2f3a;
  --line-strong: #394050;
  --text: #d8dce4;
  --muted: #8a92a3;
  --accent: #4f9cf9;
  --accent-soft: rgba(79, 156, 249, .14);
  --ok: #3fb27f;
  --ok-soft: rgba(63, 178, 127, .14);
  --err: #f0616d;
  --err-soft: rgba(240, 97, 109, .13);
  --warn: #e3a83b;
  --warn-soft: rgba(227, 168, 59, .14);
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --col-left: 50%;
  --row-top: 48%;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--sans);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
kbd {
  font: 11px var(--mono);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  background: var(--panel-2);
}
.muted { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.noscript { max-width: 720px; margin: 40px auto; padding: 0 16px; line-height: 1.6; }
.small { font-size: 12px; }
.spacer { flex: 1; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  --ctl-h: 32px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding-right: 16px;
  margin-right: 4px;
  border-right: 1px solid var(--line);
  height: var(--ctl-h);
}
.brand-mark { width: 30px; height: 30px; flex-shrink: 0; display: block; }
.brand-text { display: flex; flex-direction: column; justify-content: center; line-height: 1.1; white-space: nowrap; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.2px; }
.brand-accent { color: #22d3ee; }
.brand-sub { font-size: 10.5px; color: var(--muted); letter-spacing: .2px; margin-top: 2px; }
.tb-group { display: flex; align-items: center; gap: 8px; min-width: 0; }

/* Toolbar controls: same height, border and radius */
.segmented, .input-group, .btn-group > .btn, .btn-group .menu > .btn, .btn-run {
  height: var(--ctl-h);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}
.segmented button {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  font-size: 12px;
}
.segmented button b { font-weight: 700; color: var(--text); }
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] { background: var(--accent-soft); color: var(--text); box-shadow: inset 0 0 0 1px rgba(79, 156, 249, .35); }
.segmented button[aria-checked="true"] b { color: var(--accent); }

.input-group {
  display: inline-flex; align-items: stretch;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
}
.input-group:focus-within { border-color: var(--accent); }
.ig-addon {
  display: flex; align-items: center;
  padding: 0 10px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border-right: 1px solid var(--line-strong);
  white-space: nowrap;
}
.ig-addon.ig-suffix { border-right: 0; border-left: 1px solid var(--line-strong); padding: 0 9px; }
.input-group input {
  border: 0;
  background: transparent;
  padding: 0 10px;
  outline: none;
  min-width: 0;
  font: 12px var(--mono);
}
.ig-fn input { width: 130px; }
.ig-timeout input { width: 46px; text-align: right; -moz-appearance: textfield; }
.ig-timeout input::-webkit-inner-spin-button, .ig-timeout input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.btn-group { display: flex; align-items: stretch; min-width: 0; }
.file-bar { flex: 0 1 420px; justify-content: flex-end; }
.file-bar .btn-group { width: 100%; }
.btn-group > .ig-file {
  flex: 1 1 auto;
  min-width: 190px;
  border-radius: 8px 0 0 8px;
}
.ig-file input { flex: 1; width: 0; font-family: var(--sans); font-size: 13px; }
.btn-group > .btn, .btn-group .menu > .btn {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 0;
  margin-left: -1px;
  padding: 0 12px;
}
.btn-group .menu > .btn { border-radius: 0 8px 8px 0; padding: 0 10px; }
.btn-group .btn svg { width: 14px; height: 14px; }

.toolbar select {
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 4px 8px;
  outline: none;
}
select:focus, .kv input:focus, .kv textarea:focus { border-color: var(--accent); }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-small { padding: 2px 9px; font-size: 12px; }
.btn-toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.btn-icon { padding: 3px 10px; font-weight: 700; }
.btn-run {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--ok);
  color: #06140d;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-run svg { width: 12px; height: 12px; }
.btn-run kbd {
  font: 600 10px var(--sans);
  color: rgba(6, 20, 13, .7);
  background: rgba(255, 255, 255, .22);
  border: 0;
  padding: 2px 5px;
}
.btn-run:hover { filter: brightness(1.08); }
.btn-run[disabled] { opacity: .6; cursor: progress; }

.segmented, .input-group, .btn-run, .btn-group > .btn, .btn-group .menu, .brand { flex-shrink: 0; }
.topbar > .tb-group:not(.file-bar) { flex-shrink: 0; }

/* Narrow desktop: drop extras before wrapping */
@media (max-width: 1760px) {
  .brand-sub { display: none; }
}
@media (max-width: 1560px) {
  .btn-run kbd { display: none; }
}
@media (max-width: 1400px) {
  .segmented .seg-sub { display: none; }
}
@media (max-width: 1200px) {
  .brand-text, .segmented .seg-sub { display: none; }
  .brand { padding-right: 12px; }
}

/* Tablet: two rows (run / file) */
@media (max-width: 1024px) {
  .topbar {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "brand switch fn timeout run"
      "tc    tc     tc tc      tc";
    gap: 8px;
    padding: 8px 12px;
  }
  .tb-group { display: contents; }
  .topbar > .spacer { display: none; }
  .brand { grid-area: brand; border-right: 0; padding-right: 0; margin: 0; }
  .runtime-switch { grid-area: switch; }
  .btn-run { grid-area: run; }
  .ig-fn { grid-area: fn; }
  .ig-fn input { width: 100%; flex: 1; }
  .ig-timeout { grid-area: timeout; }
  .file-bar .btn-group { grid-area: tc; width: 100%; }
}

/* Mobile: three rows */
@media (max-width: 640px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand switch run"
      "fn    fn     timeout"
      "tc    tc     tc";
  }
  .runtime-switch { justify-self: stretch; }
  .runtime-switch button { flex: 1; justify-content: center; }
}
@media (max-width: 340px) {
  .btn-run span { display: none; }
  .btn-run { padding: 0 12px; }
}

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px);
  z-index: 20;
  min-width: 250px;
  white-space: nowrap;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 5px;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
}
.menu-list button {
  display: block; width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 5px;
  padding: 6px 10px;
  cursor: pointer;
}
.menu-list button:hover { background: var(--accent-soft); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- workspace ---------- */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--col-left) 5px 1fr;
}
.right-col {
  min-width: 0; min-height: 0;
  display: grid;
  grid-template-rows: var(--row-top) 5px 1fr;
}
.panel {
  min-width: 0; min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}
.panel-head {
  display: flex; align-items: baseline; gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
}
.panel-title { font-weight: 600; }
.editor { flex: 1; min-height: 0; position: relative; }
.editor textarea.fallback {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  resize: none;
  border: 0;
  padding: 10px 12px;
  background: #1e1e1e;
  font: 13px/1.5 var(--mono);
  outline: none;
  tab-size: 4;
}

.splitter { background: var(--line); }
.splitter:hover, .splitter.dragging { background: var(--accent); }
.splitter-v { cursor: col-resize; }
.splitter-h { cursor: row-resize; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: thin;
  flex-shrink: 0;
}
.tabs button {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 7px 10px 6px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs em {
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
  margin-left: 2px;
}
.tabs em:empty { display: none; }
.tabs .tab-error { color: var(--err); }
.tabs .tab-error.active { border-bottom-color: var(--err); color: var(--err); }

.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tab-body[hidden] { display: none !important; }
.tab-body.scroll { overflow: auto; padding: 10px 12px; display: block; }

.toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.field-inline { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.toolbar select { padding: 2px 6px; font-size: 12px; }

/* ---------- tabelle input ---------- */
.kv-wrap { flex: 1; min-height: 0; overflow: auto; padding: 8px 10px 12px; }
.kv { width: 100%; border-collapse: collapse; table-layout: fixed; }
.kv th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 4px 4px 6px;
}
.kv td { padding: 2px 3px; vertical-align: top; }
.kv input, .kv textarea, .kv select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px 7px;
  font: 12px var(--mono);
  outline: none;
}
.kv textarea { resize: vertical; min-height: 28px; height: 28px; }
.kv select { height: 28px; padding: 2px 5px; cursor: pointer; }
.kv select:focus { border-color: var(--accent); }
.kv .col-type { width: 190px; }
.kv .col-del { width: 30px; }
.kv .col-drag { width: 26px; }
.kv .drag {
  width: 22px; height: 26px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  cursor: grab;
  touch-action: none;        /* let pointer events drive the drag on touch screens */
  font-size: 14px;
  line-height: 1;
}
.kv .drag:hover, .kv .drag:focus-visible { color: var(--text); background: var(--panel-2); outline: none; }
.kv .drag:active { cursor: grabbing; }
.kv tr.dragging td { opacity: .45; }
.kv tr.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
.kv tr.drop-after td { box-shadow: inset 0 -2px 0 var(--accent); }
@media (max-width: 640px) {
  .kv .col-type { width: 120px; }
}
.kv .del {
  width: 26px; height: 26px;
  background: transparent;
  border: 0;
  color: var(--muted);
  border-radius: 5px;
  cursor: pointer;
}
.kv .del:hover { color: var(--err); background: var(--err-soft); }
.kv-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.kv-text {
  width: 100%;
  min-height: 180px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 10px;
  font: 12px/1.5 var(--mono);
  outline: none;
}
.hint { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.hint code { font-family: var(--mono); color: var(--text); }

/* ---------- output ---------- */
.status {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  min-height: 35px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-weight: 700;
  font-size: 12px;
  padding: 1px 9px;
  border-radius: 999px;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-err { background: var(--err-soft); color: var(--err); }
.badge-run { background: var(--accent-soft); color: var(--accent); }
.status .meta { color: var(--muted); font-size: 12px; }
.status .meta b { color: var(--text); font-weight: 600; }

.out-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.out-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
}
.out-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-family: var(--mono);
  word-break: break-word;
}
.out-table td.type { color: var(--muted); font-size: 11px; }
.out-table .old { color: var(--muted); text-decoration: line-through; display: block; }
.chg { font: 700 10px var(--sans); padding: 1px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.chg-added { background: var(--ok-soft); color: var(--ok); }
.chg-changed { background: var(--warn-soft); color: var(--warn); }
.chg-removed { background: var(--err-soft); color: var(--err); }
.chg-same { color: var(--muted); }
tr.removed td { opacity: .65; }

.section-title { font-weight: 600; margin: 4px 0 8px; }
.section-title:not(:first-child) { margin-top: 18px; }
.empty { color: var(--muted); font-style: italic; }
details.att {
  border: 1px solid var(--line);
  border-radius: 7px;
  margin-bottom: 8px;
  background: var(--panel-2);
}
details.att summary { padding: 6px 10px; cursor: pointer; }
details.att summary .muted { margin-left: 8px; }
details.att pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--line); max-height: 320px; overflow: auto; }
pre, .console { font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
.console { margin: 0; }

.error-box {
  border: 1px solid rgba(240, 97, 109, .4);
  background: var(--err-soft);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.error-box .etype { color: var(--err); font: 700 12px var(--mono); }
.error-box .emsg { margin-top: 4px; font: 13px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
.error-box .eline { margin-top: 8px; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }

.toast {
  position: fixed; bottom: 18px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  z-index: 50;
}
.toast.err { border-color: var(--err); color: var(--err); }

.monaco-error-line { background: rgba(240, 97, 109, .18); }
.monaco-error-glyph { background: var(--err); border-radius: 50%; margin-left: 4px; width: 8px !important; height: 8px !important; margin-top: 6px; }

.modal-backdrop {
  position: fixed; inset: 0;
  z-index: 60;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(5, 7, 10, .6);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(420px, 100%);
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 18px 18px 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
}
.modal p { margin: 0 0 16px; font-size: 14px; line-height: 1.5; }
.modal-wide { width: min(560px, 100%); }
.modal h2 { margin: 0 0 10px; font-size: 16px; }
.modal ul { margin: 0 0 16px; padding-left: 18px; font-size: 13.5px; line-height: 1.55; }
.modal li + li { margin-top: 8px; }

.app-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 3px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
}
.app-footer .footer-long { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-footer .footer-short { display: none; flex: 1; }
.modal h3 { margin: 0 0 8px; font-size: 14px; }
.modal .legal { font-size: 13.5px; color: var(--muted); }
.link-btn {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover, .link-btn:focus-visible { color: var(--text); }
/* Mobile: short line; the full text is in the Privacy dialog */
@media (max-width: 900px) {
  .app-footer { padding: 3px 12px; }
  .app-footer .footer-long { display: none; }
  .app-footer .footer-short { display: block; }
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions .btn { height: 32px; padding: 0 14px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.08); }

/* Mobile view switcher: one panel at a time, full height (no resizing needed) */
.mobile-views { display: none; }

@media (max-width: 900px) {
  body { height: 100dvh; }
  .mobile-views {
    display: flex;
    gap: 4px;
    padding: 6px 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
  }
  .mobile-views button {
    flex: 1;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 34px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--bg);
    color: var(--muted);
    font-weight: 600;
    cursor: pointer;
  }
  .mobile-views button[aria-selected="true"] {
    color: var(--text);
    background: var(--accent-soft);
    border-color: rgba(79, 156, 249, .45);
  }
  .mobile-views .mv-dot { width: 8px; height: 8px; border-radius: 50%; display: none; }
  .mobile-views .mv-dot.ok { display: inline-block; background: var(--ok); }
  .mobile-views .mv-dot.err { display: inline-block; background: var(--err); }
  .mobile-views .mv-dot.run { display: inline-block; background: var(--accent); }

  .workspace { display: flex; flex-direction: column; }
  .splitter { display: none; }
  .panel-script, .right-col, .panel-input, .panel-output { display: none; }
  .right-col { flex: 1; min-height: 0; flex-direction: column; }
  body[data-view="script"] .panel-script { display: flex; flex: 1; }
  body[data-view="input"] .right-col,
  body[data-view="output"] .right-col { display: flex; }
  body[data-view="input"] .panel-input,
  body[data-view="output"] .panel-output { display: flex; flex: 1; min-height: 0; }
}