/* =========================================================
   ปิ๊ง — กระดานรวมความคิด (ธีมฟ้า ตามระบบดีไซน์ t-educator.com)
   ส่วน tokens คัดลอกจาก MasterTemplate/tokens.css — ห้ามแก้ตรงนี้ ให้แก้ที่ต้นทางแล้วคัดลอกมาใหม่
   ========================================================= */
/* =========================================================
   Master Template — Design tokens (single source of truth)
   ---------------------------------------------------------
   ใช้ไฟล์นี้กับทุกแอปในซีรีส์ เพื่อให้สี ขนาด และธีมมืดตรงกัน
   • โหลดฟอนต์: IBM Plex Sans Thai (400/500/600) จาก Google Fonts
   • ธีม: ตามระบบปฏิบัติการ หรือบังคับด้วย <html data-theme="light|dark">
   • อธิบายเหตุผลทั้งหมดอยู่ใน DESIGN-SYSTEM.md
   Version 1.0 · พ.ย. 2569 · สีหลัก: ฟ้าอมเขียว (Bootstrap "info") + โทนมูจิ
   ========================================================= */

/* ---------- Design tokens (light) ---------- */
:root {
  color-scheme: light;
  --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;

  --sidebar-w: 268px;
  --sidebar-w-collapsed: 76px;
  --topbar-h: 64px;
  --radius-lg: 14px;
  --radius: 10px;

  --bg: #f2f5f5;
  --surface: #ffffff;
  --surface-2: #f8fafa;
  --surface-3: #edf1f1;
  --border: #e2e8e8;
  --border-strong: #d0d9d9;

  --text: #152022;
  --text-2: #4b5859;
  --text-3: #7f8b8b;
  --hover: rgba(16, 42, 46, 0.045);

  --accent: #12808f;
  --accent-hover: #0f6f7c;
  --accent-soft: #e2f1f3;
  --accent-text: #0f6b77;
  --accent-ring: rgba(18, 128, 143, 0.22);
  --on-accent: #ffffff;

  /* sidebar + topbar ("chrome") — Bootstrap "info" teal */
  --chrome: #17a2b8;
  --chrome-ink: #117a8b;              /* teal text on white (active item, badges) */
  --on-chrome: #ffffff;
  --on-chrome-2: rgba(255, 255, 255, 0.88);
  --on-chrome-3: rgba(255, 255, 255, 0.76);
  --chrome-hover: rgba(255, 255, 255, 0.15);
  --chrome-line: rgba(255, 255, 255, 0.22);

  /* chart chrome */
  --grid: #e7eded;
  --axis: #c2cccc;
  --prev: #bec8c8;
  --spark: #bec8c8;

  /* status */
  --good-text: #4a7656;
  --good-soft: #e6efe8;
  --warn-text: #80652f;
  --warn-soft: #f3ecdc;
  --bad: #d27a63;
  --bad-text: #9f5646;
  --bad-soft: #f5e7e2;

  --shadow-sm: 0 1px 2px rgba(16, 42, 46, 0.05);
  --shadow-lg: 0 16px 40px -12px rgba(16, 42, 46, 0.2), 0 2px 6px rgba(16, 42, 46, 0.05);
  --tip-bg: #182325;
  --tip-text: #f2f5f5;
  --overlay: rgba(10, 10, 9, 0.45);   /* พื้นหลังทึบใต้ drawer/dialog */
  /* soft decorative tints (muji / pastel) */
  --tint-blue: #4c7888;
  --tint-orange: #94654a;
  --tint-green: #52775c;
  --tint-pink: #955e6a;
  --tint-violet: #6c628a;
}

