/* Giao diện tour: tông đêm Tây Nguyên, đỏ thổ cẩm, vàng chiêng */
:root {
  --night: #120d0a;
  --ink: #f6efe6;
  --muted: #c9b9a6;
  --red: #a63a1f;
  --gold: #e0a83a;
  --panel: rgba(20, 14, 10, .86);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--ink);
  font-family: "Be Vietnam Pro", system-ui, sans-serif; }
button { font: inherit; cursor: pointer; }

#viewer { position: fixed; inset: 0; }

/* Hiệu ứng bước đi: phóng nhẹ về phía trước rồi trở lại */
#viewer.walking { animation: walk 1.1s ease-in-out; }
@keyframes walk {
  0%   { transform: scale(1);    filter: blur(0); }
  45%  { transform: scale(1.12); filter: blur(3px) brightness(.8); }
  100% { transform: scale(1);    filter: blur(0); }
}

/* Tên cảnh */
#hud { position: fixed; top: max(16px, env(safe-area-inset-top)); left: 16px; z-index: 50; pointer-events: none; }
#scene-name { font-weight: 800; font-size: clamp(18px, 3vw, 26px); text-shadow: 0 2px 8px rgba(0,0,0,.7); }
#sketch-badge { display: inline-block; margin-top: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px;
  background: rgba(224, 168, 58, .9); color: #2a1a08; font-weight: 600; }
#sketch-badge[hidden] { display: none; }

/* Nút nói chuyện với nhân vật */
.talk { padding: 8px 14px; border-radius: 99px; border: 2px solid var(--gold); background: var(--panel);
  color: var(--ink); font-weight: 600; white-space: nowrap; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px); } }

/* Điểm hiện vật nhấp nháy */
.spot { display: block; width: 26px; height: 26px; border-radius: 50%; background: var(--gold);
  border: 3px solid #fff; box-shadow: 0 0 0 0 rgba(224,168,58,.7); animation: pulse 1.8s infinite; cursor: pointer; }
@keyframes pulse { 70% { box-shadow: 0 0 0 18px rgba(224,168,58,0); } 100% { box-shadow: 0 0 0 0 rgba(224,168,58,0); } }

.link-label { display: block; color: var(--gold); margin-bottom: 4px; }

/* Hộp thoại */
#dialogue { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: max(20px, env(safe-area-inset-bottom)); width: min(760px, calc(100% - 32px));
  display: flex; gap: 16px; padding: 18px; border-radius: 16px; background: var(--panel);
  border: 1px solid rgba(224,168,58,.4); backdrop-filter: blur(6px); animation: rise .4s ease-out; }
#dialogue[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 20px); } }
.portrait { flex: 0 0 76px; height: 76px; border-radius: 50%; background: var(--red) center/cover;
  border: 3px solid var(--gold); display: grid; place-items: center; font-size: 30px; font-weight: 800; }
.dlg-body { flex: 1; min-width: 0; }
.dlg-who { color: var(--gold); font-size: 14px; }
.dlg-who span { color: var(--muted); }
.dlg-vi { font-size: clamp(16px, 2.2vw, 20px); margin: 6px 0; line-height: 1.45; }
.dlg-local { margin: 0; color: var(--gold); font-style: italic; }
.dlg-local:empty { display: none; }
.dlg-en { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.dlg-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
#dlg-progress { color: var(--muted); font-size: 13px; }
#dlg-next { padding: 8px 18px; border-radius: 99px; border: none; background: var(--gold); color: #2a1a08; font-weight: 700; }
@media (max-width: 560px) {
  .portrait { flex-basis: 52px; height: 52px; font-size: 22px; }
  #dialogue { gap: 12px; padding: 14px; }
}

/* Thẻ hiện vật */
#artifact { position: fixed; z-index: 70; top: 16px; right: 16px; bottom: 16px; width: min(380px, calc(100% - 32px));
  overflow-y: auto; padding: 20px; border-radius: 16px; background: var(--panel);
  border: 1px solid rgba(224,168,58,.4); backdrop-filter: blur(6px); animation: slide .35s ease-out; }
