/* ============================================================
   ลอยกระทงออนไลน์ — stylesheet (mobile-first)
   ============================================================ */
:root {
  --bg: #0b1026;
  --panel: rgba(16, 21, 50, 0.80);
  --panel-2: rgba(24, 30, 68, 0.92);
  --line: rgba(255, 214, 130, 0.25);
  --line-soft: rgba(255, 214, 130, 0.14);
  --gold: #f7c65c;
  --gold-2: #e8933f;
  --text: #f4ecd8;
  --dim: #b6b0d4;
  --pink: #ff8fb8;
  --teal: #35d0c5;
  --danger: #ff7a7a;
  --rad: 20px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%; height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Prompt", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
}

#scene3d {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block; outline: none;
  touch-action: none;
}

/* ---------- แผ่นกระจก (glass) ---------- */
.glass, .glass-mini {
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line);
  border-radius: var(--rad);
  box-shadow: var(--shadow);
}
.glass-mini {
  border-radius: 14px;
  background: rgba(16, 21, 50, 0.62);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

/* ---------- หน้าโหลด ---------- */
#loader {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  background:
    radial-gradient(90% 70% at 50% 18%, #232a5c 0%, #141b45 45%, #0b1026 100%);
  transition: opacity 0.7s ease;
}
#loader.hide { opacity: 0; pointer-events: none; }
.loader-lotus { animation: lotus-pulse 2.4s ease-in-out infinite; }
@keyframes lotus-pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 14px rgba(255, 200, 100, .45)); }
  50% { transform: scale(1.08); filter: drop-shadow(0 0 30px rgba(255, 200, 100, .85)); }
}
#loader h1 {
  margin: 10px 0 0; font-size: 1.9rem; font-weight: 700; letter-spacing: 1px;
  background: linear-gradient(180deg, #ffe9ad, #f7c65c 55%, #e8933f);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: #f7c65c;
  text-shadow: 0 0 40px rgba(247, 198, 92, .35);
}
#loader h1 span { display: block; font-size: 1.02rem; font-weight: 400; letter-spacing: 7px; text-align: center; color: var(--dim); -webkit-text-fill-color: var(--dim); margin-top: 2px; }
#loader p { color: var(--dim); font-size: 0.9rem; margin: 8px 0 0; min-height: 1.3em; }

/* ---------- แถบบน ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 8px;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 14px 7px 10px;
}
.brand-moon {
  font-size: 1.3rem; color: #ffe9ad;
  filter: drop-shadow(0 0 8px rgba(255, 220, 140, .8));
}
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; }
.brand-txt b { font-size: 0.95rem; font-weight: 600; }
.brand-txt i { font-style: normal; font-size: 0.66rem; color: var(--dim); letter-spacing: 1.5px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.count { padding: 7px 11px; font-size: 0.8rem; color: var(--dim); white-space: nowrap; }
.count b { color: var(--gold); font-size: 0.95rem; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 14px;
  display: grid; place-items: center;
  font-size: 1.1rem; cursor: pointer;
  background: rgba(16, 21, 50, 0.62);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: transform .15s ease, border-color .15s ease;
}
.icon-btn:active { transform: scale(0.92); border-color: var(--gold); }
.icon-btn.playing {
  border-color: var(--gold);
  animation: music-pulse 1.8s ease-in-out infinite;
}
@keyframes music-pulse {
  0%, 100% { box-shadow: 0 0 0 rgba(247, 198, 92, 0); }
  50% { box-shadow: 0 0 16px rgba(247, 198, 92, 0.55); }
}

/* ---------- คำใบ้ ---------- */
#hint {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(86px + var(--safe-b)); z-index: 25;
  max-width: 88vw;
  padding: 8px 16px; border-radius: 999px;
  font-size: 0.78rem; color: var(--dim); text-align: center;
  background: rgba(10, 14, 36, 0.72);
  border: 1px solid var(--line-soft);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  opacity: 0; transition: opacity .6s ease; pointer-events: none;
}
#hint.show { opacity: 1; }

/* ---------- ปุ่มลอย (FAB) ---------- */
#fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + var(--safe-b)); z-index: 28;
  padding: 14px 30px;
  border: none; border-radius: 999px; cursor: pointer;
  font-family: inherit; font-size: 1.02rem; font-weight: 600; color: #3a2306;
  background: linear-gradient(180deg, #ffdd87, #f7c65c 45%, #e8933f);
  box-shadow:
    0 10px 28px rgba(232, 147, 63, 0.45),
    0 3px 10px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: transform .18s ease, box-shadow .18s ease, opacity .25s ease;
}
#fab:active { transform: translateX(-50%) scale(0.95); }
#fab.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(80px); }

