/* ═══════════════════════════════════════════════════════════════
   WESCO Assessment — Design System
   Mobile-first · Light + Dark · WCAG AA
   ═══════════════════════════════════════════════════════════════ */

/* ───────────────────────── tokens ───────────────────────── */
:root {
  /* brand — Wesco green */
  --brand-50:  #e9f9ec;
  --brand-100: #c9f1d2;
  --brand-200: #93e4a6;
  --brand-300: #55d275;
  --brand-400: #1fc04b;
  --brand:     #00b227;   /* พื้นปุ่ม / ไฮไลต์ — ตัวอักษรสีขาวบนสีนี้ได้ 7.4:1 */
  --brand-600: #009a22;
  --brand-700: #00761e;   /* ตัวอักษรสีเขียวบนพื้นสว่าง 5.8:1 */
  --brand-800: #005c17;

  /* neutrals — โทนเย็นให้เข้ากับ wordmark */
  --ink-950: #060d10;
  --ink-900: #0d1a20;
  --ink-800: #16282f;
  --ink-700: #29424d;
  --ink-600: #41606d;
  --ink-500: #5c7480;
  --ink-400: #8399a3;
  --ink-300: #a9bcc4;
  --ink-200: #cbd8dd;
  --ink-100: #e4ebee;
  --ink-50:  #f2f6f7;

  /* semantic */
  --ok:     #00761e;
  --ok-bg:  #e9f9ec;
  --warn:   #a35a00;
  --warn-bg:#fdf0dc;
  --dang:   #c42b2b;
  --dang-bg:#fdecec;
  --info:   #0b6fbf;
  --info-bg:#e6f1fb;

  /* surfaces (light) */
  --bg:        #f4f7f7;
  --bg-accent: radial-gradient(1200px 520px at 50% -180px, #dff5e4 0%, rgba(223,245,228,0) 62%);
  --surface:   #ffffff;
  --surface-2: #f7fafa;
  --surface-3: #eef4f4;
  --border:    #dfe8ea;
  --border-strong: #c7d5d9;
  --text:      #0d1a20;
  --text-2:    #41606d;
  --text-3:    #5c7480;
  --on-brand:  #ffffff;
  --scrim:     rgba(6, 13, 16, .55);

  --shadow-xs: 0 1px 2px rgba(13, 26, 32, .06);
  --shadow-sm: 0 1px 3px rgba(13, 26, 32, .07), 0 1px 2px rgba(13, 26, 32, .04);
  --shadow-md: 0 4px 12px rgba(13, 26, 32, .08), 0 2px 4px rgba(13, 26, 32, .04);
  --shadow-lg: 0 12px 32px rgba(13, 26, 32, .12), 0 4px 8px rgba(13, 26, 32, .05);
  --shadow-brand: 0 6px 16px rgba(0, 178, 39, .28);

  /* geometry */
  --r-xs: 6px;  --r-sm: 10px; --r-md: 14px; --r-lg: 18px; --r-xl: 24px; --r-full: 999px;
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px; --sp-5: 20px;
  --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px; --sp-16: 64px;

  --tap: 44px;
  --shell: 1180px;
  --read: 680px;

  --dur-1: 120ms; --dur-2: 200ms; --dur-3: 300ms;
  --ease: cubic-bezier(.22, .61, .36, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);

  --z-nav: 40; --z-sticky: 50; --z-overlay: 100; --z-modal: 110; --z-toast: 200;

  --font: 'IBM Plex Sans Thai', 'IBM Plex Sans', -apple-system, BlinkMacSystemFont,
          'Segoe UI', 'Noto Sans Thai', system-ui, sans-serif;
}

/* ───────────────────────── dark ───────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg:        #081115;
    --bg-accent: radial-gradient(1200px 520px at 50% -200px, #0c2a18 0%, rgba(12,42,24,0) 62%);
    --surface:   #101d23;
    --surface-2: #16262d;
    --surface-3: #1d323a;
    --border:    #21353d;
    --border-strong: #2e4954;
    --text:      #e8f0f2;
    --text-2:    #a9bcc4;
    --text-3:    #8399a3;
    --scrim:     rgba(0, 0, 0, .74);

    --brand-700: #45d866;      /* ตัวอักษรเขียวบนพื้นมืด 9.2:1 */
    --ok:     #45d866; --ok-bg:   #0e2d18;
    --warn:   #f0b45e; --warn-bg: #33240d;
    --dang:   #ff7b7b; --dang-bg: #3a1618;
    --info:   #6cc0ff; --info-bg: #0d2739;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .45), 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .5), 0 2px 4px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6), 0 4px 8px rgba(0, 0, 0, .35);
    --shadow-brand: 0 6px 16px rgba(0, 178, 39, .3);
  }
}
:root[data-theme='dark'] {
  --bg:        #081115;
  --bg-accent: radial-gradient(1200px 520px at 50% -200px, #0c2a18 0%, rgba(12,42,24,0) 62%);
  --surface:   #101d23;
  --surface-2: #16262d;
  --surface-3: #1d323a;
  --border:    #21353d;
  --border-strong: #2e4954;
  --text:      #e8f0f2;
  --text-2:    #a9bcc4;
  --text-3:    #8399a3;
  --scrim:     rgba(0, 0, 0, .74);

  --brand-700: #45d866;
  --ok:     #45d866; --ok-bg:   #0e2d18;
  --warn:   #f0b45e; --warn-bg: #33240d;
  --dang:   #ff7b7b; --dang-bg: #3a1618;
  --info:   #6cc0ff; --info-bg: #0d2739;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .45), 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .5), 0 2px 4px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6), 0 4px 8px rgba(0, 0, 0, .35);
}

/* ───────────────────────── base ───────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

/* ต้องมาก่อนทุก rule ที่ตั้ง display เพราะ [hidden] ของเบราว์เซอร์มี specificity ต่ำกว่า class */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg-accent), var(--bg);
  background-repeat: no-repeat;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img, svg, video { display: block; max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-700); text-decoration-color: color-mix(in srgb, var(--brand-700) 40%, transparent); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 70%, transparent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

