/* แล็บโมเลกุล — เวทีบน / แผงล่าง (จอกว้าง: ซ้าย-ขวา) */
: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}
input,textarea,select,[contenteditable]{-webkit-user-select:text;user-select:text}

#stage{position:relative;flex:1;min-height:0;background:#f2f0ea}
#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(25,26,36,.12);
  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}

#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:6px}
.mode-btn{flex:1;padding:8px 4px;border-radius:9px;border:1.5px solid var(--line);background:#fff;
  font-family:inherit;font-size:.8rem;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}

.stat-row{display:flex;gap:8px}
.stat{flex:1;background:var(--bg);border-radius:12px;padding:8px 11px;display:flex;flex-direction:column;gap:2px}
.stat-k{font-size:.7rem;font-weight:700;color:var(--muted)}
.stat-v{font-size:1.05rem;font-weight:700;font-variant-numeric:tabular-nums}

/* เลือกธาตุ */
.el-pick{display:flex;flex-direction:column;gap:5px}
.el-lab{font-size:.72rem;font-weight:700;color:var(--muted)}
.el-row{display:flex;gap:5px;flex-wrap:wrap}
.el-btn{width:38px;height:38px;border-radius:10px;border:1.5px solid var(--line);background:#fff;
  font-family:inherit;font-size:.85rem;font-weight:700;cursor:pointer;color:var(--ink);
  display:grid;place-items:center;position:relative;padding:0}
.el-btn::after{content:'';position:absolute;left:5px;right:5px;bottom:4px;height:3px;border-radius:2px;background:var(--dot,#ccc)}
.el-btn.is-active{border-color:var(--brand);background:var(--brand-soft);color:var(--brand-ink)}

/* คลังโมเลกุล */
.mol-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(92px,1fr));gap:6px}
.mol-btn{padding:9px 6px;border-radius:10px;border:1.5px solid var(--line);background:#fff;
  font-family:inherit;cursor:pointer;color:var(--ink);display:flex;flex-direction:column;gap:2px;align-items:center}