/* ---------- Design tokens (dark) ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c1112;
    --surface: #161d1e;
    --surface-2: #1a2223;
    --surface-3: #212a2b;
    --border: #263132;
    --border-strong: #334142;
    --text: #e8eeee;
    --text-2: #b6c2c2;
    --text-3: #849191;
    --hover: rgba(255, 255, 255, 0.05);
    --accent: #17899a;
    --accent-hover: #1f9db0;
    --accent-soft: rgba(23, 162, 184, 0.16);
    --accent-text: #86d0dc;
    --accent-ring: rgba(23, 162, 184, 0.35);
    --chrome: #0f7483;
    --chrome-ink: #0f7483;
    --chrome-hover: rgba(255, 255, 255, 0.12);
    --chrome-line: rgba(255, 255, 255, 0.16);
    --grid: #243031;
    --axis: #354243;
    --prev: #4d5b5c;
    --spark: #4a5859;
    --good-text: #93bd9e;
    --good-soft: rgba(120, 168, 132, 0.16);
    --warn-text: #d8bf85;
    --warn-soft: rgba(216, 191, 133, 0.14);
    --bad-text: #e3a291;
    --bad-soft: rgba(210, 122, 99, 0.18);
    --shadow-sm: none;
    --shadow-lg: 0 16px 40px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.04);
    --tip-bg: #e8eeee;
    --tip-text: #152022;
    --overlay: rgba(0, 0, 0, 0.6);
    --tint-blue: #8db6c3;
    --tint-orange: #d0a080;
    --tint-green: #93b89c;
    --tint-pink: #d09aa5;
    --tint-violet: #aea4c8;
    --bad: #d9826c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1112;
  --surface: #161d1e;
  --surface-2: #1a2223;
  --surface-3: #212a2b;
  --border: #263132;
  --border-strong: #334142;
  --text: #e8eeee;
  --text-2: #b6c2c2;
  --text-3: #849191;
  --hover: rgba(255, 255, 255, 0.05);
  --accent: #17899a;
  --accent-hover: #1f9db0;
  --accent-soft: rgba(23, 162, 184, 0.16);
  --accent-text: #86d0dc;
  --accent-ring: rgba(23, 162, 184, 0.35);
  --chrome: #0f7483;
  --chrome-ink: #0f7483;
  --chrome-hover: rgba(255, 255, 255, 0.12);
  --chrome-line: rgba(255, 255, 255, 0.16);
  --grid: #243031;
  --axis: #354243;
  --prev: #4d5b5c;
  --spark: #4a5859;
  --good-text: #93bd9e;
  --good-soft: rgba(120, 168, 132, 0.16);
  --warn-text: #d8bf85;
  --warn-soft: rgba(216, 191, 133, 0.14);
  --bad-text: #e3a291;
  --bad-soft: rgba(210, 122, 99, 0.18);
  --shadow-sm: none;
  --shadow-lg: 0 16px 40px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --tip-bg: #e8eeee;
  --tip-text: #152022;
  --overlay: rgba(0, 0, 0, 0.6);
  --tint-blue: #8db6c3;
  --tint-orange: #d0a080;
  --tint-green: #93b89c;
  --tint-pink: #d09aa5;
  --tint-violet: #aea4c8;
  --bad: #d9826c;
}

/* ---------- Type scale & spacing (ค่าที่แอปต้นแบบใช้) ---------- */
:root {
  --fs-kpi: 28px;        /* ตัวเลขใหญ่บนการ์ด KPI · 600 */
  --fs-title: 26px;      /* หัวข้อหน้า · 600 (มือถือ 22px) */
  --fs-stat: 18px;       /* ตัวเลขสรุปในการ์ด · 600 */
  --fs-card-title: 15.5px; /* หัวข้อการ์ด · 600 */
  --fs-body: 14px;       /* เนื้อหาหลัก · 400 */
  --fs-ui: 13.5px;       /* เมนู ปุ่ม ตาราง · 500 */
  --fs-sub: 13px;        /* คำอธิบายใต้หัวข้อ */
  --fs-meta: 12.5px;     /* หัวตาราง tooltip ข้อความประกอบ */
  --fs-label: 12px;      /* ป้ายกลุ่มเมนู badge */
  --fs-tick: 11.5px;     /* แกนกราฟ kbd · เล็กสุดที่ใช้ */
  --lh-body: 1.55;       /* ภาษาไทยต้องเผื่อสระบน/ล่าง */

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;       /* gap ระหว่างการ์ด */
  --space-5: 20px;       /* padding การ์ด */
  --space-6: 24px;
  --space-7: 28px;       /* padding เนื้อหา (desktop) */

  --radius-sm: 8px;
  --radius-pill: 999px;
  --content-max: 1480px;
}


