* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; background: #0b0a0d; overflow: hidden; }
body { font-family: "Noto Serif TC", "Songti TC", "PMingLiU", "PingFang TC", "Microsoft JhengHei", serif; color: #fbf3e8;
  -webkit-user-select: none; user-select: none; }
button { font-family: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

#stage { position: absolute; overflow: hidden; background: linear-gradient(#3b2a22, #1a1316); }
.layer { position: absolute; inset: 0; }

/* ───────── 背景 ───────── */
.bg { background-size: cover; background-position: center; opacity: 0; transition: opacity .9s ease, filter .9s ease; }
.bg.on { opacity: 1; }
.bg::after { content: ""; position: absolute; inset: 0; opacity: 0; transition: opacity .9s ease; pointer-events: none;
  background: linear-gradient(rgba(34, 48, 120, .5), rgba(14, 18, 60, .55)); mix-blend-mode: multiply; }
.bg.night { filter: brightness(.62) saturate(.78); }
.bg.night::after { opacity: 1; }
#vignette { z-index: 2; pointer-events: none; background: radial-gradient(ellipse at 50% 40%, rgba(0,0,0,0) 55%, rgba(0,0,0,.45) 100%), linear-gradient(to bottom, rgba(0,0,0,0) 55%, rgba(10,6,4,.55) 100%); }

/* ───────── 角色立繪（兩層交叉淡入切換表情） ───────── */
#chars { z-index: 3; pointer-events: none; }
.char { position: absolute; bottom: 0; height: 74%; aspect-ratio: 1 / 2; left: 50%; transform: translateX(-50%) translateY(3%); opacity: 0;
  transition: opacity .45s ease, left .5s ease, filter .3s ease, transform .45s ease, height .5s ease; }
.char.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.char.speak { z-index: 2; }
.char.dim { filter: brightness(.62) saturate(.82); }
#chars.night .char { filter: brightness(.8) saturate(.85); }
#chars.night .char.dim { filter: brightness(.52) saturate(.72); }
.char .fxw, .char .bob { position: absolute; inset: 0; }
.char .bob { transform-origin: 50% 100%; animation: breathe 4.6s ease-in-out infinite; filter: drop-shadow(0 0 1.1em rgba(0,0,0,.35)); }
.char.speak .bob { animation: breathe 4.6s ease-in-out infinite, speakbob 2.2s ease-in-out infinite; }
.char .spr { position: absolute; inset: 0; background-repeat: no-repeat; background-position: center bottom; background-size: contain;
  opacity: 0; z-index: 1; transition: opacity .2s ease .12s; }
.char .spr.on { opacity: 1; z-index: 2; transition: opacity .26s ease; }
.char .spr.cut { transition: none !important; }
@keyframes breathe { 0%,100% { scale: 1 1; } 50% { scale: 1.004 1.01; } }
@keyframes speakbob { 0%,100% { translate: 0 0; } 50% { translate: 0 -0.7%; } }
.fxw.jump { animation: cjump .55s ease-out; }
.fxw.shake { animation: cshake .55s ease-in-out; }
@keyframes cjump { 0% { transform: translateY(0); } 28% { transform: translateY(-4.5%); } 55% { transform: translateY(0); } 76% { transform: translateY(-1.6%); } 100% { transform: translateY(0); } }
@keyframes cshake { 0%,100% { transform: translateX(0); } 14% { transform: translateX(-3.5%); } 30% { transform: translateX(3.5%); } 46% { transform: translateX(-2.2%); } 62% { transform: translateX(2.2%); } 80% { transform: translateX(-1%); } }

/* ───────── 特效 ───────── */
#fx { pointer-events: none; z-index: 5; }
.vfx { position: absolute; transform: translate(-50%, -50%); background-repeat: no-repeat; mix-blend-mode: screen; pointer-events: none; }
.floattxt { position: absolute; transform: translate(-50%, 0); font-weight: 700; font-size: 1.15em; color: #ffd6e2;
  text-shadow: 0 0 .6em rgba(255,90,140,.9), 0 2px 3px rgba(0,0,0,.6); animation: floatup 1.6s ease-out forwards; white-space: nowrap; }
@keyframes floatup { from { opacity: 0; margin-top: 0; } 15% { opacity: 1; } to { opacity: 0; margin-top: -3.5em; } }
.fallheart { position: absolute; color: #ff9fbd; text-shadow: 0 0 .5em #ff5c8f; animation: heartup 1.2s ease-out forwards; font-size: 1.6em; }
@keyframes heartup { from { opacity: 1; transform: translate(-50%,0) scale(.6); } to { opacity: 0; transform: translate(-50%,-4em) scale(1.3); } }

/* ───────── 好感度 HUD ───────── */
#hud { position: absolute; top: .8em; left: .8em; z-index: 6; display: grid; grid-template-columns: auto auto; gap: .32em .35em; pointer-events: none; }
.meter { display: flex; visibility: hidden; opacity: 0; align-items: center; gap: .45em; background: rgba(20,14,18,.58); border: 1px solid rgba(255,220,180,.25);
  border-radius: 2em; padding: .25em .65em; font-size: .72em; backdrop-filter: blur(4px); transition: opacity .6s ease; }
.meter.on { visibility: visible; opacity: 1; }
.meter .mn { min-width: 4.3em; letter-spacing: .04em; white-space: nowrap; }
.meter .bar { width: 4.4em; height: .45em; border-radius: 1em; background: rgba(255,255,255,.15); overflow: hidden; }
.meter .bar i { display: block; height: 100%; width: 0; border-radius: 1em; transition: width .8s ease; }
.meter .mn::before { content: "♥ "; }
#m_emma .bar i { background: linear-gradient(90deg, #ff9db8, #ffd1dc); }
#m_lucas .bar i { background: linear-gradient(90deg, #6fa8ff, #bcd8ff); }
#m_sofia .bar i { background: linear-gradient(90deg, #ff9a5c, #ffd0a8); }
#m_ethan .bar i { background: linear-gradient(90deg, #9d8cff, #d4ccff); }
#m_emma .mn::before { color: #ff9db8; }
#m_lucas .mn::before { color: #8fbcff; }
#m_sofia .mn::before { color: #ffa36b; }
#m_ethan .mn::before { color: #b3a6ff; }

.iconbtn { position: absolute; top: .7em; right: .8em; z-index: 7; width: 2.4em; height: 2.4em; border-radius: 50%;
  background: rgba(20,14,18,.55); border: 1px solid rgba(255,220,180,.4); font-size: 1em; display: none; }

/* ───────── 對話框（貼近畫面底部） ───────── */
#textbox { position: absolute; left: 3.5%; right: 3.5%; bottom: 2.4em; min-height: 8.6em; z-index: 6; padding: 1.55em 1.2em 1.3em;
  background: linear-gradient(rgba(28,20,24,.8), rgba(16,11,14,.9)); border: 1px solid rgba(255,214,170,.35); border-radius: .9em;
  box-shadow: 0 .6em 2em rgba(0,0,0,.5); display: none; cursor: pointer; backdrop-filter: blur(6px); }
#stage.touch #textbox { bottom: max(1em, env(safe-area-inset-bottom)); }
#textbox.narr { background: linear-gradient(rgba(12,10,14,.72), rgba(8,6,10,.82)); }
#nametag { position: absolute; top: -1em; left: 1em; padding: .25em 1em; border-radius: .4em; font-weight: 700; font-size: .95em;
  background: #c9874a; color: #1d120c; letter-spacing: .08em; box-shadow: 0 .2em .6em rgba(0,0,0,.4); display: none; }
#tbTools { position: absolute; top: -1.05em; right: .9em; display: flex; gap: .4em; }
.tbtn { font-size: .72em; padding: .32em .85em; border-radius: 2em; background: rgba(28,20,24,.94); border: 1px solid rgba(255,214,170,.45);
  color: #f6e3c8; letter-spacing: .1em; box-shadow: 0 .2em .5em rgba(0,0,0,.35); transition: background .15s, color .15s; white-space: nowrap; }
#stage.touch .tbtn { font-size: .78em; padding: .42em 1em; }
.tbtn.on { background: #c9874a; color: #1d120c; border-color: #ffe0b8; }
.tbtn.on::before { content: "▶ "; font-size: .8em; }
#ffBtn.on::before { content: "▶▶ "; }
#text { font-size: 1.02em; line-height: 1.75; letter-spacing: .03em; white-space: pre-wrap; }
#textbox.narr #text { color: #efe4d4; }
#cont { position: absolute; right: 1em; bottom: .5em; font-size: .75em; color: #f0c48a; opacity: 0; animation: blink 1s infinite; }
#cont.on { opacity: 1; }
@keyframes blink { 50% { opacity: .2; } }
#hintline { position: absolute; left: 4%; right: 4%; bottom: .75em; z-index: 6; text-align: center; font-size: .6em;
  color: rgba(255,240,220,.55); display: none; pointer-events: none; }

/* ───────── 選項 ───────── */
#choices { position: absolute; inset: 0; z-index: 8; display: none; flex-direction: column; justify-content: center; align-items: center;
  gap: .8em; padding: 0 8%; background: rgba(8,5,8,.5); }
#choices.on { display: flex; }
#choices button, .panel button { width: 100%; padding: .9em 1em; font-size: 1em; line-height: 1.45; border-radius: .7em;
  background: rgba(30,20,22,.86); border: 1px solid rgba(255,214,170,.45); color: #fbf0e2; letter-spacing: .03em;
  box-shadow: 0 .3em 1.2em rgba(0,0,0,.4); transition: transform .12s, background .12s, border-color .12s; }