#artifact[hidden] { display: none; }
@keyframes slide { from { opacity: 0; transform: translateX(30px); } }
@media (max-width: 560px) {
  #artifact { top: auto; left: 16px; max-height: 70vh; width: auto; }
}
#artifact .close { position: absolute; top: 10px; right: 12px; border: none; background: none; color: var(--ink); font-size: 28px; }
.art-image { height: 200px; border-radius: 10px; background: #2a1f18 center/cover; margin-bottom: 14px; }
.art-image.empty { display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted);
  font-size: 14px; border: 1px dashed rgba(224,168,58,.5); }
#artifact h2 { margin: 0; font-size: 22px; }
.art-local { color: var(--gold); font-style: italic; margin: 4px 0 0; }
.art-local:empty { display: none; }
#art-facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 14px 0; font-size: 14px; }
#art-facts dt { color: var(--muted); }
#art-facts dd { margin: 0; }
#art-story { line-height: 1.6; }
.art-source { color: var(--muted); font-size: 12px; }

/* Màn hình mở đầu */
#intro { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; text-align: center;
  background: radial-gradient(ellipse at 50% 120%, #5a2412 0%, #1c110b 55%, #0b0705 100%); transition: opacity .9s; }
#intro.leaving { opacity: 0; }
#intro[hidden] { display: none; }
.eyebrow { letter-spacing: .3em; text-transform: uppercase; color: var(--gold); font-size: 13px; }
#intro h1 { font-size: clamp(56px, 12vw, 120px); margin: 0; font-weight: 800; letter-spacing: -.02em; }
.lead { color: var(--muted); max-width: 440px; margin: 10px auto 28px; font-size: 17px; }
#enter { padding: 14px 34px; border-radius: 99px; border: 2px solid var(--gold); background: var(--gold); color: #2a1a08;
  font-weight: 800; font-size: 17px; box-shadow: 0 0 40px rgba(224,168,58,.35); }
#enter:hover { background: transparent; color: var(--gold); }
.hint { color: var(--muted); font-size: 13px; margin-top: 18px; }

#error { position: fixed; z-index: 200; left: 16px; right: 16px; bottom: 16px; padding: 14px; border-radius: 10px;
  background: #5c1a0e; color: #fff; }
#error[hidden] { display: none; }

/* ---------- Mini game dàn chiêng ----------
   Bảng nổi ở nửa dưới màn hình, phía trên vẫn thấy cảnh 360 của sân lễ hội. */
.play-game { padding: 12px 20px; border-radius: 99px; border: 2px solid #fff; background: var(--red);
  color: #fff; font-weight: 800; font-size: 16px; box-shadow: 0 0 30px rgba(224,168,58,.6);
  animation: bob 2.4s ease-in-out infinite; white-space: nowrap; }

#game { position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; max-height: 78vh; overflow-y: auto;
  padding: 70px 16px max(18px, env(safe-area-inset-bottom)); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: linear-gradient(to bottom, rgba(18,11,7,0) 0%, rgba(18,11,7,.82) 70px, rgba(18,11,7,.94) 100%);
  animation: rise-panel .45s ease-out; }
#game[hidden] { display: none; }
@keyframes rise-panel { from { transform: translateY(40px); opacity: 0; } }
body.game-open .psv-navbar, body.game-open .psv-virtual-tour-arrows { display: none !important; }