.mol-btn .mb-f{font-size:.9rem;font-weight:700}
.mol-btn .mb-n{font-size:.63rem;color:var(--muted);line-height:1.25;text-align:center}
.mol-btn.is-active{border-color:var(--brand);background:var(--brand-soft)}
.mol-btn.is-seen{border-color:#bfe0c9}

/* การ์ดผลวิเคราะห์ */
.mol-card{background:var(--bg);border-radius:12px;padding:10px 12px;display:flex;flex-direction:column;gap:8px}
.mol-top{display:flex;align-items:baseline;gap:8px}
.mol-formula{font-size:1.15rem;font-weight:700}
.mol-ax{margin-left:auto;font-size:.74rem;font-weight:700;color:var(--brand-ink);background:var(--brand-soft);padding:2px 9px;border-radius:999px}
.mol-shape{font-size:.84rem;font-weight:600;color:var(--muted)}
.pol-tag{font-size:.76rem;font-weight:700;padding:6px 10px;border-radius:9px;text-align:center}
.pol-tag.polar{background:#fdf3f2;color:#8f2018;border:1px solid #f6cdc9}
.pol-tag.nonpolar{background:#f0fbf7;color:#0a6b50;border:1px solid #bfe9da}
.bond-list{display:flex;flex-direction:column;gap:3px}
.bd-row{display:flex;align-items:center;gap:7px;font-size:.72rem;color:var(--muted)}
.bd-name{font-weight:700;color:var(--ink);width:56px;flex:none}
.bd-type{margin-left:auto;padding:1px 8px;border-radius:999px;font-weight:700;font-size:.66rem}
.bd-type.nonpolar_covalent{background:#eef0f2;color:#4b5058}
.bd-type.polar_covalent{background:#fff3e0;color:#8a5300}
.bd-type.ionic{background:#f3e8fb;color:#61338a}

/* ควิซ */
.quiz{background:var(--bg);border-radius:12px;padding:10px 12px;display:flex;flex-direction:column;gap:7px}
.q-head{font-size:.74rem;font-weight:700;color:var(--muted)}
.q-text{font-size:.95rem;line-height:1.5;font-weight:700}
.q-row{display:flex;gap:6px;flex-wrap:wrap}
.q-opt{flex:1 1 45%;min-width:110px;padding:9px 6px;border-radius:9px;border:1.5px solid var(--line);background:#fff;
  font-family:inherit;font-size:.78rem;font-weight:700;cursor:pointer;color:var(--ink)}
.q-opt:hover{border-color:var(--brand)}
.q-opt.is-right{border-color:var(--ok);background:#e9f8f2;color:#0a6b50}
.q-opt.is-wrong{border-color:var(--danger);background:#fdf3f2;color:#8f2018}
.q-feed{font-size:.76rem;font-weight:600;min-height:1em}
.q-feed.ok{color:#0a6b50}
.q-feed.bad{color:#8f2018}

.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(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-submit{background:var(--ok);color:#fff;width:100%}

@media (min-width:900px){
  body{flex-direction:row}
  #panel{width:360px;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}
}

/* เฉพาะ orbit-lab */
.body-row{display:grid;grid-template-columns:repeat(3,1fr);gap:6px}
.body-btn{padding:8px 4px;border-radius:10px;border:1.5px solid var(--line);background:#fff;
  font-family:inherit;font-size:.78rem;font-weight:600;cursor:pointer;color:var(--ink)}
.body-btn.is-active{border-color:var(--brand);background:var(--brand-soft);color:var(--brand-ink)}
.knob-box{display:flex;flex-direction:column;gap:8px}
.ctl-row{display:flex;gap:8px}
.ctl-row .btn{flex:1}
.ref{display:flex;gap:10px;flex-wrap:wrap;font-size:.72rem;color:var(--muted);
  background:var(--bg);border-radius:10px;padding:7px 11px}
.ref b{color:var(--ink);font-variant-numeric:tabular-nums}
.orb{background:var(--bg);border-radius:12px;padding:10px 12px;display:flex;flex-direction:column;gap:5px}
.orb-top{display:flex;align-items:baseline;gap:8px}
.orb-type{font-size:.95rem;font-weight:700}
.orb-type.circular{color:#0a6b50}
.orb-type.elliptic{color:#2456a8}
.orb-type.hyperbolic,.orb-type.parabolic{color:#8a5300}
.orb-type.crashed{color:var(--danger)}
.orb-row{display:flex;gap:8px;font-size:.74rem}
.orb-k{color:var(--muted);width:126px;flex:none}
.orb-v{font-weight:700;font-variant-numeric:tabular-nums}
.kep{border:1px solid var(--line);border-radius:10px;overflow:hidden;background:#fff}
.kep table{width:100%;border-collapse:collapse;font-size:.71rem;font-variant-numeric:tabular-nums}
.kep th{background:var(--bg);color:var(--muted);font-weight:700;padding:5px 7px;text-align:right}
.kep th:first-child,.kep td:first-child{text-align:left}
.kep td{padding:4px 7px;text-align:right;border-top:1px solid #f1efe9}
.kep .same{color:#0a6b50;font-weight:700}

/* ---------- ตัวเลือกสภาพแวดล้อม ---------- */
.pick-lab { font-size: .78rem; opacity: .65; margin: 10px 0 4px; }
.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: .8rem;
  border: 1px solid var(--pg-line, #d5dbe3); background: var(--pg-card, #fff); color: var(--pg-ink, #222);
  display: flex; flex-direction: column; gap: 2px; align-items: center;
}
.pick-btn.is-active { border-color: #4a7a3a; background: #e9f2e3; color: #2c5220; font-weight: 600; }
.pick-btn small { font-size: .68rem; opacity: .65; font-weight: 400; }

/* ---------- กราฟความถี่อัลลีล ---------- */
.chart-box {
  border: 1px solid var(--pg-line, #d9dee5); border-radius: 12px;
  padding: 8px 10px 4px; margin: 10px 0; background: var(--pg-card, #fff);
}
.chart-head { display: flex; justify-content: space-between; font-size: .78rem; opacity: .7; margin-bottom: 4px; }
.chart-head span:last-child { font-weight: 700; opacity: 1; font-variant-numeric: tabular-nums; }
.chart-box canvas { width: 100%; height: auto; display: block; max-width: 100%; }

/* ---------- ตารางฮาร์ดี-ไวน์เบิร์ก ---------- */
.tbl td.off { color: #b5372c; font-weight: 600; }

/* ---------- คำอธิบายสีบนฉาก ---------- */
.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;
}
.legend b { display: inline-flex; align-items: center; gap: 5px; font-weight: 500; }
.legend i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }

/* ---------- มาตรการ ---------- */
.pick-btn.is-active.measure { border-color: #b5372c; background: #fdecea; color: #8c261d; }

/* ---------- แท็บโหมด ---------- */
.mode-row { display: flex; gap: 6px; margin: 8px 0; }
.mode-btn {
  flex: 1; padding: 8px 6px; border-radius: 10px; cursor: pointer; font: inherit; font-size: .84rem;
  border: 1px solid var(--pg-line, #d5dbe3); background: var(--pg-card, #fff); color: var(--pg-ink, #222);
}
.mode-btn.is-active { border-color: #2f6fa8; background: #e5eefb; color: #17456e; font-weight: 600; }

/* ---------- สมการบนแผง ---------- */
.eq-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.15rem; font-weight: 700;
  background: #f2f5f8; border-radius: 10px; padding: 12px 10px; text-align: center; margin: 8px 0;
}
.step-list { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; max-height: 130px; overflow-y: auto; }
.step-list div {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem;
  padding: 3px 8px; border-radius: 6px; background: #f7f8fa; opacity: .8;
}
.step-list div small { font-family: system-ui, sans-serif; opacity: .6; margin-left: 6px; }

/* ---------- แถวปุ่มกระทำ ---------- */
.op-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.op-row input[type=number] {
  width: 68px; padding: 7px 8px; border-radius: 8px; font: inherit;
  border: 1px solid var(--pg-line, #d5dbe3); background: var(--pg-card, #fff); color: var(--pg-ink, #222);
  -webkit-user-select: text; user-select: text;
}
.op-btn {
  padding: 7px 13px; border-radius: 8px; cursor: pointer; font: inherit; font-size: .9rem; font-weight: 600;
  border: 1px solid var(--pg-line, #d5dbe3); background: var(--pg-card, #fff); color: var(--pg-ink, #222);
}
.op-btn:hover { border-color: #2f6fa8; color: #2f6fa8; }

/* ---------- แถบลำดับเบส ---------- */
.seq-box { margin: 8px 0; }
.seq-lab { font-size: .74rem; opacity: .6; margin-bottom: 3px; letter-spacing: .04em; }
.seq-row { display: flex; flex-wrap: wrap; gap: 2px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.seq-row .base {
  width: 21px; height: 26px; display: grid; place-items: center; border-radius: 5px;
  font-size: .82rem; font-weight: 700; cursor: pointer; user-select: none; color: #fff;
}
.seq-row .base.ro { cursor: default; opacity: .9; }
.seq-row .base.sel { outline: 2px solid #1b1c26; outline-offset: 1px; }
.base.A { background: #4f9a63; } .base.T { background: #cf3f34; }
.base.U { background: #d8722c; } .base.C { background: #3a86e0; } .base.G { background: #b8912c; }
.seq-row .codon-gap { width: 6px; }

/* ---------- สายกรดอะมิโน ---------- */
.aa-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.aa {
  padding: 4px 9px; border-radius: 999px; font-size: .76rem; font-weight: 600;
  background: #eef1f5; color: #333; white-space: nowrap;
}
.aa.changed { background: #fdecea; color: #8c261d; outline: 1px solid #cf3f34; }
.aa.stop { background: #24272d; color: #f4f6f8; }
.aa small { font-weight: 400; opacity: .65; margin-left: 4px; }

/* ---------- ตารางเทียบก่อน/หลังชน ---------- */
.cmp { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: .84rem; }
.cmp th, .cmp td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--pg-line, #e6e9ee); }
.cmp th:first-child, .cmp td:first-child { text-align: left; opacity: .7; }
.cmp td { font-variant-numeric: tabular-nums; font-weight: 600; }
.cmp tr.same td { color: #2e7d4f; }
.cmp tr.drop td:last-child { color: #b5372c; }
.cmp thead th { font-weight: 500; opacity: .6; font-size: .78rem; }
