/* ============================================================
 * Loy Krathong online — "แสงแห่งคืนเพ็ญ ส่องเสน่ห์ศิลป์อีสาน"
 * Design system ถอดจาก Key Visual (KV แสงแห่งคืนเพ็ญ.ai)
 *
 *   ราตรี   : น้ำเงินม่วงเข้ม  #05031a → #1a0c4a   (ท้องฟ้า/ผิวน้ำ)
 *   จันทร์  : ทองนวล          #ffe9a8 → #f0a928   (ดวงจันทร์ · ปุ่มหลัก · สถานะเลือก)
 *   นีออน   : ชมพู #ff4fd8 · ม่วง #a15cff · ฟ้า #46d6ff · เขียว #3dff8a (แสงจากภูเขา/ดอกบัว)
 *   พื้นผิว : "กระจกคืนเพ็ญ" โปร่งมืด + เส้นขอบไล่สี ฟ้า→ม่วง→ชมพู (เหมือนลำแสงบนฟ้า)
 *   ฟอนต์   : Charmonman (หัวข้อ — เข้ากับตัวอักษรชื่อเรื่อง) · IBM Plex Sans Thai (เนื้อหา)
 * ============================================================ */

/* ---------- 1) Design tokens ---------- */
:root {
  /* ราตรี */
  --night-0: #05031a;
  --night-1: #0b0636;
  --night-2: #170a4a;
  --night-3: #2a1370;

  /* ทองจันทร์ */
  --moon: #ffd56a;
  --moon-l: #ffeaa3;
  --moon-d: #f0a928;
  --moon-ink: #2a1200;

  /* นีออน */
  --pink: #ff4fd8;
  --pink-l: #ffb8f0;
  --violet: #a15cff;
  --cyan: #46d6ff;
  --green: #3dff8a;

  /* ข้อความ */
  --text: #f1ebff;
  --text-2: #cfc3f2;
  --muted: #9d8fcf;

  /* พื้นผิวกระจก */
  --glass: rgba(11, 6, 44, 0.78);
  --glass-strong: rgba(11, 6, 44, 0.94);
  --fill: rgba(255, 255, 255, 0.07);
  --fill-h: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.14);
  --line-pink: rgba(255, 143, 230, 0.38);
  --ray: linear-gradient(90deg, var(--cyan), var(--violet) 52%, var(--pink));
  --ray-v: linear-gradient(180deg, var(--cyan), var(--violet) 52%, var(--pink));
  --moon-grad: linear-gradient(135deg, #fff3b8 0%, var(--moon) 48%, var(--moon-d) 100%);

  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 26px;
  --shadow-pop: 0 24px 70px rgba(0, 0, 0, 0.68), 0 0 44px rgba(161, 92, 255, 0.28);

  --font: 'IBM Plex Sans Thai', 'Noto Sans Thai', system-ui, sans-serif;
  --display: 'Charmonman', 'IBM Plex Sans Thai', serif;

  --p: 0;
  --track: rgba(255, 255, 255, 0.22);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--night-0);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* เงาโทนราตรีทับฉาก: ช่วยให้ข้อความอ่านง่ายในแต่ละหน้า */
.shade {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(4, 2, 28, 0.15), rgba(4, 2, 24, 0.78)),
    linear-gradient(to top, rgba(4, 2, 24, 0.7), rgba(4, 2, 24, 0) 38%);
  opacity: 0.35;
  transition: opacity 0.6s;
}
body[data-stage='intro'] .shade { opacity: 0.45; }
body[data-stage='build'] .shade { opacity: 0.85; }
body[data-stage='light'] .shade { opacity: 0.75; }
body[data-stage='float'] .shade { opacity: 0.25; }