h1, h2, h3, h4 { line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.0625rem; } h4 { font-size: .9375rem; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1; }

::selection { background: var(--brand-200); color: var(--ink-900); }

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

/* ───────────────────────── layout ───────────────────────── */
.shell { width: 100%; max-width: var(--shell); margin-inline: auto; padding-inline: var(--sp-4); }
.shell-narrow { max-width: var(--read); }
@media (min-width: 768px) { .shell { padding-inline: var(--sp-6); } }

.stack   { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-2 { display: flex; flex-direction: column; gap: var(--sp-2); }
.stack-6 { display: flex; flex-direction: column; gap: var(--sp-6); }
.row     { display: flex; align-items: center; gap: var(--sp-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.wrap    { flex-wrap: wrap; }
.grow    { flex: 1 1 auto; min-width: 0; }
.center  { display: grid; place-items: center; }

.page { padding-block: var(--sp-5) calc(var(--sp-16) + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--sp-4); top: -100px; z-index: var(--z-toast);
  background: var(--surface); color: var(--text); padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm); box-shadow: var(--shadow-lg); font-weight: 600;
}
.skip-link:focus { top: var(--sp-4); }

/* ───────────────────────── header ───────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: var(--z-nav);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-in { display: flex; align-items: center; gap: var(--sp-3); min-height: 60px; }
.topbar .brand-lockup { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.topbar .logo { height: 30px; width: auto; flex: none; }
.topbar-title { font-size: .9375rem; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-sub { font-size: .75rem; color: var(--text-3); line-height: 1.2; }
@media (max-width: 480px) { .topbar-sub { display: none; } }

/* ───────────────────────── buttons ───────────────────────── */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap); padding: 10px var(--sp-5);
  font-size: .9375rem; font-weight: 600; line-height: 1.2;
  color: var(--btn-fg); background: var(--btn-bg);
  border: 1px solid var(--btn-bd); border-radius: var(--r-md);
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; text-decoration: none; white-space: nowrap;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
              box-shadow var(--dur-1) var(--ease), transform var(--dur-1) var(--ease), opacity var(--dur-1);
}
.btn:hover:not(:disabled) { background: color-mix(in srgb, var(--btn-bg) 92%, var(--text)); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: .45; cursor: not-allowed; }

