* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0b1020; overflow: hidden; }
#app {
  position: fixed; inset: 0; overflow: hidden; font-family: var(--font, sans-serif);
  user-select: none; -webkit-user-select: none; touch-action: none; -webkit-tap-highlight-color: transparent;
  --u: 4px; --ts: 1; --fs: max(14px, calc(var(--u) * 3.9 * var(--ts)));
  --ink: #111; --red: #d81e2c;
}
.hidden { display: none !important; }

/* ---------- title ---------- */
#title { position: absolute; inset: 0; overflow: hidden; background: #0b1020; z-index: 20; }
#titleBg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform-origin: 50% 70%; animation: kenburns 18s ease-in-out infinite alternate; }
@keyframes kenburns { from { transform: scale(1.02); } to { transform: scale(1.09) translateY(-1%); } }
#titleShade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(5,8,24,.55) 0%, rgba(5,8,24,0) 38%, rgba(5,8,24,0) 70%, rgba(5,8,24,.75) 100%); }
#titleLogoWrap { position: absolute; left: 7%; right: 7%; top: 6%; height: 27%; display: flex; align-items: center; justify-content: center; }
#titleLogo { max-width: 100%; max-height: 100%; object-fit: contain; filter: drop-shadow(0 6px 0 rgba(0,0,0,.35)); }
#titleLogoWrap.textLogo { font-weight: 900; font-size: calc(var(--u) * 12); color: #fff; text-shadow: 0 0 0 #000, 4px 4px 0 var(--red), -2px -2px 0 #111, 2px -2px 0 #111, -2px 2px 0 #111, 2px 2px 0 #111; transform: rotate(-5deg); text-align: center; }
#titleChapter {
  position: absolute; left: 50%; bottom: 15%; transform: translateX(-50%) skewX(-10deg);
  background: var(--red); color: #fff; font-weight: 900; font-size: max(15px, calc(var(--u) * 4.2));
  padding: 6px 18px; white-space: nowrap; border: 3px solid #111; box-shadow: 5px 5px 0 #111;
}
#titleStart {
  position: absolute; left: 6%; right: 6%; bottom: 8%; text-align: center; color: #fff; font-weight: 900;
  font-size: max(16px, calc(var(--u) * 4.6)); letter-spacing: .04em;
  text-shadow: -2px -2px 0 #111, 2px -2px 0 #111, -2px 2px 0 #111, 2px 2px 0 #111, 0 4px 0 #111;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .55; transform: scale(.97); } 50% { opacity: 1; transform: scale(1.03); } }