#app { position: fixed; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; pointer-events: none; animation: fadeIn 0.5s ease both; }
.screen > * { pointer-events: auto; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ---------- 2) ปุ่ม ---------- */
.btn {
  font: 600 15px var(--font);
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--fill);
  padding: 11px 22px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.15s, background 0.2s, border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.btn:hover { background: var(--fill-h); border-color: rgba(255, 255, 255, 0.34); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn.ghost { background: rgba(255, 255, 255, 0.04); }
.btn.primary {
  color: var(--moon-ink);
  font-weight: 700;
  border-color: transparent;
  background: var(--moon-grad);
  box-shadow: 0 6px 26px rgba(255, 196, 70, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
.btn.primary:hover { box-shadow: 0 8px 36px rgba(255, 196, 70, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.7); border-color: transparent; }
.btn.big { font-size: 18px; padding: 15px 34px; }
.btn.small { font-size: 13px; padding: 8px 14px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- 3) หน้าแรก ---------- */
#screen-intro { display: grid; place-items: center; padding: 20px; overflow: hidden; }
.intro-card {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 720px;
}
.intro-card::before {
  content: '';
  position: absolute;
  inset: -30px -120px;
  z-index: -1;
  background: radial-gradient(ellipse at center, rgba(5, 3, 30, 0.78) 0%, rgba(5, 3, 30, 0.5) 50%, rgba(5, 3, 30, 0) 75%);
  pointer-events: none;
}
.brand-logo { width: min(300px, 62vw); height: auto; margin: 0 0 10px; filter: drop-shadow(0 4px 18px rgba(255, 80, 220, 0.4)); }
.intro-card h1 { margin: 0 0 6px; font-size: 0; line-height: 0; }
.kv-title {
  display: block;
  height: min(37vh, 420px);
  width: auto;
  max-width: 84vw;
  margin: 0 auto;
  filter: drop-shadow(0 0 22px rgba(150, 90, 255, 0.5));
  user-select: none;
  -webkit-user-drag: none;
}
.when { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.when li {
  font-size: clamp(13px, 2.3vw, 15.5px);
  font-weight: 500;
  color: var(--text);
  padding: 6px 15px;
  border-radius: 999px;
  background: rgba(8, 4, 40, 0.62);
  border: 1px solid var(--line-pink);
  box-shadow: 0 0 18px rgba(161, 92, 255, 0.3);
}
.when li b { font-weight: 700; color: var(--moon-l); }
.lead { font-size: clamp(14px, 2.4vw, 18px); line-height: 1.7; margin: 0 0 22px; color: #efe6ff; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8); }
.lead b { color: var(--pink-l); letter-spacing: 0.06em; }
.cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.stat { margin: 20px 0 0; font-size: 14px; color: rgba(240, 233, 255, 0.85); text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8); }
#btn-start { animation: pulse 2.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 6px 22px rgba(255, 196, 70, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.7); }
  50% { box-shadow: 0 6px 48px rgba(255, 196, 70, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.7); }
}

.bfly { position: absolute; width: clamp(28px, 4.2vw, 52px); height: auto; pointer-events: none !important; filter: drop-shadow(0 0 10px rgba(255, 190, 240, 0.7)); animation: flutter 5s ease-in-out infinite; }
.bf1 { left: 6%; top: 16%; }
.bf2 { right: 6%; top: 30%; width: clamp(24px, 3.4vw, 42px); animation-delay: -2s; animation-duration: 6.4s; }
.bf3 { left: 10%; bottom: 14%; width: clamp(22px, 3vw, 36px); animation-delay: -3.5s; animation-duration: 5.6s; }
@keyframes flutter {
  0%, 100% { transform: translate(0, 0) rotate(-8deg) scaleX(1); }
  25% { transform: translate(14px, -18px) rotate(6deg) scaleX(0.72); }
  50% { transform: translate(4px, -30px) rotate(-4deg) scaleX(1); }
  75% { transform: translate(-12px, -14px) rotate(8deg) scaleX(0.76); }
}

/* จอกว้าง: ภาพ KV แนวนอนมีดวงจันทร์ซ้าย + ท้องฟ้ามืดด้านขวา -> วางการ์ดต้อนรับไว้ฝั่งขวา ไม่ทับพระจันทร์ */
@media (min-width: 900px) and (min-aspect-ratio: 112/100) {
  #screen-intro { display: flex; align-items: center; justify-content: flex-end; padding: 24px clamp(28px, 7vw, 130px) 24px 24px; }
  .intro-card {
    width: min(520px, 44vw);
    padding: 26px 28px 24px;
    border-radius: var(--r-lg);
    background: linear-gradient(180deg, rgba(14, 8, 52, 0.62), rgba(6, 3, 30, 0.7));
    border: 1px solid var(--line);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55), 0 0 60px rgba(161, 92, 255, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  .intro-card::before { display: none; }
  .intro-card::after {
    content: '';
    position: absolute;
    left: 24px;
    right: 24px;
    top: 0;
    height: 2px;
    border-radius: 2px;
    background: var(--ray);
  }
  .kv-title { height: min(34vh, 380px); max-width: 100%; }
  .bf1 { left: 38%; top: 14%; }
  .bf2 { right: 4%; top: 14%; }
  .bf3 { left: 44%; bottom: 12%; }
}

/* ---------- 4) ออกแบบกระทง ---------- */
.build {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(470px, 44vw);
  pointer-events: none;
}
.build > * { pointer-events: auto; }
.preview-wrap { position: relative; display: flex; align-items: center; justify-content: center; padding: 20px; min-height: 0; overflow: hidden; }
.preview-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 55%, rgba(140, 50, 220, 0.5), rgba(60, 20, 140, 0.18) 45%, rgba(0, 0, 0, 0) 70%);
  pointer-events: none;
}
#preview { position: relative; width: min(600px, 100%); height: min(560px, 82dvh); display: block; }
.preview-tools { position: absolute; left: 16px; top: 16px; display: flex; gap: 8px; flex-wrap: wrap; z-index: 2; }
.chip-btn {
  font: 600 13px var(--font);
  color: var(--text);
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 15px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: background 0.2s, border-color 0.2s;
}
.chip-btn:hover { background: rgba(60, 30, 120, 0.9); border-color: rgba(255, 255, 255, 0.3); }
.chip-btn.on { background: var(--moon-grad); color: var(--moon-ink); border-color: transparent; }

.panel {
  position: relative;
  overflow-y: auto;
  padding: 26px 22px 0;
  background: linear-gradient(180deg, #140b40, #08041f);
  box-shadow: -10px 0 50px rgba(120, 40, 220, 0.28);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 143, 230, 0.45) transparent;
}
@media (min-width: 761px) {
  .panel { border-left: 2px solid transparent; border-image: var(--ray-v) 1; }
}
.panel h2 { margin: 0 0 16px; font-family: var(--display); font-size: 30px; font-weight: 700; line-height: 1.2; color: var(--moon-l); text-shadow: 0 0 18px rgba(255, 196, 70, 0.4); }
.group { margin-bottom: 20px; }
.group h3 { margin: 0 0 9px; font-size: 13.5px; font-weight: 600; letter-spacing: 0.02em; color: var(--text-2); }
.group h3 small { color: var(--muted); font-weight: 400; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: 500 13.5px var(--font);
  color: var(--text);
  background: var(--fill);
  border: 1.5px solid transparent;
  border-radius: var(--r-sm);
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.chip:hover { background: var(--fill-h); }
.chip.on {
  border-color: var(--moon);
  background: rgba(255, 213, 106, 0.14);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 0 3px rgba(255, 213, 106, 0.12), 0 0 20px rgba(255, 213, 106, 0.28);
}
.chip .sw { width: 16px; height: 16px; border-radius: 50%; display: inline-block; border: 2px solid rgba(255, 255, 255, 0.85); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); }
#opt-band { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chip.band { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 5px; text-align: center; font-size: 11.5px; }
.chip.band img { width: 100%; height: 30px; object-fit: cover; border-radius: 7px; display: block; }
.chip.band .none { height: 30px; border-radius: 7px; background: var(--fill); border: 1px dashed rgba(255, 255, 255, 0.35); display: grid; place-items: center; font-style: normal; color: var(--muted); }
#opt-preset { display: grid; grid-template-columns: repeat(2, 1fr); }
.chip.preset { display: flex; align-items: center; gap: 8px; text-align: left; padding: 8px 10px; }
.chip.preset .ic { height: 34px; width: 34px; max-width: none; margin: 0; font-size: 26px; line-height: 34px; text-align: center; flex: none; }
.chip .ic { height: 22px; width: auto; max-width: 28px; object-fit: contain; vertical-align: middle; margin-right: 2px; }
.chips.small .chip { padding: 6px 11px; font-size: 12.5px; border-radius: 999px; }

.suggest { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 8px; }
.suggest button {
  text-align: left;
  font: 400 12.5px/1.5 var(--font);
  color: var(--muted);
  background: transparent;
  border: 1px dashed rgba(255, 143, 230, 0.4);
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.suggest button:hover { color: #fff; border-color: var(--pink); background: rgba(255, 79, 216, 0.12); }

input[type='text'], textarea {
  width: 100%;
  font: 500 15px var(--font);
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--r-sm);
  padding: 11px 13px;
  outline: none;
  resize: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: #8878b8; }
input:focus, textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(70, 214, 255, 0.2); }
.counter { text-align: right; font-size: 12px; color: var(--muted); margin-top: 4px; }

.actions { display: flex; gap: 10px; justify-content: space-between; align-items: center; }
.actions.sticky {
  position: sticky;
  bottom: 0;
  margin: 0 -22px;
  padding: 16px 22px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(8, 4, 34, 0.98) 62%, rgba(8, 4, 34, 0));
}

/* ---------- 5) จุดเทียน ---------- */
#screen-light { display: grid; place-items: center; padding: 16px; }
.light { position: relative; isolation: isolate; width: min(560px, 100%); display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; max-height: 100%; }
.light::before {
  content: '';
  position: absolute;
  inset: -40px -90px;
  z-index: -1;
  background: radial-gradient(ellipse at center, rgba(5, 3, 30, 0.82) 0%, rgba(5, 3, 30, 0.55) 52%, rgba(5, 3, 30, 0) 76%);
  pointer-events: none;
}
.light h2 { margin: 0; font-family: var(--display); font-size: clamp(30px, 6vw, 40px); font-weight: 700; color: var(--moon-l); text-shadow: 0 0 22px rgba(255, 196, 70, 0.55), 0 2px 14px rgba(0, 0, 0, 0.8); }
.hint { margin: 0; color: rgba(241, 235, 255, 0.95); font-size: 15px; min-height: 22px; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9); }
#lightcv { width: 100%; height: min(46dvh, 380px); touch-action: none; cursor: pointer; }
.wish-echo { font-weight: 500; font-size: 16px; color: var(--moon-l); max-width: 460px; line-height: 1.6; min-height: 26px; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9); }
.wish-echo em { display: block; color: var(--pink-l); font-style: normal; font-size: 13px; margin-top: 2px; }
.hold-btn {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 0;
  padding: 5px;
  margin: 8px 0 6px;
  cursor: pointer;
  background: conic-gradient(var(--moon) calc(var(--p) * 1%), var(--track) 0);
  box-shadow: 0 0 calc(10px + var(--p) * 0.5px) rgba(255, 196, 70, calc(0.25 + var(--p) * 0.006));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.hb-in { display: grid; place-content: center; width: 100%; height: 100%; border-radius: 50%; background: #120a3c; color: #fff; line-height: 1.1; }
.hb-in b { font-size: 30px; }
.hb-in small { font-size: 12px; color: #e4d6ff; }
.hold-btn.done { background: conic-gradient(var(--moon) 100%, transparent 0); cursor: default; }
.hold-btn.done .hb-in small { color: var(--moon-l); }
.light .actions { width: 100%; max-width: 420px; }

/* ---------- 6) HUD หน้าลอยกระทง ---------- */
.hud { position: absolute; inset: 0; pointer-events: none !important; }
.hud > * { pointer-events: auto; }
.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: calc(12px + env(safe-area-inset-top)) 16px 18px;
  background: linear-gradient(to bottom, rgba(4, 2, 28, 0.78), transparent);
  pointer-events: none !important;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 15px; color: #fff; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8); }
.brand img { height: 42px; width: auto; display: block; filter: drop-shadow(0 2px 8px rgba(255, 80, 220, 0.35)); }
.brand span { padding-left: 12px; border-left: 1.5px solid rgba(255, 255, 255, 0.5); line-height: 1.2; }
.hud-stats { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12.5px; font-weight: 500; }
.hud-stats span {
  background: var(--glass);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  backdrop-filter: blur(10px);
}
.net { color: var(--muted) !important; }
.net b { font-weight: 400; }
.net em { font-style: normal; }

.toolbar {
  position: absolute;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  max-width: calc(100vw - 16px);
  background: rgba(14, 8, 46, 0.85);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.55), 0 0 0 3px rgba(161, 92, 255, 0.26), 0 0 40px rgba(161, 92, 255, 0.25);
  animation: dockIn 0.7s cubic-bezier(0.2, 0.9, 0.3, 1) 0.15s both;
}
.toolbar button {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  cursor: pointer;
  color: var(--text);
  font: 700 15px var(--font);
  transition: transform 0.18s, box-shadow 0.25s, background 0.2s, filter 0.2s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.toolbar button i { font-style: normal; line-height: 1; }
.toolbar button:active { transform: scale(0.94); }

.toolbar button.main { height: 54px; padding: 0 24px 0 10px; border-radius: 999px; letter-spacing: 0.01em; }
.toolbar button.main i {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 21px;
  background: rgba(255, 255, 255, 0.4);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.12);
  transition: transform 0.25s;
}
.toolbar button.main:hover { transform: translateY(-2px); filter: brightness(1.06); }
.toolbar button.main:hover i { transform: rotate(-8deg) scale(1.1); }
.toolbar button.main[data-act='lantern'] {
  color: var(--moon-ink);
  background: var(--moon-grad);
  box-shadow: 0 6px 22px rgba(255, 196, 70, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  animation: glowPulse 3.2s ease-in-out infinite;
}
.toolbar button.main[data-act='newkrathong'] {
  color: #fff;
  background: linear-gradient(135deg, #ff6fe0 0%, #b23cff 100%);
  box-shadow: 0 6px 22px rgba(190, 60, 255, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.toolbar .tb-sep { flex: 0 0 1px; height: 30px; background: var(--line); margin: 0 2px; }

.toolbar button.sec { width: 48px; height: 48px; border-radius: 50%; background: var(--fill-h); border: 1px solid var(--line); }
.toolbar button.sec i { font-size: 22px; transition: transform 0.2s; }
.toolbar button.sec span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.toolbar button.sec::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 16px);
  transform: translate(-50%, 6px);
  padding: 5px 11px;
  font: 600 12px var(--font);
  white-space: nowrap;
  color: #fff;
  background: var(--night-3);
  border: 1px solid var(--line-pink);
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
.toolbar button.sec:hover { background: rgba(255, 255, 255, 0.24); border-color: var(--pink-l); transform: translateY(-3px); }
.toolbar button.sec:hover i { transform: scale(1.15); }
.toolbar button.sec:hover::after,
.toolbar button.sec:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
.toolbar .more { display: none; }
.toolbar button.badge::after { content: ''; position: absolute; width: 8px; height: 8px; background: var(--pink); border-radius: 50%; margin: -4px 0 0 18px; }
@keyframes dockIn { from { opacity: 0; transform: translate(-50%, 28px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes dockInM { from { opacity: 0; transform: translateY(28px); } to { opacity: 1; transform: none; } }
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 6px 20px rgba(255, 196, 70, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.7); }
  50% { box-shadow: 0 6px 32px rgba(255, 196, 70, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.7); }
}

/* แผ่นเมนูเพิ่มเติม */
.sheet-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.sheet-item {
  font: 600 14px var(--font);
  color: var(--text);
  background: var(--fill);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 10px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s, background 0.2s, border-color 0.2s;
}
.sheet-item i { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 50%; font-style: normal; font-size: 28px; background: var(--fill-h); border: 1.5px solid var(--line-pink); }
.sheet-item:hover { background: var(--fill-h); }
.sheet-item:active { transform: scale(0.96); background: rgba(255, 79, 216, 0.22); border-color: var(--pink); }

.hold-hint {
  position: absolute;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  text-align: center;
  color: var(--text);
  background: var(--glass);
  border: 1px solid var(--line-pink);
  border-radius: 20px;
  padding: 12px 18px;
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.55), 0 0 26px rgba(161, 92, 255, 0.3);
  width: max-content;
  max-width: calc(100vw - 24px);
  animation: floatHint 2.8s ease-in-out infinite;
}
.hold-hint p { margin: 0 0 10px; line-height: 1.5; }
.hold-hint small { color: var(--muted); }
.hold-hint .btn { margin: 0 3px; }
@keyframes floatHint { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -5px); } }

/* ---------- 7) การ์ดพร และ Modal ---------- */
#wishcard {
  position: fixed;
  left: 50%;
  top: 76px;
  transform: translateX(-50%);
  width: min(380px, calc(100vw - 24px));
  color: var(--text);
  background: linear-gradient(180deg, #1c0f58, #0b0536 70%);
  border: 1px solid var(--line-pink);
  border-radius: 20px;
  padding: 30px 18px 16px;
  box-shadow: var(--shadow-pop);
  animation: popIn 0.35s cubic-bezier(0.2, 1.3, 0.4, 1) both;
  z-index: 20;
  overflow: hidden;
}
@keyframes popIn { from { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.94); } to { opacity: 1; transform: translateX(-50%); } }
.wc-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.wc-head span { font-size: 28px; }
.wc-head b { display: block; font-size: 15px; color: var(--pink-l); }
.wc-head em { font-style: normal; font-size: 12px; font-weight: 600; color: var(--moon-l); }
#wishcard p { font-weight: 500; font-size: 17px; line-height: 1.7; margin: 6px 0 12px; word-break: break-word; }
#wishcard .btn { width: 100%; }

#wishcard::before, .modal-card::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: var(--ray);
}
.x {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--fill-h);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  z-index: 3;
  transition: background 0.15s;
}
.x:hover { background: rgba(255, 255, 255, 0.28); }

#modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(2, 1, 20, 0.72);
  backdrop-filter: blur(6px);
  animation: fadeOnly 0.25s both;
}
@keyframes fadeOnly { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  position: relative;
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  color: var(--text);
  background: linear-gradient(180deg, #1c0f58, #0b0536 70%);
  border: 1px solid var(--line-pink);
  border-radius: var(--r-lg);
  padding: 40px 24px 24px;
  box-shadow: var(--shadow-pop);
  animation: popUp 0.35s cubic-bezier(0.2, 1.2, 0.4, 1) both;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 143, 230, 0.45) transparent;
}
@keyframes popUp { from { opacity: 0; transform: translateY(24px) scale(0.96); } to { opacity: 1; transform: none; } }
.modal-card h2 { margin: 0 0 6px; font-family: var(--display); font-size: 30px; font-weight: 700; line-height: 1.25; color: var(--moon-l); text-shadow: 0 0 16px rgba(255, 196, 70, 0.4); }
.modal-card .sub { color: var(--text-2); font-size: 14px; margin: 0 0 16px; line-height: 1.7; }
.modal-card .row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.modal-card .row .btn { flex: 1 1 140px; }
.modal-card textarea { margin-top: 4px; }
.modal-mascot { float: right; width: 76px; height: auto; margin: -4px 36px 4px 8px; }
.modal-card.center { text-align: center; }