/* ---------- ธีมฟ้า (hue ≈ 208°) ---------- */
:root {
  --chrome: #3d7fb8; --chrome-ink: #2f6597;
  --accent: #336ea3; --accent-hover: #2b5f8c; --accent-soft: #e5eff8; --accent-text: #2c6496; --accent-ring: rgba(61, 127, 184, 0.24);
  --bg: #f2f5f8; --surface: #ffffff; --surface-2: #f8fafc; --surface-3: #ecf1f5; --border: #e1e7ed; --border-strong: #cfd8e1;
  --text: #172029; --text-2: #4b5764; --text-3: #7d8995; --hover: rgba(20, 40, 70, 0.045);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --chrome: #285a85; --chrome-ink: #285a85;
    --accent: #3f7fb6; --accent-hover: #4f8fc5; --accent-soft: rgba(61, 127, 184, 0.2); --accent-text: #a3c9ea; --accent-ring: rgba(61, 127, 184, 0.4);
    --bg: #0d1116; --surface: #161c23; --surface-2: #1a2129; --surface-3: #212a33; --border: #27313b; --border-strong: #34414d;
    --text: #e8edf2; --text-2: #b6c1cc; --text-3: #84909c; --hover: rgba(255, 255, 255, 0.05);
  }
}
:root[data-theme="dark"] {
  --chrome: #285a85; --chrome-ink: #285a85;
  --accent: #3f7fb6; --accent-hover: #4f8fc5; --accent-soft: rgba(61, 127, 184, 0.2); --accent-text: #a3c9ea; --accent-ring: rgba(61, 127, 184, 0.4);
  --bg: #0d1116; --surface: #161c23; --surface-2: #1a2129; --surface-3: #212a33; --border: #27313b; --border-strong: #34414d;
  --text: #e8edf2; --text-2: #b6c1cc; --text-3: #84909c; --hover: rgba(255, 255, 255, 0.05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs-body); line-height: var(--lh-body); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.3; }
p { margin: 0; }
a { color: var(--accent-text); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 var(--space-7); }
main.wrap { flex: 1 0 auto; padding-top: var(--space-6); padding-bottom: var(--space-7); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.muted { color: var(--text-3); }
.help { font-size: var(--fs-meta); color: var(--text-3); }

/* ------------------------------------------------------------ navbar + footer (เหมือนทุกแอปในซีรีส์) */
.xn { position: sticky; top: 0; z-index: 40; background: var(--chrome); color: var(--on-chrome); }
.xn-wrap { max-width: 1080px; height: var(--topbar-h); margin: 0 auto; padding: 0 var(--space-7); display: flex; align-items: center; gap: var(--space-4); }
.xn :focus-visible { outline-color: var(--on-chrome); }
.xn-brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; color: inherit; text-decoration: none; }
.xn-logo { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 9px; background: #fff; color: var(--chrome-ink); }
.xn-logo svg { width: 24px; height: 24px; }
.xn-tx { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.xn-tx b { font-size: var(--fs-card-title); font-weight: 600; }
.xn-tx span { font-size: var(--fs-label); color: var(--on-chrome-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xn-links { margin-left: auto; display: flex; align-items: center; gap: var(--space-1); }
.xn-link { display: inline-flex; align-items: center; gap: var(--space-2); height: 38px; padding: 0 var(--space-3); border: 0; border-radius: 9px; background: transparent; color: var(--on-chrome); font-size: var(--fs-ui); font-weight: 500; text-decoration: none; cursor: pointer; transition: background .15s; }
.xn-link:hover { background: var(--chrome-hover); }
.xn-link svg { width: 18px; height: 18px; flex: none; }
.xn-icon { width: 38px; padding: 0; justify-content: center; }
.xn .t-sun { display: none; }
:root[data-theme="dark"] .xn .t-sun { display: block; }
:root[data-theme="dark"] .xn .t-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .xn .t-sun { display: block; }
  :root:not([data-theme="light"]) .xn .t-moon { display: none; }
}
.xf { border-top: 1px solid var(--border); background: var(--surface); color: var(--text-3); font-size: var(--fs-meta); }
.xf-wrap { max-width: 1080px; margin: 0 auto; padding: var(--space-4) var(--space-7) calc(var(--space-4) + env(safe-area-inset-bottom)); display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-1) var(--space-4); }
.xf b { color: var(--text-2); font-weight: 500; }

/* ------------------------------------------------------------ ฟอร์มและปุ่ม */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 38px; padding: 0 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font-size: var(--fs-ui); font-weight: 500; white-space: nowrap; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.soft { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.btn.soft:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn.danger { color: var(--bad-text); border-color: color-mix(in srgb, var(--bad-text) 35%, transparent); background: transparent; }
.btn.danger:hover:not(:disabled) { background: var(--bad-soft); }
.btn.lg { min-height: 48px; padding: 0 24px; font-size: var(--fs-card-title); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: var(--fs-meta); }
.btn.icon { width: 32px; min-height: 32px; padding: 0; }
.btn.block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .lbl { font-size: var(--fs-label); font-weight: 500; color: var(--text-2); }
.input, textarea.input, select.input { width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); color: var(--text); font-size: var(--fs-body); line-height: 1.5; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea.input { resize: vertical; min-height: 72px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.input.code { height: 54px; font-size: 26px; font-weight: 600; letter-spacing: .18em; text-align: center; font-variant-numeric: tabular-nums; }
.input.code::placeholder { font-size: var(--fs-body); font-weight: 400; letter-spacing: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.row > .grow { flex: 1; min-width: 0; }

.seg { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.seg button { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--text-2); font-size: var(--fs-meta); font-weight: 500; white-space: nowrap; cursor: pointer; }
.seg button:hover { background: var(--hover); color: var(--text); }
.seg button[aria-checked="true"] { background: var(--accent-soft); color: var(--accent-text); }
.seg button svg { width: 15px; height: 15px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); cursor: pointer; }
.switch span b { display: block; font-weight: 500; font-size: var(--fs-ui); }
.switch span small { display: block; font-size: var(--fs-meta); color: var(--text-3); }
.switch input { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 42px; height: 24px; margin: 0; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-meta); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--radius-pill); font-size: var(--fs-label); font-weight: 500; white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good-text); }
.badge.warn { background: var(--warn-soft); color: var(--warn-text); }
.badge.bad { background: var(--bad-soft); color: var(--bad-text); }
.badge.live { background: var(--accent-soft); color: var(--accent-text); }
.badge.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .3; } }
.note { display: flex; gap: var(--space-2); padding: 10px 12px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn-text); font-size: var(--fs-meta); }
.note ul { margin: 4px 0 0; padding-left: 18px; }
.note b { font-weight: 600; }
.note svg { flex: none; width: 16px; height: 16px; margin-top: 2px; }
.err { color: var(--bad-text); font-size: var(--fs-meta); min-height: 1.2em; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 80; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: var(--radius); background: var(--tip-bg); color: var(--tip-text); font-size: var(--fs-ui); opacity: 0; transform: translate(-50%, 8px); transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad-text); color: #fff; }

