/* ================================================================
   KHUNG GAME TOÀN MÀN HÌNH: màn tựa đề, cốt truyện kiểu visual novel,
   bản đồ, bảng đội hình / cửa hàng, lớp phủ của trận đấu
   ================================================================ */
html, body { height: 100%; overflow: hidden; background: #0d0a07; }
#app { position: fixed; inset: 0; max-width: none; margin: 0; padding: 0; }
#screen { position: absolute; inset: 0; overflow: hidden; }

/* Nút kiểu game: sơn mài đỏ viền vàng */
.btn-game {
  font-family: var(--font-title); font-weight: 700; letter-spacing: .5px;
  color: #fff3d6; padding: 10px 26px; border-radius: 4px; cursor: pointer;
  background: linear-gradient(#9b2c22, #6e1d16); border: 1px solid #e9c46a;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .25), 0 6px 18px rgba(0, 0, 0, .45);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6); transition: transform .12s, filter .12s;
}
.btn-game:hover:not(:disabled) { filter: brightness(1.18); transform: translateY(-1px); background: linear-gradient(#9b2c22, #6e1d16); border-color: #f6dc8c; }
.btn-game.dark { background: linear-gradient(rgba(34, 24, 16, .9), rgba(15, 10, 6, .92)); }
.btn-game:disabled { opacity: .45; }

/* Ảnh cảnh nền dùng chung */
.scene-bg { position: absolute; inset: 0; background: var(--bg, linear-gradient(#3a3026, #15100b)) center / cover no-repeat; }
@keyframes kenburns { from { transform: scale(1.04); } to { transform: scale(1.14) translate(-1.5%, -1%); } }

/* ---------- Thanh trên cùng (đè lên cảnh) ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 40; margin: 0; padding: 10px 16px; border: 0;
  background: linear-gradient(rgba(10, 7, 4, .85), rgba(10, 7, 4, 0)); color: #f3e3c0;
}
#chapter-name { color: #f1d38a; font-family: var(--font-title); text-shadow: 0 2px 4px #000; }
#gold { color: #f1d38a; text-shadow: 0 2px 4px #000; }
#topbar nav button { background: rgba(20, 14, 9, .75); color: #f3e3c0; border: 1px solid rgba(233, 196, 106, .6); }
#topbar nav button:hover { background: rgba(70, 45, 20, .9); border-color: #e9c46a; }
#toast { z-index: 500; }

/* ---------- Màn tựa đề ---------- */
.title-screen { position: absolute; inset: 0; padding: 0; text-align: center; color: #fff3d6; }
.title-screen .scene-bg { animation: kenburns 28s ease-in-out infinite alternate; }
.title-shade {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 38%, transparent 25%, rgba(0, 0, 0, .7) 100%),
    linear-gradient(rgba(0, 0, 0, .3), transparent 30%, rgba(0, 0, 0, .55));
}
.title-heroes .hero { position: absolute; bottom: 3%; height: min(64vh, 60vw); display: flex; align-items: flex-end; }
.title-heroes .hero.l { left: 23%; transform: translateX(-50%); }
.title-heroes .hero.r { left: 77%; transform: translateX(-50%) scaleX(-1); }
.title-heroes canvas { height: 112%; filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .6)); }
.title-logo { position: absolute; left: 0; right: 0; top: 11%; z-index: 2; }
.title-logo .cn {
  font-size: clamp(18px, 3vw, 30px); letter-spacing: 1.1em; margin-right: -1.1em;
  color: #f1d38a; text-shadow: 0 2px 6px #000; animation: logo-in 1.6s ease-out both;
}
.title-logo h1 {
  margin: 6px 0; font-size: clamp(40px, 8.5vw, 104px); color: #fff6e0; letter-spacing: 3px;
  text-shadow: 0 0 2px #000, 0 5px 0 #6e1d16, 0 0 34px rgba(233, 196, 106, .6);
  animation: logo-in 1.8s .2s ease-out both;
}
.title-logo p { font-style: italic; color: #f3e3c0; text-shadow: 0 2px 4px #000; animation: logo-in 1.6s .5s both; }
@keyframes logo-in { from { opacity: 0; transform: scale(1.15); letter-spacing: 18px; filter: blur(6px); } }
.title-menu {
  position: absolute; left: 50%; bottom: 13%; z-index: 2; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 12px; width: min(290px, 80vw); animation: fade-up 1s 1s both;
}
@keyframes fade-up { from { opacity: 0; margin-bottom: -20px; } }
.title-menu .btn-game { font-size: 18px; padding: 12px; }

/* Cánh hoa đào rơi */
.petals { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 3; }
.petals span {
  position: absolute; top: -5%; width: 12px; height: 9px; border-radius: 60% 0 60% 0; opacity: .85;
  background: linear-gradient(135deg, #ffd6e0, #f191ad); animation: fall linear infinite;
}
@keyframes fall { to { transform: translate(-22vw, 112vh) rotate(600deg); } }

/* ---------- Cốt truyện kiểu visual novel ---------- */
.vn { position: absolute; inset: 0; cursor: pointer; color: #fff3d6; user-select: none; }
.vn .scene-bg { animation: kenburns 40s ease-in-out infinite alternate; }
.vn-skip {
  position: absolute; top: 14px; right: 16px; z-index: 9; padding: 6px 16px; border-radius: 20px;
  font-size: 13px; letter-spacing: .5px; color: #f3e3c0; cursor: pointer;
  background: rgba(15, 10, 6, .65); border: 1px solid rgba(233, 196, 106, .6);
}
.vn-skip:hover { background: rgba(70, 45, 20, .85); border-color: #e9c46a; color: #fff6e0; }
.vn:has(.vn-choices) .vn-skip { display: none; }
.vn-shade { position: absolute; inset: 0; background: linear-gradient(transparent 40%, rgba(0, 0, 0, .6)); }
.vn-actor {
  position: absolute; bottom: 0; height: min(80%, 95vw); display: flex; align-items: flex-end;
  transition: filter .35s, opacity .35s;
}
.vn-actor.left { left: 21%; transform: translateX(-50%); }
.vn-actor.right { left: 79%; transform: translateX(-50%); }
.vn-actor.right .flipper { transform: scaleX(-1); }
.vn-actor .flipper { height: 100%; display: flex; align-items: flex-end; }
.vn-actor canvas { height: 112%; filter: drop-shadow(0 10px 16px rgba(0, 0, 0, .6)); }
.vn-actor.dim { filter: brightness(.5) saturate(.6); }
.vn-actor.enter { animation: actor-in .45s ease-out both; }
@keyframes actor-in { from { opacity: 0; margin-bottom: -4%; } }

.vn-box {
  position: absolute; left: 50%; bottom: 3%; transform: translateX(-50%); z-index: 5;
  width: min(1100px, 94%); min-height: 21%; padding: 26px 30px 30px; border-radius: 10px;
  display: flex; gap: 18px; align-items: flex-start;
  background: linear-gradient(rgba(28, 19, 11, .9), rgba(12, 8, 5, .94));
  border: 1px solid rgba(233, 196, 106, .75);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, .35), 0 12px 34px rgba(0, 0, 0, .55);
}
.vn-name {
  position: absolute; top: -19px; left: 24px; padding: 4px 18px; border-radius: 4px;
  font-family: var(--font-title); font-weight: 700; color: #fff3d6;
  background: linear-gradient(#9b2c22, #6e1d16); border: 1px solid #e9c46a;
}
.vn-name:empty { display: none; }
.vn-face:empty { display: none; }
.vn-face .portrait { width: 104px; height: 104px; font-size: 44px; border-color: #e9c46a; box-shadow: 0 0 0 2px #6e1d16; }
.vn-text { flex: 1; font-size: clamp(15px, 1.55vw, 20px); line-height: 1.75; white-space: pre-line; text-shadow: 0 1px 2px #000; }
.vn-box.narration .vn-text { font-style: italic; color: #eadfc4; }
.vn-box.notice .vn-text { color: #f1d38a; }
.vn:has(.vn-chapter) .vn-box { opacity: 0; }
.vn-next { position: absolute; right: 22px; bottom: 10px; color: #e9c46a; animation: bob .8s ease-in-out infinite; }

/* Tựa hồi: hai dải đen kiểu điện ảnh + chữ lớn */
.vn-chapter { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; background: rgba(0, 0, 0, .45); }
.vn-chapter::before, .vn-chapter::after {
  content: ''; position: absolute; left: 0; right: 0; height: 13%; background: #000; animation: bars .7s ease-out both;
}
.vn-chapter::before { top: 0; }
.vn-chapter::after { bottom: 0; }
@keyframes bars { from { height: 0; } }
.vn-chapter > div { position: relative; text-align: center; }
.vn-chapter h1 {
  margin: 0 16px; text-align: center; font-size: clamp(30px, 6vw, 76px); color: #fff6e0;
  text-shadow: 0 4px 0 #6e1d16, 0 0 34px rgba(233, 196, 106, .55); animation: logo-in 1.4s ease-out both;
}
.vn-chapter small { display: block; margin-top: 12px; color: #e9c46a; font-size: 14px; letter-spacing: 2px; animation: fade-up 1s 1s both; }

.vn-choices {
  position: absolute; inset: 0; z-index: 7; display: flex; flex-direction: column;
  justify-content: center; align-items: center; gap: 14px; background: rgba(0, 0, 0, .4); cursor: default;
}
.vn-choices .btn-game { width: min(600px, 90%); font-size: 16px; }

/* ---------- Bản đồ ---------- */
.map-screen { position: absolute; inset: 0; color: #fff3d6; }
.map-shade {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, .7), rgba(0, 0, 0, .05) 58%),
    linear-gradient(transparent 58%, rgba(0, 0, 0, .75));
}
.map-party { position: absolute; left: 46%; bottom: 22%; height: 40%; display: flex; align-items: flex-end; }
.map-party .hero { height: 100%; display: flex; align-items: flex-end; margin-left: -3%; }
.map-party canvas { height: 112%; filter: drop-shadow(0 8px 12px rgba(0, 0, 0, .55)); }
.map-info { position: absolute; left: 4%; top: 13%; width: min(460px, 90%); z-index: 2; }
.map-title {
  font-family: var(--font-title); font-size: clamp(28px, 4.2vw, 56px); color: #fff6e0;
  text-shadow: 0 3px 0 #6e1d16, 0 0 20px rgba(0, 0, 0, .85);
}
.map-info .desc { color: #eadfc4; text-shadow: 0 1px 3px #000; margin: 6px 0 18px; }
.map-actions { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.map-actions .btn-game { font-size: 15px; padding: 9px 20px; }
.map-actions .btn-game.event { animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 2px rgba(0, 0, 0, .35), 0 0 24px rgba(233, 196, 106, .9); } }

.map-strip {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; align-items: center; gap: 8px;
  padding: 22px 10px 12px; background: linear-gradient(transparent, rgba(0, 0, 0, .8));
}
.map-places {
  position: relative; flex: 1; min-width: 0; display: flex; gap: 12px; padding: 4px 4px 6px; overflow-x: auto;
  scroll-behavior: smooth; scrollbar-width: none;
}
.map-places::-webkit-scrollbar { display: none; }
.strip-arrow {
  flex: none; width: 40px; height: 72px; padding: 0; display: grid; place-items: center; cursor: pointer;
  border-radius: 8px; border: 2px solid rgba(233, 196, 106, .6); background: rgba(24, 16, 9, .88); color: #f1d38a;
  transition: background .15s, border-color .15s;
}
.strip-arrow svg { width: 26px; height: 26px; }
.strip-arrow:hover:not(:disabled) { background: #6b2a1c; border-color: #e9c46a; }
.strip-arrow:disabled { opacity: .3; cursor: default; }
.place {
  position: relative; flex: none; width: 176px; height: 99px; padding: 0; overflow: hidden; cursor: pointer;
  border-radius: 8px; border: 2px solid rgba(233, 196, 106, .45); background: var(--thumb, #2a2016) center / cover;
  transition: transform .15s;
}
.place:hover { transform: translateY(-3px); border-color: #e9c46a; }
.place:active:not(:disabled) { transform: translateY(-2px); }   /* nhấn không tụt quá xa khỏi con trỏ */
.place .name {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 6px; text-align: left;
  font-size: 13px; font-weight: 700; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .9));
}
.place.current { border-color: #e9c46a; box-shadow: 0 0 0 2px #e9c46a, 0 0 18px rgba(233, 196, 106, .6); }
.place .badge {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; color: #fff;
  background: #9b2c22; border: 1px solid #e9c46a; animation: glow 1.6s infinite;
}

/* Thẻ chọn phần (bộ truyện) nằm trên dải hồi */
.part-tabs { position: absolute; left: 10px; bottom: calc(100% - 16px); display: flex; gap: 6px; flex-wrap: wrap; }
.part-tab {
  padding: 4px 12px; border-radius: 8px 8px 0 0; cursor: pointer; font: 700 13px var(--font-ui); color: #d6c6a4;
  background: rgba(24, 16, 9, .9); border: 1px solid rgba(233, 196, 106, .4); border-bottom: none;
}
.part-tab small { margin-left: 5px; font-weight: 400; font-size: 11px; color: #998a70; }
.part-tab.on { color: #fff3d6; background: #6b2a1c; border-color: #e9c46a; }
.part-tab.locked { opacity: .7; }
.part-tab:hover:not(.on) { color: #fff3d6; border-color: #e9c46a; }
.stage-map .chapter-title small { display: block; font: 700 14px var(--font-ui); color: #f1d38a; letter-spacing: 1px; }

/* ---------- Bảng đội hình / cửa hàng đè lên cảnh ---------- */
.panel-screen { position: absolute; inset: 0; overflow-y: auto; padding: 66px 16px 24px; }
.panel-screen .scene-bg { position: fixed; filter: blur(3px) brightness(.45); }
.panel {
  position: relative; max-width: 900px; margin: 0 auto; padding: 18px 20px; border-radius: 10px;
  background: rgba(243, 234, 215, .97); border: 1px solid #e9c46a; box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
}

.panel .party-sprite { height: 190px; width: auto; align-self: flex-end; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .3)); }

/* ---------- Lớp phủ của trận đấu (sân khấu chiếm cả màn hình) ---------- */
.battle { position: absolute; inset: 0; display: block; }
.battle .stage { position: absolute; inset: 0; aspect-ratio: auto; border: 0; border-radius: 0; }
.battle .battle-actions {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 320;
  width: max-content; max-width: 96%; min-height: 0; padding: 6px 10px; gap: 6px; border-radius: 8px;
  font-size: 13px; color: #fff3d6;
  background: linear-gradient(rgba(28, 19, 11, .86), rgba(12, 8, 5, .92)); border: 1px solid rgba(233, 196, 106, .6);
}
.battle .battle-actions:empty { display: none; }
.battle .battle-actions button {
  padding: 5px 12px; font-size: 13px; color: #fff3d6; background: linear-gradient(#3e2b1b, #24180f); border: 1px solid rgba(233, 196, 106, .55);
}
.battle .battle-actions button:hover:not(:disabled) { background: linear-gradient(#5a3d22, #2e1f12); border-color: #e9c46a; }
.battle .battle-actions button.primary { background: linear-gradient(#9b2c22, #6e1d16); }
.battle .skill-menu { width: min(860px, 92vw); grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.battle .skill-menu small { color: #d6c6a4; }
.battle .skill-menu .cost { color: #9cc7f0; }
.battle .kind-ngoai { color: #f0b27a; } .battle .kind-noi { color: #c9a6ff; } .battle .kind-tri { color: #8fe0a8; } .battle .kind-ho { color: #f1d38a; }
.battle .log {
  position: absolute; left: 12px; top: 10px; z-index: 310; width: min(360px, 60%); height: 100px; max-height: none;
  display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden; pointer-events: none;
  padding: 0; border: 0; border-radius: 0; background: none;
  font-size: 12px; line-height: 1.5; color: #f3e3c0; text-shadow: 0 1px 2px #000, 0 0 4px rgba(0, 0, 0, .9);
  /* dòng trên cùng mờ dần như trôi đi */
  -webkit-mask-image: linear-gradient(transparent, #000 45%); mask-image: linear-gradient(transparent, #000 45%);
}
.battle .log > div { flex: none; animation: log-in .25s ease-out; }
@keyframes log-in { from { opacity: 0; transform: translateY(8px); } }
.battle .log .crit { color: #f1d38a; }

@media (max-width: 700px) and (orientation: portrait) {
  .map-party { left: 42%; bottom: 24%; height: 30%; }
  .map-info { top: 9%; }
  .place { width: 132px; height: 76px; }
  .strip-arrow { width: 30px; height: 56px; }
  .vn-actor { height: 66%; }
  .vn-box { min-height: 26%; padding: 24px 18px 26px; }
  .vn-face .portrait { width: 64px; height: 64px; font-size: 28px; }
}
