:root {
  --bg: #eef0f3; --panel: #ffffff; --line: #e6e8ec; --line2: #d5d9df; --ink: #111827; --ink2: #374151; --mute: #8a919c;
  --acc: #2563eb; --accbg: #eef3ff; --danger: #dc2626;
  --sh: 0 1px 2px rgba(16,24,40,.06), 0 6px 20px rgba(16,24,40,.08);
  --r: 12px;
  --soft: #f3f4f6; --field: #fafbfc; --onink: #ffffff; --inkh: #1f2937; --badbg: #fef2f2; --lblbg: rgba(255,255,255,.88); --brand: #5f5f5f; --btn: #1f1f1f; --btnh: #000000; --btntx: #ffffff; --btnsh: rgba(0,0,0,.22); --selbg: #d4d4d4;
  color-scheme: light;
}
:root[data-theme=dark] {
  --bg: #0f1115; --panel: #17191e; --soft: #23262c; --field: #1c1f24; --line: #2a2e35; --line2: #3b4049;
  --ink: #eef0f3; --ink2: #c5cad2; --mute: #7d8590; --acc: #5b8cff; --accbg: #1e2a4a; --danger: #f87171;
  --onink: #111318; --inkh: #d9dce1; --badbg: #3a1d1f; --lblbg: rgba(23,25,30,.88); --brand: #a3a3a3; --btn: #e6e6e6; --btnh: #ffffff; --btntx: #161616; --btnsh: rgba(0,0,0,.5); --selbg: #4a4a4a;
  --sh: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}
body, #top, .float, #drawer, .pop, .card, .modal.start { transition: background-color .25s ease, border-color .25s ease, color .25s ease; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
/* UI ทั้งหมดไม่ให้ลากคลุมเลือกข้อความ/ดับเบิลคลิกแล้วเป็นไฮไลต์ฟ้า — ยกเว้นช่องพิมพ์ */
body { -webkit-user-select: none; user-select: none; }
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }
body { font: 13.5px/1.45 "IBM Plex Sans Thai", "Leelawadee UI", system-ui, sans-serif; color: var(--ink); background: var(--bg);
  display: flex; flex-direction: column; overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
.i { display: block; flex: none; }
.hide { display: none !important; }

/* ---------- top bar */
#top { height: 52px; display: flex; align-items: center; gap: 16px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 10; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.logo { width: 22px; height: 22px; display: block; }
.right { display: flex; align-items: center; gap: 4px; flex: none; }
.brand { flex: none; }
.ib { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; color: var(--ink2); }
.ib:hover { background: var(--soft); color: var(--ink); }
.ib:disabled { opacity: .35; cursor: default; background: none; }
.toggle { display: flex; background: var(--soft); border-radius: 9px; padding: 3px; margin: 0 4px; }
.toggle button { padding: 4px 12px; border-radius: 7px; font-weight: 600; font-size: 12.5px; color: var(--mute); }
.toggle button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- canvas area */
#view { flex: 1; position: relative; overflow: hidden; min-height: 0; }
#view canvas { display: block; outline: none; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 1; }
#view.dopen .labels { right: 360px; width: auto !important; }
.float { position: absolute; z-index: 5; background: var(--panel); border-radius: var(--r); box-shadow: var(--sh); border: 1px solid var(--line); }

#opts { top: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; padding: 6px; max-width: calc(100% - 40px); overflow-x: auto; scrollbar-width: none; }
#opts:empty { display: none; }
.sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }
.tb { display: flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 8px; color: var(--ink2); white-space: nowrap; font-weight: 500; }
.tb:hover { background: var(--soft); }
.tb.on { background: var(--ink); color: var(--onink); }
.tb.sm { padding: 5px 9px; }
.txt { color: var(--mute); padding: 0 6px; white-space: nowrap; }
.nf { display: flex; align-items: center; gap: 4px; padding: 0 6px; color: var(--mute); white-space: nowrap; }
.nf input { width: 52px; border: 1px solid var(--line); border-radius: 7px; padding: 4px 6px; text-align: right; color: var(--ink); background: var(--field); }
.nf input:focus, .fld input:focus, .fld select:focus { outline: 2px solid var(--accbg); border-color: var(--acc); }
.sw { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line); padding: 0; overflow: hidden; cursor: pointer; background: none; }
.sw::-webkit-color-swatch-wrapper { padding: 0; } .sw::-webkit-color-swatch { border: 0; }
.chip { display: flex; align-items: center; gap: 7px; padding: 5px 11px 5px 9px; border-radius: 99px; color: var(--ink2); white-space: nowrap; font-weight: 500; border: 1px solid transparent; }
.chip:hover { background: var(--soft); }
.chip.on { border-color: var(--ink); color: var(--ink); }
.dot { width: 10px; height: 10px; border-radius: 99px; flex: none; display: inline-block; }
input[type=range] { accent-color: var(--ink); width: 120px; }

/* selection card */
#card { top: 14px; right: 14px; width: 252px; padding: 14px; }
#card:empty { display: none; }
.ch { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.ch .t { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch .ic { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; background: var(--soft); color: var(--ink2); }
.fg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fld { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--mute); }
.fld.full { grid-column: 1 / -1; }
.fld input, .fld select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--field); font-size: 13px; color: var(--ink); width: 100%; }
.fld .unit { position: relative; } .fld .unit input { padding-right: 24px; } .fld .unit::after { content: 'ม.'; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--mute); font-size: 11px; }
.calc { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 12.5px; }
.calc div { display: flex; justify-content: space-between; padding: 2px 0; color: var(--ink2); }
.calc div span:first-child { color: var(--mute); }
.calc .tot { font-weight: 600; color: var(--ink); border-top: 1px dashed var(--line2); margin-top: 4px; padding-top: 6px; }
.res { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; padding: 9px 11px; border-radius: 9px; background: var(--soft); }
.res b { font-size: 15px; }
.res.bad { background: var(--badbg); color: var(--danger); }
.acts { display: flex; gap: 6px; margin-top: 12px; }
.acts .btn { flex: 1; }
.btn { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); font-weight: 500; color: var(--ink2); white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.danger { color: var(--danger); }
.btn.dark { background: var(--ink); color: var(--onink); border-color: var(--ink); }
.btn.dark:hover { background: var(--inkh); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 99px; background: var(--soft); font-size: 12px; color: var(--ink2); margin: 2px 4px 2px 0; }
.note { font-size: 12px; color: var(--mute); margin-top: 8px; }

#tip { position: absolute; z-index: 6; pointer-events: none; background: var(--ink); color: var(--onink); padding: 4px 9px; border-radius: 7px; font-size: 12px; white-space: nowrap; display: none; box-shadow: var(--sh); }
#tip b { color: #93c5fd; font-weight: 600; }

/* drawer (summary) */
#drawer { position: absolute; top: 0; right: 0; bottom: 0; width: 360px; background: var(--panel); border-left: 1px solid var(--line); z-index: 6;
  overflow-y: auto; padding: 18px 18px 24px; transform: translateX(100%); transition: transform .22s ease; }
