:root {
  --gold: #e9c56b;
  --ink: rgba(24, 21, 28, .88);
  --paper: #f1e4c2;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #a99c7e; color: var(--paper);
  font-family: "Times New Roman", "Noto Serif", Georgia, serif;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
button { font-family: inherit; }
#game { position: fixed; inset: 0; display: block; touch-action: none; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }
#top {
  position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 10px; right: 10px;
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-start;
}
#bars { flex: 1 1 200px; max-width: 330px; display: flex; flex-direction: column; gap: 5px; }
.bar {
  position: relative; height: 18px; border-radius: 9px; background: var(--ink);
  border: 1px solid rgba(10, 8, 14, .7); overflow: hidden; font-size: 11px; font-weight: 700;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .3), inset 0 0 0 1px rgba(255, 255, 255, .06);
}
.bar > div { height: 100%; width: 0; transition: width .12s linear; }
.bar.hp > div { background: linear-gradient(90deg, #b8232f, #ff6b5a); }
.bar.xp > div { background: linear-gradient(90deg, #2d7fbf, #8fd0ff); }
.bar span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px #000; color: #fff; }

#stats { display: flex; gap: 8px; }
.stat {
  background: var(--ink); border: 1px solid rgba(10, 8, 14, .7); border-radius: 6px 14px 6px 14px / 14px 6px 14px 6px;
  padding: 4px 10px; min-width: 64px; text-align: center; box-shadow: 0 2px 0 rgba(0, 0, 0, .3);
}
.stat .label { display: block; font-size: 10px; opacity: .75; text-transform: uppercase; letter-spacing: .5px; }
.stat b { font-size: 15px; }
#realm { font-weight: 800; }

#ctrl { margin-left: auto; display: flex; gap: 6px; }
#ctrl button {
  background: var(--ink); color: #fff; border: 1px solid rgba(10, 8, 14, .7);
  border-radius: 10px; padding: 6px 10px; font-size: 13px; cursor: pointer; box-shadow: 0 2px 0 rgba(0, 0, 0, .3);
}
#btn-auto.on { border-color: var(--gold); color: var(--gold); }
#btn-gear { border-color: rgba(233, 197, 107, .6) !important; }

#bossbar {
  position: absolute; top: calc(96px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: min(520px, 80vw); height: 14px; background: var(--ink); border: 1px solid #c8303a; border-radius: 7px;
}
#bossbar div { height: 100%; border-radius: 7px; background: linear-gradient(90deg, #8f1420, #e0483e); transition: width .1s; }
#bossbar span {
  position: absolute; left: 0; right: 0; top: -20px; text-align: center; font-size: 13px;
  color: #ffd0c8; font-weight: 700; text-shadow: 0 1px 3px #000, 0 0 8px #000;
}

#announce {
  position: absolute; top: 24%; left: 0; right: 0; text-align: center; padding: 0 16px;
  font-size: clamp(22px, 4.5vw, 42px); font-weight: 800; letter-spacing: 1px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .7), 0 0 22px currentColor; opacity: 0;
}
#announce.show { animation: announce 2.4s ease-out forwards; }
@keyframes announce {
  0%   { opacity: 0; transform: scale(.6); }
  12%  { opacity: 1; transform: scale(1.06); }
  25%  { transform: scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-24px); }
}

/* ---------- Chiêu thức & lướt ---------- */
#skills {
  position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; gap: 10px;
}
.skill, .act {
  position: relative; width: 64px; height: 64px; border-radius: 50%; padding: 0; overflow: hidden;
  border: 2px solid rgba(10, 8, 14, .7); background: var(--ink); color: #fff; cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(255, 255, 255, .08);
}
.skill .icon, .act .icon { font-size: 25px; line-height: 60px; }
.skill .cd, .act .cd {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(rgba(0, 0, 0, .74) var(--p, 0%), transparent 0);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px; text-shadow: 0 1px 3px #000;
}
.skill .key { position: absolute; top: 4px; left: 8px; font-size: 10px; opacity: .75; font-weight: 800; }
.skill .name { position: absolute; bottom: 4px; left: 0; right: 0; font-size: 9px; opacity: .85; }
.skill.ready { border-color: var(--gold); box-shadow: 0 0 16px rgba(233, 197, 107, .6); }
.skill.locked { opacity: .45; filter: grayscale(1); }
.skill.locked::after { content: '🔒'; position: absolute; inset: 0; font-size: 22px; line-height: 60px; }