#title.enter #titleLogoWrap { animation: logoDrop .65s cubic-bezier(.3,1.5,.5,1) both, floaty 4s ease-in-out .7s infinite; }
#title.enter #titleChapter { animation: stripeIn .45s .35s cubic-bezier(.3,1.4,.5,1) both; }
@keyframes logoDrop { from { transform: translateY(-60%) scale(1.25); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes stripeIn { from { transform: translateX(-50%) skewX(-10deg) scaleX(0); } to { transform: translateX(-50%) skewX(-10deg) scaleX(1); } }

/* ---------- intro ---------- */
#introWrap { position: absolute; inset: 0; z-index: 40; background: #000 url(assets/cover-bg.webp) center / cover no-repeat; }
#introVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#skipBtn { position: absolute; right: 20px; bottom: 28px; z-index: 2; }

/* ---------- reader ---------- */
#reader { position: absolute; inset: 0; overflow: hidden; background: #fdfcf8; --cap: #333; }
#reader.theme-court { background: repeating-linear-gradient(90deg, #c98a4b 0 46px, #b8783c 46px 49px, #d39556 49px 95px, #c07f42 95px 98px); --cap: #2a1606; }
#reader.theme-night { background: radial-gradient(circle at 15% 12%, rgba(255,60,110,.28), transparent 42%), radial-gradient(circle at 85% 70%, rgba(40,220,255,.22), transparent 48%), #0d1028; --cap: #ffe36a; }
#content { position: absolute; left: 0; top: 0; width: 100%; will-change: transform; padding-bottom: 20px; }
.page { position: relative; }
.imgwrap { position: relative; width: 100%; background: #1b2238; }
.imgwrap img { display: block; width: 100%; height: 100%; object-fit: cover; opacity: 0; transform: translateY(28px); transition: opacity .7s ease-out, transform .9s cubic-bezier(.2,.8,.2,1); }
.page.in .imgwrap img { opacity: 1; transform: none; }
.page.nomotion .imgwrap img { transition: none; }
.imgwrap.missing { background: repeating-linear-gradient(45deg, #222 0 12px, #2a2a2a 12px 24px); }

/* bubbles */
.bubble {
  position: absolute; z-index: 5; width: max-content; max-width: 66%;
  transform: translate(-50%, -50%) rotate(var(--r, 0deg)) scale(0);
  background: #fff; color: #111; --bc: #111; border: 2.5px solid var(--bc); border-radius: 1.3em;
  padding: .55em .95em; font-size: var(--fs); font-weight: 700; line-height: 1.4; text-align: center;
  transition: transform .38s cubic-bezier(.3,1.6,.5,1), box-shadow .2s;
  box-shadow: 0 3px 0 rgba(0,0,0,.18);
}
.bubble.show { transform: translate(-50%, -50%) rotate(var(--r, 0deg)) scale(1); }
.bubble.voiced { cursor: pointer; min-height: 44px; display: flex; align-items: center; justify-content: center; }
.bubble.speaking { box-shadow: 0 0 0 3px #ffd23a, 0 0 18px rgba(255,190,30,.85); }
.bubble[class*="tail-"]::after {
  content: ""; position: absolute; width: 14px; height: 14px; background: inherit;
  border: 0 solid var(--bc);
}
.tail-b::after, .tail-bl::after, .tail-br::after { bottom: -8.5px; border-right-width: 2.5px !important; border-bottom-width: 2.5px !important; transform: rotate(45deg) skew(8deg, 8deg); }
.tail-t::after, .tail-tl::after, .tail-tr::after { top: -8.5px; border-left-width: 2.5px !important; border-top-width: 2.5px !important; transform: rotate(45deg) skew(8deg, 8deg); }
.tail-b::after, .tail-t::after { left: calc(50% - 7px); }
.tail-bl::after, .tail-tl::after { left: 22%; }
.tail-br::after, .tail-tr::after { right: 22%; }
.bubble.shout { border-width: 3.5px; font-weight: 900; font-size: calc(var(--fs) * 1.12); border-radius: .7em; box-shadow: 4px 4px 0 #111; }
.bubble.shout[class*="tail-"]::after { border-width: 0; }
.bubble.sepia { background: #fff4dc; --bc: #6b4320; color: #3d2410; }
.bubble.memory { background: rgba(255, 238, 200, .9); --bc: #a0642c; border-style: dashed; color: #5a3510; font-style: italic; box-shadow: 0 0 22px rgba(255,200,120,.8); }
.bubble.phone { background: #eef5ff; border-style: dotted; border-width: 3px; --bc: #1d3a6b; color: #10264a; }
.bubble.phone::before { content: "📞"; display: none; }
.bubble.nar { background: #111; color: #fff; --bc: #111; border-radius: 3px; font-weight: 700; font-size: calc(var(--fs) * .92); padding: .45em .8em; box-shadow: 3px 3px 0 rgba(216,30,44,.9); }
.bubble.nar.sepia { background: #4a2d14; box-shadow: 3px 3px 0 rgba(0,0,0,.35); }
.caption { position: absolute; z-index: 5; transform: translate(-50%, -50%); white-space: nowrap; color: var(--cap); font-weight: 900; font-size: calc(var(--fs) * .95); letter-spacing: .25em; opacity: 0; transition: opacity .8s; }
.caption.show { opacity: 1; }
.sfxText {
  position: absolute; z-index: 6; pointer-events: none; white-space: nowrap; color: #fff; font-weight: 900; font-style: italic;
  font-size: calc(var(--fs) * 2.5 * var(--s, 1)); line-height: 1;
  transform: translate(-50%, -50%) rotate(var(--r, 0deg)) scale(0);
  text-shadow: -3px -3px 0 #111, 3px -3px 0 #111, -3px 3px 0 #111, 3px 3px 0 #111, 0 0 0 #111, 7px 7px 0 var(--red);
  transition: transform .32s cubic-bezier(.2,1.9,.4,1);
}
.sfxText.show { transform: translate(-50%, -50%) rotate(var(--r, 0deg)) scale(1); }

/* fx layers */
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 8; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 9; }
#progress { position: absolute; left: 0; right: 0; top: 0; height: 4px; background: rgba(0,0,0,.18); z-index: 10; }
#progressFill { height: 100%; width: 0; background: var(--red); }
#hud { position: absolute; top: 12px; left: 70px; right: 70px; display: flex; justify-content: center; z-index: 10; pointer-events: none; }
#hudPill {
  display: flex; align-items: center; gap: 10px; background: rgba(12, 14, 28, .82); color: #fff; border: 2px solid #111;
  border-radius: 999px; padding: 7px 14px; font-weight: 900; font-size: 16px; box-shadow: 3px 3px 0 var(--red); white-space: nowrap;
}
#hudPage { color: #ffd23a; }
#hudGold { display: flex; align-items: center; gap: 4px; border-left: 2px solid rgba(255,255,255,.25); padding-left: 10px; }
#hudGold img { width: 20px; height: 20px; object-fit: contain; }
#autoBadge { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); z-index: 10; background: var(--red); color: #fff; font-weight: 900; font-size: 13px; padding: 4px 12px; border: 2px solid #111; border-radius: 999px; pointer-events: none; animation: pulse 1.4s ease-in-out infinite; white-space: nowrap; }

/* ---------- comic UI art ---------- */
.panel {
  border: 22px solid transparent;
  border-image-source: var(--panel-img, none); border-image-slice: 40 fill; border-image-width: 22px; border-image-repeat: stretch;
  color: #111;
}
.btn {
  appearance: none; -webkit-appearance: none; background: none; cursor: pointer; font-family: inherit;
  border: 14px solid transparent;
  border-image-source: var(--btn-img, none); border-image-slice: 64 fill; border-image-width: 22px; border-image-repeat: stretch;
  color: #fff; font-weight: 900; font-size: 16px; min-height: 50px; min-width: 50px; padding: 0 8px; line-height: 1.15;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-shadow: -1.5px -1.5px 0 #111, 1.5px -1.5px 0 #111, -1.5px 1.5px 0 #111, 1.5px 1.5px 0 #111, 0 2.5px 0 #111;
  transition: transform .12s, filter .12s;
}
.btn:hover, .btn.focus { filter: brightness(1.12) drop-shadow(0 0 6px #ffd23a); transform: scale(1.04); }
.btn:active { transform: scale(.93); }
.btn.gold { filter: hue-rotate(38deg) saturate(1.3) brightness(1.08); }
.btn.gold:hover, .btn.gold.focus { filter: hue-rotate(38deg) saturate(1.3) brightness(1.2) drop-shadow(0 0 6px #fff); }
.btn.dim { filter: grayscale(1) opacity(.6); cursor: default; }
.btn.small { font-size: 15px; min-width: 96px; }
.btn.arrow { font-size: 26px; min-width: 52px; padding: 0; }
.btn .coinIcon, .rewardRow .coinIcon { width: 22px; height: 22px; object-fit: contain; filter: none; }

/* end card */
.endcard { padding: calc(var(--u) * 22) 6% 120px; }
.endPanel { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 4px; }
.endTitle { font-weight: 900; font-size: calc(var(--u) * 8); color: #fff; transform: rotate(-4deg); text-shadow: -3px -3px 0 #111, 3px -3px 0 #111, -3px 3px 0 #111, 3px 3px 0 #111, 6px 6px 0 var(--red); margin-top: 6px; text-align: center; }
.dribble { width: 46%; aspect-ratio: 3 / 4; }
.nextEp { font-weight: 800; font-size: 15px; text-align: center; color: #333; padding: 0 6px; line-height: 1.4; }
.rewardRow { display: flex; align-items: center; gap: 8px; background: #111; color: #fff; border-radius: 999px; padding: 6px 16px; font-weight: 900; font-size: 15px; }
.rewardRow .rewardNum { color: #ffd23a; font-size: 20px; }
.rewardRow.pop { animation: popIn .5s cubic-bezier(.3,1.7,.5,1); }
@keyframes popIn { from { transform: scale(.2); } to { transform: scale(1); } }
.endBtns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin-top: 4px; }
.endBtns .wide { grid-column: 1 / -1; }

/* overlays */
#overlay { position: absolute; inset: 0; z-index: 30; }
.ovlBack { position: absolute; inset: 0; background: rgba(8, 10, 24, .66); }
.ovlPanel { position: absolute; left: 50%; top: 50%; width: 88%; max-height: 88%; transform: translate(-50%, -50%); display: flex; flex-direction: column; gap: 8px; padding: 4px; }
.ovlPanel.enter { animation: ovlPop .28s cubic-bezier(.3,1.5,.5,1); }
@keyframes ovlPop { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
.ovlTitle { font-weight: 900; font-size: 22px; text-align: center; color: #fff; text-shadow: -2px -2px 0 #111, 2px -2px 0 #111, -2px 2px 0 #111, 2px 2px 0 #111, 4px 4px 0 var(--red); }
.ovlBody { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.ovlBtns { display: flex; justify-content: center; gap: 10px; margin-top: 4px; }
.ovlBtns .btn { min-width: 120px; }
.abView { display: flex; align-items: center; gap: 6px; }
.abCard { flex: 1; height: min(40vh, 330px); display: flex; align-items: center; justify-content: center; background: radial-gradient(circle, #ffe9a8 0%, rgba(255,233,168,0) 70%); }
.abImg { max-width: 100%; max-height: 100%; object-fit: contain; }
.abImg.locked { filter: brightness(0) opacity(.55); }
.abName { font-weight: 900; font-size: 22px; text-align: center; color: var(--red); }
.abProf { font-size: 15px; line-height: 1.55; color: #222; text-align: center; padding: 0 4px; min-height: 4.6em; }
.dots { display: flex; justify-content: center; gap: 6px; }
.dots span { width: 9px; height: 9px; border-radius: 50%; background: #bbb; border: 1.5px solid #111; }
.dots span.on { background: var(--red); }
.buyRow { display: flex; justify-content: center; }
.buyRow .btn { min-width: 160px; }
.thRow { display: flex; align-items: center; gap: 10px; padding: 6px 2px; border-bottom: 2px dashed rgba(0,0,0,.15); }
.thIcon { width: 52px; height: 52px; flex: none; border: 2.5px solid #111; border-radius: 8px; overflow: hidden; background: #fdfcf8; }
.thIcon img { width: 100%; height: 100%; object-fit: cover; }
.thName { flex: 1; font-weight: 900; font-size: 16px; color: #111; }
.thRow .btn { min-width: 104px; font-size: 15px; }

#toast { position: absolute; left: 50%; top: 18%; transform: translate(-50%, -10px); background: #111; color: #fff; font-weight: 900; font-size: 15px; padding: 10px 18px; border-radius: 999px; border: 2px solid #ffd23a; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
