:root {
  --bg: #1e1e1e; --panel: #252526; --border: #3c3c3c; --text: #e6e6e6; --muted: #9aa0a6;
  --primary: #2e8b57; --accent: #7c4dff; --danger: #d64545; --btn: #3a3d41;
  --err: #ff6b6b; --info: #8ab4f8; --changed: rgba(255, 213, 79, .25); --line: rgba(124, 77, 255, .3);
}
[data-theme="light"] {
  --bg: #ffffff; --panel: #f5f6f8; --border: #d0d4da; --text: #1f2328; --muted: #5f6b7a;
  --btn: #e4e7ec; --err: #c62828; --info: #1a5fb4; --changed: rgba(255, 193, 7, .35); --line: rgba(124, 77, 255, .18);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: system-ui, "Segoe UI", sans-serif; }

.app { display: flex; flex-direction: column; height: 100%; }
.spacer { flex: 1; }
.hidden { display: none !important; }

.toolbar, .tabs { display: flex; align-items: center; gap: 8px; padding: 8px; background: var(--panel); border-bottom: 1px solid var(--border); }
.status { color: var(--muted); font-size: 13px; }

.btn, select {
  background: var(--btn); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 14px; font-size: 14px; cursor: pointer; font-family: inherit;
}
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.test { background: #1f7a9c; border-color: #1f7a9c; color: #fff; }
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.editor-pane { border-right: 1px solid var(--border); }
#editor { flex: 1; min-height: 0; }

@media (max-width: 800px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1.2fr 1fr; }
  .editor-pane { border-right: 0; border-bottom: 1px solid var(--border); }
}

.tabs { padding: 0 8px; gap: 2px; }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); padding: 9px 14px; font-size: 14px; cursor: pointer; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.terminal {
  flex: 1; overflow: auto; padding: 10px; white-space: pre-wrap; word-break: break-word;
  font: 15px/1.45 Consolas, "Courier New", monospace; outline: none;
}
.terminal .stderr { color: var(--err); }
.terminal .info { color: var(--info); font-style: italic; }
.terminal input {
  background: transparent; border: 0; border-bottom: 1px solid var(--muted); color: inherit;
  font: inherit; outline: none; width: 14ch; min-width: 4ch;
}

.dbg-controls { display: flex; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
#dbg-slider { flex: 1; min-width: 80px; }
.dbg-count { font-size: 13px; color: var(--muted); min-width: 80px; text-align: right; }
.dbg-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; }
.dbg-col { overflow: auto; padding: 8px 12px; min-width: 0; }
.dbg-col + .dbg-col { border-left: 1px solid var(--border); }
.dbg-col h3 { margin: 6px 0; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dbg-empty { padding: 20px; color: var(--muted); }

.frame { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; overflow: hidden; }
.frame-head { background: var(--panel); padding: 5px 10px; font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; }
.frame-head span { font-weight: 400; color: var(--muted); }
.frame table { width: 100%; border-collapse: collapse; font: 14px Consolas, monospace; }
.frame td { padding: 4px 10px; border-top: 1px solid var(--border); vertical-align: top; word-break: break-all; }
.frame td.name { width: 30%; font-weight: 600; }
.frame td .type { color: var(--muted); font-size: 11px; margin-left: 6px; }
.frame tr.changed td { background: var(--changed); }
.frame .none { padding: 6px 10px; color: var(--muted); font-size: 13px; }

.dbg-next-line { font: 14px Consolas, monospace; background: var(--panel); border-left: 4px solid var(--accent); padding: 8px 10px; border-radius: 4px; white-space: pre-wrap; margin-bottom: 8px; }
.dbg-next-line.error { border-left-color: var(--err); color: var(--err); }
.dbg-output { margin: 0; font: 14px Consolas, monospace; white-space: pre-wrap; word-break: break-word; }

/* Monaco decorations */
.tests-results { flex: 1; overflow: auto; padding: 10px 12px; }
.tests-results:empty::before { content: "Press ✔ Test to check your code against the challenge."; color: var(--muted); }
.test-summary { font-weight: 700; padding: 8px 12px; border-radius: 6px; margin-bottom: 10px; }
.test-summary.pass { background: rgba(46, 139, 87, .25); }
.test-summary.fail { background: rgba(214, 69, 69, .2); }
.test-card { border: 1px solid var(--border); border-left-width: 5px; border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.test-card.pass { border-left-color: var(--primary); }
.test-card.fail { border-left-color: var(--err); }
.test-head { display: flex; justify-content: space-between; font-weight: 600; }
.test-inputs { font: 13px Consolas, monospace; color: var(--muted); font-weight: 400; }
.test-want, .test-label { font-size: 13px; color: var(--muted); margin: 4px 0; }
.test-detail { margin: 4px 0 8px; padding: 6px 8px; background: var(--panel); border-radius: 4px; font: 13px Consolas, monospace; white-space: pre-wrap; }
.test-detail.stderr { color: var(--err); }
.debug-line { background: var(--line); }
.debug-arrow::before { content: "▶"; color: #7c4dff; font-size: 12px; margin-left: 4px; }
.error-line { background: rgba(214, 69, 69, .3); }