#choices button.sel, .panel button.sel { background: rgba(201,135,74,.9); color: #1b100a; border-color: #ffe0b8; transform: scale(1.03); }
@media (hover: hover) { #choices button:hover, .panel button:hover { background: rgba(201,135,74,.88); color: #1b100a; } }
#choices button { animation: popin .35s ease both; }
#choices button:nth-child(2) { animation-delay: .07s; }
#choices button:nth-child(3) { animation-delay: .14s; }
#choices button:nth-child(4) { animation-delay: .21s; }
@keyframes popin { from { opacity: 0; transform: translateY(.8em); } }
.choicehint { font-size: .7em; color: rgba(255,230,200,.75); letter-spacing: .1em; margin-bottom: .2em; }

/* ───────── 章節標題 ───────── */
#chapter { position: absolute; inset: 0; z-index: 9; display: none; flex-direction: column; justify-content: center; align-items: center;
  background: rgba(10,7,9,.9); cursor: pointer; }
#chapter.on { display: flex; animation: fadein .6s ease; }
#chapter .ch { font-size: 1em; letter-spacing: .6em; color: #e7b47c; margin-bottom: .6em; }
#chapter .sub { font-size: 1.8em; letter-spacing: .15em; }
#chapter .sub::after { content: ""; display: block; width: 3em; height: 1px; background: #e7b47c; margin: .7em auto 0; }
@keyframes fadein { from { opacity: 0; } }

