:root {
  --bg: #ffffff;
  --fg: #111113;
  --muted: #68686e;
  --faint: #8e8e94;
  --line: #e6e6e9;
  --surface: #f4f4f5;
  --ui: "Anuphan", "Leelawadee UI", system-ui, sans-serif;
  --word: "Noto Sans Thai Looped", "Leelawadee UI", "Anuphan", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f10;
    --fg: #ededee;
    --muted: #a2a2a8;
    --faint: #77777d;
    --line: #27272a;
    --surface: #1b1b1d;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f0f10;
  --fg: #ededee;
  --muted: #a2a2a8;
  --faint: #77777d;
  --line: #27272a;
  --surface: #1b1b1d;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 400 16px/1.6 var(--ui); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { width: 100%; max-width: 860px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 700px) { .wrap { padding: 0 24px; } }

.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.bar-row { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { text-decoration: none; font-weight: 500; letter-spacing: .01em; }
.tools { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px;
  background: none; color: var(--muted);
}
.icon-btn:hover { background: var(--surface); color: var(--fg); }
.icon-btn.sm { width: 30px; height: 30px; }
/* the icon shows what a click switches to: moon while light, sun while dark */
#theme .sun { display: none; }
:root[data-dark="1"] #theme .moon { display: none; }
:root[data-dark="1"] #theme .sun { display: block; }

.lang { display: flex; align-items: center; gap: 2px; margin-right: 4px; color: var(--muted); }
.lang .i { margin-right: 4px; }
.lang button { border: 0; border-radius: 6px; background: none; padding: 3px 8px; font-size: 14px; color: var(--muted); }
.lang button:hover { color: var(--fg); }
.lang button[aria-pressed="true"] { background: var(--surface); color: var(--fg); font-weight: 500; }

/* ---------- search ---------- */
h1 { margin: 28px 0 0; font: 500 clamp(64px, 12vw, 96px)/1.15 var(--word); }
.sub { margin: 6px 0 0; max-width: 34em; font-size: 18px; }
.uses { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
@media (max-width: 560px) { h1 { margin-top: 12px; } .sub { font-size: 17px; } }

.search {
  display: flex; align-items: center; gap: 10px; margin-top: 22px; padding: 0 10px 0 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  transition: border-color .12s;
}
.search:focus-within { border-color: var(--fg); }
.search > .i { width: 20px; height: 20px; color: var(--faint); }
#q {
  flex: 1; min-width: 0; border: 0; background: none; padding: 13px 0;
  font: 500 24px/1.4 var(--word); letter-spacing: .02em;
}
#q:focus { outline: none; }
#q::placeholder { color: var(--faint); font-weight: 400; opacity: .8; }
kbd {
  display: none; min-width: 24px; padding: 1px 6px; border: 1px solid var(--line); border-radius: 6px;
  font: 12px/1.6 var(--mono); color: var(--faint); text-align: center;
}
@media (pointer: fine) { .search:not(:focus-within) kbd.on { display: block; } }

.modes { display: flex; gap: 22px; margin-top: 14px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.modes::-webkit-scrollbar { display: none; }
.modes button {
  flex: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none;
  padding: 8px 0; color: var(--muted); white-space: nowrap;
}
.modes button:hover { color: var(--fg); }
.modes button[aria-selected="true"] { color: var(--fg); font-weight: 500; border-bottom-color: var(--fg); }
.hint { margin: 10px 0 0; min-height: 1.6em; font-size: 14px; color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; }
.f {
  display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 8px; background: none; color: var(--muted);
}
.f input {
  width: 3.4em; border: 0; background: none; padding: 0; text-align: center; color: var(--fg);
  -moz-appearance: textfield; appearance: textfield;
}
.f input::-webkit-outer-spin-button, .f input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.f input::placeholder { color: var(--faint); }
.f input:focus, .f select:focus { outline: none; }
.f:focus-within { border-color: var(--fg); }
.f select { border: 0; background: var(--bg); color: var(--fg); padding: 0 2px 0 0; }
.toggle:hover, .toggle[aria-expanded="true"], .toggle[aria-pressed="true"] { color: var(--fg); }
.toggle[aria-expanded="true"], .toggle[aria-pressed="true"] { background: var(--surface); }
.toggle[aria-pressed="true"] { border-color: var(--fg); }
.seg { display: flex; height: 36px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; }
.seg button {
  display: flex; align-items: center; gap: 6px; border: 0; border-radius: 5px; background: none;
  padding: 0 9px; color: var(--muted);
}
.seg button:hover { color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); }
.seg .i, .f .i { width: 16px; height: 16px; }

.kbd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px; margin-top: 10px; }
.kbd-grid[hidden] { display: none; }
.kbd-grid button { height: 40px; border: 1px solid var(--line); border-radius: 8px; background: none; font: 400 18px/1 var(--word); }
.kbd-grid button:hover { background: var(--surface); }
.kbd-grid button.wide { grid-column: span 2; font: 14px/1 var(--ui); color: var(--muted); }

/* ---------- results ---------- */
.meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px; margin-top: 30px; min-height: 36px; }
#count { margin: 0; color: var(--muted); }
#count b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
#count .ms { margin-left: 8px; font: 12px var(--mono); color: var(--faint); }
.acts { display: flex; gap: 2px; margin-right: -8px; }
.ghost {
  display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 9px; border: 0; border-radius: 8px;
  background: none; font-size: 14px; color: var(--muted);
}
.ghost:hover { background: var(--surface); color: var(--fg); }
.ghost .i { width: 16px; height: 16px; }
.ghost[hidden] { display: none; }
@media (max-width: 520px) { .ghost span { display: none; } .ghost { width: 36px; justify-content: center; padding: 0; } }

