/* kit/css/lab-shell.css — โครงหน้าห้องปฏิบัติการเสมือนจริง (Virtual Bench) ตาม DESIGN §5
   ใช้คู่กับ tokens.css, base.css, components.css (ต้องโหลดก่อนไฟล์นี้) */

.k-bench {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  max-width: 100%;
  background: var(--c-bg);
}

.k-bench__header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 20;
  min-width: 0;
}
.k-bench__title { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); flex: 1 1 auto; min-width: 0; row-gap: 2px; }
.k-bench__title h1 { font-size: var(--fs-lg); font-weight: 800; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.k-bench__title-badges { display: flex; align-items: center; gap: var(--sp-2); flex: none; }

.k-bench--embed .k-bench__header { display: none; }

.k-bench__body { flex: 1 1 auto; padding: var(--sp-5); max-width: 1360px; margin: 0 auto; width: 100%; min-width: 0; box-sizing: border-box; }
.k-bench__section[hidden] { display: none; }

/* V5: เวที ~62% + สมุด/แท่นเครื่องมือ ~38% บนจอกว้าง (DESIGN §5) — ซ้อนกันบนจอแคบกว่า 1200px แทน 900px เดิม
   เพื่อให้เวทีอุปกรณ์มีที่ทางพอสำหรับความสูง ≥520px ที่ตั้งไว้ใน bench.js (createStage2D minHeight) */
.k-bench__apparatus-grid,
.k-bench__measure-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: start;
  min-width: 0;
}
.k-bench__apparatus-grid > *, .k-bench__measure-grid > * { min-width: 0; }
@media (max-width: 1200px) {
  .k-bench__apparatus-grid, .k-bench__measure-grid { grid-template-columns: 1fr; }
}

.k-bench__stage-wrap { position: relative; border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--sh-1); background: var(--stage-bg, #EAF2F6); }
.k-bench__stage { width: 100%; position: relative; }
.k-bench__stage canvas { display: block; width: 100%; }
/* แผงควบคุมอุปกรณ์ (V5): แต่ละการทดลองต่อ panel ของตัวเอง (DOM ธรรมดา) ไว้ใต้ canvas เสมอ (ดู bench.js) —
   จัดให้เป็นการ์ดอ่านง่ายทั่วไปโดยไม่ผูกกับชื่อคลาสเฉพาะของการทดลองใดการทดลองหนึ่ง (ยึดโครงสร้าง DOM แทน) */
.k-bench__stage > div:not(.k-stage-handle) {
  margin-top: var(--sp-4); padding: var(--sp-4); background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--r-lg);
  display: flex; flex-direction: column; gap: var(--sp-3);
}
.k-bench__stage > div:not(.k-stage-handle) .k-row { row-gap: var(--sp-2); align-items: center; }
.k-bench__stage > div:not(.k-stage-handle) .k-btn,
.k-bench__stage > div:not(.k-stage-handle) .k-chip { min-height: 44px; box-sizing: border-box; }

.k-bench__magnifier-btn {
  position: absolute;
  right: var(--sp-3);
  top: var(--sp-3);
  z-index: 5;
  font-size: 20px;
  width: 44px;
  height: 44px;
}
.k-bench__magnifier-btn[aria-pressed="true"] { background: var(--c-primary); color: var(--c-on-primary); }
.k-bench__magnifier-lens {
  position: absolute;
  z-index: 6;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 4px solid var(--c-surface);
  box-shadow: var(--sh-3);
  pointer-events: none;
  box-sizing: border-box;
  background: #fff;
}

.k-bench__rack {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--sp-4);
  margin-top: var(--sp-4);
  padding: var(--sp-4);
  background: var(--c-surface-2);
  border-radius: var(--r-lg);
  border: 1px solid var(--c-border);
}
/* V5: แท่นเครื่องมือเป็น "การ์ดที่อ่านได้จริง" — แต่ละชิ้นมีพื้นผิว เงา ขอบ ของตัวเอง ไม่ใช่ลอยอยู่บนพื้นเทาเฉย ๆ
   ให้ความกว้างขั้นต่ำมากพอที่จะเห็นสเกลไม้บรรทัด/เวอร์เนียร์ได้จริง (ปุ่ม "ขยายดู" ช่วยอ่านละเอียดอีกที) */
.k-instrument-slot {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  min-width: 0; padding: var(--sp-3); background: var(--c-surface);
}
.k-instrument-slot__label { font-size: var(--fs-sm); color: var(--c-ink); font-weight: 700; text-align: center; }
.k-instrument-slot__zoom { align-self: stretch; justify-content: center; }

