:root {
  --iris: #566FAD;
  --navy: #23374D;
  --ink: #292827;
  --bronze: #90754B;
  --paper: #E5DFD3;
  --serif: 'Noto Serif TC', 'PT Serif', serif;
  --hand: 'LXGW WenKai TC', 'Noto Serif TC', serif;
  --type: 'Special Elite', 'Noto Serif TC', monospace;
}
* { box-sizing: border-box; }
:root { --vw: 1vw; --vh: 1vh; }
#app { position: fixed; top: 0; left: 0; width: calc(100 * var(--vw)); height: calc(100 * var(--vh)); overflow: hidden; }
html.rot #app { transform-origin: top left; transform: rotate(90deg) translateY(-100%); }
html, body { margin: 0; height: 100%; overflow: hidden; background: #050506; color: var(--paper); font-family: var(--serif); -webkit-tap-highlight-color: transparent; user-select: none; }
button { font-family: inherit; cursor: var(--cur-pointer); }
.hidden { display: none !important; }

#stage { position: fixed; inset: 0; transition: filter 3s ease; }
#stage canvas { display: block; width: 100%; height: 100%; }
#fade { position: fixed; inset: 0; background: #000; opacity: 1; pointer-events: none; transition: opacity 1.6s ease; z-index: 5; }

/* 地點字幕 */
#caption { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); text-align: center; z-index: 6; pointer-events: none; text-shadow: 0 2px 18px #000; }
#caption div { opacity: 0; animation: capIn 3.6s ease forwards; letter-spacing: .3em; }
#caption div:first-child { font-size: clamp(18px, calc(2.4 * var(--vw)), 30px); font-weight: 600; }
#caption div:nth-child(2) { font-size: clamp(13px, calc(1.4 * var(--vw)), 17px); margin-top: .8em; color: #c9c1b2; animation-delay: .5s; }
@keyframes capIn { 0% { opacity: 0; filter: blur(4px); } 25%, 75% { opacity: 1; filter: none; } 100% { opacity: 0; } }

/* 章節卡 */
#chapter { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 7; cursor: var(--cur-pointer); }
#chapter .c1 { font-size: clamp(14px, calc(1.5 * var(--vw)), 18px); letter-spacing: .6em; color: var(--iris); }
#chapter .c2 { font-size: clamp(26px, calc(4 * var(--vw)), 52px); font-weight: 900; margin: .4em 0; letter-spacing: .12em; }
#chapter .c3 { font-family: var(--type); color: #8d877c; letter-spacing: .3em; }
#chapter > * { opacity: 0; animation: fadeUp 1.4s ease forwards; }
#chapter .c2 { animation-delay: .4s; } #chapter .c3 { animation-delay: .9s; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 對話框：卷宗紙感 */
#dialog {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(1040px, calc(100% - 24px)); min-height: 150px; z-index: 20; cursor: var(--cur-pointer);
  background: linear-gradient(180deg, rgba(14,16,22,.86), rgba(8,9,12,.93));
  border: 1px solid rgba(144,117,75,.45); border-radius: 3px;
  box-shadow: 0 10px 40px rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.6);
  padding: 30px 34px 26px;
}
#dialog::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--iris); opacity: .8; }
#dialog .name {
  position: absolute; top: -15px; left: 26px; padding: 4px 16px 5px; font-weight: 600; letter-spacing: .2em; font-size: 15px;
  background: var(--navy); border: 1px solid rgba(144,117,75,.6); color: #efe8da;
}
#dialog .name:empty { display: none; }
#dialog .text { font-size: clamp(16px, calc(1.55 * var(--vw)), 20px); line-height: 1.85; letter-spacing: .04em; white-space: pre-wrap; }
#dialog.narr .text { color: #cfc8ba; font-style: normal; }
#dialog.dark { background: transparent; border-color: transparent; box-shadow: none; }
#dialog.dark::before { display: none; }
#dialog .next { position: absolute; right: 20px; bottom: 12px; font-size: 12px; color: var(--bronze); animation: blink 1.2s infinite; }
#dialog.typing .next { visibility: hidden; }
@keyframes blink { 50% { opacity: .2; } }

