.mpide {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --line: #dcdcd6;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --accent: #1f6feb;
  --ok: #1a7f37;
  --warn: #9a6700;
  --bad: #cf222e;
  --term-bg: #ffffff;
  --term-head: #6b6b66;
  --term-line: #dcdcd6;
  color-scheme: light;
}
/* idecore.js sets data-theme: the page's choice (option theme), else the system's, followed live */
.mpide[data-theme=dark] {
  --bg: #111214;
  --panel: #1a1b1e;
  --line: #2c2e33;
  --text: #e6e6e3;
  --muted: #9a9a94;
  --accent: #4c8dff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --term-bg: #0d0e10;
  --term-head: #c9c9c4;
  --term-line: #2c2e33;
  color-scheme: dark;
}
.mpide, .mpide * { box-sizing: border-box; }
.mpide {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: flex;
  flex-direction: column;
}
.mpide button, .mpide input { font: inherit; color: inherit; }
.mpide button, .mpide .file-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.mpide button:hover:not(:disabled), .mpide .file-btn:hover { border-color: var(--accent); }
.mpide button:disabled { opacity: .45; cursor: default; }
.mpide input:not([type=checkbox]) {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
  min-width: 0;
}
.mpide .bar {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
/* row 1: name, connection state, menus; row 2: the connect form, wrapping only within itself */
.mpide .bar-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 16px 6px; position: relative; }
.mpide .bar-top .spacer { flex: 1; }
.mpide .brand { font-size: 15px; }
.mpide .badge { font-size: 11px; font-weight: 500; color: var(--warn); border: 1px solid var(--warn); border-radius: 8px; padding: 0 6px; margin-left: 4px; vertical-align: 2px; }
.mpide .connect { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 6px 16px 8px; border-top: 1px solid var(--line); background: var(--bg); }
.mpide .connect label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.mpide .connect #url { width: 180px; }
.mpide .connect #key { width: 110px; }
.mpide .check { cursor: pointer; }
.mpide .status { font-size: 13px; padding: 2px 8px; border-radius: 10px; border: 1px solid var(--line); }
.mpide .status[data-state=on] { color: var(--ok); border-color: var(--ok); }
.mpide .status[data-state=busy] { color: var(--warn); border-color: var(--warn); }
.mpide .status[data-state=error] { color: var(--bad); border-color: var(--bad); }

/* link health: dot + round trip times + ping, a chip at the REPL's bottom right */
.mpide .health {
  position: absolute; right: 26px; bottom: 10px; z-index: 5;
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap;
  color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 2px 3px 2px 9px;
  opacity: .92;
}
.mpide .health:hover { opacity: 1; }
.mpide .health[hidden] { display: none; }
.mpide .health .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.mpide .health[data-state=ok] .dot { background: var(--ok); }
.mpide .health[data-state=slow] .dot { background: var(--warn); }
.mpide .health[data-state=bad] .dot { background: var(--bad); }
.mpide .health[data-state=busy] .dot { background: var(--accent); }
.mpide .health[data-state=bad] { color: var(--bad); }
.mpide .health .dot.beat { animation: beat .6s ease-out; }
@keyframes beat { from { box-shadow: 0 0 0 0 currentColor; transform: scale(1.5); } to { box-shadow: 0 0 0 6px transparent; transform: scale(1); } }
.mpide #pingBtn { font-size: 12px; padding: 0 8px; border-radius: 10px; }

/* board resources under the file list: one row per resource, bar = used share, text = what is left */
.mpide .usage { border-top: 1px solid var(--line); padding: 8px 10px 4px; display: grid; gap: 7px; font-size: 12px; cursor: pointer; }
.mpide .usage-head { display: flex; justify-content: space-between; color: var(--muted); font-weight: 500; }
.mpide .usage-age { font-weight: 400; font-variant-numeric: tabular-nums; }
.mpide .usage-rows { display: grid; gap: 7px; }
.mpide .usage-row { display: grid; gap: 2px; }
.mpide .usage-top { display: flex; justify-content: space-between; gap: 8px; }
.mpide .usage-top b { font-weight: 500; }
.mpide .usage-top span { font-variant-numeric: tabular-nums; white-space: nowrap; }
.mpide .usage-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.mpide .usage-bar i { display: block; height: 100%; background: var(--accent); }
.mpide .usage-bar i.warn { background: var(--warn); }
.mpide .usage-bar i.bad { background: var(--bad); }
.mpide .usage-detail { color: var(--muted); font-variant-numeric: tabular-nums; }
.mpide .usage-old { color: var(--muted); }
@media (max-width: 760px) { .mpide .usage:not([hidden]) { display: none; } }