.k-instrument { display: flex; flex-direction: column; align-items: center; max-width: 100%; }
.k-instr-svg { width: 100%; max-width: 260px; height: auto; display: block; }
/* LAB3D-KIT review: the transparent protractor has dark printed graduations;
   retain a light backing in the tray and on its zoomed copy. */
.k-instr-protractor { background: #f2f7f8; border-radius: 4px; }
.k-instrument__graph { width: 100%; margin-top: var(--sp-2); }

/* "ขยายดู" (V5): หน้าต่างตรวจอ่านเครื่องมือขนาดใหญ่ */
.k-instrument-zoom { width: min(640px, 92vw); max-height: 85vh; overflow: auto; padding: var(--sp-5); border-radius: var(--r-lg); border: 1px solid var(--c-border); }
.k-instrument-zoom__body {
  display: flex; justify-content: center; align-items: center; padding: var(--sp-5) var(--sp-4);
  background: var(--c-surface-2); border-radius: var(--r-md); min-height: 220px; overflow: auto;
}
.k-instrument-zoom__body input, .k-instrument-zoom__body button { pointer-events: none; }

.k-bench__notebook { background: var(--c-surface); border-radius: var(--r-lg); padding: var(--sp-4); border: 1px solid var(--c-border); width: 100%; box-sizing: border-box; }
.k-notebook { overflow-x: auto; width: 100%; }
/* บั๊กเดิม: .k-table (components.css) ตั้ง width:100% ไว้สำหรับตารางทั่วไปที่มีไม่กี่คอลัมน์ — สมุดบันทึก
   จริงมีคอลัมน์เยอะ (ตั้งค่า/วัดหลายครั้ง/คำนวณ/ผู้บันทึก) ถ้าบังคับ 100% จะถูกบีบจนตัวเลขในช่อง
   input มองไม่เห็นเลย (ไม่เหมือนเซลล์ข้อความล้วนที่ยังล้นออกมาให้เห็นได้) ทั้งที่ .k-notebook เผื่อ
   overflow-x:auto ไว้ให้แล้วแต่ไม่เคยได้ใช้เพราะตารางไม่เคยกว้างเกิน 100% ของตัวเอง — ให้ตารางกว้างเท่า
   เนื้อหาจริงแทน (ไม่ต่ำกว่า 100%) เพื่อให้เลื่อนแนวนอนทำงานและอ่านตัวเลขในช่องกรอกได้ */
/* คำใบ้เลื่อนตาราง: ซ่อนไว้ แสดงเมื่อตารางยังเลื่อนไปทางขวาได้ (edgeFade ตั้ง data-scroll-r="1" ที่ .k-table-scroll) */
.k-notebook__scroll-hint { display: none; margin-top: 6px; font-size: var(--fs-sm); color: var(--c-ink-2); text-align: left; white-space: normal; overflow-wrap: anywhere; }
.k-table-scroll[data-scroll-r="1"] + .k-notebook__scroll-hint { display: block; }
.k-notebook .k-table { width: auto; min-width: 100%; border-collapse: separate; border-spacing: 0; }
.k-notebook .k-table input.k-input { min-width: 6.2em; box-sizing: border-box; } /* K1 (E18a ข้อ 4): กว้างพอสำหรับ 5 เลขนัยสำคัญ เช่น 157.32 */
.k-notebook .k-table input.k-input[type="text"] { min-width: 7em; }
.k-cell--outlier { background: var(--c-warn-soft) !important; outline: 2px solid var(--c-warn); }

/* ---- หัวตาราง 2 บรรทัด (V5): บรรทัดบน "สัญลักษณ์ (หน่วย)" ตัวหนา บรรทัดล่างชื่อไทยสั้นสีรอง
   คำอธิบายเต็มอยู่ใน title (tooltip) เท่านั้น — กันหัวตารางพับแนวตั้งยาวเป็นกองแบบที่เจอใน pendulum-g จริง */
.k-notebook__th, .k-notebook__th-idx { min-width: 96px; max-width: 220px; vertical-align: bottom; padding: 6px 8px !important; box-sizing: border-box; }
.k-notebook__th-idx { min-width: 34px; max-width: 34px; text-align: center; }
.k-notebook__th-main {
  display: flex; align-items: center; justify-content: center; gap: 3px;
  font-weight: 700; font-size: var(--fs-sm); color: var(--c-ink); line-height: 1.2;
  white-space: normal; word-break: keep-all;
}
.k-notebook__th-main sub, .k-notebook__th-main sup { font-size: 0.72em; }
.k-notebook__unit { font-weight: 600; color: var(--c-ink-2); }
.k-notebook__th-sub {
  font-size: 10.5px; font-weight: 400; color: var(--c-ink-3); line-height: 1.25; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  max-height: 2.6em; word-break: break-word;
}
.k-notebook__th-icon { display: inline-flex; color: var(--c-primary); flex: none; }
.k-notebook__th-icon svg { width: 12px; height: 12px; display: block; }
.k-notebook__th--group { text-align: center; }
.k-notebook__th-sub2 { font-size: var(--fs-xs); font-weight: 600; color: var(--c-ink-2); min-width: 64px; padding: 4px 6px !important; text-align: center; }
.k-notebook__th-sub2--mean { color: var(--c-primary-ink); background: var(--c-primary-soft); }
th.k-cell--derived, td.k-cell--derived { background: var(--c-primary-soft); }
th.k-cell--derived .k-notebook__th-main { color: var(--c-primary-ink); }
td.k-cell--derived { font-weight: 600; color: var(--c-primary-ink); }

/* แถวสลับสี + ช่องกรอกสูง 44px ตัวเลข tabular (V5 — อ่านตารางยาวได้ง่ายขึ้น ไม่ใช่แถบขาวเรียบต่อกันยาว) */
.k-notebook__table tbody tr:nth-child(even) td:not(.k-cell--derived) { background: var(--c-surface-2); }
.k-notebook__table tbody tr:nth-child(even) td.k-cell--derived { background: color-mix(in srgb, var(--c-primary-soft) 80%, var(--c-surface-2)); }
.k-notebook .k-table input.k-input { height: 44px; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.k-notebook .k-table td { padding: 4px 6px; }
.k-notebook .k-table td .k-chip { white-space: nowrap; }

/* หัว และคอลัมน์ # ติดหนึบ (sticky) ตาม DESIGN/CONTRACTS §7.4 */
.k-notebook__table thead th {
  position: sticky; top: 0; z-index: 3; background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border-strong);
}
.k-notebook__table thead tr:first-child th { top: 0; }
/* K1: เฉพาะหัวตาราง 2 แถว (แถวที่สองติดใต้แถวแรก) — หัวแถวเดียวต้องไม่ถูกดันลงทับแถวข้อมูลแถวที่ 1 (E01b/E15b/E16a/E17a/E20a/E23a)
   ความสูงแถวแรกวัดจริงจาก JS (--nb-row1-h) ถ้ายังไม่วัดได้ใช้ 46px */
.k-notebook__table thead tr:last-child:not(:first-child) th { top: var(--nb-row1-h, 46px); }
.k-notebook__table th:first-child, .k-notebook__table td:first-child {
  position: sticky; left: 0; z-index: 2; background: var(--c-surface);
  box-shadow: 1px 0 0 var(--c-border) inset;
}
.k-notebook__table thead th:first-child { z-index: 4; background: var(--c-surface-2); }
.k-notebook__table tbody tr:nth-child(even) td:first-child { background: var(--c-surface-2); }

.k-bench__graph-full { width: 100%; }

/* ---- กระดาษกราฟเสมือนจริง (V5): "โต๊ะ" พื้นกลาง > แผ่นกระดาษ (เงา+ขอบมน) ตาม DESIGN §8 ---- */
.k-graph-paper {
  width: 100%; box-sizing: border-box; padding: var(--sp-5);
  background: linear-gradient(180deg, var(--c-surface-3), var(--c-surface-2));
  border-radius: var(--r-lg); border: 1px solid var(--c-border);
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); position: relative;
}
.k-graph-paper__sheet {
  width: 100%; max-width: 900px; position: relative; border-radius: 3px; overflow: hidden;
  background: #FFFDF6; box-shadow: 0 10px 28px rgba(20, 30, 40, .22), 0 1px 3px rgba(20, 30, 40, .18);
}
.k-graph-paper__canvas { width: 100%; display: block; cursor: crosshair; touch-action: none; }
.k-graph-paper__title-box {
  position: absolute; top: 8px; right: 8px; z-index: 2; pointer-events: none; text-align: right;
  background: rgba(255, 253, 246, .88); border: 1px solid rgba(41, 66, 87, .25); border-radius: 6px;
  padding: 4px 9px; max-width: 62%;
}
.k-graph-paper__title-text { font: 700 11px 'Sarabun', sans-serif; color: #173147; line-height: 1.3; }
.k-graph-paper__title-author { font: 400 10px 'Sarabun', sans-serif; color: #57616f; line-height: 1.3; }
.k-graph-paper__reset-view {
  position: absolute; top: calc(var(--sp-5) + 8px); left: calc(var(--sp-5) + 8px); z-index: 3;
  display: flex; align-items: center; gap: 5px; font: 600 12px var(--font-sans); color: var(--c-ink);
  background: var(--c-surface); border: 1px solid var(--c-border-strong); border-radius: var(--r-pill);
  padding: 5px 12px 5px 8px; box-shadow: var(--sh-1); cursor: pointer;
}
.k-graph-paper__reset-view svg { width: 14px; height: 14px; }
.k-graph-paper__reset-view:hover { background: var(--c-surface-2); }
.k-graph-paper__legend {
  display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); justify-content: center; width: 100%;
  font-size: 11px; color: var(--c-ink-2);
}
.k-graph-paper__legend-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.k-graph-paper__swatch { width: 11px; height: 11px; border-radius: 2px; display: inline-block; flex: none; }
.k-graph-paper__swatch--line { width: 16px; height: 0; border-top: 2px dashed; background: none; border-radius: 0; }
.k-graph-paper__swatch--bar { width: 3px; height: 12px; border-radius: 0; }
@media (max-width: 640px) {
  .k-graph-paper { padding: var(--sp-3); }
  .k-graph-paper__reset-view { top: calc(var(--sp-3) + 6px); left: calc(var(--sp-3) + 6px); font-size: 11px; padding: 4px 10px 4px 6px; }
  .k-graph-paper__title-box { max-width: 72%; }
}

.k-group-panel { padding: var(--sp-3) 0; }

/* ขั้นวิเคราะห์ (V5): สูตร → แทนค่า → ผล ± u → % error เป็นการ์ดลำดับขั้น (DESIGN/CONTRACTS §7.1) */
.k-analysis-step { display: flex; gap: var(--sp-3); padding: var(--sp-4); align-items: flex-start; }
.k-analysis-step__num {
  flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--topic-soft, var(--c-primary-soft));
  color: var(--topic-ink, var(--c-primary-ink)); font-weight: 800; display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm);
}
.k-analysis-step__body { flex: 1 1 auto; min-width: 0; }
.k-analysis-step__title { font-weight: 700; font-size: var(--fs-sm); color: var(--c-ink-2); margin-bottom: 4px; }
.k-analysis-step__text { margin: 0; font-size: var(--fs-md); }
.k-analysis-step__text sub, .k-analysis-step__text sup { font-size: 0.75em; }
.k-analysis-step__text--placeholder { color: var(--c-ink-3); }
.k-analysis-step--muted { border-style: dashed; background: var(--c-surface-2); } /* G7: เดิม opacity .55 ทำให้ตัวอักษรต่ำกว่า 4.5:1 ทั้งสองธีม */
.k-analysis-step--muted .k-analysis-step__text { font-style: italic; }

