/* แล็บระบบไฟฟ้ากำลัง — เวทีบน / แผงล่าง (จอกว้าง: ซ้าย-ขวา) */
:root{
  --sans:'IBM Plex Sans Thai','Noto Sans Thai',system-ui,-apple-system,'Segoe UI',sans-serif;
  --ink:#171d24; --muted:#68727e; --line:#e2e5e6; --surface:#fff; --bg:#f2f5f5;
  --brand:#1c5fa8; --brand-ink:#134680; --brand-soft:#e3eefa;
  --ok:#129a72; --warn:#c07a12; --danger:#d9534a;
}
*{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}
input,textarea,select,[contenteditable]{-webkit-user-select:text;user-select:text}

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

.status{
  position:absolute;left:12px;top:12px;
  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(23,29,36,.12);
  pointer-events:none;max-width:min(600px,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}

#panel{
  flex:none;background:var(--surface);border-top:1px solid var(--line);
  padding:12px 14px 14px;display:flex;flex-direction:column;gap:11px;max-height:54vh;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{font-size:.76rem;color:var(--muted);line-height:1.55;margin:0}

.mode-row{display:flex;gap:5px;flex-wrap:wrap}
.mode-btn{flex:1 1 30%;padding:8px 4px;border-radius:9px;border:1.5px solid var(--line);background:#fff;
  font-family:inherit;font-size:.79rem;font-weight:600;cursor:pointer;color:var(--ink)}
.mode-btn.is-active{border-color:var(--brand);background:var(--brand-soft);color:var(--brand-ink)}

.ctl-col{display:flex;flex-direction:column;gap:9px}
.ctl-col[hidden]{display:none}
.knob-box{display:flex;flex-direction:column;gap:8px}

.pick-lab{font-size:.72rem;font-weight:700;color:var(--muted);margin:2px 0 0}
.pick-row{display:flex;flex-wrap:wrap;gap:6px}
.pick-btn{
  flex:1 1 30%;padding:8px 6px;border-radius:10px;cursor:pointer;font:inherit;font-size:.78rem;
  border:1.5px solid var(--line);background:#fff;color:var(--ink);
  display:flex;flex-direction:column;gap:2px;align-items:center;text-align:center;
}
.pick-btn.is-active{border-color:var(--brand);background:var(--brand-soft);color:var(--brand-ink);font-weight:600}
.pick-btn small{font-size:.66rem;opacity:.7;font-weight:400}

/* กล่องสรุป — เขียวเมื่อผลตรงกับที่ควรเป็น */
.alias-note{
  border-radius:12px;padding:10px 12px;font-size:.8rem;line-height:1.55;
  border:1px solid #bfe9da;background:#f0fbf7;color:#0a6b50;
}
.alias-note.is-bad{border-color:#f7e2bd;background:#fffaf0;color:#7d5209}
.alias-note b{font-variant-numeric:tabular-nums}

/* ตารางผลการลู่เข้า — ต้องเลื่อนได้เองในกล่อง ไม่ใช่ดันหน้าให้เลื่อนทั้งหน้า */
.conv-table{overflow-x:auto;font-size:.75rem}
.conv-table table{border-collapse:collapse;width:100%;min-width:280px}
.conv-table th,.conv-table td{padding:4px 6px;text-align:right;border-bottom:1px solid var(--line);
  font-variant-numeric:tabular-nums;white-space:nowrap}
.conv-table th{color:var(--muted);font-weight:600;font-size:.7rem}
.conv-table td:first-child,.conv-table th:first-child{text-align:left}
.conv-table tr.is-best td{color:var(--brand-ink);font-weight:700;background:var(--brand-soft)}

.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;display:grid;place-items:center;font-size:.6rem;color:#fff}
.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(23,29,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}
.btn-submit{background:var(--ok);color:#fff;width:100%}

.legend{
  position:absolute;left:16px;bottom:16px;z-index:4;
  display:flex;flex-wrap:wrap;gap:10px;padding:8px 12px;border-radius:12px;
  background:rgba(255,255,255,.9);box-shadow:0 6px 20px -10px rgba(20,24,29,.4);font-size:.78rem;
}
/* display:flex ชนะ [hidden] ของเบราว์เซอร์ ต้องสั่งซ่อนเองไม่งั้นเหลือกล่องขาวเปล่า ๆ */
.legend[hidden],.stage-badge[hidden]{display:none}
.legend b{display:inline-flex;align-items:center;gap:5px;font-weight:500}
.legend i{width:11px;height:11px;border-radius:3px;display:inline-block}

.stage-badge{
  position:absolute;right:12px;bottom:12px;z-index:3;
  background:rgba(255,255,255,.93);border:1px solid #d5dfe2;border-radius:14px;
  padding:8px 14px;text-align:right;line-height:1.25;
  box-shadow:0 2px 10px rgba(20,32,38,.08);
}
.stage-badge.is-bad{border-color:#f0d4b7;background:rgba(255,250,240,.95)}
.stage-badge.is-bad b{color:#7d5209}
.stage-badge b{display:block;font-size:20px;font-weight:700;color:#0a5064}
.stage-badge span{display:block;font-size:12px;color:#68727e}
/* บนมือถือมุมขวาบนเป็นที่ของปุ่มสลับภาษา ป้ายจึงต้องหลบไปซ้าย */
@media(max-width:820px){.stage-badge{left:12px;right:auto;bottom:auto;top:10px;padding:6px 10px;text-align:left}
  .stage-badge b{font-size:15px}}

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

.ctl-row{display:flex;gap:8px}
.ctl-row .btn{flex:1}

/* ui.css มี .res ให้อยู่แล้ว เติมเฉพาะสีเตือนที่ยังไม่มี */
.res-v.warn{color:#8a6212}
.res-v.hot{color:#c0392b}
.res-v.good{color:#0a6b50}

/* แถบไล่สีความเค้นฟอน มีเซส — น้ำเงินคือเนื้อที่ว่าง แดงคือเนื้อที่ทำงานหนักสุด */
.vm-bar{display:inline-block;width:78px;height:11px;border-radius:3px;
  background:linear-gradient(90deg,#1b3f6b,#2a86b8,#37b58c,#d6c840,#e0582f)}

/* ปุ่มเสียง — เปลี่ยนสีให้รู้ว่าเปิดอยู่ */
.btn-sound{width:100%;background:var(--surface);border-color:var(--line);color:var(--muted)}
.btn-sound.is-on{background:var(--brand-soft);border-color:var(--brand);color:var(--brand-ink)}
.btn-sound[hidden]{display:none}

/* ปุ่มสายส่ง — เรียงเป็นตารางให้กดปลดหรือต่อกลับได้ทีละเส้น */
.line-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(96px,1fr));gap:6px}
.line-btn{
  padding:7px 6px;border-radius:9px;cursor:pointer;font:inherit;font-size:.74rem;
  border:1.5px solid var(--line);background:#fff;color:var(--ink);
  display:flex;flex-direction:column;gap:1px;align-items:center;line-height:1.3;
}
.line-btn b{font-weight:700;font-variant-numeric:tabular-nums}
.line-btn small{font-size:.66rem;opacity:.72;font-variant-numeric:tabular-nums}
.line-btn.is-open{border-color:#c0392b;background:#fdf1ef;color:#8f2018;text-decoration:line-through}
.line-btn.is-over{border-color:#c0392b;background:#fdf1ef;color:#8f2018;font-weight:700}
.line-btn.is-warm{border-color:#d68a17;background:#fffaf0;color:#7d5209}

/* แถบไล่สีภาระของสายส่ง — เขียวคือว่าง แดงคือเต็มพิกัด */
.load-bar{display:inline-block;width:78px;height:11px;border-radius:3px;
  background:linear-gradient(90deg,#2f9e6e,#8dbb3a,#d8b02a,#d9622f,#c0392b)}