#drawer.open { transform: none; }
.dh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dh h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
.stat { background: var(--soft); border-radius: 10px; padding: 10px 12px; }
.stat .v { font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.stat .l { font-size: 12px; color: var(--mute); }
.sec { font-size: 12px; font-weight: 600; color: var(--mute); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.bar { display: grid; grid-template-columns: 64px 1fr 34px; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.bar .tr { height: 6px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar .tr i { display: block; height: 100%; background: var(--ink); border-radius: 99px; }
.bar .n { text-align: right; font-weight: 600; }
.bar.bad { color: var(--danger); } .bar.bad .tr i { background: var(--danger); }
.rows .r { display: grid; grid-template-columns: 70px 1fr auto; gap: 8px; align-items: center; padding: 7px 6px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.rows .r:hover, .rows .r.on { background: var(--soft); }
.rows .r .m { color: var(--mute); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .r .bad { color: var(--danger); font-weight: 600; }
.code { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.dacts { display: flex; gap: 6px; }
.dacts .btn { flex: 1; }
.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--soft); font-size: 13px; }
.kv span:last-child { font-weight: 600; }

/* popover */
.pop { position: fixed; z-index: 30; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 10px 40px rgba(16,24,40,.16); padding: 6px; min-width: 200px; display: none; }
.pop.open { display: block; }
.mi { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; text-align: left; color: var(--ink2); }
.mi:hover { background: var(--soft); color: var(--ink); }
.mi.danger { color: var(--danger); }
.mdiv { height: 1px; background: var(--line); margin: 4px 2px; }
.pop .ph { font-size: 11.5px; font-weight: 600; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px 4px; }
.vrow { display: flex; align-items: center; gap: 9px; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.vrow:hover { background: var(--soft); }
.vrow input { accent-color: var(--ink); }
.cfg { width: 340px; padding: 6px 8px 10px; }
.lrow { display: grid; grid-template-columns: 26px 1fr 28px; gap: 6px; align-items: center; margin: 4px 0; }
.trow { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin: 6px 0; display: grid; grid-template-columns: 1fr 56px 28px; gap: 6px; align-items: center; }
.trow .full { grid-column: 1 / -1; }
.cfg input[type=text], .cfg input[type=number], .cfg select { border: 1px solid var(--line); border-radius: 7px; padding: 5px 7px; background: var(--field); width: 100%; font-size: 13px; }
.cfg .ib { width: 28px; height: 28px; }
.cfg .add { color: var(--acc); font-weight: 500; padding: 4px 2px; }

/* labels in scene */
.lbl { font: 500 11px/1.2 "IBM Plex Sans Thai", "Leelawadee UI", system-ui, sans-serif; white-space: nowrap; pointer-events: none; }
.lbl.tag { color: #fff; padding: 2px 6px; border-radius: 5px; font-weight: 600; letter-spacing: .01em; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.lbl.dev { color: var(--ink2); background: var(--lblbg); padding: 0 5px; border-radius: 4px; }

/* setup modal */
.modal { position: fixed; inset: 0; background: rgba(17,24,39,.35); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hide { display: none; }
.card { background: var(--panel); border-radius: 16px; padding: 26px 28px 20px; width: min(440px, 92vw); box-shadow: 0 24px 70px rgba(0,0,0,.22); }
.card h2 { margin: 18px 0 14px; font-size: 20px; letter-spacing: -.02em; }
.dims { display: flex; align-items: flex-end; gap: 10px; }
.dims label { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--mute); position: relative; }
.dims input { color: var(--ink); font-size: 26px; font-weight: 600; border: 1px solid var(--line); border-radius: 10px; padding: 8px 40px 8px 12px; width: 100%; letter-spacing: -.02em; }
.dims em { position: absolute; right: 12px; bottom: 15px; font-style: normal; color: var(--mute); }
.dims .x { font-size: 20px; color: var(--mute); padding-bottom: 12px; }
.drop { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 14px; padding: 14px; border: 1.5px dashed var(--line2); border-radius: 10px; color: var(--mute); cursor: pointer; text-align: center; }
#dropTxt { display: flex; align-items: center; gap: 8px; }
.drop:hover { border-color: var(--ink); color: var(--ink); }
.drop.has { border-style: solid; color: var(--ink); background: var(--soft); }
.row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.row input[type=range] { flex: 1; }
details { margin-top: 14px; }
summary { cursor: pointer; color: var(--ink2); font-weight: 500; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-top: 10px; }
.grid2 label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--mute); }
.grid2 input, .grid2 select { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 13.5px; color: var(--ink); background: var(--panel); }
.primary { background: var(--ink); color: var(--onink); border-radius: 10px; padding: 11px; font-weight: 600; font-size: 14.5px; }
.primary:hover { background: var(--inkh); }
.block { width: 100%; margin-top: 18px; }
.links { display: flex; justify-content: center; gap: 18px; margin-top: 12px; }
.link { color: var(--mute); font-weight: 500; }
.link:hover { color: var(--ink); }
.link.danger { color: var(--danger); }
.muted { color: var(--mute); }

/* ---------- start screen (Tencer Snap): white, one question */
.hero { display: none; }
.modal.start { background: var(--panel); backdrop-filter: none; transition: opacity .45s ease; }
.modal.start .card { box-shadow: none; background: none; text-align: center; width: min(460px, 92vw); padding: 0; }
.modal.start .hero { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.modal.start .hlogo { width: 72px; height: 72px; animation: bob 3.2s ease-in-out infinite; }
.modal.start .hname { font-size: 15px; font-weight: 600; letter-spacing: .02em; color: var(--brand); }
.modal.start h2 { margin: 44px 0 26px; font-size: 28px; font-weight: 600; letter-spacing: -.02em; }
.modal.start .dims label span { display: none; }
.modal.start .dims { align-items: center; gap: 14px; }
.modal.start .dims input { text-align: center; font-size: 40px; border: 0; border-bottom: 2px solid var(--line); border-radius: 0; padding: 6px 34px 6px 6px; background: none; transition: border-color .2s; }
.modal.start .dims input:focus { outline: none; border-color: var(--ink); }
.modal.start .dims em { bottom: 18px; right: 4px; font-size: 15px; }
.modal.start .dims .x { padding: 0; font-size: 24px; color: var(--line2); }
.modal.start .drop, .modal.start details, .modal.start #imgOpts { display: none !important; }
.modal.start #sGo { width: auto; margin: 40px auto 0; padding: 13px 38px; border-radius: 99px; background: var(--btn); color: var(--btntx); font-size: 15px;
  transition: transform .15s ease, box-shadow .2s ease, background .2s; box-shadow: 0 6px 20px var(--btnsh); }
.modal.start #sGo:hover { background: var(--btnh); transform: translateY(-2px); box-shadow: 0 10px 26px var(--btnsh); }
.modal.start #sGo:active { transform: translateY(0) scale(.98); }
.modal.start .card > * { animation: rise .6s cubic-bezier(.2,.8,.2,1) both; }
.modal.start .card > :nth-child(2) { animation-delay: .08s; }
.modal.start .card > :nth-child(3) { animation-delay: .16s; }
.modal.start .card > .goRow { animation-delay: .24s; }
.modal.start.leaving { opacity: 0; pointer-events: none; }
.modal.start.leaving .card { transform: scale(.96); transition: transform .45s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes bob { 50% { transform: translateY(-6px); } }
.modal.start input::-webkit-inner-spin-button { -webkit-appearance: none; }
/* โลโก้ขาวดำ: กลับสีในโหมดมืดให้มองเห็น */
:root[data-theme=dark] .logo, :root[data-theme=dark] .hlogo { filter: invert(1); }
#bThemeStart { position: absolute; top: 14px; right: 14px; display: none; }
.modal.start #bThemeStart { display: grid; }
.modal.start input::selection { background: var(--selbg); color: var(--ink); }

/* ---------- step timeline (กลางแถบขาวด้านบน): ไอคอนทุกขั้น / วงทึบ (ปัจจุบัน) / ไอคอนเข้ม (ถัดไป) */
.spacer { flex: 1; }
#timeline { position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 11; display: flex; justify-content: center; align-items: center; pointer-events: none; }
.tl { position: relative; display: flex; align-items: center; gap: 4px; pointer-events: auto; }
.tl::before { content: ''; position: absolute; left: 20px; right: 20px; top: 50%; border-top: 2px dotted var(--line2); }
.pt { position: relative; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 99px; color: var(--mute); transition: color .3s; }
.pt .dt { position: relative; width: 26px; height: 26px; border-radius: 99px; background: var(--panel); display: grid; place-items: center;
  transition: all .4s cubic-bezier(.3,1.4,.5,1); }
.pt .dt svg { width: 15px; height: 15px; transition: width .35s, height .35s; }
.pt .nm { position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%) translateY(-3px); padding: 3px 8px; border-radius: 7px; background: var(--ink); color: var(--onink);
  font-size: 11px; font-weight: 600; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s, transform .15s; }
.pt:hover .nm { opacity: 1; transform: translateX(-50%); }
.pt.done { color: var(--ink2); }
.pt.fut { color: var(--mute); cursor: pointer; }
.pt.cur { color: var(--onink); cursor: default; }
.pt.cur .dt { width: 38px; height: 38px; background: var(--ink); box-shadow: 0 4px 14px rgba(0,0,0,.18); animation: pop .5s cubic-bezier(.3,1.6,.5,1); }
.pt.cur .dt svg { width: 20px; height: 20px; }
.pt.next { color: var(--ink); cursor: pointer; }
.pt.next:hover .dt { transform: scale(1.2); }
.pt.done:hover, .pt.fut:hover { color: var(--ink); }
.pt.done:hover .dt, .pt.fut:hover .dt { transform: scale(1.2); }
.pt:disabled { cursor: default; }
.pt:focus, .pt:focus-visible { outline: none; }
@keyframes pop { 0% { transform: scale(.4); } }
@keyframes ring { 0% { transform: scale(.6); opacity: .55; } 100% { transform: scale(1.5); opacity: 0; } }

/* ---------- axis gizmo (มุมขวาบน) */
#gizmo { position: absolute; top: 14px; right: 14px; width: 100px; height: 100px; z-index: 5; border-radius: 99px; cursor: grab; transition: background .2s, right .22s; }
#gizmo:hover { background: color-mix(in srgb, var(--soft) 75%, transparent); }
#gizmo svg { display: block; overflow: visible; }
#gizmo .gzc { cursor: pointer; transition: transform .15s; transform-box: fill-box; transform-origin: center; }
#gizmo .gzc:hover { transform: scale(1.18); }
#gizmo text { font: 700 10.5px/1 system-ui, sans-serif; fill: #fff; pointer-events: none; }

/* ---------- right vertical toolbar */
#tools { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); z-index: 5; display: flex; flex-direction: column; gap: 4px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--sh); animation: slideL .35s cubic-bezier(.2,.8,.2,1); }
#tools:empty { display: none; }
.tool { position: relative; width: 78px; padding: 10px 4px 18px; border-radius: 11px; display: flex; flex-direction: column; align-items: center; gap: 5px;
  color: var(--ink2); font-size: 11px; line-height: 1.2; text-align: center; transition: background .15s, color .15s, transform .12s; }
.tool:hover { background: var(--soft); }
.tool.on { background: var(--ink); color: var(--onink); }
.tool:active { transform: scale(.94); }
@keyframes slideL { from { opacity: 0; transform: translate(14px, -50%); } }
.hk { position: absolute; right: 3px; bottom: 3px; font: 700 9px/1 ui-monospace, Consolas, monospace; padding: 2px 3px; border-radius: 3px;
  background: var(--soft); color: var(--mute); border: 1px solid var(--line); pointer-events: none; }
.tool.on .hk, .tb.on .hk, .chip.on .hk { background: transparent; color: inherit; opacity: .7; border-color: currentColor; }
.tb, .chip { position: relative; }
.tb[data-hk], .chip[data-hk] { padding-right: 22px; }
.tb .hk, .chip .hk { bottom: 50%; transform: translateY(50%); right: 4px; }

/* ---------- selection card: bottom-right */
#card { top: auto; bottom: 18px; right: 18px; transition: right .22s; animation: rise .3s cubic-bezier(.2,.8,.2,1); }

/* ---------- key legend (ซ้ายล่าง แบบเกม) */
#keys { position: absolute; left: 18px; bottom: 18px; z-index: 4; display: flex; flex-direction: column; gap: 6px; pointer-events: none; font-size: 12px; color: var(--ink2); }
#keys .k { display: flex; align-items: center; gap: 10px; height: 22px; }      /* ทุกแถวสูงเท่ากัน (เมาส์/ปุ่มคีย์บอร์ด) → ระยะห่างเท่ากัน */
#keys.intro .k { animation: rise .35s cubic-bezier(.2,.8,.2,1) both; }
#keys.intro .k:nth-child(1) { animation-delay: 0.04s; }
#keys.intro .k:nth-child(2) { animation-delay: 0.08s; }
#keys.intro .k:nth-child(3) { animation-delay: 0.12s; }
#keys.intro .k:nth-child(4) { animation-delay: 0.16s; }
#keys.intro .k:nth-child(5) { animation-delay: 0.20s; }
#keys.intro .k:nth-child(6) { animation-delay: 0.24s; }
#keys.intro .k:nth-child(7) { animation-delay: 0.28s; }
#keys.intro .k:nth-child(8) { animation-delay: 0.32s; }
#keys.intro .k:nth-child(9) { animation-delay: 0.36s; }
#keys.intro .k:nth-child(10) { animation-delay: 0.40s; }

#keys .kc { width: var(--kcw, 44px); display: flex; gap: 3px; justify-content: flex-end; align-items: center; color: var(--ink); }
#keys kbd { font: 600 10.5px/1 ui-monospace, Consolas, monospace; box-sizing: border-box; height: 21px; padding: 0 7px; min-width: 22px; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px;
  background: var(--panel); border: 1.4px solid var(--ink); color: var(--ink); }      /* สูงเท่าไอคอนเมาส์ (21px) ขอบเส้นเดียวกัน → ช่องว่างระหว่างแถวเท่ากันทุกแถว */
#keys .ms { display: block; }
#keys .kc > * { flex: none; }      /* ไม่ให้ปุ่มบีบตัว (Shift + เมาส์) — วัดความกว้างจริงได้ */
#keys .kl { text-shadow: 0 0 6px var(--bg); }

/* ---------- toast */
#toast { position: absolute; top: 74px; left: 50%; transform: translateX(-50%); z-index: 8; background: var(--ink); color: var(--onink); padding: 7px 15px;
  border-radius: 99px; font-size: 12.5px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
#toast.show { opacity: 1; transform: translate(-50%, 4px); }

/* โลโก้ขาวดำ: กลับสีในโหมดมืดให้มองเห็น */
:root[data-theme=dark] .logo, :root[data-theme=dark] .hlogo { filter: invert(1); }
.modal.start input::selection { background: var(--selbg); color: var(--ink); }


/* ปุ่มหมุน 90° ใต้แกน */
#gizrot { position: absolute; top: 118px; right: 14px; width: 100px; z-index: 5; display: flex; justify-content: center; gap: 6px; transition: right .22s; }
#gizrot .ib { width: 34px; height: 34px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--sh); transition: transform .15s, background .15s; }
#gizrot .ib:hover { transform: scale(1.08); }
#gizrot .ib:active { transform: scale(.92) rotate(var(--r, 0deg)); }

/* ---------- right toolbar: วงกลมใน capsule แบบ iOS */
#tools { border-radius: 999px; padding: 7px; gap: 8px; background: color-mix(in srgb, var(--panel) 86%, transparent); backdrop-filter: blur(14px); }
.tool { width: 50px; height: 50px; padding: 0; border-radius: 999px; justify-content: center; gap: 0; background: var(--soft); }
.tool:hover { background: var(--line); }
.tool.on { background: var(--ink); color: var(--onink); box-shadow: 0 4px 14px rgba(0,0,0,.22); }
.tool > span { position: absolute; right: calc(100% + 14px); top: 50%; transform: translate(6px, -50%); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--onink); padding: 5px 11px; border-radius: 99px; font-size: 12px; white-space: nowrap; transition: opacity .18s, transform .18s; }
.tool:hover > span { opacity: 1; transform: translate(0, -50%); }
.tool .hk { right: -3px; bottom: -3px; width: 17px; height: 17px; padding: 0; display: grid; place-items: center; border-radius: 99px;
  background: var(--panel); color: var(--ink2); border: 1px solid var(--line2); }
.tool.on .hk { background: var(--panel); color: var(--ink); opacity: 1; border-color: var(--line2); }

/* ---------- bottom-right view capsule */
#viewbar { position: absolute; right: 18px; bottom: 18px; z-index: 5; display: flex; align-items: center; gap: 6px; padding: 5px;
  border-radius: 999px; background: color-mix(in srgb, var(--panel) 86%, transparent); backdrop-filter: blur(14px);
  border: 1px solid var(--line); box-shadow: var(--sh); transition: right .22s; }
.seg2 { position: relative; display: flex; gap: 2px; }
.seg2 button { position: relative; height: 36px; min-width: 36px; padding: 0 11px; border-radius: 999px; display: grid; place-items: center;
  color: var(--mute); font-weight: 600; font-size: 12.5px; transition: background .2s, color .2s, transform .12s; }
.seg2 button:hover { color: var(--ink); background: var(--soft); }
.seg2 button:active { transform: scale(.93); }
.seg2 button.on { background: var(--ink); color: var(--onink); }
#wallView button { padding: 0; width: 36px; }
#wallView button[data-tip]::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translate(-50%, 4px);
  background: var(--ink); color: var(--onink); padding: 4px 10px; border-radius: 99px; font-size: 11.5px; font-weight: 500; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
#wallView button:hover::after { opacity: 1; transform: translate(-50%, 0); }
.vsep { width: 1px; height: 22px; background: var(--line); }
#viewbar #wallView, #viewbar .vsep { transition: opacity .25s, max-width .3s; max-width: 220px; overflow: visible; }
#viewbar.is2d #wallView, #viewbar.is2d .vsep { opacity: 0; max-width: 0; pointer-events: none; overflow: hidden; }
#card { bottom: 78px; }

/* ---------- curved rotate arrows under gizmo */
#gizrot { top: 112px; height: 30px; display: block; }
#gizrot svg { display: block; overflow: visible; }
#gizrot .rarr { cursor: pointer; }
#gizrot .rarr .hit { fill: none; stroke: transparent; stroke-width: 16; }
#gizrot .rarr .ln { fill: none; stroke: var(--ink2); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; transition: stroke .15s; }
#gizrot .rarr:hover .ln { stroke: var(--ink); stroke-width: 3; }
#gizrot .rarr:active { opacity: .6; }
#keys .ms { width: 15px; height: 21px; }

#gizrot { top: 106px; height: 34px; }
#gizrot .rarr .ln { stroke-width: 3; }
#gizrot .rarr .hd { fill: var(--ink2); transition: fill .15s; }
#gizrot .rarr:hover .hd { fill: var(--ink); }

/* เลขระยะบนขอบพื้นที่ */
.lbl.ruler { color: var(--mute); opacity: .75; font-size: 10.5px; font-weight: 500; font-variant-numeric: tabular-nums; }

/* แถบมุมมองขวาล่าง: ขนาดเท่าแถบเครื่องมือ */
#viewbar { padding: 7px; gap: 8px; }
.seg2 { gap: 8px; }
.seg2 button { width: 50px; height: 50px; min-width: 50px; padding: 0; font-size: 14px; background: var(--soft); }
#wallView button { width: 50px; }
.seg2 button.on { background: var(--ink); color: var(--onink); box-shadow: 0 4px 14px rgba(0,0,0,.22); }
.vsep { height: 30px; }
#card { bottom: 96px; }

/* ลูกศรหมุน 90°: ซ้อนรอบแกน (ศูนย์กลางเดียวกัน) ไม่บังการคลิกแกน */
#gizrot { top: 14px; right: 4px; width: 120px; height: 106px; pointer-events: none; }
#gizrot svg { pointer-events: none; }
#gizrot .rarr { pointer-events: auto; }
#gizrot .rarr .hit { stroke-width: 18; }
#gizrot .rarr .ln { stroke: var(--ink2); stroke-width: 4.5; stroke-linecap: round; }
#gizrot .rarr .hd { fill: var(--ink2); stroke: var(--ink2); stroke-width: 1.5; stroke-linejoin: round; }
#gizrot .rarr:hover .ln { stroke: var(--ink); stroke-width: 4.5; }
#gizrot .rarr:hover .hd { fill: var(--ink); stroke: var(--ink); }
#gizrot .rarr { transition: opacity .15s; } #gizrot .rarr:active { opacity: .55; }

/* แถบมุมมอง: สมมาตรทั้งตอน 2D (เหลือ 2 ปุ่ม) และ 3D */
#viewbar { gap: 0; }
#viewbar .vsep { margin: 0 10px; transition: opacity .25s, margin .3s, width .3s; }
#viewbar.is2d .vsep { margin: 0; width: 0; }
#viewbar #wallView { transition: opacity .25s, max-width .3s; }
#viewbar.is2d #wallView { max-width: 0; }
.seg2 .hk { right: -2px; bottom: -2px; width: 16px; height: 16px; padding: 0; display: grid; place-items: center; border-radius: 99px;
  background: var(--panel); color: var(--ink2); border: 1px solid var(--line2); transform: none; }
.seg2 button.on .hk { background: var(--panel); color: var(--ink); opacity: 1; border-color: var(--line2); }
#viewToggle { position: relative; }
#viewToggle .tabk { width: auto; padding: 0 4px; height: 15px; right: 50%; bottom: -6px; transform: translateX(50%); font-size: 8.5px; }

/* ลูกศรหมุน: ความหนาพอดีแบบเดิม แต่เส้นโค้งยาวกว้างขึ้น */
#gizrot .rarr .ln, #gizrot .rarr:hover .ln { stroke-width: 3; }
#gizrot .rarr .hd { stroke-width: 1; }

/* ลูกศรหมุน (แบบร่าง): อยู่ใต้แกนพอดี สั้น หนา */
#gizrot { top: 104px; right: 14px; width: 100px; height: 34px; }
#gizrot .rarr .ln, #gizrot .rarr:hover .ln { stroke-width: 5; stroke-linecap: round; }
#gizrot .rarr .hd { stroke-width: 2.5; stroke-linejoin: round; }

#gizrot { top: 100px; height: 36px; }
#gizrot .rarr .ln, #gizrot .rarr:hover .ln { stroke-width: 5.5; }

/* แถบเครื่องมือพรม: ช่องตัวเลขหน้ากว้าง + สี เป็นวงกลมขนาดเดียวกับปุ่ม */
.tsep { width: 30px; height: 1px; background: var(--line); margin: 2px auto; }
.tnum { flex-direction: column; gap: 0; cursor: text; }
.tnum input { width: 40px; border: 0; background: none; text-align: center; font: 600 15px/1 inherit; color: var(--ink); padding: 0; -moz-appearance: textfield; }
.tnum input::-webkit-inner-spin-button, .tnum input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.tnum input:focus { outline: none; }
.tnum em { font-style: normal; font-size: 9.5px; color: var(--mute); margin-top: 2px; }
.tnum:focus-within { box-shadow: 0 0 0 2px var(--ink); }
.tcolor { cursor: pointer; }
.tcolor input { width: 32px; height: 32px; border: 0; padding: 0; border-radius: 99px; overflow: hidden; background: none; cursor: pointer; }
.tcolor input::-webkit-color-swatch-wrapper { padding: 0; } .tcolor input::-webkit-color-swatch { border: 0; border-radius: 99px; }

/* การ์ดพรม: ปุ่มแนวปู + สี ขนาดใหญ่ */
.crow { display: flex; gap: 8px; }
.cbtn { flex: 1; height: 48px; border-radius: 12px; display: grid; place-items: center; background: var(--soft); color: var(--ink2); border: 1px solid transparent; transition: background .15s, color .15s; cursor: pointer; }
.cbtn:hover { background: var(--line); }
.cbtn.on { background: var(--ink); color: var(--onink); }
.ccol input { width: 30px; height: 30px; border: 0; padding: 0; border-radius: 99px; background: none; cursor: pointer; }
.ccol input::-webkit-color-swatch-wrapper { padding: 0; } .ccol input::-webkit-color-swatch { border: 0; border-radius: 99px; }

/* ชื่อโปรแกรม + เวอร์ชัน (แบบ Tencer Beam) */
#top .logo { width: 28px; height: 28px; }
.bname { display: flex; flex-direction: column; line-height: 1.1; }
.bname span { font-size: 15px; font-weight: 600; }
.bname small { font-size: 9.5px; font-weight: 600; letter-spacing: .08em; color: var(--mute); margin-top: 2px; }

/* ---------- แคตตาล็อกเฟอร์นิเจอร์ (สไลด์ขึ้นจากด้านล่าง) */
#catalog { position: absolute; left: 50%; bottom: 18px; z-index: 6; width: min(620px, calc(100% - 520px)); min-width: 360px;
  transform: translate(-50%, calc(100% + 30px)); opacity: 0; pointer-events: none; transition: transform .35s cubic-bezier(.2,.8,.2,1), opacity .25s;
  background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--sh); padding: 10px 10px 12px; }