/* ------------------------------------------------------------ หน้าแรก */
.hero { display: grid; justify-items: center; gap: 8px; padding: var(--space-4) 0 var(--space-6); text-align: center; }
.hero-mark { width: 96px; height: 96px; color: var(--accent); animation: float 4s ease-in-out infinite; }
.hero h1 { font-size: clamp(34px, 7vw, 46px); }
.hero p { max-width: 36em; color: var(--text-2); font-size: var(--fs-card-title); }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.doors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); align-items: start; }
.door { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-6); }
.door-h { display: flex; align-items: center; gap: var(--space-3); }
.door-ic { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: var(--radius); background: var(--accent-soft); color: var(--accent-text); }
.door-ic svg { width: 22px; height: 22px; }
.door h2 { font-size: 20px; }
.door-h p { font-size: var(--fs-sub); color: var(--text-3); }
.code-made { display: grid; justify-items: center; gap: 6px; padding: var(--space-5); border: 1px dashed var(--accent); border-radius: var(--radius); background: var(--accent-soft); text-align: center; }
.code-made .big { font-size: 40px; font-weight: 600; letter-spacing: .14em; color: var(--accent-text); font-variant-numeric: tabular-nums; }
.steps3 { margin-top: var(--space-6); padding: var(--space-5); }
.steps3 h2 { font-size: var(--fs-card-title); margin-bottom: var(--space-4); }
.steps3 ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.steps3 li { display: flex; gap: var(--space-3); }
.steps3 .n { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); font-weight: 600; font-size: var(--fs-meta); }
.steps3 b { display: block; font-weight: 600; }
.steps3 p { font-size: var(--fs-sub); color: var(--text-2); }