.btn-primary { --btn-bg: var(--brand); --btn-fg: var(--on-brand); --btn-bd: var(--brand); box-shadow: var(--shadow-brand); }
.btn-primary:hover:not(:disabled) { --btn-bg: var(--brand-600); --btn-bd: var(--brand-600); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-danger { --btn-bg: var(--dang-bg); --btn-fg: var(--dang); --btn-bd: color-mix(in srgb, var(--dang) 35%, transparent); }
.btn-danger:hover:not(:disabled) { --btn-bg: var(--dang); --btn-fg: #fff; }
.btn-sm { min-height: 36px; padding: 6px var(--sp-3); font-size: .8125rem; border-radius: var(--r-sm); }
.btn-lg { min-height: 54px; padding: 14px var(--sp-6); font-size: 1rem; border-radius: var(--r-lg); }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: var(--tap); min-width: var(--tap); }
.btn-icon.btn-sm { width: 36px; min-width: 36px; }
.btn .ic { flex: none; }

.btn.is-loading { pointer-events: none; position: relative; color: transparent !important; }
.btn.is-loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: var(--btn-fg); animation: spin .6s linear infinite;
}
.btn-primary.is-loading::after { border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────────────────── cards ───────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--sp-5); }
@media (min-width: 768px) { .card-pad { padding: var(--sp-6); } }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { font-size: .9375rem; }
.card-body { padding: var(--sp-5); }

/* เส้นเฉียงรับกับโลโก้ W */
.card-accent { position: relative; overflow: hidden; }
.card-accent::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: linear-gradient(180deg, var(--brand-300), var(--brand));
}

/* ───────────────────────── forms ───────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: .875rem; font-weight: 600; color: var(--text-2); }
.label .req { color: var(--dang); margin-inline-start: 2px; }
.help { font-size: .8125rem; color: var(--text-3); line-height: 1.45; }
.err  { font-size: .8125rem; color: var(--dang); font-weight: 500; display: flex; gap: 6px; align-items: flex-start; }

.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 11px var(--sp-4);
  font-size: 1rem; /* 16px กัน iOS zoom */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), background var(--dur-1);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: .8; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-400); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent);
}
.input[aria-invalid='true'], .textarea[aria-invalid='true'] { border-color: var(--dang); }
.input[aria-invalid='true']:focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--dang) 18%, transparent); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-3); opacity: .6; cursor: not-allowed; }

.select {
  appearance: none; padding-inline-end: var(--sp-10);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%235c7480' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--sp-3) center;
}
[dir='rtl'] .select { background-position: left var(--sp-3) center; }

.switch { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--tap); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  flex: none; width: 46px; height: 28px; border-radius: var(--r-full);
  background: var(--ink-300); position: relative;
  transition: background var(--dur-2) var(--ease);
}
.switch-track::after {
  content: ''; position: absolute; inset-block-start: 3px; inset-inline-start: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow-sm); transition: transform var(--dur-2) var(--ease-out);
}
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid color-mix(in srgb, var(--brand) 70%, transparent); outline-offset: 2px; }
.switch-label { font-size: .9375rem; font-weight: 500; }

/* ───────────────────────── badges ───────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: .75rem; font-weight: 600; line-height: 1.5; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
  border: 1px solid transparent;
}
.badge-ok   { background: var(--ok-bg);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.badge-warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.badge-dang { background: var(--dang-bg); color: var(--dang); border-color: color-mix(in srgb, var(--dang) 25%, transparent); }
.badge-info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }

/* เกรด — ใช้ทั้งสีและตัวอักษร ไม่พึ่งสีอย่างเดียว */
.grade {
  display: inline-grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: var(--r-sm);
  font-weight: 700; font-size: 1rem; line-height: 1;
  border: 1.5px solid transparent;
}
.grade-A { background: var(--ok-bg);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.grade-B { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 35%, transparent); }
.grade-C { background: var(--dang-bg); color: var(--dang); border-color: color-mix(in srgb, var(--dang) 35%, transparent); }
.grade-pending { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); font-size: .8125rem; }
.grade-lg { width: 44px; height: 44px; font-size: 1.375rem; border-radius: var(--r-md); }