/* ───────── 標題畫面 ───────── */
#title { position: absolute; inset: 0; z-index: 20; cursor: pointer; }
#title .tbg { position: absolute; inset: 0; background: #2a1d17 center/cover no-repeat; animation: slowzoom 30s ease-in-out infinite alternate; }
@keyframes slowzoom { to { transform: scale(1.08); } }
#title::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(0,0,0,.05) 35%, rgba(12,7,5,.88) 100%); }
#title .tcontent { position: absolute; left: 0; right: 0; bottom: 15%; text-align: center; z-index: 1; padding: 0 6%; }
#title .eyebrow { font-size: .7em; letter-spacing: .45em; color: #f2c58e; margin-bottom: .5em; }
#title h1 { font-size: 2.3em; letter-spacing: .12em; font-weight: 700; text-shadow: 0 .1em 1em rgba(0,0,0,.7); }
#title .tag { margin-top: .6em; font-size: .85em; color: #ecdcc8; }
#title .tag2 { margin-top: .55em; font-size: .7em; letter-spacing: .18em; color: #f2c58e; }
#startHint { margin-top: 2em; font-size: 1em; color: #ffe6c4; }
.pulse { animation: blink 1.6s infinite; }
.keys { margin-top: 1.1em; font-size: .6em; color: rgba(255,240,220,.65); line-height: 1.75; white-space: pre-line; }