#catalog.open { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.ctabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding-bottom: 8px; }
.ctabs button { padding: 6px 12px; border-radius: 99px; color: var(--mute); font-weight: 600; white-space: nowrap; transition: background .15s, color .15s; }
.ctabs button:hover { color: var(--ink); background: var(--soft); }
.ctabs button.on { background: var(--ink); color: var(--onink); }
.citems { display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding: 2px; }     /* ซ่อนแถบเลื่อน (เลื่อนด้วยลูกกลิ้งเมาส์แทน) ไม่ให้โผล่ตอนการ์ดเลื่อนเข้ามา */
.citems::-webkit-scrollbar { display: none; }
/* แถบเลื่อนได้ทั่วไป: ลูกศรติดขอบ (sticky) บนพื้นจาง ขึ้นเฉพาะฝั่งที่ยังเลื่อนไปได้ */
:is(#opts, .ctabs)::before, :is(#opts, .ctabs)::after, .lpm-list::before, .lpm-list::after {
  content: ''; position: sticky; flex: none; z-index: 3; pointer-events: none; opacity: 0; transition: opacity .18s; background-repeat: no-repeat; }
:is(#opts, .ctabs)::before, :is(#opts, .ctabs)::after { width: 30px; align-self: stretch; }
:is(#opts, .ctabs)::before { left: 0; margin-right: -30px; order: -999;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m15 18-6-6 6-6'/%3E%3C/svg%3E"), linear-gradient(to right, var(--panel) 55%, transparent);
  background-size: 15px, 100%; background-position: 3px center, 0 0; }
:is(#opts, .ctabs)::after { right: 0; margin-left: -30px; order: 999;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E"), linear-gradient(to left, var(--panel) 55%, transparent);
  background-size: 15px, 100%; background-position: calc(100% - 3px) center, 0 0; }
.lpm-list::before, .lpm-list::after { height: 24px; min-height: 24px; }
.lpm-list::before { top: 0; margin-bottom: -30px; order: -999;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m18 15-6-6-6 6'/%3E%3C/svg%3E"), linear-gradient(to bottom, var(--panel) 55%, transparent);
  background-size: 15px, 100%; background-position: center 2px, 0 0; }
.lpm-list::after { bottom: 0; margin-top: -30px; order: 999;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"), linear-gradient(to top, var(--panel) 55%, transparent);
  background-size: 15px, 100%; background-position: center calc(100% - 2px), 0 0; }
:is(#opts, .ctabs, .lpm-list).sh-s::before, :is(#opts, .ctabs, .lpm-list).sh-e::after { opacity: 1; pointer-events: auto; cursor: pointer; }
/* ลูกศรเลื่อน + ขอบจาง: ขึ้นเฉพาะฝั่งที่ยังเลื่อนไปได้ */
.cwrap { position: relative; --fl: 0px; --fr: 0px; }
.cwrap.l { --fl: 56px; } .cwrap.r { --fr: 56px; }
.cwrap .citems { -webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%); }
.cnav { position: absolute; top: 50%; z-index: 2; width: 34px; height: 34px; border-radius: 99px; display: grid; place-items: center; background: var(--panel); color: var(--ink);
  box-shadow: 0 2px 10px rgba(0,0,0,.16); opacity: 0; pointer-events: none; transform: translateY(-50%) scale(.7); transition: opacity .18s, transform .22s cubic-bezier(.3,1.5,.5,1); }
.cnav.l { left: -4px; } .cnav.r { right: -4px; }
.cwrap.l .cnav.l, .cwrap.r .cnav.r { opacity: 1; pointer-events: auto; transform: translateY(-50%); }
.cwrap .cnav:hover { transform: translateY(-50%) scale(1.1); }
.citem { flex: none; min-width: 96px; padding: 6px 10px 8px; border-radius: 14px; background: var(--soft); display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 2px solid transparent; transition: transform .15s, border-color .15s, background .15s; animation: rise .3s both; }
.citem:hover { transform: translateY(-3px); background: var(--line); }
.citem.on { border-color: var(--ink); background: var(--panel); }
.citem img { width: 68px; height: 68px; object-fit: contain; }
.citem b { font-size: 12.5px; font-weight: 600; color: var(--ink); white-space: nowrap; }      /* ชื่อบรรทัดเดียว — ชื่อยาวการ์ดกว้างขึ้นเอง */
.citem small { font-size: 11px; color: var(--mute); }
/* การ์ดเฟอร์นิเจอร์ */
.fsub { font-size: 11.5px; color: var(--mute); margin: 12px 0 5px; }
.pset { display: flex; align-items: center; gap: 8px; }
.pset .cbtn { flex: none; width: 40px; height: 40px; }
.pset span { flex: 1; text-align: center; font-weight: 600; }
.imgrow { display: flex; align-items: center; gap: 6px; }
.imgrow img { width: 44px; height: 32px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.imgrow .btn:first-of-type { flex: 1; }

/* ปุ่ม "สร้างห้อง": hover แบบเกม — เด้งขยาย, ลูกศรเลื่อนเข้า, แสงวิ่งผ่าน, วงคลื่นกระจายออก */
:root { --shine: rgba(255,255,255,.38); } :root[data-theme=dark] { --shine: rgba(0,0,0,.14); }
.modal.start #sGo { position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; gap: 0; padding: 14px 44px;
  transition: transform .45s cubic-bezier(.34,1.56,.64,1), gap .4s cubic-bezier(.34,1.56,.64,1), padding .4s cubic-bezier(.34,1.56,.64,1), background .3s, box-shadow .4s; }
.modal.start #sGo .i { width: 0; opacity: 0; transform: translateX(-10px); transition: width .4s cubic-bezier(.34,1.56,.64,1), opacity .25s, transform .45s cubic-bezier(.34,1.56,.64,1); }
.modal.start #sGo::before { content: ''; position: absolute; top: 0; left: -70%; width: 45%; height: 100%; pointer-events: none;
  background: linear-gradient(100deg, transparent, var(--shine), transparent); transform: skewX(-20deg); }
