:root {
  --ink: #4a3a52;
  --muted: #8a7a92;
  --bg1: #fff7e6;
  --bg2: #f6eaff;
  --bg3: #e4f7ee;
  --pink: #ff8fb8;
  --leaf: #5fb98a;
  --accent: #ff8fb8;       /* เปลี่ยนตามตัวละครที่สแกนเจอ */
  --accent-soft: #ffe3ee;
  --card: rgba(255, 255, 255, .82);
  --shadow: 0 10px 28px rgba(150, 100, 170, .18);
  --r: 26px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; background: var(--bg2); }
body {
  font-family: "Mali", "Noto Sans Thai", "Sarabun", system-ui, sans-serif;
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 8%, var(--bg1) 0, transparent 45%),
    radial-gradient(circle at 90% 30%, var(--bg3) 0, transparent 45%),
    linear-gradient(180deg, #fdf3ff, var(--bg2) 50%, #eaf8f1);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* ประกายลอย */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.sky i {
  position: absolute; left: var(--x); top: 105%;
  font-style: normal; font-size: calc(22px * var(--s));
  color: #ffb6d0; opacity: .7;
  animation: rise var(--d) linear var(--t) infinite;
}
.sky i:nth-child(3n) { color: #b9a4f5; }
.sky i:nth-child(3n+1) { color: #ffd76a; }
@keyframes rise { to { transform: translateY(-120vh) rotate(360deg); } }

.app { position: relative; z-index: 1; max-width: 520px; margin: 0 auto; padding: 14px 16px 40px; display: grid; gap: 28px; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 1.05rem; }
.brand b { color: var(--pink); }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); }
.chip { background: #fff; padding: 5px 12px; border-radius: 999px; font-size: .78rem; box-shadow: var(--shadow); white-space: nowrap; }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 8px 4px 0; }
.eyebrow { display: inline-block; background: #fff; color: var(--leaf); font-weight: 700; font-size: .78rem; padding: 4px 14px; border-radius: 999px; box-shadow: var(--shadow); }
.hero h1 { font-family: "Sriracha", "Mali", cursive; font-weight: 400; font-size: clamp(2rem, 9vw, 2.7rem); line-height: 1.25; margin: 14px 0 10px; }
.hero h1 em { font-style: normal; color: #e0558a; position: relative; }
.hero h1 em::after { content: ""; position: absolute; left: 0; right: 0; bottom: 2px; height: 10px; background: #ffe0ec; z-index: -1; border-radius: 6px; }
.lead { color: var(--muted); max-width: 34ch; margin: 0 auto 18px; }
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn { font: inherit; font-weight: 700; border: 0; cursor: pointer; border-radius: 999px; padding: 13px 24px; transition: transform .15s, box-shadow .15s; }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-main { color: #fff; background: linear-gradient(135deg, #ff8fb8, #ff9f6e); box-shadow: 0 8px 20px rgba(255, 130, 150, .45); font-size: 1.05rem; }
.btn-main:hover { transform: translateY(-2px); }
.btn-soft { color: var(--ink); background: #fff; box-shadow: var(--shadow); }
.tip { margin-top: 14px; font-size: .8rem; color: var(--muted); }

/* พัดการ์ด 3 ใบ */
.fan { display: flex; justify-content: center; margin-top: 26px; height: 190px; }
.fan img { width: 118px; height: auto; border-radius: 14px; border: 4px solid #fff; box-shadow: var(--shadow); margin: 0 -14px; transform-origin: 50% 120%; animation: sway 4.5s ease-in-out infinite; }
.fan img:nth-child(1) { transform: rotate(-12deg) translateY(10px); animation-delay: 0s; }
.fan img:nth-child(2) { transform: translateY(-6px); z-index: 2; animation-delay: -1.5s; }
.fan img:nth-child(3) { transform: rotate(12deg) translateY(10px); animation-delay: -3s; }
@keyframes sway { 50% { translate: 0 -8px; } }

/* ---------- scanner ---------- */
.scanner { background: var(--card); border: 3px solid #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; backdrop-filter: blur(8px); }
.scanner-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; font-size: .95rem; }
.status { font-size: .75rem; color: var(--muted); text-align: right; }

.camera {
  position: relative; width: 100%; aspect-ratio: 3 / 4; border-radius: 20px; overflow: hidden;
  background: linear-gradient(160deg, #f8e9ff, #e5f7ee);
  outline: 3px dashed var(--accent); outline-offset: -3px;
  transition: outline-color .3s;
}
.ar-host, .ar-host a-scene { position: absolute; inset: 0; width: 100%; height: 100%; }
.ar-host video { object-fit: cover; }
body.ar-live .camera { outline-style: solid; }

.placeholder { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 6px; }
.placeholder h2 { font-size: 1.2rem; }
.placeholder p { color: var(--muted); font-size: .88rem; max-width: 24ch; }
.bob { font-size: 4rem; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(6deg); } }
.c { position: absolute; width: 34px; height: 34px; border: 5px solid var(--pink); }
.c.tl { top: 16px; left: 16px; border-right: 0; border-bottom: 0; border-top-left-radius: 14px; }
.c.tr { top: 16px; right: 16px; border-left: 0; border-bottom: 0; border-top-right-radius: 14px; }
.c.bl { bottom: 16px; left: 16px; border-right: 0; border-top: 0; border-bottom-left-radius: 14px; }
.c.br { bottom: 16px; right: 16px; border-left: 0; border-top: 0; border-bottom-right-radius: 14px; }

.hud { position: absolute; top: 12px; left: 12px; z-index: 5; display: flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, .92); padding: 6px 12px; border-radius: 999px; font-size: .8rem; font-weight: 700; box-shadow: var(--shadow); }
.hud-dot { width: 10px; height: 10px; border-radius: 50%; background: #f5b53d; animation: blink 1.2s infinite; }
.hud.found .hud-dot { background: #3fc27a; animation: none; }
@keyframes blink { 50% { opacity: .25; } }

.tools { position: absolute; top: 10px; right: 10px; z-index: 6; display: flex; gap: 8px; }
.tool { width: 38px; height: 38px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .92); font-size: 1rem; cursor: pointer; box-shadow: var(--shadow); }
body:not(.ar-live) .tools { display: none; }

/* ป้ายกำลังเล่นเพลง */
.now { position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 6; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 12px; padding: 10px 14px; border-radius: 18px; background: rgba(255, 255, 255, .94); border: 3px solid var(--accent); box-shadow: var(--shadow); animation: pop .35s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { from { transform: translateY(20px) scale(.9); opacity: 0; } }
.now-text { display: grid; line-height: 1.25; min-width: 0; }
.now-text b { color: var(--accent); font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-text span { font-size: .75rem; color: var(--muted); }
.now-bar { grid-column: 1 / -1; height: 5px; border-radius: 3px; background: var(--accent-soft); overflow: hidden; }
.now-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; }
.eq { display: flex; align-items: flex-end; gap: 3px; height: 26px; }
.eq i { width: 5px; border-radius: 3px; background: var(--accent); animation: eq 0.9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -.3s; } .eq i:nth-child(3) { animation-delay: -.6s; } .eq i:nth-child(4) { animation-delay: -.15s; }
@keyframes eq { 0%, 100% { height: 6px; } 50% { height: 26px; } }
.now.muted .eq i { animation-play-state: paused; height: 6px; }

/* ---------- sections ---------- */
.title { text-align: center; margin-bottom: 14px; }
.title span { font-size: .72rem; letter-spacing: .14em; color: var(--leaf); font-weight: 700; }
.title h2 { font-family: "Sriracha", "Mali", cursive; font-weight: 400; font-size: 1.7rem; }
.title p { color: var(--muted); font-size: .85rem; }

.grid { display: grid; gap: 14px; }
.char { --c: var(--pink); --s: var(--accent-soft); display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; text-align: left; font: inherit; color: inherit; width: 100%; cursor: pointer; border: 3px solid #fff; border-radius: 22px; padding: 10px; background: linear-gradient(135deg, #fff, var(--s)); box-shadow: var(--shadow); transition: transform .2s; }
.char:hover { transform: translateY(-3px) rotate(-.6deg); }
.char img { width: 96px; border-radius: 12px; border: 3px solid #fff; box-shadow: 0 4px 10px rgba(0, 0, 0, .12); display: block; }
.char b { display: block; color: var(--c); font-size: 1.05rem; }
.char .sub { font-size: .85rem; font-weight: 600; }
.char p { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.badge { display: inline-block; margin-top: 6px; font-size: .7rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: #fff; color: var(--muted); }
.char.found .badge { background: var(--c); color: #fff; }

.steps { display: grid; gap: 12px; }
.steps article { display: grid; grid-template-columns: 52px 1fr; column-gap: 12px; align-items: center; background: var(--card); border: 3px solid #fff; border-radius: 20px; padding: 12px 14px; box-shadow: var(--shadow); }
.steps i { grid-row: span 2; width: 52px; height: 52px; display: grid; place-items: center; font-style: normal; font-size: 1.6rem; background: #fff; border-radius: 16px; }
.steps p { font-size: .82rem; color: var(--muted); }

footer { text-align: center; font-size: .8rem; color: var(--muted); }
footer span { color: var(--pink); }

/* ---------- lightbox / toast ---------- */
.lightbox { border: 0; background: transparent; margin: auto; max-width: 92vw; max-height: 92vh; text-align: center; color: #fff; }
.lightbox::backdrop { background: rgba(60, 30, 80, .72); backdrop-filter: blur(4px); }
.lightbox img { max-width: 100%; max-height: 78vh; border-radius: 18px; border: 5px solid #fff; }
.lightbox p { margin-top: 8px; font-weight: 700; }
.lb-close { position: absolute; top: -6px; right: -6px; width: 38px; height: 38px; border-radius: 50%; border: 0; background: #fff; font-size: 1rem; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); z-index: 50; max-width: 88vw; padding: 10px 18px; border-radius: 16px; background: #4a3a52; color: #fff; font-size: .85rem; opacity: 0; pointer-events: none; transition: .3s; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 760px) {
  .app { max-width: 760px; }
  .grid { grid-template-columns: repeat(3, 1fr); }
  .char { grid-template-columns: 1fr; text-align: center; }
  .char img { width: 70%; margin: 0 auto; }
  .steps { grid-template-columns: repeat(3, 1fr); }
  .camera { aspect-ratio: 4 / 3; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
