:root{
  color-scheme:light;
  --bg:#f1f4f8;
  --surface:#ffffff;
  --surface-2:#f8fafc;
  --surface-3:#eef2f7;
  --line:#dce3ec;
  --line-strong:#cbd5e1;
  --text:#0f172a;
  --muted:#475569;
  --soft-text:#64748b;
  --brand:#0f5c48;
  --brand-hover:#0b4738;
  --brand-soft:#ecfdf5;
  --brand-border:#a7f3d0;
  --ease:cubic-bezier(0.22,1,0.36,1);
  font-family:Inter,"Segoe UI",system-ui,-apple-system,sans-serif;
  background:var(--bg);
  color:var(--text);
  font-synthesis:none;
}
*{box-sizing:border-box}
body{margin:0;min-height:100vh;display:flex;flex-direction:column}
button{font:inherit;cursor:pointer;transition:background-color .18s var(--ease),border-color .18s var(--ease),color .18s var(--ease),box-shadow .18s var(--ease),transform .12s var(--ease)}
button:active:not(:disabled){transform:translateY(1px)}
button:disabled{opacity:.48;cursor:default}
[hidden]{display:none!important}
button:focus-visible,a:focus-visible,canvas:focus-visible,summary:focus-visible{outline:2px solid var(--brand);outline-offset:2px}
a{color:var(--brand);text-underline-offset:3px}
svg{width:17px;height:17px;vertical-align:middle}
i{font-style:normal}

