/* ==========================================================================
   FastFit — Design System (เหลือง · ขาว · เทา)
   ========================================================================== */

:root {
  --y-50: #fffae6; --y-100: #fff3c2; --y-200: #ffe68a; --y-300: #ffd84d; --y-400: #ffcc1a;
  --y-500: #ffc400; --y-600: #e6ac00; --y-700: #b88600;
  --g-0: #ffffff; --g-25: #fafbfc; --g-50: #f5f6f8; --g-100: #eef0f3; --g-200: #e2e5ea;
  --g-300: #c9ced6; --g-400: #9aa1ad; --g-500: #6b7280; --g-600: #4b5261; --g-700: #343944;
  --g-800: #22262d; --g-850: #1a1d23; --g-900: #14161a; --g-950: #0e0f12;

  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f5f6f8;
  --surface-3: #eceef2;
  --text: #111318;
  --text-2: #4b5261;
  --text-3: #858d9b;
  --border: #e3e6eb;
  --border-2: #d3d8df;
  --brand: #ffc400;
  --brand-2: #ffd84d;
  --brand-ink: #111318;
  --brand-soft: #fff5cf;
  --brand-strong: #d89f00;
  --ink: #0f1115;
  --ink-2: #1a1d23;
  --ink-3: #262a31;
  --success: #16a34a;
  --danger: #e5484d;
  --warn: #f59e0b;
  --info: #3b82f6;
  --overlay: rgba(10, 11, 14, .55);
  --stage-a: #ffffff;
  --stage-b: #e7e9ee;
  --muscle: #dde0e5;
  --mus-sec: #3b9eff;        /* กล้ามเนื้อรอง (ฟ้า) คู่กับกล้ามหลักสีเหลืองแบรนด์ */
  --muscle-stroke: #1d2026;
  --skin: #262a31;
  --skin-stroke: #3b4049;
  --bm-base: #262a31;
  --bm-edge: #3b4049;
  --bm-hi: #ffffff;
  --bm-lo: #a2a8b2;
  --bm-lite-hi: #f4f5f7;
  --bm-lite-lo: #b7bcc4;
  --bm-cloth: #15171b;

  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 8px rgba(16, 24, 40, .05);
  --shadow: 0 2px 6px rgba(16, 24, 40, .05), 0 12px 28px -8px rgba(16, 24, 40, .12);
  --shadow-lg: 0 10px 30px -6px rgba(16, 24, 40, .18), 0 30px 60px -20px rgba(16, 24, 40, .25);
  --glow: 0 10px 30px -8px rgba(255, 196, 0, .55);

  --r-xs: 8px; --r-sm: 10px; --r: 16px; --r-lg: 22px; --r-xl: 28px; --r-full: 999px;
  --font-display: 'Kanit', 'Noto Sans SC', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'IBM Plex Sans Thai', 'Noto Sans SC', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --header-h: 68px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --container: 1720px;                          /* ความกว้างเนื้อหาสูงสุด (เดิม 1240 — จอใหญ่ดูโล่ง) */
  --gutter: clamp(16px, 3vw, 56px);             /* ระยะขอบซ้าย-ขวา ปรับตามความกว้างจอ */
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0e0f12;
  --surface: #16181d;
  --surface-2: #1c1f25;
  --surface-3: #242830;
  --text: #f2f3f5;
  --text-2: #b4bac5;
  --text-3: #7c8492;
  --border: #252930;
  --border-2: #31363f;
  --brand-soft: rgba(255, 196, 0, .12);
  --overlay: rgba(0, 0, 0, .62);
  --stage-a: #252932;
  --stage-b: #111317;
  --muscle: #d3d7dd;
  --muscle-stroke: #0c0e11;
  --skin: #15171b;
  --skin-stroke: #8f96a1;
  --bm-base: #15171b;
  --bm-edge: #8f96a1;
  --bm-hi: #ffffff;
  --bm-lo: #8d939d;
  --bm-lite-hi: #e9ebee;
  --bm-lite-lo: #9aa0a9;
  --bm-cloth: #0a0b0d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .25);
  --shadow: 0 2px 6px rgba(0, 0, 0, .3), 0 12px 28px -8px rgba(0, 0, 0, .5);
  --shadow-lg: 0 10px 30px -6px rgba(0, 0, 0, .5), 0 30px 60px -20px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

html[lang="zh-CN"] {
  --font-display: 'Noto Sans SC', 'Kanit', system-ui, sans-serif;
  --font-body: 'Noto Sans SC', 'IBM Plex Sans Thai', system-ui, sans-serif;
}

/* ---------- Reset / Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 15.5px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
img, svg, video, canvas { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; opacity: .55; }
h1, h2, h3, h4, h5 { font-family: var(--font-display); margin: 0; line-height: 1.2; letter-spacing: -.005em; font-weight: 600; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }
::selection { background: var(--brand); color: var(--brand-ink); }
:focus-visible { outline: 2.5px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.ic { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--brand); color: var(--brand-ink); padding: 8px 14px; border-radius: 10px; }
.skip-link:focus { left: 8px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 var(--gutter); }
.main { min-height: 60vh; padding-bottom: 40px; outline: none; }
.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.nowrap { white-space: nowrap; }
.linklike { color: inherit; text-align: left; }
.linklike:hover { color: var(--brand-strong); }
.divider { height: 1px; background: var(--border); margin: 20px 0; border: 0; }

/* ---------- Beta bar ---------- */
.beta-bar { background: var(--ink); color: #d6dae1; font-size: 13px; }
.beta-bar__in { display: flex; align-items: center; gap: 10px; min-height: 38px; padding-top: 6px; padding-bottom: 6px; }
.beta-bar__badge { background: var(--brand); color: var(--ink); font: 700 11px/1 var(--font-display); letter-spacing: .08em; padding: 4px 7px; border-radius: 6px; }
.beta-bar__text { flex: 1; min-width: 0; }
.beta-bar__link { display: inline-flex; align-items: center; gap: 6px; color: var(--brand); font-weight: 600; white-space: nowrap; }
.beta-bar__close { color: #8b93a1; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; }
.beta-bar__close:hover { color: #fff; background: rgba(255,255,255,.08); }
/* ประกาศจากหลังบ้าน (admin/site.php) */
.announce { font-size: 14px; color: #fff; background: linear-gradient(90deg, #1d4ed8, #2563eb); }
.announce--success { background: linear-gradient(90deg, #15803d, #16a34a); }
.announce--warn { background: linear-gradient(90deg, #b45309, #d97706); }
.announce__in { display: flex; align-items: center; gap: 10px; min-height: 42px; padding-top: 7px; padding-bottom: 7px; }
.announce__ic .ic { width: 18px; height: 18px; }
.announce__text { flex: 1; min-width: 0; font-weight: 500; line-height: 1.4; }
.announce__link { display: inline-flex; align-items: center; gap: 4px; color: #fff; font-weight: 600; white-space: nowrap; text-decoration: underline; text-underline-offset: 3px; }
.announce__link .ic { width: 15px; height: 15px; }
.announce__close { color: rgba(255,255,255,.75); width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; flex: none; }
.announce__close:hover { color: #fff; background: rgba(255,255,255,.15); }
.is-embedded .fab-feedback { display: none !important; }
.tester-code span { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .06em; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-t);
  transition: box-shadow .25s;
}
.topbar.is-scrolled { box-shadow: 0 6px 20px -12px rgba(16,24,40,.35); }
.topbar__in { height: var(--header-h); display: flex; align-items: center; gap: 18px; }
.brand { display: inline-flex; align-items: center; gap: 10px; flex: none; }
.brand__mark svg, .brand__mark img { width: 34px; height: 34px; border-radius: 9px; filter: drop-shadow(0 4px 10px rgba(255,196,0,.3)); }
.brand__name { display: inline-block; font: 700 22px/1 var(--font-display); letter-spacing: -.035em; color: var(--text); transform: skewX(-10deg); padding-right: 2px; }
.brand__slogan { display: block; margin: 8px 0 2px; font: 600 11px/1.3 var(--font-display); letter-spacing: .16em; text-transform: uppercase; color: var(--text-3); }
.brand__name b { color: var(--brand); font-weight: 700; }
.brand__beta { font: 700 10px/1 var(--font-display); letter-spacing: .08em; color: var(--text-2); border: 1px solid var(--border-2); padding: 4px 6px; border-radius: 6px; }
.mainnav { display: flex; align-items: center; gap: 2px; margin: 0 auto; }
.mainnav__link { display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 13px; border-radius: 12px; color: var(--text-2); font: 500 15px/1 var(--font-display); white-space: nowrap; transition: background .2s, color .2s; }
.mainnav__link .ic { width: 18px; height: 18px; }
.mainnav__link:hover { color: var(--text); background: var(--surface-2); }
.mainnav__link.is-active { color: var(--text); background: var(--brand-soft); }
.mainnav__link.is-active .ic { color: var(--brand-strong); }
[data-theme="dark"] .mainnav__link.is-active .ic { color: var(--brand); }
.topbar__actions { display: flex; align-items: center; gap: 4px; flex: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-grid; place-items: center; color: var(--text-2); position: relative; transition: background .2s, color .2s, transform .12s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.is-active { color: var(--text); background: var(--brand-soft); }
.icon-btn .ic { width: 21px; height: 21px; }
.btn--login { margin-left: 6px; height: 40px; padding: 0 14px; border-radius: 12px; background: var(--ink); color: #fff; border: 0; }
[data-theme="dark"] .btn--login { background: var(--brand); color: var(--ink); }
.lang-menu { position: relative; }
.lang-menu__btn { width: auto; padding: 0 10px; gap: 5px; display: inline-flex; }
.lang-menu__code { font: 600 13px/1 var(--font-display); }
.lang-menu__pop { position: absolute; right: 0; top: calc(100% + 8px); min-width: 180px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; opacity: 0; visibility: hidden; transform: translateY(-6px) scale(.98); transform-origin: top right; transition: .18s var(--ease); z-index: 60; }
.lang-menu.is-open .lang-menu__pop { opacity: 1; visibility: visible; transform: none; }
.lang-menu__item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; font-weight: 500; }
.lang-menu__item:hover { background: var(--surface-2); }
.lang-menu__item.is-active { color: var(--text); }
.lang-menu__item .ic { margin-left: auto; color: var(--brand-strong); }
.lang-menu__flag { width: 30px; height: 22px; display: grid; place-items: center; border-radius: 6px; background: var(--surface-3); font: 700 11px/1 var(--font-display); }

/* ---------- Tab bar (มือถือ) ---------- */
.tabbar { display: none; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 40px; }
.footer__in { display: grid; grid-template-columns: 1.2fr 2fr; gap: 40px; padding-top: 40px; padding-bottom: 28px; }
.footer__brand p { color: var(--text-3); margin-top: 10px; max-width: 360px; font-size: 14px; }
.footer__cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.footer__cols h4 { font-size: 14px; color: var(--text); margin-bottom: 12px; }
.footer__cols a, .footer__cols .linklike { display: block; color: var(--text-3); font-size: 14px; padding: 4px 0; }
.footer__cols a:hover { color: var(--text); }
.footer__bottom { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-top: 16px; padding-bottom: 24px; border-top: 1px solid var(--border); color: var(--text-3); font-size: 12.5px; }
.footer__credit { margin-top: -12px; padding-bottom: 24px; color: var(--text-3); font-size: 11.5px; line-height: 1.5; }
.footer__credit a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.fab-feedback { position: fixed; right: 22px; bottom: 24px; z-index: 30; width: 52px; height: 52px; border-radius: 18px; background: var(--ink); color: var(--brand); display: grid; place-items: center; box-shadow: var(--shadow-lg); transition: transform .2s var(--ease); }
.fab-feedback:hover { transform: translateY(-2px) rotate(-4deg); }
.fab-feedback .ic { width: 24px; height: 24px; }

/* ---------- Typography helpers ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 28px 0 20px; flex-wrap: wrap; }
.page-title { font-size: clamp(26px, 3.2vw, 36px); font-weight: 600; }
.page-sub { color: var(--text-2); margin-top: 6px; max-width: 640px; }
.page-head__actions { display: flex; gap: 10px; flex-wrap: wrap; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font: 600 12.5px/1 var(--font-display); letter-spacing: .12em; text-transform: uppercase; color: var(--brand-strong); margin-bottom: 10px; }
[data-theme="dark"] .eyebrow { color: var(--brand); }
.eyebrow::before { content: ''; width: 18px; height: 3px; border-radius: 3px; background: var(--brand); }
.sec { margin-top: 44px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.sec-title { font-size: clamp(20px, 2.2vw, 24px); display: flex; align-items: center; gap: 10px; }
.sec-title .ic { color: var(--brand-strong); width: 24px; height: 24px; }
[data-theme="dark"] .sec-title .ic { color: var(--brand); }
.sec-sub { color: var(--text-3); font-size: 14px; margin-top: 4px; }
.sec-link { display: inline-flex; align-items: center; gap: 6px; font: 500 14.5px/1 var(--font-display); color: var(--text-2); white-space: nowrap; }
.sec-link:hover { color: var(--text); }
.sec-link .ic { width: 16px; height: 16px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 20px; border-radius: 14px; border: 1px solid transparent; font: 500 15.5px/1 var(--font-display); letter-spacing: .01em; white-space: nowrap; transition: transform .12s var(--ease), background .2s, box-shadow .2s, color .2s, border-color .2s; user-select: none; }
.btn .ic { width: 19px; height: 19px; }
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--brand); color: var(--brand-ink); box-shadow: 0 8px 20px -10px rgba(255,196,0,.8), inset 0 -2px 0 rgba(0,0,0,.08); }
.btn--primary:hover { background: var(--y-400); box-shadow: var(--glow); }
.btn--dark { background: var(--ink); color: #fff; }
.btn--dark:hover { background: var(--ink-2); }
[data-theme="dark"] .btn--dark { background: var(--surface-3); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border-2); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--soft { background: var(--surface-2); color: var(--text); }
.btn--soft:hover { background: var(--surface-3); }
.btn--danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn--sm { height: 36px; padding: 0 13px; border-radius: 11px; font-size: 14px; }
.btn--sm .ic { width: 17px; height: 17px; }
.btn--lg { height: 54px; padding: 0 26px; border-radius: 16px; font-size: 17px; }
.btn--block { width: 100%; }
.btn--icon { width: 46px; padding: 0; }
.btn--icon.btn--sm { width: 36px; }
.btn.is-loading { pointer-events: none; opacity: .75; }
.btn.is-loading::after { content: ''; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }

/* ---------- Chips / pills / badges ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips--scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; margin: 0 calc(-1 * var(--gutter)); padding-left: var(--gutter); padding-right: var(--gutter); scroll-padding: 0 var(--gutter); scroll-snap-type: x proximity;
  /* ชิปที่เลื่อนเข้าขอบค่อยๆ จางหาย (ไม่ขาดกึกกลางขอบ) */
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--gutter), #000 calc(100% - var(--gutter)), transparent 100%); mask-image: linear-gradient(90deg, transparent 0, #000 var(--gutter), #000 calc(100% - var(--gutter)), transparent 100%); }
.chips--scroll::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: var(--r-full); background: var(--surface); border: 1px solid var(--border); color: var(--text-2); font: 500 14.5px/1 var(--font-display); white-space: nowrap; scroll-snap-align: start; transition: background .18s, border-color .18s, color .18s, transform .12s; }
.chip .ic { width: 17px; height: 17px; }
.chip:hover { border-color: var(--border-2); color: var(--text); }
.chip:active { transform: scale(.96); }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip.is-on .ic { color: var(--brand); }
[data-theme="dark"] .chip.is-on { background: var(--brand); border-color: var(--brand); color: var(--ink); }
[data-theme="dark"] .chip.is-on .ic { color: var(--ink); }
.chip__count { font-size: 12px; color: var(--text-3); }
.chip.is-on .chip__count { color: inherit; opacity: .7; }
.badge { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 8px; font: 600 12px/1 var(--font-display); background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge .ic { width: 14px; height: 14px; }
.badge--brand { background: var(--brand); color: var(--brand-ink); }
.badge--soft { background: var(--brand-soft); color: var(--brand-strong); }
[data-theme="dark"] .badge--soft { color: var(--brand); }
.badge--dark { background: var(--ink); color: #fff; }
.badge--glass { background: rgba(15,17,21,.62); color: #fff; backdrop-filter: blur(6px); }
.lvl { display: inline-flex; align-items: center; gap: 6px; font: 600 12px/1 var(--font-display); color: var(--text-2); }
.lvl__dots { display: inline-flex; gap: 2.5px; }
.lvl__dots i { width: 5px; height: 10px; border-radius: 2px; background: var(--border-2); }
.lvl__dots i.on { background: var(--brand); }
.lvl--glass { background: rgba(15,17,21,.6); color: #fff; padding: 6px 8px; border-radius: 8px; backdrop-filter: blur(6px); }
.lvl--glass .lvl__dots i { background: rgba(255,255,255,.28); }
.lvl--glass .lvl__dots i.on { background: var(--brand); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-xs); }
.card--pad { padding: 20px; }
.card--hover { transition: transform .2s var(--ease), box-shadow .2s, border-color .2s; }
.card--hover:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-2); }
.card-title { font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card-title .ic { color: var(--brand-strong); }
[data-theme="dark"] .card-title .ic { color: var(--brand); }

/* Exercise card */
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
/* แถวการ์ดแบบเลื่อน: การ์ดเต็มใบพอดีความกว้างทุกขนาดจอ (--per ใบต่อหน้า) + ปุ่ม < > ที่หัวแถว — initRails ใน app.js
   padding ซ้าย-ขวา 8px (≤ gap) ให้เงาการ์ดไม่โดนตัด โดยไม่เห็นเศษการ์ดใบข้างเคียง */
.rail { --per: 5; --gap: 16px; display: grid; grid-auto-flow: column; grid-auto-columns: calc((100% - (var(--per) - 1) * var(--gap)) / var(--per)); gap: var(--gap);
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scroll-padding: 0 8px; scrollbar-width: none; padding: 6px 8px 14px; margin: -6px -8px -14px; }
.rail::-webkit-scrollbar { display: none; }
.rail > * { scroll-snap-align: start; min-width: 0; }
.rail > .ex-card { content-visibility: visible; }   /* การ์ดที่ยังเลื่อนไม่ถึงต้องสูงจริง ไม่ใช่ 300px ประมาณการ (ไม่งั้นแถวยืดการ์ดที่เห็นจนมีช่องว่าง) */
.ex-row { --per: 6; }
@media (max-width: 1499px) { .ex-row { --per: 5; } }
@media (max-width: 1199px) { .ex-row { --per: 4; } }
@media (max-width: 899px) { .ex-row { --per: 3; --gap: 14px; } }
@media (max-width: 599px) { .ex-row { --per: 2; --gap: 12px; } }
.sec-head__end { display: flex; align-items: center; gap: 14px; flex: none; }
.rail-nav { display: inline-flex; gap: 6px; }
.rail-nav[hidden] { display: none; }
.rail-nav button { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); color: var(--text); box-shadow: var(--shadow-xs); transition: border-color .15s, color .15s, opacity .15s, transform .12s; }
.rail-nav button:hover:not(:disabled) { border-color: var(--brand); color: var(--brand-strong); }
[data-theme="dark"] .rail-nav button:hover:not(:disabled) { color: var(--brand); }
.rail-nav button:active:not(:disabled) { transform: scale(.94); }
.rail-nav button:disabled { opacity: .35; cursor: default; box-shadow: none; }
.rail-nav .ic { width: 19px; height: 19px; stroke-width: 2.2; }
.ex-card { position: relative; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; overflow: hidden; transition: transform .22s var(--ease), box-shadow .22s, border-color .22s; content-visibility: auto; contain-intrinsic-size: 300px; }
.ex-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--border-2); }
.ex-card:active { transform: scale(.985); }
.ex-card__media { position: relative; aspect-ratio: 1 / .92; background: radial-gradient(120% 90% at 50% 25%, var(--stage-a), var(--stage-b)); overflow: hidden; }
.ex-card__media img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s var(--ease), opacity .3s; }
.ex-card__media img[data-loading] { opacity: 0; }
.ex-card:hover .ex-card__media img { transform: scale(1.05); }
.ex-card__media .thumb-ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); }
.ex-card__media .thumb-ph .ic { width: 42px; height: 42px; opacity: .35; }
.ex-card__tl { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; }
.ex-card__add { position: absolute; right: 10px; top: 10px; width: 36px; height: 36px; border-radius: 12px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; box-shadow: 0 6px 16px -6px rgba(0,0,0,.4); transition: transform .15s var(--ease); z-index: 2; }
.ex-card__add:hover { transform: scale(1.08); }
.ex-card__add.is-added { background: var(--ink); color: var(--brand); }
.ex-card__add .ic { width: 19px; height: 19px; stroke-width: 2.2; }
.ex-card__body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.ex-card__name { font: 500 15.5px/1.3 var(--font-display); color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ex-card__en { font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-card__meta { display: flex; align-items: center; gap: 6px; margin-top: auto; padding-top: 8px; font-size: 12.5px; color: var(--text-2); min-width: 0; }
.ex-card__meta > span:first-child { flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-card__meta > span:last-child { flex: none; white-space: nowrap; }
.ex-card__meta .dot, .ex-card__meta .ic { flex: none; }
.ex-card__meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-3); }
.ex-card__meta .ic { width: 15px; height: 15px; color: var(--text-3); }
.ex-card--compact { flex-direction: row; align-items: center; border-radius: 16px; }
.ex-card--compact .ex-card__media { width: 84px; min-width: 84px; aspect-ratio: 1; }
.ex-card--compact .ex-card__body { padding: 10px 12px; }
.ex-card.is-selected { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field + .field { margin-top: 14px; }
.label { font: 500 14px/1.2 var(--font-display); color: var(--text-2); }
.input, .select, .textarea { width: 100%; height: 48px; padding: 0 14px; border-radius: 13px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); font-size: 16px; transition: border-color .18s, box-shadow .18s; appearance: none; }
.textarea { height: auto; min-height: 110px; padding: 12px 14px; resize: vertical; line-height: 1.5; }
.select { padding-right: 40px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a92a0' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 22%, transparent); }
.input-icon { position: relative; }
.input-icon > .ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); width: 19px; height: 19px; pointer-events: none; }
.input-icon .input { padding-left: 44px; }
.hint { font-size: 13px; color: var(--text-3); }
.stepper-input { display: inline-flex; align-items: center; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border); height: 40px; }
.stepper-input button { width: 36px; height: 38px; display: grid; place-items: center; color: var(--text-2); }
.stepper-input button:hover { color: var(--text); }
.stepper-input button .ic { width: 16px; height: 16px; }
.stepper-input input { width: 46px; text-align: center; border: 0; background: transparent; font: 600 15px/1 var(--font-display); font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.stepper-input input::-webkit-outer-spin-button, .stepper-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-input input:focus { outline: none; }

/* Toggle switch */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 30px; background: var(--border-2); transition: background .2s; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); transition: transform .22s var(--ease); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2.5px solid var(--brand); outline-offset: 2px; }

/* Segmented control */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 4px; gap: 2px; }
.seg__btn { height: 36px; padding: 0 14px; border-radius: 10px; display: inline-flex; align-items: center; gap: 7px; font: 500 14px/1 var(--font-display); color: var(--text-2); white-space: nowrap; transition: background .18s, color .18s, box-shadow .18s; }
.seg__btn .ic { width: 17px; height: 17px; }
.seg__btn:hover { color: var(--text); }
.seg__btn.is-on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .seg__btn.is-on { background: var(--surface-3); }
.seg--dark { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.08); }
.seg--dark .seg__btn { color: #aab1bd; }
.seg--dark .seg__btn.is-on { background: var(--brand); color: var(--ink); }
.seg--block { display: flex; }
.seg--block .seg__btn { flex: 1; justify-content: center; }

/* Range */
.range { width: 100%; appearance: none; height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--brand) var(--p, 50%), var(--border-2) var(--p, 50%)); outline: none; }
.range::-webkit-slider-thumb { appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--brand); box-shadow: 0 2px 8px rgba(0,0,0,.2); cursor: pointer; }
.range::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--brand); cursor: pointer; }

