/* Dictionary — Thai ⇄ English Dictionary */
:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #f2eee4;
  --surface-3: #e9e3d5;
  --ink: #1d1a2f;
  --ink-2: #47435d;
  --muted: #625d76; /* ≥4.5:1 บนพื้นทุกสี (WCAG AA) */
  --line: #e5dfd1;
  --brand: #3d2fb0;
  --brand-ink: #ffffff;
  --brand-soft: #ece9ff;
  --teal: #0f766e;
  --gold: #8f5d00; /* ≥4.5:1 สำหรับตัวอักษร */
  --gold-soft: #fff4d6;
  --mark: #ffe28a;
  --mark-ink: #3b2a00;
  --hero-1: #1b1747;
  --hero-2: #12424a;
  --hero-ink: #fbf8ef;
  --danger: #c2410c;
  --ok: #15803d;
  --shadow-1: 0 1px 2px rgba(29, 26, 47, .06), 0 2px 8px rgba(29, 26, 47, .05);
  --shadow-2: 0 10px 30px -10px rgba(29, 26, 47, .25), 0 2px 6px rgba(29, 26, 47, .06);
  --radius: 18px;
  --radius-sm: 12px;
  --font: "IBM Plex Sans Thai", "Thonburi", "Leelawadee UI", "Sukhumvit Set", system-ui, sans-serif;
  --font-serif-th: "Noto Serif Thai", "Thonburi", serif;
  --font-serif-en: "Fraunces", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0d18; --surface: #17162a; --surface-2: #1f1d36; --surface-3: #2a2846;
    --ink: #f3f1ff; --ink-2: #cbc7e3; --muted: #918cab; --line: #2d2a48;
    --brand: #a7a0ff; --brand-ink: #15122e; --brand-soft: #262356;
    --teal: #5eead4; --gold: #f5c451; --gold-soft: #3a2f12;
    --mark: rgba(245, 196, 81, .32); --mark-ink: #fff3cf;
    --hero-1: #0f0c2e; --hero-2: #082d33; --danger: #fb923c; --ok: #4ade80;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4); --shadow-2: 0 14px 40px -12px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0d18; --surface: #17162a; --surface-2: #1f1d36; --surface-3: #2a2846;
  --ink: #f3f1ff; --ink-2: #cbc7e3; --muted: #918cab; --line: #2d2a48;
  --brand: #a7a0ff; --brand-ink: #15122e; --brand-soft: #262356;
  --teal: #5eead4; --gold: #f5c451; --gold-soft: #3a2f12;
  --mark: rgba(245, 196, 81, .32); --mark-ink: #fff3cf;
  --hero-1: #0f0c2e; --hero-2: #082d33; --danger: #fb923c; --ok: #4ade80;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4); --shadow-2: 0 14px 40px -12px rgba(0,0,0,.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-synthesis: none; /* ไม่ให้เบราว์เซอร์บิด/ถมตัวอักษรเองเมื่อไม่มีน้ำหนักหรือตัวเอียงในฟอนต์ */
  font-family: var(--font); font-size: 16px; line-height: 1.6;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--brand); }
