/* =========================================================
   MY STORY – side-scroller
   Kích thước UI nhân var(--s) (scale của trang chủ) cho đồng bộ
   ========================================================= */

/* Khói chuyển cảnh: canvas độ phân giải thấp, phóng to giữ pixel */
.smoke-fx {
  position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 100;
  image-rendering: pixelated; pointer-events: none; visibility: hidden;
}
.smoke-fx.on { visibility: visible; pointer-events: auto; }

.story { position: fixed; inset: 0; z-index: 20; background: #f6efe2; color: var(--ink); }
.story[hidden] { display: none; }
.story__scroll { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; overscroll-behavior: contain; }
.story__scroll::-webkit-scrollbar { display: none; }
.story__track { height: 700vh; position: relative; }
.story__view { position: sticky; top: 0; height: 100vh; overflow: hidden; }

/* ---------- Thế giới (toạ độ ảnh gốc 2172x724) ---------- */
.world { position: absolute; left: 0; top: 0; width: 2172px; height: 724px; transform-origin: 0 0; will-change: transform; }
.world img, .world canvas { position: absolute; display: block; user-select: none; -webkit-user-drag: none; }
.w-base { left: 0; top: 0; width: 2172px; height: 724px; }
.w-train { left: 0; top: 0; width: 2172px; height: 724px; pointer-events: none; }
.w-car { position: absolute; will-change: transform; }
.w-car__img, .w-car__ghost { left: 0; top: 0; width: 100%; height: 100%; }
.w-car__ghost { opacity: var(--o); visibility: hidden; }
.w-smoke { left: 0; top: 0; width: 2172px; height: 724px; image-rendering: pixelated; pointer-events: none; }
.w-parents { position: absolute; left: 0; top: 0; }
.w-sprite { position: absolute; background-repeat: no-repeat; }
.w-shadow { position: absolute; height: 12px; border-radius: 50%; background: rgba(60, 40, 50, .3); filter: blur(2px); }
.w-wave { visibility: hidden; }
.w-wave.on { visibility: visible; }

/* ---------- HUD ---------- */
.hud {
  position: absolute; left: 0; right: 0; top: 0; z-index: 3;
  display: flex; align-items: center; gap: calc(18px * var(--s));
  padding: calc(16px * var(--s)) calc(22px * var(--s));
  font-family: var(--pixel); font-weight: 700; font-size: calc(18px * var(--s)); letter-spacing: calc(1px * var(--s));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.chip {
  display: inline-flex; align-items: center; gap: calc(8px * var(--s));
  padding: calc(8px * var(--s)) calc(14px * var(--s));
  background: rgba(246, 239, 226, .94); color: var(--ink); text-decoration: none;
  border: calc(3px * var(--s)) solid var(--ink); border-radius: calc(8px * var(--s));
  box-shadow: calc(3px * var(--s)) calc(3px * var(--s)) 0 rgba(42, 26, 16, .35);
  font: inherit; cursor: pointer; white-space: nowrap;
}
button.chip:hover, a.chip:hover { background: #ffd23f; }
.hud__sound.off { color: rgba(42, 26, 16, .55); }

.journey { flex: 1; display: flex; justify-content: center; pointer-events: none; }
.journey__bar {
  position: relative; display: flex; align-items: center; gap: calc(54px * var(--s));
  padding: calc(8px * var(--s)) calc(20px * var(--s));
  background: rgba(246, 239, 226, .94); border: calc(3px * var(--s)) solid var(--ink); border-radius: calc(8px * var(--s));
  box-shadow: calc(3px * var(--s)) calc(3px * var(--s)) 0 rgba(42, 26, 16, .35);
}
.journey__bar::before { /* đường ray chấm nối các ga */
  content: ""; position: absolute; left: calc(40px * var(--s)); right: calc(40px * var(--s)); top: 50%;
  border-top: calc(3px * var(--s)) dashed rgba(42, 26, 16, .35);
}
.journey__stop { position: relative; display: flex; align-items: center; gap: calc(7px * var(--s)); background: rgba(246, 239, 226, 1); padding: 0 calc(6px * var(--s)); }
.journey__stop i { width: calc(11px * var(--s)); height: calc(11px * var(--s)); background: var(--ink); transform: rotate(45deg); }
.journey__stop.here i { background: var(--orange); }
.journey__stop:not(.here) { color: rgba(42, 26, 16, .5); }
.journey__marker { color: var(--orange);
  --k: 0; position: absolute; top: calc(-22px * var(--s)); left: calc(16px * var(--s) + (100% - 40px * var(--s)) * var(--k));
  font-size: calc(18px * var(--s)); animation: chug .5s steps(2) infinite;
}
@keyframes chug { 50% { transform: translateY(calc(-2px * var(--s))); } }
.party b { color: var(--orange-dark); }

/* ---------- Hộp thoại RPG ---------- */
.dialog {
  position: absolute; left: 50%; bottom: calc(26px * var(--s)); z-index: 3; transform: translateX(-50%);
  width: min(calc(1080px * var(--s)), calc(100vw - 32px));
  display: flex; gap: calc(18px * var(--s)); align-items: stretch;
  padding: calc(16px * var(--s)) calc(22px * var(--s)) calc(18px * var(--s)) calc(16px * var(--s));
  background: rgba(246, 239, 226, .97); border: calc(4px * var(--s)) solid var(--ink); border-radius: calc(10px * var(--s));
  box-shadow: calc(6px * var(--s)) calc(6px * var(--s)) 0 rgba(42, 26, 16, .4), inset 0 0 0 calc(3px * var(--s)) #fffaf0;
}
.dialog--top { bottom: auto; top: calc(78px * var(--s)); left: calc(22px * var(--s)); transform: none; width: min(calc(760px * var(--s)), 56vw); }
.dialog--top .dialog__text { min-height: 1.32em; }
.dialog__face {
  flex: none; width: calc(96px * var(--s)); height: calc(96px * var(--s));
  background: #e9dcc4; border: calc(3px * var(--s)) solid var(--ink); border-radius: calc(6px * var(--s));
  display: flex; align-items: flex-end; justify-content: center; overflow: hidden;
}
.dialog__face img { width: 100%; image-rendering: pixelated; }
.dialog__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: calc(6px * var(--s)); }
.dialog__name {
  align-self: flex-start; font-family: var(--pixel); font-weight: 700; font-size: calc(17px * var(--s)); letter-spacing: calc(1px * var(--s));
  color: #fff4e6; background: var(--orange); border: calc(2px * var(--s)) solid var(--orange-dark); border-radius: calc(4px * var(--s));
  padding: calc(2px * var(--s)) calc(10px * var(--s));
}
.dialog__text {
  font-family: var(--pixel); font-weight: 600; font-size: calc(27px * var(--s)); line-height: 1.32;
  min-height: 2.64em;
}
.dialog__more {
  position: absolute; right: calc(18px * var(--s)); bottom: calc(10px * var(--s));
  font-family: var(--pixel); font-weight: 700; font-size: calc(15px * var(--s)); color: var(--orange-dark);
  visibility: hidden; animation: blink 1s steps(1) infinite;
}
.dialog__more.on { visibility: visible; }

/* ---------- Màn tên chương ---------- */
.title-card {
  position: absolute; left: 0; right: 0; top: 34%; z-index: 4; text-align: center; pointer-events: none;
  opacity: 0;
}
.title-card.on { animation: titleIn 3s steps(1) forwards; }
.title-card h2 {
  font-family: var(--pixel); font-weight: 700; font-size: calc(96px * var(--s)); line-height: 1; letter-spacing: calc(4px * var(--s));
  color: #fff6e6;
  text-shadow:
    calc(4px * var(--s)) 0 0 var(--ink), calc(-4px * var(--s)) 0 0 var(--ink), 0 calc(4px * var(--s)) 0 var(--ink), 0 calc(-4px * var(--s)) 0 var(--ink),
    calc(4px * var(--s)) calc(4px * var(--s)) 0 var(--ink), calc(-4px * var(--s)) calc(4px * var(--s)) 0 var(--ink),
    calc(4px * var(--s)) calc(-4px * var(--s)) 0 var(--ink), calc(-4px * var(--s)) calc(-4px * var(--s)) 0 var(--ink),
    calc(9px * var(--s)) calc(9px * var(--s)) 0 var(--orange-dark);
}
.title-card p {
  display: inline-block; margin-top: calc(22px * var(--s));
  font-family: var(--pixel); font-weight: 700; font-size: calc(28px * var(--s)); letter-spacing: calc(3px * var(--s));
  padding: calc(8px * var(--s)) calc(22px * var(--s));
  background: rgba(255, 246, 230, .95); border: calc(4px * var(--s)) solid var(--ink); border-radius: calc(10px * var(--s));
  box-shadow: calc(5px * var(--s)) calc(5px * var(--s)) 0 rgba(42, 26, 16, .35);
}
@keyframes titleIn {
  0% { opacity: 0; transform: scale(.9); }
  6% { opacity: 1; transform: scale(1.04); }
  12% { transform: none; }
  80% { opacity: 1; }
  86% { opacity: .5; }
  92%, 100% { opacity: 0; }
}

/* ---------- Popup kiểu game ---------- */
.popup {
  position: absolute; right: calc(24px * var(--s)); top: calc(200px * var(--s)); z-index: 4;
  display: flex; flex-direction: column; gap: calc(4px * var(--s));
  padding: calc(10px * var(--s)) calc(18px * var(--s));
  font-family: var(--pixel); font-size: calc(17px * var(--s));
  background: #ffd23f; border: calc(3px * var(--s)) solid var(--ink); border-radius: calc(8px * var(--s));
  box-shadow: calc(4px * var(--s)) calc(4px * var(--s)) 0 rgba(42, 26, 16, .4);
  opacity: 0; transform: translateX(calc(30px * var(--s))); pointer-events: none;
}
.popup b { font-size: calc(21px * var(--s)); letter-spacing: calc(1px * var(--s)); }
.popup.on { animation: popIn 3.2s steps(1) forwards; }
@keyframes popIn {
  0% { opacity: 0; transform: translateX(calc(30px * var(--s))); }
  4% { opacity: 1; transform: translateX(calc(-6px * var(--s))); }
  8% { transform: none; opacity: 1; }
  88% { opacity: 1; transform: none; }
  94%, 100% { opacity: 0; transform: translateX(calc(30px * var(--s))); }
}

/* "TOOT TOOT!" bật ra cạnh ống xả – JS đặt vị trí theo đầu tàu */
.toot { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; }
.toot span {
  display: inline-block; transform-origin: 0 100%;
  font-family: var(--pixel); font-weight: 700; font-size: calc(46px * var(--s)); letter-spacing: calc(2px * var(--s));
  color: #ffd23f; opacity: 0; white-space: nowrap;
  text-shadow:
    calc(3px * var(--s)) 0 0 var(--ink), calc(-3px * var(--s)) 0 0 var(--ink), 0 calc(3px * var(--s)) 0 var(--ink), 0 calc(-3px * var(--s)) 0 var(--ink),
    calc(3px * var(--s)) calc(3px * var(--s)) 0 var(--ink), calc(-3px * var(--s)) calc(-3px * var(--s)) 0 var(--ink),
    calc(3px * var(--s)) calc(-3px * var(--s)) 0 var(--ink), calc(-3px * var(--s)) calc(3px * var(--s)) 0 var(--ink),
    calc(6px * var(--s)) calc(6px * var(--s)) 0 var(--orange-dark);
}
.toot.on span { animation: toot 1.7s steps(1) forwards; }
@keyframes toot {
  0% { opacity: 1; transform: scale(.6) rotate(-6deg); }
  8% { transform: scale(1.18) rotate(-6deg); }
  16% { transform: scale(1) rotate(-6deg); }
  27% { transform: scale(1.14) rotate(4deg); }
  35% { transform: scale(1) rotate(4deg); }
  80% { opacity: 1; transform: translateY(calc(-14px * var(--s))) rotate(4deg); }
  100% { opacity: 0; transform: translateY(calc(-26px * var(--s))) rotate(4deg); }
}

/* chớp trắng khi tua lại cảnh */
.flash { position: absolute; inset: 0; z-index: 6; background: #fffaf0; opacity: 0; pointer-events: none; }
.flash.on { animation: flash .45s steps(3) forwards; }
@keyframes flash { 0% { opacity: 0; } 30% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Kết chương ---------- */
.end-card {
  position: absolute; left: 50%; top: 38%; z-index: 5; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: calc(14px * var(--s));
  padding: calc(24px * var(--s)) calc(34px * var(--s));
  background: rgba(246, 239, 226, .97); border: calc(4px * var(--s)) solid var(--ink); border-radius: calc(12px * var(--s));
  box-shadow: calc(7px * var(--s)) calc(7px * var(--s)) 0 rgba(42, 26, 16, .4);
  font-family: var(--pixel); text-align: center;
  visibility: hidden; opacity: 0; transition: opacity .3s steps(3), visibility 0s .3s;
}
.story.is-next .world, .story.is-next .dialog, .story.is-next .toot, .story.is-next .popup { visibility: hidden; }
.story.is-next .end-card { top: 50%; }
.end-card.on { visibility: visible; opacity: 1; transition: opacity .3s steps(3); }
.end-card h3 { font-size: calc(44px * var(--s)); font-weight: 700; letter-spacing: calc(2px * var(--s)); color: var(--orange-dark); }
.end-card p { font-size: calc(20px * var(--s)); font-weight: 600; }
.end-card__row { display: flex; gap: calc(12px * var(--s)); margin-top: calc(6px * var(--s)); }
.end-card .chip { font-weight: 700; font-size: calc(18px * var(--s)); }
.end-card .chip[disabled] { cursor: default; color: rgba(42, 26, 16, .45); background: #e9dcc4; }

/* Gợi ý kéo xuống lúc mở đầu */
.scroll-hint {
  position: absolute; right: calc(28px * var(--s)); bottom: calc(190px * var(--s)); z-index: 3;
  font-family: var(--pixel); font-weight: 700; font-size: calc(16px * var(--s)); color: #fff6e6;
  text-shadow: calc(2px * var(--s)) calc(2px * var(--s)) 0 var(--ink);
  animation: blink 1.1s steps(1) infinite;
}

@media (prefers-reduced-motion: reduce) {
  .journey__marker, .dialog__more, .scroll-hint { animation: none; }
  .title-card.on { animation: none; opacity: 1; }
}
.scroll-hint.gone { display: none; }

/* =========================================================
   MÀN BẢN ĐỒ (Ninh Bình → Nha Trang)
   ========================================================= */
.map { position: absolute; inset: 0; overflow: hidden; background: #22609e; visibility: hidden; }
.story.is-map .map { visibility: visible; }
.story.is-map .world, .story.is-map .toot { visibility: hidden; }
.map__world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.map__sky { pointer-events: none; }
.mcloud { position: absolute; left: 0; top: 0; background-repeat: no-repeat; image-rendering: auto; will-change: transform; }
.mcloud--sh { filter: brightness(0); opacity: .16; }
.map__world > * { position: absolute; left: 0; top: 0; image-rendering: pixelated; image-rendering: crisp-edges; user-select: none; -webkit-user-drag: none; }
/* viền tối mép màn hình cho cảm giác tấm bản đồ cũ */
.map::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 calc(120px * var(--s)) rgba(20, 30, 50, .45); }
.map__labels { position: absolute; inset: 0; pointer-events: none; }

/* ga trên tuyến */
.mpin { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: calc(6px * var(--s));
  font-family: var(--pixel); font-weight: 700; font-size: calc(15px * var(--s)); letter-spacing: calc(1px * var(--s));
  white-space: nowrap; will-change: transform; }
.mpin > i { flex: none; display: block; width: calc(12px * var(--s)); height: calc(12px * var(--s)); margin-left: calc(-6px * var(--s));
  background: #fff6e6; border: calc(3px * var(--s)) solid var(--ink); transform: rotate(45deg); font-style: normal; }
.mpin > span { display: flex; flex-direction: column; line-height: 1.05;
  padding: calc(3px * var(--s)) calc(8px * var(--s)); background: rgba(246, 239, 226, .95);
  border: calc(2px * var(--s)) solid var(--ink); border-radius: calc(5px * var(--s));
  box-shadow: calc(2px * var(--s)) calc(2px * var(--s)) 0 rgba(42, 26, 16, .4); color: rgba(42, 26, 16, .6); }
.mpin small { font-size: calc(11px * var(--s)); color: var(--orange-dark); letter-spacing: calc(2px * var(--s)); }
.mpin.on > i { background: var(--orange); }
.mpin.on > span { color: var(--ink); }
.mpin.pop > span { animation: pinPop .5s steps(4); }
@keyframes pinPop { 0% { transform: translateY(0); } 40% { transform: translateY(calc(-8px * var(--s))); background: #ffd23f; } 100% { transform: none; } }
/* đích: cờ Nha Trang nhấp nháy */
.mpin--end > i { background: #ffd23f; animation: blink 1s steps(1) infinite; }
.mpin--end.on > i { animation: none; background: var(--orange); }
.mpin--end > span { color: var(--ink); }
.mpin--end.on > span { background: #ffd23f; animation: pinPop .6s steps(4) 2; }
/* thủ đô: chỉ chấm sao nhỏ, mờ */
.mpin--cap > i { width: auto; height: auto; margin-left: calc(-7px * var(--s)); border: 0; background: none; transform: none;
  color: #c0392b; font-size: calc(16px * var(--s)); text-shadow: 0 0 2px #fff6e6; }
.mpin--cap > span { background: none; border: 0; box-shadow: none; padding: 0; color: rgba(42, 26, 16, .75);
  text-shadow: 1px 1px 0 #fff6e6, -1px -1px 0 #fff6e6, 1px -1px 0 #fff6e6, -1px 1px 0 #fff6e6; font-size: calc(13px * var(--s)); }
.mpin--start > span, .mpin--cap { transform-origin: 0 50%; }
/* dịch nhãn sang trái cho các ga nằm sát bờ biển (đặt nhãn phía đất liền) */
.mpin--stop, .mpin--start, .mpin--end { flex-direction: row-reverse; }
.mpin--stop > i, .mpin--start > i, .mpin--end > i { margin-left: 0; margin-right: calc(-6px * var(--s)); }
.mpin { translate: -100% -50%; }
.mpin--cap { flex-direction: row-reverse; }
.mpin--cap > i { margin-left: 0; margin-right: calc(-7px * var(--s)); }

/* quần đảo + biển */
.mlabel { position: absolute; left: 0; top: 0; translate: -50% -100%; display: flex; flex-direction: column; align-items: center;
  font-family: var(--pixel); font-weight: 700; color: #fff6e6; white-space: nowrap; line-height: 1.1;
  text-shadow: calc(2px * var(--s)) calc(2px * var(--s)) 0 #163a5c; will-change: transform; }
.mlabel b { font-size: calc(15px * var(--s)); letter-spacing: calc(1px * var(--s)); }
.mlabel span { font-size: calc(11px * var(--s)); letter-spacing: calc(2px * var(--s)); opacity: .85; }
.mlabel--sea { translate: -50% -50%; font-size: calc(22px * var(--s)); letter-spacing: calc(10px * var(--s)); color: rgba(214, 238, 240, .55); text-shadow: none; }

/* HUD: km tính từ nhà (đường chim bay) – chỉ hiện ở màn bản đồ */
.km { display: none; }
.story.is-map .km { display: inline-flex; }
.km b { color: var(--orange-dark); min-width: 3ch; text-align: right; }
.journey__stop.been i { background: var(--orange-dark); }
.journey__stop.been { color: rgba(42, 26, 16, .75); }

.story.is-map .end-card { top: 44%; left: 74%; }
@media (max-aspect-ratio: 1/1) { .story.is-map .end-card { left: 50%; top: 72%; } }
.story.is-map .end-card.on ~ .dialog, .story.is-map .dialog:has(~ .end-card.on) { visibility: hidden; }
@media (prefers-reduced-motion: reduce) {
  .mpin--end > i, .mpin.pop > span, .mpin--end.on > span { animation: none; }
}

/* =========================================================
   WORLD 2 – NHA TRANG
   ========================================================= */
.w2 { position: absolute; inset: 0; overflow: hidden; display: none; background: #8fc6e8; }
.story.is-w2 .w2 { display: block; }
.story.is-w2 .w2 { visibility: visible; }
.story.is-w2 .world, .story.is-w2 .map, .story.is-w2 .toot, .story.is-w2 .km { visibility: hidden; }
.story.is-w2 .km { display: none; }
.w2__world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.w2-panel { position: absolute; top: 0; overflow: hidden; }
.w2-panel img { position: absolute; top: 0; height: 100%; width: auto; max-width: none; display: block; user-select: none; -webkit-user-drag: none; }
.w2-panel--fade { -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 160px); mask-image: linear-gradient(90deg, transparent 0, #000 160px); }
.w2-sprite { position: absolute; left: 0; background-repeat: no-repeat; image-rendering: auto; z-index: 20; will-change: transform; }
.w2-bike { z-index: 21; }
.w2__fx { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; pointer-events: none; }
/* biển gỗ ven đường */
.w2-sign { position: absolute; top: 452px; z-index: 10; display: flex; flex-direction: column; align-items: center; transform: translateX(-50%); }
.w2-sign b { position: relative; z-index: 1; font-family: var(--pixel); font-weight: 700; font-size: 30px; letter-spacing: 2px; color: #fff6e6; white-space: nowrap;
  padding: 8px 26px 8px 18px; background: #9a5b2c; border: 4px solid #4a2a14; clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 50%, calc(100% - 18px) 100%, 0 100%);
  box-shadow: inset 0 -6px 0 #7a4422; text-shadow: 2px 2px 0 #4a2a14; }
.w2-sign i { display: block; width: 14px; height: 96px; background: #7a4422; border: 3px solid #4a2a14; border-top: 0; margin-top: -2px; }
.w2-sign--year b { font-size: 34px; background: #b8461a; }
/* tên trường trên tấm biển dưới mái cổng */
.w2-plaque { position: absolute; top: 470px; z-index: 5; transform: translateX(-50%); padding: 3px 8px;
  font-family: var(--pixel); font-weight: 700; font-size: 11px; letter-spacing: .5px; color: #ffd23f; white-space: nowrap;
  background: #8e1f1a; border: 2px solid #5a1410; }

/* chuyển cảnh: khử pixel */
.zoomfx { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 7; image-rendering: pixelated; visibility: hidden; pointer-events: none; }
.zoomfx.on { visibility: visible; }

/* banner khu vực mới */
.area { position: absolute; right: calc(24px * var(--s)); top: calc(118px * var(--s)); z-index: 4; display: flex; flex-direction: column; align-items: flex-end;
  font-family: var(--pixel); font-weight: 700; color: #fff6e6; pointer-events: none; opacity: 0; white-space: nowrap; }
.area small { font-size: calc(14px * var(--s)); letter-spacing: calc(4px * var(--s)); color: #ffd23f; text-shadow: calc(2px * var(--s)) calc(2px * var(--s)) 0 var(--ink); }
.area b { font-size: calc(30px * var(--s)); letter-spacing: calc(2px * var(--s)); padding: calc(6px * var(--s)) calc(18px * var(--s));
  background: rgba(42, 26, 16, .82); border: calc(3px * var(--s)) solid #ffd23f; border-radius: calc(8px * var(--s)); }
.area.on { animation: areaIn 4s steps(1) forwards; }
@keyframes areaIn { 0% { opacity: 0; transform: translateY(calc(-10px * var(--s))); } 5% { opacity: 1; transform: none; } 85% { opacity: 1; } 92%, 100% { opacity: 0; } }

/* tem phượt (HUD, dưới thanh hành trình) */
.stamps { position: absolute; right: calc(24px * var(--s)); top: calc(74px * var(--s)); z-index: 3; display: none; gap: calc(10px * var(--s)); pointer-events: none; }
.story.is-w2 .stamps.on { display: flex; }
.stamp { display: flex; align-items: center; gap: calc(6px * var(--s)); padding: calc(4px * var(--s)) calc(10px * var(--s));
  font-family: var(--pixel); font-weight: 700; font-size: calc(14px * var(--s)); letter-spacing: calc(1px * var(--s)); color: rgba(42, 26, 16, .4);
  background: rgba(246, 239, 226, .7); border: calc(2px * var(--s)) dashed rgba(42, 26, 16, .4); border-radius: calc(6px * var(--s)); }
.stamp i { width: calc(10px * var(--s)); height: calc(10px * var(--s)); border: calc(2px * var(--s)) solid rgba(42, 26, 16, .4); border-radius: 50%; }
.stamp.on { color: var(--ink); background: #ffd23f; border: calc(2px * var(--s)) solid var(--ink); animation: stampIn .35s steps(3); }
.stamp.on i { background: var(--orange); border-color: var(--ink); }
@keyframes stampIn { 0% { transform: scale(1.6) rotate(-8deg); } 100% { transform: none; } }

/* bảng nhiệm vụ */
.quest { position: absolute; right: calc(24px * var(--s)); top: calc(118px * var(--s)); z-index: 3; width: calc(330px * var(--s));
  padding: calc(12px * var(--s)) calc(16px * var(--s)); font-family: var(--pixel); color: var(--ink);
  background: rgba(246, 239, 226, .96); border: calc(3px * var(--s)) solid var(--ink); border-radius: calc(8px * var(--s));
  box-shadow: calc(4px * var(--s)) calc(4px * var(--s)) 0 rgba(42, 26, 16, .4);
  visibility: hidden; opacity: 0; transform: translateX(calc(30px * var(--s))); transition: opacity .25s steps(3), transform .25s steps(3), visibility 0s .25s; }
.story.is-w2 .quest.on { visibility: visible; opacity: 1; transform: none; transition: opacity .25s steps(3), transform .25s steps(3); }
.quest h4 { font-size: calc(14px * var(--s)); letter-spacing: calc(3px * var(--s)); color: var(--orange-dark); margin-bottom: calc(6px * var(--s)); }
.quest p { display: flex; align-items: center; gap: calc(8px * var(--s)); font-size: calc(17px * var(--s)); font-weight: 600; line-height: 1.5; }
.quest p i { flex: none; width: calc(16px * var(--s)); height: calc(16px * var(--s)); border: calc(2px * var(--s)) solid var(--ink); border-radius: calc(3px * var(--s)); background: #fff; position: relative; }
.quest:not(.unlock) .quest__side { visibility: hidden; height: 0; }
.quest.intern .quest__side i, .quest.done .quest__main i { background: var(--orange); }
.quest.intern .quest__side i::after, .quest.done .quest__main i::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: calc(13px * var(--s)); font-weight: 700; line-height: 1; }
.quest.intern .quest__side, .quest.done .quest__main { color: rgba(42, 26, 16, .55); text-decoration: line-through; }
.quest__xp { display: flex; align-items: center; gap: calc(8px * var(--s)); margin-top: calc(8px * var(--s)); font-size: calc(13px * var(--s)); font-weight: 700; }
.quest__xp b { flex: 1; height: calc(12px * var(--s)); border: calc(2px * var(--s)) solid var(--ink); background:
  linear-gradient(90deg, #ffd23f calc(var(--xp) * 100%), #e9dcc4 0); }
.quest.done .quest__xp b { --xp: 1 !important; }
.quest__xp b { background: linear-gradient(90deg, #ffd23f 0, #ffd23f calc(var(--xp, 0) * 100%), #e9dcc4 calc(var(--xp, 0) * 100%)); }

/* ảnh tốt nghiệp dạng polaroid */
.polaroid { position: absolute; left: 50%; top: 52%; z-index: 5; width: min(calc(820px * var(--s)), 70vw); margin: 0;
  padding: calc(14px * var(--s)) calc(14px * var(--s)) 0; background: #fffaf0; border: calc(3px * var(--s)) solid var(--ink);
  box-shadow: calc(8px * var(--s)) calc(8px * var(--s)) 0 rgba(42, 26, 16, .45);
  transform: translate(-50%, -50%) rotate(-3deg) scale(.6); opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform .45s steps(5), opacity .2s steps(2), visibility 0s .45s; }
.polaroid img { display: block; width: 100%; border: calc(2px * var(--s)) solid var(--ink); }
.polaroid figcaption { font-family: var(--pixel); font-weight: 700; font-size: calc(24px * var(--s)); letter-spacing: calc(2px * var(--s));
  text-align: center; padding: calc(12px * var(--s)) 0 calc(16px * var(--s)); color: var(--orange-dark); }
.story.is-w2 .polaroid.on { opacity: 1; visibility: visible; transform: translate(-50%, -50%) rotate(-3deg); transition: transform .45s steps(5), opacity .2s steps(2); }
.story.is-w2 .end-card { top: auto; bottom: calc(24px * var(--s)); transform: translateX(-50%); }
.story.is-w2 .end-card h3 { font-size: calc(34px * var(--s)); }
.story__view:has(.polaroid.on) .dialog { visibility: hidden; }
@media (prefers-reduced-motion: reduce) { .area.on, .stamp.on { animation: none; } .area.on { opacity: 1; } }

/* ---------- Chuyến bay Nha Trang → Hà Nội ---------- */
.mpin--cap.mpin--dest > i { color: #ffd23f; font-size: calc(26px * var(--s)); text-shadow: calc(2px * var(--s)) calc(2px * var(--s)) 0 var(--ink); animation: blink 1s steps(1) infinite; }
.mpin--cap.mpin--dest > span { padding: calc(3px * var(--s)) calc(8px * var(--s)); font-size: calc(15px * var(--s)); color: var(--ink); text-shadow: none;
  background: rgba(246, 239, 226, .95); border: calc(2px * var(--s)) solid var(--ink); border-radius: calc(5px * var(--s)); box-shadow: calc(2px * var(--s)) calc(2px * var(--s)) 0 rgba(42, 26, 16, .4); }
.mpin--cap.mpin--dest.on > i { animation: none; color: var(--orange); }
.mpin--cap.mpin--dest.on > span { background: #ffd23f; animation: pinPop .6s steps(4) 2; }
@media (prefers-reduced-motion: reduce) { .mpin--cap.mpin--dest > i, .mpin--cap.mpin--dest.on > span { animation: none; } }

/* =========================================================
   WORLD 3 – HÀ NỘI
   ========================================================= */
.w3 { position: absolute; inset: 0; overflow: hidden; display: none; background: #8fc6e8; }
.story.is-w3 .w3 { display: block; }
.story.is-w3 .world, .story.is-w3 .map, .story.is-w3 .toot, .story.is-w3 .km { visibility: hidden; }
.story.is-w3 .km { display: none; }
.w3__world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.w3__dark { position: absolute; inset: 0; background: #1b2238; mix-blend-mode: multiply; opacity: 0; pointer-events: none; }
.w3__glow { position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at 75% 30%, rgba(255, 214, 140, .28), transparent 60%), linear-gradient(180deg, rgba(160, 140, 255, .12), transparent 60%); }
.w3__fx { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; pointer-events: none; }
.w3__bolt { position: absolute; inset: 0; background: #eef4ff; opacity: 0; pointer-events: none; }
.w3__bolt.on { animation: bolt .5s steps(1) forwards; }
@keyframes bolt { 0% { opacity: .75; } 12% { opacity: 0; } 22% { opacity: .5; } 34%, 100% { opacity: 0; } }
.w3-leavers { z-index: 21; }

/* thanh RESILIENCE (HUD, bên phải dưới PARTY) */
.meter { position: absolute; right: calc(24px * var(--s)); top: calc(74px * var(--s)); z-index: 3; display: none; align-items: center; gap: calc(8px * var(--s));
  padding: calc(6px * var(--s)) calc(12px * var(--s)); font-family: var(--pixel); font-weight: 700; font-size: calc(14px * var(--s)); letter-spacing: calc(2px * var(--s));
  background: rgba(246, 239, 226, .94); border: calc(3px * var(--s)) solid var(--ink); border-radius: calc(8px * var(--s));
  box-shadow: calc(3px * var(--s)) calc(3px * var(--s)) 0 rgba(42, 26, 16, .35); }
.story.is-w3 .meter.on { display: flex; }
.meter b { --v: 0; display: block; width: calc(170px * var(--s)); height: calc(14px * var(--s)); border: calc(2px * var(--s)) solid var(--ink); background: #e9dcc4; position: relative; }
.meter i { position: absolute; inset: 0; right: auto; width: calc(var(--v) * 100%); background: repeating-linear-gradient(90deg, var(--orange) 0 calc(8px * var(--s)), var(--orange-dark) calc(8px * var(--s)) calc(10px * var(--s))); }
.meter { --v: 0; }
.meter b { --v: inherit; }
.meter.max { background: #ffd23f; animation: pinPop .6s steps(4) 2; }
.story.is-w3 .area { top: calc(124px * var(--s)); }

/* =========================================================
   BẢNG NHÂN VẬT (kết MY STORY, hiện trên trang chủ)
   ========================================================= */
.sheet { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; pointer-events: none; }
.sheet[hidden] { display: none; }
.sheet__card { pointer-events: auto; position: relative; width: min(calc(980px * var(--s)), 92vw); max-height: 90vh; overflow: auto;
  padding: calc(22px * var(--s)) calc(30px * var(--s)) calc(24px * var(--s)); font-family: var(--pixel); color: var(--ink);
  background: rgba(246, 239, 226, .97); border: calc(4px * var(--s)) solid var(--ink); border-radius: calc(12px * var(--s));
  box-shadow: calc(8px * var(--s)) calc(8px * var(--s)) 0 rgba(42, 26, 16, .45), inset 0 0 0 calc(3px * var(--s)) #fffaf0;
  transform: translateX(calc(60px * var(--s))); opacity: 0; transition: transform .35s steps(5), opacity .25s steps(3); }
.sheet.on .sheet__card { transform: none; opacity: 1; }
.sheet__close { position: absolute; right: calc(12px * var(--s)); top: calc(10px * var(--s)); font: inherit; font-size: calc(20px * var(--s)); font-weight: 700;
  background: none; border: 0; color: var(--ink); cursor: pointer; }
.sheet__title { font-size: calc(30px * var(--s)); letter-spacing: calc(3px * var(--s)); color: var(--orange-dark); margin-bottom: calc(14px * var(--s)); }
.sheet__body { display: grid; grid-template-columns: calc(250px * var(--s)) 1fr; gap: calc(26px * var(--s)); }
.sheet__who { display: flex; flex-direction: column; align-items: center; gap: calc(6px * var(--s)); text-align: center; }
.sheet__face { width: calc(150px * var(--s)); height: calc(150px * var(--s)); background: #e9dcc4; border: calc(3px * var(--s)) solid var(--ink); border-radius: calc(8px * var(--s));
  display: flex; align-items: flex-end; justify-content: center; overflow: hidden; }
.sheet__face img { width: 100%; image-rendering: pixelated; }
.sheet__name { font-size: calc(24px * var(--s)); letter-spacing: calc(3px * var(--s)); }
.sheet__class { font-size: calc(14px * var(--s)); font-weight: 700; color: #fff4e6; background: var(--orange); border: calc(2px * var(--s)) solid var(--orange-dark); border-radius: calc(4px * var(--s)); padding: calc(2px * var(--s)) calc(8px * var(--s)); }
.sheet__quote { font-size: calc(15px * var(--s)); font-style: italic; opacity: .8; margin-top: calc(4px * var(--s)); }
.sheet__stats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: calc(9px * var(--s)); justify-content: center; }
.sheet__stats li { display: grid; grid-template-columns: calc(150px * var(--s)) 1fr calc(44px * var(--s)); align-items: center; gap: calc(10px * var(--s)); font-size: calc(17px * var(--s)); font-weight: 700; letter-spacing: calc(1px * var(--s)); }
.sheet__stats b { height: calc(16px * var(--s)); border: calc(2px * var(--s)) solid var(--ink); background: #e9dcc4; position: relative; }
.sheet__stats i { position: absolute; inset: 0; right: auto; width: 0; background: repeating-linear-gradient(90deg, var(--orange) 0 calc(10px * var(--s)), var(--orange-dark) calc(10px * var(--s)) calc(12px * var(--s))); transition: width 1.2s steps(12); }
.sheet.play .sheet__stats i { width: calc(var(--v) * 100%); }
.sheet__stats li:nth-child(-n+2) span { color: var(--orange-dark); }
.sheet__stats em { font-style: normal; text-align: right; opacity: 0; transition: opacity .2s steps(2) 1.2s; }
.sheet.play .sheet__stats em { opacity: 1; }
.sheet__story { margin-top: calc(16px * var(--s)); padding-top: calc(12px * var(--s)); border-top: calc(3px * var(--s)) dashed rgba(42, 26, 16, .3); min-height: 4.2em; }
.sheet__line { font-size: calc(20px * var(--s)); font-weight: 600; line-height: 1.35; }
.sheet__row { display: flex; flex-wrap: wrap; gap: calc(12px * var(--s)); margin-top: calc(16px * var(--s)); }
.sheet__row .chip { font-weight: 700; font-size: calc(17px * var(--s)); }
.sheet__cta-btn { background: #ffd23f; }
@media (max-aspect-ratio: 1/1) { .sheet__body { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { .sheet__stats i { transition: none; } }
.sheet__badge { display: inline-block; margin-bottom: calc(8px * var(--s)); padding: calc(3px * var(--s)) calc(10px * var(--s)); font-size: calc(14px * var(--s)); letter-spacing: calc(1px * var(--s));
  background: #ffd23f; border: calc(2px * var(--s)) solid var(--ink); border-radius: calc(5px * var(--s)); opacity: 0; }
.sheet.play .sheet__badge { opacity: 1; animation: pinPop .6s steps(4); }

/* bảng tên trên đầu nhân vật (World 3) – toạ độ thế giới, phóng to cùng cảnh */
.w3-tag { position: absolute; z-index: 15; transform: translate(-50%, -100%); padding: 3px 10px 4px; white-space: nowrap; pointer-events: none;
  font-family: var(--pixel); font-weight: 700; font-size: 17px; letter-spacing: 1px; line-height: 1;
  color: #fff6e6; background: var(--orange); border: 3px solid var(--ink); border-radius: 6px; box-shadow: 3px 3px 0 rgba(42, 26, 16, .45);
  animation: tagBob 1.6s steps(2) infinite; }
.w3-tag::after { content: ""; position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%);
  border: 7px solid transparent; border-top: 7px solid var(--ink); border-bottom: 0; }
.w3-tag--boss { color: var(--ink); background: #ffd23f; }
.w3-tag--boss1 { color: var(--ink); background: #e9dcc4; }
.w3-tag--wife { color: #fff6e6; background: #d9486a; }
@keyframes tagBob { 50% { transform: translate(-50%, calc(-100% - 3px)); } }
@media (prefers-reduced-motion: reduce) { .w3-tag { animation: none; } }

/* ---------- hiệu ứng chuyển cảnh (lớp phủ mở ra để lộ cảnh mới) ---------- */
@property --r { syntax: '<length>'; inherits: false; initial-value: 0px; }
@property --b { syntax: '<length>'; inherits: false; initial-value: 0px; }
.trans { position: absolute; inset: 0; z-index: 6; pointer-events: none; visibility: hidden; }
.trans.on { visibility: visible; }
/* iris: vòng tròn mở dần */
.trans.t-iris { background: #2a1a10;
  -webkit-mask: radial-gradient(circle at 50% 55%, transparent var(--r), #000 calc(var(--r) + 1px));
          mask: radial-gradient(circle at 50% 55%, transparent var(--r), #000 calc(var(--r) + 1px));
  animation: tIris 1s steps(12) forwards; }
@keyframes tIris { 0% { --r: 0px; } 15% { --r: 24px; } 100% { --r: 110vmax; visibility: hidden; } }
/* màn đêm buông: tối sầm rồi sáng dần */
.trans.t-night { background: #0d1230; animation: tNight 1.1s steps(8) forwards; }
@keyframes tNight { 0% { opacity: 1; } 35% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
/* rèm mưa: các dải ngang mở dần */
.trans.t-blinds { background: #5b6b80;
  -webkit-mask: repeating-linear-gradient(180deg, #000 0 var(--b), transparent var(--b) 48px);
          mask: repeating-linear-gradient(180deg, #000 0 var(--b), transparent var(--b) 48px);
  animation: tBlinds .8s steps(8) forwards; }
@keyframes tBlinds { 0% { --b: 48px; } 100% { --b: 0px; visibility: hidden; } }
.trans-cv { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 6; image-rendering: pixelated; pointer-events: none; visibility: hidden; }
.trans-cv.on { visibility: visible; }