.modal.start #sGo:hover { transform: scale(1.07); gap: 10px; padding: 14px 36px 14px 44px; background: var(--btnh); animation: sgoPulse 1.6s ease-out infinite; }
.modal.start #sGo:hover .i { width: 18px; opacity: 1; transform: none; }
.modal.start #sGo:hover::before { animation: sgoShine .9s ease .05s; }
.modal.start #sGo:active { transform: scale(.94); transition-duration: .12s; }
@keyframes sgoShine { to { left: 135%; } }
@keyframes sgoPulse {
  0% { box-shadow: 0 14px 34px var(--btnsh), 0 0 0 0 color-mix(in srgb, var(--btn) 40%, transparent); }
  100% { box-shadow: 0 14px 34px var(--btnsh), 0 0 0 16px color-mix(in srgb, var(--btn) 0%, transparent); }
}

/* ---------- เข้าโปรแกรม: แถบต่าง ๆ เลื่อนเข้ามาทีละชิ้น */
body.entering #top { animation: inTop .6s cubic-bezier(.2,.8,.2,1) .15s both; }
body.entering #timeline { animation: inTop .6s cubic-bezier(.2,.8,.2,1) .35s both; }
body.entering #keys { animation: inLeft .7s cubic-bezier(.2,.8,.2,1) .55s both; }
body.entering #gizmo, body.entering #gizrot { animation: inRight .7s cubic-bezier(.2,.8,.2,1) .4s both; }
body.entering #tools { animation: inRightMid .7s cubic-bezier(.34,1.4,.64,1) .5s both; }
body.entering #viewbar { animation: inBottom .7s cubic-bezier(.34,1.4,.64,1) .6s both; }
body.entering #view canvas { animation: inFade .8s ease both; }
@keyframes inTop { from { opacity: 0; transform: translateY(-100%); } }
@keyframes inLeft { from { opacity: 0; transform: translateX(-40px); } }
@keyframes inRight { from { opacity: 0; transform: translateX(40px); } }
@keyframes inRightMid { from { opacity: 0; transform: translate(40px, -50%); } }
@keyframes inBottom { from { opacity: 0; transform: translateY(40px); } }
@keyframes inFade { from { opacity: 0; } }