button { font: inherit; color: inherit; }
kbd {
  font-family: ui-monospace, Menlo, monospace; font-size: .75em; padding: .05em .45em;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--surface);
}
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--brand); color: var(--brand-ink); padding: 8px 14px; border-radius: 10px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 2px; border-radius: 8px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, calc((100vw - 1180px) / 2));
  background: color-mix(in srgb, var(--hero-1) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  color: var(--hero-ink); border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  font-family: var(--font-serif-th); font-weight: 700; font-size: 22px; color: #1b1747;
  background: linear-gradient(135deg, #ffd86b, #f0a92c); box-shadow: 0 4px 14px -4px rgba(240,169,44,.7);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-family: var(--font-serif-th); font-size: 20px; }
.brand-text small { font-size: 11px; opacity: .7; letter-spacing: .12em; text-transform: uppercase; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs a {
  position: relative; display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px; color: rgba(251,248,239,.78);
  text-decoration: none; font-weight: 500; font-size: 15px; transition: background .15s, color .15s;
}
.tabs a:hover { background: rgba(255,255,255,.08); color: #fff; }
.tabs a.active { background: rgba(255,255,255,.14); color: #fff; }
.tabs .badge {
  font-style: normal; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center; border-radius: 999px; background: #f5c451; color: #1b1747;
}
[hidden] { display: none !important; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06); cursor: pointer; font-size: 18px; flex: none;
}
.icon-btn:hover { background: rgba(255,255,255,.14); }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden; color: var(--hero-ink);
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(167,160,255,.35), transparent 60%),
    radial-gradient(900px 380px at 100% 120%, rgba(45,212,191,.28), transparent 60%),
    linear-gradient(135deg, var(--hero-1), var(--hero-2));
  padding: 56px 16px 64px;
}
.hero::before { /* ลวดลายจุดแบบลายผ้า */
  content: ""; position: absolute; inset: 0; opacity: .14; pointer-events: none;
  background-image:
    radial-gradient(circle at 50% 50%, #f5c451 1.2px, transparent 1.6px),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.7) 1px, transparent 1.4px);
  background-size: 28px 28px, 28px 28px; background-position: 0 0, 14px 14px;
  mask-image: linear-gradient(to bottom, #000 0%, transparent 95%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, transparent 95%);
}
.hero-deco { position: absolute; inset: 0; pointer-events: none; }
.hero-deco span {
  position: absolute; font-weight: 700; line-height: 1; color: rgba(255,255,255,.05);
}
.hero-deco span:first-child { font-family: var(--font-serif-th); font-size: 340px; left: -30px; top: -70px; }
.hero-deco span:last-child { font-family: var(--font-serif-en); font-size: 300px; right: -10px; bottom: -110px; }
.hero-inner { position: relative; max-width: 820px; margin: 0 auto; text-align: center; }
.hero h1 {
  margin: 0; font-family: var(--font-serif-th); font-weight: 700;
  font-size: clamp(30px, 5.4vw, 54px); line-height: 1.3;
}
.hero h1 .en { font-family: var(--font-serif-en); font-weight: 700; color: #ffd86b; }
.hero h1 .th { color: #fff; }
.hero h1 .swap { display: inline-block; color: #5eead4; font-family: var(--font); font-weight: 400; transform: translateY(-.04em); }
.hero-sub { margin: 10px auto 28px; max-width: 560px; color: rgba(251,248,239,.78); font-size: clamp(15px, 2vw, 17px); }
body.compact .hero { padding: 22px 16px 26px; }
body.compact .hero h1, body.compact .hero-sub { display: none; }

.search {
  position: relative; display: flex; align-items: center; gap: 8px;
  background: var(--surface); color: var(--ink); border-radius: 20px; padding: 8px 10px 8px 8px;
  box-shadow: 0 20px 50px -18px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.12);
}
.search:focus-within { box-shadow: 0 20px 50px -18px rgba(0,0,0,.6), 0 0 0 4px rgba(245,196,81,.55); }
.dir-chip {
  flex: none; font-size: 13px; font-weight: 600; padding: 8px 12px; border-radius: 14px;
  background: var(--brand-soft); color: var(--brand); white-space: nowrap; transition: background .2s, color .2s;
}
.dir-chip.en { background: var(--gold-soft); color: var(--gold); }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 19px; padding: 10px 4px;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }
.clear { border: 0; background: var(--surface-2); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; color: var(--muted); flex: none; }
.clear:hover { color: var(--ink); }
.kbd-hint { flex: none; color: var(--muted); }
.history { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 16px; min-height: 0; }
.history:empty { display: none; }
.history button {
  border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.07); color: var(--hero-ink);
  padding: 4px 12px; border-radius: 999px; font-size: 14px; cursor: pointer;
}
.history button:hover { background: rgba(255,255,255,.16); }
.history .label { font-size: 13px; opacity: .6; align-self: center; }

/* ---------- layout ---------- */
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 28px 16px 40px; outline: none; }
.section { margin-bottom: 40px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-family: var(--font-serif-th); font-size: 24px; }
.section-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.link-btn { border: 0; background: none; color: var(--brand); font-weight: 600; cursor: pointer; padding: 6px 0; text-decoration: none; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: -58px auto 32px; max-width: 760px; position: relative; z-index: 2; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; text-align: center; box-shadow: var(--shadow-2); border: 1px solid var(--line); }
.stat b { display: block; font-family: var(--font-serif-en); font-weight: 700; font-size: 28px; line-height: 1.1; color: var(--brand); }
.stat span { font-size: 13px; color: var(--muted); }

/* word of the day */
.wotd {
  position: relative; overflow: hidden; display: grid; grid-template-columns: 1.1fr 1fr; gap: 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 28px; box-shadow: var(--shadow-1);
}
.wotd::after {
  content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--gold) 28%, transparent), transparent 70%); pointer-events: none;
}
.eyebrow { font-size: 13px; font-weight: 700; color: var(--gold); }
.wotd .head-th { font-family: var(--font-serif-th); font-size: clamp(34px, 5vw, 48px); line-height: 1.38; margin: 6px 0 2px; cursor: pointer; }
.wotd .head-en { font-family: var(--font-serif-en); font-weight: 600; font-size: 24px; color: var(--teal); }
.wotd .ex-list { margin: 0; }