/* ------------------------------------------------------------ หน้าจัดการห้อง */
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); }
.head h1 { font-size: var(--fs-title); word-break: break-word; }
.head .sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 6px; font-size: var(--fs-sub); color: var(--text-3); }
.head .acts { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--space-4); align-items: start; }
.side { display: flex; flex-direction: column; gap: var(--space-4); position: sticky; top: calc(var(--topbar-h) + 16px); }
.panel { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.panel-h h2 { font-size: var(--fs-card-title); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.qform { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-4); border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.qlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); counter-reset: q; }
.qitem { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: var(--space-3); align-items: start; padding: 12px 12px 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.qitem.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.qitem .qn { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-3); color: var(--text-2); font-size: var(--fs-meta); font-weight: 600; margin-top: 1px; }
.qitem.on .qn { background: var(--accent); color: var(--on-accent); }
.qitem .qt { font-weight: 500; line-height: 1.5; word-break: break-word; }
.qitem .qm { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: var(--fs-meta); color: var(--text-3); }
.qitem .qa { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px; }
.qitem .qedit { grid-column: 2 / 4; display: flex; flex-direction: column; gap: var(--space-2); }
.qform select.input, .qedit select.input { width: auto; min-width: 150px; }
.empty-note { padding: var(--space-5); border: 1px dashed var(--border-strong); border-radius: var(--radius); text-align: center; color: var(--text-3); font-size: var(--fs-sub); }
.mod-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; max-height: 420px; overflow: auto; position: relative; }
.mod-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: var(--space-3); align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.mod-list li.hid .t { color: var(--text-3); text-decoration: line-through; }
.mod-list .t { word-break: break-word; }
.mod-list .n { font-size: var(--fs-meta); color: var(--text-2); font-variant-numeric: tabular-nums; }
.kv { display: flex; justify-content: space-between; gap: var(--space-3); font-size: var(--fs-sub); }
.kv span { color: var(--text-3); }
dialog.dlg { margin: auto; width: min(440px, calc(100% - 32px)); padding: var(--space-6) var(--space-5) var(--space-5); border: 0; border-radius: var(--radius-lg); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.dlg::backdrop { background: var(--overlay); }
dialog.dlg h2 { font-size: 19px; margin-bottom: var(--space-2); }
dialog.dlg .acts { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-4); }

