:root {
  --ground: 60svh;            /* เส้นขอบฟ้า/ขอบลานวัด — app.js ตั้งเป็น px จากความสูงจอจริง */
  --text: #f6f0e1;
  --muted: #bdb5c8;
  --gold: #ffcf6b;
  --card: #1a1530;
  --field: #110d22;
  --line: #3a2f5c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: #070a1c;
  color: var(--text);
  font-family: "Noto Sans Lao", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
:lang(th) body, body:lang(th) { font-family: "Noto Sans Thai", "Noto Sans Lao", system-ui, sans-serif; }

/* ---------- ฉาก ---------- */
.sky {
  position: fixed; top: 0; left: 0; right: 0; height: calc(var(--ground) + 2px);
  background: linear-gradient(#04061a 0%, #0c1238 50%, #2a2152 85%, #4a2f55 100%);
}
#stars { position: absolute; inset: 0; width: 100%; height: 100%; }
.moon {
  position: absolute; right: 10%; top: 17%;
  width: min(15vw, 86px); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #fffdf2, #fbefc4 55%, #ecd28d);
  box-shadow: 0 0 36px 8px rgba(255, 236, 170, .4), 0 0 110px 34px rgba(255, 220, 140, .15);
}
/* ลานวัด: พื้นมืด มีแสงเทียนอุ่น ๆ สะท้อนหน้าพระธาตุ */
.ground {
  position: fixed; inset: var(--ground) 0 0 0;
  background:
    radial-gradient(ellipse 70% 38% at 50% 18%, rgba(255, 170, 70, .30), transparent 70%),
    linear-gradient(#3a2438 0%, #1d1225 30%, #0c0814 100%);
}
.layer { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.layer.front { touch-action: manipulation; }
.stupa { position: fixed; left: 0; top: 0; width: 300px; pointer-events: none; }
.stupa svg { display: block; width: 100%; height: auto; overflow: visible; filter: drop-shadow(0 0 22px rgba(255, 186, 80, .42)); transition: filter 1.2s; }
.stupa.bless svg { filter: drop-shadow(0 0 46px rgba(255, 214, 120, .95)); }

/* ---------- หัว / ท้าย ---------- */
.top { position: fixed; top: 0; left: 0; right: 0; text-align: center; padding: 12px 16px 0; pointer-events: none; }
.top > * { pointer-events: auto; }
h1 { margin: 6px 0 0; font-size: clamp(1.45rem, 6.6vw, 2.3rem); color: var(--gold); text-shadow: 0 0 18px rgba(255, 207, 107, .45); }
.tagline { margin: 2px auto; max-width: 34em; font-size: clamp(.88rem, 3.5vw, 1.02rem); pointer-events: none; }
.count { margin: 4px 0 0; color: var(--muted); font-size: .9rem; min-height: 1.2em; pointer-events: none; }
.lang-switch {
  display: inline-flex; align-items: center; gap: 2px; padding: 3px;
  border: 1px solid rgba(255, 207, 107, .6); border-radius: 999px; background: rgba(7, 10, 28, .6);
}
.lang-switch span { padding: 0 4px 0 6px; }
.lang-switch button {
  font: inherit; font-size: 14px; font-weight: bold; color: var(--text); background: none; border: 0;
  padding: 4px 12px; border-radius: 999px; cursor: pointer; min-height: 32px;
}
.lang-switch button.on { background: var(--gold); color: #1b1300; }
.top-btn {
  font: inherit; font-size: .9rem; font-weight: bold; cursor: pointer; margin-top: 6px;
  padding: 5px 14px; min-height: 34px; border-radius: 999px;
  color: var(--gold); background: rgba(7, 10, 28, .6); border: 1px solid rgba(255, 207, 107, .7);
}

.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; text-align: center;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(6, 4, 14, .88) 45%);
  pointer-events: none;
}
.bottom button { pointer-events: auto; }
.hint { margin: 0 0 8px; color: var(--muted); font-size: .9rem; }
.foot { margin: 8px 0 0; color: var(--muted); font-size: .75rem; }
.light-btn {
  font: inherit; font-size: 1.15rem; font-weight: bold; cursor: pointer;
  padding: 12px 34px; min-height: 52px; border: 0; border-radius: 999px;
  color: #1b1300; background: linear-gradient(#ffe7a3, #f5a623);
  box-shadow: 0 0 26px rgba(255, 180, 60, .6);
}
.light-btn:active, .mine-btn:active { transform: scale(.97); }
.link-btn { font: inherit; color: var(--gold); background: none; border: 0; padding: 4px 2px; cursor: pointer; text-decoration: underline; }
.mine-btn {
  font: inherit; font-size: .95rem; font-weight: bold; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; margin: 0 auto 10px;
  padding: 8px 18px; min-height: 42px; border-radius: 999px;
  color: var(--gold); background: rgba(7, 10, 28, .75); border: 2px solid var(--gold);
}
.mine-btn[hidden] { display: none; }
.mine-count { min-width: 22px; padding: 0 7px; border-radius: 999px; background: var(--gold); color: #1b1300; font-size: .85rem; line-height: 22px; }

/* ---------- กล่องข้อความ ---------- */
.dlg {
  width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto;
  border: 1px solid var(--line); border-radius: 18px; padding: 18px;
  background: var(--card); color: var(--text);
}
.dlg::backdrop { background: rgba(3, 2, 10, .6); backdrop-filter: blur(2px); }
.dlg h2 { margin: 0 0 10px; font-size: 1.15rem; color: var(--gold); }
.styles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.styles button {
  font: inherit; color: var(--text); cursor: pointer; padding: 6px 2px 4px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--field); display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .75rem; line-height: 1.25;
}
.styles button svg { width: 100%; max-width: 62px; height: auto; }
.styles button[aria-checked="true"] { border-color: var(--gold); background: #2a2148; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--field);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; resize: vertical; min-height: 84px;
}
.field textarea:focus, .comment-form input:focus { outline: 2px solid var(--gold); border-color: transparent; }
.field small { align-self: flex-end; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.msg { min-height: 1.2em; margin: 6px 0; color: #ffb4a2; font-size: .9rem; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.actions [hidden] { display: none !important; }
.btn {
  font: inherit; font-size: 15px; cursor: pointer; min-height: 44px; padding: 8px 18px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--text);
}
.btn.primary { border: 0; background: var(--gold); color: #1b1300; font-weight: bold; }
.btn.ghost { border: 0; color: var(--muted); font-size: 13px; margin-right: auto; padding-left: 0; }
.btn.danger { color: #ff8a80; border-color: #5a2a36; }
.btn:disabled { opacity: .5; cursor: default; }

/* หน้าอ่าน: ไม่เกินความสูงจอ เลื่อนเฉพาะคอมเมนต์ */
.dlg.read[open] { display: flex; flex-direction: column; overflow: hidden; text-align: center; padding: 14px 16px; }
.dlg.read > * { flex-shrink: 0; }
.read-art { width: 92px; margin: 0 auto; }
.read-art svg { display: block; width: 100%; height: auto; }
.read-text { font-size: 1.1rem; line-height: 1.55; margin: 6px 0 2px; max-height: 22vh; overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
.read-meta { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; margin: 2px 0 4px; }
.sathu-btn {
  font: inherit; font-size: .95rem; font-weight: bold; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 16px; min-height: 40px; border-radius: 999px;
  color: var(--text); background: var(--field); border: 2px solid #6b5420;
}
.sathu-btn[aria-pressed="true"] { color: #1b1300; background: var(--gold); border-color: var(--gold); box-shadow: 0 0 16px rgba(255, 207, 107, .5); }
.sathu-btn[hidden] { display: none; }
.sathu-btn.pop { animation: pop .35s ease; }
@keyframes pop { 50% { transform: scale(1.15); } }

.comments { text-align: left; border-top: 1px solid var(--line); flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; margin-top: 6px; padding-top: 8px; }
.comments[hidden] { display: none; }
.comments h3 { margin: 0 0 6px; font-size: 1rem; color: var(--gold); }
.comments .msg:empty { display: none; }
.comment-list { list-style: none; padding: 0; margin: 0 0 8px; flex: 1 1 auto; min-height: 56px; overflow-y: auto; display: grid; align-content: start; gap: 4px; }
.comment-list li { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 10px; background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 5px 10px; }
.comment-list li.mine { border-color: rgba(255, 207, 107, .55); }
.comment-list li.empty { display: block; background: none; border: 0; color: var(--muted); padding: 2px 0; }
.comment-list .c-text { white-space: pre-wrap; word-break: break-word; }
.comment-list .c-meta { display: flex; gap: 10px; align-items: center; font-size: .75rem; color: var(--muted); margin-left: auto; }
.comment-list .c-meta button { font: inherit; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 0; text-decoration: underline; }
.comment-form { display: flex; gap: 6px; }
.comment-form input:not(.hp) {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--text); background: var(--field);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px;
}

.mine { display: grid; gap: 8px; margin: 8px 0; }
.mine .item { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--field); }
.mine .item .open { width: 100%; display: block; text-align: left; cursor: pointer; font: inherit; color: var(--text); background: none; border: 0; padding: 0 0 6px; }
.mine .item .open:disabled { cursor: default; opacity: .6; }
.mine .item .txt { display: block; white-space: pre-wrap; word-break: break-word; }
.mine .item .stat { color: var(--gold); font-size: .8rem; }
.mine .item .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.small-btn { min-height: 36px; font-size: 13px; padding: 4px 12px; }

.top-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- อ่านทั้งหมด ---------- */
.list-dlg[open] { display: flex; flex-direction: column; overflow: hidden; height: calc(100dvh - 24px); }
.list-dlg > * { flex-shrink: 0; }
.list-dlg .muted.small { margin: 2px 0 6px; }
.tabs { display: flex; gap: 6px; margin-bottom: 4px; }
.tabs button {
  flex: 1; font: inherit; font-size: .9rem; font-weight: bold; cursor: pointer; padding: 8px 6px; border-radius: 10px;
  color: var(--muted); background: var(--field); border: 1px solid var(--line);
}
.tabs button[aria-selected="true"] { color: #1b1300; background: var(--gold); border-color: var(--gold); }
.all-list { flex: 1 1 auto !important; min-height: 0; overflow-y: auto; list-style: none; padding: 0; margin: 0; display: grid; align-content: start; gap: 6px; }
.all-list li > button {
  width: 100%; font: inherit; color: var(--text); text-align: left; cursor: pointer;
  display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--field);
}
.all-list li > button:hover, .all-list li > button:focus-visible { border-color: var(--gold); }
.all-list .ico { width: 40px; flex: none; }
.all-list .ico svg { display: block; width: 100%; height: auto; }
.all-list .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.all-list .txt { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-word; }
.all-list .meta { color: var(--muted); font-size: .78rem; }
.all-list .meta b { color: var(--gold); font-weight: normal; }
.all-list .note { text-align: center; color: var(--muted); padding: 10px 0; }

.top-list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 8px; }
.top-list li button {
  width: 100%; font: inherit; color: var(--text); text-align: left; cursor: pointer;
  display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--field);
}
.top-list li button:hover, .top-list li button:focus-visible { border-color: var(--gold); }
.top-list .rank { font-size: 1.4rem; min-width: 1.6em; text-align: center; }
.top-list .txt { flex: 1; min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.top-list .n { color: var(--gold); font-weight: bold; white-space: nowrap; }
.top-list .empty { color: var(--muted); }

.sites { display: grid; gap: 8px; }
.sites a {
  display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--field); color: var(--text); text-decoration: none;
}
.sites a:hover, .sites a:focus-visible { border-color: var(--gold); }
.sites .ico { font-size: 1.6rem; }
.sites b { display: block; }
.sites small { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  width: max-content; max-width: calc(100vw - 32px); text-align: center;
  background: rgba(26, 21, 48, .95); border: 1px solid var(--gold); color: var(--text);
  padding: 10px 16px; border-radius: 14px; font-size: .95rem;
  opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.flame { transform-origin: 40px 27px; animation: flicker .2s ease-in-out infinite alternate; }
@keyframes flicker { from { transform: scale(.93, .9); } to { transform: scale(1.04, 1.08); } }
@media (max-width: 600px) { .moon { top: 46%; right: 6%; width: 12vw; } }
@media (max-width: 420px) { .light-btn { padding: 12px 24px; font-size: 1.08rem; } }
@media (prefers-reduced-motion: reduce) { .flame { animation: none; } .stupa svg { transition: none; } }