/* ทำโคม */
.modal-card.lantern { width: min(560px, 100%); }
.modal-card.lantern .sub { margin-bottom: 8px; font-size: 13.5px; }
.lt-cv {
  display: block;
  width: 100%;
  height: clamp(170px, 34dvh, 290px);
  border-radius: 18px;
  margin: 0 0 14px;
  position: sticky;
  top: -8px;
  z-index: 2;
  background: radial-gradient(ellipse at 50% 60%, rgba(255, 170, 70, 0.3), rgba(10, 5, 50, 0) 70%), linear-gradient(180deg, #1c0f58, #07041f);
  border: 1px solid var(--line-pink);
  box-shadow: 0 10px 18px -6px rgba(0, 0, 0, 0.6);
}
.lt-act {
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  bottom: -24px;
  z-index: 2;
  margin: 0 -24px -24px;
  padding: 12px 24px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, #0b0536 70%, rgba(11, 5, 54, 0));
}
.lt-act .hold-btn { flex: 0 0 auto; margin: 0; --track: rgba(255, 255, 255, 0.2); }
.lt-act .hint { flex: 1; font-size: 13.5px; line-height: 1.6; color: var(--text-2); text-shadow: none; }

.fact { display: flex; gap: 12px; margin-bottom: 14px; clear: both; }
.fact .fi { font-size: 24px; flex: 0 0 auto; }
.fact b { display: block; margin-bottom: 2px; color: var(--pink-l); }
.fact p { margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.7; }

.card-preview { display: block; width: 100%; max-height: 52vh; object-fit: contain; border-radius: 14px; background: transparent; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6), 0 0 24px rgba(161, 92, 255, 0.3); }
.done-ic { display: block; width: 118px; height: auto; margin: 0 auto 2px; animation: bob 3.6s ease-in-out infinite; }
.done-tag { text-align: center; margin: 0 0 4px; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; color: var(--moon-l); }

