:root {
  --bg: #0a0e19; --bg-2: #0e1322; --panel: #121726; --panel-2: #161c2e; --card: #151b2c;
  --border: #232a40; --border-2: #2f3856; --text: #e6e9f5; --muted: #98a0bf; --dim: #5f6787;
  --accent: #7c86ff; --cyan: #38d6f0; --green: #3ddc97; --amber: #f5b13d; --red: #ff5d6c; --pink: #ff7aa8;
  --canvas-bg: #0b1020; --canvas-dot: #1f2740; --hover: #1d2438; --input: #0e1322;
  --font: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
}
:root[data-theme="bright"] {
  --bg: #eef1f8; --bg-2: #e6eaf4; --panel: #ffffff; --panel-2: #f6f8fd; --card: #ffffff;
  --border: #d8deee; --border-2: #bcc5de; --text: #1c2340; --muted: #566086; --dim: #8791b4;
  --accent: #4f5df0; --cyan: #0894b3; --green: #129a64; --amber: #c27b00; --red: #d63548; --pink: #d6397a;
  --canvas-bg: #f4f6fc; --canvas-dot: #cfd6ea; --hover: #e9edf8; --input: #f3f5fb;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 13px; display: grid; grid-template-rows: 48px 1fr 24px; overflow: hidden; }
button, select, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.mono { font-family: var(--mono); }
i[data-icon] { display: inline-flex; width: 16px; height: 16px; flex: none; }
i[data-icon] svg { width: 100%; height: 100%; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 12px 0 10px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 230px; }
.logo { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, #12c2e9, #7c86ff); display: grid; place-items: center; color: #fff; box-shadow: 0 4px 14px #4f6bff44; }
.logo i[data-icon] { width: 18px; height: 18px; }
.brand-title { font-weight: 700; font-size: 14.5px; line-height: 1.1; }
.brand-title span { color: var(--accent); font-weight: 600; }
.brand-sub { font-size: 10.5px; color: var(--muted); }
.menu { display: flex; align-items: center; gap: 2px; }
.menu > button, .dropdown > button, .ghost { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 7px; color: var(--text); }
.menu > button:hover, .dropdown > button:hover, .dropdown.open > button, .ghost:hover { background: var(--hover); }
.icon-only { padding: 6px 7px !important; }
.chev { width: 13px !important; height: 13px !important; opacity: .7; }
.vsep { width: 1px; height: 18px; background: var(--border); margin: 0 6px; }
.dropdown { position: relative; }
.dropdown-menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 60; min-width: 360px; padding: 6px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 10px; box-shadow: 0 16px 40px #0007; display: none; }
.dropdown.open .dropdown-menu { display: block; }
.ex-item { display: flex; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; border-radius: 7px; align-items: flex-start; }
.ex-item:hover { background: var(--hover); }
.ex-num { font-family: var(--mono); color: var(--accent); font-size: 11px; padding-top: 2px; }
.ex-name { font-weight: 600; }
.ex-desc { color: var(--muted); font-size: 11.5px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.theme-toggle, .lang-toggle { display: flex; align-items: center; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-2); color: var(--muted); }
.lang-toggle { padding-left: 9px; }
.theme-toggle button, .lang-toggle button { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; color: var(--muted); display: inline-flex; align-items: center; }
.theme-toggle button i { width: 14px; height: 14px; }
.theme-toggle button.active, .lang-toggle button.active { background: var(--accent); color: #fff; }
.lang-toggle i { width: 14px; height: 14px; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-2); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.dot.ok { background: var(--green); box-shadow: 0 0 0 3px #3ddc9726; }
.dot.warn { background: var(--amber); }
.dot.err { background: var(--red); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr) 348px; min-height: 0; }
.panel-head { height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--border); color: var(--muted); flex: none; }
.panel-head b { color: var(--text); letter-spacing: .8px; font-size: 12px; }
.panel-head i { width: 14px; height: 14px; }
.toolbox, .right { display: flex; flex-direction: column; background: var(--panel); min-height: 0; }
.toolbox { border-right: 1px solid var(--border); }
.right { border-left: 1px solid var(--border); }
.tool-search { padding: 8px 10px 4px; }
.tool-search input, .field input[type=text], .field input[type=number], .field select, .tt-input, .t-input { width: 100%; background: var(--input); border: 1px solid var(--border-2); border-radius: 7px; padding: 6px 9px; outline: none; color: var(--text); }
.tool-search input:focus, .field input:focus, .field select:focus { border-color: var(--accent); }
.toolbox-list, .right-body, .tab-body, .modal-body { overflow: auto; }
.toolbox-list { flex: 1; padding: 4px 8px 10px; }
::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }
.cat-head { display: flex; align-items: center; gap: 7px; margin: 10px 4px 5px; font-size: 10.5px; font-weight: 700; letter-spacing: .9px; color: var(--muted); text-transform: uppercase; }
.cat-head i.cdot { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }
.tool { display: flex; align-items: center; gap: 9px; width: 100%; padding: 5px 7px; border-radius: 8px; text-align: left; cursor: grab; border: 1px solid transparent; }
.tool:hover { background: var(--hover); border-color: var(--border); }
.tool canvas { width: 60px; height: 42px; flex: none; background: #e9edf5; border-radius: 7px; border: 1px solid var(--border); }
.tool .tn { font-size: 12.5px; line-height: 1.2; }
.tool-hint { padding: 8px 12px; border-top: 1px solid var(--border); font-size: 11px; color: var(--dim); line-height: 1.5; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.canvas-wrap { position: relative; flex: 1 1 0; min-height: 120px; overflow: hidden; background: var(--canvas-bg); }
#cv { position: absolute; inset: 0; outline: none; touch-action: none; }
.zoom-ctl { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.zoom-ctl button { width: 30px; height: 30px; border-radius: 8px; background: var(--panel); border: 1px solid var(--border-2); display: grid; place-items: center; color: var(--text); }
.zoom-ctl button:hover { background: var(--hover); }
.toast { position: absolute; left: 50%; bottom: 18px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; padding: 8px 14px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--border-2); box-shadow: 0 8px 24px #0006; transition: .2s; max-width: 80%; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { border-color: var(--amber); }

/* ---------- bottom ---------- */
.bottom { flex: none; height: min(290px, 44vh); background: var(--panel); border-top: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.bottom.collapsed { height: 38px; }
.bottom.collapsed .tab-body { display: none; }
.tabs { height: 38px; flex: none; display: flex; align-items: center; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--border); }
.tabs > button { padding: 6px 12px; border-radius: 7px; color: var(--muted); font-weight: 600; }
.tabs > button.active { background: var(--hover); color: var(--text); }
.tabs .legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-right: 8px; }
.sw { width: 14px; height: 3px; border-radius: 2px; display: inline-block; margin-left: 6px; }
.sw.sig { background: var(--cyan); } .sw.noi { background: #7b86a8; } .sw.oth { background: var(--amber); }
.bottom.collapsed #btnCollapse i { transform: rotate(180deg); }
.tab-body { flex: 1; min-height: 0; padding: 10px; }
.spec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 10px; }
.spec-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.spec-card.sel { border-color: var(--accent); }
.spec-head { display: flex; gap: 8px; align-items: center; padding: 6px 10px; font-size: 11.5px; color: var(--muted); border-bottom: 1px solid var(--border); }
.spec-head b { color: var(--amber); font-family: var(--mono); }
.spec-head .ro { margin-left: auto; font-family: var(--mono); font-size: 10.5px; }
.spec-card canvas { width: 100%; height: 190px; display: block; background: #05080f; }
.empty { color: var(--dim); padding: 24px; text-align: center; line-height: 1.7; }
table.bt { width: 100%; border-collapse: collapse; font-size: 12px; }
table.bt th { text-align: right; font-weight: 600; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--border-2); position: sticky; top: -10px; background: var(--panel); white-space: nowrap; }
table.bt th:first-child, table.bt td:first-child { text-align: left; }
table.bt td { padding: 5px 10px; border-bottom: 1px solid var(--border); text-align: right; font-family: var(--mono); white-space: nowrap; }
table.bt td.nm { font-family: var(--font); }
table.bt td.nm b { font-family: var(--mono); color: var(--accent); margin-right: 6px; }
table.bt tr.sel td { background: var(--hover); }
table.bt td.neg { color: var(--red); } table.bt td.pos { color: var(--green); } table.bt td.warn { color: var(--amber); text-align: left; white-space: normal; font-family: var(--font); }
.bsum { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 10px 0 2px; }
.bsum div { background: var(--bg-2); border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; }
.bsum small { display: block; color: var(--muted); font-size: 10.5px; } .bsum b { font-family: var(--mono); font-size: 14px; }
.lv-head { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; }
.lv-wrap { height: calc(100% - 22px); min-height: 150px; } .lv-wrap canvas { width: 100%; height: 100%; }

/* ---------- right panel ---------- */
.right-body { flex: 1; padding: 12px; }
.sec { margin-bottom: 14px; }
.sec-h { font-size: 10.5px; font-weight: 700; letter-spacing: .9px; color: var(--muted); text-transform: uppercase; margin-bottom: 7px; display: flex; align-items: center; gap: 6px; }
.blk-title { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.blk-title .tt-input { width: 92px; font-family: var(--mono); font-weight: 700; padding: 4px 8px; }
.blk-name { font-weight: 600; }
.blk-desc { color: var(--muted); font-size: 12px; line-height: 1.55; margin: 4px 0 10px; }
.field { margin-bottom: 9px; }
.field label { display: flex; justify-content: space-between; color: var(--muted); font-size: 11.5px; margin-bottom: 3px; }
.field .row { display: flex; gap: 8px; align-items: center; }
.field .row input[type=number] { width: 96px; font-family: var(--mono); flex: none; }
.field .row .unit { color: var(--dim); font-size: 11px; width: 34px; flex: none; }
.field input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.field.dis { opacity: .55; pointer-events: none; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 12px; }
.kv span:nth-child(odd) { color: var(--muted); } .kv span:nth-child(even) { font-family: var(--mono); text-align: right; }
.kv .good { color: var(--green); } .kv .bad { color: var(--red); } .kv .mid { color: var(--amber); }
.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 11px; }
.warnbox { margin: 8px 0; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--amber); background: #f5b13d14; color: var(--amber); font-size: 12px; line-height: 1.5; }
.warnbox.bad { border-color: var(--red); background: #ff5d6c14; color: var(--red); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-weight: 700; font-size: 11.5px; }
.badge.good { background: #3ddc9722; color: var(--green); } .badge.marginal { background: #f5b13d22; color: var(--amber); } .badge.fail { background: #ff5d6c22; color: var(--red); }
.polar-wrap { display: flex; justify-content: center; } .polar-wrap canvas { width: 220px; height: 220px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border-2); background: var(--panel-2); color: var(--text); font-weight: 500; }
.btn:hover { background: var(--hover); } .btn.primary { background: linear-gradient(180deg, #8890ff, #6c74f3); border-color: transparent; color: #fff; font-weight: 600; }
.btn.danger { color: var(--red); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12px; line-height: 1.7; }

/* ---------- homework bar ---------- */
.hwbar { flex: none; background: var(--panel); border-bottom: 1px solid var(--border); padding: 8px 14px; display: flex; flex-wrap: wrap; gap: 6px 16px; max-height: 42vh; overflow: auto; align-items: flex-start; }
.hwbar > div:first-child { flex: 1 1 260px; min-width: 0; }
.hwbar h3 { margin: 0 0 3px; font-size: 14px; } .hwbar .desc { color: var(--muted); white-space: pre-wrap; line-height: 1.55; font-size: 12.5px; max-height: 110px; overflow: auto; }
.hwgoals { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.goal { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border-2); font-size: 12px; background: var(--bg-2); }
.goal.ok { border-color: var(--green); color: var(--green); } .goal.no { border-color: var(--red); } .goal small { color: var(--muted); font-family: var(--mono); }
.hwact { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.hwact input { background: var(--input); border: 1px solid var(--border-2); border-radius: 7px; padding: 6px 9px; width: 150px; color: var(--text); }
.hwmsg { flex: 1 1 100%; font-size: 12.5px; }

/* ---------- misc ---------- */
.statusbar { display: flex; align-items: center; padding: 0 12px; background: var(--panel); border-top: 1px solid var(--border); color: var(--dim); font-size: 11px; gap: 14px; font-family: var(--mono); }
.modal { position: fixed; inset: 0; background: #0009; z-index: 100; display: grid; place-items: center; }
.modal-card { width: min(720px, 92vw); max-height: 86vh; background: var(--panel); border: 1px solid var(--border-2); border-radius: 14px; display: flex; flex-direction: column; box-shadow: 0 20px 60px #000a; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 14px 18px; line-height: 1.7; }
.modal-body h4 { margin: 14px 0 4px; color: var(--accent); } .modal-body code { font-family: var(--mono); background: var(--bg-2); padding: 1px 6px; border-radius: 5px; }
.modal-body dt { font-family: var(--mono); color: var(--cyan); margin-top: 6px; } .modal-body dd { margin: 0 0 0 14px; color: var(--muted); }
@media (max-width: 1100px) { .layout { grid-template-columns: 200px minmax(0, 1fr) 300px; } .brand-sub, .menu button span { display: none; } }

/* ---------- noise cascade (equivalent noise sources) ---------- */
.nz-flow { display: flex; align-items: flex-start; overflow-x: auto; padding: 6px 4px 14px; }
.nz-unit { display: flex; flex-direction: column; flex: none; }
.nz-cap { font-size: 10.5px; color: var(--muted); text-align: right; padding-right: 4px; height: 16px; white-space: nowrap; }
.nz-main { display: flex; align-items: center; height: 56px; }
.nz-arrow { color: var(--accent); font-size: 18px; width: 22px; text-align: center; flex: none; }
.nz-node { text-align: center; font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 60px; }
.nz-node b { display: block; color: var(--text); font-size: 12.5px; }
.nz-plus { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted); display: grid; place-items: center; font-weight: 700; flex: none; background: var(--bg-2); line-height: 1; }
.nz-box { border: 2px solid var(--accent); border-radius: 8px; padding: 7px 12px; min-width: 100px; text-align: center; font-size: 11.5px; background: var(--bg-2); }
.nz-box b { display: block; font-family: var(--mono); color: var(--accent); }
.nz-under { display: flex; flex-direction: column; align-items: center; width: 26px; margin-left: 22px; margin-top: 0; }
.nz-up { width: 2px; height: 14px; background: var(--amber); position: relative; }
.nz-up::before { content: ''; position: absolute; top: -6px; left: -5px; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 8px solid var(--amber); }
.nz-src { width: 78px; height: 78px; margin: 0 -26px; border-radius: 50%; border: 2px solid var(--amber); display: grid; place-content: center; text-align: center; font-family: var(--mono); font-size: 10px; line-height: 1.3; color: var(--muted); background: var(--bg-2); }
.nz-src b { display: block; color: var(--amber); font-size: 12.5px; }
.nz-bar { height: 8px; border-radius: 4px; background: var(--amber); display: inline-block; vertical-align: middle; }
.bsum.big div b { font-size: 16px; }

.zoom-ctl button.active { background: var(--amber); color: #1a1200; border-color: var(--amber); font-weight: 700; }

/* ---------- palette folders ---------- */
.folder { margin: 3px 0; }
.fold-head { display: flex; align-items: center; gap: 7px; width: 100%; padding: 7px 6px; border-radius: 8px; font-size: 11px; font-weight: 700; letter-spacing: .6px; color: var(--muted); text-align: left; cursor: pointer; }
.fold-head:hover { background: var(--hover); color: var(--text); }
.fold-head small { margin-left: auto; font-weight: 500; color: var(--dim); }
.fold-head i.cdot { width: 8px; height: 8px; border-radius: 3px; display: inline-block; flex: none; }
.fold-head .chev { font-style: normal; font-size: 10px; width: 10px; transition: transform .15s; display: inline-block; }
.folder.open > .fold-head .chev { transform: rotate(90deg); }
.fold-body { display: none; padding-left: 4px; }
.folder.open > .fold-body { display: block; }
.folder.d1 { margin-left: 6px; border-left: 2px solid var(--border); }
.folder.d1 > .fold-head { font-size: 10.5px; font-weight: 600; letter-spacing: 0; text-transform: none; }

.fold-head .flogo { flex: none; width: 22px; height: 22px; padding: 2px; border-radius: 6px; background: var(--bg-2); border: 1px solid var(--border); box-sizing: content-box; }
.folder.d1 > .fold-head .flogo { width: 18px; height: 18px; }
