:root {
  --horizon: 46vh;            /* เส้นขอบฟ้า: ท้องฟ้าอยู่บน แม่น้ำอยู่ล่าง */
  --text: #f4efe2;
  --muted: #b9b6c9;
  --gold: #ffcf6b;
  --accent: #ff9f1c;
  --card: #151b38;
  --line: #2c3566;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: #0b1026;
  color: var(--text);
  font-family: "Noto Sans Thai", "Noto Sans Lao", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
:lang(lo) body, body:lang(lo) { font-family: "Noto Sans Lao", "Noto Sans Thai", system-ui, sans-serif; }

/* ---------- ท้องฟ้า ---------- */
.sky {
  position: fixed; inset: 0 0 calc(100vh - var(--horizon)) 0;
  background: linear-gradient(#060918 0%, #0e1536 55%, #24306a 100%);
}
#stars { position: absolute; inset: 0; width: 100%; height: 100%; }
.moon {
  position: absolute; right: 12%; top: 13%;
  width: min(18vw, 110px); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #fffdf2, #fbefc4 55%, #ecd28d);
  box-shadow: 0 0 40px 10px rgba(255, 236, 170, .45), 0 0 120px 40px rgba(255, 220, 140, .18);
}
/* ---------- แม่น้ำ ---------- */
.river {
  position: fixed; inset: var(--horizon) 0 0 0; overflow: hidden;
  background: linear-gradient(#1a2457 0%, #0d1438 35%, #070b22 100%);
}
#water { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }

/* ---------- กระทง ---------- */
.pond { position: fixed; inset: 0; pointer-events: none; }
.krathong {
  position: absolute; left: 0; top: 0; width: 120px; padding: 0; border: 0; background: none;
  pointer-events: auto; cursor: pointer; transform-origin: 50% 85%;
  will-change: transform;
}
.krathong .bob { position: relative; }   /* โยกตามคลื่น: คำนวณใน app.js */
.krathong svg { display: block; width: 100%; height: auto; overflow: visible; }
.krathong .bob::after {   /* แสงเทียนสะท้อนน้ำ */
  content: ""; position: absolute; left: 30%; right: 30%; bottom: -14%; height: 26%;
  background: radial-gradient(ellipse, rgba(255, 170, 60, .45), transparent 70%);
  filter: blur(2px);
}
.krathong .flame, .lantern-k .flame { transform-origin: 60px 22px; animation: flicker .18s ease-in-out infinite alternate; }
.krathong .label {
  position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%);
  white-space: nowrap; font-size: 13px; font-weight: bold; color: #1b1300;
  background: var(--gold); padding: 2px 10px; border-radius: 999px; margin-bottom: 4px;
  box-shadow: 0 0 14px rgba(255, 207, 107, .7);
}
.krathong.own .bob::before {
  content: ""; position: absolute; inset: -12% -8% 0; border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 207, 107, .35), transparent 65%);
}
.krathong:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; border-radius: 12px; }
@keyframes flicker { from { transform: scale(.92, .9) skewX(-3deg); opacity: .9; } to { transform: scale(1.05, 1.1) skewX(3deg); opacity: 1; } }

/* ---------- หัว / ท้าย ---------- */
.top { position: fixed; top: 0; left: 0; right: 0; text-align: center; padding: 14px 16px 0; pointer-events: none; }
.top > * { pointer-events: auto; }
h1 { margin: 6px 0 0; font-size: clamp(1.5rem, 7vw, 2.4rem); color: var(--gold); text-shadow: 0 0 18px rgba(255, 207, 107, .45); }
.tagline { margin: 2px 0; color: var(--text); font-size: clamp(.9rem, 3.6vw, 1.05rem); }
.count { margin: 4px 0 0; color: var(--muted); font-size: .9rem; min-height: 1.2em; }
.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(11, 16, 38, .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; }

.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(5, 8, 22, .85) 45%);
}
.hint { margin: 0 0 8px; color: var(--muted); font-size: .9rem; }
.foot { margin: 8px 0 0; color: var(--muted); font-size: .75rem; }
.float-btn {
  font: inherit; font-size: 1.15rem; font-weight: bold; cursor: pointer;
  padding: 12px 32px; min-height: 52px; border: 0; border-radius: 999px;
  color: #1b1300; background: linear-gradient(#ffd98a, #ff9f1c);
  box-shadow: 0 0 24px rgba(255, 159, 28, .55);
}
.float-btn:active { transform: scale(.97); }

/* ---------- กล่องข้อความ ---------- */
.dlg {
  width: min(440px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto;
  border: 1px solid var(--line); border-radius: 18px; padding: 18px;
  background: var(--card); color: var(--text);
}
.dlg::backdrop { background: rgba(3, 5, 15, .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: #0e1430; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .75rem;
}
.styles button svg { width: 100%; max-width: 70px; height: auto; }
.styles button[aria-checked="true"] { border-color: var(--gold); background: #1f2650; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field textarea {
  font: inherit; font-size: 16px; color: var(--text); background: #0e1430;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; resize: vertical; min-height: 84px;
}
.field textarea: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; }
.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:disabled { opacity: .5; cursor: default; }
.read { text-align: center; }
.read-art { width: 120px; margin: 0 auto; }
.read-text { font-size: 1.2rem; line-height: 1.6; margin: 10px 0 4px; white-space: pre-wrap; word-break: break-word; }

.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(21, 27, 56, .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); }

