:root {
  --ink: #16110f; --paper: #f2e8d5; --crimson: #b3122a; --rose: #e0344c; --indigo: #33405e;
  --font: Georgia, serif;
  --ol: -2px -2px 0 #16110f, 2px -2px 0 #16110f, -2px 2px 0 #16110f, 2px 2px 0 #16110f, 0 -2px 0 #16110f, 0 2px 0 #16110f, -2px 0 0 #16110f, 2px 0 0 #16110f, 3px 4px 0 rgba(0,0,0,.55);
  --ols: -1.5px -1.5px 0 #16110f, 1.5px -1.5px 0 #16110f, -1.5px 1.5px 0 #16110f, 1.5px 1.5px 0 #16110f, 0 2px 0 #16110f, 2px 3px 0 rgba(0,0,0,.5);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
html, body { margin: 0; width: 100%; height: 100%; background: #0d0a09; overflow: hidden; overscroll-behavior: none; touch-action: manipulation; }
#root { position: fixed; inset: 0; overflow: hidden; font-family: var(--font); color: var(--paper); }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#tap { position: absolute; inset: 0; z-index: 2; cursor: pointer; }
.hidden { display: none !important; }

:where(button.btn) { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font); transition: transform .12s ease, filter .15s ease; -webkit-tap-highlight-color: transparent; }
button.btn:active { transform: scale(.93); }

/* lacquer plate (ui-button) */
.pill, .choice, .mBtn, #namePlate {
  /* the plate is drawn in a band of the picture (x 9–376, y 84–158 of 384×256): slice around it, push the empty margin outside */
  border: 0 solid transparent; border-image-source: url(assets/ui-button.webp); border-image-slice: 104 38 118 39 fill;
  border-image-width: 42px 15px 47px 16px; border-image-outset: 34px 3px 39px 4px; border-image-repeat: stretch;
}
#textbox, .panel {
  /* the frame is drawn at x 12–499, y 132–380 of 512×512 */
  border: 0 solid transparent; border-image-source: url(assets/ui-panel.webp); border-image-slice: 172 98 172 97 fill;
  border-image-width: 52px 29px 52px 29px; border-image-outset: 40px 4px 40px 4px; border-image-repeat: stretch;
}
.pill { min-width: 60px; height: 44px; padding: 0 16px; color: var(--paper); font-size: 15px; font-weight: 700; text-shadow: var(--ols); letter-spacing: .05em; opacity: .9; }
.pill.on { opacity: 1; color: #ffd6dc; filter: brightness(1.2) drop-shadow(0 0 6px rgba(224,52,76,.95)); }
@media (hover: hover) { .pill:hover { filter: brightness(1.2); } }

/* HUD */
#hud { position: absolute; z-index: 5; top: calc(10px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); display: flex; gap: 8px; align-items: center; animation: slideDown .35s cubic-bezier(.2,1.4,.4,1); }
#goldBox { display: flex; align-items: center; gap: 4px; height: 36px; padding: 0 12px 0 4px; background: rgba(22,17,15,.62); border-radius: 18px; box-shadow: inset 0 0 0 1.5px rgba(179,18,42,.7); font-size: 17px; font-weight: 700; text-shadow: var(--ols); }
#goldBox img { width: 30px; height: 30px; object-fit: contain; }

/* dialogue box (ui-panel) */
#textbox { position: absolute; z-index: 4; left: calc(10px + env(safe-area-inset-left)); right: calc(10px + env(safe-area-inset-right)); bottom: calc(12px + env(safe-area-inset-bottom));
  min-height: 168px; padding: 30px 30px 26px;
  color: var(--ink); font-size: 17px; line-height: 1.75; pointer-events: none; animation: boxIn .35s cubic-bezier(.2,1.5,.4,1); }
#textbox.narr #lineText { color: var(--indigo); }
#textbox.gold { filter: sepia(.55) saturate(1.7) hue-rotate(-12deg) brightness(1.04) drop-shadow(0 0 6px rgba(230,180,80,.55)); }
#lineText { min-height: 3.4em; white-space: pre-wrap; word-break: break-word; }
#namePlate { position: absolute; left: 14px; top: -50px; height: 44px; padding: 0 24px; display: flex; align-items: center;
  font-size: 18px; font-weight: 700; color: var(--paper); text-shadow: var(--ols); letter-spacing: .1em; white-space: nowrap; }
#namePlate.pop { animation: plateIn .3s cubic-bezier(.2,1.6,.4,1); }
#namePlate[data-who="xiaohan"] { color: #ffc9d0; }
#namePlate[data-who="wei"] { color: #c9c3ff; }
#nextMark { position: absolute; right: 26px; bottom: 22px; width: 11px; height: 11px; background: var(--crimson); transform: rotate(45deg); opacity: 0; }
#nextMark.on { opacity: 1; animation: bob 1s ease-in-out infinite; }

