:root {
  --bg: #f6f4ee; --panel: #ffffff; --ink: #1d2330; --muted: #6b7280; --line: #e3e0d6;
  --accent: #2f7d4f; --accent-ink: #ffffff; --bad: #b42318; --bad-bg: #fde8e7;
  --code-bg: #fbfaf7;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
header h1 { font-size: 20px; margin: 0; }
.spacer { flex: 1; }
.status { color: var(--muted); font-size: 14px; }
main { display: grid; grid-template-columns: minmax(320px, 1fr) 432px; gap: 16px; padding: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.left, .side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
#editor { width: 100%; height: 460px; border-radius: 12px; overflow: hidden; background: var(--code-bg); }
/* Monaco marks */
.stop-sign { background: #d93025; clip-path: polygon(30% 0,70% 0,100% 30%,100% 70%,70% 100%,30% 100%,0 70%,0 30%); width: 14px !important; height: 14px !important; margin: 7px 0 0 4px; cursor: pointer; }
.monaco-editor .margin-view-overlays .cgmr { cursor: pointer; }
.monaco-editor .line-numbers { cursor: pointer !important; }
.ln-ran { background: #fff1a8; }
.ln-ran-edge { background: #e0b400; width: 4px !important; margin-left: 3px; }
.ln-next { background: #d7ecff; }
.ln-infunc { background: #cbb8ff; width: 4px !important; margin-left: 3px; }
.ghost-text { color: #9a8f6a !important; font-style: italic; }
#cv { display: block; width: 400px; height: 400px; margin: 15px auto; border: 1px solid var(--line); border-radius: 8px; }
.coords { text-align: center; color: var(--muted); font: 13px ui-monospace, monospace; padding-bottom: 8px; min-height: 26px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px; }
button { font: 600 16px system-ui; display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 10px; border: 2px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--ink); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-size: 18px; padding: 12px 22px; }
button svg { width: 20px; height: 20px; }
.speed { display: flex; align-items: center; gap: 8px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.error { padding: 12px 16px; background: var(--bad-bg); color: var(--bad); border-color: #f5c2bf; }
.error[hidden], .out[hidden], .warn[hidden] { display: none; }
#errText { font-size: 17px; font-weight: 600; }
.error .raw { margin-top: 4px; font: 13px ui-monospace, monospace; color: #8a2a22; opacity: .8; }
.warn { padding: 12px 16px; background: #fff7e0; color: #7a5300; border-color: #f0d48a; }
.warn code { font: 14px ui-monospace, monospace; }
.out { padding: 10px 16px; font: 15px/1.5 ui-monospace, monospace; white-space: pre-wrap; max-height: 200px; overflow: auto; }
.out h2 { font: 600 13px system-ui; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 4px; }
/* debugger toolbar */
.codepanel { overflow: hidden; position: relative; }
.controls { padding: 6px 8px; display: flex; align-items: center; gap: 4px; background: #f1efe7; border-bottom: 1px solid var(--line); }
.controls button { padding: 0; width: 32px; height: 32px; justify-content: center; border-width: 1px; border-radius: 8px; gap: 4px; }
.controls button svg { width: 16px; height: 16px; }
.controls button.primary { width: auto; padding: 0 12px 0 8px; font-size: 15px; }
#bExplain[aria-pressed="false"] { color: #b9b4a6; }
#speed { font: 600 14px system-ui; height: 32px; padding: 0 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); }
.codepanel #editor { border-radius: 0; }
/* turtle chips */
.turtles { padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 8px; min-height: 50px; }
.tchip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border: 2px solid var(--line); border-radius: 99px; }
.tchip.active { border-color: #e0b400; background: #fffbe6; }
.tchip svg { width: 28px; height: 28px; }
.tchip svg.pen { width: 18px; height: 18px; }
/* canvas bar */
.canvasbar { display: flex; justify-content: space-between; align-items: center; padding: 0 16px 10px; min-height: 30px; }
.canvasbar .coords { padding: 0; min-height: 0; }
/* variable boxes */
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 12px 16px 6px; }
.frames { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.frame { border: 2px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.frame.top { border-color: #7c4dff; }
.frame .fname { font-weight: 700; margin-bottom: 6px; }
.frame .fname small { font-weight: 400; color: var(--muted); }
.boxes { display: flex; flex-wrap: wrap; gap: 8px; }
.box { background: #eef6ff; border: 2px solid #8bb8e8; border-radius: 8px; min-width: 70px; max-width: 100%; text-align: center; overflow: hidden; }
.box .label { font: 600 13px ui-monospace, monospace; background: #8bb8e8; color: #fff; padding: 1px 8px; }
.box .val { font: 700 17px ui-monospace, monospace; padding: 4px 8px; overflow-wrap: anywhere; }
.box.changed { animation: flash 0.9s; }
@keyframes flash { 0% { background: #ffe066; transform: scale(1.12); } 100% { background: #eef6ff; transform: scale(1); } }
.empty { color: var(--muted); font-style: italic; }
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; padding: 16px; }
  #cv { width: 100%; height: auto; aspect-ratio: 1; }
}
/* variables dropdown */
.controls .varsbtn { width: auto; padding: 0 8px; gap: 4px; font: 600 14px ui-monospace, monospace; }
.varsbtn svg { width: 10px !important; height: 10px !important; }
.varsbtn .cnt { font: 600 11px system-ui; background: #8bb8e8; color: #fff; border-radius: 99px; padding: 0 6px; }
.varsbtn[aria-expanded="true"] { background: #eef6ff; border-color: #8bb8e8; }
.varsbtn.pulse { animation: flash 0.9s; }
.varspop { position: absolute; right: 60px; top: 42px; z-index: 20; background: #fff; border: 1px solid #c9c4b6; border-radius: 10px; box-shadow: 0 6px 20px #0002; padding: 8px 10px; min-width: 260px; max-width: calc(100% - 80px); max-height: 60%; overflow: auto; }
.varspop[hidden] { display: none; }
.vp-head { font: 600 12px system-ui; color: #7c4dff; margin: 4px 0; }
.vp-head small { color: var(--muted); font-weight: 400; }
.vp-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.vchip { display: inline-flex; align-items: baseline; gap: 5px; border: 1px solid; border-radius: 99px; padding: 2px 9px; font: 14px ui-monospace, monospace; max-width: 100%; overflow-wrap: anywhere; }
.vchip b { font-weight: 700; }
.vchip i { font: 10px system-ui; font-style: normal; opacity: .7; }
.vchip.num { border-color: #8bb8e8; background: #eef6ff; }
.vchip.str { border-color: #8fcf9f; background: #ecf8ef; }
.vchip.list { border-color: #f0b27a; background: #fff4e8; }
.vchip.bool { border-color: #b9a2f0; background: #f3efff; }
.vchip.fn { border-color: #c9c4b6; background: #f6f4ee; }
.vchip.changed { animation: flash 0.9s; }
/* lessons */
.lnav { display: flex; align-items: center; gap: 6px; }
.lnav[hidden] { display: none; }
.lnav button { width: 30px; height: 30px; padding: 0; justify-content: center; border-width: 1px; border-radius: 8px; }
.lnav button svg { width: 14px; height: 14px; }
.ltitle { font-weight: 700; margin: 0 4px; }
.dots { display: flex; gap: 3px; margin-left: 8px; flex-wrap: wrap; }
.dots a { width: 9px; height: 9px; border-radius: 50%; background: #e3e0d6; }
.dots a.done { background: #2f7d4f; }
.dots a.now { background: #e0b400; }
.modelink { font-size: 14px; color: var(--muted); text-decoration: none; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; }
.modelink[hidden] { display: none; }
.lesson { padding: 10px 14px 12px; }
.lesson[hidden], .lbody[hidden] { display: none; }
.lesson h2 { margin: 0 0 6px; font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.lesson .fold { margin-left: auto; font-size: 13px; color: var(--muted); cursor: pointer; font-weight: 400; }
.lesson p { margin: 0 0 6px; font-size: 15px; }
.lesson .task { background: #eef6ff; border: 1px solid #8bb8e8; border-radius: 8px; padding: 6px 10px; font-size: 15px; }
.lesson .task b { color: #1565c0; }
.lesson .acts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.lesson .acts button { padding: 4px 10px; font-size: 14px; border-width: 1px; border-radius: 8px; }
.lesson .acts button[hidden] { display: none; }
.hint { font-size: 14px; color: #7a5300; background: #fff7e0; border: 1px solid #f0d48a; border-radius: 8px; padding: 4px 10px; margin-top: 6px; }
.badge { margin: 0 16px 10px; padding: 8px 12px; border-radius: 8px; font-weight: 600; }
.badge[hidden] { display: none; }
.badge.no { background: #fff7e0; color: #7a5300; border: 1px solid #f0d48a; }
.badge.yes { background: #e6f4ea; color: #1e6b3a; border: 1px solid #a8d5b5; }
.badge a { margin-left: 8px; color: inherit; }
