:root {
  --bg: #1b1530; --bg2: #251d42; --card: #2e2550; --line: #3d3366;
  --tx: #f3effc; --mut: #a99fcc; --acc: #ffcf5a; --acc2: #ff6f91;
  --hl: #5ee0a0; --h: #ffcf5a; --sm: #6fb6ff; --so: #ff8fb1;
  --N: #8f8aa6; --R: #4fa3ff; --SR: #b26bff; --SSR: #ffb02e; --UR: #ff4f7b;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--tx); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; background: radial-gradient(1200px 600px at 50% -200px, #3a2a6e 0%, var(--bg) 60%); }
#app { max-width: 560px; margin: 0 auto; padding: 16px 14px calc(24px + env(safe-area-inset-bottom)); }
.screen { display: none; flex-direction: column; gap: 14px; animation: fade .25s ease; }
.screen.active { display: flex; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
h1, h2, h3 { margin: 0; }
small { color: var(--mut); font-weight: 400; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--tx); border-radius: 12px; padding: 11px 16px; font: inherit; font-weight: 600; cursor: pointer; transition: transform .08s, background .15s; }
.btn:hover { background: #3a3066; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--acc2), #b25cff); border-color: transparent; }
.btn.big { padding: 16px; font-size: 18px; border-radius: 16px; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 8px 12px; min-width: 44px; }
.btn.danger { color: #ff8f8f; border-color: #6a2b3a; }
.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }

.hero { text-align: center; padding: 18px 6px 4px; }
.logo { font-size: 64px; filter: drop-shadow(0 6px 18px #ff6f9166); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
.hero h1 { font-size: 34px; letter-spacing: .5px; }
.sub { color: var(--acc); margin: 2px 0 10px; font-weight: 600; }
.lead { color: #d8d0f0; margin: 0 0 12px; }
.counter { display: inline-block; background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; color: var(--mut); }
.counter b { color: var(--tx); font-variant-numeric: tabular-nums; }
.wallet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.wallet > div { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 10px; text-align: center; display: flex; flex-direction: column; }
.wallet .ico { font-size: 20px; } .wallet b { font-size: 20px; }
.fine { color: var(--mut); font-size: 12.5px; text-align: center; margin: 4px 8px; }

.bar { display: flex; align-items: center; gap: 10px; }
.bar h2 { flex: 1; font-size: 19px; }
.pill { background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; }
.hint, .rates { color: var(--mut); margin: 0; font-size: 13.5px; }
.rates { font-size: 12px; text-align: center; }

/* Thẻ gacha */
.cards { display: grid; gap: 10px; }
.gcard { position: relative; border-radius: 16px; padding: 14px; background: var(--card); border: 2px solid var(--rc, var(--line)); cursor: pointer; overflow: hidden;
  box-shadow: 0 0 0 0 var(--rc); transition: transform .12s, box-shadow .2s; animation: flip .5s cubic-bezier(.2,.8,.3,1.2) both; }
.gcard:nth-child(2) { animation-delay: .12s; } .gcard:nth-child(3) { animation-delay: .24s; }
@keyframes flip { from { opacity: 0; transform: perspective(600px) rotateY(80deg) scale(.9); } }
.gcard:hover { transform: translateY(-2px); box-shadow: 0 6px 22px -6px var(--rc); }
.gcard.SSR, .gcard.UR { background: linear-gradient(135deg, var(--card), color-mix(in srgb, var(--rc) 28%, var(--card))); }
.gcard.UR::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, #fff3 50%, transparent 70%); animation: shine 2.2s infinite; pointer-events: none; }
@keyframes shine { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.rar { position: absolute; top: 10px; right: 12px; font-weight: 900; font-size: 18px; color: var(--rc); letter-spacing: 1px; }
.gcard .t { font-size: 17px; font-weight: 700; padding-right: 50px; }
.gcard .s { color: var(--mut); font-size: 13px; margin-top: 2px; }
.gcard .facts { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 12px; margin-top: 8px; font-size: 13px; }
.gcard .facts span { color: var(--mut); }
.gcard .odds { margin-top: 8px; font-size: 12px; color: var(--mut); border-top: 1px dashed var(--line); padding-top: 6px; }
.N { --rc: var(--N); } .R { --rc: var(--R); } .SR { --rc: var(--SR); } .SSR { --rc: var(--SSR); } .UR { --rc: var(--UR); }

/* Cuộc đời */
.life-bar { background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; position: sticky; top: 8px; z-index: 5; }
.who { flex: 1; min-width: 0; }
.name { font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--mut); font-size: 13px; }
.age { text-align: center; line-height: 1; }
.age b { font-size: 30px; display: block; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.stat .lbl { display: flex; justify-content: space-between; font-size: 13px; color: var(--mut); }
.stat .lbl b { color: var(--tx); }
.stat .track { height: 8px; background: #0003; border-radius: 9px; overflow: hidden; margin-top: 3px; }
.stat .fill { height: 100%; border-radius: 9px; transition: width .35s ease; }
.money { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.money > div { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 7px 8px; display: flex; flex-direction: column; min-width: 0; }
.money small { font-size: 11px; } .money b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.perks { display: flex; flex-wrap: wrap; gap: 6px; }
.perks:empty { display: none; }
.perk { font-size: 12px; border: 1px solid var(--rc); color: var(--tx); border-radius: 999px; padding: 3px 9px; background: color-mix(in srgb, var(--rc) 15%, transparent); }
.focus-h { font-size: 13px; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg2); color: var(--tx); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13.5px; cursor: pointer; }
.chip small { margin-left: 4px; font-size: 11px; }
.chip.on { background: var(--acc); color: #2a1d00; border-color: var(--acc); font-weight: 700; }
.chip.on small { color: #5a4300; }
.controls { display: flex; gap: 8px; position: sticky; bottom: 10px; z-index: 5; }
.controls .primary { flex: 1; }
.controls .btn { box-shadow: 0 6px 18px -8px #000; }
.panel { background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.panel-h { font-weight: 700; margin-bottom: 8px; }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow: auto; }
.log li { display: flex; gap: 10px; font-size: 14px; }
.log li .a { color: var(--mut); min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.log li.good { color: #c9f5dc; } .log li.bad { color: #ffc2cf; } .log li.big { color: var(--acc); font-weight: 600; }
.twins { display: grid; gap: 6px; }
.twin { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.twin:last-child { border: 0; }
.twin .st { color: var(--mut); text-align: right; white-space: nowrap; }
.twin.dead .st { color: #ff9fb3; }

/* Kết thúc */
.tomb { text-align: center; padding: 18px; background: var(--bg2); border: 1px solid var(--line); border-radius: 20px; }
.candle { font-size: 44px; animation: flick 1.8s infinite; }
@keyframes flick { 50% { filter: brightness(1.4) drop-shadow(0 0 10px #ffcf5a); } }
.tomb h2 { font-size: 24px; margin-top: 4px; }
.cause { margin: 6px 0 0; color: #ffc2cf; }
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.summary > div { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; }
.summary small { display: block; font-size: 12px; } .summary b { font-size: 16px; }
.summary .wide { grid-column: 1 / -1; }
.reflect { text-align: center; color: #d8d0f0; font-style: italic; margin: 4px 10px; }

/* Bộ sưu tập */
.grid { display: flex; flex-wrap: wrap; gap: 6px; }
.grid span { font-size: 12.5px; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--mut); }
.grid span.got { color: var(--tx); border-color: var(--acc); background: #ffcf5a1a; }
.lives { display: grid; gap: 6px; }
.lives:empty::after { content: "Chưa có kiếp nào."; color: var(--mut); font-size: 13px; }
.lives div { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; border-bottom: 1px dashed var(--line); padding: 5px 0; }
.lives div span:last-child { color: var(--mut); white-space: nowrap; }

/* Hộp thoại */
.modal { position: fixed; inset: 0; background: #0009; backdrop-filter: blur(3px); display: flex; align-items: flex-end; justify-content: center; z-index: 20; padding: 10px; }
.modal[hidden] { display: none; }
.sheet { width: 100%; max-width: 540px; max-height: 92vh; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 18px 16px; animation: up .25s ease; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h3 { font-size: 19px; margin-bottom: 6px; }
.sheet > p { color: #d8d0f0; margin: 0 0 12px; white-space: pre-line; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.actions .btn { text-align: left; }
.actions .btn small { display: block; font-weight: 400; margin-top: 2px; }
.sheet .cards { margin-top: 4px; }
.pity { font-size: 12px; color: var(--mut); text-align: center; margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--acc); color: #2a1d00; padding: 9px 16px; border-radius: 999px; font-weight: 700; z-index: 30; box-shadow: 0 6px 20px #0008; animation: up .2s; max-width: 90vw; text-align: center; }
.toast[hidden] { display: none; }
.help li { margin-bottom: 6px; }
