/* แล็บเครื่องกลอย่างง่าย — เวทีซ้าย / แผงควบคุมขวา */
: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:#eef1f6}
#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}

.readout{
  position:absolute;right:12px;top:66px;display:flex;gap:14px;
  background:rgba(255,255,255,.96);border:1px solid var(--line);border-radius:14px;
  padding:9px 14px;box-shadow:0 4px 14px rgba(25,26,36,.08);
}
.readout .ri{display:flex;flex-direction:column;align-items:center;min-width:56px}
.readout .ri b{font-size:1.05rem;font-variant-numeric:tabular-nums;line-height:1.2}
.readout .ri span{font-size:.66rem;color:var(--muted)}

#panel{
  flex:none;background:var(--surface);border-top:1px solid var(--line);
  padding:12px 14px 14px;display:flex;flex-direction:column;gap:10px;max-height:52vh;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}
#panel .btn-switch{flex:none;align-self:stretch;width:100%;padding:10px 14px;text-align:center}
.note{font-size:.74rem;color:var(--muted);line-height:1.5;margin:2px 0 0}

#panel-body{display:flex;flex-direction:column;gap:10px}

.tasks{display:flex;flex-direction:column;gap:5px}
.tk-head{font-size:.78rem;font-weight:600;color:var(--muted)}
.tk-head span:last-child{background:var(--brand-soft);color:var(--brand-ink);padding:1px 8px;border-radius:999px;font-size:.72rem}
.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)}
.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;flex:2}
.btn-submit{background:var(--ok);color:#fff;flex:1}

/* หน้าจอเลือกเครื่องกล */
.chooser{position:absolute;inset:0;background:rgba(238,241,246,.97);display:flex;align-items:center;justify-content:center;padding:20px;z-index:10}
.chooser[hidden]{display:none}
.chooser-box{max-width:600px;width:100%}
.chooser-title{font-size:1.3rem;margin:0 0 4px}
.chooser-sub{font-size:.84rem;color:var(--muted);margin:0 0 16px}
.chooser-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px}
.choice{display:flex;flex-direction:column;gap:4px;padding:14px;border:1px solid var(--line);border-radius:14px;
  background:#fff;cursor:pointer;text-align:left;font-family:inherit;transition:border-color .15s,transform .1s}
.choice:hover{border-color:var(--brand);transform:translateY(-2px)}
.choice .ico{font-size:1.6rem}
.choice .nm{font-weight:700;font-size:.9rem}
.choice .dn{font-size:.72rem;color:var(--ok);font-weight:600}

@media (min-width:900px){
  body{flex-direction:row}
  #panel{width:342px;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}
  .readout{position:static;margin:0 12px 8px}
  #stage{display:flex;flex-direction:column;min-height:48vh}
  #webgl-canvas{flex:1;min-height:170px}
}

.mat-label{font-size:.74rem;font-weight:600;color:var(--muted,#6b6c7e);margin-top:4px}
.matsel{display:flex;flex-wrap:wrap;gap:5px}
.mat-btn{border:1px solid var(--line,#e6e3dc);background:#fff;border-radius:9px;padding:5px 11px;
  font-family:inherit;font-size:.76rem;color:inherit;cursor:pointer}
.mat-btn.is-active{background:var(--brand-soft,#dcecee);border-color:var(--brand,#2e7d88);color:var(--brand-ink,#1f5f68);font-weight:600}
.readbox{background:var(--bg,#f5f4ef);border-radius:12px;padding:8px 12px;font-size:.76rem;line-height:1.6;font-variant-numeric:tabular-nums}
.readbox b{color:var(--brand-ink,#1f5f68)}
.readbox.danger{background:#fdf3f2}
.readbox.danger b{color:var(--danger,#e2564a)}