/* ---------- แผงด้านล่าง (sheet) ---------- */
.sheet {
  position: fixed; left: 10px; right: 10px;
  bottom: calc(10px + var(--safe-b));
  z-index: 40;
  max-height: min(76dvh, 640px);
  display: flex; flex-direction: column;
  background: var(--panel-2);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  backdrop-filter: blur(18px) saturate(1.25);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  transform: translateY(calc(100% + 30px));
  transition: transform .38s cubic-bezier(.22, .9, .28, 1);
}
.sheet.open { transform: translateY(0); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 6px; flex: none;
}
.sheet-head .handle {
  position: absolute; top: 7px; left: 50%; transform: translateX(-50%);
  width: 44px; height: 4px; border-radius: 4px;
  background: rgba(255, 214, 130, 0.35);
}
.sheet-head h2 {
  margin: 8px 0 2px; font-size: 1.05rem; font-weight: 600;
  color: var(--gold); letter-spacing: 0.5px;
}
.sheet-close {
  width: 34px; height: 34px; border-radius: 12px;
  border: 1px solid var(--line-soft); background: transparent;
  color: var(--dim); font-size: 1rem; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.sheet-close:active { background: rgba(255, 214, 130, 0.15); color: var(--text); }
.sheet-body {
  padding: 6px 16px calc(18px + var(--safe-b));
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}

/* ---------- ฟอร์ม ---------- */
.fld { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 4px; font-size: 0.82rem; color: var(--dim); }
.fld small { color: var(--dim); font-weight: 300; }
.fld-label { margin: 12px 0 6px; font-size: 0.82rem; color: var(--dim); }
input {
  font-family: inherit; font-size: 0.98rem; color: var(--text);
  background: rgba(8, 11, 30, 0.65);
  border: 1.5px solid var(--line-soft);
  border-radius: 13px; padding: 12px 14px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
  width: 100%;
}
input::placeholder { color: #77719c; }
input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(247, 198, 92, 0.15); }
input.shake { animation: shake .4s ease; border-color: var(--danger); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}

/* การ์ดเลือกชนิดกระทง */
.style-row {
  display: flex; gap: 9px;
  overflow-x: auto; padding: 4px 2px 8px;
  scrollbar-width: none;
}
.style-row::-webkit-scrollbar { display: none; }
.style-card {
  flex: none; width: 88px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 9px 4px 7px;
  border-radius: 15px; cursor: pointer;
  background: rgba(8, 11, 30, 0.55);
  border: 1.5px solid var(--line-soft);
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.style-card svg { width: 54px; height: 54px; filter: drop-shadow(0 3px 6px rgba(0,0,0,.4)); }
.style-card span { font-size: 0.74rem; color: var(--dim); }
.style-card.sel {
  border-color: var(--gold);
  background: rgba(247, 198, 92, 0.13);
  transform: translateY(-2px);
}
.style-card.sel span { color: var(--gold); }

/* ปุ่มปล่อยกระทง */
.btn-release {
  width: 100%; margin-top: 14px;
  padding: 15px; border: none; border-radius: 17px; cursor: pointer;
  font-family: inherit; font-size: 1.06rem; font-weight: 600; color: #3a2306;
  background: linear-gradient(180deg, #ffdd87, #f7c65c 45%, #e8933f);
  box-shadow: 0 10px 24px rgba(232, 147, 63, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform .15s ease, filter .15s ease;
}
.btn-release:active { transform: scale(0.97); filter: brightness(1.08); }

/* ---------- สมุดกระทง ---------- */
.search { margin: 4px 0 10px; }
.klist { display: flex; flex-direction: column; }
.krow {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 6px;
  border: none; border-bottom: 1px solid rgba(255, 214, 130, 0.09);
  background: transparent; cursor: pointer;
  font-family: inherit; color: var(--text); text-align: left;
  border-radius: 10px;
}
.krow:active { background: rgba(247, 198, 92, 0.08); }
.krow .kicon { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: rgba(8, 11, 30, 0.5); }
.krow .kicon svg { width: 32px; height: 32px; }
.krow .kmain { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.krow .kmain b { font-size: 0.94rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.krow .kmain small { font-size: 0.72rem; color: var(--dim); }
.krow .kmain small em { font-style: normal; color: var(--teal); }
.krow .ktime { flex: none; font-size: 0.66rem; color: #77719c; }
.krow .kgoto {
  flex: none; font-size: 0.72rem; font-weight: 500; color: var(--gold);
  padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--line-soft);
  background: rgba(247, 198, 92, 0.08);
}
.kempty { padding: 30px 10px; text-align: center; color: var(--dim); font-size: 0.86rem; }
.list-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 2px 2px; font-size: 0.7rem; color: #77719c;
  flex-wrap: wrap;
}
.foot-actions { display: flex; gap: 12px; }
.foot-actions button {
  background: none; border: none; padding: 0;
  font-family: inherit; font-size: 0.7rem; color: #9a92c2;
  text-decoration: underline dotted; cursor: pointer;
}
.foot-actions button:hover { color: var(--danger); }

/* ---------- การ์ดข้อมูลกระทง ---------- */
#kinfo {
  position: fixed; z-index: 50;
  left: 50%; top: 50%;
  transform: translate(-50%, -46%) scale(0.92);
  width: min(88vw, 330px);
  padding: 20px 18px 16px;
  opacity: 0; pointer-events: none;
  transition: opacity .28s ease, transform .28s cubic-bezier(.22, .9, .28, 1);
}
#kinfo.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
#kinfo-close {
  position: absolute; top: 10px; right: 10px;
  width: 30px; height: 30px; border-radius: 10px;
  border: 1px solid var(--line-soft); background: transparent;
  color: var(--dim); cursor: pointer;
}
.ki-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.ki-head svg { width: 64px; height: 64px; flex: none; filter: drop-shadow(0 4px 10px rgba(0,0,0,.5)); }
.ki-head .ki-name { font-size: 1.2rem; font-weight: 600; color: var(--gold); line-height: 1.2; word-break: break-word; }
.ki-head .ki-style { font-size: 0.74rem; color: var(--dim); }
.ki-rows { display: flex; flex-direction: column; gap: 5px; font-size: 0.8rem; color: var(--dim); }
.ki-rows b { color: var(--text); font-weight: 500; }
.ki-rows .zone { color: var(--teal); }
.ki-wish {
  margin-top: 10px; padding: 10px 12px;
  border-left: 3px solid var(--gold);
  background: rgba(247, 198, 92, 0.08);
  border-radius: 0 10px 10px 0;
  font-size: 0.84rem; color: var(--text); font-style: italic;
}

/* ---------- ปุ่มเปิดเบราว์เซอร์ภายนอก (เมื่อเปิดจาก in-app browser) ---------- */
#open-external {
  position: fixed; z-index: 32;
  top: calc(64px + env(safe-area-inset-top, 0px));
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 8px 18px; border-radius: 999px; cursor: pointer;
  font-family: inherit; font-size: 0.82rem; font-weight: 600; color: var(--gold);
  background: var(--panel-2);
  border: 1.5px solid var(--gold);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 16px rgba(247, 198, 92, 0.25);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  animation: ext-pulse 2.2s ease-in-out infinite;
  max-width: 92vw;
}
#open-external small { font-size: 0.62rem; font-weight: 400; color: var(--dim); letter-spacing: 1px; }
#open-external:active { transform: translateX(-50%) scale(0.95); }
@keyframes ext-pulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(0,0,0,.5), 0 0 10px rgba(247,198,92,.2); }
  50% { box-shadow: 0 8px 24px rgba(0,0,0,.5), 0 0 22px rgba(247,198,92,.55); }
}

/* ---------- toast ---------- */
#toast {
  position: fixed; top: calc(64px + env(safe-area-inset-top, 0px));
  left: 50%; transform: translate(-50%, -12px);
  z-index: 60; max-width: 88vw;
  padding: 11px 18px; border-radius: 999px;
  font-size: 0.84rem; text-align: center;
  background: var(--panel-2);
  border: 1px solid var(--gold);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.5), 0 0 20px rgba(247, 198, 92, 0.18);
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- เดสก์ท็อป ---------- */
@media (min-width: 860px) {
  .sheet {
    left: auto; right: 18px; bottom: 18px;
    width: 400px; max-height: min(82vh, 700px);
    transform: translateX(calc(100% + 40px));
  }
  .sheet.open { transform: translateX(0); }
  .sheet-head .handle { display: none; }
  .sheet-body { padding: 4px 20px 22px; }
  #fab { left: 26px; transform: none; }
  #fab:active { transform: scale(0.95); }
  #fab.hidden { transform: translateY(90px); }
  #hint { bottom: 88px; }
  #topbar { padding: 16px 20px 8px; }
  .brand-txt b { font-size: 1.02rem; }
}