/* choices */
#choices { position: absolute; z-index: 6; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: 70px 18px 200px; background: radial-gradient(ellipse at 50% 45%, rgba(10,6,6,.55), rgba(10,6,6,.25) 70%); animation: fadeIn .25s; }
#choiceList { display: flex; flex-direction: column; gap: 14px; width: 100%; align-items: center; }
.choice { width: min(100%, 360px); min-height: 62px; padding: 12px 28px; color: var(--paper); font-size: 17px; font-weight: 700; line-height: 1.45;
  text-align: center; text-shadow: var(--ols); animation: choiceIn .5s cubic-bezier(.2,1.5,.4,1) both; }
.choice.fromR { animation-name: choiceInR; }
.choice.focus { transform: scale(1.05); filter: brightness(1.3) drop-shadow(0 0 8px rgba(224,52,76,.95)); }
@media (hover: hover) { .choice:hover { transform: scale(1.04); filter: brightness(1.3) drop-shadow(0 0 8px rgba(224,52,76,.95)); } }
.choice.fated { animation: fated 1.1s ease-in-out infinite; color: #ffd6dc; }
.choice.picked { animation: picked .42s ease-out forwards; }
.choice.gone { animation: gone .3s ease-in forwards; }
.pill.hint { height: 46px; padding: 0 18px 0 8px; }
.pill.hint img { width: 34px; height: 34px; object-fit: contain; }

#toast { position: absolute; z-index: 8; left: 0; right: 0; top: 33%; text-align: center; font-size: 26px; font-weight: 900; color: #ff6b7d; text-shadow: var(--ol); letter-spacing: .2em; opacity: 0; pointer-events: none; padding: 0 16px; }
#toast.down { color: #b9c3dc; }
#toast.show { animation: toast 1.7s ease-out; }

/* chapter card */
#chapterCard { position: absolute; z-index: 7; left: 0; right: 0; top: 36%; height: 170px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; pointer-events: none; }
#chapterCard .ink { position: absolute; inset: 0; background: var(--ink);
  clip-path: polygon(0 16%, 7% 7%, 28% 12%, 52% 3%, 77% 10%, 100% 0, 100% 86%, 84% 95%, 62% 88%, 36% 98%, 13% 90%, 0 100%); transform-origin: left center; animation: inkIn .6s cubic-bezier(.6,0,.2,1) both; }
#chapterCard .ink::after { content: ""; position: absolute; left: 8%; right: 8%; bottom: 22%; height: 3px; background: var(--crimson); transform-origin: left; animation: inkIn .6s .5s cubic-bezier(.6,0,.2,1) both; }
#chapterCard .num { position: relative; color: var(--rose); font-size: 16px; letter-spacing: .45em; font-weight: 700; animation: fadeUp .5s .3s both; }
#chapterCard .name { position: relative; color: var(--paper); font-size: 38px; font-weight: 900; letter-spacing: .25em; text-shadow: var(--ol); text-align: center; padding: 0 12px; animation: nameIn .9s .4s cubic-bezier(.2,1.2,.3,1) both; }
#chapterCard .rew { position: relative; display: flex; align-items: center; gap: 6px; font-size: 20px; font-weight: 700; text-shadow: var(--ols); animation: fadeUp .5s .7s both; }
#chapterCard .rew img { width: 32px; height: 32px; }
#chapterCard.out { animation: cardOut .35s ease-in forwards; }

/* title */
#title { position: absolute; inset: 0; z-index: 9; cursor: pointer; }
#logoWrap { position: absolute; left: 7%; right: 7%; top: calc(6% + env(safe-area-inset-top)); height: 30%; display: flex; align-items: center; justify-content: center; animation: float 5s 1s ease-in-out infinite; }
#logo { max-width: 100%; max-height: 100%; object-fit: contain; filter: drop-shadow(0 4px 12px rgba(0,0,0,.45)); animation: logoIn .9s cubic-bezier(.2,1.4,.4,1) both; }
#startPrompt { position: absolute; left: 0; right: 0; bottom: calc(9% + env(safe-area-inset-bottom)); text-align: center; font-size: 18px; font-weight: 700; letter-spacing: .18em; color: var(--paper); text-shadow: var(--ol); animation: pulse 2.2s ease-in-out infinite; padding: 0 20px; }
#startPrompt::before, #startPrompt::after { content: "◆"; color: var(--rose); font-size: 12px; margin: 0 12px; vertical-align: middle; }
.corner { position: absolute; top: calc(10px + env(safe-area-inset-top)); width: 48px; height: 48px; border-radius: 50%; background: rgba(22,17,15,.55); box-shadow: inset 0 0 0 2px rgba(179,18,42,.75); animation: fadeIn .6s .6s both; }
#root:has(#modal:not(.hidden)) #startPrompt, #root:has(#cgView:not(.hidden)) #startPrompt { visibility: hidden; }
.corner img { width: 34px; height: 34px; object-fit: contain; pointer-events: none; }
.corner.left { left: calc(10px + env(safe-area-inset-left)); }
.corner.right { right: calc(10px + env(safe-area-inset-right)); }

/* modal panels */
#modal { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(8,5,5,.6); animation: fadeIn .2s; }
#modal.bottom { align-items: flex-end; padding-bottom: calc(22px + env(safe-area-inset-bottom)); background: linear-gradient(rgba(8,5,5,0) 35%, rgba(8,5,5,.8)); }
.panel { width: min(92%, 380px); max-height: 94%; padding: 36px 30px 32px;
  color: var(--ink); display: flex; flex-direction: column; align-items: stretch; gap: 12px; animation: pop .32s cubic-bezier(.2,1.5,.4,1); }