.mpide .layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 240px 1fr;
  /* editor and REPL share the height (editor larger); a dragged REPL height (--term-h, px) replaces the default */
  grid-template-rows: minmax(120px, 1fr) 7px var(--term-h, minmax(120px, .75fr));
  grid-template-areas: "files editor" "files split" "files term";
}
/* the bar between the editor and the REPL: drag it (or focus it and use the arrow keys); double-click resets */
.mpide .splitter {
  grid-area: split;
  cursor: row-resize;
  background: var(--line);
  position: relative;
  touch-action: none;
}
.mpide .splitter::after {
  content: "";
  position: absolute; left: 50%; top: 2px;
  width: 36px; height: 3px; margin-left: -18px;
  border-radius: 2px;
  background: var(--muted);
  opacity: .55;
}
.mpide .splitter:hover, .mpide .splitter:focus-visible, .mpide .splitter.dragging { background: var(--accent); outline: none; }
.mpide .splitter:hover::after, .mpide .splitter.dragging::after { background: #fff; opacity: .9; }
.mpide.resizing { cursor: row-resize; user-select: none; }
.mpide.resizing iframe, .mpide.resizing .terminal { pointer-events: none; }
.mpide .files { grid-area: files; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.mpide .editor-pane { grid-area: editor; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.mpide .term-pane { grid-area: term; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--term-bg); position: relative; }

.mpide .files-head, .mpide .editor-head, .mpide .term-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line);
}
.mpide .term-head { color: var(--term-head); border-color: var(--term-line); }
.mpide .tools { margin-left: auto; display: flex; gap: 4px; }
.mpide .cwd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.mpide .file-list { list-style: none; margin: 0; padding: 4px 0; overflow: auto; flex: 1; }
.mpide .file-list li { display: flex; align-items: center; gap: 6px; padding: 3px 10px; cursor: pointer; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.mpide .file-list li:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.mpide .file-list li.active { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.mpide .file-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mpide .file-list .size { color: var(--muted); font-size: 11px; }
.mpide .file-list .acts { display: none; gap: 2px; }
.mpide .file-list li:hover .acts { display: flex; }
.mpide .file-list .acts button { padding: 0 5px; font-size: 12px; }
.mpide .hint { color: var(--muted); font-size: 12px; margin: 6px 10px 10px; }
.mpide .file-name { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.mpide .dirty { color: var(--warn); }
.mpide .board-info { font-size: 12px; color: #8b8b86; }
.mpide .editor { flex: 1; min-height: 0; }
.mpide .editor .CodeMirror { height: 100%; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.mpide .terminal { flex: 1; min-height: 0; padding: 4px 6px; }
.mpide .progress { position: relative; height: 18px; background: var(--line); }
.mpide .progress > div { height: 100%; width: 0; background: var(--accent); transition: width .1s; }
.mpide .progress span { position: absolute; inset: 0; font-size: 12px; text-align: center; line-height: 18px; color: var(--text); }

@media (max-width: 760px) {
  /* the file list takes a share too, so a short window still leaves the editor several lines */
  .mpide .layout { grid-template-columns: 1fr; grid-template-rows: minmax(100px, .6fr) minmax(120px, 1fr) 7px var(--term-h, minmax(120px, .75fr)); grid-template-areas: "files" "editor" "split" "term"; }
  .mpide .files { border-right: 0; border-bottom: 1px solid var(--line); }
  .mpide .files .hint { display: none; } /* the drag-and-drop hint: rows for files instead */
  .mpide .connect #url { width: 100%; }
  .mpide .bar { padding: 8px 16px; }
}
.mpide .setup-link { font-size: 13px; color: var(--accent); text-decoration: none; }
.mpide .setup-link:hover { text-decoration: underline; }
.mpide .files.drop { outline: 2px dashed var(--accent); outline-offset: -4px; background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }

/* examples menu (top bar) */
.mpide .examples { position: relative; }
.mpide .examples summary {
  list-style: none;
  font-size: 13px;
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
  background: var(--panel);
  white-space: nowrap;
}
.mpide .examples summary::-webkit-details-marker { display: none; }
.mpide .examples summary:hover, .mpide .examples[open] summary { border-color: var(--accent); }
.mpide .examples .caret { font-size: 10px; margin-left: 2px; }
.mpide .examples-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: min(380px, calc(100vw - 32px));
  max-height: 70vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgb(0 0 0 / .22);
}
.mpide .example-list { list-style: none; margin: 0; padding: 0; }
/* one section per kind: a tinted header with a colored bar, then the indented examples */
.mpide .example-section + .example-section { border-top: 1px solid var(--line); }
.mpide .example-section { --kind: var(--accent); }
.mpide .example-section[data-kind=main] { --kind: var(--warn); }
.mpide .example-head {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 9px 14px 8px 12px;
  border-left: 4px solid var(--kind);
  background: color-mix(in srgb, var(--kind) 10%, var(--panel));
}
.mpide .example-head strong { font-size: 13px; color: var(--kind); letter-spacing: .02em; }
.mpide .example-head small { font-size: 12px; color: var(--muted); }
.mpide .example-items { list-style: none; margin: 0; padding: 4px 6px 8px 16px; }
.mpide .example-items button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  padding: 6px 8px 6px 10px;
  white-space: normal;
  background: transparent;
}
.mpide .example-items button:hover { background: var(--bg); border-left-color: var(--kind); }
.mpide .example-title { font-size: 14px; font-weight: 600; }
.mpide .example-pins { color: var(--muted); font-size: 11px; margin-left: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; }
.mpide .example-about { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.mpide .example-empty { color: var(--muted); font-size: 13px; padding: 10px 14px; }
@media (max-width: 760px) {
  /* narrow: the menu spans the bar (16px gutters) instead of hanging off the button */
  .mpide .examples { position: static; }
  .mpide .examples-menu { left: 16px; right: 16px; top: calc(100% - 4px); width: auto; }
}

/* a long task is running (withTask in ide.js): show it on the run area too */
.mpide.task-busy #runBtn, .mpide.task-busy #saveBtn { cursor: progress; }
.mpide.task-busy .status[data-state="busy"]::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; vertical-align: -1px; animation: task-spin .8s linear infinite; }
@keyframes task-spin { to { transform: rotate(360deg); } }

/* [hidden] wins over the display rules above (the board resources panel before connecting) */
.mpide [hidden] { display: none !important; }
