:root {
  --bg: #1e1e2e;
  --bg-panel: #181825;
  --bg-elevated: #252537;
  --border: #313147;
  --text: #cdd6f4;
  --text-dim: #7f849c;
  --accent: #89b4fa;
  --accent-hover: #a6c8ff;
  --green: #a6e3a1;
  --red: #f38ba8;
  --yellow: #f9e2af;
  --highlight: rgba(249, 226, 175, 0.14);
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --line-height: 21px;
  --font-size: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  overflow: hidden;
  /* Render native controls (the Examples dropdown popup, etc.) dark so the
     light option text isn't drawn on a white system background. */
  color-scheme: dark;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---- toolbar ---- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#toolbar .title {
  font-weight: 600;
  margin-right: 8px;
  color: var(--accent);
  white-space: nowrap;
}
#toolbar .title small { color: var(--text-dim); font-weight: 400; }
#toolbar .spacer { flex: 1; }

button.tool {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button.tool:hover:not(:disabled) { border-color: var(--accent); }
button.tool:disabled { opacity: 0.4; cursor: not-allowed; }
button.tool.primary { background: var(--accent); color: #11111b; border-color: var(--accent); font-weight: 600; }
button.tool.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.tool.danger:hover:not(:disabled) { border-color: var(--red); color: var(--red); }

select.tool {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
select.tool option,
select.tool optgroup {
  background-color: var(--bg-elevated);
  color: var(--text);
}
select.tool optgroup { font-weight: 600; }

/* ---- main split ---- */
#main { display: flex; flex: 1; min-height: 0; }
#editor-pane { display: flex; flex-direction: column; flex: 1.3; min-width: 0; border-right: 1px solid var(--border); }
#right-pane { display: flex; flex-direction: column; flex: 1; min-width: 320px; }

.pane-header {
  padding: 6px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ---- editor ---- */
#editor-wrap {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: var(--bg);
  display: flex;
}
#gutter {
  flex-shrink: 0;
  padding: 12px 8px 12px 12px;
  text-align: right;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: var(--font-size);
  line-height: var(--line-height);
  background: var(--bg-panel);
  user-select: none;
  overflow: hidden;
  white-space: pre;
}
#gutter .cur { color: var(--yellow); font-weight: 700; }
#editor-scroll { position: relative; flex: 1; overflow: auto; }
#highlight-layer {
  position: absolute;
  top: 12px; left: 0; right: 0;
  pointer-events: none;
}
#current-line-band {
  position: absolute;
  left: 0; right: 0;
  height: var(--line-height);
  background: var(--highlight);
  border-left: 3px solid var(--yellow);
  display: none;
}
#code {
  position: relative;
  width: 100%;
  min-height: 100%;
  margin: 0;
  padding: 12px 12px 40vh 12px;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: var(--font-size);
  line-height: var(--line-height);
  white-space: pre;
  overflow-wrap: normal;
  tab-size: 2;
  caret-color: var(--accent);
}

/* ---- tabs / right pane ---- */
#tabs { display: flex; background: var(--bg-panel); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.tab {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .badge {
  display: inline-block;
  min-width: 16px;
  padding: 0 5px;
  margin-left: 6px;
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 10px;
  text-align: center;
}

.tab-panel { flex: 1; overflow: auto; display: none; }
.tab-panel.active { display: block; }

/* ---- console ---- */
#console {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 12px;
}
#console .out { white-space: pre-wrap; word-break: break-word; }
#console .err { color: var(--red); white-space: pre-wrap; }
#console .sys { color: var(--text-dim); font-style: italic; }
#console .input-line { display: flex; align-items: center; gap: 8px; margin: 2px 0; }
#console .input-line .prompt { color: var(--green); }
#console .input-line input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 3px 8px;
}
#console .input-done { color: var(--green); }
#console .input-done .val { color: var(--text); }

/* ---- variable inspector ---- */
#vars table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13px; }
#vars th {
  text-align: left;
  padding: 6px 12px;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--bg);
}
#vars td { padding: 5px 12px; border-bottom: 1px solid var(--bg-elevated); vertical-align: top; }
#vars td.name { color: var(--accent); }
#vars td.val { color: var(--text); word-break: break-word; }
#vars td.type { color: var(--text-dim); font-size: 11px; }
#vars tr.changed td { background: rgba(166, 227, 161, 0.08); }
#vars .empty, #files .empty { padding: 16px 12px; color: var(--text-dim); font-style: italic; }

/* ---- files ---- */
#files { padding: 10px 12px; }
#files .file { margin-bottom: 14px; }
#files .file label { display: block; color: var(--accent); font-family: var(--mono); font-size: 12px; margin-bottom: 4px; }
#files textarea {
  width: 100%;
  min-height: 70px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 8px;
  resize: vertical;
}
#files .add-file { display: flex; gap: 8px; margin-top: 6px; }
#files .add-file input {
  flex: 1; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); font-family: var(--mono); padding: 5px 8px; font-size: 12px;
}

/* ---- status bar ---- */
#status {
  padding: 4px 12px;
  font-size: 12px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  flex-shrink: 0;
  display: flex;
  gap: 16px;
}
#status .dot { color: var(--text-dim); }
#status.running .state { color: var(--green); }
#status.error .state { color: var(--red); }
#status.paused .state { color: var(--yellow); }