.mTitle { text-align: center; font-size: 22px; font-weight: 900; color: var(--crimson); letter-spacing: .15em; }
.mSub { text-align: center; font-size: 14px; font-weight: 700; color: var(--indigo); letter-spacing: .1em; }
.mBtn { min-height: 52px; padding: 10px 20px; color: var(--paper); font-size: 16px; font-weight: 700; text-shadow: var(--ols); text-align: center; line-height: 1.3; }
.mBtn.primary { color: #ffd6dc; }
.mBtn.focus { transform: scale(1.04); filter: brightness(1.3) drop-shadow(0 0 7px rgba(224,52,76,.95)); }
@media (hover: hover) { .mBtn:hover { filter: brightness(1.3) drop-shadow(0 0 7px rgba(224,52,76,.95)); } }
.mBtn img { width: 28px; height: 28px; object-fit: contain; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { aspect-ratio: 2 / 3; width: 100%; background: #2a201c center / cover no-repeat; box-shadow: inset 0 0 0 2px var(--ink); border-radius: 3px; color: #8b7b70; font-size: 22px; font-weight: 900; }
.thumb.focus { transform: scale(1.05); filter: drop-shadow(0 0 6px rgba(224,52,76,.95)); }
.endList { display: flex; flex-direction: column; gap: 4px; font-size: 15px; font-weight: 700; }
.endList div { display: flex; justify-content: space-between; border-bottom: 1px dashed rgba(22,17,15,.35); padding: 3px 2px; }
.endList .got { color: var(--crimson); }
.bag { display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: center; font-size: 15px; font-weight: 700; }
.bag span { display: inline-flex; align-items: center; gap: 4px; }
.bag img { width: 30px; height: 30px; object-fit: contain; }
.endNo { text-align: center; color: var(--crimson); font-size: 15px; font-weight: 700; letter-spacing: .4em; }
.endName { text-align: center; font-size: 30px; font-weight: 900; letter-spacing: .2em; color: var(--ink); animation: nameIn .9s .1s cubic-bezier(.2,1.2,.3,1) both; }
.endName::after { content: ""; display: block; height: 3px; margin: 6px auto 0; width: 60%; background: var(--crimson); }
.reward { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 22px; font-weight: 900; color: var(--crimson); }
.reward img { width: 36px; height: 36px; }

#cgView { position: absolute; inset: 0; z-index: 22; background: #0d0a09 center / contain no-repeat; animation: fadeIn .25s; cursor: pointer; }
#intro { position: absolute; inset: 0; z-index: 30; background: #000 url(assets/cover-bg.webp) center / cover no-repeat; }
#introVid { width: 100%; height: 100%; object-fit: cover; display: block; }
#btnSkipIntro { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); }
#introSub { position: absolute; left: 8%; right: 8%; bottom: 12%; text-align: center; font-size: 18px; font-weight: 700; line-height: 1.6; text-shadow: var(--ol); opacity: 0; transition: opacity .6s; }
#introSub.on { opacity: 1; }
#fadeCover { position: absolute; inset: 0; z-index: 25; background: #0d0a09; opacity: 0; pointer-events: none; transition: opacity .45s ease; }
#fadeCover.on { opacity: 1; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideDown { from { transform: translateY(-60px); } to { transform: none; } }
@keyframes boxIn { from { transform: translateY(40px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes plateIn { from { transform: translateX(-24px) scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(45deg); } 50% { transform: translateY(4px) rotate(45deg); } }
@keyframes choiceIn { from { transform: translateX(-60px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes choiceInR { from { transform: translateX(60px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fated { 0%,100% { filter: brightness(1.15) drop-shadow(0 0 4px rgba(224,52,76,.8)); } 50% { filter: brightness(1.4) drop-shadow(0 0 14px rgba(255,60,90,1)); } }
@keyframes picked { 0% { transform: scale(1); } 30% { transform: scale(1.1); filter: brightness(1.6) drop-shadow(0 0 16px #ff4a62); } 100% { transform: scale(1.02); opacity: 0; } }
@keyframes gone { to { transform: scale(.9); opacity: 0; } }
@keyframes toast { 0% { opacity: 0; transform: scale(.6); } 15% { opacity: 1; transform: scale(1.12); } 25% { transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-30px); } }
@keyframes inkIn { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes nameIn { from { opacity: 0; letter-spacing: .9em; filter: blur(6px); } to { opacity: 1; filter: none; } }
@keyframes cardOut { to { opacity: 0; transform: scale(1.06); } }
@keyframes logoIn { 0% { opacity: 0; transform: translateY(-50px) scale(1.25); } 70% { opacity: 1; transform: translateY(4px) scale(.97); } 100% { transform: none; } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes pulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }
@keyframes pop { 0% { transform: scale(.7); opacity: 0; } 70% { transform: scale(1.03); opacity: 1; } 100% { transform: none; } }