/* Top MNC Studio Header */
.top{
  height:56px;
  padding:0 max(20px,calc((100vw - 1600px)/2));
  background:var(--surface);
  border-bottom:1px solid var(--line);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  position:sticky;
  top:0;
  z-index:30;
}
.brand,.top-right{display:flex;align-items:center;gap:10px}
.logo{
  display:grid;place-items:center;
  width:32px;height:32px;
  background:linear-gradient(145deg,#116852,#0a4838);
  color:#fff;border-radius:7px;
  box-shadow:0 1px 3px rgba(15,92,72,.24);
}
.logo svg{width:18px;height:18px}
.brand-meta{display:flex;align-items:baseline;gap:8px;white-space:nowrap}
.brand strong{font-size:15px;font-weight:700;letter-spacing:-.02em;color:var(--text)}
.brand-meta span{
  border-left:1px solid var(--line-strong);
  padding-left:9px;
  color:var(--muted);
  font-size:12px;
  font-weight:500;
}

/* Segmented Mode Bar */
.lessons{
  display:inline-grid;
  grid-auto-flow:column;
  grid-auto-columns:1fr;
  gap:3px;
  padding:3px;
  background:var(--surface-3);
  border:1px solid var(--line);
  border-radius:8px;
}
.lessons button{
  border:1px solid transparent;
  background:transparent;
  color:var(--muted);
  border-radius:6px;
  display:flex;align-items:center;justify-content:center;gap:6px;
  padding:5px 13px;
  min-height:30px;
  white-space:nowrap;
}
.lessons button:hover{color:var(--text);background:rgba(255,255,255,.6)}
.lessons button[aria-pressed=true]{
  background:var(--surface);
  border-color:var(--line);
  color:var(--brand);
  box-shadow:0 1px 2px rgba(15,23,42,.06);
}
.lessons button span{display:inline-flex;color:currentColor}
.lessons button span svg{width:14px;height:14px}
.lessons strong{font-size:12.5px;font-weight:650}

.offline,.view-chip{display:inline-flex;align-items:center;gap:6px;color:var(--muted);font-size:11.5px;font-weight:550;white-space:nowrap}
.offline i,.view-chip i,.status::before{width:7px;height:7px;border-radius:50%;background:#10b981;display:inline-block;flex:none}
.status{
  display:inline-flex;align-items:center;gap:7px;
  border:1px solid #cbd5e1;background:var(--surface-2);color:var(--text);
  border-radius:999px;font-weight:650;font-size:12px;white-space:nowrap;padding:5px 11px;
  transition:all .2s var(--ease);
}
.status::before{content:"";background:#64748b}
.status.ready{border-color:#cbd5e1;background:var(--surface-2);color:#334155}
.status.ready::before{background:#10b981}
.status.running{border-color:#6ee7b7;background:#ecfdf5;color:#065f46}
.status.running::before{background:#059669;box-shadow:0 0 0 3px rgba(16,185,129,.22)}
.status.fault{border-color:#ef4444;background:#fef2f2;color:#991b1b}
.status.fault::before{background:#dc2626;box-shadow:0 0 0 3px rgba(220,38,38,.2)}
.status.off{border-color:#cbd5e1;background:#f1f5f9;color:#475569}
.status.off::before{background:#94a3b8}

/* Main Workspace */
main{flex:1;margin:0 auto;width:100%;max-width:1620px;padding:12px 18px 10px}
.workspace{display:grid;grid-template-columns:242px minmax(0,1fr) 296px;gap:12px;align-items:start}
.panel{
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:9px;
  box-shadow:0 1px 2px rgba(15,23,42,.04);
  min-width:0;
}
.panel-title{display:flex;justify-content:space-between;gap:8px;align-items:center}
.panel-title h2,.viewport-title h2{margin:0;font-size:12.5px;font-weight:700;text-transform:uppercase;letter-spacing:.04em;color:#334155}
.panel-title>span{font-size:11px;font-weight:600;color:var(--soft-text)}
.mono-pill,.spec-badge{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--surface-3);border:1px solid var(--line);padding:2px 7px;border-radius:5px;font-size:11px;color:#334155}

/* Left Hardware Catalog */
.library{padding:11px 10px}
.library .panel-title{padding:0 3px 9px;border-bottom:1px solid var(--line);margin-bottom:8px}
.library .panel-title>span{background:var(--surface-3);padding:2px 7px;border-radius:999px;font-size:10.5px}
.component-list{display:grid;gap:5px}
.component-list button{
  width:100%;min-height:54px;text-align:left;
  background:var(--surface);border:1px solid transparent;border-radius:7px;
  color:var(--text);padding:6px 7px;
  display:flex;align-items:center;gap:9px;
}
.component-list button:hover{background:var(--surface-2);border-color:var(--line)}
.component-list button[aria-pressed=true]{background:#f0fdf9;border-color:#99d5c0;box-shadow:0 1px 2px rgba(15,92,72,.08)}
.component-list button i.thumb{
  width:42px;height:42px;background:#fff;border:1px solid var(--line);border-radius:6px;
  display:grid;place-items:center;flex:none;overflow:hidden;padding:2px;
}
.component-list button i.thumb img{object-fit:contain;width:100%;height:100%}
.component-list .dev-meta{min-width:0;flex:1}
.component-list .dev-head{display:flex;align-items:center;justify-content:space-between;gap:5px}
.component-list .dev-tag{font:700 10.5px ui-monospace,monospace;color:var(--brand);background:#ecfdf5;border:1px solid #cceee0;border-radius:4px;padding:1px 5px}
.component-list .dev-dot{width:6px;height:6px;border-radius:50%;background:#cbd5e1;transition:all .2s var(--ease)}
.component-list .dev-dot.on{background:#10b981;box-shadow:0 0 0 3px rgba(16,185,129,.2)}
.component-list .dev-dot.fault{background:#dc2626;box-shadow:0 0 0 3px rgba(220,38,38,.2)}
.component-list strong{display:block;font-size:12px;font-weight:650;line-height:1.25;margin-top:2px;color:var(--text)}
.component-list small{display:block;font-size:10.5px;color:var(--soft-text);margin-top:1px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* Center Workbench */
.viewport{overflow:hidden;display:flex;flex-direction:column}
.task-bar{
  display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:10px 14px;
  background:var(--surface-2);
  border-bottom:1px solid var(--line);
}
.task-copy{min-width:0}
.task-copy h1{margin:0;font-size:14.5px;font-weight:700;letter-spacing:-.015em;color:var(--text)}
.task-copy p{margin:2px 0 0;font-size:12.5px;line-height:1.4;color:var(--muted)}
.task-copy #feedback{margin-top:5px;font-size:12.5px;font-weight:600;color:#b45309}
.task-copy #feedback.pass{color:#059669}
.task-copy #feedback.error{color:#dc2626}
.lesson-actions{display:flex;gap:6px;flex:none}

.viewport-head,.viewport-foot{display:flex;justify-content:space-between;align-items:center;gap:10px;padding:8px 13px;background:var(--surface)}
.viewport-title,.tools,.legend,.toggles{display:flex;align-items:center;gap:7px}
.viewport-title>span{color:var(--brand);display:inline-flex}
.icon-button{
  display:inline-grid;place-items:center;width:29px;height:28px;padding:0;
  color:var(--muted);background:var(--surface-2);border:1px solid var(--line);border-radius:6px;
}
.icon-button:hover,.icon-button[aria-pressed=true]{color:var(--brand);border-color:#99d5c0;background:#f0fdf9}
.icon-button svg{width:15px;height:15px}
.divider{width:1px;height:18px;background:var(--line)}
.fs-button{min-height:28px;padding:3px 9px;font-size:11.5px;font-weight:650;background:var(--surface-2);border-color:var(--line)}
.fs-button[aria-pressed=true]{background:#ecfdf5;border-color:#99d5c0;color:var(--brand)}
.fs-hud{
  display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px;
  padding:7px 14px;background:var(--surface-2);border-top:1px solid var(--line);
}
.fs-hud-group{display:flex;align-items:center;flex-wrap:wrap;gap:6px}
.trip-inline{color:#92400e;background:#fffbeb;border-color:#fde68a}
.viewport.is-fullscreen,.viewport:fullscreen{
  position:fixed;inset:0;z-index:100;border-radius:0;border:none;
  width:100vw;height:100vh;background:var(--surface);
}
.viewport.is-fullscreen .canvas-wrap,.viewport:fullscreen .canvas-wrap{
  flex:1;height:auto;min-height:0;
}
.viewport:not(.is-fullscreen):not(:fullscreen) .fs-hud{display:none!important}

@keyframes alertSlide{from{opacity:0;transform:translateY(-6px)}to{opacity:1;transform:translateY(0)}}
.wiring-alert{
  display:flex;align-items:center;justify-content:space-between;gap:12px;
  margin:0;padding:10px 14px;
  background:#fef2f2;border-top:1px solid #fecaca;border-bottom:2px solid #dc2626;border-left:5px solid #dc2626;
  color:#7f1d1d;animation:alertSlide .22s var(--ease);
}
.wiring-alert-body{display:flex;align-items:flex-start;gap:10px;min-width:0}
.wiring-alert-icon{flex:none;width:28px;height:28px;border-radius:6px;background:#fee2e2;color:#dc2626;display:grid;place-items:center}
.wiring-alert-icon svg{width:16px;height:16px}
.wiring-alert strong{display:block;font-size:13px;line-height:1.3;color:#991b1b}
.wiring-alert p{margin:2px 0 0;font-size:12.5px;line-height:1.4;color:#7f1d1d}
.alert-action{flex:none;background:#dc2626;color:#fff;border-color:#b91c1c}
.alert-action:hover{background:#b91c1c}

.canvas-wrap{height:clamp(430px,59vh,640px);position:relative;background:#f3f6fa;border-block:1px solid var(--line)}
canvas{width:100%;height:100%;display:block;touch-action:none;cursor:grab}
canvas:active{cursor:grabbing}
canvas[data-mode=pan]{cursor:move}
canvas:focus-visible{outline-offset:-3px}
.view-chip,.back,.selection,.canvas-tip{position:absolute}
.view-chip{
  pointer-events:none;top:10px;left:10px;
  border:1px solid var(--line-strong);background:rgba(255,255,255,.92);backdrop-filter:blur(6px);
  color:#1e293b;padding:4px 9px;border-radius:6px;box-shadow:0 1px 2px rgba(15,23,42,.05);
}
.back{top:10px;right:10px;background:rgba(255,255,255,.95)!important;box-shadow:0 1px 3px rgba(15,23,42,.08)}
.selection{
  left:10px;bottom:10px;max-width:calc(100% - 20px);
  display:flex;align-items:center;gap:8px;
  color:#0f5c48;border:1px solid #99d5c0;background:rgba(255,255,255,.96);backdrop-filter:blur(6px);
  border-radius:7px;padding:5px 9px;font-size:12px;font-weight:600;box-shadow:0 2px 8px rgba(15,23,42,.08);
}
.canvas-tip{
  bottom:10px;right:10px;pointer-events:none;
  color:var(--soft-text);font-size:11px;font-weight:500;
  background:rgba(255,255,255,.9);border:1px solid var(--line);border-radius:5px;padding:4px 8px;
}
.selection:not([hidden])~.canvas-tip{display:none}

.flow-strip{
  display:flex;flex-wrap:wrap;align-items:center;gap:6px 9px;
  padding:8px 13px;background:var(--surface-2);border-bottom:1px solid var(--line);
  font-size:11.5px;color:#1e293b;
}
.flow-item{
  display:inline-flex;align-items:center;gap:6px;padding:3px 8px;
  border-radius:5px;background:#ecfdf5;border:1px solid #bfe8d5;
  font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;
}
.flow-item strong{font-family:Inter,system-ui,sans-serif;font-size:10.5px;text-transform:uppercase;letter-spacing:.04em;color:#0f5c48}
.flow-item.control{background:#eff6ff;border-color:#bfdbfe}
.flow-item.control strong{color:#1d4ed8}
.flow-item.fault{background:#fef2f2;border-color:#fca5a5;color:#7f1d1d}
.flow-item.fault strong{color:#dc2626}

.viewport-foot{flex-wrap:wrap;background:var(--surface)}
.legend,.toggles{flex-wrap:wrap;gap:12px;color:var(--muted);font-size:11.5px;font-weight:500}
.legend span,.toggles label{display:flex;align-items:center;gap:5px;white-space:nowrap}
.legend span::before{content:"";width:13px;height:3px;border-radius:3px;background:#9a4d2c}
.legend .control::before{background:#1d5b96}
.legend .earth::before{background:#15803d}
.legend .fault-wire::before{background:#dc2626}
.legend .live::before{width:7px;height:7px;border-radius:50%;background:#f59e0b}
.wire-picker{display:flex;align-items:center;gap:5px;flex-wrap:wrap;padding:2px 8px;background:var(--surface-2);border:1px solid var(--line);border-radius:999px}
.wire-picker-label{font-size:11px;font-weight:650;color:var(--muted);margin-right:2px}
.wire-swatch{
  width:18px;height:18px;padding:0;border-radius:50%;
  border:1.5px solid rgba(15,23,42,.24);
  background:var(--swatch);position:relative;flex:none;
}
.wire-swatch:hover{transform:scale(1.12);border-color:#0f172a}
.wire-swatch[aria-pressed=true]{outline:2px solid var(--brand);outline-offset:2px;border-color:#fff;box-shadow:0 0 0 1px rgba(15,23,42,.2)}
.toggles input{margin:0;accent-color:var(--brand)}

/* Right Control Desk & Inspector */
.right{display:grid;gap:10px}
.right section{padding:11px 12px}
.supply{
  background:var(--surface-2);color:var(--text);border:1px solid var(--line);border-radius:7px;
  display:flex;align-items:center;justify-content:space-between;width:100%;
  padding:8px 10px;gap:6px;margin:9px 0 8px;font-size:12.5px;font-weight:600;
}
.supply:hover{border-color:var(--line-strong);background:#fff}
.supply span{display:flex;align-items:center;gap:6px}
.supply span i{color:var(--brand);display:inline-flex}
.switch{display:inline-block;position:relative;width:34px;height:19px;flex:none;border-radius:999px;background:#cbd5e1;transition:background-color .2s var(--ease)}
.switch::after{content:"";background:#fff;box-shadow:0 1px 2px rgba(15,23,42,.25);position:absolute;top:2.5px;left:2.5px;width:14px;height:14px;border-radius:50%;transition:transform .2s var(--ease)}
.supply[aria-checked=true] .switch{background:#10b981}
.supply[aria-checked=true] .switch::after{transform:translateX(15px)}

.control-row{display:grid;grid-template-columns:1fr 1fr;gap:7px}
.button{
  display:inline-flex;justify-content:center;align-items:center;gap:6px;
  min-height:32px;padding:5px 10px;border-radius:7px;
  font-size:12px;font-weight:650;color:var(--text);background:var(--surface-2);
  border:1px solid var(--line-strong);white-space:nowrap;
}
.button:hover:not(:disabled){background:#fff;border-color:#94a3b8}
.button svg{width:14px;height:14px}
.primary{background:var(--brand);color:#fff;border-color:var(--brand)}
.primary:hover:not(:disabled){background:var(--brand-hover);border-color:var(--brand-hover)}
.primary[aria-pressed=true]{background:#059669;border-color:#047857;box-shadow:inset 0 2px 4px rgba(0,0,0,.15)}
.stop{background:#fef2f2;color:#991b1b;border-color:#fecaca}
.stop:hover:not(:disabled){background:#fee2e2;border-color:#fca5a5}
.stop[aria-pressed=true]{background:#dc2626;color:#fff;border-color:#b91c1c}
.trip{width:100%;margin-top:7px;color:#92400e;background:#fffbeb;border-color:#fde68a}
.trip:hover:not(:disabled){background:#fef3c7;border-color:#fcd34d}
.secondary{background:var(--surface);color:#1e293b}

dl{margin:8px 0 8px}
dl div{display:flex;align-items:center;justify-content:space-between;padding:5px 0;border-bottom:1px solid #eef2f6;font-size:12px;color:var(--muted)}
dd{
  margin:0;border-radius:5px;padding:2px 7px;
  background:var(--surface-3);color:#334155;
  font:700 11px ui-monospace,SFMono-Regular,Menlo,monospace;
  transition:all .2s var(--ease);
}
dd.on{background:#ecfdf5;color:#047857;border:1px solid #a7f3d0}
.trace p,.part-info{margin:0;color:var(--muted);font-size:12px;line-height:1.45}
.trace p{min-height:34px;padding:6px 8px;background:var(--surface-2);border:1px solid var(--line);border-radius:6px}

.inspector h3{margin:8px 0 1px;font-size:14.5px;font-weight:700;line-height:1.2;color:var(--text)}
.inspector .model{margin:2px 0 8px;color:var(--soft-text);font:550 11.5px ui-monospace,monospace}
.tag{color:var(--brand)!important;background:#ecfdf5;border:1px solid #bfe8d5;border-radius:5px;padding:2px 6px;font:700 11px ui-monospace,monospace}
.inspect-actions{display:flex;gap:6px;flex-wrap:wrap;margin:0 0 8px}
.terminal-controls{display:flex;gap:4px;flex-wrap:wrap;margin-top:8px}
.terminal-controls button{
  border:1px solid var(--line-strong);background:var(--surface-2);color:#1e293b;
  border-radius:5px;padding:3px 6px;font:600 11px ui-monospace,monospace;min-width:32px;
}
.terminal-controls button.energized{color:#b45309;border-color:#fcd34d;background:#fffbeb}
.terminal-controls button:hover,.terminal-controls button[aria-pressed=true]{background:#ecfdf5;border-color:var(--brand);color:var(--brand)}
.inspector figure{margin:8px 0;padding:8px;background:#fff;border:1px solid var(--line);border-radius:7px}
.inspector img{width:100%;height:118px;object-fit:contain;display:block}
.inspector figcaption{font-size:11px;margin-top:5px;text-align:right}
.linked{font-size:12px;margin-top:8px;color:var(--muted)}
.linked summary{cursor:pointer;font-weight:600}
.linked button{width:100%;display:block;margin-top:4px;color:#1e293b;text-align:left;border:1px solid var(--line);border-radius:5px;background:var(--surface-2);padding:5px 7px;font-size:11px}
.linked button[aria-pressed=true]{border-color:#7c3aed;background:#f5f3ff;color:#5b21b6}

footer{display:flex;justify-content:space-between;gap:8px;padding:10px 2px 6px;color:var(--soft-text);font-size:11.5px}
dialog{background:var(--surface);color:var(--text);border:1px solid var(--line-strong);border-radius:10px;max-width:520px;padding:16px 18px;margin:auto;font-size:13.5px;line-height:1.55;box-shadow:0 20px 50px rgba(15,23,42,.18)}
dialog ul{padding-left:18px}
dialog li{margin:7px 0}
dialog::backdrop{background:rgba(15,23,42,.38);backdrop-filter:blur(2px)}

@media(max-width:1200px){
  .workspace{grid-template-columns:206px minmax(0,1fr) 264px;gap:10px}
  .canvas-wrap{height:clamp(400px,56vh,580px)}
}
@media(max-width:980px){
  .top{height:auto;flex-wrap:wrap;padding:8px 14px;gap:8px}
  .workspace{grid-template-columns:196px minmax(0,1fr)}
  .right{grid-column:1/-1;grid-template-columns:repeat(3,minmax(0,1fr))}
}
@media(max-width:680px){
  .brand-meta span,.offline{display:none}
  main{padding:8px}
  .workspace{grid-template-columns:minmax(0,1fr)}
  .viewport{grid-row:1}
  .library{grid-row:2}
  .component-list{grid-template-columns:1fr 1fr}
  .right{grid-row:3;grid-template-columns:1fr}
  .task-bar{flex-direction:column;align-items:stretch}
  .wiring-alert{flex-direction:column;align-items:stretch}
  .canvas-wrap{height:clamp(320px,48vh,430px)}
}
@media(prefers-reduced-motion:reduce){
  *{animation:none!important;transition:none!important}
}