#actions {
  position: absolute; right: calc(14px + env(safe-area-inset-right)); bottom: calc(94px + env(safe-area-inset-bottom));
  display: none; align-items: flex-end; gap: 10px;
}
.act.big { width: 80px; height: 80px; }
.act.big .icon { font-size: 32px; line-height: 76px; }
.act:active { background: rgba(233, 197, 107, .35); }
@media (pointer: coarse) { #actions { display: flex; } }

/* ---------- Joystick ---------- */
#joy {
  position: absolute; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%;
  border: 2px solid rgba(24, 21, 28, .45); background: rgba(24, 21, 28, .12); display: none;
}
#joy.show { display: block; }
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%; background: rgba(24, 21, 28, .45);
}

/* ---------- Bảng ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(20, 14, 6, .55); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 10; backdrop-filter: blur(2px);
}
.panel {
  background: rgba(24, 21, 30, .95); border: 1px solid rgba(217, 166, 64, .4); border-radius: 16px; padding: 22px 24px;
  max-width: 600px; width: 100%; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); max-height: 94vh; overflow: auto;
}
.panel h1 { margin: 0 0 10px; font-size: 32px; color: var(--gold); }
.panel h2 { margin: 0 0 2px; font-size: 24px; color: var(--gold); }
.panel h3 { margin: 12px 0 6px; font-size: 16px; color: var(--gold); }
.panel p { line-height: 1.55; opacity: .92; margin: 8px 0; }
.panel p.sub { opacity: .7; font-size: 13px; }
.panel kbd {
  background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .25); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; font-size: 12px; font-family: inherit;
}
.primary {
  background: linear-gradient(135deg, #e9c56b, #c58a2a); color: #201300; border: none; border-radius: 12px;
  padding: 12px 28px; font-size: 17px; font-weight: 800; cursor: pointer; margin-top: 8px;
}
.primary:hover { filter: brightness(1.08); }
button.sm {
  padding: 8px 14px; font-size: 14px; border-radius: 10px; cursor: pointer; margin: 4px;
  background: rgba(255, 255, 255, .1); color: var(--paper); border: 1px solid rgba(233, 197, 107, .45);
}
button.sm:disabled { opacity: .4; cursor: default; }
.primary.sm { background: linear-gradient(135deg, #e9c56b, #c58a2a); color: #201300; border: none; font-weight: 800; }
.ov-more { margin-top: 4px; }
#ov-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 10px 0 6px; }
#ov-stats .stat { padding: 8px 6px; }
#ov-stats .stat.rec b { color: var(--gold); }

#cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.card {
  flex: 1 1 150px; max-width: 180px; min-height: 176px; position: relative;
  background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .03));
  border: 1px solid rgba(233, 197, 107, .35); border-radius: 14px; color: #fff; padding: 14px 10px; cursor: pointer;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.card:hover, .card:focus { transform: translateY(-4px); border-color: var(--gold); box-shadow: 0 0 18px rgba(233, 197, 107, .35); outline: none; }
.card .c-icon { font-size: 34px; display: block; }
.card b { display: block; font-size: 15px; margin-top: 6px; color: var(--gold); }
.card small { display: block; opacity: .6; font-size: 11px; min-height: 13px; }
.card p { font-size: 12.5px; margin: 8px 0 0; opacity: .9; line-height: 1.4; }
.card em { position: absolute; top: 6px; left: 9px; font-style: normal; font-size: 11px; opacity: .5; }

/* ---------- Trang bị ---------- */
.gear-panel { max-width: 640px; text-align: left; }
.gear-panel h2 { text-align: center; }
#gear-sum { text-align: center; }
#gear-eq { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.g-slot {
  display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 10px;
  background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .12); min-height: 64px;
}
.g-slot img, .g-empty { width: 46px; height: 46px; flex: 0 0 46px; }
.g-empty { display: flex; align-items: center; justify-content: center; font-size: 24px; opacity: .35; border-radius: 50%; border: 1px dashed rgba(255, 255, 255, .25); }
.g-slot small { display: block; font-size: 11px; opacity: .6; }
.g-slot b { display: block; font-size: 14px; }
.g-slot span { display: block; font-size: 12px; opacity: .85; }
.r1 { border-color: rgba(115, 242, 128, .55); } .r2 { border-color: rgba(102, 184, 255, .6); }
.r3 { border-color: rgba(209, 122, 255, .65); box-shadow: 0 0 10px rgba(209, 122, 255, .25); }
.r4 { border-color: rgba(255, 204, 77, .75); box-shadow: 0 0 12px rgba(255, 204, 77, .3); }
#gear-count { font-size: 13px; opacity: .7; font-weight: 400; }
#gear-bag { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.g-cell {
  position: relative; aspect-ratio: 1; border-radius: 10px; padding: 3px; cursor: pointer;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .15);
}
.g-cell img { width: 100%; height: 100%; display: block; }
.g-cell.empty { cursor: default; opacity: .35; }
.g-cell.sel { outline: 2px solid var(--gold); outline-offset: 1px; }
.g-cell i { position: absolute; right: 3px; top: 1px; font-style: normal; font-size: 11px; color: #7ff28a; text-shadow: 0 1px 2px #000; }
#gear-info { margin-top: 10px; min-height: 64px; padding: 8px 10px; border-radius: 10px; background: rgba(0, 0, 0, .25); font-size: 14px; line-height: 1.5; }
#gear-info em { font-style: normal; font-size: 12px; margin-left: 4px; }
#gear-info em.up { color: #7ff28a; } #gear-info em.down { color: #ff8a7a; }
.g-act { margin-top: 4px; }
.g-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; flex-wrap: wrap; }

