
/* ===========================================
   THEME: "Taxonomy Grid" ชุดเดียวกับสไลด์ Bloom's Taxonomy
   =========================================== */
:root {
    --paper: #f6f4ec;
    --ink: #14203c;
    --cobalt: #1F49C7;
    --red: #E8555A;
    --green: #1E9E6A;
    --amber: #C8811F;
    --muted: #5a6377;
    --card: #ffffff;
    --grid-line: rgba(31, 73, 199, 0.07);
    --grid-line-major: rgba(31, 73, 199, 0.16);

    --font-display: 'Bai Jamjuree', sans-serif;
    --font-body: 'IBM Plex Sans Thai', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);

    /* ── โทเคนสำหรับสเปกกลางของคลังสไลด์ (DESIGN.md ส่วนที่ 8.6 และ 12) ──
       บล็อกผู้ช่วยถามตอบและหน้าต่างตั้งค่าถูกยกมาทั้งก้อนโดยไม่แก้แม้แต่ตัวเดียว
       จึงต้องมีโทเคนครบตามที่บล็อกนั้นเรียกใช้ ค่าที่ใส่ตรงกับเด็คอื่นในคลัง
       ผังนี้ไม่มีโหมดชุดควบคุมสองแบบ จึงตรึง --gutter-x ไว้ที่ 0 */
    --cobalt-deep: #17389a;
    --red-deep: #b0272e;
    --green-deep: #146f4b;
    --amber-deep: #8f5a00;
    --danger: #b0272e;
    --stone: var(--paper);
    --stone-deep: #ece8d9;
    --stone-card: #fbfaf4;
    --stone-line: rgba(20, 32, 60, 0.22);
    --ink-soft: var(--muted);
    --ink-faint: #7a8296;
    --bronze: var(--cobalt);
    --bronze-deep: var(--cobalt-deep);
    --bronze-soft: rgba(31, 73, 199, 0.10);
    --bronze-line: rgba(31, 73, 199, 0.38);
    --patina: var(--green);
    --patina-soft: rgba(30, 158, 106, 0.12);
    --act-deep: var(--cobalt-deep);
    --act-soft: rgba(31, 73, 199, 0.10);
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --gutter-x: 0px;
    --fab-size: 52px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { background: #d9d5c9; }
body {
    font-family: var(--font-body);
    color: var(--ink);
    background: #d9d5c9;
    padding: 34px 20px 90px;
    display: flex;
    justify-content: center;
    -webkit-font-smoothing: antialiased;
}

/* กระดาษกราฟ */
.sheet {
    width: 1720px;
    background: var(--paper);
    border: 3px solid var(--ink);
    box-shadow: 16px 16px 0 rgba(20, 32, 60, 0.28);
    position: relative;
    overflow: hidden;
}
.sheet::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
        linear-gradient(var(--grid-line-major) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line-major) 1px, transparent 1px);
    background-size: 32px 32px, 32px 32px, 160px 160px, 160px 160px;
    z-index: 0;
}
.sheet > * { position: relative; z-index: 1; }

/* ===== แถบหัวและท้าย ===== */
.bar-top, .bar-bot {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 40px;
    font-family: var(--font-mono);
    font-size: 15px; font-weight: 700; letter-spacing: 0.08em;
    color: var(--ink);
}
.bar-top { border-bottom: 3px solid var(--ink); background: rgba(255,255,255,0.5); }
.bar-bot { border-top: 3px solid var(--ink); background: rgba(255,255,255,0.5); }

/* ปุ่มกลับหน้า Hub ผังนี้เป็นหน้าเลื่อนอ่าน ไม่มีชุดควบคุมแบบเด็คสไลด์
   จึงวางไว้ที่แถบบนแทน และเขียนเส้นทางเต็มถึง index.html ตาม DESIGN.md ส่วนที่ 16.3 */
.bar-top .hub-link {
    font-family: var(--font-mono); font-size: 12.5px; font-weight: 700;
    letter-spacing: 0.05em; color: var(--cobalt); text-decoration: none;
    border: 2px solid var(--cobalt); padding: 4px 11px; margin-right: 16px;
    transition: background 0.16s var(--ease-out-expo), color 0.16s var(--ease-out-expo);
}
.bar-top .hub-link:hover, .bar-top .hub-link:focus-visible {
    background: var(--cobalt); color: var(--paper); outline: none;
}
.bar-top .dot {
    display: inline-block; width: 11px; height: 11px; border-radius: 50%;
    background: var(--cobalt); margin-right: 10px; vertical-align: middle;
}

.pad { padding: 40px 48px 46px; }

/* ===== หัวเรื่อง ===== */
.kicker {
    display: inline-block;
    font-family: var(--font-mono); font-size: 15px; font-weight: 700;
    letter-spacing: 0.18em; color: var(--cobalt);
    border: 2.5px solid var(--cobalt); padding: 7px 16px;
    box-shadow: 5px 5px 0 rgba(31,73,199,0.22);
    margin-bottom: 20px;
}
h1 {
    font-family: var(--font-display); font-weight: 700;
    font-size: 50px; line-height: 1.16; letter-spacing: -0.01em;
    margin-bottom: 14px;
}
h1 .accent { color: var(--cobalt); }
.lede { font-size: 22px; line-height: 1.62; color: var(--muted); max-width: 1340px; }
.lede strong { color: var(--ink); font-weight: 600; }

/* ===== ป้ายชั้น ===== */
.layer-label {
    display: flex; align-items: center; gap: 14px;
    margin-bottom: 16px;
}
.layer-label .tag {
    font-family: var(--font-mono); font-size: 14px; font-weight: 700;
    letter-spacing: 0.14em; padding: 6px 14px;
    border: 2.5px solid var(--ink); background: var(--ink); color: var(--paper);
}
.layer-label .tag.tool { background: var(--amber); border-color: var(--amber); }
.layer-label .tag.amb  { background: var(--muted); border-color: var(--muted); }
.layer-label .say { font-size: 19px; color: var(--muted); line-height: 1.5; }
.layer-label .say b { color: var(--ink); font-weight: 600; }

.block { margin-top: 40px; }

/* ===== การ์ดพื้นฐาน ===== */
.node {
    background: var(--card);
    border: 2.5px solid var(--ink);
    box-shadow: 6px 6px 0 rgba(20,32,60,0.20);
    padding: 14px 16px;
    cursor: pointer;
    text-align: left;
    font-family: var(--font-body);
    width: 100%;
    display: block;
    transition: transform 0.18s var(--ease-out-expo), box-shadow 0.18s var(--ease-out-expo);
}
.node:hover, .node:focus-visible {
    transform: translate(-2px, -2px);
    box-shadow: 9px 9px 0 rgba(20,32,60,0.28);
    outline: none;
}
.node .num {
    font-family: var(--font-mono); font-size: 13px; font-weight: 700;
    color: var(--cobalt); letter-spacing: 0.06em;
}
.node .en {
    font-family: var(--font-display); font-weight: 600;
    font-size: 18px; line-height: 1.25; margin: 3px 0 4px; color: var(--ink);
}
.node .th { font-size: 16px; line-height: 1.4; color: var(--muted); }