/* ขั้นสรุป/ส่ง (V5): ตัวอย่างหน้ารายงาน A4 ย่อ อยู่บนพื้น "โต๊ะ" เหมือนกระดาษกราฟ ให้รู้สึกเหมือนกระดาษจริง */
.k-report-a4 {
  background: linear-gradient(180deg, var(--c-surface-3), var(--c-surface-2));
  border-radius: var(--r-md); padding: var(--sp-4); display: flex; justify-content: center;
}
.k-report-a4 iframe { max-width: 400px; box-shadow: 0 10px 24px rgba(20, 30, 40, .18); }
@media (min-width: 640px) { .k-report-a4 iframe { max-width: 480px; } }

@media (max-width: 640px) {
  .k-bench__body { padding: var(--sp-3); }
  /* F3b-08: ชื่อการทดลอง ('ลูกตุ้มอย่างง่ายหาค่า g') เคยถูกตัดเหลือ 'ลูก…' เพราะต้องแบ่งพื้นที่บรรทัด
     เดียวกับป้ายชั้น/บท — บนมือถือให้ชื่อเรื่องขึ้นบรรทัดของตัวเอง (ไม่ตัดคำ) แล้วป้ายลงบรรทัดถัดไป */
  .k-bench__title h1 { font-size: var(--fs-md); flex-basis: 100%; white-space: normal; overflow: visible; text-overflow: clip; }
  .k-bench__title-badges { flex-basis: 100%; flex-wrap: wrap; row-gap: 4px; }
  /* G2: บั๊กที่พบจากภาพหน้าจอมือถือจริงของ pendulum-g — เดิมป้ายชั้น/บทกว้างรวมกันไม่เกินจอเพราะชื่อบทสั้น
     แต่เมื่อแก้ชื่อบทให้ถูกหลักสูตร (เช่น "บทที่ 7 การเคลื่อนที่แนวโค้ง (การเคลื่อนที่แบบฮาร์มอนิกอย่างง่าย)")
     ป้ายยาวขึ้นมากจนล้นออกนอกจอที่ 390px ทั้งที่ห่อ (.k-bench__title-badges) ตั้ง flex-basis:100% ไว้แล้ว —
     สาเหตุจริงคือ `.k-badge` ทั่วทั้ง kit (components.css) ตั้ง `white-space: nowrap` ตายตัว (ใช้ได้ดีกับ
     ป้ายสั้นอย่าง "ม.5" แต่พังกับป้ายบทยาว) แก้เฉพาะป้ายบท (`.k-badge--topic`) ในบริบทนี้ให้ขึ้นได้หลาย
     บรรทัดแทน — ไม่แตะ `.k-badge`/`.k-badge--topic` ทั่วไปนอก header การทดลอง (การ์ดคลังซิม ฯลฯ ยังเป็น
     ป้ายบรรทัดเดียวเหมือนเดิมทุกที่) */
  .k-bench__title-badges .k-badge--topic {
    white-space: normal; height: auto; min-height: 22px; padding-block: 3px; line-height: 1.25; text-align: center;
  }
}

