/* แล็บแขนกล — เวทีซ้าย / แผงคำสั่งขวา บนจอกว้าง, ซ้อนกันบนจอเล็ก */
:root{
  --sans:'IBM Plex Sans Thai','Noto Sans Thai',system-ui,-apple-system,'Segoe UI',sans-serif;
  --ink:#191a24; --muted:#6b6c7e; --line:#e6e3dc; --surface:#fff; --bg:#f5f4ef;
  --brand:#2e7d88; --brand-ink:#1f5f68; --brand-soft:#dcecee;
  --ok:#129a72; --warn:#d68a17; --danger:#e2564a;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden}
body{font-family:var(--sans);color:var(--ink);background:var(--bg);display:flex;flex-direction:column;
  -webkit-font-smoothing:antialiased;user-select:none;-webkit-user-select:none}

#stage{position:relative;flex:1;min-height:0;background:#fff}
#webgl-canvas{width:100%;height:100%;display:block;touch-action:none}

.status{
  position:absolute;left:12px;top:12px;right:96px;
  background:rgba(255,255,255,.95);border:1px solid var(--line);border-radius:12px;
  padding:8px 13px;font-size:.82rem;box-shadow:0 4px 14px rgba(25,26,36,.08);
  pointer-events:none;max-width:min(560px,calc(100% - 120px));line-height:1.5;
}
.status.ok{border-color:#bfe9da;color:#0a6b50;background:#f0fbf7}
.status.bad{border-color:#f6cdc9;color:#8f2018;background:#fdf3f2}
.status.warn{border-color:#f7e2bd;color:#7d5209;background:#fffaf0}

.hud{
  position:absolute;right:12px;bottom:12px;background:#191a24;color:#fff;
  padding:6px 13px;border-radius:999px;font-size:.8rem;font-weight:600;
}

/* ---------- แผงคำสั่ง ---------- */
#panel{
  flex:none;background:var(--surface);border-top:1px solid var(--line);
  padding:12px 14px 14px;display:flex;flex-direction:column;gap:9px;max-height:48vh;overflow-y:auto;
}
.panel-head{display:flex;align-items:baseline;gap:10px}
.panel-title{font-weight:700;font-size:.92rem}
.goal{font-size:.78rem;color:var(--muted);margin-left:auto;text-align:right}
.hint{margin:0;font-size:.74rem;color:var(--muted);line-height:1.5}

.cmd-palette{display:grid;grid-template-columns:repeat(auto-fill,minmax(96px,1fr));gap:6px}
.cmd-btn{
  display:flex;align-items:center;justify-content:center;gap:5px;padding:9px 8px;
  border:1px solid var(--line);border-radius:10px;background:var(--bg);
  font-family:inherit;font-size:.78rem;font-weight:600;cursor:pointer;min-height:44px;text-align:center;
}
.cmd-btn:hover{border-color:var(--brand);background:var(--brand-soft)}
.cmd-btn .ic{font-size:1rem}

/* ---------- โปรแกรม ---------- */
.prog,.tasks{display:flex;flex-direction:column;gap:5px}
.prog-head{font-size:.78rem;font-weight:600;color:var(--muted)}
.prog-head span:last-child{background:var(--brand-soft);color:var(--brand-ink);padding:1px 8px;border-radius:999px;font-size:.72rem}
.prog-list{
  border:1.5px dashed var(--line);border-radius:12px;padding:7px;
  display:flex;flex-direction:column;gap:5px;min-height:56px;max-height:220px;overflow-y:auto;
}
.prog-empty{margin:auto;color:#a0a1b0;font-size:.8rem}
.prog-row{
  display:flex;align-items:center;gap:8px;background:var(--bg);
  border-left:3px solid var(--brand);border-radius:8px;padding:6px 8px;font-size:.8rem;
}
.prog-row.is-active{background:#eef0ff;border-left-color:var(--brand-ink);box-shadow:0 0 0 1px var(--brand-soft)}
.prog-row .idx{color:var(--muted);font-variant-numeric:tabular-nums;min-width:16px}
.prog-row .nm{font-weight:600;flex:none}
.prog-row input[type=number]{
  width:66px;padding:4px 7px;border:1px solid var(--line);border-radius:7px;
  font-family:inherit;font-size:.78rem;background:#fff;
}
.prog-row .unit{font-size:.72rem;color:var(--muted)}
.prog-row .grip-t{
  border:1px solid var(--line);background:#fff;border-radius:999px;padding:3px 10px;
  font-family:inherit;font-size:.72rem;cursor:pointer;
}
.prog-row .grip-t.is-close{background:var(--brand);color:#fff;border-color:var(--brand)}
.prog-row .rm{margin-left:auto;border:none;background:transparent;color:#b9bac6;cursor:pointer;font-size:.9rem}
.prog-row .rm:hover{color:var(--danger)}

.task-list{display:flex;flex-direction:column;gap:4px}
.task-item{display:flex;align-items:center;gap:7px;font-size:.78rem;padding:6px 9px;border-radius:8px;background:var(--bg)}
.task-item.is-done{background:#e9f8f2;color:#0a6b50}
.task-check{width:16px;height:16px;border-radius:50%;border:2px solid var(--line);flex:none}
.task-item.is-done .task-check{background:var(--ok);border-color:var(--ok)}

.actions{display:flex;gap:8px}
.btn{padding:10px 14px;border-radius:999px;border:1px solid transparent;font-family:inherit;
  font-size:.84rem;font-weight:600;cursor:pointer;box-shadow:0 2px 6px rgba(25,26,36,.12);flex:1}
.btn:active{transform:translateY(1px)}
.btn[disabled]{opacity:.45;pointer-events:none}
.btn-ghost{background:var(--surface);border-color:var(--line);color:var(--ink)}
.btn-run{background:var(--brand);color:#fff}
.btn-submit{background:var(--ok);color:#fff}

/* ---------- กล่องโค้ด ---------- */
.modal{position:fixed;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;
  background:rgba(20,20,28,.5);padding:18px}
.modal[hidden]{display:none}
.modal-box{background:#fff;border-radius:16px;max-width:min(640px,100%);width:100%;max-height:86vh;
  display:flex;flex-direction:column;box-shadow:0 18px 50px rgba(0,0,0,.3);overflow:hidden}
.modal-head{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;
  border-bottom:1px solid var(--line);font-weight:700}
.modal-x{border:none;background:none;font-size:1.1rem;cursor:pointer;color:var(--muted)}
.code{margin:0;padding:16px;overflow:auto;background:#0f1117;color:#e6e6ee;font-size:.8rem;line-height:1.5;
  font-family:'SF Mono',ui-monospace,Menlo,Consolas,monospace;white-space:pre;flex:1}
.modal-foot{padding:12px 16px;border-top:1px solid var(--line);display:flex;justify-content:flex-end}
.modal-foot .btn{flex:none}

/* ---------- จอกว้าง ---------- */
@media (min-width:900px){
  body{flex-direction:row}
  #panel{width:340px;max-height:none;height:100%;border-top:none;border-left:1px solid var(--line);padding:16px}
}
@media (max-width:560px){
  .status{position:static;margin:8px 12px;max-width:none;right:auto}
  #stage{display:flex;flex-direction:column;min-height:50vh}
  #webgl-canvas{flex:1;min-height:180px}
}