/* ───────────────────────── topic cards ───────────────────────── */
.topic-grid { display: grid; gap: var(--sp-3); grid-template-columns: 1fr; }
@media (min-width: 720px)  { .topic-grid { grid-template-columns: repeat(2, 1fr); gap: var(--sp-4); } }
@media (min-width: 1080px) { .topic-grid { grid-template-columns: repeat(3, 1fr); } }

.topic {
  position: relative; display: flex; flex-direction: column; gap: var(--sp-3);
  width: 100%; text-align: start; padding: var(--sp-4) var(--sp-4) var(--sp-4) var(--sp-5);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  cursor: pointer; overflow: hidden; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), transform var(--dur-1) var(--ease);
}
.topic::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: linear-gradient(180deg, var(--brand-300), var(--brand));
  opacity: .5; transition: opacity var(--dur-2) var(--ease);
}
.topic:hover { border-color: var(--brand-300); box-shadow: var(--shadow-md); }
.topic:hover::before { opacity: 1; }
.topic:active { transform: scale(.99); }
.topic-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); }
.topic-code {
  font-size: .6875rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--brand-700); background: color-mix(in srgb, var(--brand) 12%, transparent);
  padding: 2px 8px; border-radius: var(--r-xs);
  display: inline-block; align-self: flex-start; width: fit-content;
}
.topic-title { font-size: 1.0625rem; font-weight: 600; line-height: 1.35; }
.topic-sub { font-size: .8125rem; color: var(--text-3); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.topic-meta { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4);
  font-size: .75rem; color: var(--text-3); margin-top: auto; padding-top: var(--sp-1); }
.topic-meta span { display: inline-flex; align-items: center; gap: 5px; }

/* ───────────────────────── exam ───────────────────────── */
.exam-head { position: sticky; top: 0; z-index: var(--z-sticky);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.exam-head-in { padding-block: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-3); }

.progress { height: 6px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.progress-bar { height: 100%; border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--brand-400), var(--brand));
  transition: width var(--dur-3) var(--ease-out); }

.qdots { display: flex; flex-wrap: wrap; gap: 6px; }
.qdot {
  width: 30px; height: 30px; border-radius: var(--r-sm);
  display: grid; place-items: center; font-size: .75rem; font-weight: 600;
  background: var(--surface-3); color: var(--text-3);
  border: 1.5px solid transparent; cursor: pointer; padding: 0;
  transition: all var(--dur-1) var(--ease);
}
.qdot:hover { border-color: var(--border-strong); }
.qdot.done { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand-700); }
.qdot.current { border-color: var(--brand); background: var(--brand); color: var(--on-brand); }

.timer { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: .875rem;
  padding: 4px 10px; border-radius: var(--r-full); background: var(--surface-3); color: var(--text-2); }
.timer.warn { background: var(--warn-bg); color: var(--warn); }
.timer.danger { background: var(--dang-bg); color: var(--dang); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .6; } }

.qnum { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand-700); }
.qtext { font-size: 1.125rem; font-weight: 600; line-height: 1.55; letter-spacing: -0.01em; }
@media (min-width: 768px) { .qtext { font-size: 1.25rem; } }

.qimage { position: relative; margin-block: var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--r-md);
  overflow: hidden; background: #fff; cursor: zoom-in; }
.qimage img { width: 100%; }
.qimage::after {
  content: 'แตะเพื่อขยาย';
  position: absolute; inset-block-end: 8px; inset-inline-end: 8px;
  font-size: .6875rem; font-weight: 600; color: #fff;
  background: rgba(6, 13, 16, .74); padding: 4px 10px; border-radius: var(--r-full);
  pointer-events: none;
}
.qimage:hover::after { background: rgba(6, 13, 16, .9); }