.results { margin-top: 8px; min-height: 7rem; }
.words { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.6rem, 1fr)); grid-auto-flow: dense; gap: 0 8px; margin: 0 -10px; }
.w {
  border: 0; border-radius: 8px; background: none; padding: 5px 10px; text-align: left;
  font: 400 18px/1.7 var(--word); color: var(--fg); white-space: nowrap;
}
.w:hover { background: var(--surface); }
.w.wide { grid-column: span 2; }
.w.l1 { color: var(--muted); }
.w.l0 { color: var(--faint); }
@media (max-width: 480px) { .words { grid-template-columns: repeat(2, 1fr); } }

.fams { border-top: 1px solid var(--line); }
.fam { display: grid; grid-template-columns: 6.5rem 1fr; gap: 0 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.stem { display: flex; align-items: center; gap: 4px; height: 41px; font: 500 18px/1 var(--word); }
.stem .i { width: 15px; height: 15px; color: var(--faint); }
.stem.other { font: 14px/1 var(--ui); color: var(--muted); }
.fam-words { display: flex; flex-wrap: wrap; gap: 0 2px; margin-left: -10px; }
@media (max-width: 480px) { .fam { grid-template-columns: 1fr; } .stem { height: 30px; } }

.note { margin: 0 0 10px; font-size: 14px; color: var(--muted); }
.idle { padding: 6px 0; color: var(--muted); font-size: 14px; }
.idle p { margin: 0 0 8px; }
.tries { display: flex; flex-wrap: wrap; gap: 6px; }
.tries button { display: flex; align-items: baseline; gap: 8px; border: 1px solid var(--line); border-radius: 8px; background: none; padding: 5px 11px; }
.tries button:hover { border-color: var(--fg); }
.tries small { font-size: 13px; color: var(--muted); }
.tries span { font: 400 17px/1.5 var(--word); }

.more-row { display: flex; justify-content: center; margin-top: 16px; }
.btn { border: 1px solid var(--line); border-radius: 8px; background: none; padding: 8px 16px; font-size: 14px; }
.btn:hover { border-color: var(--fg); }
.legend { margin: 14px 0 0; font-size: 13px; color: var(--faint); }

/* ---------- about ---------- */
.about { margin-top: 72px; }
.about h2 { margin: 0 0 12px; font: 600 18px/1.4 var(--ui); }
.about p { margin: 0 0 10px; color: var(--muted); }
.rows { margin: 0; border-top: 1px solid var(--line); }
.rows > div { display: grid; grid-template-columns: 11rem 1fr; gap: 4px 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.rows dt { font-weight: 500; }
.rows dd { margin: 0; color: var(--muted); }
@media (max-width: 600px) { .rows > div { grid-template-columns: 1fr; } }
pre {
  margin: 0 0 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px;
  font: 13.5px/1.75 var(--mono); overflow-x: auto;
}
pre .c { color: var(--faint); }

.foot { margin-top: 72px; border-top: 1px solid var(--line); padding: 18px 0 28px; font-size: 14px; color: var(--muted); }
.foot-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 20px; }
.foot p { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 20px; translate: -50% 8px; max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 14px; padding: 9px 14px; border-radius: 10px;
  background: var(--fg); color: var(--bg); font-size: 14px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .15s, translate .15s;
}
.toast.show { opacity: 1; translate: -50% 0; pointer-events: auto; }
.toast a { display: flex; align-items: center; gap: 3px; text-underline-offset: 3px; }
.toast .i { width: 14px; height: 14px; }
@media (prefers-reduced-motion: reduce) { .toast, .search { transition: none; } }

/* ---------- static word pages (built by scripts/build_pages.py) ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; font-size: 14px; color: var(--muted); }
.crumbs a { text-underline-offset: 3px; }
.static { padding-top: 20px; }
.static h1 { margin: 10px 0 0; font: 600 clamp(26px, 5vw, 36px)/1.3 var(--ui); }
.static h2 { margin: 36px 0 10px; font: 600 18px/1.4 var(--ui); }
.static .sub { max-width: 42em; color: var(--muted); font-size: 16px; }
.static .sub b { color: var(--fg); font-weight: 500; }
.cta { display: inline-block; margin-top: 6px; text-decoration: none; }
.wordlist { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(8.6rem, 1fr)); gap: 0 14px; margin: 0; padding: 0; }
.wordlist li { padding: 4px 0; font: 400 18px/1.7 var(--word); overflow-wrap: anywhere; }
@media (max-width: 480px) { .wordlist { grid-template-columns: repeat(2, 1fr); } }
.links { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; }
.links a { border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; text-decoration: none; font: 400 17px/1.6 var(--word); }
.links a:hover { border-color: var(--fg); }
.links small { margin-left: 4px; font: 13px var(--ui); color: var(--muted); }
.links.letters a { min-width: 42px; text-align: center; }
.static .note { margin-top: 28px; }
