:root {
  --bg: #0f1115; --panel: #151821; --panel2: #1c2030; --line: #262b3a;
  --text: #e5e7eb; --muted: #8b93a7; --accent: #4ade80; --accent-ink: #052e16;
  --err: #f87171; --warn: #fbbf24; --info: #60a5fa;
  --fs: 14px; --out-w: 42%;
  --mono: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
}
:root[data-theme="light"] {
  --bg: #f6f7f9; --panel: #ffffff; --panel2: #eef0f4; --line: #dfe2e8;
  --text: #1f2330; --muted: #6b7280; --accent: #16a34a; --accent-ink: #ffffff;
  --err: #dc2626; --warn: #b45309; --info: #2563eb;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
#app { display: grid; grid-template-rows: auto 1fr; height: 100vh; height: 100dvh; }

header { display: flex; align-items: center; gap: 6px; padding: 7px 12px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 15px; margin-right: 10px; letter-spacing: .3px; }
.brand .logo { color: var(--accent-ink); background: var(--accent); padding: 1px 5px; border-radius: 5px; margin-right: 2px; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.spacer { flex: 1; }

button, input { font: inherit; color: var(--text); }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 11px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger:not(:disabled) { color: var(--err); border-color: var(--err); }
button.icon { padding: 5px 8px; }
button.link { background: none; border: 0; color: var(--muted); padding: 2px 4px; }
button.link:hover { color: var(--text); }
input { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; outline: none; }
input:focus { border-color: var(--accent); }

.status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; margin-right: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.idle { background: var(--accent); }
.dot.busy { background: var(--warn); animation: pulse 1s infinite; }
.dot.loading { background: var(--info); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

main { display: grid; grid-template-columns: 220px minmax(0, 1fr) 5px var(--out-w); min-height: 0; }

aside { background: var(--panel); border-right: 1px solid var(--line); overflow: auto; padding-bottom: 12px; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 4px; }
.side-head h2, .out-head h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0; }
#files, #pkgs { list-style: none; margin: 0; padding: 0 6px; }
#files li, #pkgs li { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 5px; }
#files li { cursor: pointer; }
#files li:hover, #pkgs li:hover { background: var(--panel2); }
#files li.active { background: var(--panel2); color: var(--accent); }
#files .ext { font: 10px var(--mono); color: var(--muted); width: 22px; }
#files li.active .ext { color: var(--accent); }
#files .name, #pkgs .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pkgs .name { font-family: var(--mono); font-size: 12px; }
.x { color: var(--muted); background: none; border: 0; padding: 0 4px; visibility: hidden; }
li:hover .x { visibility: visible; }
.x:hover { color: var(--err); }
.pkg-row { display: flex; gap: 6px; padding: 4px 12px 6px; }
.pkg-row input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12px; }
.hint { color: var(--muted); font-size: 11px; padding: 4px 14px 0; margin: 0; }
code { font-family: var(--mono); font-size: 11px; background: var(--panel2); padding: 0 3px; border-radius: 3px; }

#editor { min-height: 0; min-width: 0; }
.CodeMirror { height: 100%; font-family: var(--mono); font-size: var(--fs); line-height: 1.55; }
:root[data-theme="light"] .CodeMirror { background: #fff; }
:root[data-theme="light"] .CodeMirror-activeline-background { background: #f3f5f9; }
.CodeMirror-dialog { background: var(--panel2); color: var(--text); }
.CodeMirror-dialog input { color: var(--text); }

#split { cursor: col-resize; background: var(--line); }
#split:hover { background: var(--accent); }

#right { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; background: var(--bg); }
.out-head { display: flex; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
#out { overflow: auto; padding: 10px 12px; font: calc(var(--fs) - 1px)/1.5 var(--mono);
  white-space: pre-wrap; word-break: break-word; }
#out .err { color: var(--err); }
#out .sys { color: var(--muted); }
#out .in { color: var(--warn); }
#out img { display: block; max-width: 100%; margin: 8px 0; border-radius: 6px; background: #fff; }
.term-input { display: inline-block; min-width: 50%; background: none; border: 0; border-bottom: 1px dashed var(--warn);
  border-radius: 0; color: var(--warn); font: inherit; padding: 0 2px; }
#repl { display: flex; align-items: center; border-top: 1px solid var(--line); background: var(--panel); }
#repl .prompt { padding-left: 12px; color: var(--accent); font-family: var(--mono); }
#repl input { flex: 1; border: 0; background: none; font-family: var(--mono); padding: 9px 8px; }

.CodeMirror-hints { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  font-family: var(--mono); font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.35); z-index: 50; }
.CodeMirror-hint { color: var(--text); padding: 2px 8px; }
li.CodeMirror-hint-active { background: var(--accent); color: var(--accent-ink); }
.CodeMirror-hint::after { float: right; margin-left: 14px; font-size: 10px; opacity: .6; }
.hint-function::after { content: "fn"; }
.hint-class::after { content: "class"; }
.hint-module::after { content: "mod"; }
.hint-keyword::after { content: "kw"; }
.hint-instance::after, .hint-statement::after { content: "var"; }
.hint-param::after { content: "param"; }
.hint-property::after { content: "prop"; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--panel2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px;
  transition: .2s; pointer-events: none; z-index: 100; }
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto 48vh 0 48vh; overflow: auto; }
  aside { max-height: 210px; border-right: 0; border-bottom: 1px solid var(--line); }
  #split { display: none; }
  .sep, #fontDown, #fontUp { display: none; }
}
