:root {
  --bg: #0d2240; --panel: #16304f; --panel2: #1f416a; --text: #f4f7fb; --muted: #a9bdd6;
  --ok: #7ee2a8; --bad: #ff9c8a; --na: #8aa0bb; --gold: #ffd23f;
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
/* hidden ต้องชนะ display ของ class (.excount/.intro ตั้ง display:flex) — เดิมแถบนับถอยหลังพื้นมืด 45% ทับภาพกล้องตลอด ภาพดูซีด */
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
button, select, input { font: inherit; }
button, select { background: var(--panel2); color: var(--text); border: 1px solid #36598a; border-radius: 10px; padding: 8px 12px; cursor: pointer; }
button.primary { background: #2b7a4b; border-color: #3fa868; }
button.danger { background: #6b2a2a; border-color: #94403e; }
button:disabled { opacity: .5; }
input { background: #0b1b33; color: var(--text); border: 1px solid #36598a; border-radius: 8px; padding: 8px; width: 100%; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.top { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; padding: 8px 12px; background: #0a1a31; z-index: 5; }
.brand { font-weight: 700; margin-right: auto; } .tag { font-weight: 400; font-size: 12px; color: var(--gold); margin-left: 6px; }
.controls { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.controls.sub button { font-size: 14px; padding: 6px 10px; }
/* ลิงก์ทดสอบกับคลิป: แถวเลือกคลิปเต็มความกว้าง */
.controls.clips { flex: 1 1 100%; }
.controls.clips select { flex: 1; min-width: 0; max-width: 720px; }
.clipcard { margin: 8px 0 0; font-size: 15px; line-height: 1.55; border: 1px solid #36598a; }
.clipinfo div { margin: 2px 0; }
#pose { max-width: 62vw; }
#camBtn { font-weight: 700; }
/* จอกว้าง: แถบบนติดหัวจอ · มือถือ: ไม่ติด (เดิมสูง 176 px กินจอตลอด) ปุ่มหลักใหญ่ เรียงเป็นแถว */
@media (min-width: 901px) { .top { position: sticky; top: 0; } }
@media (max-width: 900px) {
  .top { padding: 8px 10px; }
  .brand { width: 100%; }
  .controls { width: 100%; display: grid; grid-template-columns: 1fr auto auto; }
  .controls.sub { grid-template-columns: 1fr 1fr 1fr; }
  #pose { max-width: none; width: 100%; min-width: 0; }
}
.layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 12px; padding: 12px; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; padding: 8px; gap: 8px; } }
/* กรอบภาพ = สัดส่วนกล้องจริง (--ar ตั้งจาก app.js) → ภาพกับเส้นโครงกระดูกทับกันพอดี ไม่ยืด ไม่มีขอบดำ
   สูงไม่เกิน --maxh (มือถือ ~55% ของจอ ให้เห็นคำแนะนำใต้ภาพโดยไม่ต้องเลื่อน) */
.stage { --ar: 16 / 9; --maxh: 74vh; position: relative; background: #000; border-radius: 12px; overflow: hidden;
  aspect-ratio: var(--ar); width: min(100%, calc(var(--maxh) * var(--ar))); margin-inline: auto; }
@media (max-width: 900px) { .stage { --maxh: 55vh; } }
#video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }   /* กรอบเท่าสัดส่วนกล้องแล้ว contain = เต็มกรอบพอดี (ถ้าเบราว์เซอร์ไม่รองรับกับ canvas ก็ไม่ยืดเพราะสัดส่วนเท่ากัน) */
.mirror #video, .mirror #overlay { transform: scaleX(-1); }
.notice { margin: 8px 12px 0; padding: 8px 12px; border-radius: 10px; background: #3a2f0b; border: 1px solid var(--gold); color: #fff3c4; font-size: 15px; }
.notice button { margin-left: 8px; }
.excount { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(6,19,31,.45); color: #fff; font-size: clamp(18px, 3vw, 30px); font-weight: 700; text-align: center; pointer-events: none; }
.excount b { font-size: clamp(60px, 12vw, 140px); color: var(--gold); line-height: 1; }
.view3d { position: absolute; left: 6px; bottom: 14px; width: clamp(80px, 22%, 200px); aspect-ratio: 1; background: rgba(6,19,31,.7); border: 1px solid #36598a; border-radius: 10px; overflow: hidden; }
#view3d { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.mirror #view3d { transform: scaleX(-1); }
.v3label { position: absolute; left: 6px; top: 3px; right: 6px; font-size: 11px; color: var(--muted); pointer-events: none; }
#dimBtn.on3d { background: #5b3fa8; border-color: #8a6be0; }
.refimg { position: absolute; right: 6px; top: 6px; height: 24%; max-width: 30%; object-fit: contain; background: #fff; border-radius: 8px; opacity: .92; cursor: zoom-in; transition: height .15s, max-width .15s; }
.refimg.big { height: 62%; max-width: 80%; opacity: 1; cursor: zoom-out; }   /* แตะภาพตัวอย่าง = ขยาย/ย่อ */
.status { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); padding: 3px 8px; border-radius: 8px; font-size: 13px; max-width: 60%; }
.status:empty { display: none; }
.intro { z-index: 1; } .status { z-index: 3; }   /* ข้อความ "กำลังเปิดกล้อง/เปิดกล้องไม่ได้" ต้องอยู่บนวิธีใช้ */
.intro { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; padding: 14px 18px; background: linear-gradient(#0d2240ee, #0d2240dd); font-size: clamp(15px, 2.4vw, 20px); line-height: 1.5; }
.intro ol { margin: 6px 0 0; padding-left: 1.4em; }
.intro li { margin: 4px 0; }
.coach { margin-top: 8px; background: #0a1a31; border-radius: 10px; padding: 8px 12px; font-size: clamp(19px, 3.2vw, 32px); font-weight: 700; text-align: center; min-height: 1.6em; }
.legend { margin-top: 6px; }
.legendbox { margin: 4px 2px; font-size: 14px; }
.legendbox summary { cursor: pointer; }
.perf { padding: 2px; }
details > summary { cursor: pointer; }
details.more { margin-top: 8px; }
.card.verdict { border: 1px solid var(--gold); }
#jointDetails > summary { padding: 4px 0; font-size: 16px; }
.lg { display: inline-block; width: 22px; height: 5px; border-radius: 3px; vertical-align: middle; }
.lg.used { background: #e8f1ff; } .lg.chest { background: #ff8fd0; } .lg.ok { background: #2fd36f; } .lg.bad { background: #ff4545; } .lg.unused { background: rgba(232,241,255,.35); } .lg.ext { background: #9fd8ff; }
.holdbar { position: absolute; left: 0; right: 0; bottom: 0; height: 10px; background: rgba(255,255,255,.12); }
.holdbar i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .1s linear; }
.repline { display: flex; gap: 6px 14px; flex-wrap: wrap; padding: 8px 2px 2px; font-size: 16px; }
#phase:empty, #live:empty { display: none; }
#reps { color: var(--gold); font-weight: 700; }
.card { background: var(--panel); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.card h3 { margin: 2px 0 8px; font-size: 17px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
table.comps { width: 100%; border-collapse: collapse; font-size: 14px; }
table.comps td, table.comps th { padding: 4px 4px; border-bottom: 1px solid #24476f; text-align: left; }
table.comps th { color: var(--muted); font-weight: 400; }
td.st { font-weight: 700; text-align: center; width: 28px; }
.num { display: inline-block; min-width: 1.6em; text-align: center; border-radius: 1em; font-weight: 700; font-size: 13px; color: #06131f; background: var(--na); }
.num.pass { background: #2fd36f; } .num.fail { background: #ff4545; }
td.val { font-weight: 700; } td.val.pass { color: #2fd36f; } td.val.fail { color: #ff6b6b; } td.val.na { color: var(--na); font-weight: 400; }
.rulebtn { padding: 3px 8px; font-size: 14px; background: transparent; color: var(--muted); border-style: dashed; white-space: nowrap; }
.rulebtn.tuned { color: var(--gold); border-color: var(--gold); border-style: solid; }
tr.edit td { background: #0f2645; }
.tune { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 4px 0; }
.tune label { display: flex; align-items: center; gap: 6px; }
.stepper { display: inline-flex; align-items: center; }
.stepper button { width: 40px; height: 40px; padding: 0; font-size: 22px; line-height: 1; }
.stepper input { width: 74px; text-align: center; margin: 0 4px; }
.tunenote { color: var(--gold); }
.tune3 { padding: 4px 0; }
.pl { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 6px 0; border-bottom: 1px dashed #24476f; }
.pl label.check { display: flex; align-items: center; gap: 6px; min-width: 9.5em; }
.pl label.check input { width: auto; }
.pl .pv { min-width: 4.5em; font-weight: 700; }
.pl .pv.pass { color: #2fd36f; } .pl .pv.fail { color: #ff6b6b; } .pl .pv.na { color: var(--na); font-weight: 400; }
.pl:not(.on) .pctl { opacity: .4; }
.pl.na { opacity: .55; }
.pl .stepper button { width: 34px; height: 34px; font-size: 20px; }
.pl .stepper input { width: 64px; }
.jrow { border-bottom: 1px solid #24476f; }
.jrow.open { background: #0f2645; }
.jhead { width: 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: transparent; border: 0; border-radius: 0; padding: 8px 4px; text-align: left; }
.jsum { margin-left: auto; }
.jsum.tuned { color: var(--gold); }
.jdot { width: 12px; height: 12px; border-radius: 50%; background: #3a587d; flex: none; }
.jdot.pass { background: #2fd36f; } .jdot.fail { background: #ff4545; } .jdot.na { background: var(--na); }
.jrow.open .jdot { box-shadow: 0 0 0 3px #b48cff; }
.jbody { padding: 0 4px 8px 24px; }
.jgroup { border-bottom: 2px solid #24476f; }
.ghead { width: 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: #0c2140; border: 0; border-radius: 0; padding: 10px 4px; text-align: left; }
.jgroup.open > .ghead { background: #123059; }
.gbody { padding-left: 14px; }
.jswap { color: var(--gold); margin: 6px 0; }
.pass { color: var(--ok); } .fail { color: var(--bad); } .na { color: var(--na); }
.trial { background: var(--panel2); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.trial .sys { font-size: 15px; }
.trial .row button { flex: 1; font-size: 17px; padding: 10px; }
.btn-ok { background: #2b7a4b !important; } .btn-bad { background: #8a3b2f !important; }
.stats { font-size: 15px; line-height: 1.6; }
.stats table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.stats td, .stats th { border-bottom: 1px solid #24476f; padding: 3px; text-align: left; }
dialog { background: var(--panel); color: var(--text); border: 1px solid #36598a; border-radius: 14px; width: min(440px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog.expert { width: min(1180px, 98vw); max-height: 96vh; padding: 10px 12px; overflow: auto; }
.ex-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.ex-head h3 { margin: 0 0 6px; font-size: 17px; }
.ex-head h3 small { font-size: 13px; font-weight: 400; }   /* คำอธิบายใต้หัวเรื่องไม่ใหญ่เท่าหัวเรื่อง (มือถือกินจอ) */
.ex-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 1fr); gap: 12px; }
@media (max-width: 860px) { .ex-body { grid-template-columns: 1fr; } }
.ex-canvas-wrap { position: relative; background: #081a30; border-radius: 10px; aspect-ratio: 4 / 3.4; width: min(100%, calc(52vh * 4 / 3.4)); margin-inline: auto; }   /* มือถือ: หุ่นไม่สูงเกินครึ่งจอ */
#exCanvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.ex-ref { position: absolute; right: 6px; top: 6px; height: 24%; border-radius: 6px; opacity: .75; background: #fff; pointer-events: none; }   /* ลากหุ่นทะลุรูปได้ */
.ex-tip { position: absolute; left: 8px; bottom: 6px; right: 8px; color: var(--muted); pointer-events: none; }
.ex-modes label.check { display: flex; align-items: center; gap: 6px; }
.ex-modes input { width: auto; }
.ex-right { max-height: 70vh; overflow: auto; padding-right: 4px; }
.ex-right h4 { margin: 10px 0 4px; color: var(--gold); font-size: 15px; }
.dof { border-bottom: 1px dashed #24476f; padding: 6px 2px; }
.dof.sel { background: #13305a; }
.dof.on .dof-top b { color: var(--gold); }
.dof-top { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.dof-top label.check { display: flex; gap: 6px; align-items: center; }
.dof-top input { width: auto; }
.dof-ctl { display: flex; align-items: center; gap: 8px; }
.dof-ctl input[type=range] { flex: 1; padding: 0; min-height: 30px; accent-color: #ffd23f; }
.dof-val { min-width: 3.2em; font-weight: 700; text-align: right; }
.dof-live { min-width: 6em; color: var(--muted); }
.dof-live.pass { color: #2fd36f; } .dof-live.fail { color: #ff6b6b; }
.dof-rng { margin-top: 4px; font-size: 14px; }
.dof-rng .stepper button { width: 32px; height: 32px; font-size: 18px; }
.dof-rng .stepper input { width: 62px; }
.ex-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.ex-foot label { display: flex; gap: 6px; align-items: center; }
.ex-foot input { width: 12em; }
#exSave { margin-left: auto; }
.rulebtn.expert { color: #b48cff; border-color: #b48cff; border-style: solid; }
.settings label { display: block; margin: 10px 0; }
.settings label.check { display: flex; gap: 8px; align-items: center; }
.settings label.check input { width: auto; }

/* เกณฑ์จุดที่ตั้งจากคลิปสาธิต 5 ต.ค. (ยังไม่ได้ปรับเอง) */
.jdef { display: inline-block; font-size: 11px; line-height: 1.4; padding: 0 6px; border-radius: 99px; background: #23406a; color: #cfe3ff; vertical-align: middle; }