/* ---------- Menu, kết quả, hồi sinh ---------- */
.panel p.tag { margin: -4px 0 10px; opacity: .75; font-style: italic; }
.login {
  margin: 0 auto 10px; padding: 7px 12px; border-radius: 10px; display: inline-block;
  background: rgba(115, 242, 128, .1); border: 1px solid rgba(115, 242, 128, .45); font-size: 14px;
}
.jade { font-size: 17px; margin: 4px 0 10px; }
.jade b { color: #8ff0b8; font-size: 20px; }
.jade.gain { font-size: 20px; font-weight: 800; color: #8ff0b8; margin: 12px 0 4px; }
.jade .sm { vertical-align: middle; }
p.goal { font-size: 14px; margin: 4px 0 8px; opacity: .9; }
.stage-pick { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px auto 8px; max-width: 420px; }
.stage-pick > div {
  flex: 1; padding: 8px 10px; border-radius: 12px; background: rgba(255, 255, 255, .06); border: 1px solid rgba(233, 197, 107, .35);
}
.stage-pick b { display: block; font-size: 19px; color: var(--gold); }
.stage-pick small { display: block; font-size: 12.5px; opacity: .8; margin-top: 2px; }
.stage-pick .sm { min-width: 44px; margin: 0; }
.duo { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.duo .primary { margin-top: 0; min-width: 200px; }
.primary.alt { background: linear-gradient(135deg, #b8b0a0, #8a8272); }
button.sm.ad { border-color: rgba(143, 240, 184, .7); color: #c8ffe0; }
.primary.friends { background: linear-gradient(135deg, #8fe0cc, #2f8f86); color: #08221e; margin-left: 10px; }
#ov-shop.glow { border-color: #8ff0b8; color: #d8ffe8; animation: shopGlow 1.4s ease-in-out infinite; }
@keyframes shopGlow { 50% { box-shadow: 0 0 14px rgba(143, 240, 184, .65); } }
p.jade-use { font-size: 13.5px; margin: 10px 0 4px; opacity: .9; }
button.sm.share { margin: 2px 0 6px; border-color: rgba(120, 170, 255, .7); color: #dbe7ff; }
.share-txt { background: rgba(255, 255, 255, .06); border-radius: 10px; padding: 10px 12px; font-size: 14.5px; text-align: left; word-break: break-word; }
.share-txt b { color: #9cc3ff; font-weight: 400; }
.share-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.share-btns .primary { margin: 0; }
#sh-fb { background: linear-gradient(135deg, #5b8def, #2d5fc4); color: #fff; }
#sh-zalo { background: linear-gradient(135deg, #5fb8ff, #1f7de0); color: #fff; }
p.jade-use b { color: #8ff0b8; }
#overlay:not([data-mode=menu]):not([data-mode=result]):not([data-mode=online]) .gnx-btn { display: none !important; }

/* ---------- Tàng Kinh Các + Nhiệm vụ ---------- */
#meta { z-index: 12; }
.meta-panel { max-width: 680px; }
.shop { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0 10px; text-align: left; }
.sh-item {
  display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 10px;
  background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .12);
}
.sh-item.max { border-color: rgba(233, 197, 107, .5); }
.sh-item .c-icon { font-size: 26px; flex: 0 0 34px; text-align: center; }
.sh-item > div { flex: 1; min-width: 0; }
.sh-item b { font-size: 14.5px; color: var(--gold); }
.sh-item small { opacity: .6; font-size: 11px; }
.sh-item span { display: block; font-size: 12px; opacity: .88; line-height: 1.35; }
.sh-item em { font-style: normal; color: #8ff0b8; }
.sh-item .buy { flex: 0 0 auto; margin: 0; min-width: 72px; }
.sh-item .buy:not(:disabled) { border-color: rgba(143, 240, 184, .8); color: #c8ffe0; background: rgba(143, 240, 184, .12); }
.quests { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; text-align: left; }
.q { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .12); }
.q > div { flex: 1; }
.q.done { border-color: rgba(115, 242, 128, .55); }
.q.done b { color: #8ff0b8; }
.q em { font-style: normal; color: #8ff0b8; font-weight: 800; white-space: nowrap; }
.q small { opacity: .7; font-size: 12px; }
.qbar { height: 6px; border-radius: 3px; background: rgba(0, 0, 0, .35); margin: 5px 0 2px; overflow: hidden; }
.qbar i { display: block; height: 100%; background: linear-gradient(90deg, #2d9f6f, #8ff0b8); }
.streak { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 12px; }
.streak div { padding: 6px 2px; border-radius: 8px; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .12); }
.streak small { display: block; font-size: 10px; opacity: .65; }
.streak b { font-size: 12.5px; }
.streak .got { border-color: rgba(115, 242, 128, .5); opacity: .6; }
.streak .today { opacity: 1; background: rgba(115, 242, 128, .15); }
#reroll { margin-top: 12px; }

/* ---------- Gợi ý ván đầu ---------- */
#hint {
  position: absolute; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(24, 21, 28, .9); border: 1px solid rgba(233, 197, 107, .55); border-radius: 12px; padding: 10px 16px;
  font-size: 16px; max-width: min(92vw, 520px); text-align: center; opacity: 0; transition: opacity .3s; pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
#hint.show { opacity: 1; animation: hintPulse 1.6s ease-in-out infinite; }
@keyframes hintPulse { 50% { border-color: rgba(233, 197, 107, 1); } }

#toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 11; pointer-events: none;
  background: rgba(24, 21, 28, .88); border: 1px solid rgba(233, 197, 107, .35); padding: 8px 14px; border-radius: 10px;
  font-size: 14px; opacity: 0; transition: opacity .2s; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; }

@media (max-width: 640px) {
  #top { gap: 6px 8px; }
  #bars { flex-basis: 140px; }
  #stats .stat { min-width: 50px; padding: 3px 6px; }
  .stat b { font-size: 13px; }
  .stat .label { font-size: 9px; }
  #ctrl button { padding: 5px 8px; font-size: 13px; }
  #ctrl .lbl { display: none; }
  #bossbar { top: calc(108px + env(safe-area-inset-top)); }
  .skill, .act { width: 56px; height: 56px; }
  .skill .icon, .act .icon { font-size: 22px; line-height: 52px; }
  .skill.locked::after { line-height: 52px; }
  .act.big { width: 72px; height: 72px; }
  .act.big .icon { font-size: 28px; line-height: 68px; }
  #actions { bottom: calc(86px + env(safe-area-inset-bottom)); }
  .panel { padding: 16px 14px; }
  .panel h1 { font-size: 24px; }
  .panel p { font-size: 14px; }
  .card { min-height: 150px; flex-basis: 125px; padding: 10px 8px; }
  .card .c-icon { font-size: 28px; }
  #gear-eq { grid-template-columns: 1fr; }
  #gear-bag { grid-template-columns: repeat(4, 1fr); }
  .shop { grid-template-columns: 1fr; }
  .duo .primary { min-width: 0; flex: 1; }
  .primary.friends { margin-left: 6px; }
  #hint { font-size: 14px; bottom: calc(170px + env(safe-area-inset-bottom)); }
}
/* màn hình thấp (điện thoại xoay ngang, khung 800×450) */
@media (max-height: 500px) {
  .panel { padding: 12px 16px; }
  .panel h1 { font-size: 22px; margin-bottom: 4px; }
  .panel p { margin: 4px 0; }
  .panel p.tag { display: none; }
  #ov-stats { margin: 6px 0 2px; grid-template-columns: repeat(6, 1fr); }
  #ov-stats .stat .label { font-size: 9px; }
  .jade.gain { margin: 6px 0 2px; }
  #ov-stats .stat { padding: 4px; }
  .primary { padding: 9px 22px; font-size: 16px; }
  .card { min-height: 0; }
}