.citem { animation: none; }
.citems.anim .citem { animation: rise .32s cubic-bezier(.2,.8,.2,1) both; }
.citems.anim .citem:nth-child(1) { animation-delay: 0.00s; }
.citems.anim .citem:nth-child(2) { animation-delay: 0.04s; }
.citems.anim .citem:nth-child(3) { animation-delay: 0.08s; }
.citems.anim .citem:nth-child(4) { animation-delay: 0.12s; }
.citems.anim .citem:nth-child(5) { animation-delay: 0.16s; }
.citems.anim .citem:nth-child(6) { animation-delay: 0.20s; }

/* ภาพทับตอนสลับ 2D/3D (จางออก) */
#xfade { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; opacity: 0; }
/* ห้ามลากรูปในแคตตาล็อก (กดค้างแล้วไม่กลายเป็นการลากรูป) */
.citem, .citem img { -webkit-user-drag: none; user-select: none; -webkit-user-select: none; }
.citem img { pointer-events: none; }

/* หน้าแรก: ปุ่มไอคอนเปิดไฟล์งาน อยู่ขวาปุ่มสร้างห้อง */
.goRow { display: flex; justify-content: center; align-items: center; gap: 12px; }
.modal.start .goRow { margin-top: 40px; padding-left: 60px; }     /* เว้นซ้ายเท่าปุ่มโฟลเดอร์ ให้ปุ่มสร้างห้องอยู่กึ่งกลางพอดี */ .modal.start .goRow #sGo { margin: 0; }
#sOpenIc { display: none; }
.modal.start #sOpenIc { display: grid; width: 48px; height: 48px; border-radius: 99px; border: 1px solid var(--line); color: var(--ink2); transition: transform .3s cubic-bezier(.34,1.56,.64,1), border-color .2s, color .2s; }
.modal.start #sOpenIc:hover { transform: scale(1.1); color: var(--ink); border-color: var(--ink2); }
.modal.start #sOpenIc:active { transform: scale(.94); }
.modal.start .links { display: none !important; }