/* ---------- Modal / bottom sheet ---------- */
.modal { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal__backdrop { position: absolute; inset: 0; background: var(--overlay); backdrop-filter: blur(3px); opacity: 0; transition: opacity .25s; }
.modal__panel { position: relative; width: 100%; max-width: 520px; max-height: min(86dvh, 820px); display: flex; flex-direction: column; background: var(--surface); border-radius: 24px; box-shadow: var(--shadow-lg); transform: translateY(16px) scale(.98); opacity: 0; transition: transform .32s var(--ease), opacity .22s; overflow: hidden; }
.modal--wide .modal__panel { max-width: 760px; }
.modal.is-open .modal__backdrop { opacity: 1; }
.modal.is-open .modal__panel { transform: none; opacity: 1; }
.modal__handle { display: none; }
.modal__head { display: flex; align-items: center; gap: 12px; padding: 20px 22px 14px; }
.modal__title { font-size: 19px; flex: 1; }
.modal__close { margin-right: -8px; }
.modal__body { padding: 4px 22px 22px; overflow-y: auto; overscroll-behavior: contain; }
.modal__foot { padding: 14px 22px calc(18px + var(--safe-b)); border-top: 1px solid var(--border); display: flex; gap: 10px; }
.modal__foot .btn { flex: 1; }
.modal__hero { padding: 26px 24px 10px; text-align: center; }
.modal__hero-ic { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 20px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); }
.modal__hero-ic .ic { width: 32px; height: 32px; }
[data-theme="dark"] .modal__hero-ic { color: var(--brand); }