/* categories */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.cat-card {
  --c: #4f46e5; position: relative; overflow: hidden; display: flex; align-items: center; gap: 14px;
  padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow-1);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s;
}
.cat-card::before {
  content: ""; position: absolute; inset: 0; opacity: .08; pointer-events: none;
  background: linear-gradient(120deg, var(--c), transparent 70%);
}
.cat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-2); border-color: color-mix(in srgb, var(--c) 45%, var(--line)); }
.cat-icon {
  flex: none; width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 26px;
  background: color-mix(in srgb, var(--c) 16%, var(--surface)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 25%, transparent);
}
.cat-card b { display: block; font-size: 16px; line-height: 1.35; }
.cat-card small { display: block; color: var(--muted); font-size: 12.5px; }
.cat-count { margin-left: auto; font-family: var(--font-serif-en); font-weight: 700; font-size: 20px; color: var(--c); }
.legal-band {
  border-radius: 24px; padding: 20px; margin-bottom: 18px;
  background: linear-gradient(135deg, color-mix(in srgb, #b45309 12%, var(--surface)), var(--surface));
  border: 1px solid color-mix(in srgb, #b45309 30%, var(--line));
}
.legal-band h3 { margin: 0 0 4px; font-family: var(--font-serif-th); font-size: 20px; }
.legal-band p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }

/* results */
.results-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 22px; align-items: start; }
.results { display: flex; flex-direction: column; gap: 8px; }
.results-meta { color: var(--muted); font-size: 14px; margin: 0 0 10px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.group-label { font-size: 13px; font-weight: 700; color: var(--muted); margin: 14px 0 2px; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; width: 100%; text-align: left;
  padding: 12px 16px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line);
  cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .12s;
}
.row:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.row.sel { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.row .w { font-size: 18px; font-weight: 600; }
.row .w .alt { font-weight: 400; color: var(--muted); font-size: 14px; margin-left: 6px; }
.row .t { grid-column: 1 / -1; color: var(--ink-2); font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .t i { color: var(--muted); font-style: normal; }
.row mark, .ex mark, .card-face mark { background: var(--mark); color: var(--mark-ink); border-radius: 3px; padding: 0; box-shadow: 0 0 0 2px var(--mark); -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.pos {
  display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.pos.n { background: #e0f2fe; color: #075985; } .pos.v { background: #fee2e2; color: #991b1b; }
.pos.adj { background: #f3e8ff; color: #6b21a8; } .pos.adv { background: #fae8ff; color: #86198f; }
.pos.phrase { background: #ffedd5; color: #9a3412; } .pos.idiom { background: #ffe4e6; color: #9f1239; }
.pos.clf, .pos.num { background: #cffafe; color: #155e75; } .pos.pron { background: #dcfce7; color: #166534; }
:root[data-theme="dark"] .pos, :root[data-theme="dark"] .pos[class] { background: var(--surface-3); color: var(--ink-2); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pos[class] { background: var(--surface-3); color: var(--ink-2); } }

/* detail */
.detail {
  position: sticky; top: 76px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px;
  box-shadow: var(--shadow-2); overflow: hidden; max-height: calc(100vh - 96px); overflow-y: auto;
}
.detail-empty { padding: 48px 28px; text-align: center; color: var(--muted); }
.detail-empty .big { font-size: 46px; }
.d-head { --c: var(--brand); padding: 26px 28px 18px; background: linear-gradient(160deg, color-mix(in srgb, var(--c) 12%, var(--surface)), var(--surface) 70%); border-bottom: 1px solid var(--line); }
.d-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.d-th { font-family: var(--font-serif-th); font-size: clamp(32px, 4.5vw, 44px); line-height: 1.38; margin: 4px 0 0; }
.d-roman { color: var(--muted); font-size: 15px; }
.d-en { margin: 14px 0 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.d-en .main { font-family: var(--font-serif-en); font-size: 28px; font-weight: 600; color: var(--teal); }
.d-en .more { font-size: 16px; color: var(--ink-2); }
.d-read { font-size: 14px; color: var(--muted); margin-top: 2px; }
.d-read b { color: var(--ink-2); font-weight: 600; }
.d-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  padding: 8px 14px; border-radius: 12px; cursor: pointer; font-size: 14px; font-weight: 500; text-decoration: none; color: var(--ink);
  transition: background .12s, border-color .12s, transform .08s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); background: var(--brand); }
.btn.on { background: var(--gold-soft); border-color: color-mix(in srgb, var(--gold) 50%, transparent); color: var(--gold); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 10px; }
.speak { border: 0; background: var(--surface-2); width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 14px; flex: none; display: inline-grid; place-items: center; }
.speak:hover { background: var(--brand-soft); }
.speak.playing { background: var(--brand); color: var(--brand-ink); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }
.d-body { padding: 20px 28px 28px; }
.d-body h4 { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.note {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: 14px; margin-bottom: 20px; font-size: 14.5px;
  background: var(--gold-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--gold) 28%, transparent);
}
.ex-list { list-style: none; padding: 0; margin: 0 0 22px; display: flex; flex-direction: column; gap: 12px; }
.ex { position: relative; padding: 14px 16px 14px 18px; border-radius: 16px; background: var(--surface-2); border-left: 4px solid var(--c, var(--brand)); }
.ex .line { display: flex; gap: 10px; align-items: flex-start; }
.ex .line + .line { margin-top: 6px; }
.ex .line p { margin: 0; flex: 1; }
.ex .th { font-size: 17px; }
.ex .en { font-family: var(--font); font-size: 16px; font-weight: 400; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  --c: var(--brand); display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  font-size: 13.5px; text-decoration: none; color: var(--ink); cursor: pointer;
  background: color-mix(in srgb, var(--c) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c) 25%, transparent);
}
.chip:hover { background: color-mix(in srgb, var(--c) 22%, var(--surface)); }
.related { display: flex; flex-wrap: wrap; gap: 8px; }
.related button { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 12px; cursor: pointer; font-size: 14px; }
.related button:hover { border-color: var(--brand); }
.related button small { color: var(--muted); margin-left: 4px; }

/* empty / not found */
.empty { text-align: center; padding: 40px 20px; background: var(--surface); border: 1px dashed var(--line); border-radius: 24px; }
.empty .big { font-size: 50px; }
.empty h3 { margin: 6px 0; font-family: var(--font-serif-th); font-size: 22px; }
.empty p { color: var(--muted); margin: 4px 0 16px; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 18px; }

/* category page */
.cat-hero {
  --c: var(--brand); display: flex; align-items: center; gap: 18px; padding: 22px; border-radius: 24px; margin-bottom: 18px;
  background: linear-gradient(120deg, color-mix(in srgb, var(--c) 18%, var(--surface)), var(--surface) 75%);
  border: 1px solid color-mix(in srgb, var(--c) 28%, var(--line));
}
.cat-hero .cat-icon { width: 72px; height: 72px; font-size: 38px; border-radius: 22px; }
.cat-hero h2 { margin: 0; font-family: var(--font-serif-th); font-size: clamp(24px, 3.5vw, 32px); line-height: 1.25; }
.cat-hero p { margin: 2px 0 0; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.field {
  display: flex; align-items: center; gap: 8px; flex: 1 1 240px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 0 12px;
}
.field input, .field select { border: 0; outline: 0; background: transparent; font: inherit; color: var(--ink); padding: 10px 0; width: 100%; }
.select { flex: 0 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 9px 12px; font: inherit; color: var(--ink); }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13.5px; }
.filter-chips button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.word-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.wcard {
  --c: var(--brand); position: relative; text-align: left; padding: 16px 16px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); cursor: pointer; box-shadow: var(--shadow-1);
  transition: transform .15s, box-shadow .15s, border-color .15s; display: flex; flex-direction: column; gap: 4px; min-height: 132px;
}
.wcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: color-mix(in srgb, var(--c) 40%, var(--line)); }
.wcard .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.wcard .w { font-size: 20px; font-weight: 600; line-height: 1.3; }
.wcard .e { font-family: var(--font-serif-en); font-weight: 600; color: var(--teal); font-size: 16.5px; }
.wcard .s { color: var(--muted); font-size: 13.5px; margin-top: auto; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.wcard .fav { position: absolute; right: 12px; bottom: 10px; font-size: 14px; }
.more-wrap { text-align: center; margin-top: 18px; }

/* flashcards */
.fc-setup { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 20px; }
.fc-setup label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 600; }
.fc-stage { max-width: 620px; margin: 0 auto; }
.fc-progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-bottom: 14px; }
.fc-progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--teal)); width: 0; transition: width .3s; }
.fc-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.card3d { perspective: 1400px; cursor: pointer; }
.card3d .inner { position: relative; height: 340px; transition: transform .6s cubic-bezier(.2,.8,.2,1); transform-style: preserve-3d; }
.card3d.flipped .inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 28px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 28px; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2);
}
.card-face.front { background: linear-gradient(150deg, var(--hero-1), var(--hero-2)); color: var(--hero-ink); border: 0; }
.card-face.back { transform: rotateY(180deg); }
.card-face .big-th { font-family: var(--font-serif-th); font-size: clamp(36px, 7vw, 56px); line-height: 1.38; }
.card-face .big-en { font-family: var(--font-serif-en); font-weight: 600; font-size: clamp(30px, 6vw, 46px); line-height: 1.2; }
.card-face.front .big-en { color: #ffd86b; }
.card-face .hint { position: absolute; bottom: 16px; font-size: 13px; opacity: .6; }
.card-face .ans { font-family: var(--font-serif-en); font-weight: 600; font-size: 28px; color: var(--teal); }
.card-face .ans.th { font-family: var(--font-serif-th); }
.card-face .ex-mini { font-size: 14.5px; color: var(--ink-2); max-width: 460px; }
.fc-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.fc-buttons .btn { justify-content: center; padding: 14px; font-size: 16px; border-radius: 16px; }
.btn.bad { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); color: var(--danger); }
.btn.good { background: var(--ok); color: #fff; border-color: transparent; }
.fc-done { text-align: center; padding: 30px; background: var(--surface); border-radius: 28px; border: 1px solid var(--line); box-shadow: var(--shadow-2); }
.fc-done .score { font-family: var(--font-serif-en); font-weight: 700; font-size: 64px; color: var(--brand); line-height: 1; }

/* sheet (mobile detail) */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 8, 30, .55); animation: fade .2s; }
.sheet-panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); overflow-y: auto; background: var(--surface); border-radius: 26px; box-shadow: var(--shadow-2);
  animation: pop .22s cubic-bezier(.2,.8,.2,1);
}
.sheet-close { position: absolute; right: 14px; top: 14px; z-index: 2; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--surface-2); cursor: pointer; font-size: 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -46%) scale(.98); } }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; z-index: 60; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 14px; font-size: 14.5px; box-shadow: var(--shadow-2);
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot { text-align: center; padding: 22px 16px 30px; color: var(--muted); font-size: 13.5px; border-top: 1px solid var(--line); }
.foot p { margin: 4px 0; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .results-wrap { grid-template-columns: 1fr; }
  .detail.side { display: none; }
  .wotd { grid-template-columns: 1fr; padding: 22px; }
}
@media (max-width: 720px) {
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .topbar { padding: 8px 16px; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--hero-1); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; margin: 0; justify-content: space-around; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--hero-1) 96%, transparent);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid rgba(255,255,255,.1);
  }
  .tabs a { flex-direction: column; gap: 0; font-size: 11.5px; padding: 6px 8px; border-radius: 12px; flex: 1; }
  .tabs a span:first-child { font-size: 20px; }
  .tabs .badge { position: absolute; top: 2px; right: calc(50% - 22px); }
  #themeBtn { margin-left: auto; }
  .hero { padding: 34px 16px 52px; }
  .hero-deco span:first-child { font-size: 220px; }
  .hero-deco span:last-child { font-size: 200px; bottom: -70px; }
  .kbd-hint { display: none; }
  .search input { font-size: 17px; }
  .dir-chip { padding: 6px 9px; font-size: 12px; }
  .stats { gap: 8px; margin-top: -46px; }
  .stat { padding: 10px 6px; }
  .stat b { font-size: 22px; }
  .stat span { font-size: 12px; }
  .cat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .cat-card { flex-direction: column; align-items: flex-start; gap: 8px; padding: 14px; }
  .cat-count { position: absolute; right: 12px; top: 10px; font-size: 16px; }
  .cat-card b { font-size: 14.5px; }
  .word-grid { grid-template-columns: 1fr; }
  .sheet-panel {
    left: 0; right: 0; top: auto; bottom: 0; transform: none; width: 100%; max-height: 90vh;
    border-radius: 24px 24px 0 0; animation: slideup .25s cubic-bezier(.2,.8,.2,1);
  }
  .d-head, .d-body { padding-left: 18px; padding-right: 18px; }
  .card3d .inner { height: 300px; }
  .cat-hero { padding: 16px; gap: 12px; }
  .cat-hero .cat-icon { width: 56px; height: 56px; font-size: 30px; }
  .foot .muted { display: none; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ================= 📄 หนังสือรับรอง ================= */
@font-face { font-family: "CertSarabun"; src: url("fonts/THSarabunNew.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: block; }
@font-face { font-family: "CertSarabun"; src: url("fonts/THSarabunNew-Bold.ttf") format("truetype"); font-weight: 700; font-style: normal; font-display: block; }
body.cert-mode .hero { display: none; }
.cert-wrap { display: grid; grid-template-columns: minmax(320px, 430px) minmax(0, 1fr); gap: 24px; align-items: start; }
.cert-form { display: flex; flex-direction: column; gap: 14px; }
.cert-types { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ctype {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 12px; border-radius: 16px;
  border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.ctype span { font-size: 22px; line-height: 1; }
.ctype b { font-size: 14.5px; line-height: 1.3; }
.ctype small { font-size: 12px; color: var(--muted); line-height: 1.35; }
.ctype.on { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); background: color-mix(in srgb, var(--brand) 6%, var(--surface)); }
.cset { border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px 6px; margin: 0; background: var(--surface); box-shadow: var(--shadow-1); }
.cset legend { font-weight: 700; padding: 0 6px; font-size: 15px; }
.cset legend small { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.cf { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.cf-l { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.cf input, .cf select, .cf textarea {
  width: 100%; font: inherit; font-size: 15px; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 12px; outline: none; transition: border-color .15s, background .15s;
}
.cf textarea { resize: vertical; line-height: 1.5; font-family: var(--font); }
.cf input:focus, .cf select:focus, .cf textarea:focus { border-color: var(--brand); background: var(--surface); }
.cf small { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.cf .pre { display: flex; align-items: center; gap: 8px; }
.cf .pre span { font-weight: 600; color: var(--muted); }
.cf.helper input { background: color-mix(in srgb, var(--gold) 8%, var(--surface)); }
.cf-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.cf-row.narrow { grid-template-columns: 110px 1fr; }
.cf-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: -6px 0 12px; }
.linkish { border: 0; background: none; color: var(--brand); padding: 0; cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600; text-decoration: underline; }
.cert-side { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 10px; }
.cert-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.cert-status { font-size: 13.5px; color: var(--muted); flex: 1 1 220px; }
.cert-status .warn { color: var(--danger); font-weight: 600; }
.cert-status .okay { color: var(--ok); font-weight: 600; }
.cert-note { font-size: 12.5px; margin: 0; }
.paper-frame { position: relative; overflow: hidden; border-radius: 4px; box-shadow: 0 18px 50px -18px rgba(0,0,0,.45), 0 0 0 1px rgba(0,0,0,.06); background: #fff; }
.paper-scale { transform-origin: top left; width: 210mm; }

/* หน้ากระดาษ A4 — ขนาดและระยะตามแบบฟอร์ม Word ของศาล (ขอบ บน 1.5 ขวา 2 ล่าง 1 ซ้าย 3 ซม., TH Sarabun 17pt) */
.paper {
  position: relative; box-sizing: border-box; width: 210mm; height: 297mm; overflow: hidden;
  padding: 1.5cm 1.8cm 1cm 3cm; background: #fff; color: #000; /* ขวา 2 ซม. ตามแบบ แต่ Word ยอมให้บรรทัดชิดขอบล้นได้ ~5pt จึงใช้ 1.8 ซม. เพื่อให้ตัดบรรทัดตรงกับต้นฉบับ */
  font-family: "CertSarabun", "TH Sarabun New", "TH SarabunPSK", sans-serif; font-size: 17pt; line-height: 22.3pt;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.paper .garuda { position: absolute; top: 42pt; left: 268.3pt; width: 80.7pt; height: 87.9pt; }
.paper .p-head { display: flex; align-items: flex-start; gap: 12pt; margin-top: var(--head-top, 69pt); }
.paper .p-no { flex: none; white-space: nowrap; }
.paper .p-addr { margin-left: auto; margin-right: -0.8cm; min-width: 6cm; } /* เริ่มที่แท็บ 11 ซม. เหมือนแบบ Word บรรทัดยาวล้นขอบขวาได้ถึง 1 ซม. จากขอบกระดาษ */
.paper .p-blank { height: 22.3pt; }
.paper .p-salute { text-align: center; font-weight: 700; }
.paper .p-body { margin: 0; text-indent: 2.5cm; text-align: justify; text-justify: inter-word; }
.paper .p-body.next { margin-top: 6pt; }
.paper .p-given { text-align: center; }
.paper .p-sign { width: 10cm; margin-left: 4.5cm; text-align: center; }
.paper .p-signline { height: 22.3pt; }
.paper .ph { background: #fff1a8; color: #9a5b00; border-radius: 3px; padding: 0 2pt; font-family: var(--font); font-size: 11pt; vertical-align: 1pt; }

@media (max-width: 1000px) {
  .cert-wrap { grid-template-columns: 1fr; }
  .cert-side { position: static; }
}
@media (max-width: 720px) {
  .cert-types { grid-template-columns: 1fr; }
  .ctype { flex-direction: row; align-items: center; gap: 10px; }
  .ctype small { display: none; }
  .cf-row { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; min-height: 0 !important; }
  body.printing-cert > *:not(#printRoot) { display: none !important; }
  #printRoot .paper { height: 296.8mm; box-shadow: none; transform: none; break-after: avoid; page-break-after: avoid; }
  .paper .ph { visibility: hidden; }
  /* สำรอง กรณีเบราว์เซอร์ไม่ส่งเหตุการณ์ beforeprint */
  body.cert-mode:not(.printing-cert) .topbar, body.cert-mode:not(.printing-cert) .hero, body.cert-mode:not(.printing-cert) .foot,
  body.cert-mode:not(.printing-cert) .cert-form, body.cert-mode:not(.printing-cert) .cert-bar, body.cert-mode:not(.printing-cert) .cert-note,
  body.cert-mode:not(.printing-cert) .section-head, body.cert-mode:not(.printing-cert) .toast, body.cert-mode:not(.printing-cert) .skip { display: none !important; }
  body.cert-mode:not(.printing-cert) main { padding: 0 !important; max-width: none; }
  body.cert-mode:not(.printing-cert) .cert-wrap { display: block; }
  body.cert-mode:not(.printing-cert) .paper-frame { height: auto !important; box-shadow: none; border-radius: 0; }
  body.cert-mode:not(.printing-cert) .paper-scale { transform: none !important; }
  body.cert-mode:not(.printing-cert) .paper { height: 296.8mm; }
}

/* ---- fixes: ความกว้างพรีวิวกระดาษ และแถบเมนู 5 แท็บ ---- */
.cert-wrap > * { min-width: 0; }
.paper-frame { width: 100%; }
.tabs a { white-space: nowrap; }
@media (max-width: 1000px) { .cert-wrap { grid-template-columns: minmax(0, 1fr); } }
@media (min-width: 721px) and (max-width: 1060px) {
  .topbar { gap: 10px; }
  .tabs { gap: 2px; }
  .tabs a { padding: 8px 10px; font-size: 14px; gap: 5px; }
  .brand-text small { display: none; }
}
@media (min-width: 721px) and (max-width: 860px) {
  .tabs a span:nth-child(2) { display: none; }
  .tabs a { padding: 8px 12px; font-size: 18px; }
}
.cert-types { grid-template-columns: 1fr; gap: 6px; }
.ctype { display: grid; grid-template-columns: 30px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 10px 12px; }
.ctype span { grid-row: 1 / 3; }
.ctype small { display: block !important; }
.paper.tight .p-blank { height: 11pt; }
.paper.tighter .p-blank { height: 4pt; }
.paper.tighter .p-signline { height: 18pt; }

/* ================= 📊 แบบประเมิน ================= */
body.no-hero .hero { display: none; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.seg a { padding: 7px 14px; border-radius: 10px; text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: 14px; }
.seg a.on { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-1); }
.survey { display: flex; flex-direction: column; gap: 16px; max-width: 900px; }
.choice { display: flex; flex-wrap: wrap; gap: 8px; }
.choice.col { flex-direction: column; gap: 6px; }
.choice label { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); cursor: pointer; font-size: 14.5px; }
.choice label:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--surface)); }
.choice input { accent-color: var(--brand); width: 16px; height: 16px; }
.s-hint { font-size: 13px; margin: 0 0 10px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.rate-table, .res-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14.5px; }
.rate-table th, .rate-table td, .res-table th, .res-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: center; }
.rate-table tbody th, .res-table tbody th { text-align: left; font-weight: 500; min-width: 200px; }
.rate-table thead th, .res-table thead th { font-size: 13px; color: var(--muted); font-weight: 700; }
.rate { display: inline-grid; place-items: center; cursor: pointer; }
.rate input { position: absolute; opacity: 0; pointer-events: none; }
.rate span { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; color: var(--ink-2); transition: all .12s; }
.rate:hover span { border-color: var(--brand); }
.rate input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); transform: scale(1.06); }
.rate input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }
.rate.na input:checked + span { background: var(--muted); border-color: var(--muted); }
.survey-submit { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 35%); }
.survey-submit .btn { padding: 12px 26px; font-size: 16px; }
.warn { color: var(--danger); font-weight: 600; }
.s-actions { margin: 0 0 18px; }
.s-stats { margin: 0 0 22px; max-width: none; }
.s-h { font-family: var(--font-serif-th); font-size: 19px; margin: 22px 0 8px; }
.res-table td b { color: var(--brand); }
.lvl { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; background: var(--surface-2); }
.lvl.l5 { background: #dcfce7; color: #166534; } .lvl.l4 { background: #e0f2fe; color: #075985; } .lvl.l3 { background: #fef9c3; color: #854d0e; }
.lvl.l2, .lvl.l1 { background: #fee2e2; color: #991b1b; }
.bar-cell { width: 30%; }
.sbar { display: inline-block; width: 100%; height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; vertical-align: middle; }
.sbar.sm { width: 120px; height: 8px; margin: 0 10px; }
.sbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--teal)); border-radius: 999px; }
.s-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.s-list { list-style: none; padding: 0; margin: 0; }
.s-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.s-list li span:first-child { flex: 1; }
.s-notes { padding-left: 20px; margin: 0; } .s-notes li { margin-bottom: 8px; } .s-notes small { color: var(--muted); }
@media (max-width: 720px) {
  .s-grid { grid-template-columns: 1fr; }
  .rate span { width: 32px; height: 32px; }
  .rate-table tbody th { min-width: 150px; font-size: 13.5px; }
  .tabs a { font-size: 10.5px; padding: 6px 2px; min-width: 0; }
  .tabs a span:nth-child(2) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
}
@media print {
  body.printing-survey .topbar, body.printing-survey .hero, body.printing-survey .foot, body.printing-survey .seg,
  body.printing-survey .s-actions, body.printing-survey .toast { display: none !important; }
  body.printing-survey { background: #fff !important; color: #000; }
  body.printing-survey main { padding: 0; }
}
@media (max-width: 720px) {
  .tabs a { flex: 1 1 0; min-width: 0; padding: 6px 0; font-size: 11px; }
  .tabs a span:nth-child(2) { display: none; }
  .tabs a::after { content: attr(data-short); white-space: nowrap; }
  .rate-table th, .rate-table td { padding: 7px 2px; }
  .rate-table tbody th { min-width: 118px; font-size: 13px; }
  .rate span { width: 30px; height: 30px; font-size: 13px; }
  .res-table tbody th { min-width: 140px; font-size: 13.5px; }
  .bar-cell { display: none; }
}
/* ชื่อโปรแกรม Dictionary (อักษรละติน) */
.brand-text b { font-family: var(--font-serif-en); font-size: 21px; letter-spacing: 0; }
.brand-mark { font-family: var(--font-serif-en); }

.group-toggle { border: 1px dashed var(--line); background: transparent; color: var(--brand); font: inherit; font-size: 14px; font-weight: 600; padding: 9px 12px; border-radius: 12px; cursor: pointer; text-align: left; margin-top: 2px; }
.group-toggle:hover { background: var(--surface); border-color: var(--brand); }
.gov-band { background: linear-gradient(135deg, color-mix(in srgb, #1d4ed8 10%, var(--surface)), var(--surface)); border-color: color-mix(in srgb, #1d4ed8 28%, var(--line)); }