/* K1 (E10 ข้อ 3): เครื่องชั่ง/เครื่องมือ SVG สีอ่อนบนแท่นธีมมืด — ลดความสว่างให้กลมกลืน (ตัวเลขจอ LCD ยังอ่านชัด) */
:root[data-theme="dark"] .k-instr-digital-balance { filter: brightness(.82) contrast(1.06); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .k-instr-digital-balance { filter: brightness(.82) contrast(1.06); }
}

/* K1: แถบสลับโหมดของ bench (config.modeSwitcher) */
.k-bench__modes { display: flex; flex-wrap: wrap; gap: var(--sp-2); padding: var(--sp-2) var(--sp-5) 0; max-width: 1360px; margin: 0 auto; width: 100%; box-sizing: border-box; }
.k-bench__modes .k-chip { text-decoration: none; min-height: 36px; }
@media (max-width: 720px) { .k-bench__modes { padding-inline: var(--sp-3); } .k-bench__modes .k-chip { min-height: 44px; } }
/* ชิป/ปุ่มที่หน้าตั้งสถานะด้วยคลาส is-active (บางหน้าไม่ได้ตั้ง aria-pressed/aria-checked) ต้องเห็นว่าเลือกอยู่ */
.k-chip.is-active { background: var(--c-primary-soft); color: var(--c-primary-ink); border-color: var(--c-primary); }
.k-seg__opt.is-active { background: var(--c-surface); color: var(--c-primary-ink); box-shadow: var(--sh-1); }
/* ช่องสมุดที่ค่าอยู่นอกช่วง min/max ของคอลัมน์ (notebook.js — K1) */
.k-notebook input[aria-invalid="true"] { border-color: var(--c-danger); background: var(--c-danger-soft); }

