:root {
  --fs: 19px;
  --bg: #f7f3ea;
  --card: #fffdf8;
  --ink: #2d2a26;
  --muted: #7a7266;
  --line: #e7dfd0;
  --accent: #2f6f4f;
  --accent-soft: #e6f0e9;
  --q-bg: #fbf3df;
  --q-line: #d9a640;
  --chip: #efe8da;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a17; --card: #24221e; --ink: #e8e2d6; --muted: #a39b8d; --line: #37332c;
    --accent: #8fc7a6; --accent-soft: #23332a; --q-bg: #2c2618; --q-line: #b8893a; --chip: #2f2c26;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1a17; --card: #24221e; --ink: #e8e2d6; --muted: #a39b8d; --line: #37332c;
  --accent: #8fc7a6; --accent-soft: #23332a; --q-bg: #2c2618; --q-line: #b8893a; --chip: #2f2c26;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'Sarabun', 'Noto Sans Thai', system-ui, sans-serif;
  font-size: 17px; line-height: 1.7;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
.wrap { max-width: 40rem; margin: 0 auto; padding: 0 18px 40px; }

/* top bar: hides on scroll down, returns on scroll up */
.top {
  /* solid background: backdrop-filter blanked the page while scrolling in some browsers */
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  border-bottom: 1px solid var(--line); transition: transform .25s ease;
  padding-top: env(safe-area-inset-top);
}
.top.hide { transform: translateY(-100%); }
.top-in { max-width: 40rem; margin: 0 auto; display: flex; align-items: center; gap: 4px; padding: 6px 10px; }
.brand { font-weight: 700; text-decoration: none; font-size: 18px; display: flex; gap: 6px; align-items: center; padding: 0 6px; }
.spacer { flex: 1; }
.icon-btn {
  min-width: 44px; height: 44px; border: 0; background: transparent; border-radius: 12px;
  font-size: 18px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; cursor: pointer;
}
.icon-btn:active { background: var(--chip); }
.progress { height: 3px; width: 0; background: var(--accent); }

.font-panel {
  position: fixed; z-index: 30; top: calc(60px + env(safe-area-inset-top)); right: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px;
  display: flex; align-items: center; gap: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.12); font-size: 14px; color: var(--muted);
}
.font-panel[hidden] { display: none; }
.font-panel button { min-width: 44px; height: 40px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; cursor: pointer; }

/* home */
.hero { padding: 22px 0 6px; }
.hero h1 { margin: 0; font-size: 28px; }
.hero p { margin: 2px 0 0; color: var(--muted); font-size: 15px; }
.hero .en { color: var(--accent); font-size: 16px; font-weight: 500; letter-spacing: .02em; margin: 0 0 4px; }
.search { display: flex; gap: 8px; margin: 14px 0 10px; }
.search input {
  flex: 1; min-width: 0; height: 48px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 0 14px; font: inherit; font-size: 17px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.random { height: 48px; padding: 0 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--accent-soft); color: var(--accent); font-weight: 500; cursor: pointer; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; margin-right: -18px; padding-right: 18px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; background: var(--chip); border-radius: 999px; padding: 6px 12px; font-size: 14px;
  text-decoration: none; cursor: pointer; line-height: 1.4;
}
.chip small { color: var(--muted); }
.chip.on { background: var(--accent); color: #fff; }
.chip.on small { color: rgba(255,255,255,.8); }
h2 { font-size: 18px; margin: 26px 0 8px; }
h2 small { font-weight: 400; color: var(--muted); font-size: 14px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li a {
  display: block; text-decoration: none; padding: 12px 2px; border-bottom: 1px solid var(--line);
}
.list li a:active { background: var(--chip); }
.list .no { display: inline-block; min-width: 2.6em; margin-right: .35em; color: var(--accent); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.list .t { font-weight: 500; font-size: 17px; line-height: 1.55; }
.list .ex { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 14.5px; line-height: 1.6; margin-top: 2px; }
.list li[hidden] { display: none; }
#featured .ex { display: none; }
#featured .list li a { padding: 9px 2px; }
.list mark { background: var(--q-bg); color: inherit; border-radius: 3px; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }
.link { border: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; }
.continue a {
  display: flex; gap: 10px; align-items: center; margin-top: 12px; padding: 12px 14px; border-radius: 14px;
  background: var(--accent-soft); text-decoration: none; font-size: 15px;
}
.continue b { color: var(--accent); white-space: nowrap; }
.continue[hidden] { display: none; }

/* article */
.art { padding-top: 18px; }
.meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; color: var(--muted); font-size: 14px; }
.no-badge { background: var(--accent); color: #fff; border-radius: 8px; padding: 1px 9px; font-weight: 700; }
.art h1 { font-size: 25px; line-height: 1.5; margin: 10px 0 6px; }
.title-en { color: var(--muted); font-style: italic; margin: 0 0 6px; font-size: 15px; }
.question {
  background: var(--q-bg); border-left: 4px solid var(--q-line); border-radius: 0 14px 14px 0;
  padding: 12px 16px; margin: 18px 0 8px; font-size: calc(var(--fs) - 1px); line-height: 1.85;
}
.q-label, .a-label { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.q-label { color: var(--q-line); }
.a-label { color: var(--accent); margin-top: 22px; }
.body { font-size: var(--fs); line-height: 1.9; overflow-wrap: anywhere; }
.body p { margin: 0 0 1.1em; }
.body .qa { color: var(--accent); }
.body a { color: var(--accent); word-break: break-all; }
hr.orn { border: 0; text-align: center; margin: 1.6em 0; }
hr.orn::after { content: "· · ·"; color: var(--muted); letter-spacing: .5em; }
.pn { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 30px 0 0; }
.pn-a {
  display: block; text-decoration: none; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 12px; font-size: 15px; line-height: 1.5;
}
.pn-a small { display: block; color: var(--accent); font-size: 13px; }
.pn-a.r { text-align: right; }
.related h2 { margin-top: 30px; }
.foot { text-align: center; padding: 22px 18px calc(28px + env(safe-area-inset-bottom)); }
.home-link {
  display: block; max-width: 40rem; margin: 0 auto; padding: 14px 16px; border-radius: 14px;
  background: var(--accent-soft); color: var(--accent); font-weight: 500; text-decoration: none;
}
.home-link:active { opacity: .8; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; z-index: 40;
}

@media (min-width: 700px) {
  .art h1 { font-size: 30px; }
  .hero h1 { font-size: 34px; }
}
