:root {
  --bg: #12161d; --panel: #1a202b; --panel2: #212836; --line: #2d3646; --text: #e3e8ef; --mut: #94a0b3;
  --acc: #3b8cff; --ok: #2fa84f; --err: #e5484d; --warn: #e2a13a;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", system-ui, Arial, sans-serif; display: flex; flex-direction: column; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
.sp { flex: 1; }

/* ---------- yuqori panel ---------- */
#top { display: flex; align-items: center; gap: 8px; padding: 7px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.brand { display: flex; align-items: center; gap: 9px; margin-right: 14px; }
.brand .logo { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, #3b8cff, #18c29c); display: grid; place-items: center; font-weight: 800; font-size: 18px; color: #fff; }
.brand b { display: block; font-size: 16px; line-height: 1.1; }
.brand small { color: var(--mut); font-size: 11px; }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #4a5870; background: #283143; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.run { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.btn.run:hover:not(:disabled) { background: #37bb5a; }
.btn.stop:not(:disabled) { background: var(--err); border-color: var(--err); color: #fff; font-weight: 600; }
.btn.accent { background: #23406e; border-color: #33609f; }
.btn.icon { padding: 6px 10px; min-width: 34px; }
.status { color: var(--mut); font-size: 13px; padding-left: 4px; }
.status.on { color: #5fd67e; }
.status.on::before { content: "● "; }

/* ---------- asosiy tartib ---------- */
main { flex: 1; display: flex; min-height: 0; }
#palette { width: 214px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
#search { margin: 8px; padding: 6px 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); outline: none; }
#search:focus { border-color: var(--acc); }
#palList { overflow-y: auto; padding: 0 8px 12px; flex: 1; }
#palList h4 { margin: 12px 2px 5px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--mut); }
.pal { display: flex; align-items: center; gap: 7px; width: 100%; text-align: left; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 5px 6px; cursor: pointer; font-size: 13px; }
.pal:hover { background: var(--panel2); border-color: var(--line); }
.pal i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.pal span { flex: 1; }
.pal em { font-style: normal; color: var(--mut); font-size: 11px; opacity: 0; }
.pal:hover em { opacity: 1; }

#stage { flex: 1; position: relative; min-width: 0; background: #dfe6ee; }
#view { position: absolute; inset: 0; }
#view canvas { display: block; outline: none; }
#tip { position: absolute; display: none; max-width: 260px; background: rgba(18, 22, 29, .95); border: 1px solid #44506a; border-radius: 7px; padding: 6px 9px; font-size: 12.5px; pointer-events: none; z-index: 5; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); }
#tip b { color: #ffd54a; }
#tip i { color: #8fd3a0; }
#viewbtns { position: absolute; left: 10px; top: 10px; display: flex; gap: 5px; z-index: 3; }
#viewbtns button { background: rgba(26, 32, 43, .88); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 12.5px; }
#viewbtns button:hover { background: #2a3447; }
#hint { position: absolute; left: 10px; right: 10px; bottom: 8px; text-align: center; font-size: 12.5px; color: #dfe6f0; background: rgba(18, 22, 29, .82); border-radius: 7px; padding: 5px 10px; pointer-events: none; z-index: 3; }
#hint b { color: #ffd54a; }
#toasts { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 6; width: min(520px, 80%); pointer-events: none; }
.toast { background: rgba(26, 32, 43, .96); border: 1px solid var(--line); border-left: 4px solid var(--acc); border-radius: 7px; padding: 8px 12px; font-size: 13px; box-shadow: 0 6px 18px rgba(0, 0, 0, .3); }
.toast.warn { border-left-color: var(--warn); }
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }

/* ---------- xususiyatlar oynasi ---------- */
#props { position: absolute; right: 10px; top: 10px; width: 292px; max-height: calc(100% - 56px); overflow-y: auto; background: rgba(26, 32, 43, .96); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; z-index: 4; display: none; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); font-size: 13px; }
#props h3 { margin: 0 0 2px; font-size: 15px; }
#props .info { color: var(--mut); font-size: 12px; margin-bottom: 8px; }
#props h5 { margin: 11px 0 5px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--mut); }
#props .row { display: flex; align-items: center; gap: 7px; margin: 5px 0; }
#props .row label { flex: 1; }
#props input[type=range] { width: 100%; accent-color: var(--acc); }
#props .val { font-variant-numeric: tabular-nums; color: #ffd54a; min-width: 62px; text-align: right; }
#props .auto { font-size: 11.5px; color: #8fd3a0; margin: -2px 0 6px; }
#props select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; max-width: 170px; }
.mini { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; cursor: pointer; font-size: 12.5px; }
.mini:hover { border-color: #4a5870; background: #283143; }
.mini.danger:hover { background: #5a1f24; border-color: var(--err); }
.mini.wide { width: 100%; padding: 6px; margin: 3px 0; }
table.pins { width: 100%; border-collapse: collapse; font-size: 12px; }
table.pins td { padding: 3px 4px; border-top: 1px solid var(--line); vertical-align: top; }
table.pins td:first-child { font-weight: 700; color: #ffd54a; white-space: nowrap; }
table.pins .v { color: #7fc8ff; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
table.pins .net { color: #8fd3a0; }
.sw { display: inline-block; width: 22px; height: 22px; border-radius: 5px; border: 2px solid transparent; cursor: pointer; margin-right: 4px; }
.sw.on { border-color: #fff; }

/* ---------- o'ng panel ---------- */
#side { width: 440px; flex: none; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#tabs { display: flex; flex: none; border-bottom: 1px solid var(--line); }
#tabs button { flex: 1; background: transparent; border: 0; border-bottom: 2px solid transparent; padding: 9px; cursor: pointer; color: var(--mut); }
#tabs button.on { color: var(--text); border-bottom-color: var(--acc); font-weight: 600; }
.tab { display: none; flex: 1; min-height: 0; }
.tab.on { display: flex; flex-direction: column; }
.edhead, .serhead { display: flex; align-items: center; gap: 6px; padding: 5px 10px; background: var(--panel2); font-size: 12.5px; color: var(--mut); border-bottom: 1px solid var(--line); flex: none; }
.serhead { border-top: 1px solid var(--line); }
.editor { flex: 1.7; display: flex; min-height: 120px; background: #0e1218; }
#gutter { width: 40px; flex: none; text-align: right; padding: 8px 6px 8px 0; color: #4d5a70; overflow: hidden; user-select: none; white-space: pre; }
.edwrap { position: relative; flex: 1; min-width: 0; }
#hl, #code, #gutter { font: 13px/1.5 Consolas, "Cascadia Mono", "Courier New", monospace; tab-size: 2; }
#hl, #code { position: absolute; inset: 0; margin: 0; padding: 8px; border: 0; white-space: pre; overflow: auto; }
#hl { pointer-events: none; overflow: hidden; color: #d7dde8; }
#code { background: transparent; color: transparent; caret-color: #fff; resize: none; outline: none; }
#code::selection { background: rgba(59, 140, 255, .35); }
.t-c { color: #6b7a90; font-style: italic; } .t-s { color: #e6b673; } .t-k { color: #ff7b72; } .t-t { color: #79c0ff; } .t-f { color: #d2a8ff; } .t-n { color: #7ee787; } .t-p { color: #ffa657; } .t-b { color: #56d4dd; }
#serial { flex: 1; min-height: 80px; margin: 0; padding: 7px 10px; background: #0a0d12; color: #9be09b; font: 12.5px/1.45 Consolas, "Courier New", monospace; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.serin { display: flex; gap: 6px; padding: 6px 8px; flex: none; border-top: 1px solid var(--line); }
.serin input { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; outline: none; }

/* ---------- darsliklar ---------- */
#tab-lesson, #tab-idea { overflow-y: auto; padding: 12px 14px 30px; display: none; }
#tab-lesson.on, #tab-idea.on { display: block; }
.lcard { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; margin: 6px 0; cursor: pointer; }
.lcard:hover { border-color: var(--acc); }
.lcard .n { width: 30px; height: 30px; border-radius: 8px; background: #23406e; display: grid; place-items: center; font-weight: 700; flex: none; }
.lcard b { display: block; }
.lcard small { color: var(--mut); }
.lesson h2 { font-size: 18px; margin: 6px 0 8px; }
.lesson h3 { font-size: 14px; margin: 16px 0 6px; color: #8fc1ff; }
.lesson p, .lesson li { color: #cfd6e2; }
.lesson ul, .lesson ol { padding-left: 20px; margin: 6px 0; }
.lesson li { margin: 3px 0; }
.lesson table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0; }
.lesson th, .lesson td { border: 1px solid var(--line); padding: 4px 7px; text-align: left; }
.lesson th { background: var(--panel2); color: var(--mut); font-weight: 600; }
.lesson td.pn { font-weight: 700; color: #ffd54a; white-space: nowrap; }
.lesson pre { background: #0e1218; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; overflow-x: auto; font: 12.5px/1.5 Consolas, "Courier New", monospace; color: #d7dde8; }
.lesson .act { display: flex; gap: 7px; flex-wrap: wrap; margin: 8px 0; }
.lesson .act button { background: #23406e; border: 1px solid #33609f; border-radius: 7px; padding: 7px 11px; cursor: pointer; }
.lesson .act button:hover { background: #2c5290; }
.lesson .act button.go { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.lesson .lab { margin-top: 20px; border-top: 2px solid var(--acc); padding-top: 6px; }
.lesson .badge { display: inline-block; background: #23406e; border-radius: 5px; padding: 1px 8px; font-size: 11.5px; color: #a8cbff; letter-spacing: .04em; text-transform: uppercase; }
.lesson .note { background: #1f2a3c; border-left: 3px solid var(--warn); padding: 7px 10px; border-radius: 0 7px 7px 0; margin: 8px 0; color: #e7dcc5; }
.back { background: transparent; border: 0; color: #8fc1ff; cursor: pointer; padding: 2px 0; }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; z-index: 20; }
#modal[hidden] { display: none; }
.mbox { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 22px; width: min(640px, 92vw); max-height: 86vh; overflow-y: auto; }
.mbox h2 { margin: 0 0 10px; }
.mbox li { margin: 5px 0; color: #cfd6e2; }
.mbox kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 12px; }
.mclose { position: absolute; right: 10px; top: 8px; background: transparent; border: 0; font-size: 24px; cursor: pointer; color: var(--mut); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #33405a; border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
@media (max-width: 1150px) { #side { width: 360px; } #palette { width: 180px; } .brand small { display: none; } }

/* ---------- g'oyalar ---------- */
#tabs button[hidden] { display: none; }
details.cls { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; margin: 8px 0; }
details.cls summary { cursor: pointer; font-size: 15px; }
details.cls summary small { color: var(--mut); margin-left: 6px; }
details.cls .lcard { background: var(--panel); }
.idea .mut { color: var(--mut); font-size: 12.5px; margin: 2px 0 8px; }
.idea .prog { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-size: 13px; color: #ffd54a; }
.idea .prog .bar { flex: 1; height: 9px; background: var(--bg); border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.idea .prog .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #2fa84f, #18c29c); transition: width .4s; }
.idea details.bom { margin: 6px 0; color: var(--mut); }
.idea details.bom summary { cursor: pointer; color: #8fc1ff; }
.idea details.step { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; margin: 6px 0; padding: 0 10px; }
.idea details.step[open] { border-color: var(--acc); padding-bottom: 8px; }
.idea details.step > summary { cursor: pointer; padding: 8px 0; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 9px; }
.idea details.step > summary::-webkit-details-marker { display: none; }
.idea .st { width: 24px; height: 24px; border-radius: 50%; background: #23406e; display: grid; place-items: center; font-size: 12px; flex: none; }
.idea details.step.done .st { background: var(--ok); color: #fff; font-size: 0; }
.idea details.step.done .st::after { content: "✓"; font-size: 14px; }
.idea details.step.done > summary { color: #8fd3a0; }
.idea ul.chk { list-style: none; padding: 0; margin: 6px 0; }
.idea ul.chk li { padding: 3px 0 3px 24px; position: relative; color: #cfd6e2; }
.idea ul.chk li::before { content: "○"; position: absolute; left: 4px; color: var(--mut); }
.idea ul.chk li.ok { color: #8fd3a0; }
.idea ul.chk li.ok::before { content: "✓"; color: #5fd67e; font-weight: 700; }
.idea details.hint { margin-top: 6px; }
.idea details.hint summary { cursor: pointer; color: #ffd54a; font-size: 13px; }