/* ------------------------------------------------------------ หน้าผู้ร่วมกิจกรรม */
.join-card { width: 100%; max-width: 640px; margin: 0 auto; padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.join-card .room-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: var(--fs-sub); color: var(--text-3); }
.join-card h1 { font-size: clamp(22px, 4.6vw, 28px); word-break: break-word; }
.answer-row { display: flex; gap: var(--space-2); }
.answer-row .input { flex: 1; min-height: 50px; font-size: 17px; }
.answer-row .btn { min-height: 50px; }
.mine { display: flex; flex-wrap: wrap; gap: 6px; }
.mine span { padding: 4px 12px; border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-sub); }
.state { display: grid; justify-items: center; gap: var(--space-3); padding: var(--space-6) var(--space-4); text-align: center; }
.state svg { width: 84px; height: 84px; color: var(--accent); }
.state.wait svg { animation: float 3s ease-in-out infinite; }
.state h2 { font-size: 20px; }
.state p { color: var(--text-2); max-width: 30em; }
.thanks { display: flex; align-items: center; gap: var(--space-2); padding: 10px 14px; border-radius: var(--radius); background: var(--good-soft); color: var(--good-text); font-weight: 500; }
.mini-viz { height: 280px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }

/* ------------------------------------------------------------ จอนำเสนอ */
.pres { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-5); min-height: calc(100vh - var(--topbar-h) - 120px); }
.pres-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.joinbox { display: flex; align-items: center; gap: var(--space-3); padding: 8px 10px 8px 14px; border-radius: var(--radius); background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-sub); }
.joinbox b { font-size: 1.35em; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.joinbox .qr { width: 64px; height: 64px; padding: 3px; border: 0; border-radius: 8px; background: #fff; cursor: zoom-in; }
.joinbox .qr svg { display: block; width: 100%; height: 100%; }
.pres-q { font-size: clamp(24px, 3.4vw, 40px); line-height: 1.35; word-break: break-word; }
.viz { position: relative; flex: 1; min-height: 360px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.viz-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: var(--space-2); color: var(--text-3); text-align: center; }
.viz-empty svg { width: 64px; height: 64px; color: var(--accent); opacity: .6; animation: float 3s ease-in-out infinite; }
.pres-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.pres-bar .count { font-size: var(--fs-sub); color: var(--text-2); font-variant-numeric: tabular-nums; }
.pres-bar .count b { font-size: 1.25em; color: var(--text); }
.pres-bar .nav { display: flex; align-items: center; gap: var(--space-2); }
.pres-bar .qpos { min-width: 64px; text-align: center; font-size: var(--fs-sub); color: var(--text-3); font-variant-numeric: tabular-nums; }
.qr-overlay { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px; background: rgba(10, 16, 24, .84); cursor: zoom-out; }
.qr-big { display: grid; justify-items: center; gap: 10px; width: min(92vw, 80vh, 620px); padding: 24px; border-radius: 22px; background: #fff; color: #172029; text-align: center; }
.qr-big .qr-svg { width: 100%; aspect-ratio: 1; }
.qr-big .qr-svg svg { display: block; width: 100%; height: 100%; }
.qr-big .t { font-size: clamp(18px, 2.6vw, 26px); font-weight: 600; color: #2f6597; }
.qr-big .c { font-size: clamp(34px, 6vw, 60px); font-weight: 600; letter-spacing: .14em; line-height: 1.1; }
.qr-big .u { font-size: clamp(13px, 1.8vw, 18px); color: #4b5764; overflow-wrap: anywhere; }

/* โหมดเต็มจอ: เหลือแต่พื้นที่นำเสนอ ตัวใหญ่อ่านได้จากหลังห้อง */
.pres:fullscreen { min-height: 100vh; padding: 3vh 3vw; border: 0; border-radius: 0; background: var(--bg); gap: 2vh; }
.pres:fullscreen .pres-q { font-size: clamp(28px, 4.4vw, 64px); }
.pres:fullscreen .joinbox { font-size: clamp(14px, 1.5vw, 22px); }
.pres:fullscreen .joinbox .qr { width: clamp(64px, 9vh, 120px); height: clamp(64px, 9vh, 120px); }
.pres:fullscreen .viz { border: 0; background: transparent; }

/* ------------------------------------------------------------ เมฆคำ */
.cloud { position: absolute; inset: 0; }
.cw { position: absolute; left: 0; top: 0; white-space: nowrap; line-height: 1.15; font-weight: 600; transform-origin: center; transition: transform .6s cubic-bezier(.2, .8, .2, 1), font-size .6s cubic-bezier(.2, .8, .2, 1), opacity .4s; will-change: transform; user-select: none; }
.cw.new { animation: pop .55s cubic-bezier(.2, 1.5, .4, 1); }
.cw.bump { animation: bump .5s ease; }
.cw.out { opacity: 0; }
@keyframes pop { 0% { opacity: 0; scale: .3; } 100% { opacity: 1; scale: 1; } }
@keyframes bump { 40% { scale: 1.12; } }
.c0 { color: var(--accent); }
.c1 { color: var(--tint-violet); }
.c2 { color: var(--tint-green); }
.c3 { color: var(--tint-orange); }
.c4 { color: var(--tint-pink); }
.c5 { color: var(--tint-blue); }

/* ------------------------------------------------------------ เรียงลำดับ */
.rank { position: absolute; inset: 0; overflow: auto; padding: var(--space-4); }
.rank ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.rank li { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: var(--space-3); transition: transform .5s cubic-bezier(.2, .8, .2, 1); }
.rank li.new { animation: pop .45s ease; }
.rank .rk { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-3); color: var(--text-2); font-size: var(--fs-meta); font-weight: 600; }
.rank li:nth-child(1) .rk { background: var(--accent); color: var(--on-accent); }
.rank li:nth-child(2) .rk, .rank li:nth-child(3) .rk { background: var(--accent-soft); color: var(--accent-text); }
.rank .bx { position: relative; min-width: 0; padding: 8px 12px; border-radius: var(--radius-sm); overflow: hidden; }
.rank .bar { position: absolute; inset: 0 auto 0 0; width: var(--w, 0%); background: var(--accent-soft); border-radius: inherit; transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.rank li:nth-child(1) .bar { background: color-mix(in srgb, var(--accent) 26%, var(--surface)); }
.rank .tx { position: relative; display: block; font-size: clamp(15px, 1.6vw, 20px); font-weight: 500; word-break: break-word; }
.rank .n { min-width: 40px; text-align: right; font-weight: 600; font-size: clamp(15px, 1.6vw, 20px); font-variant-numeric: tabular-nums; color: var(--text-2); }
.pres:fullscreen .rank .tx, .pres:fullscreen .rank .n { font-size: clamp(18px, 2.2vw, 32px); }
.rank .more { padding: 8px 0 0 46px; font-size: var(--fs-meta); color: var(--text-3); }

/* ------------------------------------------------------------ จอเล็ก */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; }
  .doors { grid-template-columns: minmax(0, 1fr); }
  .steps3 ol { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 767px) {
  .wrap, .xn-wrap, .xf-wrap { padding-left: var(--space-4); padding-right: var(--space-4); }
  main.wrap { padding-top: var(--space-5); padding-bottom: var(--space-6); }
  .xn-tx span { display: none; }
  .head h1 { font-size: 22px; }
  .door, .join-card { padding: var(--space-5); }
  .pres { padding: var(--space-4); }
  .qitem { grid-template-columns: 30px minmax(0, 1fr); }
  .qitem .qa { grid-column: 1 / 3; justify-content: flex-start; }
}
@media (max-width: 479px) {
  .xn-link .xn-l { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .answer-row { flex-direction: column; }
  .head .acts .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* โลโก้ KruKits ในแถบบน (19 พ.ย. 2569) */
.xn-brand .kk-logo{display:block;flex:none;width:auto;fill:currentColor}
.xn-brand .kk-logo+.xn-tx{padding-left:12px;border-left:1px solid var(--chrome-line)}
@media (max-width:767px){.xn-brand .kk-logo+.xn-tx{display:none}}