/* ───────── 開場影片 ───────── */
#videoWrap { position: absolute; inset: 0; z-index: 25; background: #000; display: none; }
#videoWrap.on { display: block; }
#videoWrap video { width: 100%; height: 100%; object-fit: cover; }
#videoCaption { position: absolute; left: 6%; right: 6%; bottom: 20%; text-align: center; font-size: 1.05em; line-height: 1.7;
  text-shadow: 0 2px 6px rgba(0,0,0,.9); opacity: 0; transition: opacity 1.2s; }
#videoCaption.on { opacity: 1; }
#skipBtn { position: absolute; top: .8em; right: .8em; padding: .5em 1em; border-radius: 2em; font-size: .9em;
  background: rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.5); }

/* ───────── 覆蓋視窗 ───────── */
.overlay { position: absolute; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center; background: rgba(6,4,6,.7); padding: 0 10%; }
.overlay.on { display: flex; animation: fadein .4s ease; }
.panel { width: 100%; background: rgba(24,17,20,.93); border: 1px solid rgba(255,214,170,.35); border-radius: 1em; padding: 1.6em 1.3em;
  display: flex; flex-direction: column; gap: .8em; text-align: center; box-shadow: 0 1em 3em rgba(0,0,0,.6); }
.panel h2 { font-size: 1.4em; letter-spacing: .1em; margin-bottom: .3em; color: #ffe2bf; }

/* 對話紀錄 */
#log { z-index: 31; padding: 0 5%; }
.panel.logpanel { height: 84%; padding: 1em 1em .9em; gap: .55em; text-align: left; }
.loghead { display: flex; align-items: center; justify-content: space-between; padding: 0 .2em; }
.loghead h2 { margin: 0; font-size: 1.2em; }
.panel button.xbtn { width: 2.2em; height: 2.2em; padding: 0; border-radius: 50%; font-size: .95em; flex: none; line-height: 1; }
#logList { flex: 1; min-height: 0; overflow-y: auto; padding: .2em .35em .2em .1em; display: flex; flex-direction: column; gap: .8em;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; border-top: 1px solid rgba(255,214,170,.18); border-bottom: 1px solid rgba(255,214,170,.18); padding-top: .7em; padding-bottom: .7em; }
.le { font-size: .84em; line-height: 1.65; color: #efe4d4; display: flex; gap: .55em; align-items: flex-start; }
.le .lt { flex: 1; min-width: 0; }
.le .ln { display: block; font-weight: 700; font-size: .9em; letter-spacing: .08em; margin-bottom: .05em; }
.le.narr .lt { color: rgba(239,228,212,.72); }
.le.choice .lt { color: #f2b872; font-style: italic; }
.le.choice .lt::before { content: "➤ "; font-style: normal; }
.panel button.vb { width: 2.1em; height: 2.1em; padding: 0; flex: none; border-radius: 50%; font-size: .72em; margin-top: .25em; line-height: 1; box-shadow: none; }
.loghint { font-size: .64em; color: rgba(255,235,210,.55); text-align: center; }

/* 結局卡 */
.endsmall { font-size: .7em; letter-spacing: .5em; color: #e7b47c; }
#endStats { display: grid; grid-template-columns: 1fr 1fr; gap: .35em .8em; font-size: .86em; color: #efe1cf; }
#endStats .es { background: rgba(255,255,255,.05); border-radius: .5em; padding: .3em .5em; }
#endStats .es b { margin-left: .3em; }
#endCount { font-size: .8em; color: #ffd9a8; letter-spacing: .08em; }
#endNote { font-size: .74em; color: rgba(255,235,210,.72); line-height: 1.6; margin-bottom: .3em; }
#endcard { background: linear-gradient(rgba(6,4,6,.1), rgba(6,4,6,.78)); align-items: flex-end; padding-bottom: 18%; }
