:root {
  --blue: #0b2a6b;
  --fg: #e8e8e8;
  --hi: #f5d76e;
  --get: #1d5fd1;
  --page: #141414;
  --panel: #1b1b1b;
  --panel2: #222;
  --line: #333;
  --muted: #9a9a9a;
  --row: 1.17em; /* tight rows so box-drawing lines join up */
  --mono: "DejaVu Sans Mono", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--page); color: var(--fg); font: 14px/1.4 system-ui, sans-serif; display: flex; flex-direction: column; }
#env-badge { background: #e65100; color: #fff; font-weight: 700; font-size: 12px; letter-spacing: .08em; padding: 1px 8px; border-radius: 4px; }
header { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 12px; }
.mono { font-family: var(--mono); }
code { font-family: var(--mono); font-size: 12px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: #2b2b2b; color: var(--muted); }
.badge.warn { background: #4a3a10; color: #f5d76e; }
.badge.danger { background: #4a1616; color: #ff9b9b; }
button { font: inherit; font-size: 13px; color: var(--fg); background: #2b2b2b; border: 1px solid #444; border-radius: 6px; padding: 3px 10px; cursor: pointer; }
button:hover { background: #363636; }
button.icon { padding: 0 7px; line-height: 1.4; }
button:disabled { opacity: .4; cursor: default; background: #2b2b2b; }

/* ---- IDE grid */
.ide { flex: 1; min-height: 0; display: grid; position: relative;
  grid-template-columns: 210px minmax(0, 1fr) minmax(320px, 40%);
  grid-template-rows: minmax(0, 1fr) 210px; }
#tree { grid-row: 1 / 3; grid-column: 1; border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 6px 0; }
#editor-pane { grid-row: 1; grid-column: 2; display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--line); }
#browse-pane { grid-row: 1; grid-column: 3; display: flex; flex-direction: column; min-width: 0; }
#console-pane { grid-row: 2; grid-column: 2 / 4; border-top: 1px solid var(--line); display: flex; flex-direction: column; background: var(--blue); font: 13px/1.35 var(--mono); padding: 4px 8px; min-height: 0; }
@media (max-width: 900px) {
  .ide { grid-template-columns: 1fr; grid-template-rows: auto 50vh 50vh 220px; }
  #tree { grid-row: 1; grid-column: 1; max-height: 160px; }
  #editor-pane { grid-row: 2; grid-column: 1; }
  #browse-pane { grid-row: 3; grid-column: 1; }
  #console-pane { grid-row: 4; grid-column: 1; }
}
.pane-head { display: flex; align-items: center; gap: 8px; padding: 4px 8px; background: var(--panel2); border-bottom: 1px solid var(--line); min-height: 32px; }

/* ---- tree */
.tree-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
#tree ul { list-style: none; margin: 0 0 6px; padding: 0; }
#tree li { display: flex; align-items: center; gap: 6px; padding: 2px 10px; cursor: pointer; font-family: var(--mono); font-size: 13px; }
#tree li:hover { background: #262626; }
#tree li.active { background: #263a5e; }
#tree li .count { margin-left: auto; color: var(--muted); font-size: 11px; }
#tree li .act { display: none; margin-left: auto; gap: 2px; }
#tree li:hover .act { display: flex; }
#tree li .act button { padding: 0 4px; font-size: 11px; line-height: 1.3; }
.tree-hint { padding: 0 10px; }

/* ---- editor (editor.js) */
#editor-host { flex: 1; min-height: 0; position: relative; display: flex; background: var(--panel); }
.gutter { width: 44px; flex: none; overflow: hidden; background: var(--panel2); border-right: 1px solid var(--line); color: #666; font: 13px/1.5 var(--mono); padding-top: 8px; text-align: right; user-select: none; }
.gutter .ln { padding-right: 8px; }
.gutter .ln.has-err { color: #ff8a80; background: #3a1d1d; cursor: help; }
.code-view { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.code-hl, .code-input { margin: 0; padding: 8px 10px; font: 13px/1.5 var(--mono); tab-size: 3; white-space: pre; letter-spacing: 0; }
.code-hl { position: absolute; top: 0; left: 0; min-width: 100%; color: var(--fg); pointer-events: none; }
.code-input { position: absolute; inset: 0; width: 100%; height: 100%; resize: none; border: 0; outline: none; background: transparent; color: transparent; caret-color: #fff; overflow: auto; }
.code-input::selection { background: rgba(110, 168, 255, .35); color: transparent; }
.code-measure { position: absolute; visibility: hidden; font: 13px/1.5 var(--mono); white-space: pre; }
.tk { color: #c792ea; } .tf { color: #82aaff; } .tu { color: #82aaff; font-style: italic; } .td { color: #ffcb6b; }
.ta { color: #ffcb6b; } .ts { color: #c3e88d; } .tn { color: #f78c6c; } .tc { color: #6a737d; font-style: italic; }
.err { text-decoration: underline wavy #ff5370; text-decoration-skip-ink: none; text-underline-offset: 3px; }
.err-eol { background: rgba(255, 83, 112, .35); }
.complete { position: absolute; z-index: 5; margin: 0; padding: 2px 0; list-style: none; min-width: 240px; max-height: 260px; overflow-y: auto; background: #262626; border: 1px solid #444; border-radius: 6px; font: 12px/1.6 var(--mono); box-shadow: 0 4px 16px rgba(0, 0, 0, .4); }
.complete li { display: flex; gap: 12px; justify-content: space-between; padding: 0 8px; cursor: pointer; }
.complete li.sel { background: #263a5e; }
.complete .d { color: var(--muted); }
.k-field { color: #ffcb6b; } .k-func { color: #82aaff; } .k-kw { color: #c792ea; }
.hover-tip { position: absolute; z-index: 6; max-width: 70%; padding: 4px 8px; background: #2b2b2b; border: 1px solid #444; border-radius: 6px; font: 12px/1.5 var(--mono); white-space: pre-wrap; pointer-events: none; }
#editor-foot { border-top: 1px solid var(--line); background: var(--panel2); }
#field-info { padding: 2px 10px; min-height: 1.5em; }
#problems { list-style: none; margin: 0; padding: 0; max-height: 96px; overflow-y: auto; font: 12px/1.5 var(--mono); }
#problems li { padding: 1px 10px; cursor: pointer; color: #ff8a80; }
#problems li:hover { background: #2a2a2a; }
#problems li.ok { color: #8bc34a; cursor: default; }

/* ---- browse */
#browse-wrap { flex: 1; overflow: auto; min-height: 0; }
#browse-empty { padding: 12px; }
#browse { border-collapse: collapse; font: 12px/1.4 var(--mono); width: max-content; min-width: 100%; }
#browse th { position: sticky; top: 0; background: var(--panel2); color: var(--muted); font-weight: normal; text-align: left; padding: 3px 8px; border-bottom: 1px solid var(--line); }
#browse td { padding: 2px 8px; border-bottom: 1px solid #262626; white-space: pre; cursor: default; }
#browse td.num { text-align: right; }
#browse td.rec { color: var(--muted); text-align: right; }
#browse tr.current td { background: #263a5e; }
#browse tr.deleted td { color: #8a6b6b; text-decoration: line-through; }
#browse td input { font: inherit; width: 100%; min-width: 6ch; background: var(--hi); color: var(--blue); border: 0; outline: none; padding: 0 2px; }

/* ---- console */
#output { flex: 1; overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
#output .err { color: var(--hi); }
#output .cmd { color: #9fc3ff; }
#prompt-row { display: flex; align-items: center; }
#input { flex: 1; background: transparent; color: var(--fg); border: 0; outline: none; font: inherit; padding: 0; }
#status { color: #b9c7e6; font-size: 11px; }

/* ---- run screen */
#run-overlay { position: absolute; z-index: 10; inset: 33px 0 210px 210px; /* below the pane headers: Run/Stop stays reachable */ display: flex; align-items: flex-start; justify-content: center; padding: 12px; background: rgba(0, 0, 0, .45); overflow: auto; }
#run-overlay[hidden] { display: none; }
.classic { background: var(--blue); color: var(--fg); font: 15px/1.35 var(--mono); width: calc(80ch + 16px); max-width: 100%; padding: 4px 8px 8px; border-radius: 6px; }
.run-head { display: flex; align-items: center; font: 12px system-ui, sans-serif; color: #b9c7e6; padding: 2px 0 4px; }
.run-head button { background: transparent; border-color: #4a64a0; color: var(--fg); }
#grid { position: relative; white-space: pre; line-height: var(--row); }
#grid .row { height: var(--row); }
#grid input { position: absolute; height: var(--row); line-height: var(--row); padding: 0; border: 0; margin: 0; font: inherit; background: var(--get); color: #fff; outline: none; }
#grid input:focus { background: var(--hi); color: var(--blue); }
#grid input[readonly] { background: #3b4f7a; color: #cfd8ea; }
.bar { background: var(--fg); color: var(--blue); white-space: pre; margin-top: 4px; padding: 0 4px; min-height: 1.35em; }
.bar.error { background: var(--hi); }
