:root {
  --bg: #f5f8f7;
  --surface: rgba(255,255,255,.88);
  --surface-2: #eef5f3;
  --surface-3: #e3efec;
  --text: #17302b;
  --muted: #61756f;
  --line: #d7e2df;
  --primary: #0f766e;
  --primary-2: #0d9488;
  --primary-soft: #dff7f3;
  --accent: #d97706;
  --accent-soft: #fff3d6;
  --success: #15803d;
  --danger: #b42318;
  --code-bg: #0d1b1a;
  --code-text: #e6fffb;
  --shadow: 0 18px 50px rgba(38, 70, 64, .09);
  --shadow-sm: 0 8px 24px rgba(38, 70, 64, .07);
  --radius: 22px;
  --radius-sm: 14px;
  --sidebar: 320px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #091311;
  --surface: rgba(15, 31, 28, .9);
  --surface-2: #10211e;
  --surface-3: #17302b;
  --text: #e8f4f1;
  --muted: #9db1ac;
  --line: #24423c;
  --primary: #5eead4;
  --primary-2: #2dd4bf;
  --primary-soft: #123b35;
  --accent: #fbbf24;
  --accent-soft: #392b10;
  --success: #4ade80;
  --danger: #fb7185;
  --code-bg: #050b0a;
  --code-text: #d9fffa;
  --shadow: 0 18px 50px rgba(0,0,0,.25);
  --shadow-sm: 0 8px 24px rgba(0,0,0,.2);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  /* clip บน html เท่านั้น: กัน pan แนวนอนบนมือถือโดยไม่ทำให้ body กลายเป็น scroll container
     (ถ้า body เป็น scroll container position:sticky ของ topbar จะไม่ติดขอบจอ) */
  overflow-x: hidden;
  overflow-x: clip;
  /* ตัด scroll chaining: ลากนิ้วในบล็อกโค้ด/แผนภาพแล้วแรงไม่ส่งต่อไปแพนทั้งหน้า */
  overscroll-behavior-x: none;
}
body {
  margin: 0;
  min-height: 100vh;
  overflow-wrap: anywhere;
  /* ครอบ ink ที่หลุดออกจาก body (รวมถึง div วัดขนาดชั่วคราวที่ mermaid แทรกตอน render)
     — ใช้ clip ไม่ใช่ hidden เพื่อไม่ให้ body กลายเป็น scroll container ทำให้ sticky topbar เสีย */
  overflow-x: clip;
  background:
    radial-gradient(circle at 10% 10%, color-mix(in srgb, var(--primary) 12%, transparent), transparent 30%),
    radial-gradient(circle at 90% 4%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 24%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", sans-serif;
  line-height: 1.65;
  transition: background .3s ease, color .3s ease;
}
button, input, select { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.skip-link {
  position: fixed; top: 8px; left: 8px; z-index: 9999;
  transform: translateY(-160%); padding: 10px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); text-decoration: none;
}
.skip-link:focus { transform: translateY(0); }
.lesson-output { margin:16px 0 22px; padding:11px 14px; border-left:3px solid var(--primary); border-radius:0 9px 9px 0; background:var(--surface-2); color:var(--muted); }
.lesson-output strong { color:var(--text); }

.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 50; height: 70px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 22px; border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  /* พื้นทึบ + ไม่ใช้ backdrop-filter: บน Android (Chrome/Samsung Internet) blur บน sticky header
     render เพี้ยน/โดนตัดครึ่งเมื่อ URL bar ยุบตอน scroll */
  background: var(--bg);
}
.brand { display:flex; align-items:center; gap:12px; min-width:0; text-decoration:none; font-weight:800; letter-spacing:-.02em; }
.brand-mark { flex:none; display:block; width:38px; height:38px; object-fit:contain; }
.brand-copy { min-width:0; }
.brand-copy span { display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.top-actions { display:flex; align-items:center; gap:8px; }
.icon-btn, .btn {
  border:1px solid var(--line); background:var(--surface); border-radius:12px; cursor:pointer;
  transition:transform .18s ease, border-color .18s ease, background .18s ease, box-shadow .18s ease;
}
.icon-btn:hover,.btn:hover { transform: translateY(-1px); border-color:color-mix(in srgb,var(--primary) 45%,var(--line)); box-shadow:var(--shadow-sm); }
.icon-btn { width:42px; height:42px; display:grid; place-items:center; }
.lang-btn { width:auto; min-width:42px; padding:0 12px; font-weight:700; font-size:13px; letter-spacing:.02em; color:var(--text); white-space:nowrap; }

.layout { display:grid; grid-template-columns: var(--sidebar) minmax(0,1fr); min-height:calc(100vh - 70px); }
.sidebar {
  position:sticky; top:70px; height:calc(100vh - 70px); overflow:auto;
  border-right:1px solid var(--line); padding:20px 16px 40px;
  background:color-mix(in srgb,var(--surface) 72%,transparent); backdrop-filter:blur(14px);
}
.sidebar-progress { background:var(--surface); border:1px solid var(--line); padding:16px; border-radius:18px; margin-bottom:16px; box-shadow:var(--shadow-sm); }
.progress-top { display:flex; justify-content:space-between; gap:10px; align-items:center; font-size:13px; color:var(--muted); margin-bottom:10px; }
.progress-top strong { color:var(--text); font-size:15px; }
.progress-track { height:8px; background:var(--surface-3); border-radius:999px; overflow:hidden; }
.progress-fill { height:100%; width:0; border-radius:inherit; background:linear-gradient(90deg,var(--primary),var(--primary-2)); transition:width .45s cubic-bezier(.2,.8,.2,1); }
.continue-btn { width:100%; margin-top:12px; }
.group-label { margin:18px 9px 8px; color:var(--muted); font-size:11px; font-weight:800; letter-spacing:.08em; text-transform:uppercase; }
.lesson-nav { display:flex; flex-direction:column; gap:5px; }
.lesson-link { display:grid; grid-template-columns:30px 1fr auto; align-items:center; gap:9px; text-decoration:none; padding:9px; border-radius:12px; color:var(--muted); font-size:13px; transition:.18s ease; }
.lesson-link:hover { background:var(--surface-2); color:var(--text); }
.lesson-link.active { background:var(--primary-soft); color:var(--text); }
.lesson-link.done .lesson-num { background:var(--success); color:#fff; border-color:transparent; }
.lesson-num { width:28px; height:28px; border:1px solid var(--line); border-radius:9px; display:grid; place-items:center; font-size:11px; font-weight:800; background:var(--surface); }
.lesson-duration { font-size:11px; opacity:.75; }
.mobile-menu { display:none; }

.main { min-width:0; }
.content { width:min(100% - 40px, 1040px); margin:0 auto; padding:44px 0 80px; }

.hero { position:relative; min-height:calc(100vh - 70px); display:grid; align-items:center; overflow:hidden; }
.hero-inner { position:relative; z-index:2; width:min(100% - 40px, 1180px); margin:auto; display:grid; grid-template-columns:minmax(0,1.12fr) minmax(0,.88fr); gap:64px; align-items:center; padding:64px 0; }
.eyebrow { display:inline-flex; align-items:center; gap:8px; max-width:100%; padding:7px 11px; border-radius:999px; background:var(--primary-soft); color:color-mix(in srgb,var(--primary) 82%,var(--text)); font-weight:800; font-size:12px; letter-spacing:.04em; text-transform:uppercase; }
.hero h1 { margin:20px 0 18px; font-size:clamp(42px,6vw,76px); line-height:.98; letter-spacing:-.055em; max-width:850px; }
.hero h1 .accent { color:var(--primary); }
.hero p.lead { margin:0; max-width:720px; font-size:clamp(18px,2vw,22px); color:var(--muted); }
.hero-actions { display:flex; gap:10px; flex-wrap:wrap; margin-top:28px; }
.btn { display:inline-flex; align-items:center; justify-content:center; gap:8px; padding:11px 16px; text-decoration:none; font-weight:750; }
.btn-primary { border-color:transparent; background:linear-gradient(145deg,var(--primary),var(--primary-2)); color:#fff; }
.btn-secondary { background:var(--surface); }
.btn-small { padding:8px 11px; font-size:13px; }
.hero-meta { display:flex; flex-wrap:wrap; gap:18px; margin-top:30px; color:var(--muted); font-size:13px; }
.hero-meta span { display:flex; gap:6px; align-items:center; }
.hero-panel { position:relative; border:1px solid var(--line); background:linear-gradient(145deg,color-mix(in srgb,var(--surface) 95%,transparent),color-mix(in srgb,var(--surface-2) 90%,transparent)); border-radius:28px; padding:22px; box-shadow:var(--shadow); transform:rotate(1deg); animation:float 6s ease-in-out infinite; }
@keyframes float { 0%,100%{transform:translateY(0) rotate(1deg)} 50%{transform:translateY(-8px) rotate(.4deg)} }
.journey-mini { display:flex; flex-direction:column; gap:13px; }
.journey-step { display:grid; grid-template-columns:38px 1fr auto; gap:11px; align-items:center; padding:12px; border-radius:14px; background:color-mix(in srgb,var(--surface) 82%,transparent); border:1px solid var(--line); }
.journey-step .dot { width:36px; height:36px; display:grid; place-items:center; border-radius:11px; background:var(--surface-3); color:var(--primary); font-weight:900; }
.journey-step strong { display:block; font-size:14px; }
.journey-step small { color:var(--muted); }
.hero-orb { position:absolute; border-radius:50%; filter:blur(1px); pointer-events:none; opacity:.55; animation:drift 10s ease-in-out infinite alternate; }
.orb-a { width:300px;height:300px;right:8%;top:8%;background:radial-gradient(circle,var(--primary-soft),transparent 68%); }
.orb-b { width:360px;height:360px;left:-100px;bottom:-80px;background:radial-gradient(circle,var(--accent-soft),transparent 70%); animation-delay:-4s; }
@keyframes drift { to { transform:translate(20px,24px) scale(1.08); } }

.section { padding:70px 0; }
.section-head { max-width:760px; margin-bottom:30px; }
.section-head h2 { font-size:clamp(30px,4vw,46px); line-height:1.05; margin:12px 0; letter-spacing:-.035em; }
.section-head p { color:var(--muted); font-size:17px; }
.grid-3 { display:grid; grid-template-columns:repeat(3,1fr); gap:16px; }
.card { border:1px solid var(--line); background:var(--surface); border-radius:var(--radius); padding:22px; box-shadow:var(--shadow-sm); }
.card h3 { margin:10px 0 8px; font-size:19px; }
.card p { color:var(--muted); margin:0; }
.card-icon { width:42px;height:42px;border-radius:13px;display:grid;place-items:center;background:var(--primary-soft);color:var(--primary);font-weight:900; }
.track-card { display:flex; flex-direction:column; gap:14px; }
.track-card .day { color:var(--primary); font-weight:850; font-size:12px; text-transform:uppercase; letter-spacing:.08em; }
.track-card ul { margin:0; padding-left:18px; color:var(--muted); }

.share-page { padding-top:32px; }
.share-topbar { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; }
.share-badge { display:inline-flex; align-items:center; gap:8px; padding:7px 12px; border-radius:999px; background:var(--primary-soft); color:color-mix(in srgb,var(--primary) 82%,var(--text)); font-weight:800; font-size:12px; letter-spacing:.02em; text-decoration:none; transition:box-shadow .18s ease; }
.share-badge img { display:block; }
.share-badge:hover { box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--primary) 45%,transparent); }
.share-actions { display:flex; align-items:center; gap:8px; }

.lesson-header { padding:28px 0 12px; }
.lesson-top { display:flex; flex-wrap:wrap; justify-content:space-between; align-items:center; gap:10px; }
.lesson-tools { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
.lesson-kicker { display:flex; flex-wrap:wrap; gap:8px; align-items:center; color:var(--muted); font-size:13px; }
/* แผงควบคุมการฟัง: พัก/เล่นต่อ · หยุด · ความเร็ว · แถบความคืบหน้า */
.speak-panel { display:flex; flex-wrap:wrap; align-items:center; gap:8px; padding:6px 8px; border:1px solid color-mix(in srgb,var(--primary) 45%,var(--line)); border-radius:13px; background:var(--surface); }
.speak-panel .btn-small { padding:6px 10px; }
.rate-switch .lang-opt { padding:3px 8px; }
.speak-progress { width:92px; height:5px; border-radius:999px; background:var(--surface-3); overflow:hidden; }
.speak-progress i { display:block; height:100%; border-radius:inherit; background:var(--primary); transition:width .25s ease; }
.pill { padding:5px 9px; border:1px solid var(--line); border-radius:999px; background:var(--surface); }
.lesson-title { margin:12px 0 10px; font-size:clamp(34px,5vw,58px); line-height:1.04; letter-spacing:-.045em; }
.lesson-intro { color:var(--muted); font-size:19px; max-width:820px; }
.lesson-goals { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; margin-top:24px; }
/* outcomes จำนวนคี่: การ์ดสุดท้ายยืดเต็มแถว แทนการทิ้งช่องว่างปลาย grid */
.lesson-goals .goal:last-child:nth-child(odd) { grid-column:1 / -1; }
.goal { padding:13px 14px; border-radius:13px; border:1px solid var(--line); background:var(--surface); display:flex; gap:9px; align-items:flex-start; }
.goal-mark { color:var(--primary); font-weight:900; }

.lesson-body { display:flex; flex-direction:column; gap:22px; margin-top:30px; }
.block { border:1px solid var(--line); background:var(--surface); border-radius:var(--radius); padding:24px; box-shadow:var(--shadow-sm); animation:rise .35s both; }
@keyframes rise { from { opacity:0; transform:translateY(8px) } to { opacity:1; transform:none } }
.block h2,.block h3 { margin-top:0; letter-spacing:-.02em; }
.block p:last-child { margin-bottom:0; }
.callout { border-left:4px solid var(--primary); background:linear-gradient(90deg,var(--primary-soft),var(--surface) 34%); }
.callout.warning { border-left-color:var(--accent); background:linear-gradient(90deg,var(--accent-soft),var(--surface) 34%); }
.callout.danger { border-left-color:var(--danger); }
.callout-title { font-weight:850; margin-bottom:6px; }
.two-col { display:grid; grid-template-columns:1fr 1fr; gap:14px; }
.compare { padding:16px; border-radius:14px; background:var(--surface-2); border:1px solid var(--line); }
.compare strong { display:block; margin-bottom:6px; }
.compare-example { margin:12px 0 0; padding-top:10px; border-top:1px dashed var(--line); color:var(--muted); font-size:13.5px; }
.compare-example strong { display:block; margin-bottom:4px; font-size:11px; text-transform:uppercase; letter-spacing:.06em; }
ul.clean,ol.clean { margin:10px 0 0; padding-left:20px; }

.code-wrap { position:relative; background:var(--code-bg); color:var(--code-text); border-radius:16px; overflow:hidden; border:1px solid color-mix(in srgb,var(--line) 35%,transparent); }
.code-head { min-height:38px; display:flex; align-items:center; justify-content:space-between; gap:10px; padding:7px 9px 7px 14px; background:rgba(255,255,255,.04); border-bottom:1px solid rgba(255,255,255,.08); color:#9fc8c1; font-size:11px; text-transform:uppercase; letter-spacing:.08em; }
.copy-btn { border:1px solid rgba(255,255,255,.12); background:rgba(255,255,255,.06); color:#d9fffa; border-radius:9px; padding:5px 9px; cursor:pointer; }
.code-head-actions { display:flex; align-items:center; gap:8px; }
.lang-switch-compact { padding:2px; border-radius:9px; }
.lang-switch-compact .lang-opt { padding:3px 9px; font-size:12px; }
.code-wrap pre { margin:0; overflow:auto; padding:18px; font:13px/1.7 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace; white-space:pre; }
.inline-code { font-family:ui-monospace,SFMono-Regular,Menlo,monospace; background:var(--surface-3); padding:2px 6px; border-radius:7px; font-size:.9em; }
.text-danger { color:var(--danger); }

.block a, .lesson-intro a, .callout a { color:var(--primary); text-decoration:underline; text-decoration-color:color-mix(in srgb,var(--primary) 45%,transparent); text-underline-offset:2px; font-weight:650; }
.block a:hover, .lesson-intro a:hover, .callout a:hover { text-decoration-color:var(--primary); }
.code-wrap a { color:#7ee6da; text-decoration:underline; text-underline-offset:2px; }
.code-wrap a:hover { color:#c3fff5; }

.diagram { position:relative; border:1px solid var(--line); border-radius:16px; background:var(--surface-2); padding:16px; overflow:auto; }
.diagram .mermaid { display:flex; justify-content:center; min-width:580px; }
/* ตัวแปรมือถือ (แนวตั้ง) ของไดอะแกรม แสดงเฉพาะจอแคบ */
.diagram .mermaid-mobile { display:none; }
.diagram-expand {
  position:absolute; top:10px; right:10px; z-index:2;
  display:flex; align-items:center; gap:6px; padding:7px 11px; font-size:12px; font-weight:750;
  border:1px solid var(--line); border-radius:10px; background:var(--surface); color:var(--text);
  cursor:pointer; box-shadow:var(--shadow-sm); transition:transform .18s ease, border-color .18s ease;
}
.diagram-expand:hover { transform:translateY(-1px); border-color:color-mix(in srgb,var(--primary) 45%,var(--line)); }

.diagram-modal { position:fixed; inset:0; z-index:200; display:none; }
.diagram-modal.open { display:block; }
.diagram-modal-backdrop { position:absolute; inset:0; background:rgba(6,14,12,.62); backdrop-filter:blur(3px); }
.diagram-modal-panel {
  position:relative; z-index:1; width:min(94vw,1240px); height:min(88vh,860px); margin:6vh auto 0;
  display:flex; flex-direction:column; background:var(--surface); border:1px solid var(--line);
  border-radius:20px; box-shadow:var(--shadow); overflow:hidden; animation:rise .25s both;
}
.diagram-modal-toolbar { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 16px; border-bottom:1px solid var(--line); background:var(--surface-2); }
.diagram-modal-title { font-size:14px; }
.diagram-modal-tools { display:flex; align-items:center; gap:6px; }
.diagram-modal-tools button {
  display:grid; place-items:center; width:34px; height:34px; border:1px solid var(--line); border-radius:10px;
  background:var(--surface); cursor:pointer; color:var(--text);
}
.diagram-modal-tools button:hover { border-color:color-mix(in srgb,var(--primary) 45%,var(--line)); }
#diagramModalClose { background:var(--danger); color:#fff; border-color:transparent; }
.diagram-zoom-label { min-width:44px; text-align:center; font-size:12px; color:var(--muted); font-weight:700; }
.diagram-modal-body { flex:1; overflow:hidden; display:flex; align-items:center; justify-content:center; padding:30px; background:var(--surface-2); cursor:grab; touch-action:none; }
.diagram-modal-body.dragging { cursor:grabbing; }
.diagram-modal-svg { transform-origin:center center; transition:transform .18s ease; user-select:none; }
.diagram-modal-body.dragging .diagram-modal-svg { transition:none; }
.diagram-modal-svg svg { max-width:none !important; height:auto !important; pointer-events:none; }

@media (max-width: 780px) {
  .diagram-modal-panel { width:100vw; height:100vh; height:100dvh; margin:0; border-radius:0; }
  .diagram-expand span { display:none; }
}

@media (max-width: 780px) {
  .diagram .mermaid { min-width:0; }
  .diagram .mermaid svg { max-width:100%; height:auto; }
  /* ไดอะแกรมที่ถูกขยายให้อ่านได้ (สูงขั้นต่ำ 170px): ห้าม flex บีบย่อ ให้คงขนาดจริงแล้วเลื่อนแนวนอนในกล่อง */
  .diagram .mermaid.diagram-pinned { justify-content:flex-start; }
  .diagram .mermaid.diagram-pinned svg { max-width:none; flex-shrink:0; }
}

.practice { border:1px solid color-mix(in srgb,var(--accent) 32%,var(--line)); background:linear-gradient(145deg,var(--surface),var(--accent-soft)); }
.practice-label { color:var(--accent); font-weight:900; text-transform:uppercase; font-size:11px; letter-spacing:.08em; }
.checklist { display:flex; flex-direction:column; gap:10px; padding:0; margin:16px 0 0; list-style:none; }
.check-item { border:1px solid var(--line); border-radius:14px; background:var(--surface); transition:border-color .16s ease; }
.check-item.done { border-color:color-mix(in srgb,var(--success) 45%,var(--line)); }
.check-row { display:flex; align-items:flex-start; gap:12px; padding:12px 14px; cursor:pointer; }
.check-row input[type="checkbox"] { appearance:none; -webkit-appearance:none; flex-shrink:0; width:22px; height:22px; margin:1px 0 0; border:2px solid color-mix(in srgb,var(--accent) 55%,var(--muted)); border-radius:7px; background:var(--surface); cursor:pointer; position:relative; transition:background .16s ease, border-color .16s ease; }
.check-row input[type="checkbox"]:checked { background:var(--success); border-color:var(--success); }
.check-row input[type="checkbox"]:checked::after { content:''; position:absolute; left:6px; top:2px; width:5px; height:10px; border:solid #fff; border-width:0 2.5px 2.5px 0; transform:rotate(45deg); }
html[data-theme="dark"] .check-row input[type="checkbox"]:checked::after { border-color:#091311; }
.check-row input[type="checkbox"]:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
.check-text { min-width:0; flex:1; }
.check-item.done .check-text { color:var(--muted); }
.check-item .code-wrap { margin:0 14px 12px 48px; }
.check-count { display:inline-block; margin-top:12px; padding:4px 10px; border-radius:999px; border:1px solid var(--line); background:var(--surface-2); font-size:12px; font-weight:800; color:var(--muted); }
.practice .cmd-expect { margin-top:16px; }
.reveal { margin-top:14px; }
.reveal-panel { display:none; margin-top:10px; padding:14px; border-radius:12px; background:var(--surface); border:1px dashed color-mix(in srgb,var(--accent) 55%,var(--line)); }
.reveal.open .reveal-panel { display:block; animation:rise .25s both; }

/* ---- narrative, step-by-step commands, bilingual prompts ---- */
.prose p { margin:0 0 14px; font-size:16.5px; }
.prose p:last-of-type { margin-bottom:0; }
.prose ul.clean li { margin-bottom:6px; }
.block-lead { color:var(--muted); margin:0 0 16px; max-width:78ch; }
.block-outro { color:var(--muted); margin:14px 0 0; }
.diagram-notes { margin-top:16px; padding:14px 16px; border-radius:14px; background:var(--surface-2); border:1px solid var(--line); }
.diagram-notes strong { display:block; margin-bottom:6px; font-size:13px; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); }
.diagram-notes ul.clean { margin:0; }
.diagram-notes li { margin-bottom:5px; }

.commands .cmd-list { list-style:none; margin:18px 0 0; padding:0; display:flex; flex-direction:column; gap:14px; }
.cmd-step { display:grid; grid-template-columns:44px minmax(0,1fr); gap:14px; align-items:start; padding:16px; border:1px solid var(--line); border-radius:16px; background:var(--surface-2); }
.cmd-index { width:38px; height:38px; display:grid; place-items:center; border-radius:12px; background:linear-gradient(145deg,var(--primary),var(--primary-2)); color:#fff; font-weight:900; font-size:13px; }
.cmd-body { min-width:0; }
.cmd-body h3 { margin:2px 0 6px; font-size:16px; }
.cmd-body > p { margin:0 0 12px; color:var(--muted); }
.cmd-body .code-wrap { margin:0; }
.cmd-nocmd { margin:0 0 12px; font-size:13px; color:var(--muted); font-style:italic; }
.cmd-expect { margin-top:10px; padding:10px 12px; border-radius:11px; background:var(--surface); border:1px dashed color-mix(in srgb,var(--primary) 40%,var(--line)); font-size:14px; }
.cmd-expect strong { color:var(--primary); margin-right:6px; }

.prompt-block { border-color:color-mix(in srgb,var(--primary) 30%,var(--line)); }
.prompt-head { display:flex; flex-wrap:wrap; gap:14px; align-items:flex-start; justify-content:space-between; margin-bottom:10px; }
.prompt-heading h2 { margin:6px 0 0; }
.lang-switch { display:inline-flex; align-items:center; gap:4px; padding:4px; border:1px solid var(--line); border-radius:12px; background:var(--surface-2); }
.lang-switch-divider { width:1px; align-self:stretch; margin:3px 3px; background:var(--line); }
.lang-switch-label { font-size:11px; font-weight:800; letter-spacing:.06em; text-transform:uppercase; color:var(--muted); padding:0 6px; }
.lang-opt { border:1px solid transparent; background:transparent; border-radius:9px; padding:6px 12px; cursor:pointer; font-size:13px; font-weight:750; color:var(--muted); transition:.16s ease; }
.lang-opt:hover { color:var(--text); }
.lang-opt.active { background:var(--primary); border-color:transparent; color:#fff; }
html[data-theme="dark"] .lang-opt.active { color:#05201c; }
.prompt-after { margin-top:14px; padding:14px 16px; border-radius:14px; background:var(--surface-2); border:1px solid var(--line); }
.prompt-after strong { display:block; margin-bottom:6px; font-size:13px; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); }
.prompt-after ul.clean { margin:0; }
.prompt-after li { margin-bottom:5px; }
.prompt-hint { margin:12px 0 0; font-size:12.5px; color:var(--muted); }

.tool-tabs { display:inline-flex; flex-wrap:wrap; gap:4px; padding:4px; border:1px solid var(--line); border-radius:12px; background:var(--surface-2); margin:0 0 16px; }
.tool-tab { border:1px solid transparent; background:transparent; border-radius:9px; padding:7px 14px; cursor:pointer; font-size:13.5px; font-weight:750; color:var(--muted); transition:.16s ease; }
.tool-tab:hover { color:var(--text); }
.tool-tab.active { background:var(--primary); border-color:transparent; color:#fff; }
html[data-theme="dark"] .tool-tab.active { color:#05201c; }
.agent-panel[hidden] { display:none; }
.agent-panel .cmd-list { margin-top:0; }

@media (max-width: 780px) {
  .cmd-step { grid-template-columns:1fr; gap:10px; }
  .cmd-index { width:32px; height:32px; }
  .check-row { padding:11px 12px; }
  .check-item .code-wrap { margin:0 12px 12px; }
  .prompt-head { flex-direction:column; }
  .lang-switch { width:100%; justify-content:flex-end; flex-wrap:wrap; }
  .lang-switch-compact { width:auto; }
  .code-head { flex-wrap:wrap; }
  .tool-tabs { width:100%; }
  .tool-tab { flex:1; text-align:center; }
}

.checkpoint { background:linear-gradient(145deg,var(--surface),var(--primary-soft)); }
.options { display:flex; flex-direction:column; gap:8px; margin-top:14px; }
.option { display:flex; gap:10px; align-items:flex-start; border:1px solid var(--line); border-radius:12px; padding:11px; cursor:pointer; background:var(--surface); }
.option:hover { border-color:var(--primary); }
.option input { margin-top:5px; }
.quiz-btn { margin-top:14px; }
.check-result { display:none; margin-top:12px; padding:10px 12px; border-radius:10px; font-weight:700; }
.check-result.show { display:block; }
.check-result.good { background:color-mix(in srgb,var(--success) 14%,var(--surface)); color:var(--success); }
.check-result.bad { background:color-mix(in srgb,var(--danger) 12%,var(--surface)); color:var(--danger); }

.wrapup { background:var(--surface-2); }
.wrapup-list { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; padding:0; list-style:none; }
.wrapup-list li { padding:10px 12px; background:var(--surface); border:1px solid var(--line); border-radius:11px; }
.lesson-actions { display:flex; justify-content:space-between; gap:12px; margin-top:28px; align-items:center; flex-wrap:wrap; }
.complete-btn.done { background:var(--success); border-color:transparent; color:#fff; }

.capstone-steps { display:flex; flex-direction:column; gap:12px; }
.capstone-step { border:1px solid var(--line); border-radius:15px; overflow:hidden; background:var(--surface); }
.capstone-step summary { cursor:pointer; list-style:none; display:flex; align-items:center; justify-content:space-between; gap:14px; padding:15px 17px; font-weight:850; }
.capstone-step summary::-webkit-details-marker { display:none; }
.capstone-step summary::after { content:'+'; font-size:20px; color:var(--primary); }
.capstone-step[open] summary::after { content:'–'; }
.capstone-step .inside { border-top:1px solid var(--line); padding:16px 17px; color:var(--muted); }
.capstone-guide { margin:12px 0 0; }
.capstone-guide .cmd-step { grid-template-columns:34px minmax(0,1fr); gap:12px; padding:12px 14px; }
.capstone-guide .cmd-index { width:30px; height:30px; border-radius:9px; font-size:12px; }
.capstone-guide .cmd-body > p { margin:0; color:var(--text); }

.final-summary { border-radius:30px; background:linear-gradient(145deg,color-mix(in srgb,var(--primary-soft) 90%,var(--surface)),var(--surface)); border:1px solid var(--line); padding:34px; }
.skill-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:10px; margin-top:20px; }
.skill { padding:14px; border-radius:13px; background:var(--surface); border:1px solid var(--line); }

/* ---- certificate ---- */
.cert-frame { position:relative; display:grid; place-items:center; aspect-ratio:2000 / 1414; border-radius:var(--radius-sm); border:1px solid var(--line); background:var(--surface-2); overflow:hidden; }
.cert-image { display:block; width:100%; height:auto; }
.cert-status { margin:0; color:var(--muted); font-weight:650; }
.cert-actions { display:flex; flex-wrap:wrap; gap:10px; margin-top:18px; }
.block .cert-actions a.btn { color:var(--text); font-weight:750; text-decoration:none; }
.cert-actions .btn:disabled { opacity:.55; cursor:not-allowed; transform:none; box-shadow:none; }
.cert-meta { display:flex; flex-wrap:wrap; gap:10px 32px; margin:20px 0 0; }
.cert-meta dt { font-size:12px; font-weight:800; letter-spacing:.06em; text-transform:uppercase; color:var(--muted); }
.cert-meta dd { margin:4px 0 0; font-weight:700; }
.cert-note { margin:12px 0 0; font-size:14px; color:var(--muted); }
.cert-locked .progress-track { margin:6px 0 22px; }
.cert-locked h2 { font-size:18px; margin-bottom:10px; }
.cert-locked a.lesson-link { color:var(--muted); font-weight:inherit; text-decoration:none; }
.cert-locked a.lesson-link:hover { color:var(--text); }
.cert-form { display:grid; gap:8px; max-width:520px; }
.cert-form[hidden] { display:none; }
.cert-form label { font-weight:750; }
#certName { padding:12px 14px; border:1px solid var(--line); border-radius:13px; background:var(--surface); color:var(--text); font:inherit; font-size:17px; outline:none; transition:border-color .18s ease, box-shadow .18s ease; }
#certName:focus { border-color:var(--primary); box-shadow:0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
#certName[aria-invalid="true"] { border-color:var(--danger); }
#certName::placeholder { color:var(--muted); }
.cert-hint { margin:0 0 8px; font-size:13px; color:var(--muted); }
.cert-error { margin:0; font-size:13px; font-weight:700; color:var(--danger); }
.cert-confirm-name { font-size:24px; font-weight:800; margin:4px 0 10px; overflow-wrap:anywhere; }
#certPrint { display:none; }
@media print {
  body.print-cert { background:#fff !important; }
  body.print-cert > *:not(#certPrint) { display:none !important; }
  body.print-cert #certPrint { display:block; }
  body.print-cert #certPrint img { display:block; width:100%; max-height:100vh; object-fit:contain; }
}
@media (max-width: 780px) {
  .cert-actions .btn { flex:1 1 100%; }
}

/* ---- glossary ---- */
.glossary-toolbar { display:flex; flex-wrap:wrap; align-items:center; gap:10px 16px; margin-top:26px; }
#glossarySearch { flex:1 1 280px; max-width:440px; padding:11px 14px; border:1px solid var(--line); border-radius:13px; background:var(--surface); color:var(--text); outline:none; transition:border-color .18s ease, box-shadow .18s ease; }
#glossarySearch:focus { border-color:var(--primary); box-shadow:0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
#glossarySearch::placeholder { color:var(--muted); }
.glossary-count { margin:0; font-size:13px; color:var(--muted); font-weight:650; }
.glossary-group h2 { margin-bottom:16px; }
.glossary-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; margin:0; }
.glossary-item { padding:13px 15px; border:1px solid var(--line); border-radius:13px; background:var(--surface-2); }
.glossary-item dt { display:flex; align-items:center; flex-wrap:wrap; gap:8px; font-weight:800; font-size:15px; letter-spacing:-.01em; }
.glossary-alias { font-size:11.5px; font-weight:750; color:color-mix(in srgb,var(--primary) 82%,var(--text)); background:var(--primary-soft); padding:2px 9px; border-radius:999px; }
.glossary-item dd { margin:6px 0 0; font-size:14px; color:var(--muted); line-height:1.65; }
.glossary-item dd .inline-code { font-size:.86em; }
.glossary-empty { text-align:center; color:var(--muted); font-weight:650; }
@media (max-width: 780px) {
  .glossary-grid { grid-template-columns:1fr; }
}

.toast { position:fixed; right:20px; bottom:20px; z-index:100; padding:11px 14px; border-radius:12px; background:var(--text); color:var(--bg); box-shadow:var(--shadow); opacity:0; transform:translateY(10px); pointer-events:none; transition:.2s ease; }
.toast.show { opacity:1; transform:none; }

@media (max-width: 980px) {
  :root { --sidebar:280px; }
  .hero-inner { grid-template-columns:minmax(0,1fr); gap:28px; }
  .hero-panel { max-width:680px; transform:none; }
  .grid-3 { grid-template-columns:1fr 1fr; }
}

@media (max-width: 780px) {
  .layout { display:block; }
  .sidebar { position:fixed; z-index:60; inset:70px auto 0 0; width:min(86vw,340px); height:auto; transform:translateX(-104%); transition:transform .25s ease; box-shadow:var(--shadow); background:var(--surface-2); backdrop-filter:none; }
  body.menu-open .sidebar { transform:translateX(0); }
  .mobile-menu { display:grid; }
  .content { width:min(100% - 28px,1040px); padding-top:28px; }
  .lesson-goals,.two-col,.wrapup-list,.skill-grid { grid-template-columns:1fr; }
  /* ซ่อนตัวหลักเฉพาะกล่องที่มีตัวแปรมือถือ กล่องธรรมดายังแสดงไดอะแกรมปกติ */
  .diagram.has-mobile-diagram .mermaid:not(.mermaid-mobile) { display:none; }
  .diagram .mermaid-mobile { display:flex; min-width:0; }
  .grid-3 { grid-template-columns:1fr; }
  .hero-inner { width:min(100% - 28px,1180px); padding:42px 0; }
  .hero h1 { font-size:clamp(42px,13vw,66px); }
  .topbar { padding:0 12px; }
  /* มือถือ: ปุ่มบทเรียนเรียงแนวตั้ง ปุ่มละบรรทัดเต็มความกว้าง */
  .lesson-actions { flex-direction:column; align-items:stretch; gap:10px; }
  .lesson-actions > div { width:100%; }
  .lesson-actions .btn { width:100%; }
  /* มือถือ: แผงควบคุมการฟังกินเต็มแถว แถบความคืบหน้ายืดตามพื้นที่เหลือ */
  .speak-panel { width:100%; }
  .speak-progress { flex:1 1 120px; width:auto; }
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { animation-duration:.001ms !important; animation-iteration-count:1 !important; transition-duration:.001ms !important; scroll-behavior:auto !important; }
}