@media (prefers-reduced-motion: reduce) {
  .krathong .flame, .lantern-k .flame { animation: none; }
}

/* ---------- โคมลอย ---------- */
.lantern-k {
  position: absolute; left: 0; top: 0; width: 64px; padding: 0; border: 0; background: none;
  pointer-events: auto; cursor: pointer; transform-origin: 50% 50%; will-change: transform, opacity;
}
.lantern-k svg { position: relative; display: block; width: 100%; height: auto; overflow: visible; }
.lantern-k::before {      /* แสงเรือง */
  content: ""; position: absolute; inset: -35% -45%; border-radius: 50%;
  background: radial-gradient(circle at 50% 60%, rgba(255, 170, 60, .45), transparent 62%);
}
.lantern-k .flame { transform-origin: 30px 76px; }
.lantern-k .label { position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); }
.lantern-k.own::before { background: radial-gradient(circle at 50% 60%, rgba(255, 207, 107, .7), transparent 65%); }
.lantern-k:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; border-radius: 12px; }
.label {
  white-space: nowrap; font-size: 13px; font-weight: bold; color: #1b1300;
  background: var(--gold); padding: 2px 10px; border-radius: 999px; margin-bottom: 4px;
  box-shadow: 0 0 14px rgba(255, 207, 107, .7);
}

.main-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.float-btn.lantern { background: linear-gradient(#ffb199, #e5533d); color: #fff; box-shadow: 0 0 24px rgba(229, 83, 61, .5); }
@media (max-width: 420px) { .float-btn { padding: 12px 18px; font-size: 1.05rem; } }
.link-btn { font: inherit; color: var(--gold); background: none; border: 0; padding: 4px 2px; cursor: pointer; text-decoration: underline; }

.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: #0e1430; 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); }
.styles.is-lantern button svg { max-width: 44px; }
.read-art.is-lantern { width: 70px; }

/* ---------- รูป ---------- */
.photo-pick { margin: 8px 0 4px; }
.photo-pick .btn { display: inline-flex; align-items: center; cursor: pointer; }
.photo-preview { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.photo-preview img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.small-btn { min-height: 36px; font-size: 13px; padding: 4px 12px; }
.read-photo { display: block; max-width: 100%; max-height: 50vh; margin: 10px auto 0; border-radius: 12px; border: 1px solid var(--line); }
.btn.danger { color: #ff8a80; border-color: #5a2a36; }
/* รูปจิ๋วกรอบโพลารอยด์: ตั้งบนกระทง (ด้านขวาของเทียน) / ห้อยข้างโคม */
.photo-badge {
  position: absolute; right: 2%; top: -6%; width: 40%; padding: 4% 4% 10%;
  background: #fffaf0; border-radius: 3px; transform: rotate(var(--tilt, 4deg));
  box-shadow: 0 2px 8px rgba(0, 0, 0, .45), 0 0 14px rgba(255, 190, 90, .35); pointer-events: none;
}
.photo-badge img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 1px; }
.lantern-k .photo-badge { right: -62%; top: 34%; width: 66%; }
.mine { display: grid; gap: 8px; margin: 8px 0; }
.mine .item { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #0e1430; }
.mine .item p { margin: 0 0 6px; white-space: pre-wrap; word-break: break-word; }
.mine .item .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.mine .item img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.photo-pick [hidden], .actions [hidden] { display: none !important; }

/* ปุ่ม "กระทงและโคมของฉัน" — โชว์เมื่อเคยส่งจากเครื่องนี้ */
.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(11, 16, 38, .75); border: 2px solid var(--gold);
  box-shadow: 0 0 16px rgba(255, 207, 107, .35);
}
.mine-btn[hidden] { display: none; }
.mine-btn:active { transform: scale(.97); }
.mine-count { min-width: 22px; padding: 0 7px; border-radius: 999px; background: var(--gold); color: #1b1300; font-size: .85rem; line-height: 22px; }

/* ---------- ถูกใจ + Top 5 ---------- */
.like-btn {
  font: inherit; font-size: 1rem; font-weight: bold; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; margin: 4px auto 0;
  padding: 8px 20px; min-height: 44px; border-radius: 999px;
  color: var(--text); background: #0e1430; border: 2px solid #5a2a46;
}
.like-btn[aria-pressed="true"] { color: #fff; background: #c2185b; border-color: #e91e63; box-shadow: 0 0 16px rgba(233, 30, 99, .45); }
.like-btn[hidden] { display: none; }
.like-btn.pop { animation: pop .35s ease; }
@keyframes pop { 50% { transform: scale(1.15); } }
.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(11, 16, 38, .6); border: 1px solid rgba(255, 207, 107, .7);
}
.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: #0e1430;
}
.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 img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; flex: none; }
.top-list .n { color: #ff8fb1; font-weight: bold; white-space: nowrap; }
.top-list .empty { color: var(--muted); }