/* ---------- Toast ---------- */
.toast-root { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 440px); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; background: var(--ink); color: #fff; padding: 12px 14px 12px 16px; border-radius: 16px; box-shadow: var(--shadow-lg); font-size: 14.5px; width: 100%; animation: toastIn .35s var(--ease); }
.toast .ic { width: 20px; height: 20px; color: var(--brand); flex: none; }
.toast__msg { flex: 1; }
.toast__action { color: var(--brand); font: 600 14px/1 var(--font-display); padding: 6px 8px; border-radius: 8px; }
.toast--error .ic { color: #ff8a8e; }
.toast.is-out { animation: toastOut .25s forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px) scale(.97); } }

/* ---------- Skeleton / empty ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: shimmer 1.3s infinite linear; border-radius: 12px; }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 48px 20px; }
.empty__ic { width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 24px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); }
.empty__ic .ic { width: 36px; height: 36px; }
[data-theme="dark"] .empty__ic { color: var(--brand); }
.empty h3 { font-size: 20px; }
.empty p { color: var(--text-3); margin: 8px auto 20px; max-width: 420px; }
.empty__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; height: 46px; padding: 0 14px; font: 500 15px/1 var(--font-display); color: var(--text-3); white-space: nowrap; display: inline-flex; align-items: center; gap: 7px; }
.tab:hover { color: var(--text); }
.tab.is-on { color: var(--text); }
.tab.is-on::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--brand); }
.tab .ic { width: 18px; height: 18px; }
.tab__count { font-size: 12px; background: var(--surface-3); padding: 2px 7px; border-radius: 10px; color: var(--text-2); }

/* ---------- Progress ring ---------- */
.ring { --size: 120px; --stroke: 9px; width: var(--size); height: var(--size); position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: var(--stroke); stroke-linecap: round; }
.ring .ring__bg { stroke: var(--surface-3); }
.ring .ring__fg { stroke: var(--brand); transition: stroke-dashoffset .35s linear; }
.ring__label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }

/* ---------- Search overlay ---------- */
.search-ov { position: fixed; inset: 0; z-index: 95; display: flex; justify-content: center; align-items: flex-start; padding: 70px 16px 16px; }
.search-ov__backdrop { position: absolute; inset: 0; background: var(--overlay); backdrop-filter: blur(4px); }
.search-ov__panel { position: relative; width: 100%; max-width: 680px; background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-lg); overflow: hidden; animation: popIn .25s var(--ease); }
.search-ov__bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--border); }
.search-ov__bar .ic { color: var(--text-3); width: 22px; height: 22px; }
.search-ov__bar input { flex: 1; height: 50px; border: 0; background: transparent; font-size: 18px; outline: none; }
.search-ov__results { max-height: min(62dvh, 560px); overflow-y: auto; padding: 8px; }
.search-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 14px; }
.search-item:hover, .search-item.is-active { background: var(--surface-2); }
.search-item__thumb { width: 52px; height: 52px; border-radius: 12px; overflow: hidden; background: radial-gradient(circle at 50% 30%, var(--stage-a), var(--stage-b)); flex: none; }
.search-item__thumb img { width: 100%; height: 100%; object-fit: cover; }
.search-item__name { font: 500 15px/1.3 var(--font-display); }
.search-item__sub { font-size: 12.5px; color: var(--text-3); }
.search-ov__hint { padding: 26px; text-align: center; color: var(--text-3); font-size: 14px; }
@keyframes popIn { from { opacity: 0; transform: translateY(-10px) scale(.98); } }