/* ===== ชั้นเครื่องมือ ===== */
/* สามการ์ด คือ Bloom หนึ่งใบ และ Backward อีกสองใบที่เป็นคู่แฝด
   สัดส่วน 1.15 ต่อ 1 ต่อ 1 เพราะการ์ด Bloom มีชิปสามใบ จึงต้องการความกว้างมากกว่า */
.tool-grid { display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 22px; }
.node.tool {
    border-color: var(--amber);
    box-shadow: 7px 7px 0 rgba(200,129,31,0.30);
    padding: 18px 22px;
}

/* คู่แฝด Backward ใช้สีเขียวทั้งคู่ เพื่อให้เห็นว่าเป็นตระกูลเดียวกัน
   แยกจากกันด้วยป้ายหน่วยการออกแบบที่หัวการ์ด ไม่ได้แยกด้วยสี */
.node.tool.bwd {
    border-color: var(--green);
    box-shadow: 7px 7px 0 rgba(30,158,106,0.30);
}
.node.tool.bwd .num, .node.tool.bwd .en { color: var(--green); }
.node.tool.bwd .chip {
    border-color: var(--green); color: var(--green); background: rgba(30,158,106,0.08);
}
.node.tool .scale-tag {
    display: inline-block;
    font-family: var(--font-mono); font-size: 11.5px; font-weight: 700;
    letter-spacing: 0.05em; padding: 3px 9px; margin-bottom: 8px;
    background: var(--green); color: var(--paper);
}

/* แถบคาดใต้การ์ดคู่แฝด บอกว่าสองใบนี้ใช้ตรรกะเดียวกัน คร่อมคอลัมน์ที่ 2 กับ 3 */
.bwd-brace {
    grid-column: 2 / span 2;
    border: 2px dashed var(--green); border-top: none;
    padding: 11px 16px 0; text-align: center;
    font-size: 15.5px; line-height: 1.5; color: var(--ink);
}
.bwd-brace b { color: var(--green); font-weight: 600; }
.node.tool .num, .node.tool .en { color: var(--amber); }
.node.tool .en { font-size: 21px; }
.node.tool .th { font-size: 17px; color: var(--ink); }
.node.tool .acts {
    margin-top: 10px; display: flex; flex-wrap: wrap; gap: 7px;
}
.node.tool .chip {
    font-family: var(--font-mono); font-size: 12px; font-weight: 700;
    letter-spacing: 0.04em; padding: 4px 9px;
    border: 2px solid var(--amber); color: var(--amber); background: rgba(200,129,31,0.08);
}

/* ===== แถวลูกศรจากเครื่องมือลงสายธาร ===== */
.arrow-row {
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 14px;
    margin: 14px 0 6px;
}
.arrow-down {
    grid-row: 1; justify-self: center;
    width: 0; height: 40px;
    border-left: 3px dashed var(--amber);
    position: relative;
}
.arrow-down::after {
    content: ''; position: absolute; left: -8px; bottom: -2px;
    border-left: 8px solid transparent; border-right: 8px solid transparent;
    border-top: 11px solid var(--amber);
}
.back-arrow {
    grid-row: 2; align-self: center; height: 0;
    border-top: 3px dashed var(--green);
    position: relative; margin: 12px 0 4px;
}
.back-arrow::after {
    content: ''; position: absolute; left: -2px; top: -8px;
    border-top: 8px solid transparent; border-bottom: 8px solid transparent;
    border-right: 11px solid var(--green);
}
.back-arrow .cap {
    position: absolute; right: 0; top: -30px;
    font-family: var(--font-mono); font-size: 12.5px; font-weight: 700;
    color: var(--green); letter-spacing: 0.05em; white-space: nowrap;
}
/* ลูกศรย้อนของคำที่ 14 ยาวคลุมทั้งเจ็ดขั้น เพราะออกแบบทั้งสายธารใหม่
   วางไว้แถวล่างสุด และเว้นระยะบนให้ป้ายกำกับของตัวเองไม่ชนลูกศรของคำที่ 15 */
.back-arrow.macro {
    grid-row: 3; border-top-width: 4px; margin: 40px 0 6px;
}
.back-arrow.macro::after { border-right-color: var(--green); }

/* ===== สายธาร 7 ขั้น ===== */
.spine { display: grid; grid-template-columns: repeat(7, 1fr); gap: 14px; }
.stage { display: flex; flex-direction: column; gap: 10px; }
.stage-head {
    border: 2.5px solid var(--cobalt);
    background: var(--cobalt);
    color: #fff;
    padding: 11px 12px;
    position: relative;
}
.stage-head .no {
    font-family: var(--font-mono); font-size: 13px; font-weight: 700;
    color: rgba(255,255,255,0.82); letter-spacing: 0.08em;
}
.stage-head .nm {
    font-family: var(--font-display); font-weight: 600; font-size: 16.5px;
    line-height: 1.24; margin-top: 2px;
}
.stage-head .th {
    font-size: 14.5px; line-height: 1.35; color: rgba(255,255,255,0.9); margin-top: 3px;
}
/* หัวลูกศรเชื่อมระหว่างขั้น */
.stage-head::after {
    content: ''; position: absolute; right: -12px; top: 50%;
    transform: translateY(-50%);
    border-top: 9px solid transparent; border-bottom: 9px solid transparent;
    border-left: 10px solid var(--cobalt);
    z-index: 3;
}
.stage:last-child .stage-head::after { display: none; }

.stage .slot-note {
    font-family: var(--font-mono); font-size: 11.5px; font-weight: 700;
    letter-spacing: 0.06em; color: var(--muted); text-align: center;
    padding-top: 2px;
}

/* การ์ด null = คัดออก */
.node.excluded {
    border-style: dashed; border-color: var(--red);
    box-shadow: 6px 6px 0 rgba(232,85,90,0.22);
    background: rgba(232,85,90,0.05);
}
.node.excluded .num, .node.excluded .en { color: var(--red); }
.node.excluded .drop {
    margin-top: 8px;
    font-family: var(--font-mono); font-size: 11.5px; font-weight: 700;
    color: var(--red); letter-spacing: 0.04em; line-height: 1.4;
}
/* การ์ดที่ไม่ผ่านเอกสาร */
.node.unwritten { border-color: var(--red); box-shadow: 6px 6px 0 rgba(232,85,90,0.22); }
.node.unwritten .num, .node.unwritten .en { color: var(--red); }

/* ===== ลูกศรจากวงแวดล้อมขึ้นสายธาร ===== */
.up-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 14px; margin: 18px 0 10px; }
.arrow-up { justify-self: center; width: 0; height: 34px; border-left: 3px dashed var(--muted); position: relative; }
.arrow-up::after {
    content: ''; position: absolute; left: -8px; top: -2px;
    border-left: 8px solid transparent; border-right: 8px solid transparent;
    border-bottom: 11px solid var(--muted);
}

/* ===== วงแวดล้อมรอบนอก ===== */
.ambient-wrap {
    border: 3px dashed var(--muted);
    background: rgba(90,99,119,0.05);
    padding: 22px 24px;
}
.ambient-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.node.ambient { border-color: var(--muted); box-shadow: 6px 6px 0 rgba(90,99,119,0.22); }
.node.ambient .num { color: var(--muted); }

