:root {
  --red: #c8261f; --red-d: #8a1a14; --gold: #f5d36e; --gold-d: #b98a22; --jade: #2f8f83;
  --paper: #fbf3e0; --paper-d: #eadbb8; --ink: #3b1a12; --night: #1c0f0d;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #2a0f0b; color: var(--ink); font-family: Itim, system-ui, sans-serif; overscroll-behavior: none; }
body { display: flex; justify-content: center; }
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
#app { position: relative; width: 100%; max-width: 480px; height: 100dvh; overflow: hidden; background: var(--paper); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#app.is-dark { background: var(--night); color: #f3e6cf; }
#app.is-dim { background: #e6dccb; }
#app.is-dawn { background: linear-gradient(#f7e3c4, #fbf3e0); }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px; padding: max(12px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom)); overflow-y: auto; overflow-x: hidden; }
.ui-txt { font-family: Itim, system-ui, sans-serif; }
.hand { font-family: Pangolin, Itim, cursive; }
h2 { margin: 6px 0; font-size: 26px; color: var(--red); }
.is-dark h2 { color: #f5d36e; }
.center { text-align: center; }
.muted { opacity: .72; font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.topbar { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; background: #fff8e6; border: 2px solid var(--paper-d); font-size: 20px; display: grid; place-items: center; flex: none; }
.is-dark .icon-btn { background: #3a2420; border-color: #5a3a30; color: #f3e6cf; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: #fff8e6; border: 2px solid var(--paper-d); font-size: 14px; white-space: nowrap; }
.chip.gold { background: var(--gold); border-color: var(--gold-d); color: var(--red-d); }
.card { background: #fffaf0; border: 3px solid var(--paper-d); border-radius: 16px; padding: 12px 14px; box-shadow: 0 4px 0 #dcc89c; }

/* ---------- nút ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 14px; font-size: 19px; min-height: 48px;
  background: var(--red); color: #fff5d6; box-shadow: 0 5px 0 var(--red-d); transition: transform .08s; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--red-d); }
.btn.big { font-size: 24px; padding: 14px 20px; width: 100%; }
.btn.gold { background: linear-gradient(#ffe38a, #f2b632); color: var(--red-d); box-shadow: 0 5px 0 var(--gold-d); }
.btn.ghost { background: var(--paper-d); color: var(--ink); box-shadow: 0 4px 0 #c9b489; }
.btn.dark { background: #3a2420; color: #f3e6cf; box-shadow: 0 5px 0 #1a0c0a; border: 2px solid #5a3a30; }
.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }

/* ---------- trang đầu ---------- */
.title-screen { background: radial-gradient(circle at 50% 30%, #fff1cf, #f3dfb6 70%); }
.logo { text-align: center; margin-top: 4px; }
.logo-sm { display: inline-block; background: var(--jade); color: #fff; padding: 2px 12px; border-radius: 6px; font-size: 15px; transform: rotate(-2deg); }
.logo h1 { margin: 6px 0 4px; font-size: 58px; line-height: .92; color: var(--red); text-shadow: 3px 4px 0 var(--gold), 5px 7px 0 rgba(138, 26, 20, .25); letter-spacing: 1px; }
.tag { font-size: 18px; }
.title-dolls { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); align-items: center; min-height: 150px; margin: 0 -10px; }
.title-dolls svg { width: 100%; height: 100%; max-height: 300px; }
.title-dolls > div { display: flex; align-items: flex-end; animation: bob 2.4s ease-in-out infinite; }
.title-dolls > div:nth-child(2) { animation-delay: -.6s; } .title-dolls > div:nth-child(3) { animation-delay: -1.2s; } .title-dolls > div:nth-child(4) { animation-delay: -1.8s; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(1.5deg); } }
.note { font-size: 13px; opacity: .7; text-align: center; margin: 6px 0 0; }

/* ---------- hẻm ---------- */
.hub { padding: 0; }
.hub-stage { position: relative; flex: 1; min-height: 320px; overflow: hidden; }
.hub-stage.short { flex: none; height: 38vh; min-height: 220px; margin: -12px -16px 0; }
.hub-stage.short.tall { height: 52vh; }
.alley { position: absolute; inset: 0; width: 100%; height: 100%; }
.hub-table { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; overflow: hidden; }
.hub-head { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; gap: 6px; align-items: center; }
.pick { cursor: pointer; transition: transform .15s; }
.pick.locked { opacity: .55; }
.pick:hover .doll-body, .pick:active .doll-body { filter: brightness(1.1); }
.tap-obj { cursor: pointer; animation: glint 2s ease-in-out infinite; }
@keyframes glint { 50% { filter: drop-shadow(0 0 6px #fff3a0); } }
.hub-bottom { padding: 10px 16px max(14px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; background: var(--paper); }
.hint { margin: 0; text-align: center; font-size: 17px; }

/* ---------- hình nhân / mâm ---------- */
.sheet-doll { height: 32vh; min-height: 180px; display: flex; justify-content: center; }
.sheet-doll svg { height: 100%; }
.sheet-name { text-align: center; margin: 0; } .sheet-name small { font-size: 16px; color: var(--ink); opacity: .7; }
.accuse { text-align: center; margin: 0; font-size: 18px; }
.frags { display: flex; flex-direction: column; gap: 8px; }
.frag { background: #fffaf0; border: 2px solid var(--paper-d); border-left: 6px solid var(--red); border-radius: 10px; padding: 8px 12px; font-size: 16px; line-height: 1.4; }
.frag .kind { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--red); margin-bottom: 2px; }
.frag.locked { opacity: .5; border-left-color: #bbb; }
.frag.new { border-left-color: var(--gold-d); background: #fff6d8; animation: rise .5s ease-out; }
.frag.dark { background: #2c1a16; border-color: #4a2e26; border-left-color: #8a1a14; color: #f3e6cf; }
.frag.dark .kind { color: #f5d36e; }
.ev-ico { float: right; margin-left: 8px; }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.tray { position: relative; height: 34vh; min-height: 200px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.tray-doll { height: 80%; } .tray-doll svg { height: 100%; }
.tray-items { display: flex; gap: 22px; padding: 8px 26px; background: linear-gradient(#e9b73a, #b98a22); border-radius: 50%/30%; box-shadow: 0 6px 0 #7a5a12; }
.ti { font-size: 34px; opacity: .15; filter: grayscale(1); transition: all .3s; }
.ti.on { opacity: 1; filter: none; transform: translateY(-4px); }
.vow { min-height: 92px; font-size: 19px; line-height: 1.45; text-align: center; padding: 4px 6px; }
.vow .vp { animation: rise .4s ease-out; }
.vow s, .line s { text-decoration-color: var(--red); text-decoration-thickness: 3px; opacity: .7; }

/* ---------- lượt đập ---------- */
.play { padding: 0; gap: 0; }
.stage { position: relative; flex: 1; overflow: hidden; touch-action: none; background: #7d8d96; }
.arena { position: absolute; inset: 0; width: 100%; height: 100%; }
.hud { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 10px; align-items: flex-start; padding: max(10px, env(safe-area-inset-top)) 12px 8px; background: linear-gradient(rgba(251, 243, 224, .95), rgba(251, 243, 224, .75)); }
.hud-name { color: var(--red); white-space: nowrap; }
.bar { height: 12px; background: rgba(59, 26, 18, .15); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--jade), #4fc0ad); transition: width .1s linear; }
.bar.low i { background: linear-gradient(90deg, var(--red), #f06a3a); }
.timer-txt { width: 28px; text-align: right; font-size: 18px; }
.score { font-size: 28px; color: var(--red); line-height: 1; }
.combo { font-size: 16px; } .combo b { font-size: 22px; } .combo.hot { color: var(--red); animation: pulse .5s infinite; }
#dollG { transition: opacity .25s; }
.doll .shield { display: none; }
#dollG.shielding .shield { display: inline; }
#dollG.tele { animation: jitter .1s linear infinite; }
@keyframes jitter { 50% { transform: scale(1.18, 1.18) translateX(1.5px); } 0%, 100% { transform: scale(1.18); } }
#dollG.hit-anim .doll-head { animation: hithead .16s ease-out; }
#dollG.hit-anim .doll-body { animation: hitbody .16s ease-out; }
@keyframes hithead { 40% { transform: translateY(12px) rotate(-3deg); } }
@keyframes hitbody { 40% { transform: translateY(4px); } }
.talk-mouth { animation: talk .22s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes talk { to { transform: scaleY(.3); } }
.stage.hush .alley { filter: brightness(.7) saturate(.6); transition: filter .4s; }
.slip { position: absolute; pointer-events: none; opacity: 0; transform-origin: 50% 100%; z-index: 5; }
.slip.go { animation: swing .2s ease-out; }
@keyframes swing { 0% { opacity: 1; transform: rotate(-55deg) translateY(-30px); } 45% { opacity: 1; transform: rotate(8deg); } 100% { opacity: 0; transform: rotate(0); } }
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.pop { position: absolute; transform: translate(-50%, -50%); font-size: 22px; color: var(--red); font-weight: bold; text-shadow: 2px 2px 0 #fff5d6; animation: popup .7s ease-out forwards; white-space: nowrap; }
.pop.big { font-size: 34px; color: #f2b632; text-shadow: 3px 3px 0 var(--red-d); }
.pop.miss { color: #7a6a5a; font-size: 18px; }
.pop.keng { color: #6b4f12; font-size: 28px; text-shadow: 2px 2px 0 #fff; }
@keyframes popup { from { opacity: 1; } to { opacity: 0; transform: translate(-50%, -160%); } }
.shard { position: absolute; width: 9px; height: 13px; margin: -6px; border-radius: 2px; }
.bubble { position: absolute; z-index: 4; width: 220px; padding: 10px 12px; background: #fffef8; border: 2px dashed #9a8a7a; border-radius: 16px; font-size: 17px; font-style: italic; color: #4a3a30;
  opacity: 0; transform: translateY(10px) scale(.95); transition: opacity .25s, transform .25s; pointer-events: none; box-shadow: 0 6px 18px rgba(0, 0, 0, .2); }
.bubble.on { opacity: 1; transform: none; }
.bubble.heard { border-style: solid; border-color: var(--jade); }
.bubble.torn { border-color: var(--red); color: #9a3a30; transform: rotate(-3deg); }
.w-ok { display: block; font-style: normal; font-size: 13px; color: var(--jade); margin-top: 4px; }
.taunt { position: absolute; top: 96px; left: 50%; transform: translateX(-50%) scale(.8); z-index: 3; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 12px; font-size: 16px; opacity: 0; transition: all .15s; white-space: nowrap; pointer-events: none; }
.taunt.on { opacity: 1; transform: translateX(-50%) scale(1); }
.stop-hint { position: absolute; left: 50%; bottom: 20%; transform: translateX(-50%); z-index: 7; background: rgba(28, 15, 13, .85); color: #fff5d6; padding: 10px 18px; border-radius: 14px; font-size: 22px; white-space: nowrap; animation: pulse 1s infinite; pointer-events: none; }
.banner { position: absolute; top: 38%; left: 0; right: 0; text-align: center; z-index: 8; font-size: 34px; color: #fff5d6; background: linear-gradient(90deg, transparent, rgba(200, 38, 31, .92) 20%, rgba(200, 38, 31, .92) 80%, transparent); padding: 10px; animation: bannerin .35s ease-out; pointer-events: none; text-shadow: 2px 2px 0 var(--red-d); }
@keyframes bannerin { from { transform: scaleY(0); } }
.pause-mask { position: absolute; inset: 0; z-index: 20; background: rgba(28, 15, 13, .85); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; }
.pause-mask .btn.big { max-width: 280px; }
.pm-title { font-size: 34px; color: #fff5d6; }

/* ---------- kết quả ---------- */
.big-score { text-align: center; font-size: 54px; color: var(--red); line-height: 1; display: flex; gap: 8px; justify-content: center; align-items: center; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; font-size: 13px; }
.stats div { background: #fffaf0; border: 2px solid var(--paper-d); border-radius: 10px; padding: 6px 2px; }
.stats b { display: block; font-size: 20px; }

/* ---------- truyện ---------- */
.story .lines p, .story .line { font-size: 19px; line-height: 1.5; margin: 6px 0; animation: rise .45s ease-out; }
.lines.big .line { font-size: 22px; }
.tap-more { text-align: center; opacity: .55; margin-top: auto; }
.paper { white-space: pre-wrap; font-family: 'Times New Roman', serif; background: #ece3cc; color: #3a3226; padding: 12px 14px; border: 1px solid #b9ab88; font-size: 15px; line-height: 1.4; transform: rotate(-1deg); box-shadow: 0 4px 10px rgba(0, 0, 0, .15); }
.paper.reveal { animation: rise .8s ease-out; }
.after { font-size: 18px; color: var(--red-d); }
.trash-items { display: flex; justify-content: space-around; gap: 6px; }
.trash-it { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px; border-radius: 12px; background: #fffaf0; border: 2px dashed #b9ab88; font-size: 14px; }
.trash-it.on { border-style: solid; border-color: var(--red); }
.white-doll { position: relative; height: 30vh; min-height: 180px; display: flex; justify-content: center; }
.white-doll svg { height: 100%; }
.white-doll .pen { position: absolute; right: 18%; bottom: 6px; font-size: 34px; transform: rotate(30deg); }
.white-doll .slipper-ico { position: absolute; left: 4%; bottom: -30px; transform: scale(.45) rotate(-75deg); }
.choices { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.name-in { font-family: Pangolin, Itim, cursive; font-size: 26px; text-align: center; padding: 10px; border-radius: 12px; border: 2px solid #5a3a30; background: #fbf6ea; color: var(--red); }
.quote { font-family: Pangolin, Itim, cursive; font-size: 22px; color: #f5d36e; text-align: center; margin: 6px 0; }
.end-card { position: absolute; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); background: #fffaf0; color: var(--ink); border-radius: 18px; padding: 16px; text-align: center; animation: rise .5s ease-out; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }
.end-card h2 { margin: 2px 0 4px; }

/* ---------- hồ sơ / cài đặt ---------- */
.j summary { cursor: pointer; font-size: 18px; margin-bottom: 6px; }
.j .frag { margin-top: 6px; }
.ws { margin: 0; padding-left: 18px; font-size: 15px; line-height: 1.5; }
.ws .torn { color: #b0a090; list-style: none; margin-left: -18px; }
.settings input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--red); }
.dump { width: 100%; height: 120px; margin-top: 8px; font-size: 11px; font-family: monospace; }

#toast { display: none; position: fixed; left: 50%; bottom: 12%; transform: translateX(-50%); background: rgba(28, 15, 13, .9); color: #fff5d6; padding: 10px 18px; border-radius: 12px; z-index: 50; font-size: 16px; max-width: 90vw; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .pulse, .title-dolls > div, .tap-obj, .combo.hot, .stop-hint { animation: none; }
}