.game-top { display: flex; gap: 10px; align-items: center; justify-content: space-between; width: min(980px, 100%); flex-wrap: wrap; }
.game-tabs { display: flex; gap: 6px; background: rgba(255,255,255,.08); padding: 4px; border-radius: 99px; }
.game-tabs button { border: none; background: none; color: var(--muted); padding: 8px 14px; border-radius: 99px; font-weight: 600; }
.game-tabs button.active { background: var(--gold); color: #2a1a08; }
.back { border: 1px solid rgba(255,255,255,.3); background: rgba(0,0,0,.3); color: var(--ink); padding: 8px 14px; border-radius: 99px; }

.game-options { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }
.game-options label { color: var(--muted); font-size: 14px; }
.game-options select { margin-left: 6px; padding: 6px 10px; border-radius: 8px; border: 1px solid rgba(224,168,58,.5);
  background: #2a1d14; color: var(--ink); font: inherit; }
#game[data-mode="free"] .opt-song, #game[data-mode="free"] #beats { display: none; }
#game:not([data-mode="follow"]) .opt-role, #game:not([data-mode="follow"]) .opt-score { display: none; }
.opt-score { color: var(--muted); font-size: 14px; }
.opt-score b { color: var(--gold); font-size: 18px; }
#game-start, #result-again { padding: 9px 22px; border-radius: 99px; border: none; background: var(--gold);
  color: #2a1a08; font-weight: 800; }
#game-start[hidden] { display: none; }
#game-msg { color: var(--muted); max-width: 620px; margin: 0; min-height: 2.6em; font-size: 14px; }

#gongs { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: clamp(6px, 2vw, 18px);
  padding: 10px 0 18px; max-width: 980px; }
.gong { --d: calc(var(--size) * clamp(70px, 12vw, 130px));
  position: relative; width: var(--d); height: var(--d); border-radius: 50%; border: none; padding: 0;
  transform: translateY(var(--lift)); touch-action: manipulation;
  background: radial-gradient(circle at 35% 30%, #f6d68a 0%, #c8932b 30%, #8a5a17 65%, #4a2d0a 100%);
  box-shadow: inset 0 0 0 6px rgba(0,0,0,.25), inset 0 0 0 12px rgba(255,220,150,.25), 0 10px 30px rgba(0,0,0,.6); }
.gong.boss::after { content: ""; position: absolute; left: 50%; top: 50%; width: 28%; height: 28%; border-radius: 50%;
  transform: translate(-50%, -50%); background: radial-gradient(circle at 35% 30%, #fff1c4, #c8932b 55%, #6b4210);
  box-shadow: 0 4px 10px rgba(0,0,0,.5); }
.gong-name { position: absolute; left: 50%; bottom: -22px; transform: translateX(-50%); white-space: nowrap;
  font-size: 12px; color: var(--muted); }
.gong kbd { position: absolute; top: 4px; right: 4px; font: 600 11px/1 "Be Vietnam Pro", sans-serif; color: #2a1a08;
  background: rgba(255,240,200,.7); border-radius: 4px; padding: 2px 5px; }
.gong.mine { outline: 4px solid #fff; outline-offset: 5px; }
.gong.mine .gong-name { color: var(--gold); font-weight: 700; }
.gong.mine .gong-name::before { content: "★ "; }
.gong.hit { animation: gong-hit .5s ease-out; }
@keyframes gong-hit {
  0% { transform: translateY(var(--lift)) scale(.93); filter: brightness(1.7); }
  100% { transform: translateY(var(--lift)) scale(1); filter: brightness(1); }
}
.gong .ring { position: absolute; inset: -10px; border-radius: 50%; border: 5px solid #fff; opacity: 0;
  pointer-events: none; box-shadow: 0 0 18px rgba(255,255,255,.7); }

#game-feedback { height: 26px; font-weight: 800; font-size: 20px; opacity: 0; }
#game-feedback.show { animation: pop .7s ease-out; }
#game-feedback.perfect { color: #ffe08a; }
#game-feedback.good { color: #b8f0c0; }
#game-feedback.warn { color: #ffb08a; }
#game-feedback.miss { color: #ff8a8a; }
@keyframes pop { 0% { opacity: 0; transform: scale(.7); } 20% { opacity: 1; transform: scale(1.1); } 100% { opacity: 0; transform: scale(1); } }

#beats { display: grid; gap: 4px; width: min(620px, 100%); }
#beats span { height: 12px; border-radius: 4px; background: rgba(255,255,255,.12); transition: background .1s; }
#beats span.downbeat { background: rgba(255,255,255,.22); }
#beats span.mine { background: rgba(224,168,58,.6); }
#beats span.now { background: #fff; box-shadow: 0 0 10px #fff; }

#game-result { background: var(--panel); border: 1px solid rgba(224,168,58,.4); border-radius: 16px;
  padding: 18px; width: min(480px, 100%); }
#game-result[hidden] { display: none; }
#result-percent { font-size: 52px; font-weight: 800; color: var(--gold); line-height: 1; }
#result-score { margin: 6px 0 0; font-weight: 700; }
#result-verdict { font-size: 17px; margin: 8px 0 4px; }
#result-detail { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.result-lesson { font-style: italic; opacity: .85; }

#toast { position: fixed; z-index: 80; top: 70px; left: 50%; transform: translateX(-50%); width: max-content;
  max-width: calc(100% - 32px); padding: 10px 18px; border-radius: 99px; background: var(--panel);
  border: 1px solid var(--gold); font-size: 14px; animation: rise .4s ease-out; }
#toast[hidden] { display: none; }

/* Mô hình 3D và video trong thẻ hiện vật */
.art-image[hidden], .art-3d[hidden], .art-video[hidden] { display: none; }
.art-3d { display: block; width: 100%; height: 260px; border-radius: 10px; margin-bottom: 14px;
  background: radial-gradient(circle at 50% 40%, #4a3424 0%, #1e1510 75%); --poster-color: transparent; }
.art-video { display: block; width: 100%; border-radius: 10px; margin: 4px 0 12px; background: #000; }
@media (max-width: 560px) { .art-3d { height: 200px; } }
/* Nút đóng luôn nằm trên mô hình 3D (mô hình chiếm phần trên của thẻ) */
#artifact .close { z-index: 5; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  line-height: 1; background: rgba(20, 14, 10, .75); }

/* ---------- Màn hình mở đầu: video nền, nút nổi bật, nút nhạc ---------- */
#intro { overflow: hidden; background-size: cover; background-position: center; }
.intro-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 1.2s; }
.intro-video.ready { opacity: 1; }
.intro-video[hidden] { display: none; }
.intro-shade { position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 55%, rgba(12, 7, 4, .25) 0%, rgba(12, 7, 4, .78) 100%); }
.intro-inner { position: relative; z-index: 1; text-shadow: 0 2px 18px rgba(0, 0, 0, .55); }
#intro.has-poster h1, #intro .intro-inner h1 { color: #fff; }

/* Nút "Bước vào làng": tỏa sáng nhịp nhàng để mời bấm */
#enter { position: relative; display: inline-flex; gap: 10px; align-items: center; text-shadow: none;
  animation: enter-glow 2.4s ease-in-out infinite; }
#enter::after { content: ""; position: absolute; inset: -6px; border-radius: 99px; border: 2px solid var(--gold);
  opacity: 0; animation: enter-ring 2.4s ease-out infinite; pointer-events: none; }
.enter-arrow { display: inline-block; transition: transform .25s; animation: enter-nudge 2.4s ease-in-out infinite; }
#enter:hover .enter-arrow { transform: translateX(6px); }
@keyframes enter-glow { 50% { box-shadow: 0 0 46px rgba(224, 168, 58, .75); transform: scale(1.04); } }
@keyframes enter-ring { 0% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(1.35); } }
@keyframes enter-nudge { 50% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { #enter, #enter::after, .enter-arrow { animation: none; } }

/* Nút bật/tắt nhạc: góc trên bên phải, nằm trên cả màn hình mở đầu */
.music-toggle { position: fixed; z-index: 120; top: max(14px, env(safe-area-inset-top)); right: 14px;
  padding: 8px 14px; border-radius: 99px; border: 1px solid rgba(224, 168, 58, .6); background: rgba(20, 14, 10, .7);
  color: var(--ink); font-weight: 600; font-size: 14px; backdrop-filter: blur(6px); }
.music-toggle.on { border-color: var(--gold); color: var(--gold); }
.music-toggle[hidden] { display: none; }
/* Thẻ hiện vật dời xuống một chút để không đè nút nhạc */
@media (min-width: 561px) { #artifact { top: 64px; } }
/* Nhạc đang bật nhưng trình duyệt chờ khách chạm: nhấp nháy nhẹ để mời chạm */
.music-toggle.waiting { color: var(--gold); border-color: var(--gold); animation: music-wait 1.6s ease-in-out infinite; }
@keyframes music-wait { 50% { box-shadow: 0 0 22px rgba(224, 168, 58, .6); } }
