:root {
  --bg: #0b1433; --bg2: #121d47; --card: #1a2757; --line: #2c3b75;
  --text: #f4f1e6; --muted: #a9b2d6; --gold: #f5c453; --gold-dark: #c9972a; --danger: #ff8a80;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif; font-size: 16px; line-height: 1.5;
}
#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; background: linear-gradient(#0b1433, #14235a); }
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.7rem; color: var(--gold); }
h2 { font-size: 1.15rem; }
p { margin: 0; }
.muted { color: var(--muted); font-size: .9rem; }
.pad { padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.center { text-align: center; align-items: center; }
.grow { flex: 1; min-height: 0; }

header.bar { padding: 12px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
header.bar h2 { flex: 1; }
nav.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); background: var(--bg); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs button { background: none; border: 0; color: var(--muted); padding: 12px 4px; font: inherit; font-size: .85rem; cursor: pointer; }
nav.tabs button.on { color: var(--gold); font-weight: 600; }

label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
textarea { resize: none; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.check { flex-direction: row; align-items: flex-start; gap: 10px; color: var(--text); }
.check input { width: 20px; height: 20px; flex: none; margin-top: 2px; }

button.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 13px 16px; cursor: pointer;
  background: var(--gold); color: #2a1c00; width: 100%;
}
button.btn:disabled { opacity: .55; cursor: default; }
button.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.btn.line { background: #06c755; color: #fff; }
button.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: .85rem; text-decoration: underline; cursor: pointer; padding: 6px; }
button.link.danger { color: var(--danger); }
a.btn-link { display: block; text-decoration: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  font: inherit; font-size: .9rem; padding: 8px 14px; border-radius: 999px; cursor: pointer;
  background: var(--bg2); color: var(--text); border: 1px solid var(--line);
}
.chips button.on { background: var(--gold); color: #2a1c00; border-color: var(--gold); font-weight: 600; }
.preview { display: flex; justify-content: center; padding: 8px 0; }

/* แม่น้ำ */
.river {
  position: relative; flex: 1; min-height: 360px; overflow: hidden;
  background: linear-gradient(#0b1433 0%, #10205a 38%, #0d2f6b 60%, #0a2452 100%);
}
.moon { position: absolute; top: 22px; right: 32px; width: 64px; height: 64px; border-radius: 50%; background: #fdf3c8; box-shadow: 0 0 40px 12px rgba(253, 243, 200, .35); }
.shore { position: absolute; left: 0; right: 0; top: 30%; height: 10%; background: linear-gradient(transparent, rgba(245, 196, 83, .10), transparent); }
.float { position: absolute; left: -110px; width: 96px; background: none; border: 0; padding: 0; cursor: pointer; animation: drift linear infinite; }
.float > div { animation: bob 3.2s ease-in-out infinite alternate; }
.float.pair svg { filter: drop-shadow(0 0 8px rgba(245, 196, 83, .9)); }
.float.dim { opacity: .55; }
.float .tag { display: block; font-size: .72rem; color: var(--gold); text-align: center; margin-top: -6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mine { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); text-align: center; }
.mine > div { animation: bob 3.2s ease-in-out infinite alternate; }
.mine span { display: block; font-size: .78rem; color: var(--muted); margin-top: -4px; }
.empty-river { position: absolute; top: 44%; left: 0; right: 0; text-align: center; padding: 0 24px; }
@keyframes drift { from { left: -110px; } to { left: 100%; } }
@keyframes bob { from { transform: translateY(0) rotate(-2deg); } to { transform: translateY(6px) rotate(2deg); } }
@media (prefers-reduced-motion: reduce) { .float > div, .mine > div { animation: none; } }

/* รายการคู่และแชท */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; width: 100%; }
.item .who { flex: 1; min-width: 0; }
.item .who p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; background: var(--card); align-self: flex-start; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.mine-msg { align-self: flex-end; background: var(--gold); color: #2a1c00; }
.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.composer button { width: auto; flex: none; }

/* แผ่นซ้อนและ toast */
#overlay { position: fixed; inset: 0; background: rgba(4, 8, 24, .72); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
#overlay[hidden], #toast[hidden] { display: none; }
.sheet { width: 100%; max-width: 480px; background: var(--card); border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; max-height: 92dvh; overflow-y: auto; }
.wish { background: var(--bg2); border-radius: 12px; padding: 12px; font-style: italic; overflow-wrap: anywhere; }
.pairart { display: flex; justify-content: center; gap: 4px; }
#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: #000c; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 20; max-width: 90vw; text-align: center; }