/* Alt+ลาก วัดระยะ */
.lbl.meas { color: #fff; background: #f59e0b; padding: 3px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; box-shadow: 0 2px 8px rgba(0,0,0,.25); }


/* ปุ่ม ✓ ยืนยันสร้างโต๊ะเคาน์เตอร์: ใต้กึ่งกลางโต๊ะ (ตำแหน่งตั้งจาก JS ทุกเฟรม) */
#okmark { position: absolute; left: 0; top: 0; z-index: 5; width: 34px; height: 34px; border-radius: 99px; display: none; place-items: center; background: #16a34a; color: #fff; border: 0; box-shadow: 0 4px 14px rgba(0,0,0,.3); cursor: pointer; }
#okmark.on { display: grid; }
#okmark:hover { background: #15803d; }

/* ระหว่างโหลดสคริปต์ (ไอคอนยังไม่ถูกใส่) ไม่โชว์ปุ่มว่าง */
#sOpenIc:empty, #bThemeStart:empty { visibility: hidden; }

.tool.tdanger { color: var(--danger); }
.tool.tdanger:hover { background: var(--danger); color: #fff; }

/* popup ตั้งค่า Truss: แคปซูลแยก เลื่อนออกมาทางซ้ายของแถบเครื่องมือ */
#tprops { position: absolute; right: 94px; top: 50%; transform: translateY(-50%); z-index: 5; display: flex; flex-direction: column; gap: 8px; padding: 7px; border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 86%, transparent); backdrop-filter: blur(14px); border: 1px solid var(--line); box-shadow: var(--sh); animation: tpIn .32s cubic-bezier(.2,.8,.2,1); }
#tprops:empty { display: none; }
@keyframes tpIn { from { opacity: 0; transform: translate(30px, -50%); } }

/* แถบเลเยอร์ (V): บนกลาง แคปซูล ปุ่มวงกลมแบบเดียวกับแถบอื่น (เปิด = ทึบ, ปิด = จาง), ชื่อขึ้นตอนชี้ */
#layerbar { position: absolute; left: 18px; top: 18px; z-index: 7; display: flex; align-items: center; gap: 4px; padding: 5px; border-radius: 999px;      /* ซ้ายบน กะทัดรัด */
  background: color-mix(in srgb, var(--panel) 86%, transparent); backdrop-filter: blur(14px); border: 1px solid var(--line); box-shadow: var(--sh);
  transform: translateY(-8px); opacity: 0; pointer-events: none; transition: transform .22s ease-out, opacity .18s; }
#layerbar.open { transform: none; opacity: 1; pointer-events: auto; }
.lbtn { position: relative; width: 34px; height: 34px; border-radius: 999px; display: grid; place-items: center; background: linear-gradient(var(--ink), var(--ink)) bottom / 100% 0% no-repeat, var(--soft); color: var(--mute); opacity: .42; transition: opacity .25s ease, background-size .38s cubic-bezier(.3,.7,.3,1), color .25s ease, transform .15s; }
.lbtn.bump { animation: lpop .38s cubic-bezier(.34,1.56,.64,1); }
.lbtn.bump .i, .lbtn.bump .ldot { animation: lspin .38s cubic-bezier(.34,1.56,.64,1); }
@keyframes lpop { 0% { transform: scale(1); } 35% { transform: scale(.82); } 100% { transform: scale(1); } }
@keyframes lspin { 0% { transform: scale(1); } 40% { transform: scale(.7) rotate(-8deg); } 100% { transform: scale(1) rotate(0); } }
.lbtn:hover { opacity: .85; }
.lbtn.on { opacity: 1; background-size: 100% 100%; color: var(--onink); }
.lbtn:active { transform: scale(.93); }
.lbtn .ltip { position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%); padding: 3px 8px; border-radius: 7px; background: var(--ink); color: var(--onink); font-size: 11px; font-weight: 600; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; }
.lbtn:hover .ltip { opacity: 1; }
.lbtn svg { width: 17px; height: 17px; }
.ldot { width: 15px; height: 15px; border-radius: 99px; display: block; box-shadow: 0 0 0 2px var(--panel); }
.lsep { width: 1px; height: 20px; margin: 0 3px; background: var(--line); }
.lclose { width: 26px; height: 26px; border-radius: 99px; display: grid; place-items: center; color: var(--mute); }
.lclose:hover { background: var(--soft); color: var(--ink); }
.vsep2 { width: 1px; height: 30px; background: var(--line); }