/* ---------- Flow stepper (workflow) ---------- */
.flow { display: flex; align-items: center; gap: 0; counter-reset: flow; overflow-x: auto; scrollbar-width: none; }
.flow::-webkit-scrollbar { display: none; }
.flow__step { display: flex; align-items: center; gap: 10px; flex: 1; min-width: max-content; color: var(--text-3); font: 500 14.5px/1.2 var(--font-display); }
.flow__num { width: 34px; height: 34px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); font-weight: 600; flex: none; transition: .25s; }
.flow__num .ic { width: 18px; height: 18px; stroke-width: 2.4; }
.flow__line { flex: 1; height: 2px; min-width: 18px; margin: 0 12px; background: var(--border-2); border-radius: 2px; }
.flow__step.is-on { color: var(--text); }
.flow__step.is-on .flow__num { background: var(--brand); color: var(--brand-ink); box-shadow: 0 6px 16px -6px rgba(255,196,0,.8); }
.flow__step.is-done .flow__num { background: var(--ink); color: var(--brand); }
[data-theme="dark"] .flow__step.is-done .flow__num { background: var(--surface-3); }
.flow__step.is-done + .flow__line, .flow__line.is-done { background: var(--brand); }
button.flow__step { background: none; }

/* ---------- Anatomy / body map (SVG) ---------- */
.bodymap { position: relative; }
.bodymap svg { width: 100%; height: auto; overflow: visible; }
.bodymap .bm-skin { fill: var(--bm-base); }
/* เส้นรอบตัว/มือ/ชุดกีฬา/ผม เป็นแค่ภาพประกอบ — ต้องไม่ขวางการแตะเลือกกล้ามเนื้อ */
.bodymap .bm-outline { fill: none; stroke: var(--bm-edge); stroke-width: 1.2; stroke-linejoin: round; pointer-events: none; }
.bodymap .bm-lite { fill: url(#bmLite); stroke: var(--muscle-stroke); stroke-width: 1.2; pointer-events: none; }
.bodymap .bm-cloth { fill: var(--bm-cloth); stroke: var(--bm-edge); stroke-opacity: .3; stroke-width: .8; pointer-events: none; }
/* เส้นรายละเอียด (ซิกแพ็ค/ร่องกลาง) เป็นแค่ลวดลาย ต้องไม่ขวางการแตะเลือกกล้ามเนื้อ */
.bodymap .bm-detail { fill: none; stroke: var(--skin-stroke); stroke-width: .9; opacity: .8; pointer-events: none; }
.bodymap .bm-hair { fill: var(--bm-cloth); stroke: var(--bm-edge); stroke-width: .8; pointer-events: none; }
.bodymap .bm-shadow { fill: rgba(0, 0, 0, .18); }
.bodymap .m { cursor: pointer; }
.bodymap .m path, .bodymap .m ellipse, .bodymap .m polygon { fill: url(#bmMuscle); stroke: var(--muscle-stroke); stroke-width: 1.5; stroke-linejoin: round; transition: fill .2s, stroke .2s, filter .2s; }
.bodymap .m:hover path, .bodymap .m:hover ellipse, .bodymap .m:hover polygon, .bodymap .m.is-hover path { fill: url(#bmHover); stroke: var(--y-600); }
.bodymap .m.is-sec path, .bodymap .m.is-sec ellipse, .bodymap .m.is-sec polygon { fill: url(#bmSecondary); stroke: #1f6fd1; }
.bodymap .m.is-on path, .bodymap .m.is-on ellipse, .bodymap .m.is-on polygon { fill: url(#bmActive); stroke: #b88600; filter: url(#bmGlow); }
.bodymap .m:focus-visible { outline: none; }
.bodymap .m:focus-visible path { stroke: var(--brand); stroke-width: 2.2; }
.bodymap.is-readonly .m { cursor: default; }
.bodymap__label { font: 600 12px/1 var(--font-display); fill: var(--text-3); letter-spacing: .08em; text-transform: uppercase; }
.bm-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font: 500 13px/1.2 var(--font-display); padding: 7px 10px; border-radius: 10px; white-space: nowrap; transform: translate(-50%, calc(-100% - 12px)); box-shadow: var(--shadow); z-index: 5; opacity: 0; transition: opacity .15s; }
.bm-tip.is-on { opacity: 1; }
.bm-tip b { color: var(--brand); font-weight: 600; }

/* ---------- 3D viewer ---------- */
.viewer { position: relative; border-radius: var(--r-xl); overflow: hidden; background: radial-gradient(120% 90% at 50% 20%, var(--stage-a) 0%, var(--stage-b) 100%); isolation: isolate; }
.viewer::before { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(135deg, transparent 0 22px, rgba(128,134,146,.05) 22px 23px); pointer-events: none; z-index: 0; }
.viewer .fig-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; z-index: 1; touch-action: none; cursor: grab; }
.viewer .fig-canvas:active { cursor: grabbing; }
.viewer__stage { position: relative; aspect-ratio: 4 / 3.4; }
.viewer__loading { position: absolute; inset: 0; display: grid; place-items: center; z-index: 2; color: var(--text-3); transition: opacity .4s; }
.viewer__loading .spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--border-2); border-top-color: var(--brand); animation: spin .8s linear infinite; }
.viewer.is-ready .viewer__loading { opacity: 0; pointer-events: none; }
.viewer__tl, .viewer__tr { position: absolute; top: 14px; z-index: 3; display: flex; gap: 8px; }
.viewer__tl { left: 14px; }
.viewer__tr { right: 14px; }
.viewer__hint { position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%); z-index: 3; font-size: 12.5px; color: var(--text-3); display: flex; align-items: center; gap: 6px; background: color-mix(in srgb, var(--surface) 70%, transparent); padding: 6px 10px; border-radius: 10px; backdrop-filter: blur(6px); transition: opacity .5s; white-space: nowrap; }
.viewer__hint .ic { width: 16px; height: 16px; }
.viewer__bar { position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 3; display: flex; align-items: center; gap: 8px; background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid color-mix(in srgb, var(--border) 70%, transparent); border-radius: 18px; padding: 6px; box-shadow: var(--shadow-sm); }
.vbtn { height: 42px; min-width: 42px; padding: 0 12px; border-radius: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 500 14px/1 var(--font-display); color: var(--text-2); transition: background .15s, color .15s; white-space: nowrap; }
.vbtn .ic { width: 19px; height: 19px; }
.vbtn:hover { background: var(--surface-2); color: var(--text); }
.vbtn.is-on { background: var(--ink); color: #fff; }
[data-theme="dark"] .vbtn.is-on { background: var(--brand); color: var(--ink); }
.vbtn--play { background: var(--brand); color: var(--brand-ink); width: 42px; padding: 0; }
.vbtn--play:hover { background: var(--y-400); color: var(--brand-ink); }
.viewer__steps { display: flex; gap: 4px; flex: 1; justify-content: center; }
.vstep { width: 34px; height: 34px; border-radius: 11px; font: 600 14px/1 var(--font-display); color: var(--text-2); background: var(--surface-2); transition: .15s; }
.vstep:hover { color: var(--text); }
.vstep.is-on { background: var(--brand); color: var(--brand-ink); }
.viewer__sep { width: 1px; height: 24px; background: var(--border); }
.vpop { position: relative; }
.vpop__menu { position: absolute; bottom: calc(100% + 10px); right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; min-width: 150px; display: none; z-index: 5; }
.vpop.is-open .vpop__menu { display: block; animation: popIn .18s var(--ease); }
.vpop__item { display: flex; width: 100%; align-items: center; gap: 8px; padding: 9px 11px; border-radius: 10px; font: 500 14px/1 var(--font-display); color: var(--text-2); }
.vpop__item:hover { background: var(--surface-2); color: var(--text); }
.vpop__item.is-on { color: var(--text); }
.vpop__item.is-on::after { content: ''; margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
/* แถบควบคุมตัวดู 3D (หน้าท่า) ปรับตามความกว้าง "ตัวดู" เอง ไม่ใช่ความกว้างจอ — คอลัมน์แคบบนเดสก์ท็อปก็ไม่ล้น/ป้ายไม่บีบ */
.viewer--bar { container: viewer / inline-size; }
@container viewer (max-width: 579px) {
  .viewer__bar .vbtn span { display: none; }
}
/* ตัวดูแคบ (มือถือ): แถบล่างเหลือ เล่น · ทั้งท่า · ขั้นตอน · ความเร็ว — ปุ่มมุมมอง/หุ่น/เต็มจอ ย้ายเป็นแถบแนวตั้งมุมขวาเหนือแถบล่าง */
@container viewer (max-width: 499px) {
  .viewer__bar { gap: 6px; }
  .viewer__bar .viewer__sep { display: none; }
  .viewer__bar > [data-pop="view"], .viewer__bar > [data-pop="fig"], .viewer__bar > [data-fs] { position: absolute; right: 0; }
  .viewer__bar > [data-fs] { bottom: calc(100% + 8px); }
  .viewer__bar > [data-pop="fig"] { bottom: calc(100% + 56px); }
  .viewer__bar > [data-pop="view"] { bottom: calc(100% + 104px); }
  .viewer__bar > [data-pop="view"] > .vbtn, .viewer__bar > [data-pop="fig"] > .vbtn, .viewer__bar > [data-fs] { background: color-mix(in srgb, var(--surface) 84%, transparent); border: 1px solid color-mix(in srgb, var(--border) 70%, transparent); box-shadow: var(--shadow-sm); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
  .viewer__bar > [data-pop="view"] .vpop__menu, .viewer__bar > [data-pop="fig"] .vpop__menu { bottom: auto; top: 0; right: calc(100% + 8px); }
}
/* ตัวดูแคบมาก (จอ ≤350px): ย่อปุ่มในแถบล่างอีกนิดให้พอดี */
@container viewer (max-width: 330px) {
  .viewer__bar { gap: 4px; }
  .viewer__bar .vbtn { min-width: 36px; padding: 0 7px; }
  .viewer__bar .vbtn--play { width: 36px; }
  .viewer__steps { gap: 3px; }
  .vstep { width: 28px; }
}
.viewer:fullscreen { border-radius: 0; }
.viewer:fullscreen .viewer__stage { aspect-ratio: auto; height: 100dvh; }

/* ---------- Utilities ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mt-32 { margin-top: 32px; }
.w-full { width: 100%; }
.center { text-align: center; }
.kbd { font: 600 12px/1 var(--font-display); padding: 3px 6px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); }
.fade-in { animation: fadeIn .45s var(--ease) both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 0 rgba(22,163,74,.5); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(22,163,74,0); } 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); } }

/* ---------- View transitions (ข้ามหน้าเหมือนแอป) ---------- */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .28s; animation-timing-function: var(--ease); }
::view-transition-old(root) { animation-name: vtOut; }
::view-transition-new(root) { animation-name: vtIn; }
.topbar { view-transition-name: topbar; }
.tabbar { view-transition-name: tabbar; }
@keyframes vtOut { to { opacity: 0; transform: translateY(-6px); } }
@keyframes vtIn { from { opacity: 0; transform: translateY(10px); } }

/* ==========================================================================
   Responsive
   ========================================================================== */
/* เมนูบน 7 รายการ: ซ่อนไอคอนเมื่อจอไม่กว้างพอ · จอ 1024–1100 บีบระยะอีกนิด (ไม่ล้นขอบ) */
@media (max-width: 1400px) {
  .mainnav__link { padding: 0 10px; font-size: 14.5px; }
  .mainnav__link .ic { display: none; }
}
@media (max-width: 1100px) {
  .mainnav { gap: 0; }
  .mainnav__link { padding: 0 8px; font-size: 14px; }
}
@media (max-width: 1023px) {
  :root { --header-h: 58px; }
  .mainnav, .btn--login span, .footer { display: none; }
  .btn--login { width: 40px; padding: 0; margin-left: 2px; }
  .topbar__in { gap: 10px; }
  .topbar__actions { margin-left: auto; }
  .brand__mark svg { width: 30px; height: 30px; }
  .brand__name { font-size: 20px; }
  .main { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 28px); }
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);   /* จำนวนเมนูเท่าไหร่ก็อยู่แถวเดียว */
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px);
    border-top: 1px solid var(--border);
  }
  .tabbar__item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--text-3); font: 500 11.5px/1 var(--font-display); position: relative; transition: color .2s; }
  .tabbar__icon { width: 44px; height: 30px; border-radius: 12px; display: grid; place-items: center; transition: background .25s var(--ease), transform .2s var(--ease); }
  .tabbar__icon .ic { width: 23px; height: 23px; }
  .tabbar__label { max-width: calc(100% - 4px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-bottom: 1px; }
  .tabbar__item.is-active { color: var(--text); }
  .tabbar__item.is-active .tabbar__icon { background: var(--brand); color: var(--brand-ink); }
  .tabbar__item:active .tabbar__icon { transform: scale(.9); }
  .fab-feedback { display: none; }
  .toast-root { bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); }
  .modal { align-items: flex-end; padding: 0; }
  .modal__panel { max-width: none; border-radius: 26px 26px 0 0; max-height: 92dvh; transform: translateY(100%); opacity: 1; }
  .modal.is-open .modal__panel { transform: translateY(var(--drag, 0px)); }
  .modal.is-dragging .modal__panel { transition: none; }
  .modal__handle { display: block; width: 40px; height: 5px; border-radius: 5px; background: var(--border-2); margin: 10px auto 0; flex: none; }
  .modal__head { padding-top: 12px; }
  .modal--center { align-items: center; padding: 20px; }
  .modal--center .modal__panel { border-radius: 24px; transform: scale(.96); opacity: 0; }
  .modal--center.is-open .modal__panel { transform: none; opacity: 1; }
  .modal--center .modal__handle { display: none; }
  .search-ov { padding: calc(10px + var(--safe-t)) 10px 10px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  /* หัวข้อส่วน: ชื่อ + ปุ่ม < > อยู่บรรทัดเดียว คำอธิบายเต็มความกว้างด้านล่าง (ไม่บีบคำอธิบายเป็นคอลัมน์แคบ) */
  .sec-head:has(> div:first-child > .sec-sub) { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 10px; row-gap: 0; }
  .sec-head > div:first-child:has(> .sec-sub) { display: contents; }
  .sec-head > div:first-child > .sec-sub { grid-column: 1 / -1; grid-row: 2; }
  .sec-head__end { gap: 10px; }
  /* แถวปุ่มหลัก (CTA): ถ้าวางบรรทัดเดียวได้ → กว้างเท่ากัน, ถ้าไม่พอ → เต็มความกว้างทีละบรรทัด (ไม่เหลือปุ่มสั้นยาวไม่เท่ากัน) */
  .cta-row > .btn, .page-head__actions > .btn, .set-hero__actions > .btn:not(.btn--icon) { flex: 1 1 0; min-width: min(100%, max-content); max-width: 100%; }
  .cta-row > .btn span, .page-head__actions > .btn span, .set-hero__actions > .btn span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .page-head__actions { width: 100%; }
  /* แท็บที่ต้องพอดีจอ (ยอดนิยม/มาแรง/มือใหม่): ซ่อนไอคอน แบ่งความกว้างเท่าๆ กัน ไม่ให้แท็บสุดท้ายโดนตัด */
  .tabs--fit .tab { flex: 1 0 auto; justify-content: center; padding: 0 10px; }
  .tabs--fit .tab .ic { display: none; }
  .rail-nav { gap: 5px; }
  .rail-nav button { width: 34px; height: 34px; border-radius: 11px; }
  .rail-nav .ic { width: 17px; height: 17px; }
  .page-head { padding: 18px 0 14px; }
  .beta-bar__text { font-size: 12px; line-height: 1.35; }
  .beta-bar__link span { display: none; }
  .ex-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .ex-card { border-radius: 16px; }
  .ex-card__body { padding: 10px 11px 12px; }
  .ex-card__name { font-size: 14.5px; }
  .ex-card__add { width: 32px; height: 32px; border-radius: 10px; right: 8px; top: 8px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .sec { margin-top: 34px; }
  .btn { height: 48px; }
  .btn--sm { height: 38px; }
  .viewer { border-radius: 22px; }
  .viewer__stage { aspect-ratio: 1 / 1.08; }
  .viewer__bar { left: 8px; right: 8px; bottom: 8px; border-radius: 16px; }
  .vbtn { height: 40px; min-width: 40px; padding: 0 9px; }
  .vbtn span { display: none; }
  .vstep { width: 32px; height: 32px; }
}
/* ขั้นตอน (.flow — การ์ด 4 ขั้นตอนหน้าชุดฝึก / แถบขั้นตอนหน้าสร้างชุดฝึก) บนจอแคบ: เรียงไอคอนเหนือป้ายชื่อ เห็นครบ 4 ขั้นในจอเดียว ไม่ต้องเลื่อนข้าง */
@media (max-width: 760px) {
  .flow { align-items: flex-start; overflow: visible; }
  .flow__step { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 7px; text-align: center; font-size: 12.5px; line-height: 1.3; }
  .flow__step small { display: none !important; }
  .flow__num { width: 32px; height: 32px; border-radius: 11px; }
  .flow__line { flex: 0 1 22px; min-width: 8px; margin: 15px 0 0; }
}
/* จอแคบมาก (≤400px): ซ่อนป้าย BETA ข้างโลโก้ (มีแถบ BETA ด้านบนอยู่แล้ว) กันปุ่มหัวเว็บล้นขอบจอ */
@media (max-width: 400px) {
  .brand__beta { display: none; }
  /* แท็บล่าง 6 เมนู: ย่อไอคอน/ตัวอักษรเล็กน้อยให้ป้ายไม่ชนกัน */
  .tabbar__icon { width: 40px; }
  .tabbar__item { font-size: 10.5px; }
}
/* จอเล็กมาก (≤359px เช่น 320–350): บีบหัวเว็บ/แท็บ/ปุ่มให้พอดี ไม่ล้นขอบจอ */
@media (max-width: 359px) {
  .lang-menu__code { display: none; }
  .lang-menu__btn { padding: 0; width: 40px; justify-content: center; }
  .tabs--fit .tab { padding: 0 6px; font-size: 14px; }
  [data-range] { min-width: 0 !important; flex: 1; font-size: 14px; }
  .exd__actions { grid-template-columns: minmax(0, 1fr) !important; }
  .exd__actions .btn:last-child { grid-column: auto !important; }
}
@media (hover: none) {
  .ex-card:hover { transform: none; box-shadow: none; }
  .ex-card:hover .ex-card__media img { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media print {
  .topbar, .tabbar, .footer, .fab-feedback, .beta-bar { display: none !important; }
}

/* ---------- หุ่น 3D กำลังสร้าง (ครั้งแรกของเครื่อง) ---------- */
.fig-loading { position: relative; }
.fig-loading::after { content: ''; position: absolute; left: 50%; top: 50%; width: 38px; height: 38px; margin: -19px 0 0 -19px; border-radius: 50%; border: 3px solid rgba(255, 196, 0, .22); border-top-color: var(--brand); animation: figspin .9s linear infinite; z-index: 2; pointer-events: none; }
@keyframes figspin { to { transform: rotate(360deg); } }

/* ---------- แถวเลื่อนแนวนอนบนคอมพิวเตอร์ (assets/js/core/hscroll.js): ปุ่ม < > ที่ขอบ · ลากด้วยเมาส์ (Shift+ล้อ/ทัชแพดแนวนอนตามปกติของเบราว์เซอร์) ---------- */
.hs-arrow { position: absolute; z-index: 6; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; padding: 0; background: var(--surface); border: 1px solid var(--border-2); color: var(--text); box-shadow: 0 4px 14px -4px rgba(0, 0, 0, .35); cursor: pointer; transition: background .15s, transform .12s, opacity .15s; }
.hs-arrow[hidden] { display: none; }
.hs-arrow:hover { background: var(--surface-2); border-color: var(--brand); }
.hs-arrow:active { transform: scale(.92); }
.hs-arrow .ic { width: 18px; height: 18px; stroke-width: 2.2; }
.hs-mouse .hs-over { cursor: grab; }
.hs-mouse .hs-over.hs-drag, .hs-mouse .hs-over.hs-drag * { cursor: grabbing; }
.hs-drag { user-select: none; -webkit-user-select: none; }
.hs-free { scroll-snap-type: none !important; }
