/* 云海回声 — galgame UI. The whole game is laid out in a fixed 1920x1080 box
   (#game) that is scaled to fit the window by engine.js (letterboxed). */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
body { font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif; color: #f3f6fa; }
button { font: inherit; cursor: pointer; }

#game { position: absolute; left: 50%; top: 50%; width: 1920px; height: 1080px; transform-origin: 0 0; overflow: hidden; background: #000; }
#stage { position: absolute; inset: 0; overflow: hidden; z-index: 0; } /* own stacking context: sprite z-index (1/2) must never rise above #textbox/#choices */
#stage.shake { animation: shake .5s cubic-bezier(.36,.07,.19,.97); }
@keyframes shake { 10%,90%{transform:translate(-4px,2px)} 20%,80%{transform:translate(8px,-4px)} 30%,50%,70%{transform:translate(-14px,6px)} 40%,60%{transform:translate(14px,-6px)} }

/* ---------- background (two layers for cross-fade) ---------- */
#bg, .bgl { position: absolute; inset: 0; }
.bgl { background-size: cover; background-position: center; opacity: 0; transition: opacity .9s ease; }
.bgl.on { opacity: 1; }
.bgl.placeholder { display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg,#2b3c55,#11192a); }
.bgl.placeholder::after { content: attr(data-label); font-size: 40px; color: rgba(255,255,255,.35); letter-spacing: .2em; border: 2px dashed rgba(255,255,255,.25); padding: 30px 60px; border-radius: 16px; }

/* ---------- characters ---------- */
#chars { position: absolute; inset: 0; pointer-events: none; }
.ch { position: absolute; bottom: 0; height: 1060px; transform: translateX(-50%); transition: left .6s cubic-bezier(.3,.8,.3,1), opacity .45s ease, filter .35s ease, transform .45s ease; will-change: left, opacity; }
.ch img { position: absolute; bottom: 0; left: 50%; height: 100%; transform: translateX(-50%); transition: opacity .25s ease; filter: drop-shadow(0 0 18px rgba(0,0,0,.25)); }
.ch img.old { opacity: 0; }
.ch.dim { filter: brightness(.68) saturate(.8); }
.ch.enter-fade { opacity: 0; }
.ch.enter-slide-l { opacity: 0; transform: translateX(calc(-50% - 120px)); }
.ch.enter-slide-r { opacity: 0; transform: translateX(calc(-50% + 120px)); }
.ch.enter-pop { opacity: 0; transform: translateX(-50%) scale(.92); }
.ch.bounce { animation: bounce .45s ease; }
@keyframes bounce { 0%,100%{margin-bottom:0} 35%{margin-bottom:46px} 65%{margin-bottom:-6px} }
.ch.speaking { animation: breathe 3.2s ease-in-out infinite; }
@keyframes breathe { 0%,100%{margin-bottom:0} 50%{margin-bottom:5px} }
/* placeholder silhouette for characters without art */
.ch .ph { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 520px; height: 960px; }
.ch .ph svg { width: 100%; height: 100%; }
.ch .ph .phname { position: absolute; left: 0; right: 0; top: 46%; text-align: center; font-size: 38px; font-weight: 700; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
.ch .ph .phnote { position: absolute; left: 0; right: 0; top: 52%; text-align: center; font-size: 22px; color: rgba(255,255,255,.75); }

/* ---------- overlays ---------- */
#weather { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#tint { position: absolute; inset: 0; pointer-events: none; transition: background 1.2s ease, opacity 1.2s ease; mix-blend-mode: multiply; }
#tint.dusk { background: rgba(255,150,90,.28); }
#tint.night { background: rgba(30,50,120,.55); }
#tint.sepia { background: rgba(160,120,70,.55); mix-blend-mode: color; }
#tint.red { background: rgba(200,20,30,.35); animation: alarm 1.4s ease-in-out infinite; }
#tint.green { background: rgba(40,200,120,.30); mix-blend-mode: hard-light; }
#tint.cold { background: rgba(120,160,220,.35); }
@keyframes alarm { 50% { background: rgba(200,20,30,.12); } }
#fx { position: absolute; inset: 0; pointer-events: none; }
#fx.flash { animation: flash .5s ease-out; }
@keyframes flash { 0% { background: rgba(255,255,255,.95); } 100% { background: rgba(255,255,255,0); } }
#fx.whiteout { background: #fff; transition: background 1.2s ease; }
#fx.blackout { background: #000; transition: background 1.2s ease; }
#fx.heartbeat { animation: hb 1.1s ease-in-out 2; }
@keyframes hb { 0%,100%{box-shadow:inset 0 0 0 rgba(160,0,0,0)} 15%{box-shadow:inset 0 0 260px rgba(160,0,0,.75)} 30%{box-shadow:inset 0 0 60px rgba(160,0,0,.2)} 45%{box-shadow:inset 0 0 220px rgba(160,0,0,.6)} }
#fx canvas { position: absolute; inset: 0; }
/* Stage layers: sprites use z-index 1/2 (engine zorder), so every overlay must sit above 2. */
#weather { z-index: 3; } #tint { z-index: 4; } #fx { z-index: 5; } #center { z-index: 6; }
#center { position: absolute; left: 0; right: 0; top: 42%; text-align: center; font-size: 56px; letter-spacing: .3em; font-family: "Songti SC","SimSun","Noto Serif CJK SC",serif; color: #fff; text-shadow: 0 0 24px rgba(0,0,0,.8), 0 0 6px rgba(0,0,0,.9); opacity: 0; transition: opacity .8s ease; pointer-events: none; }
#center.on { opacity: 1; }

/* ---------- rewind effect ---------- */
#stage.rewind { animation: rewind 1.6s ease-in-out; }
@keyframes rewind { 0%{filter:none} 30%{filter:invert(1) hue-rotate(180deg) blur(2px)} 60%{filter:grayscale(1) blur(6px) brightness(1.6)} 100%{filter:none} }
.clockface { position: absolute; left: 50%; top: 50%; width: 700px; height: 700px; margin: -350px 0 0 -350px; border-radius: 50%; border: 6px solid rgba(255,255,255,.8); box-shadow: 0 0 60px rgba(160,200,255,.8), inset 0 0 60px rgba(160,200,255,.6); animation: clockin 1.6s ease forwards; }
.clockface::before, .clockface::after { content: ""; position: absolute; left: 50%; top: 50%; width: 8px; background: #fff; transform-origin: 50% 0; border-radius: 4px; }
.clockface::before { height: 260px; animation: hand 1.6s linear; transform: rotate(180deg); }
.clockface::after { height: 180px; animation: hand 1.6s linear reverse; transform: rotate(90deg); }
@keyframes hand { from{transform:rotate(1260deg)} to{transform:rotate(180deg)} }
@keyframes clockin { 0%{opacity:0;transform:scale(1.6)} 30%{opacity:1;transform:scale(1)} 80%{opacity:1} 100%{opacity:0;transform:scale(.4)} }

/* ---------- text box ---------- */
#textbox { position: absolute; left: 120px; right: 120px; bottom: 26px; height: 270px; border-radius: 22px; background: linear-gradient(180deg, rgba(18,32,54,.80), rgba(10,18,32,.88)); border: 2px solid rgba(190,164,113,.55); box-shadow: 0 10px 40px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.06); padding: 54px 80px 40px; transition: opacity .3s ease; }
#textbox.hidden { opacity: 0; pointer-events: none; }
#namebox { position: absolute; left: 50px; top: -30px; min-width: 200px; padding: 8px 36px; font-size: 34px; font-weight: 700; border-radius: 14px; background: linear-gradient(180deg,#24456e,#152e43); border: 2px solid rgba(190,164,113,.8); box-shadow: 0 4px 14px rgba(0,0,0,.4); text-align: center; letter-spacing: .06em; }
#namebox:empty { display: none; }
#text { font-size: 36px; line-height: 1.65; letter-spacing: .04em; text-shadow: 0 2px 4px rgba(0,0,0,.6); min-height: 120px; }
#text.think { color: #b9cce4; font-style: italic; }
#text.narr { color: #f0ece2; }
#next-ind { position: absolute; right: 50px; bottom: 50px; font-size: 26px; color: #bea471; animation: blink 1s ease-in-out infinite; opacity: 0; }
#next-ind.on { opacity: 1; }
@keyframes blink { 50% { transform: translateY(6px); opacity: .4; } }
#quick { position: absolute; right: 36px; bottom: 8px; display: flex; gap: 6px; }
#quick button { background: none; border: 0; color: rgba(255,255,255,.6); font-size: 22px; padding: 4px 10px; border-radius: 8px; }
#quick button:hover, #quick button.on { color: #ffd98a; background: rgba(255,255,255,.08); }

/* ---------- choices ---------- */
#choices { position: absolute; inset: 0 0 300px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; pointer-events: none; }
#choices button { pointer-events: auto; min-width: 900px; max-width: 1300px; padding: 22px 50px; font-size: 34px; color: #fff; background: linear-gradient(90deg, rgba(21,46,67,.0), rgba(21,46,67,.92) 12%, rgba(21,46,67,.92) 88%, rgba(21,46,67,0)); border: 0; border-top: 1px solid rgba(190,164,113,.6); border-bottom: 1px solid rgba(190,164,113,.6); transition: all .2s ease; animation: choicein .4s ease backwards; text-shadow: 0 2px 4px rgba(0,0,0,.6); }
#choices button:nth-child(2) { animation-delay: .07s; } #choices button:nth-child(3) { animation-delay: .14s; } #choices button:nth-child(4) { animation-delay: .21s; }
#choices button:hover, #choices button:focus { background: linear-gradient(90deg, rgba(56,100,119,0), rgba(56,100,119,.95) 12%, rgba(56,100,119,.95) 88%, rgba(56,100,119,0)); color: #ffe7a8; transform: scale(1.03); outline: none; }
#choices button.danger { color: #ffb8b8; }
@keyframes choicein { from { opacity: 0; transform: translateY(16px); } }

/* ---------- tip, chapter card, toast ---------- */
#tip { position: absolute; left: 50%; top: 60px; transform: translate(-50%, -30px); max-width: 1300px; padding: 22px 44px; font-size: 28px; line-height: 1.6; background: rgba(250,244,230,.95); color: #3a2a1a; border-left: 8px solid #bea471; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.4); opacity: 0; transition: all .5s ease; pointer-events: none; }
#tip.on { opacity: 1; transform: translate(-50%, 0); }
#chapter-card { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 50%, rgba(21,46,67,.92), rgba(5,10,18,.98)); opacity: 0; pointer-events: none; transition: opacity .8s ease; font-family: "Songti SC","SimSun","Noto Serif CJK SC",serif; }
#chapter-card.on { opacity: 1; pointer-events: auto; }
#chapter-card .num { font-size: 34px; letter-spacing: .6em; color: #bea471; margin-bottom: 30px; }
#chapter-card .ttl { font-size: 72px; letter-spacing: .18em; color: #fff; text-shadow: 0 0 30px rgba(120,180,255,.5); }
#chapter-card .num::before, #chapter-card .num::after { content: "—"; margin: 0 .5em; opacity: .5; }
#toast { position: absolute; left: 50%; bottom: 330px; transform: translateX(-50%); padding: 12px 34px; border-radius: 30px; background: rgba(0,0,0,.7); font-size: 26px; opacity: 0; transition: opacity .3s; pointer-events: none; }
#toast.on { opacity: 1; }

/* ---------- screens ---------- */
.screen { position: absolute; inset: 0; z-index: 20; }
.screen.hidden, #confirm.hidden { display: none; }
#title .title-bg { position: absolute; inset: 0; background-size: cover; background-position: center; filter: brightness(.85); }
#title .title-bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10,20,36,.85), rgba(10,20,36,.2) 55%, rgba(10,20,36,0)); }
.title-logo { position: absolute; left: 140px; top: 200px; }
.title-logo .t1 { font-family: "Songti SC","SimSun","Noto Serif CJK SC",serif; font-size: 150px; letter-spacing: .14em; font-weight: 700; color: #fff; text-shadow: 0 0 40px rgba(120,180,255,.6), 0 6px 20px rgba(0,0,0,.5); }
.title-logo .t2 { font-size: 30px; letter-spacing: .3em; color: #bea471; margin-top: 10px; }
.title-menu { position: absolute; left: 150px; top: 540px; display: flex; flex-direction: column; gap: 12px; }
.title-menu button { width: 420px; text-align: left; padding: 14px 30px; font-size: 38px; letter-spacing: .2em; color: #eef5f6; background: none; border: 0; border-left: 4px solid transparent; transition: all .2s; text-shadow: 0 2px 6px rgba(0,0,0,.6); }
.title-menu button:hover, .title-menu button:focus { border-left-color: #bea471; color: #ffe7a8; padding-left: 46px; background: linear-gradient(90deg, rgba(190,164,113,.2), transparent); outline: none; }
.title-menu button:disabled { opacity: .35; pointer-events: none; }
.title-foot { position: absolute; right: 60px; bottom: 40px; font-size: 22px; color: rgba(255,255,255,.5); }
#title .title-chars { position: absolute; right: 80px; bottom: 0; height: 1000px; display: flex; align-items: flex-end; }
#title .title-chars img { height: 1000px; margin-left: -200px; filter: drop-shadow(0 0 30px rgba(0,0,0,.4)); }

#panel { background: linear-gradient(180deg, rgba(12,24,40,.97), rgba(6,12,22,.98)); padding: 60px 120px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid rgba(190,164,113,.5); padding-bottom: 20px; margin-bottom: 30px; }
.panel-title { font-size: 52px; letter-spacing: .3em; font-family: "Songti SC","SimSun",serif; color: #bea471; }
.panel-close { font-size: 30px; padding: 10px 40px; color: #fff; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.25); border-radius: 12px; }
.panel-body { height: 860px; overflow-y: auto; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 30px; }
.slot { height: 250px; border-radius: 16px; overflow: hidden; position: relative; border: 2px solid rgba(255,255,255,.15); background: rgba(255,255,255,.04) center/cover; text-align: left; color: #fff; padding: 0; }
.slot:hover { border-color: #bea471; }
.slot .info { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 20px; background: linear-gradient(transparent, rgba(0,0,0,.85)); font-size: 22px; line-height: 1.5; }
.slot .info b { font-size: 26px; color: #ffe7a8; }
.slot.empty .info { top: 0; display: flex; align-items: center; justify-content: center; background: none; color: rgba(255,255,255,.4); font-size: 28px; }
.log-item { padding: 18px 10px; border-bottom: 1px solid rgba(255,255,255,.08); font-size: 30px; line-height: 1.6; }
.log-item .n { color: #bea471; margin-right: 20px; }
.log-item.choice { color: #9fd3ff; }
.cfg-row { display: flex; align-items: center; gap: 40px; font-size: 32px; padding: 22px 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.cfg-row label { width: 360px; }
.cfg-row input[type=range] { width: 600px; height: 40px; }
.cfg-row .opt { padding: 8px 28px; border-radius: 10px; border: 1px solid rgba(255,255,255,.3); background: none; color: #fff; font-size: 28px; }
.cfg-row .opt.on { background: #386477; border-color: #bea471; }
.list-btn { display: block; width: 100%; text-align: left; padding: 24px 30px; margin-bottom: 14px; font-size: 32px; color: #fff; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.12); border-radius: 12px; }
.list-btn:hover { border-color: #bea471; background: rgba(190,164,113,.12); }
.list-btn:disabled { opacity: .35; }
.list-btn small { color: rgba(255,255,255,.55); margin-left: 20px; font-size: 24px; }

#confirm { position: absolute; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; }
#confirm .box { width: 900px; padding: 60px; background: #152e43; border: 2px solid #bea471; border-radius: 20px; text-align: center; }
#confirm .msg { font-size: 34px; line-height: 1.6; margin-bottom: 40px; }
#confirm .btns button { font-size: 30px; padding: 12px 60px; margin: 0 20px; border-radius: 12px; border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.08); color: #fff; }
#confirm .btns .yes { background: #386477; border-color: #bea471; }

/* ending card */
.ending-card { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(0,0,0,.0); animation: endin 2.5s ease forwards; font-family: "Songti SC","SimSun",serif; }
.ending-card .id { font-size: 34px; letter-spacing: .5em; color: #bea471; }
.ending-card .t { font-size: 80px; letter-spacing: .15em; margin: 30px 0 60px; text-shadow: 0 0 30px rgba(160,200,255,.6); }
.ending-card .h { font-size: 26px; color: rgba(255,255,255,.6); font-family: inherit; }
@keyframes endin { to { background: rgba(0,0,0,.92); } }

@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