/* ปุ่มสี่เหลี่ยมกลางแกน: สลับ perspective / orthographic */
#gizmo .gzp { cursor: pointer; }
#gizmo .gzp .hit { fill: transparent; }
#gizmo .gzp path { fill: color-mix(in srgb, var(--panel) calc(var(--lit) * 100%), var(--line)); stroke: var(--ink2); stroke-width: 1.3; stroke-linejoin: round; transition: fill .15s; }
#gizmo .gzp:hover path { stroke: var(--ink); }
#gizmo .gzp.on path { fill: color-mix(in srgb, var(--ink) calc(var(--lit) * 100%), #000); stroke: var(--ink); }

/* ปุ่มในแถบที่เพิ่งเปลี่ยนชุด: เด้งเข้าทีละปุ่ม */
.tin { animation: tin .34s cubic-bezier(.34,1.56,.64,1) both; }
@keyframes tin { from { opacity: 0; transform: scale(.55); } }

/* เลือก layer ของ Switch: ปุ่มหลัก + สีของแต่ละ layer เด้งเรียงเป็นวงโค้งทางซ้ายตอนชี้ */
.lpick { position: relative; }
.lpdot { width: 22px; height: 22px; border-radius: 99px; display: grid; place-items: center; box-shadow: 0 0 0 2px var(--panel), 0 0 0 3.5px var(--line2); color: var(--mute); }
.lpfan { position: absolute; left: 50%; top: 50%; width: 0; height: 0; z-index: 3; }
.lpfan::before { content: ''; position: absolute; left: -112px; top: -130px; width: 126px; height: 260px; border-radius: 60px 0 0 60px; pointer-events: none; }
.lpick:hover .lpfan::before { pointer-events: auto; }
.lpsw { position: absolute; left: 0; top: 0; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 99px; background: var(--c, var(--soft)); border: 2px solid var(--panel); box-shadow: var(--sh);
  display: grid; place-items: center; color: var(--ink2); opacity: 0; pointer-events: none;
  transform: translate(0, 0) scale(.3); transition: transform .28s cubic-bezier(.34,1.56,.64,1) var(--d), opacity .18s var(--d); }
