/* Coding Bot — layout แบบ stage บน / แผงคำสั่งล่าง บนจอเล็ก
   และ stage ซ้าย / แผงขวา บนจอกว้าง */

: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;
}

/* ---------- เวที 3D ---------- */
#stage{position:relative;flex:1;min-height:0;background:#fff}
#webgl-canvas{width:100%;height:100%;display:block;touch-action:none}

.status{
  /* right เว้นช่องไว้ให้ปุ่มสลับภาษา (pin-tr) มุมขวาบน ไม่ให้ทับกัน */
  position:absolute;left:14px;top:14px;right:96px;
  background:rgba(255,255,255,.94);border:1px solid var(--line);
  border-radius:12px;padding:9px 14px;font-size:.85rem;
  box-shadow:0 4px 14px rgba(25,26,36,.08);pointer-events:none;
  max-width:min(520px,calc(100% - 110px));
}
.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}

.level-badge{
  position:absolute;right:14px;bottom:14px;
  background:var(--ink);color:#fff;border-radius:999px;
  padding:5px 14px;font-size:.78rem;font-weight:600;pointer-events:none;
}

/* ---------- แผงคำสั่ง ---------- */
#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:46vh;overflow-y:auto;   /* จอเตี้ย: เนื้อหาเกิน 46vh ต้องเลื่อนถึงปุ่มส่งงานได้ */
}
.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}

/* ปุ่มทิศทาง — จัดเป็น D-pad ขนาดนิ้วแตะได้ (min 48px) */
.dpad{
  display:grid;grid-template-columns:repeat(3,minmax(0,58px));
  grid-template-rows:repeat(3,48px);gap:6px;justify-content:center;flex:none;
}
.key{
  border:none;border-radius:13px;cursor:pointer;color:#fff;
  display:grid;place-items:center;
  box-shadow:0 2px 5px rgba(25,26,36,.14);
  transition:transform .1s,filter .15s;
  -webkit-tap-highlight-color:transparent;
}
.key:active{transform:translateY(1px) scale(.97)}
.key:hover{filter:brightness(1.07)}
.key svg{width:23px;height:23px;fill:#fff}
.key-up{grid-area:1/2;background:#3b82f6}
.key-left{grid-area:2/1;background:#0d9488}
.key-jump{grid-area:2/2;background:#db2777}
.key-right{grid-area:2/3;background:#8b5cf6}
.key-down{grid-area:3/2;background:#d97706}
.key[disabled]{opacity:.3;pointer-events:none}

/* ---------- คิวคำสั่ง ---------- */
.queue{
  flex:1;min-height:60px;overflow-y:auto;
  border:1.5px dashed var(--line);border-radius:14px;padding:8px;
  display:flex;flex-wrap:wrap;gap:6px;align-content:flex-start;
}
.queue-empty{margin:auto;color:#a0a1b0;font-size:.82rem;text-align:center}
.blk{
  display:inline-flex;align-items:center;gap:6px;
  background:var(--bg);border-left:3px solid var(--brand);
  border-radius:8px;padding:5px 8px 5px 9px;font-size:.8rem;font-weight:600;
}
.blk.is-running{background:var(--brand-soft);border-left-color:var(--brand-ink)}
.blk svg{width:15px;height:15px;fill:var(--brand-ink)}
.blk .n{color:var(--muted);font-weight:500;font-size:.74rem}
.blk button{
  border:none;background:transparent;color:#b9bac6;cursor:pointer;
  font-size:.9rem;line-height:1;padding:2px 0 2px 2px;
}
.blk button:hover{color:var(--danger)}

/* ---------- ปุ่มสั่งการ ---------- */
.actions{display:flex;gap:8px;flex:none}
.btn{
  flex:1;padding:11px;border-radius:999px;border:1px solid transparent;
  font-family:inherit;font-size:.9rem;font-weight:600;cursor:pointer;
  transition:filter .15s,transform .1s;
}
.btn:active{transform:translateY(1px)}
.btn[disabled]{opacity:.45;pointer-events:none}
.btn-run{background:var(--brand);color:#fff;flex:2}
.btn-run:hover{background:var(--brand-ink)}
.btn-ghost{background:var(--surface);border-color:var(--line);color:var(--ink)}
.btn-ghost:hover{background:var(--bg)}
.btn-submit{background:var(--ok);color:#fff;width:100%;flex:none}
.btn-submit:hover{filter:brightness(1.06)}

/* ---------- จอกว้าง: แผงไปอยู่ขวา ---------- */
@media (min-width:820px){
  body{flex-direction:row}
  #panel{
    width:330px;max-height:none;height:100%;
    border-top:none;border-left:1px solid var(--line);padding:16px;
  }
  .dpad{grid-template-rows:repeat(3,54px)}
}