/* LAB3D-KIT: preserve the 2D canvas and its dimensions underneath the room. */
.k-bench__stage { position: relative; }
.k-bench__stage > .k-bench__lab3d { position: absolute; top: 0; left: 0; right: 0; margin: 0; padding: 0; border: 0; border-radius: 0; overflow: hidden; }
.k-bench__lab3d[hidden] { display: none; }
.k-bench__view-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }

/* โฉมพรีเมียม (2026-11-19): ตรา φ ของ Physic Lab หน้าปุ่มกลับ — แบรนด์เดียวกับหน้าทางเข้า (CSS ล้วน ไม่เปลี่ยนข้อความของปุ่ม) */
.k-sim-header__back::before, .k-bench__header > a.k-btn:first-child::before {
  content: "φ"; display: inline-grid; place-items: center; flex: none;
  width: 26px; height: 26px; margin-right: 6px; border-radius: 8px;
  background: var(--c-primary-ink); color: var(--c-on-strong); /* G7: โทเคนคู่ที่ตัดกันพอทั้งธีมสว่าง/มืด */
  font-weight: 800; font-size: 15px; line-height: 1;
}
/* จอ ≤ 900 px หัวหน้าแน่น (ป้ายปุ่มกลับก็ซ่อนแล้ว) — ไม่แสดงตรา φ เพื่อไม่ให้หัวหน้าล้นขวา */
@media (max-width: 900px) { .k-sim-header__back::before, .k-bench__header > a.k-btn:first-child::before { content: none; } }