.lpsw.add { background: var(--panel); border-color: var(--line2); }
.lpick:hover .lpsw { opacity: 1; pointer-events: auto; transform: translate(var(--x), var(--y)) scale(1); }
.lpsw:hover { transform: translate(var(--x), var(--y)) scale(1.18) !important; }
.lpsw.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--ink); }
.lptip { position: absolute; right: calc(100% + 6px); top: 50%; transform: translateY(-50%); padding: 2px 7px; border-radius: 6px; background: var(--ink); color: var(--onink); font-size: 11px; font-weight: 600; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; }
.lpsw:hover .lptip { opacity: 1; }
/* popup สร้าง layer ใหม่ */
#lpnew { position: absolute; right: 172px; top: 50%; transform: translateY(-50%) scale(.95); z-index: 8; width: 230px; padding: 14px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--sh);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .22s cubic-bezier(.34,1.56,.64,1); display: flex; flex-direction: column; gap: 10px; }
#lpnew.open { opacity: 1; pointer-events: auto; transform: translateY(-50%) scale(1); }
.lpn-h { font-weight: 700; font-size: 14px; }
.lpn-name { width: 100%; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--soft); color: var(--ink); font: inherit; }
.lpn-sw { display: flex; flex-wrap: wrap; gap: 7px; }
.lpn-sw button, .lpn-cust { width: 26px; height: 26px; border-radius: 99px; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.lpn-sw button.on { box-shadow: 0 0 0 2px var(--ink); }
.lpn-cust { position: relative; overflow: hidden; background: conic-gradient(#ef4444, #f59e0b, #22c55e, #3b82f6, #a855f7, #ef4444); }
.lpn-cust input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.lpn-act { display: flex; gap: 8px; justify-content: flex-end; }
.lpick:not(.empty) > .tool > span { display: none; }      /* มีวงสีเด้งออกทางซ้ายแล้ว → ไม่โชว์ชื่อปุ่มซ้อนทับ */

.lpn-row { display: flex; align-items: center; gap: 8px; }
.lpn-run { font-size: 13px; white-space: nowrap; }

/* แบบติดตั้ง AP: ใช้วงโค้งเดียวกับเลือก layer แต่เป็นปุ่มไอคอน */
.lpsw.ico { background: var(--panel); border-color: var(--line2); color: var(--ink2); }
.lpsw.ico.on { background: var(--ink); color: var(--onink); }

/* หน้าต่างจัดการ layer */
.lpm-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; scrollbar-width: none; }
.lpm-row { display: flex; align-items: center; gap: 8px; }
.lpm-row .lpn-name { flex: 1; min-width: 0; padding: 6px 9px; }
.lpm-c { position: relative; flex: none; width: 26px; height: 26px; border-radius: 99px; cursor: pointer; box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--line2); }
.lpm-c input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.lpm-x { flex: none; width: 28px; height: 28px; border-radius: 99px; display: grid; place-items: center; color: var(--mute); }
.lpm-x:hover { background: color-mix(in srgb, #ef4444 15%, transparent); color: #ef4444; }
.lpm-empty { font-size: 12px; color: var(--mute); }

/* ตัวเลือกสี: ช่องสี + แถบ hue + ปุ่ม ✗ / ✓ */
#cpick { position: fixed; z-index: 30; width: 240px; padding: 14px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--sh); display: flex; flex-direction: column; gap: 12px;
  opacity: 0; pointer-events: none; transform: scale(.94); transition: opacity .15s, transform .2s cubic-bezier(.34,1.56,.64,1); }
#cpick.open { opacity: 1; pointer-events: auto; transform: none; }
.cp-sv { position: relative; height: 140px; border-radius: 12px; cursor: crosshair; touch-action: none; }
.cp-hue { position: relative; height: 12px; border-radius: 99px; cursor: pointer; touch-action: none; background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.cp-sv i, .cp-hue i { position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 99px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35), 0 2px 6px rgba(0,0,0,.3); pointer-events: none; }
.cp-hue i { top: 50%; }
.cp-row { display: flex; align-items: center; gap: 8px; }
.cp-prev { flex: none; width: 28px; height: 28px; border-radius: 99px; box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--line2); }
.cp-hex { flex: 1; min-width: 0; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--soft); color: var(--ink); font: inherit; font-size: 12px; text-transform: uppercase; }
.cp-btn { flex: none; width: 32px; height: 32px; border-radius: 99px; display: grid; place-items: center; color: var(--ink2); background: var(--soft); transition: transform .12s, background .12s; }
.cp-btn:hover { transform: scale(1.08); }
.cp-btn.ok { background: var(--ink); color: var(--onink); }

/* แก้ไขสาย */
.ce-f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--mute); }
.ce-f select.lpn-name { appearance: auto; }
.ce-f .lpn-row input { flex: 1; min-width: 0; }
.ce-lock { width: 36px; height: 36px; flex: none; border-radius: 99px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--soft); color: var(--ink2); cursor: pointer; }
.ce-lock.on { background: var(--ink); color: var(--onink); border-color: var(--ink); }
.ce-need { font-size: 12px; color: var(--mute); }
.crun { display: flex; align-items: center; gap: 6px; }
.crun input { flex: 1; min-width: 0; }
.crun .ce-lock { width: 30px; height: 30px; }

/* ความยาวสายในแคปซูล: ตัวเลขแทนไอคอน */
.tlen { font: 700 15px/1 inherit; color: inherit; }
.tlen.bad { color: #dc2626; }
.lpsw.txt { font: 700 11px/1 inherit; color: var(--ink2); }
.lpsw.txt.on { color: var(--onink); }
/* ปุ่มแสดงผลสายแลนโหมด "ครึ่ง" (เห็นแบบจริง): ครึ่งปุ่มทึบ */
.lbtn.half { opacity: 1; background-size: 100% 100%; color: var(--onink); }      /* โหมดครึ่ง: ปุ่มเต็มเหมือนเปิด เปลี่ยนแค่ไอคอน */

/* Pie menu (กดคีย์ลัดค้าง): ตัวเลือกกระจายเป็นวงรอบเมาส์ */
#pie { position: fixed; z-index: 60; width: 0; height: 0; pointer-events: none; }
#pie .pie-c { position: absolute; left: -16px; top: -16px; width: 32px; height: 32px; border-radius: 99px; border: 2px solid color-mix(in srgb, var(--ink) 25%, transparent); background: color-mix(in srgb, var(--panel) 70%, transparent); opacity: 0; transform: scale(.6); transition: opacity .14s, transform .24s cubic-bezier(.34,1.45,.64,1); }
#pie .pie-c::after { content: ''; position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-radius: 99px; background: var(--ink); opacity: 0; transform: var(--a, rotate(0rad)) translateX(13px); transition: opacity .15s, transform .12s ease-out; }
#pie .pie-c.aim::after { opacity: 1; }
#pie .pie-c.snap::after { transition: none; }
#pie.open .pie-c { opacity: 1; transform: scale(1); }
.pie-i { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; transform: translate(-50%, -23px) translate(calc(var(--x) * .25), calc(var(--y) * .25)) scale(.5); opacity: 0; will-change: transform, opacity;
  transition: transform .3s cubic-bezier(.34,1.45,.64,1) var(--d), opacity .16s ease-out var(--d); }
#pie.open .pie-i { opacity: 1; transform: translate(-50%, -23px) translate(var(--x), var(--y)) scale(1); }
.pie-i b { width: 46px; height: 46px; border-radius: 99px; display: grid; place-items: center; background: var(--panel); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--sh); transition: background .12s, color .12s, transform .12s; }
.pie-i b svg { width: 20px; height: 20px; }
.pie-i .pie-dot { width: 22px; height: 22px; border-radius: 99px; display: block; }
.pie-i span { padding: 2px 7px; border-radius: 6px; background: var(--panel); color: var(--ink2); font-size: 11px; font-weight: 600; white-space: nowrap; box-shadow: var(--sh); }
.pie-i.cur b { border: 2px solid var(--ink); }
.pie-i.on b { background: var(--ink); color: var(--onink); transform: scale(1.1); }
.pie-i.on span { background: var(--ink); color: var(--onink); }

/* ปุ่มในการ์ดแก้ไข: บอกคีย์ลัด (R หมุน, Del ลบ) ชิดขวากลางปุ่ม */
.acts .btn { position: relative; }
.acts .btn .hk { bottom: 50%; transform: translateY(50%); right: 6px; }