/* ตัวเลือก — พื้นที่แตะใหญ่ */
.choices { display: flex; flex-direction: column; gap: var(--sp-2); }
.choice {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  min-height: 56px; padding: var(--sp-3) var(--sp-4);
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--r-md); cursor: pointer; text-align: start;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.choice:hover { border-color: var(--ink-400); background: var(--surface-2); }
.choice:active { transform: scale(.99); }
.choice input { position: absolute; opacity: 0; width: 0; height: 0; }
.choice-key {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: .8125rem; font-weight: 700;
  background: var(--surface-3); color: var(--text-2);
  border: 1.5px solid var(--border-strong);
  transition: all var(--dur-1) var(--ease);
}
.choice-text { flex: 1; font-size: .9375rem; line-height: 1.55; padding-top: 3px; }
.choice.selected { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--surface)); }
.choice.selected .choice-key { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.choice:focus-within { outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 2px; }

/* เฉลย */
.choice.correct { border-color: var(--ok); background: var(--ok-bg); }
.choice.correct .choice-key { background: var(--ok); color: #fff; border-color: var(--ok); }
.choice.wrong { border-color: var(--dang); background: var(--dang-bg); }
.choice.wrong .choice-key { background: var(--dang); color: #fff; border-color: var(--dang); }

/* แถบปุ่มล่างติดหน้าจอ */
.exam-foot {
  position: sticky; bottom: 0; z-index: var(--z-sticky);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: var(--sp-3) 0 calc(var(--sp-3) + env(safe-area-inset-bottom));
  margin-top: var(--sp-6);
}
.exam-foot .row { gap: var(--sp-2); }
.exam-foot .btn { flex: 1; }

/* ───────────────────────── result ───────────────────────── */
.result-hero { display: flex; flex-direction: column; align-items: center; gap: var(--sp-4);
  padding: var(--sp-8) var(--sp-5); text-align: center; }
.ring { position: relative; width: 168px; height: 168px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-3); stroke-width: 12; }
.ring-fill  { fill: none; stroke-width: 12; stroke-linecap: round;
  transition: stroke-dashoffset 900ms var(--ease-out); }
.ring-A .ring-fill { stroke: var(--ok); }
.ring-B .ring-fill { stroke: var(--info); }
.ring-C .ring-fill { stroke: var(--dang); }
.ring-pending .ring-fill { stroke: var(--warn); }
.ring-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring-grade { font-size: 3rem; font-weight: 700; line-height: 1; letter-spacing: -0.03em; }
.ring-pct { font-size: .875rem; font-weight: 600; color: var(--text-3); margin-top: 4px; }

.score-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-2); }
@media (min-width: 560px) { .score-grid { grid-template-columns: repeat(4, 1fr); } }
.score-tile { background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); }
.score-tile dt { font-size: .75rem; color: var(--text-3); font-weight: 500; }
.score-tile dd { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }

.review-item { padding: var(--sp-4) 0; border-bottom: 1px solid var(--border); }
.review-item:last-child { border-bottom: 0; }

/* ───────────────────────── stats ───────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); }
@media (min-width: 900px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-4); box-shadow: var(--shadow-xs); overflow: hidden;
}
.stat-label { font-size: .75rem; color: var(--text-3); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.2; margin-top: var(--sp-1); }
.stat-note { font-size: .75rem; color: var(--text-3); }

/* แถบสัดส่วนเกรด */
.gradebar { display: flex; height: 10px; border-radius: var(--r-full); overflow: hidden; background: var(--surface-3); }
.gradebar i { display: block; height: 100%; transition: width var(--dur-3) var(--ease-out); }
.gradebar .gb-A { background: var(--ok); }
.gradebar .gb-B { background: var(--info); }
.gradebar .gb-C { background: var(--dang); }

/* ───────────────────────── table ───────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-md); }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; min-width: 640px; }
/* ตารางข้อมูลหนาแน่น — กันคอลัมน์ถูกบีบจนข้อความตัดบรรทัดยับ */
.table-lg { min-width: 900px; }
.table-lg td > div { overflow: hidden; text-overflow: ellipsis; }
.cell-id { max-width: 190px; }
.cell-topic { max-width: 240px; }
.table th, .table td { padding: var(--sp-3) var(--sp-3); text-align: start; vertical-align: middle; }
.table thead th {
  position: sticky; top: 0; z-index: 1;
  font-size: .75rem; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: end; }