/* 選項 */
#choices { position: fixed; left: 50%; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 180px); transform: translateX(-50%); width: min(620px, calc(100% - 40px)); z-index: 21; display: flex; flex-direction: column; gap: 10px; }
#choices button {
  text-align: left; padding: 14px 22px; font-size: clamp(15px, calc(1.4 * var(--vw)), 18px); color: #efe8da; letter-spacing: .05em;
  background: rgba(20,24,34,.88); border: 1px solid rgba(86,111,173,.5); border-radius: 2px;
  transition: background .2s, border-color .2s, transform .2s; animation: fadeUp .4s ease both;
}
#choices button:nth-child(2) { animation-delay: .08s; } #choices button:nth-child(3) { animation-delay: .16s; }
#choices button:hover, #choices button:focus-visible { background: rgba(35,55,77,.95); border-color: var(--iris); transform: translateX(4px); outline: none; }
#choices button .k { color: var(--bronze); font-family: var(--type); margin-right: 12px; font-size: .85em; }

/* 疊加層 */
.overlay { position: fixed; inset: 0; overflow-y: auto; overscroll-behavior: contain; z-index: 30; display: flex; align-items: center; justify-content: center; background: rgba(3,4,6,.72); backdrop-filter: blur(3px); animation: ovIn .35s ease; }
@keyframes ovIn { from { opacity: 0; } }

/* 道具檢視 */
#prop { cursor: var(--cur-pointer); flex-direction: column; }
.prop-body { width: min(820px, calc(92 * var(--vw))); display: flex; justify-content: center; animation: propIn .5s ease; }
@keyframes propIn { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.prop-hint { margin-top: 18px; font-size: 13px; color: #8d877c; letter-spacing: .3em; }

.ticket { position: relative; width: 100%; aspect-ratio: 1536 / 1024; filter: drop-shadow(0 18px 30px rgba(0,0,0,.6)); }
.ticket img { width: 100%; height: 100%; display: block; }
.ticket .print { position: absolute; left: 13%; top: 23%; width: 50%; transform: rotate(-8deg); font-family: var(--type); color: rgba(60,40,25,.78); text-align: center; line-height: 1.5; font-size: clamp(11px, calc(2.1 * var(--vw)), 22px); }
.ticket .print .big { font-size: 1.35em; letter-spacing: .06em; }
.ticket .print .rule { border-top: 1px dashed rgba(60,40,25,.5); margin: .4em 8%; }
.ticket.old .print { color: rgba(70,48,28,.55); filter: blur(.3px); }

.ticket-crop { position: relative; width: min(640px, calc(88 * var(--vw))); aspect-ratio: 955 / 635; overflow: hidden; filter: drop-shadow(0 18px 30px rgba(0,0,0,.6)); clip-path: inset(2% 1% 2% 1% round 10px); }
.ticket-crop img { position: absolute; width: 160.8%; left: -11%; top: -11.8%; }
.ticket-crop.new img { filter: saturate(.75) brightness(1.15) contrast(.95); }
.ticket-crop.back img { filter: brightness(.95) saturate(.85); }
.ticket-crop .print { position: absolute; inset: 14% 6% 10%; transform: rotate(-8deg); font-family: var(--type); color: rgba(50,32,20,.85); text-align: center; line-height: 1.6; font-size: clamp(12px, calc(2.6 * var(--vw)), 24px); display: flex; flex-direction: column; justify-content: center; }
.ticket-crop .print .big { font-size: 1.3em; }
.ticket-crop .print .rule { border-top: 1px dashed rgba(50,32,20,.5); margin: .3em 10%; }
.ticket-crop .pencil { position: absolute; left: 22%; top: 38%; transform: rotate(7deg); font-family: 'Marck Script', cursive; font-size: clamp(30px, calc(6 * var(--vw)), 58px); color: rgba(60,60,66,.75); }
.ticket-crop .pencil .rest { opacity: .2; filter: blur(2.2px); }

.paper {
  position: relative; width: min(560px, calc(90 * var(--vw))); padding: 44px 46px 40px; color: #2a2620; transform: rotate(-1.2deg);
  background: #e9e1cf linear-gradient(transparent 0 0); box-shadow: 0 20px 40px rgba(0,0,0,.6);
  background-image: radial-gradient(circle at 20% 15%, rgba(120,90,50,.12), transparent 40%), radial-gradient(circle at 85% 90%, rgba(120,90,50,.18), transparent 45%);
}
.paper.note { font-family: var(--hand); font-size: clamp(17px, calc(2.2 * var(--vw)), 22px); line-height: 2.1; background-color: #ece5d3;
  background-image: repeating-linear-gradient(transparent 0 calc(2.1em - 1px), rgba(86,111,173,.25) calc(2.1em - 1px) 2.1em), radial-gradient(circle at 85% 90%, rgba(120,90,50,.18), transparent 45%); }
.paper.note .u2 { border-bottom: 3px double rgba(40,36,30,.7); }
.paper.note .indent { padding-left: 1.5em; }
.paper.tele { font-family: var(--type); font-size: clamp(15px, calc(1.9 * var(--vw)), 19px); line-height: 1.9; transform: rotate(.8deg); background-color: #ddd3bd; }
.paper.tele .head { font-size: 1.3em; letter-spacing: .4em; text-align: center; border-bottom: 2px solid rgba(40,36,30,.6); padding-bottom: 6px; margin-bottom: 18px; }
.paper.tele .strip { background: rgba(255,255,255,.55); padding: 2px 8px; box-shadow: 0 1px 0 rgba(0,0,0,.08); display: inline; line-height: 2.3; font-family: 'Noto Serif TC', serif; letter-spacing: .08em; }

/* 搜查 */
.search-box { width: min(760px, calc(94 * var(--vw))); max-height: calc(calc(100 * var(--vh)) - 32px); overflow-y: auto; overscroll-behavior: contain; padding: 30px; background: rgba(12,14,19,.94); border: 1px solid rgba(144,117,75,.4); }
.search-title { font-size: 22px; font-weight: 600; letter-spacing: .2em; }
.search-sub { color: #8d877c; margin: 6px 0 20px; font-size: 14px; }
.search-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.search-grid button { position: relative; padding: 18px 16px; text-align: left; color: var(--paper); background: rgba(35,55,77,.35); border: 1px solid rgba(86,111,173,.45); transition: background .2s, transform .2s; }
.search-grid button:hover { background: rgba(35,55,77,.75); transform: translateY(-2px); }
.search-grid button .l { font-size: 17px; font-weight: 600; letter-spacing: .1em; }
.search-grid button .h { font-size: 13px; color: #9d968a; margin-top: 6px; }
.search-grid button.done { opacity: .55; }
.search-grid button.done::after { content: '已查看'; position: absolute; top: 8px; right: 10px; font-size: 11px; color: var(--bronze); letter-spacing: .15em; }
.search-done { margin-top: 20px; width: 100%; padding: 14px; font-size: 16px; letter-spacing: .3em; color: #fff; background: var(--navy); border: 1px solid var(--iris); }
.search-done:disabled { opacity: .4; cursor: var(--cur-no); }

/* 命名 */
#naming { overflow-y: auto; overflow-x: hidden; }
.naming-box { width: min(980px, calc(94 * var(--vw))); display: flex; flex-direction: column; align-items: center; gap: 18px; margin: auto; padding: 16px 0; }
.idbook { position: relative; width: min(820px, calc(94 * var(--vw))); aspect-ratio: 1774 / 887; filter: drop-shadow(0 20px 30px rgba(0,0,0,.6)); }
.idbook img { width: 100%; height: 100%; display: block; }
.id-photo { position: absolute; left: 8%; top: 24.2%; width: 13.3%; height: 37.5%; overflow: hidden; }
.id-photo .stain { position: absolute; inset: -10%; background: radial-gradient(ellipse at 45% 50%, rgba(70,60,55,.75), rgba(90,75,60,.45) 45%, rgba(120,95,70,.15) 70%, transparent 80%); filter: blur(6px); }
.id-label { position: absolute; left: 56%; font-family: 'PT Serif', serif; font-size: clamp(7px, calc(1.05 * var(--vw)), 12px); letter-spacing: .12em; color: rgba(70,50,40,.7); }
.id-label.l1 { top: 25%; } .id-label.l2 { top: 47%; } .id-label.l3 { top: 63%; }
.id-name, .id-sex, .id-line { position: absolute; left: 56%; width: 37%; border-bottom: 1px solid rgba(70,50,40,.45); height: 10%; display: flex; align-items: flex-end; padding: 0 2% 1%; }
.id-name { top: 30%; } .id-sex { top: 52%; width: 12%; } .id-line.l3v { top: 68%; font-family: 'PT Serif'; color: rgba(70,50,40,.35); font-size: clamp(8px, calc(1.2 * var(--vw)), 14px); }
.id-name .ink, .id-sex .ink { font-family: var(--hand); color: #1f2c4a; font-size: clamp(14px, calc(2.6 * var(--vw)), 30px); opacity: 0; transition: opacity 1.8s ease, filter 1.8s ease; filter: blur(4px); white-space: nowrap; }
.id-name .stain { position: absolute; left: -6%; right: -6%; top: -60%; bottom: -40%; background: radial-gradient(ellipse at 40% 55%, rgba(30,40,70,.55), rgba(60,60,80,.3) 40%, rgba(120,100,80,.12) 65%, transparent 75%); filter: blur(5px); transition: opacity 2.2s ease; }
.idbook.revealed .ink { opacity: 1; filter: none; }
.idbook.revealed .id-name .stain { opacity: .25; }
.naming-form { width: min(520px, calc(92 * var(--vw))); display: flex; flex-direction: column; gap: 12px; padding: 22px 24px; background: rgba(12,14,19,.94); border: 1px solid rgba(144,117,75,.4); }
.naming-q { font-size: 16px; letter-spacing: .08em; }
.naming-input { font-family: var(--hand); font-size: 22px; padding: 10px 14px; color: #f2ecdf; background: rgba(255,255,255,.05); border: 1px solid rgba(86,111,173,.55); outline: none; user-select: text; }
.naming-input:focus { border-color: var(--iris); background: rgba(255,255,255,.08); }
.naming-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.naming-label { color: #8d877c; font-size: 13px; width: 3em; letter-spacing: .2em; }
.sex { padding: 7px 22px; color: var(--paper); background: transparent; border: 1px solid rgba(86,111,173,.5); font-size: 15px; }
.sex.on { background: var(--navy); border-color: var(--iris); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.chips button { padding: 4px 10px; font-size: 13px; color: #c9c1b2; background: rgba(255,255,255,.04); border: 1px dashed rgba(144,117,75,.5); }
.chips button:hover { color: #fff; border-style: solid; }
.naming-ok { margin-top: 4px; padding: 12px; font-size: 16px; letter-spacing: .25em; color: #fff; background: var(--navy); border: 1px solid var(--iris); }
.naming-ok:disabled { opacity: .4; cursor: var(--cur-no); }
.naming-note { font-size: 12px; color: #7d776c; line-height: 1.6; }
.naming-box.done .naming-form { display: none; }
.naming-box .continue { color: #8d877c; letter-spacing: .3em; font-size: 13px; animation: blink 1.6s infinite; }

/* 結局 */
.end-box { text-align: center; padding: 40px; max-width: 640px; }
.end-title { font-size: clamp(28px, calc(4 * var(--vw)), 48px); font-weight: 900; letter-spacing: .2em; }
#end.bad .end-title { color: #b8b2a6; font-family: var(--type); letter-spacing: .3em; }
#end.clear .end-title { color: var(--paper); }
#end.good .end-title { color: #e6c77e; }
.end-sub { font-size: clamp(16px, calc(2 * var(--vw)), 22px); margin-top: 10px; color: var(--iris); letter-spacing: .3em; }
.end-next { margin-top: 26px; color: #9d968a; line-height: 1.8; }
.end-btns { margin-top: 34px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.end-btns button { padding: 12px 26px; font-size: 15px; letter-spacing: .2em; color: var(--paper); background: rgba(35,55,77,.6); border: 1px solid var(--iris); }
.end-btns button:hover { background: var(--navy); }

/* 標題 */
#title { background: radial-gradient(ellipse at 50% 60%, rgba(35,55,77,.35), rgba(3,4,6,.96) 70%); backdrop-filter: none; z-index: 40; }
.title-box { text-align: center; padding: 20px; }
.title-ru { font-family: 'Marck Script', cursive; font-size: clamp(22px, calc(3 * var(--vw)), 34px); color: var(--bronze); }
#title h1 { font-size: clamp(40px, calc(7 * var(--vw)), 86px); font-weight: 900; letter-spacing: .18em; margin: .15em 0 .2em; text-shadow: 0 4px 30px rgba(0,0,0,.8); }
.title-sub { color: var(--iris); letter-spacing: .4em; font-size: clamp(13px, calc(1.4 * var(--vw)), 16px); }
.title-start { margin-top: 44px; padding: 14px 54px; font-size: 18px; letter-spacing: .5em; color: #fff; background: transparent; border: 1px solid var(--bronze); transition: background .3s; }
.title-start:not(:disabled):hover { background: rgba(144,117,75,.25); }
.title-start:disabled { opacity: .5; cursor: var(--cur-no); }
.title-tip { margin-top: 22px; font-size: 13px; color: #6f695f; letter-spacing: .1em; }

#mute { position: fixed; top: max(12px, env(safe-area-inset-top)); right: 14px; z-index: 50; width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(144,117,75,.5); background: rgba(8,9,12,.6); color: var(--paper); font-size: 17px; }
#mute.off { opacity: .45; text-decoration: line-through; }

@media (max-width: 640px) {
  #dialog { padding: 26px 20px 22px; min-height: 130px; }
  #choices { bottom: calc(max(18px, env(safe-area-inset-bottom)) + 155px); }
  .paper { padding: 30px 26px; }
}

/* 內容比畫面高時可以捲動（auto 邊距讓置中的內容不會被切掉上半） */
.overlay > * { margin-block: auto; flex-shrink: 0; }

/* 矮螢幕（手機橫拿） */
html.short #dialog { min-height: 92px; padding: 18px 24px 14px; }
html.short #dialog .text { font-size: 15px; line-height: 1.65; }
html.short #dialog .name { top: -13px; font-size: 13px; padding: 3px 12px 4px; }
html.short #choices { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 118px); max-height: calc(100 * var(--vh) - 140px); overflow-y: auto; overflow-x: hidden; gap: 6px; }
html.short #choices button { padding: 9px 16px; font-size: 14px; }
html.short .search-box { padding: 18px 20px; }
html.short .search-grid button { padding: 12px 14px; }
html.short .title-start { margin-top: 22px; }
html.short .title-tip { margin-top: 12px; }
html.short .paper { padding: 22px 22px; }

/* 道具文件：俄文原文／翻譯切換 */
.prop-lang { display: block; margin: 14px auto 0; padding: 6px 18px; font-size: 13px; letter-spacing: .15em; color: var(--paper); background: rgba(8,9,12,.7); border: 1px solid var(--bronze); border-radius: 16px; font-family: inherit; }
.prop-lang:hover { background: rgba(35,55,77,.9); }
.paper.ru { font-family: 'PT Serif', var(--serif); letter-spacing: .02em; }
.paper .mono { font-family: 'Special Elite', monospace; letter-spacing: .12em; }