/* ===== ข้อสังเกต ===== */
.findings { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 12px; }
.finding {
    background: var(--card); border: 2.5px solid var(--ink);
    border-left: 11px solid var(--cobalt);
    box-shadow: 7px 7px 0 rgba(20,32,60,0.18);
    padding: 20px 24px;
}
.finding.b { border-left-color: var(--green); }
.finding h3 {
    font-family: var(--font-display); font-weight: 600; font-size: 21px;
    margin-bottom: 8px; line-height: 1.3;
}
.finding p { font-size: 17.5px; line-height: 1.6; color: var(--ink); }
.finding .src {
    margin-top: 9px; font-family: var(--font-mono); font-size: 12.5px;
    color: var(--muted); letter-spacing: 0.03em; line-height: 1.5;
}

/* ===== คำอธิบายสัญลักษณ์ ===== */
.legend { display: flex; flex-wrap: wrap; gap: 26px; align-items: center; margin-top: 30px; }
.legend .li { display: flex; align-items: center; gap: 9px; font-size: 16px; color: var(--ink); }
.legend .sw { width: 26px; height: 15px; border: 2.5px solid var(--ink); background: #fff; flex: none; }
.legend .sw.tool { border-color: var(--amber); background: rgba(200,129,31,0.14); }
.legend .sw.amb { border-color: var(--muted); background: rgba(90,99,119,0.14); }
.legend .sw.exc { border-color: var(--red); border-style: dashed; background: rgba(232,85,90,0.10); }
.legend .sw.stg { border-color: var(--cobalt); background: var(--cobalt); }
.legend .sw.bwd { border-color: var(--green); background: rgba(30,158,106,0.14); }

.refs {
    margin-top: 26px; padding: 20px 26px;
    background: rgba(255,255,255,0.7); border: 2.5px solid var(--ink);
}
.refs .rt {
    font-family: var(--font-mono); font-size: 13px; font-weight: 700;
    letter-spacing: 0.12em; color: var(--cobalt); margin-bottom: 10px;
}
.refs ul { font-size: 16px; line-height: 1.75; padding-left: 26px; color: var(--ink); }

/* ===== หน้าต่างรายละเอียด ===== */
.modal-back {
    position: fixed; inset: 0; background: rgba(20,32,60,0.55);
    display: none; align-items: center; justify-content: center;
    z-index: 2000; padding: 30px;
}
.modal-back.show { display: flex; }
.modal {
    background: var(--paper); border: 3px solid var(--ink);
    box-shadow: 14px 14px 0 rgba(20,32,60,0.4);
    max-width: 720px; width: 100%; max-height: 86vh; overflow-y: auto;
    padding: 32px 36px;
}
.modal .mnum {
    font-family: var(--font-mono); font-size: 14px; font-weight: 700;
    letter-spacing: 0.1em; color: var(--cobalt);
}
.modal h2 {
    font-family: var(--font-display); font-weight: 700; font-size: 32px;
    line-height: 1.22; margin: 6px 0 4px;
}
.modal .mth { font-size: 20px; color: var(--muted); margin-bottom: 18px; }
.modal .mdef { font-size: 19px; line-height: 1.68; margin-bottom: 16px; }
.modal .mrow {
    display: flex; gap: 12px; padding: 11px 0;
    border-top: 2px solid rgba(20,32,60,0.14); font-size: 16.5px; line-height: 1.55;
}
.modal .mrow .k {
    font-family: var(--font-mono); font-size: 12.5px; font-weight: 700;
    letter-spacing: 0.04em; color: var(--cobalt); flex: none; width: 156px;
    padding-top: 3px; line-height: 1.45; word-break: break-word;
}
.modal .mfoot {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 22px;
}
/* ปุ่มถาม AI ใช้สีเขียวชุดเดียวกับคู่แฝด Backward และมุมฉากตามภาษาออกแบบของคลัง */
.modal .ask-ai {
    display: inline-flex; align-items: center; gap: 8px;
    font-family: var(--font-body); font-size: 15.5px; font-weight: 600;
    padding: 10px 18px; cursor: pointer;
    background: var(--green); color: var(--paper);
    border: 2.5px solid var(--green); border-radius: 0;
    box-shadow: 4px 4px 0 rgba(30,158,106,0.30);
    transition: transform 0.16s var(--ease-out-expo), box-shadow 0.16s var(--ease-out-expo);
}
.modal .ask-ai:hover, .modal .ask-ai:focus-visible {
    transform: translate(-2px, -2px); box-shadow: 6px 6px 0 rgba(30,158,106,0.38); outline: none;
}
.modal .close {
    margin-top: 22px; font-family: var(--font-mono); font-size: 14px; font-weight: 700;
    letter-spacing: 0.08em; padding: 11px 22px; cursor: pointer;
    background: var(--ink); color: var(--paper); border: 2.5px solid var(--ink);
}
.modal .close:hover { background: var(--cobalt); border-color: var(--cobalt); }

/* ===== ปุ่มปรับขนาดตัวอักษร ===== */
.font-controls {
    /* ถอยจากขอบขวา 96px เพื่อหลบปุ่มลอยผู้ช่วยถามตอบ ซึ่งกว้าง 56px และห่างขอบ 24px
       ระยะล่างคงไว้ที่ 20px จึงอยู่ต่ำกว่าขอบล่างของหน้าต่างแชตที่ 88px เสมอ */
    position: fixed; right: 96px; bottom: 20px; z-index: 1500;
    display: flex; gap: 8px; align-items: center;
}
.font-controls button {
    background: var(--paper); border: 2.5px solid var(--ink);
    box-shadow: 4px 4px 0 rgba(20,32,60,0.3);
    padding: 10px 13px; cursor: pointer;
    font-family: var(--font-mono); font-size: 14px; font-weight: 700;
    color: var(--ink); letter-spacing: 0.03em; line-height: 1;
}
.font-controls button:hover { background: #fff; }
.font-controls .pct { min-width: 68px; }

@media print {
    body { background: #fff; padding: 0; }
    .font-controls, .modal-back { display: none !important; }
    .sheet { box-shadow: none; width: 100%; }
}

/* ===========================================
   ยกมาจากคลังสไลด์โดยไม่แก้ถ้อยความ
   หนึ่ง ปุ่มลอยตั้งค่า หน้าต่างตั้งค่า AI Model และกล่องเชิญตั้งค่า
   สอง สเปกกลางของผู้ช่วยถามตอบตาม DESIGN.md ส่วนที่ 12
   ทั้งสองบล็อกต้องอยู่ท้ายสุดของสไตล์ เพื่อเขียนทับกฎเดิมด้วยลำดับที่มาทีหลัง
   =========================================== */
    /* ===========================================
   AI SETTINGS FAB + MODAL + SETUP OVERLAY
   (edu-ai-slides-builder pattern, themed to Delphic palette)
   =========================================== */
    .fab-settings {
      position: fixed;
      bottom: 24px;
      left: 24px;
      z-index: 8000;
      width: 52px;
      height: 52px;
      border-radius: 50%;
      background: var(--ink);
      color: var(--stone);
      border: none;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
      transition: transform .2s, background .2s;
    }

    .fab-settings:hover {
      transform: scale(1.08);
      background: var(--bronze-deep);
    }

    .fab-settings svg {
      width: 24px;
      height: 24px;
    }

    /* ===========================================
   AI Q&A CHATBOT มุมล่างขวา
   (ถามเกี่ยวกับ Delphi Technique, ใช้ callLLM()/API key ร่วมกับ AI Demo)
   =========================================== */
    .fab-chat {
      position: fixed;
      bottom: 24px;
      right: 24px;
      z-index: 8000;
      width: 56px;
      height: 56px;
      border-radius: 50%;
      background: var(--bronze-deep);
      color: var(--stone);
      border: none;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
      transition: transform .2s, background .2s;
    }

    .fab-chat:hover {
      transform: scale(1.08);
      background: var(--patina);
    }

    .fab-chat svg {
      width: 26px;
      height: 26px;
    }

    .chat-panel {
      position: fixed;
      bottom: 92px;
      right: 24px;
      z-index: 7999;
      width: min(400px, calc(100vw - 32px));
      height: min(560px, calc(100vh - 140px));
      background: var(--stone-card);
      border: 1.5px solid var(--stone-line);
      border-radius: 18px;
      box-shadow: 0 25px 60px rgba(0, 0, 0, .35);
      display: flex;
      flex-direction: column;
      overflow: hidden;
      opacity: 0;
      transform: translateY(16px) scale(.97);
      pointer-events: none;
      transition: opacity .25s var(--ease), transform .25s var(--ease);
    }

    .chat-panel.show {
      opacity: 1;
      transform: translateY(0) scale(1);
      pointer-events: auto;
    }

    .chat-panel-header {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      padding: 18px 18px 14px;
      border-bottom: 1px solid var(--stone-line);
      background: var(--ink);
      color: var(--stone);
      flex-shrink: 0;
    }

    .chat-panel-title {
      font-family: var(--font-display);
      font-weight: 600;
      font-size: 17px;
    }

    .chat-panel-sub {
      font-family: var(--font-body);
      font-size: 12px;
      color: var(--stone-line);
      margin-top: 3px;
    }

    .chat-panel-close {
      background: none;
      border: none;
      color: var(--stone);
      font-size: 22px;
      cursor: pointer;
      line-height: 1;
      padding: 2px 6px;
    }

    .chat-messages {
      flex: 1;
      overflow-y: auto;
      padding: 16px 18px;
      display: flex;
      flex-direction: column;
      gap: 12px;
      font-family: var(--font-body);
      font-size: 14.5px;
      line-height: 1.55;
    }

    .chat-msg {
      max-width: 88%;
      padding: 10px 13px;
      border-radius: 12px;
      white-space: pre-wrap;
    }

    .chat-msg.bot {
      align-self: flex-start;
      background: var(--bronze-soft);
      color: var(--ink);
      border-bottom-left-radius: 3px;
    }

    .chat-msg.user {
      align-self: flex-end;
      background: var(--ink);
      color: var(--stone);
      border-bottom-right-radius: 3px;
    }

    .chat-msg.error {
      align-self: flex-start;
      background: rgba(163, 55, 47, .12);
      color: var(--danger);
      border-bottom-left-radius: 3px;
    }

    .chat-msg.loading {
      align-self: flex-start;
      background: var(--bronze-soft);
      color: var(--ink-faint);
      font-style: italic;
    }

    .chat-input-row {
      display: flex;
      gap: 8px;
      padding: 12px 14px;
      border-top: 1px solid var(--stone-line);
      background: var(--stone-card);
      flex-shrink: 0;
    }

    .chat-input {
      flex: 1;
      resize: none;
      max-height: 90px;
      padding: 10px 12px;
      border-radius: 10px;
      border: 1.5px solid var(--stone-line);
      font-family: var(--font-body);
      font-size: 14px;
      color: var(--ink);
      background: var(--stone);
      outline: none;
    }

    .chat-input:focus {
      border-color: var(--bronze);
    }

    .chat-input:disabled {
      opacity: .6;
      cursor: not-allowed;
    }

    .chat-send-btn {
      width: 42px;
      height: 42px;
      border-radius: 10px;
      border: none;
      background: var(--bronze-deep);
      color: var(--stone);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: background .2s;
    }

    .chat-send-btn:hover {
      background: var(--patina);
    }

    .chat-send-btn:disabled {
      opacity: .5;
      cursor: not-allowed;
    }

    .chat-send-btn svg {
      width: 18px;
      height: 18px;
    }

    /* ── header action buttons (ล้างการสนทนา ฯลฯ) ── */
    .chat-panel-actions {
      display: flex;
      gap: 4px;
      align-items: center;
      flex-shrink: 0;
    }

    .chat-header-btn {
      background: none;
      border: none;
      color: var(--stone-line);
      cursor: pointer;
      padding: 5px;
      border-radius: 7px;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: color .2s, background .2s;
    }

    .chat-header-btn:hover {
      color: var(--stone);
      background: rgba(255, 255, 255, .12);
    }

    .chat-header-btn svg {
      width: 17px;
      height: 17px;
    }

    /* ── Markdown ในบับเบิลบอท ── */
    .chat-msg.bot p {
      margin: 0 0 8px;
    }

    .chat-msg.bot p:last-child {
      margin-bottom: 0;
    }

    .chat-msg.bot ul,
    .chat-msg.bot ol {
      margin: 0 0 8px 20px;
    }

    .chat-msg.bot ul:last-child,
    .chat-msg.bot ol:last-child {
      margin-bottom: 0;
    }

    .chat-msg.bot li {
      margin-bottom: 4px;
    }

    .chat-msg.bot h4 {
      font-family: var(--font-display);
      font-size: 15px;
      font-weight: 600;
      margin: 2px 0 6px;
      color: var(--bronze-deep);
    }

    .chat-msg.bot blockquote {
      border-left: 3px solid var(--bronze-line);
      padding-left: 10px;
      color: var(--ink-soft);
      margin: 0 0 8px;
      font-style: italic;
    }

    .chat-msg.bot hr {
      border: none;
      border-top: 1px solid var(--stone-line);
      margin: 10px 0;
    }

    .chat-msg.bot a {
      color: var(--bronze-deep);
      text-decoration: underline;
      text-underline-offset: 2px;
    }

    .chat-msg.bot .chat-code-inline {
      background: rgba(43, 38, 32, .08);
      padding: 1px 5px;
      border-radius: 4px;
      font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
      font-size: 13px;
    }

    .chat-msg.bot .chat-code-block {
      background: var(--ink);
      color: var(--stone);
      padding: 10px 12px;
      border-radius: 8px;
      overflow-x: auto;
      font-size: 12.5px;
      margin: 0 0 8px;
    }

    .chat-msg.bot .chat-code-block code {
      font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
      white-space: pre;
    }

    /* ── streaming cursor + typing indicator ── */
    .stream-cursor {
      display: inline-block;
      width: 2px;
      height: 1em;
      background: var(--ink);
      margin-left: 2px;
      vertical-align: text-bottom;
      animation: chatBlink 1s step-start infinite;
    }

    @keyframes chatBlink {
      50% {
        opacity: 0;
      }
    }

    .typing-dots {
      display: inline-flex;
      gap: 4px;
      padding: 3px 2px;
    }

    .typing-dots span {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: var(--ink-faint);
      animation: chatTypingBounce 1.2s infinite ease-in-out;
    }

    .typing-dots span:nth-child(2) {
      animation-delay: .15s;
    }

    .typing-dots span:nth-child(3) {
      animation-delay: .3s;
    }

    @keyframes chatTypingBounce {

      0%,
      60%,
      100% {
        transform: translateY(0);
        opacity: .5;
      }

      30% {
        transform: translateY(-4px);
        opacity: 1;
      }
    }

    /* ── copy button + regenerate + stopped note ── */
    .chat-msg-actions {
      display: flex;
      gap: 6px;
      margin-top: 8px;
    }

    .chat-copy-btn {
      background: none;
      border: none;
      cursor: pointer;
      color: var(--ink-faint);
      font-size: 11px;
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 3px 6px;
      border-radius: 6px;
      transition: color .2s, background .2s;
    }

    .chat-copy-btn:hover {
      color: var(--bronze-deep);
      background: var(--bronze-soft);
    }

    .chat-copy-btn svg {
      width: 12px;
      height: 12px;
    }

    .chat-regenerate-row {
      display: flex;
      justify-content: flex-start;
      align-self: flex-start;
    }

    .chat-regenerate-btn {
      background: none;
      border: 1px solid var(--stone-line);
      color: var(--ink-soft);
      font-size: 12px;
      padding: 5px 12px;
      border-radius: 999px;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 5px;
      transition: border-color .2s, color .2s;
    }

    .chat-regenerate-btn:hover {
      border-color: var(--bronze-line);
      color: var(--bronze-deep);
    }

    .chat-regenerate-btn svg {
      width: 13px;
      height: 13px;
    }

    .chat-stopped-note {
      font-size: 11px;
      color: var(--ink-faint);
      margin-top: 6px;
      font-style: italic;
    }

    /* ── quick-start chips ── */
    .chat-chips {
      display: flex;
      flex-direction: column;
      gap: 6px;
      align-self: flex-start;
      max-width: 92%;
    }

    .chat-chip {
      text-align: left;
      background: var(--stone);
      border: 1px solid var(--stone-line);
      color: var(--ink);
      font-size: 13px;
      padding: 9px 13px;
      border-radius: 10px;
      cursor: pointer;
      transition: border-color .2s, background .2s;
      font-family: var(--font-body);
    }

    .chat-chip:hover {
      border-color: var(--bronze-line);
      background: var(--bronze-soft);
    }

    @media (max-width: 480px) {
      .chat-panel {
        right: 16px;
        bottom: 84px;
      }

      .fab-chat {
        right: 16px;
        bottom: 16px;
      }
    }

    .api-modal-overlay {
      display: none;
      position: fixed;
      z-index: 9000;
      inset: 0;
      background: rgba(23, 19, 16, .7);
      backdrop-filter: blur(4px);
      opacity: 0;
      transition: opacity .3s ease;
      align-items: center;
      justify-content: center;
    }

    .api-modal-overlay.show {
      display: flex;
      opacity: 1;
    }

    .api-modal-box {
      background: var(--stone-card);
      border-radius: 14px;
      padding: 34px;
      width: 90%;
      max-width: 520px;
      max-height: 88vh;
      overflow-y: auto;
      box-shadow: 0 25px 60px rgba(0, 0, 0, .4);
      transform: scale(.94);
      transition: transform .3s ease;
      font-family: var(--font-body);
      border: 1.5px solid var(--stone-line);
    }

    .api-modal-overlay.show .api-modal-box {
      transform: scale(1);
    }

    .api-modal-box h2 {
      font-family: var(--font-display);
      font-weight: 600;
      font-size: 26px;
      color: var(--ink);
    }

    .api-modal-close {
      background: none;
      border: none;
      font-size: 26px;
      cursor: pointer;
      color: var(--ink-faint);
      width: 36px;
      height: 36px;
    }

    .setup-overlay {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(23, 19, 16, .92);
      z-index: 9999;
      align-items: center;
      justify-content: center;
    }

    .setup-overlay.show {
      display: flex;
    }

    .setup-card {
      background: var(--stone-card);
      padding: 44px;
      border-radius: 16px;
      max-width: 420px;
      width: 90%;
      text-align: center;
      box-shadow: 0 25px 60px rgba(0, 0, 0, .4);
      font-family: var(--font-body);
    }

    .setup-card h2 {
      font-family: var(--font-display);
      font-weight: 600;
      font-size: 26px;
      color: var(--ink);
      margin-bottom: 12px;
    }

    .setup-card p {
      color: var(--ink-soft);
      font-size: 16px;
      margin-bottom: 22px;
      line-height: 1.6;
    }

    .setup-icon {
      width: 52px;
      height: 52px;
      margin: 0 auto 18px;
      color: var(--bronze);
    }

    .api-field {
      margin-bottom: 16px;
    }

    .api-field label {
      display: block;
      font-size: 14px;
      font-weight: 600;
      color: var(--ink-soft);
      margin-bottom: 6px;
    }

    .api-field input,
    .api-field select {
      width: 100%;
      border: 1.5px solid var(--stone-line);
      border-radius: 8px;
      padding: 10px 14px;
      font-size: 15px;
      outline: none;
      transition: border-color .2s;
      box-sizing: border-box;
      font-family: var(--font-body);
      background: #fff;
      color: var(--ink);
    }

    .api-field input:focus,
    .api-field select:focus {
      border-color: var(--bronze);
      box-shadow: 0 0 0 3px var(--bronze-soft);
    }

    .api-save-btn {
      width: 100%;
      background: var(--patina);
      color: #fff;
      border: none;
      border-radius: 10px;
      padding: 13px;
      font-size: 16px;
      font-weight: 700;
      cursor: pointer;
      margin-top: 8px;
      transition: background .2s;
      font-family: var(--font-body);
    }

    .api-save-btn:hover {
      background: #3f5f53;
    }

    .api-status {
      text-align: center;
      font-size: 14px;
      color: var(--patina);
      margin-top: 10px;
      min-height: 20px;
    }

    .setup-btn {
      background: var(--bronze);
      color: #fff;
      border: none;
      border-radius: 10px;
      padding: 13px 24px;
      font-size: 15px;
      font-weight: 700;
      cursor: pointer;
      width: 100%;
      font-family: var(--font-body);
    }

    .preset-btn {
      background: var(--stone);
      border: 1px solid var(--stone-line);
      border-radius: 6px;
      padding: 6px 10px;
      font-size: 13px;
      cursor: pointer;
      text-align: left;
      transition: background .15s;
      font-family: var(--font-body);
      color: var(--ink);
    }

    .preset-btn:hover {
      background: var(--stone-deep);
    }

    .demo-round-label {
      font-family: var(--font-display);
      font-weight: 600;
      font-style: italic;
      font-size: 30px;
      color: var(--bronze-deep);
      margin: 20px 0 16px;
    }

    .demo-round-label:first-child {
      margin-top: 0;
    }

    .expert-card {
      background: #fff;
      border: 1.5px solid var(--stone-line);
      border-radius: 8px;
      padding: 18px 22px;
      margin-bottom: 14px;
    }

    .expert-card .exp-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 8px;
    }

    .expert-card .exp-role {
      font-weight: 700;
      font-size: 24px;
      color: var(--ink);
    }

    .expert-card .exp-stance {
      font-size: 17px;
      font-weight: 600;
      padding: 4px 12px;
      border-radius: 999px;
      background: var(--patina-soft);
      color: var(--patina);
      white-space: nowrap;
    }

    .expert-card .exp-stance.shifted {
      background: var(--bronze-soft);
      color: var(--bronze-deep);
    }

    .expert-card p {
      font-size: 22px;
      color: var(--ink-soft);
      line-height: 1.5;
    }

    .feedback-box {
      background: var(--bronze-soft);
      border-left: 5px solid var(--bronze);
      border-radius: 4px;
      padding: 16px 20px;
      font-size: 22px;
      color: var(--ink);
      line-height: 1.55;
      margin: 6px 0 8px;
    }

    .convergence-box {
      background: var(--patina-soft);
      border-left: 5px solid var(--patina);
      border-radius: 4px;
      padding: 18px 22px;
      font-size: 23px;
      color: var(--ink);
      line-height: 1.55;
      margin-top: 18px;
    }

    .demo-error {
      color: var(--danger);
      font-weight: 600;
      font-size: 22px;
    }

    .demo-spinner {
      display: inline-block;
      width: 22px;
      height: 22px;
      border: 3px solid rgba(255, 255, 255, .4);
      border-top-color: #fff;
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }

    @keyframes spin {
      to {
        transform: rotate(360deg);
      }
    }

/* ═══════════════════════════════════════════════════════════════
       UNIFIED SIDE CHROME v3  เฉพาะส่วนปุ่มลอยสองปุ่ม
       ยกมาจากเด็คมาตรฐานเพื่อให้ผิวของปุ่มลอยตรงกันทั้งคลัง
       คือทรงกลม กรอบหมึก และเงาทึบแบบ offset ไม่ใช่เงาฟุ้ง
       ไม่ได้ยกส่วนชุดควบคุมด้านขวามาด้วย เพราะผังเป็นหน้าเลื่อนอ่าน ไม่มีชุดควบคุมนั้น
       ส่วนกฎของโหมด gutter อยู่ในบล็อกสเปกกลางท้ายไฟล์อยู่แล้ว จึงไม่ยกมาซ้ำ
       ═══════════════════════════════════════════════════════════════ */

    .fab-settings,
    .fab-chat {
      border-radius: 0;
      border: 2px solid var(--ink);
      }

    .fab-settings:hover {
      background: var(--cobalt-deep);
      }

    .fab-chat {
      background: var(--cobalt);
      }

    .fab-chat:hover {
      background: var(--cobalt-deep);
      }

    .fab-settings,
    .fab-chat {
      position: fixed;
      z-index: 8000;
      width: var(--fab-size);
      height: var(--fab-size);
      padding: 0;
      border-radius: 50%;
      border: 2.5px solid var(--ink);
      box-shadow: 3px 3px 0 rgba(20, 32, 60, 0.28);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      line-height: 0;
      transform: none;
      transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
      }

    .fab-settings {
      left: 24px;
      right: auto;
      bottom: 24px;
      top: auto;
      background: var(--ink);
      color: var(--paper);
      }

    .fab-chat {
      left: auto;
      right: 24px;
      bottom: 24px;
      top: auto;
      background: var(--cobalt);
      color: #fff;
      }

    .fab-settings:hover,
    .fab-chat:hover {
      transform: translate(-1px, -1px);
      box-shadow: 5px 5px 0 rgba(20, 32, 60, 0.28);
      background: var(--cobalt-deep);
      }

    .fab-settings:focus-visible,
    .fab-chat:focus-visible {
      outline: 3px solid var(--cobalt);
      outline-offset: 3px;
      }

    .fab-settings svg,
    .fab-chat svg {
      width: 24px;
      height: 24px;
      display: block;
      }

    body.chrome-gutter .fab-settings {
      left: calc((var(--gutter-x) - var(--fab-size)) / 2);
      right: auto;
      bottom: auto;
      top: calc(50% - var(--fab-size) - 6px);
      transform: none;
      }

    body.chrome-gutter .fab-chat {
      left: calc((var(--gutter-x) - var(--fab-size)) / 2);
      right: auto;
      bottom: auto;
      top: calc(50% + 6px);
      transform: none;
      }

    body.chrome-gutter .fab-settings:hover,
    body.chrome-gutter .fab-chat:hover {
      transform: translate(-1px, -1px);
      }


/* ═══════════════════════════════════════════════════════════════
       UNIFIED API SETTINGS MODAL v3
       ผิวเดียวกันทั้ง 4 เด็ค กรอบหมึกหนา เงาทึบ ไม่มีมุมโค้ง
       แตะเฉพาะเปลือกและ CSS ไม่แตะ id ฟังก์ชัน หรือ API_PREFIX
       ═══════════════════════════════════════════════════════════════ */
    .api-modal-overlay {
      background: rgba(20, 32, 60, 0.68);
      backdrop-filter: blur(4px);
    }

    .api-modal-box {
      background: #fff;
      border: 3px solid var(--ink);
      border-radius: 0;
      box-shadow: 10px 10px 0 var(--ink);
      padding: 2rem;
      width: 90%;
      max-width: 500px;
      max-height: 90vh;
      overflow-y: auto;
      font-family: var(--font-body);
    }

    .api-modal-box h2 {
      font-family: var(--font-body);
      font-size: 1.2rem;
      font-weight: 700;
      color: var(--ink);
      margin: 0;
    }

    .api-modal-close {
      background: none;
      border: none;
      border-radius: 0;
      font-size: 1.5rem;
      line-height: 1;
      color: var(--muted);
      cursor: pointer;
      width: auto;
      height: auto;
      padding: 0 4px;
    }

    .api-modal-close:hover {
      color: var(--ink);
    }

    .api-field {
      margin-bottom: 1rem;
    }

    .api-field label {
      display: block;
      font-size: 0.85rem;
      font-weight: 600;
      color: #374151;
      margin-bottom: 0.35rem;
    }

    .api-field input,
    .api-field select {
      width: 100%;
      border: 2px solid var(--ink);
      border-radius: 0;
      padding: 0.55rem 0.75rem;
      font-size: 0.95rem;
      outline: none;
      box-sizing: border-box;
      font-family: var(--font-body);
      background: #fff;
      color: var(--ink);
      box-shadow: none;
    }

    .api-field input:focus,
    .api-field select:focus {
      border-color: var(--cobalt);
      box-shadow: 3px 3px 0 rgba(31, 73, 199, 0.20);
    }

    .api-save-btn {
      width: 100%;
      background: var(--green-deep);
      color: #fff;
      border: 2px solid var(--ink);
      border-radius: 0;
      box-shadow: 4px 4px 0 var(--ink);
      padding: 0.7rem;
      font-size: 1rem;
      font-weight: 700;
      cursor: pointer;
      margin-top: 0.5rem;
      font-family: var(--font-body);
      transition: transform 0.15s ease, box-shadow 0.15s ease;
    }

    .api-save-btn:hover {
      background: var(--green-deep);
      transform: translate(1px, 1px);
      box-shadow: 3px 3px 0 var(--ink);
    }

    .api-status {
      text-align: center;
      font-size: 0.85rem;
      color: var(--green-deep);
      margin-top: 0.5rem;
      min-height: 1.2rem;
    }

    .preset-btn {
      background: #eef1f6;
      border: 1.5px solid var(--ink);
      border-radius: 0;
      padding: 0.35rem 0.6rem;
      font-size: 0.8rem;
      cursor: pointer;
      text-align: left;
      font-family: var(--font-body);
      color: var(--ink);
      transition: background 0.15s ease;
    }

    .preset-btn:hover {
      background: #dde3ec;
    }

    /* ── หน้าต่างชวนตั้งค่าครั้งแรก มีเฉพาะบางเด็ค ── */
    .setup-overlay {
      background: rgba(20, 32, 60, 0.92);
    }

    .setup-card {
      background: #fff;
      border: 3px solid var(--ink);
      border-radius: 0;
      box-shadow: 10px 10px 0 rgba(20, 32, 60, 0.35);
      padding: 2.5rem;
      max-width: 420px;
      width: 90%;
      text-align: center;
      font-family: var(--font-body);
    }

    .setup-card h2 {
      font-family: var(--font-body);
      font-size: 1.2rem;
      font-weight: 700;
      color: var(--ink);
    }

    .setup-card p {
      color: var(--muted);
    }

    .setup-icon {
      color: var(--cobalt);
    }

    .setup-btn,
    .setup-go-btn {
      background: var(--cobalt);
      color: #fff;
      border: 2px solid var(--ink);
      border-radius: 0;
      box-shadow: 4px 4px 0 var(--ink);
      padding: 0.75rem 1.5rem;
      font-size: 1rem;
      font-weight: 700;
      cursor: pointer;
      width: 100%;
      font-family: var(--font-body);
    }


    /* ===========================================
       ผู้ช่วยถาม-ตอบประจำเด็ค สเปกกลาง (DESIGN.md v2.2 ส่วนที่ 12)
       บล็อกนี้เหมือนกันทุกตัวอักษรในทุกชุดสไลด์ของคลัง
       วางไว้ท้ายสุดของบล็อกสไตล์เสมอ เพื่อเขียนทับกฎเดิมของแต่ละชุดด้วยลำดับที่มาทีหลัง
       ใช้เฉพาะโทเคนที่มีครบทุกชุด จึงย้ายข้ามเด็คได้โดยไม่ต้องแก้อะไร
       =========================================== */

    /* ── ปุ่มแชตตรึงมุมล่างขวาเสมอ ──
       เดิมโหมด gutter ย้ายปุ่มลอยทั้งสองไปเรียงกลางขอบว่างฝั่งซ้าย
       แต่หน้าต่างแชตยึดมุมล่างขวา ปุ่มกับหน้าต่างจึงแยกกันคนละฝั่งจอ
       จึงตรึงเฉพาะปุ่มแชตไว้ที่เดิม ส่วนปุ่มฟันเฟืองยังย้ายไปซ้ายตาม DESIGN.md
       และถูกจัดกึ่งกลางแนวตั้งใหม่ เพราะไม่มีปุ่มแชตมาต่อท้ายให้เว้นที่อีกแล้ว */
    body.chrome-gutter .fab-chat {
      left: auto;
      right: calc(var(--gutter-x) + 24px);
      top: auto;
      bottom: 24px;
      transform: none;
    }

    body.chrome-gutter .fab-chat:hover {
      transform: translate(-1px, -1px);
    }

    body.chrome-gutter .fab-settings {
      top: calc(50% - (var(--fab-size) / 2));
    }

    /* ── ตัวหน้าต่าง ── */
    .chat-panel {
      position: fixed;
      left: auto;
      top: auto;
      right: calc(var(--gutter-x) + 24px);
      bottom: 88px;
      /* ขอบขวาวัดจากขอบกระดาษสไลด์ ไม่ใช่ขอบจอ ในโหมด dock ค่า --gutter-x เป็น 0
         จึงเท่ากับ 24px ตามปกติ ส่วนโหมด gutter จะถอยเข้ามาให้พ้นคอลัมน์ชุดควบคุม
         ที่ไปเรียงอยู่ในขอบว่างฝั่งขวา ปุ่มแชตถอยตามด้วยระยะเดียวกัน จึงยังอยู่ติดกันเสมอ
         ระยะล่าง 88 = 24 ขอบล่าง บวก 52 ความสูงปุ่มลอย บวก 12 ช่องไฟ */
      z-index: 7999;
      width: min(440px, calc(100vw - 48px));
      height: min(620px, calc(100vh - 112px));
      background: var(--stone-card);
      border: 2px solid var(--ink);
      border-radius: 0;
      box-shadow: 8px 8px 0 rgba(20, 32, 60, 0.22);
      display: flex;
      flex-direction: column;
      overflow: hidden;
      opacity: 0;
      transform: translateY(16px) scale(.97);
      pointer-events: none;
      transition: opacity .25s var(--ease), transform .25s var(--ease);
    }

    body.chrome-gutter .chat-panel {
      left: auto;
      right: calc(var(--gutter-x) + 24px);
      bottom: 88px;
    }

    .chat-panel.show {
      opacity: 1;
      transform: translateY(0) scale(1);
      pointer-events: auto;
    }

    /* ── แถบหัวหน้าต่าง พื้นหมึก ตัวอักษรสีกระดาษ ── */
    .chat-panel-header {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      gap: 10px;
      padding: 16px 16px 13px;
      border-bottom: 2px solid var(--ink);
      background: var(--ink);
      color: var(--paper);
      flex-shrink: 0;
    }

    .chat-panel-title {
      font-family: var(--font-display);
      font-weight: 600;
      font-size: 17px;
      line-height: 1.3;
      color: var(--paper);
    }

    /* สองกฎนี้คือจุดที่เคยพลาด เดิมสองชุดใช้ var(--stone-line) ซึ่งเป็นหมึกโปร่งแสง
       วางบนพื้นหมึกจึงกลายเป็นล่องหน ต้องใช้สีกระดาษโปร่งแสงเท่านั้น */
    .chat-panel-sub {
      font-family: var(--font-body);
      font-size: 12px;
      color: rgba(246, 244, 236, 0.72);
      margin-top: 3px;
    }

    .chat-header-btn {
      background: none;
      border: none;
      color: rgba(246, 244, 236, 0.72);
      cursor: pointer;
      padding: 5px;
      border-radius: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: color .2s, background .2s;
    }

    .chat-header-btn:hover {
      color: var(--paper);
      background: rgba(246, 244, 236, .14);
    }

    .chat-header-btn svg {
      width: 17px;
      height: 17px;
    }

    .chat-panel-actions {
      display: flex;
      gap: 4px;
      align-items: center;
      flex-shrink: 0;
    }

    .chat-panel-close {
      background: none;
      border: none;
      color: var(--paper);
      font-size: 22px;
      line-height: 1;
      cursor: pointer;
      padding: 2px 6px;
      border-radius: 0;
    }

    .chat-panel-close:hover {
      background: rgba(246, 244, 236, .14);
    }

    /* ── พื้นที่ข้อความ ── */
    .chat-messages {
      flex: 1;
      min-height: 0;
      overflow-y: auto;
      padding: 16px;
      display: flex;
      flex-direction: column;
      gap: 12px;
      font-family: var(--font-body);
      font-size: 14.5px;
      line-height: 1.55;
    }

    .chat-msg {
      max-width: 88%;
      padding: 10px 13px;
      border-radius: 0;
      white-space: pre-wrap;
    }

    .chat-msg.bot {
      align-self: flex-start;
      background: rgba(31, 73, 199, 0.10);
      color: var(--ink);
      border-left: 3px solid var(--cobalt);
    }

    .chat-msg.user {
      align-self: flex-end;
      background: var(--ink);
      color: var(--paper);
      border-left: none;
    }

    .chat-msg.error {
      align-self: flex-start;
      background: rgba(232, 85, 90, .14);
      color: var(--danger);
      border-left: 3px solid #E8555A;
      border-bottom-left-radius: 0;
    }

    /* ── ชิปคำถามชวนเริ่ม ── */
    .chat-chips {
      display: flex;
      flex-direction: column;
      gap: 6px;
      align-self: flex-start;
      max-width: 92%;
    }

    .chat-chip {
      text-align: left;
      background: var(--paper);
      border: 1.5px solid var(--stone-line);
      border-radius: 0;
      color: var(--ink);
      font-family: var(--font-body);
      font-size: 13px;
      padding: 9px 13px;
      cursor: pointer;
      transition: border-color .2s, background .2s;
    }

    .chat-chip:hover {
      border-color: var(--cobalt);
      background: rgba(31, 73, 199, 0.10);
    }

    /* ── ปุ่มคัดลอกและถามใหม่ ── */
    .chat-copy-btn,
    .chat-regenerate-btn {
      border-radius: 0;
      font-family: var(--font-body);
    }

    .chat-regenerate-btn {
      border: 1.5px solid var(--stone-line);
    }

    .chat-regenerate-btn:hover {
      border-color: var(--cobalt);
      color: var(--cobalt-deep);
    }

    /* ── แถวช่องพิมพ์ ── */
    .chat-input-row {
      display: flex;
      gap: 8px;
      padding: 12px;
      border-top: 2px solid var(--ink);
      background: var(--stone-card);
      flex-shrink: 0;
    }

    .chat-input {
      flex: 1;
      resize: none;
      max-height: 90px;
      padding: 10px 12px;
      border: 2px solid var(--ink);
      border-radius: 0;
      font-family: var(--font-body);
      font-size: 14px;
      color: var(--ink);
      background: #fff;
      outline: none;
    }

    .chat-input:focus {
      border-color: var(--cobalt);
      box-shadow: 3px 3px 0 rgba(31, 73, 199, 0.20);
    }

    .chat-send-btn {
      width: 44px;
      height: 44px;
      border: 2px solid var(--ink);
      border-radius: 0;
      background: var(--cobalt);
      color: #fff;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: background .2s;
    }

    .chat-send-btn:hover {
      background: var(--cobalt-deep);
    }

    .chat-send-btn:disabled {
      opacity: .5;
      cursor: not-allowed;
    }

    /* ── จอแคบ ── */
    @media (max-width: 560px) {

      .chat-panel,
      body.chrome-gutter .chat-panel {
        right: 12px;
        bottom: 80px;
        width: calc(100vw - 24px);
        height: min(620px, calc(100vh - 104px));
      }

      body.chrome-gutter .fab-chat {
        right: 12px;
        bottom: 12px;
      }
    }

    /* ── โหมดสลับชุดคำถาม และแถบสร้างข้อสอบด้วยปัญญาประดิษฐ์ ── */
    .qz-mode-row {
      display: flex;
      gap: 10px;
      margin-bottom: 10px;
    }

    .qz-mode-btn {
      font-family: var(--font-display);
      font-size: 20px;
      font-weight: 600;
      padding: 8px 18px;
      border: 2.5px solid var(--ink);
      background: var(--card);
      color: var(--muted);
      cursor: pointer;
      box-shadow: 4px 4px 0 rgba(20, 32, 60, 0.16);
      transition: background 0.16s, color 0.16s;
    }

    .qz-mode-btn.on {
      background: var(--act-deep);
      border-color: var(--ink);
      color: var(--paper);
    }

    .qz-genbar {
      display: flex;
      gap: 10px;
      margin-bottom: 10px;
      align-items: stretch;
    }

    .qz-gen-input {
      flex: 1;
      font-family: var(--font-body);
      font-size: 20px;
      padding: 10px 14px;
      border: 2.5px solid var(--ink);
      background: var(--card);
      color: var(--ink);
      outline: none;
    }

    .qz-gen-input:focus {
      box-shadow: 4px 4px 0 var(--act-soft);
    }

    .qz-gen-note {
      font-family: var(--font-body);
      font-size: 18px;
      color: var(--muted);
      margin-bottom: 8px;
    }

    .qz-gen-note.err {
      color: var(--red-deep);
      font-weight: 600;
    }

    /* ว่างเมื่อใด ให้ยุบพื้นที่ทิ้ง จะได้ไม่กินความสูงของกล่องเหตุผล */
    .qz-gen-note:empty {
      display: none;
    }

    /* ── ตัวเลือกโหมดของผู้ช่วยถามตอบ ── */
    .chat-ctx-row {
      display: flex;
      gap: 8px;
      padding: 10px 18px 0;
      flex-wrap: wrap;
      align-items: center;
    }

    .chat-ctx-btn {
      font-family: inherit;
      font-size: 12.5px;
      font-weight: 600;
      padding: 5px 12px;
      border: 1.5px solid #cbd5e1;
      border-radius: 0;
      background: #fff;
      color: #64748b;
      cursor: pointer;
      transition: all 0.15s;
    }

    .chat-ctx-btn.on {
      background: #1F49C7;
      border-color: #1F49C7;
      color: #fff;
    }

    .chat-ctx-here {
      font-size: 12px;
      color: #94a3b8;
      margin-left: 2px;
      max-width: 100%;
    }

    /* ── ป้ายกำกับแหล่งนอกวรรณกรรมที่อาจารย์กำหนด และลิงก์ต้นฉบับ ── */
    .src-badge {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      font-family: var(--font-mono);
      font-size: 16px;
      font-weight: 700;
      letter-spacing: 0.04em;
      color: var(--paper);
      background: var(--amber-deep);
      border: 2.5px solid var(--ink);
      padding: 5px 14px;
      margin-left: 14px;
      box-shadow: 4px 4px 0 rgba(20, 32, 60, 0.2);
    }

    .src-badge::before {
      content: "!";
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 18px;
      height: 18px;
      background: var(--paper);
      color: var(--amber-deep);
      font-weight: 700;
      flex: 0 0 auto;
    }

    .src-link {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      font-family: var(--font-mono);
      font-size: 0.8em;
      font-weight: 700;
      color: var(--cobalt-deep);
      background: rgba(31, 73, 199, 0.08);
      border: 1.5px solid var(--cobalt-deep);
      padding: 2px 9px;
      text-decoration: none;
      white-space: nowrap;
      cursor: pointer;
      transition: background .16s, color .16s;
    }

    /* ลูกศรทแยง บอกให้รู้ว่าลิงก์นี้เปิดในแท็บใหม่ */
    .src-link::after {
      content: "\2197";
      font-size: 1.05em;
      line-height: 1;
    }

    .src-link:hover,
    .src-link:focus-visible {
      background: var(--cobalt-deep);
      color: var(--paper);
    }

    .src-link:focus-visible {
      outline: 3px solid var(--amber);
      outline-offset: 2px;
    }