/* ───────────────────────── tabs ───────────────────────── */
.tabs { display: flex; gap: var(--sp-1); padding: var(--sp-1); background: var(--surface-3);
  border-radius: var(--r-md); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-height: 38px; padding: 8px var(--sp-4);
  font-size: .875rem; font-weight: 600; white-space: nowrap;
  color: var(--text-3); background: transparent; border: 0; border-radius: var(--r-sm);
  cursor: pointer; transition: all var(--dur-1) var(--ease);
}
.tab:hover { color: var(--text); }
.tab[aria-selected='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

/* ───────────────────────── admin shell ───────────────────────── */
.admin-layout { display: block; }
.sidebar { display: none; }
.admin-nav {
  position: sticky; bottom: 0; z-index: var(--z-nav);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.admin-nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 58px; padding: 6px 2px; font-size: .6875rem; font-weight: 600;
  color: var(--text-3); background: none; border: 0; cursor: pointer;
  -webkit-tap-highlight-color: transparent; transition: color var(--dur-1) var(--ease);
}
.admin-nav button[aria-current='page'] { color: var(--brand-700); }
.admin-nav button[aria-current='page'] .ic { transform: translateY(-1px); }

/* ตอนยังไม่ล็อกอิน ไม่มีเมนู — ให้เนื้อหาใช้ความกว้างเต็ม */
.admin-layout.is-plain { grid-template-columns: 1fr !important; }

@media (min-width: 1024px) {
  .admin-layout { display: grid; grid-template-columns: 250px 1fr; gap: var(--sp-6); align-items: start; }
  .admin-nav { display: none; }
  .sidebar { display: block; position: sticky; top: 76px; }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar button {
    display: flex; align-items: center; gap: var(--sp-3);
    min-height: var(--tap); padding: 10px var(--sp-4); width: 100%;
    font-size: .9375rem; font-weight: 500; text-align: start;
    color: var(--text-2); background: none; border: 0; border-radius: var(--r-md); cursor: pointer;
    transition: all var(--dur-1) var(--ease);
  }
  .sidebar button:hover { background: var(--surface-3); color: var(--text); }
  .sidebar button[aria-current='page'] {
    background: color-mix(in srgb, var(--brand) 12%, transparent);
    color: var(--brand-700); font-weight: 600;
  }
}

/* ───────────────────────── modal / sheet ───────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  background: var(--scrim);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade var(--dur-2) var(--ease);
  padding-top: env(safe-area-inset-top);
}
@media (min-width: 640px) { .overlay { align-items: center; padding: var(--sp-6); } }
@keyframes fade { from { opacity: 0; } }

.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg);
  animation: slide-up var(--dur-3) var(--ease-out);
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 640px) { .sheet { border-radius: var(--r-xl); animation: pop var(--dur-2) var(--ease-out); } }
.sheet-wide { max-width: 860px; }
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }

.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); background: var(--surface); border-bottom: 1px solid var(--border); }
.sheet-head h2 { font-size: 1.0625rem; }
.sheet-body { padding: var(--sp-5); }
.sheet-foot { position: sticky; bottom: 0; display: flex; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5);
  background: var(--surface); border-top: 1px solid var(--border); }
.sheet-foot .btn { flex: 1; }
.grabber { width: 38px; height: 4px; border-radius: var(--r-full); background: var(--border-strong);
  margin: var(--sp-2) auto 0; }
@media (min-width: 640px) { .grabber { display: none; } }

/* ───────────────────────── toast ───────────────────────── */
.toasts {
  position: fixed; z-index: var(--z-toast);
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sp-5) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: var(--sp-2);
  width: min(440px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  background: var(--ink-900); color: #fff; box-shadow: var(--shadow-lg);
  font-size: .875rem; line-height: 1.5; font-weight: 500;
  animation: toast-in var(--dur-3) var(--ease-out); pointer-events: auto;
}
:root[data-theme='dark'] .toast { background: var(--surface-3); border: 1px solid var(--border-strong); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .toast { background: var(--surface-3); border: 1px solid var(--border-strong); } }
.toast.ok   { background: var(--ok);   color: #fff; }
.toast.err  { background: var(--dang); color: #fff; }
.toast .ic { flex: none; margin-top: 1px; }
@keyframes toast-in { from { transform: translateY(14px); opacity: 0; } }

/* ───────────────────────── states ───────────────────────── */
.empty { text-align: center; padding: var(--sp-12) var(--sp-5); color: var(--text-3); }
.empty-icon {
  width: 56px; height: 56px; margin: 0 auto var(--sp-4); border-radius: var(--r-lg);
  display: grid; place-items: center; background: var(--surface-3); color: var(--text-3);
}
.empty h3 { font-size: 1rem; color: var(--text); margin-bottom: var(--sp-1); }
.empty p { font-size: .875rem; max-width: 34ch; margin-inline: auto; }

.skel { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; border-radius: var(--r-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-card { height: 118px; border-radius: var(--r-lg); }
.skel-line { height: 14px; }

.note {
  display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md); font-size: .875rem; line-height: 1.55;
  border: 1px solid transparent;
}
.note .ic { flex: none; margin-top: 2px; }
.note-info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.note-warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 22%, transparent); }
.note-ok   { background: var(--ok-bg);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 22%, transparent); }
.note-dang { background: var(--dang-bg); color: var(--dang); border-color: color-mix(in srgb, var(--dang) 22%, transparent); }
.note strong { font-weight: 700; }

/* ───────────── เอกสารอ้างอิงในข้อสอบ ───────────── */
.ref-table { width: 100%; border-collapse: collapse; font-size: .8125rem; }
.ref-table th, .ref-table td { padding: 7px var(--sp-3); border: 1px solid var(--border); text-align: start; }
.ref-table thead th { background: var(--surface-3); font-weight: 600; color: var(--text-2); position: sticky; top: 0; }
.ref-table tbody tr:nth-child(even) { background: var(--surface-2); }

/* ดูรูปขนาดเต็ม — เลื่อนดูได้ทั้งแนวตั้งและแนวนอน เพื่ออ่านตารางสเปกบนมือถือได้ */
.lightbox {
  position: fixed; inset: 0; z-index: var(--z-toast);
  background: rgba(6, 13, 16, .985);
  overflow: auto; -webkit-overflow-scrolling: touch;
  animation: fade var(--dur-2) var(--ease); overscroll-behavior: contain;
}
.lightbox-inner {
  min-height: 100%; display: grid; place-items: center;
  padding: calc(var(--sp-16) + env(safe-area-inset-top)) var(--sp-4) var(--sp-8);
}
.lightbox img {
  display: block; max-width: none; max-height: none;
  width: auto; min-width: min(100%, 320px);
  background: #fff; border-radius: var(--r-sm);
}
.lightbox-bar {
  position: fixed; inset: env(safe-area-inset-top) 0 auto 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: linear-gradient(180deg, rgba(6,13,16,.95), rgba(6,13,16,0));
  color: #fff;
}
.lightbox-bar h3 { font-size: .875rem; font-weight: 600; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox-bar button {
  flex: none; width: var(--tap); height: var(--tap); display: grid; place-items: center;
  color: #fff; background: rgba(255, 255, 255, .14); border: 0; border-radius: var(--r-full);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.lightbox-bar button:hover { background: rgba(255, 255, 255, .26); }
.lightbox-hint { position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sp-5) + env(safe-area-inset-bottom));
  font-size: .75rem; color: rgba(255,255,255,.7); background: rgba(6,13,16,.8);
  padding: 6px 14px; border-radius: var(--r-full); pointer-events: none; }

/* ───────────────────────── misc ───────────────────────── */
.divider { height: 1px; background: var(--border); border: 0; }
.muted { color: var(--text-3); }
.small { font-size: .8125rem; }
.strong { font-weight: 600; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.text-ok { color: var(--ok); } .text-dang { color: var(--dang); } .text-warn { color: var(--warn); }
.nowrap { white-space: nowrap; }
.ic { width: 20px; height: 20px; stroke-width: 1.75; }
.ic-sm { width: 16px; height: 16px; }
.ic-lg { width: 24px; height: 24px; }

.chip-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px;
  padding: 5px var(--sp-3); font-size: .8125rem; font-weight: 500;
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-full);
  cursor: pointer; transition: all var(--dur-1) var(--ease);
}
.chip:hover { border-color: var(--ink-400); }
.chip[aria-pressed='true'] { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }

.list-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }
