:root {
  --bg: #1e1e1e;
  --panel: #252526;
  --border: #3c3c3c;
  --text: #d4d4d4;
  --text-muted: #999;
  --text-faint: #777;
  --accent: #0e639c;
  --accent-hover: #1177bb;
  --accent-text: #ffffff;
  --control-bg: #333333;
  --control-hover: #3e3e3e;
  --hover-bg: #2a2d2e;
  --menu-bg: #2d2d2d;
  --output-bg: #181818;
  --shadow: rgba(0, 0, 0, 0.4);
  --ok: #3fb950;
  --ok-hover: #56d367;
  --warn: #d29922;
  --err: #f85149;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --panel: #f3f3f3;
  --border: #d4d4d4;
  --text: #1e1e1e;
  --text-muted: #5f5f5f;
  --text-faint: #8a8a8a;
  --accent: #0e639c;
  --accent-hover: #0b5a8a;
  --accent-text: #ffffff;
  --control-bg: #e8e8e8;
  --control-hover: #dcdcdc;
  --hover-bg: #e4e4e4;
  --menu-bg: #ffffff;
  --output-bg: #f5f5f5;
  --shadow: rgba(0, 0, 0, 0.15);
  --ok: #1a7f37;
  --ok-hover: #15642c;
  --warn: #9a6700;
  --err: #cf222e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

body.resizing-h { cursor: col-resize; user-select: none; }
body.resizing-v { cursor: row-resize; user-select: none; }

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#topbar h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 30px;
  height: 30px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
}
.hamburger-btn:hover:not(:disabled) {
  background: var(--control-bg);
  border-color: var(--border);
}
.hamburger-btn span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}

.theme-toggle {
  font-size: 15px;
  line-height: 1;
  padding: 4px 8px;
}

.guide-link {
  font-size: 12.5px;
  color: var(--accent-hover);
  text-decoration: none;
}
.guide-link:hover { text-decoration: underline; }

.status {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.status-loading { color: var(--warn); border-color: var(--warn); }
.status-idle { color: var(--text-muted); }
.status-ok { color: var(--ok); border-color: var(--ok); }
.status-warn { color: var(--warn); border-color: var(--warn); }
.status-err { color: var(--err); border-color: var(--err); }

#layout {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

#sidebar {
  width: 300px;
  flex: 0 0 auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
  position: relative;
}

body.sidebar-collapsed #sidebar,
body.sidebar-collapsed #sidebar-resizer {
  display: none;
}

#sidebar h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 16px 0 6px;
}

#sidebar .hint {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 0 6px;
  line-height: 1.4;
}

#sidebar .hint a { color: var(--accent-hover); }
#sidebar .hint code { color: var(--text-muted); }

.ref-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
}

.ref-picker label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.ref-picker input {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  padding: 2px 6px;
  font-family: "SF Mono", Consolas, Menlo, monospace;
}

.example-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.example-list li {
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12.5px;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.example-list li:hover {
  background: var(--hover-bg);
}

.example-list li.category {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.example-list li.category::before {
  content: "\25B8 ";
  display: inline-block;
  width: 12px;
}

.example-list li.category.open::before {
  content: "\25BE ";
}

.example-list li.file {
  padding-left: 22px;
  color: var(--text-muted);
}

.example-list li.loading,
.example-list li.empty {
  padding-left: 22px;
  color: var(--text-faint);
  font-style: italic;
  cursor: default;
}

/* Drag handles between resizable panels */
.resizer {
  flex-shrink: 0;
  background: var(--border);
}
.resizer-v {
  width: 4px;
  cursor: col-resize;
}
.resizer-v:hover { background: var(--accent); }
.resizer-h {
  height: 4px;
  cursor: row-resize;
}
.resizer-h:hover { background: var(--accent); }

#editors {
  flex: 1;
  display: flex;
  min-width: 0;
}

.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pane-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.pane-title {
  font-weight: 600;
  font-size: 12.5px;
}

.filename {
  font-size: 11.5px;
  color: var(--text-muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cursor-pos {
  font-size: 11px;
  color: var(--text-muted);
  font-family: "SF Mono", Consolas, Menlo, monospace;
  white-space: nowrap;
}

button, select, input[type="text"] {
  background: var(--control-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
}

button { cursor: pointer; }
button:hover:not(:disabled) { background: var(--control-hover); }
button:disabled { opacity: 0.5; cursor: default; }
input[type="text"]:focus {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

/* Split button (GitHub merge-button style): main action + caret + menu */
.split-button {
  display: flex;
  position: relative;
}
.split-button #instrument-btn {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  border-radius: 4px 0 0 4px;
  border-right: 1px solid rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}
.split-button #instrument-btn:hover:not(:disabled) { background: var(--accent-hover); }
.split-button #instrument-caret {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  border-radius: 0 4px 4px 0;
  padding: 4px 6px;
}
.split-button #instrument-caret:hover:not(:disabled) { background: var(--accent-hover); }
.split-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--menu-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 10;
  min-width: 220px;
  overflow: hidden;
}
.split-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 0;
  padding: 8px 12px;
}
.split-menu button:hover { background: var(--accent); color: var(--accent-text); }

#compile-run-btn {
  background: var(--ok);
  color: var(--accent-text);
  border-color: var(--ok);
  white-space: nowrap;
}
#compile-run-btn:hover:not(:disabled) {
  background: var(--ok-hover);
  border-color: var(--ok-hover);
}

.monaco-container {
  flex: 1;
  min-height: 0;
}

/* Decorations marking instrumentation calls in the C editor */
.cwt-yield-call {
  background: rgba(214, 158, 46, 0.28);
  border-radius: 2px;
}
.cwt-release-call {
  background: rgba(46, 160, 110, 0.28);
  border-radius: 2px;
}

#output-panel {
  flex-shrink: 0;
  height: 220px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: var(--output-bg);
}

#output-panel.collapsed {
  height: auto;
}

#output-resizer.collapsed {
  display: none;
}

.output-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.output-toolbar button { padding: 2px 8px; }

#output-panes {
  flex: 1;
  display: flex;
  min-height: 0;
}

.output-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.output-pane:last-child { border-right: none; }

.output-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.output-pane-header button { padding: 1px 6px; font-size: 10.5px; font-weight: 400; }

.output-content {
  margin: 0;
  padding: 8px 12px;
  overflow: auto;
  font-family: "SF Mono", Consolas, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  flex: 1;
}

#output-panel.collapsed #output-panes { display: none; }