#toast {
  position: fixed;
  left: 50%;
  top: calc(70px + env(safe-area-inset-top));
  transform: translate(-50%, -20px);
  color: var(--text);
  background: rgba(20, 10, 62, 0.95);
  border: 1px solid var(--line-pink);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 40;
  max-width: calc(100vw - 24px);
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 22px rgba(161, 92, 255, 0.3);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.noscript { position: fixed; inset: auto 0 20px; text-align: center; z-index: 99; color: #fff; }

/* ---------- 8) มือถือ / จอแคบ ---------- */
@media (max-width: 760px) {
  .toolbar { left: 10px; right: 10px; transform: none; max-width: none; gap: 8px; padding: 8px; border-radius: 30px; bottom: calc(10px + env(safe-area-inset-bottom)); animation-name: dockInM; }
  .toolbar .tb-sep { display: none; }
  .toolbar button.sec { flex: 0 0 56px; width: 56px; height: 56px; }
  .toolbar button.main { flex: 1 1 0; min-width: 0; height: 56px; padding: 0 8px; gap: 8px; font-size: 15px; justify-content: center; }
  .toolbar button.main i { width: 34px; height: 34px; font-size: 20px; }
  .toolbar .more { display: inline-flex; flex: 0 0 56px; width: 56px; height: 56px; border-radius: 50%; background: var(--fill-h); border: 1px solid var(--line); }
  .toolbar .more i { font-size: 24px; }
  .toolbar .more span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .hold-hint { bottom: calc(96px + env(safe-area-inset-bottom)); }
  .net .nt { display: none; }
  .hud-stats span#hud-net { position: absolute; right: 12px; top: calc(11px + env(safe-area-inset-top)); padding: 4px 8px; }

  /* หน้าต่างต่างๆ เป็นแผ่นเลื่อนขึ้นจากด้านล่าง */
  #modal { place-items: end center; padding: 0; }
  .modal-card, .modal-card.lantern {
    width: 100%;
    max-height: 92dvh;
    border-radius: 24px 24px 0 0;
    border-bottom: 0;
    padding: 40px 18px calc(22px + env(safe-area-inset-bottom));
    animation: sheetUp 0.35s cubic-bezier(0.2, 0.9, 0.3, 1) both;
  }
  .modal-card h2 { font-size: 26px; padding-right: 36px; }
  .lt-cv { height: clamp(150px, 27dvh, 240px); }
  .modal-card.lantern .sub { display: none; }
  .lt-act { margin: 0 -18px -22px; padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); bottom: calc(-22px - env(safe-area-inset-bottom)); }
  .modal-card .row .btn { flex: 1 1 100%; }
  input[type='text'], textarea { font-size: 16px; } /* กัน iOS ซูมตอนโฟกัส */
  .chip { padding: 9px 12px; }
  .chips.small .chip { padding: 8px 11px; }
  .x { width: 36px; height: 36px; top: 12px; }
  .btn { padding: 13px 20px; }
  .cta .btn { flex: 1 1 100%; }
  #screen-intro { padding: 16px 18px calc(18px + env(safe-area-inset-bottom)); }
  .kv-title { height: min(37vh, 340px); }
  .hud-top { padding-left: 12px; padding-right: 12px; gap: 6px; }
  .hud-stats span#hud-count { white-space: normal; }

  .build { grid-template-columns: 1fr; grid-template-rows: 36dvh minmax(0, 1fr); }
  .preview-wrap { padding: 8px; }
  #preview { width: 100%; height: 100%; }
  .preview-tools { left: 10px; top: 10px; }
  .panel { border-image: none; border-top: 2px solid transparent; border-image: var(--ray) 1; border-radius: 0; padding: 18px 16px 0; }
  .panel h2 { font-size: 26px; }
  .actions.sticky { margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
  .brand { font-size: 13px; gap: 8px; }
  .brand img { height: 34px; }
  .brand span { display: none; }
  #wishcard { top: 110px; }
  #toast { top: calc(118px + env(safe-area-inset-top)); }
  .hud-stats { font-size: 11.5px; gap: 6px; }
  .hud-stats span { padding: 4px 10px; }
}
@media (max-height: 640px) and (min-width: 761px) {
  #lightcv { height: 38dvh; }
}
@keyframes sheetUp { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }

/* มือถือแนวนอน / หน้าจอเตี้ย */
@media (max-height: 520px) {
  .toolbar { padding: 5px; gap: 8px; bottom: calc(6px + env(safe-area-inset-bottom)); }
  .toolbar button.main { height: 42px; padding: 0 16px 0 7px; font-size: 13px; gap: 8px; }
  .toolbar button.main i { width: 28px; height: 28px; font-size: 16px; }
  .toolbar button.sec { width: 38px; height: 38px; }
  .toolbar button.sec i { font-size: 18px; }
  .toolbar .tb-sep { height: 22px; }
  .hold-hint { bottom: calc(64px + env(safe-area-inset-bottom)); padding: 8px 14px; }
  .hold-hint p { margin-bottom: 6px; }
  .hud-top { padding-top: calc(6px + env(safe-area-inset-top)); }
  .brand img { height: 28px; }
  #wishcard { top: 52px; }
  #toast { top: calc(48px + env(safe-area-inset-top)); }
  .modal-card { max-height: calc(100dvh - 16px); }
  #lightcv { height: 36dvh; }
  .hold-btn { width: 78px; height: 78px; }
  .brand-logo { width: min(200px, 34vh); margin-bottom: 4px; }
  .kv-title { height: 34vh; }
  .lead { display: none; }
  .when { margin-bottom: 8px; }
  .stat { margin-top: 10px; }
}
@media (max-height: 520px) and (max-width: 760px) {
  .toolbar { left: 8px; right: 8px; }
  .toolbar button.sec { flex-basis: 42px; width: 42px; height: 42px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
