:root {
  --bg: #16161a;
  --ink: #111;
  --paper: #fff;
  --cream: #fbf6e6;
  --accent: #e8b84a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; color: #eee;
  font-family: "Zen Maru Gothic", system-ui, sans-serif; }

#stage { position: fixed; inset: 0; overflow: hidden; }
#track { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }

/* ---------- page ---------- */
.page { position: absolute; top: 0; width: 1000px; height: 1414px; background: var(--paper); overflow: hidden; color: #111;
  box-shadow: 0 30px 80px rgba(0,0,0,.55); transition: filter .8s ease; }
.page.bw { filter: grayscale(1) contrast(1.08) brightness(.82); }
.page.bw .letters, .page.bw .outs { }
.panel { position: absolute; inset: 0; transition: filter .5s ease; }
.page.reading .panel.dim, .page.reading .outgrp.dim { filter: saturate(.55) brightness(.78); }
.pc { position: absolute; inset: 0; transform-origin: 50% 50%; }
.bgimg { position: absolute; max-width: none; user-select: none; pointer-events: none; transform-origin: 50% 50%; }
.bgcol { position: absolute; inset: -20px; }
.lay { position: absolute; user-select: none; pointer-events: none; transform-origin: 50% 100%; }
.layin { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; transform-origin: 50% 50%; }
.layin.ph { position: absolute; }
/* on the children, never on the panel itself: a filtered parent stops Chrome painting matrix3d screens */
.tint-flash > :not(.onscreen), .tint-flash > .onscreen > .ui { filter: sepia(.38) saturate(.78) brightness(1.03) contrast(.96); }
.flt-motion { filter: blur(.6px); }
.pw { position: absolute; inset: 0; pointer-events: none; }
.pw .panel { pointer-events: auto; }
.frame { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.frame polygon { fill: none; stroke-linejoin: miter; }
.frame .halo { stroke-width: 16; }
.frame .ink { stroke: #111; stroke-width: 3.4; }
.outs, .letters { position: absolute; inset: 0; pointer-events: none; }
.outs { z-index: 20; } .letters { z-index: 30; }
.outgrp { position: absolute; inset: 0; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }

/* placeholders (name preview while assets are generating) */
.ph { position: absolute; border: 2px dashed rgba(60,60,80,.55); background: rgba(160,170,190,.25);
  display: flex; align-items: center; justify-content: center; text-align: center;
  font: 700 13px/1.15 "Zen Maru Gothic", sans-serif; color: #334; padding: 6px; transform-origin: 50% 100%; }
.ph.bgph { background: repeating-linear-gradient(45deg, #e9ebf0 0 14px, #f4f5f8 14px 28px); border: none;
  align-items: flex-start; justify-content: flex-end; color: #8890a0; font-size: 11px; }
.ph.cutph { background: rgba(120,140,200,.28); border-radius: 46% 46% 8% 8%; }
.ph.propph { background: rgba(200,160,90,.28); border-radius: 12px; }

/* ---------- lettering ---------- */
.bal { position: absolute; transform-origin: 50% 50%; }
.bal svg { position: absolute; overflow: visible; }
.bal .tx { position: relative; text-align: center; color: #111; text-transform: uppercase;
  font: 700 17px/1.13 "Comic Neue", "Comic Sans MS", sans-serif; letter-spacing: .01em; }
.bal.k-think .tx { font-style: italic; }
.bal.k-weak .tx { color: #555; font-size: 15px; }
.bal.k-shout .tx { font-size: 20px; font-family: "Comic Neue", sans-serif; }
.bal.k-whisper .tx { color: #333; font-size: 15px; }
.cap { position: absolute; transform-origin: 0 50%; }
.cap .tx { font: italic 700 15.5px/1.2 "Comic Neue", sans-serif; text-transform: uppercase; }
.cap.k-narr { background: var(--cream); border: 2px solid #111; padding: 6px 10px; color: #111;
  box-shadow: 3px 3px 0 rgba(0,0,0,.25); }
.cap.k-dark { background: #0c0c10; border: 1.5px solid #ddd; padding: 6px 10px; color: #f4f4f4; }
.cap.k-float { color: #111; text-align: center; }
.page[data-dark="1"] .cap.k-float, .cap.k-float.on-dark { color: #f1f1f1; text-shadow: 0 0 10px #000; }
.sfx { position: absolute; white-space: nowrap; transform-origin: 50% 50%; line-height: 1; paint-order: stroke fill;
  letter-spacing: .02em; }
.sfx.f-sfx { font-family: "Bangers", "Impact", sans-serif; }
.sfx.f-hand { font-family: "Kalam", cursive; }
.sfx.f-jp { font-family: "Dela Gothic One", sans-serif; }

/* ---------- HUD ---------- */
#fx3d { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
#hud { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; padding: 10px 18px;
  display: flex; align-items: center; gap: 16px; background: linear-gradient(transparent, rgba(0,0,0,.6)); }
#progress { flex: 1; height: 4px; background: rgba(255,255,255,.15); border-radius: 2px; overflow: hidden; }
#bar { height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }
#info { display: flex; gap: 10px; align-items: center; font-size: 13px; color: #ccc; }
#info button { background: rgba(255,255,255,.1); color: #eee; border: 1px solid rgba(255,255,255,.2);
  border-radius: 6px; padding: 4px 9px; cursor: pointer; font: inherit; }
#info button:hover { background: rgba(255,255,255,.2); }
#helpbox { position: fixed; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: #1f1f26; border: 1px solid #444; border-radius: 12px; padding: 22px 28px; max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); }
#helpbox h2 { margin-top: 0; font-family: Cinzel, serif; color: var(--accent); }
#helpbox button { margin-top: 8px; padding: 6px 18px; border-radius: 6px; border: 0; background: var(--accent);
  font-weight: 700; cursor: pointer; }

/* plate mode: the artwork alone, sent to Astra for the paint-over */
body.plate .letters, body.plate .outs, body.plate .ui, body.plate .sfx, body.plate .frame,
body.plate .speedl, body.plate .flash { visibility: hidden !important; }
/* static (screenshot) mode */
body.static { background: #fff; overflow: auto; }
body.static #hud, body.static #fx3d { display: none; }
body.static #stage { position: static; }
body.static #track { position: static; transform: none !important; }
body.static .page { position: relative; box-shadow: none; left: 0 !important; }

@media (max-width: 700px) { #info { font-size: 11px; } }

/* motion design overlays (one set per panel, created on demand) */
.fxo { position: absolute; pointer-events: none; opacity: 0; }
.fx-vig { background: radial-gradient(ellipse at 50% 45%, transparent 38%, rgba(0,0,0,.78) 100%); }
.fx-invert { backdrop-filter: invert(1) contrast(1.3); -webkit-backdrop-filter: invert(1) contrast(1.3); }
.fx-rays { mix-blend-mode: screen; transform-origin: 50% 0%;
  background: repeating-conic-gradient(from 0deg at 50% -10%, rgba(255,240,200,.55) 0deg 4deg, transparent 4deg 13deg);
  -webkit-mask: linear-gradient(#000, transparent 85%); mask: linear-gradient(#000, transparent 85%); }
.fx-grain { mix-blend-mode: multiply; background-size: 180px 180px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .38 0 0 0 0 .3 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
.sfx .ch { display: inline-block; white-space: pre; }

/* static page = the end of the animation: the 99 lost parts are faded, only the kept one shines */
body.static .ui-orbs .grid i:not(.kept) { opacity: .15; transform: scale(.6); }

/* v6: code-drawn UI living on a surface of the illustration (mapped onto its chroma quad by matrix3d) */
.onscreen { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; }
.onscreen > .ui { position: absolute; box-sizing: border-box; transform: none !important; overflow: hidden; }
.onscreen > .ui-clock { display: flex; align-items: flex-end; justify-content: flex-end; padding: 0 6% 7% 0; font-size: 96px;
  background: #0d1424 url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%22640%22%20height%3D%22420%22%20viewBox%3D%220%200%20640%20420%22%3E%3Crect%20width%3D%22640%22%20height%3D%22420%22%20fill%3D%22%230d1424%22/%3E%3Crect%20x%3D%2252%22%20y%3D%2226%22%20width%3D%22141%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%237f8ea8%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2224%22%20y%3D%2250%22%20width%3D%2264%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ffd479%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2280%22%20y%3D%2274%22%20width%3D%22169%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%238fd3ff%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2224%22%20y%3D%2298%22%20width%3D%22151%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%239ff0b0%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2224%22%20y%3D%22122%22%20width%3D%2263%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ff9fb6%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2252%22%20y%3D%22146%22%20width%3D%2271%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%238fd3ff%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22108%22%20y%3D%22170%22%20width%3D%2255%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ff9fb6%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22177%22%20y%3D%22170%22%20width%3D%22141%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23c79bff%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22332%22%20y%3D%22170%22%20width%3D%2296%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23c79bff%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2280%22%20y%3D%22194%22%20width%3D%22114%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%239ff0b0%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2224%22%20y%3D%22218%22%20width%3D%2270%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ff9fb6%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22108%22%20y%3D%22218%22%20width%3D%22118%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ff9fb6%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22240%22%20y%3D%22218%22%20width%3D%2286%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23c79bff%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2280%22%20y%3D%22242%22%20width%3D%2288%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ffd479%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22182%22%20y%3D%22242%22%20width%3D%2264%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ff9fb6%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22260%22%20y%3D%22242%22%20width%3D%2256%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ff9fb6%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2224%22%20y%3D%22266%22%20width%3D%2292%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%239ff0b0%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22130%22%20y%3D%22266%22%20width%3D%22149%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ffd479%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22293%22%20y%3D%22266%22%20width%3D%22159%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ff9fb6%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2252%22%20y%3D%22290%22%20width%3D%22116%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%238fd3ff%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22182%22%20y%3D%22290%22%20width%3D%2286%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%237f8ea8%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2224%22%20y%3D%22314%22%20width%3D%22116%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ff9fb6%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2252%22%20y%3D%22338%22%20width%3D%22154%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ffd479%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22220%22%20y%3D%22338%22%20width%3D%2258%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23c79bff%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2280%22%20y%3D%22362%22%20width%3D%2282%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ffd479%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%22176%22%20y%3D%22362%22%20width%3D%2278%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%239ff0b0%22%20opacity%3D%22.55%22/%3E%3Crect%20x%3D%2252%22%20y%3D%22386%22%20width%3D%2259%22%20height%3D%2211%22%20rx%3D%223%22%20fill%3D%22%23ff9fb6%22%20opacity%3D%22.55%22/%3E%3C/svg%3E") left top / 100% 100% no-repeat; }
.onscreen > .ui-phone { border: 0; border-radius: 0; box-shadow: none; padding-top: 8px; }
.onscreen > .ui-phone .notch { display: none; }
.onscreen > .ui-screen, .onscreen > .ui-slide, .onscreen > .ui-eval { border: 0; border-radius: 0; box-shadow: none; }
/* on a real monitor the frame may crop the top of the glass: the code sits in the middle of the screen */
.onscreen > .ui-screen { display: flex; flex-direction: column; background: #0e1726 linear-gradient(180deg, rgba(120,160,255,.10), transparent 40%); }
.onscreen > .ui-screen pre { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 4px 10px;
  font-size: 30px; color: #9fb4d8; text-shadow: 0 0 10px rgba(120,170,255,.45); }
.onscreen > .ui-screen pre::after { content: "_"; margin-left: 6px; color: #9fb4d8; animation: hrblink 1s steps(1) infinite; }
@keyframes hrblink { 50% { opacity: 0; } }
.onscreen.single > .ui-notes { display: block; padding: 0; }
.onscreen.single > .ui-notes .note { transform: none !important; height: 100%; min-height: 0; box-sizing: border-box; box-shadow: none; font-size: 26px; }
.onscreen > .ui-screen.ok pre { color: #5dff9b; font-size: 40px; text-shadow: 0 0 14px #2dff80; }
.onscreen > .ui-screen.ok pre::after { content: none; }

/* ---------- v7: live panel engine + mobile ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }   /* phones must not inflate balloon text */
#stage { touch-action: none; overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
canvas.live { position: absolute; display: block; z-index: 0; transition: none; }
#hud { padding-bottom: max(10px, env(safe-area-inset-bottom)); padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right)); }
#info button.on { background: var(--accent); color: #111; border-color: var(--accent); }
.help-touch { display: none; }
body.touch .help-keys { display: none; }
body.touch .help-touch { display: block; }
body.touch #info button { min-width: 44px; min-height: 40px; font-size: 15px; }
body.touch #hud { gap: 10px; padding-top: 8px; }
@media (max-width: 520px) {
  #pageinfo { font-size: 11px; white-space: nowrap; }
  #helpbox { padding: 18px 20px; width: 88vw; }
  #helpbox h2 { font-size: 22px; }
  #helpbox p { font-size: 15px; line-height: 1.4; }
}

/* ---------- v8: languages ---------- */
#info select { background: rgba(255,255,255,.1); color: #eee; border: 1px solid rgba(255,255,255,.2); border-radius: 6px;
  padding: 4px 6px; font: inherit; cursor: pointer; max-width: 120px; }
#info select option { background: #1f1f26; color: #eee; }
body.touch #info select { min-height: 40px; font-size: 15px; }
:lang(ja) .bal .tx, :lang(ja) .cap .tx { font-family: "Comic Neue", "Noto Sans JP", sans-serif; font-weight: 700; text-transform: none; letter-spacing: 0; line-height: 1.25; }
:lang(ko) .bal .tx, :lang(ko) .cap .tx { font-family: "Comic Neue", "Noto Sans KR", sans-serif; font-weight: 700; text-transform: none; letter-spacing: 0; line-height: 1.25; word-break: keep-all; }
:lang(zh) .bal .tx, :lang(zh) .cap .tx { font-family: "Comic Neue", "Noto Sans SC", sans-serif; font-weight: 700; text-transform: none; letter-spacing: 0; line-height: 1.25; }
:lang(ja) .sfx, :lang(ko) .sfx, :lang(zh) .sfx { font-family: "Dela Gothic One", "Noto Sans JP", "Noto Sans KR", "Noto Sans SC", sans-serif; font-weight: 900; }
:lang(ja) .ui, :lang(ko) .ui, :lang(zh) .ui { font-family: "Zen Maru Gothic", "Noto Sans JP", "Noto Sans KR", "Noto Sans SC", sans-serif; }
:lang(de) .bal .tx, :lang(nl) .bal .tx, :lang(pl) .bal .tx { hyphens: auto; -webkit-hyphens: auto; }

/* ---------- end of chapter card ---------- */
#nextcard { position: fixed; inset: 0; z-index: 60; display: none; place-items: center; background: rgba(8,6,12,.72); backdrop-filter: blur(4px); }
#nextcard.on { display: grid; }
#nextcard .nc-box { position: relative; max-width: 440px; margin: 20px; padding: 30px 28px 26px; border-radius: 18px; text-align: center;
  background: #17141f; color: #f4efe4; border: 1px solid rgba(232,184,74,.4); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
#nextcard h3 { margin: 0 0 10px; font: 900 24px Cinzel, serif; color: #e8b84a; }
#nextcard p { margin: 0 0 22px; line-height: 1.5; opacity: .88; }
#nextcard .nc-btn { display: inline-block; padding: 14px 26px; border-radius: 999px; background: linear-gradient(120deg, #e8b84a, #e6283c);
  color: #fff; font-weight: 700; text-decoration: none; }
#nextcard .nc-back { position: absolute; top: 10px; right: 12px; background: none; border: 0; color: #aaa; font-size: 18px; cursor: pointer; }
