:root {
  --bg: #04120c;
  --fg: #eafff4;
  --muted: #9ec9b4;
  --accent: #7dffb2;
  --pink: #ff4d7a;
  --glass: rgba(8, 28, 20, 0.62);
  --line: rgba(160, 255, 210, 0.22);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font-family: "Sarabun", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }

/* ---------- หน้า AR ---------- */
body.ar { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  background: radial-gradient(120% 90% at 50% 100%, #0e3a2a 0%, #05160f 55%, #020a07 100%); }
#cam, #gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#cam { object-fit: cover; transition: filter 0.9s ease; background: transparent; }
body.nocam #cam { display: none; }
body.night #cam { filter: brightness(0.42) saturate(0.75) hue-rotate(-8deg) contrast(1.05); }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: none; }
#ui button, #ui a, .sheet, .modal, .gate { pointer-events: auto; }

.topbar { position: absolute; top: calc(var(--safe-t) + 10px); left: 12px; right: 12px; display: flex; align-items: center; gap: 10px; }
.title { flex: 1; text-align: center; font-weight: 700; font-size: 17px; text-shadow: 0 1px 8px rgba(0,0,0,.7); }
.chip { min-width: 42px; height: 42px; padding: 0 12px; display: grid; place-items: center; border-radius: 21px; border: 1px solid var(--line);
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); text-decoration: none; font-weight: 700; }
.dots { position: absolute; top: calc(var(--safe-t) + 62px); left: 0; right: 0; display: flex; justify-content: center; gap: 6px; align-items: center; }
.dot { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; font-size: 16px; filter: grayscale(1) brightness(.7);
  background: var(--glass); border: 1px solid var(--line); opacity: .75; }
.dot.on { filter: none; opacity: 1; border-color: var(--accent); box-shadow: 0 0 12px rgba(125,255,178,.5); }
.dots.big .dot { width: 46px; height: 46px; font-size: 24px; }
.count { margin-left: 4px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.dock { position: absolute; left: 0; right: 0; bottom: calc(var(--safe-b) + 14px); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 0 12px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; border-radius: 24px; border: 1px solid var(--line);
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 15px; font-weight: 600; text-decoration: none; }
.pill.on { background: rgba(125,255,178,.28); border-color: var(--accent); }
.pill.primary { background: var(--accent); color: #04281a; border-color: transparent; }
.mainrow { display: flex; align-items: center; gap: 28px; }
.btn.round { width: 52px; height: 52px; border-radius: 50%; font-size: 22px; border: 1px solid var(--line); background: var(--glass);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.btn.round.on { background: rgba(125,255,178,.28); border-color: var(--accent); }
.shutter { width: 74px; height: 74px; border-radius: 50%; border: 4px solid #fff; background: transparent; display: grid; place-items: center; padding: 0; }
.shutter i { width: 56px; height: 56px; border-radius: 50%; background: #fff; transition: transform .12s; }
.shutter:active i { transform: scale(.85); }

.toast { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 178px); transform: translate(-50%, 12px); max-width: min(92vw, 460px); padding: 11px 16px;
  border-radius: 16px; background: rgba(6, 24, 17, .8); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  text-align: center; font-size: 15px; line-height: 1.45; opacity: 0; transition: opacity .4s, transform .4s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast a { color: var(--accent); font-weight: 700; }
.card { position: absolute; left: 50%; top: calc(var(--safe-t) + 104px); transform: translate(-50%, -8px); padding: 10px 18px; border-radius: 16px; background: rgba(6,24,17,.82);
  border: 1px solid var(--accent); text-align: center; opacity: 0; transition: opacity .35s, transform .35s; display: flex; flex-direction: column; gap: 2px; max-width: 90vw; }
.card.show { opacity: 1; transform: translate(-50%, 0); }
.card b { font-size: 18px; }
.card small { color: var(--muted); font-size: 12.5px; }
.label { position: absolute; left: 0; top: 0; padding: 4px 10px; border-radius: 12px; font-size: 13px; font-weight: 600; white-space: nowrap;
  background: rgba(6,24,17,.85); border: 1px solid var(--accent); opacity: 0; transition: opacity .3s; will-change: transform; }
.label.show { opacity: 1; }
.label::after { content: ""; position: absolute; left: 50%; top: 100%; width: 1px; height: 10px; background: var(--accent); }

.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }

.sheet, .modal { position: fixed; inset: 0; display: none; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.5); z-index: 20; }
.sheet.open, .modal.open { display: flex; }
.sheet-in { position: relative; width: min(560px, 100%); max-height: 82vh; overflow: auto; background: #0a2018; border-radius: 24px 24px 0 0;
  border: 1px solid var(--line); padding: 26px 22px calc(var(--safe-b) + 22px); animation: up .35s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-in h2 { margin: 0; font-size: 24px; }
.sheet-emoji { font-size: 40px; }
.tag { color: var(--accent); margin: 2px 0 12px; }
.sheet ul { padding-left: 20px; line-height: 1.6; }
.sheet li { margin-bottom: 8px; }
.note { color: var(--muted); font-size: 13px; }
.x { position: absolute; right: 14px; top: 14px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: transparent; }
.reward { margin: 14px 0; padding: 16px; border-radius: 18px; text-align: center; background: linear-gradient(135deg, rgba(255,215,107,.22), rgba(125,255,178,.16));
  border: 1px solid rgba(255,215,107,.6); display: flex; flex-direction: column; gap: 4px; }
.reward .seal { font-size: 46px; }
.reward small { color: var(--muted); }
.modal { align-items: center; }
.modal-in { width: min(420px, 92vw); display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
.modal-in img { width: 100%; max-height: 66vh; object-fit: contain; border-radius: 14px; border: 1px solid var(--line); background: #000; }
.modal-in .row { display: flex; gap: 10px; }
.modal-in small { color: var(--muted); }

/* ---------- หน้าเริ่ม (gate) ---------- */
.gate { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(100% 80% at 50% 20%, rgba(18,70,50,.92), rgba(3,14,10,.97)); transition: opacity .6s, visibility .6s; }
.gate.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.gate-in { width: min(420px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.gate-emoji { font-size: 76px; filter: drop-shadow(0 0 24px rgba(125,255,178,.55)); animation: float 3.2s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px); } }
.gate h1 { margin: 0; font-size: 30px; }
.gate ol { text-align: left; line-height: 1.7; margin: 8px 0; padding-left: 22px; color: #d5f5e4; }
.gate small { color: var(--muted); line-height: 1.5; }
.cta { display: inline-block; margin-top: 8px; padding: 15px 30px; border-radius: 30px; border: 0; background: linear-gradient(135deg, #7dffb2, #38d6a0); color: #04281a;
  font-size: 18px; font-weight: 800; text-decoration: none; box-shadow: 0 8px 28px rgba(60,255,160,.35); }
.cta:disabled { opacity: .6; }
.warn { color: #ffd98a; line-height: 1.5; }

/* ---------- หน้าหลัก ---------- */
body.home { overflow-y: auto; background: radial-gradient(120% 80% at 50% 0%, #0f4a35 0%, #06180f 55%, #03100a 100%); min-height: 100%; }
.wrap { max-width: 520px; margin: 0 auto; padding: calc(var(--safe-t) + 22px) 18px calc(var(--safe-b) + 30px); }
.hero { text-align: center; padding: 18px 0 8px; }
.hero .logo { font-size: 64px; filter: drop-shadow(0 0 22px rgba(125,255,178,.5)); }
.hero h1 { margin: 6px 0 2px; font-size: 32px; letter-spacing: .5px; }
.hero .sub { color: var(--accent); margin: 0; }
.hero p { color: #cdeedd; line-height: 1.6; }
.cards { display: grid; gap: 12px; margin: 16px 0; }
.spot { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 20px; text-decoration: none; background: rgba(255,255,255,.05);
  border: 1px solid var(--line); position: relative; overflow: hidden; }
.spot::before { content: ""; position: absolute; inset: 0; background: radial-gradient(80% 140% at 0% 50%, var(--c), transparent 70%); opacity: .18; }
.spot .em { font-size: 40px; position: relative; }
.spot .tx { flex: 1; position: relative; }
.spot b { display: block; font-size: 18px; }
.spot small { color: var(--muted); }
.spot .st { position: relative; font-size: 22px; }
.spot.locked { opacity: .55; pointer-events: none; }
.spot.finale { border-color: rgba(255,215,107,.6); }
.foot { text-align: center; color: var(--muted); font-size: 13px; line-height: 1.6; }
.foot button { margin-top: 10px; background: none; border: 1px solid var(--line); border-radius: 18px; padding: 6px 14px; color: var(--muted); }
.langrow { display: flex; justify-content: flex-end; }
.progress { text-align: center; color: var(--muted); }
