/* 山海 · 样式。画面是一卷手卷：上下绫边，右侧竖排题记，底下一排按钮。 */
:root {
  --paper: #efe6d0;
  --ink: #1d1a18;
  --ink2: #5b5247;
  --red: #b83a26;
  --blue: #2a3444;
  --gold: #b8944c;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "楷体", "BiauKai", "Songti SC", "Noto Serif CJK SC", serif;
  --song: "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", serif;
  --sh-layout: desk;
  --panel-w: min(400px, 30vw);
}
@media (max-width: 760px), (max-aspect-ratio: 4/5) { :root { --sh-layout: port; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a3444; color: var(--ink); font-family: var(--kai); }
body { position: fixed; inset: 0; overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
canvas#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
button { font-family: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- 开卷 ---------- */
#title { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20;
  background: radial-gradient(ellipse at 50% 45%, rgba(239,230,208,.90) 0%, rgba(239,230,208,.78) 45%, rgba(226,214,188,.72) 100%);
  transition: opacity 1.4s ease, visibility 1.4s; }
#title.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.tt-inner { text-align: center; padding: 24px; }
#title h1 { margin: 0; font-weight: 400; font-size: clamp(64px, 17vh, 180px); line-height: 1.04; color: var(--ink);
  display: inline-block; text-shadow: 0 0 1px rgba(0,0,0,.5); }
#title h1 span { display: block; animation: rise 1.6s cubic-bezier(.2,.7,.2,1) both; }
#title h1 span:nth-child(2) { animation-delay: .35s; }
.tt-sub { margin: 18px 0 6px; font-size: 22px; letter-spacing: .7em; text-indent: .7em; color: var(--red); animation: rise 1.4s .8s both; }
.tt-line { margin: 0 0 30px; font-size: 16px; letter-spacing: .2em; color: var(--ink2); animation: rise 1.4s 1.1s both; }
.tt-foot { margin: 26px 0 0; font-size: 13px; letter-spacing: .16em; color: var(--ink2); opacity: .8; animation: rise 1.4s 1.6s both; }
#open { font-size: 22px; letter-spacing: .5em; text-indent: .5em; padding: 12px 34px; background: var(--red); color: #f6ecd8; border: 0; border-radius: 3px;
  box-shadow: 0 0 0 3px rgba(184,58,38,.18), 0 6px 18px rgba(80,30,10,.25); animation: rise 1.4s 1.3s both; transition: transform .2s, box-shadow .2s; }
#open:hover { transform: translateY(-1px); box-shadow: 0 0 0 5px rgba(184,58,38,.2), 0 8px 22px rgba(80,30,10,.3); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }

/* ---------- 角上的小印 ---------- */
#mark { position: absolute; left: 22px; top: calc(3.4vh + 16px); display: flex; align-items: center; gap: 10px; z-index: 5; pointer-events: none; opacity: 0; transition: opacity 1.2s .6s; }
body.on #mark { opacity: 1; }
.mk-seal { writing-mode: vertical-rl; background: var(--red); color: #f6ecd8; font-size: 15px; line-height: 1.1; padding: 5px 4px; border-radius: 2px; letter-spacing: .1em; }
.mk-txt { font-size: 13px; letter-spacing: .4em; color: var(--ink2); }

/* ---------- 题记：竖排，自右向左 ---------- */
#scroll { position: absolute; z-index: 6; right: 26px; top: calc(3.4vh + 22px); bottom: calc(3.4vh + 86px); width: calc(var(--panel-w) - 30px);
  display: flex; flex-direction: row-reverse; align-items: flex-start; gap: 14px; pointer-events: none; opacity: 0; transition: opacity 1s .4s; }
body.on #scroll { opacity: 1; }
#src { writing-mode: vertical-rl; font-size: 14px; letter-spacing: .35em; color: var(--ink2); padding-top: 2px; white-space: nowrap; flex: none; }
#src b { font-weight: 400; color: var(--red); }
#text { writing-mode: vertical-rl; font-size: 23px; line-height: 1.86; letter-spacing: .1em; max-height: 100%; flex: 0 1 auto; text-align: start;
  pointer-events: auto; cursor: pointer; }
#text .c { transition: opacity .7s ease, color .7s ease, filter .7s ease; opacity: .13; filter: blur(.6px); }
#text .c.on { opacity: 1; filter: none; }
#text .c.now { color: var(--red); }
#text .c.k-voice.on { color: #27405a; }
#text .c.k-omen.on { color: #8c2c1c; }
#text .c.k-virtue.on, #text .c.k-lore.on, #text .c.k-open.on { color: #5a5146; }
#text .c.k-skip.on { opacity: .42; }
#text .c.k-gap { opacity: .35; }
#text .c.now.on { color: var(--red); }
#tail { writing-mode: vertical-rl; display: flex; align-items: flex-start; gap: 10px; flex: none; align-self: flex-end; }
#seal { display: inline-block; background: var(--red); color: #f8eedb; font-size: 21px; line-height: 1.12; padding: 7px 5px; border-radius: 3px; letter-spacing: .06em;
  opacity: 0; transform: scale(1.5) rotate(-6deg); transition: opacity .25s, transform .35s cubic-bezier(.2,1.6,.4,1);
  box-shadow: inset 0 0 0 1.5px rgba(255,240,215,.55), 0 1px 0 rgba(120,30,15,.4); }
#seal.on { opacity: .94; transform: none; }
#note { font-size: 12px; line-height: 1.6; letter-spacing: .1em; color: var(--ink2); max-height: 15em; opacity: .85; }

/* 入夜后题记换成浅色 */
#text, #src, #note, .mk-txt { transition: color 1.2s ease; }
body.night #text { color: #f1e8d3; }
body.night #text .c.k-voice.on { color: #b9d0ea; }
body.night #text .c.k-omen.on { color: #f0a48f; }
body.night #text .c.k-virtue.on, body.night #text .c.k-lore.on, body.night #text .c.k-open.on { color: #cfc5b2; }
body.night #src, body.night #note, body.night .mk-txt { color: #cfc5b2; }
body.night #src b { color: #f0a48f; }

/* 读到哪一句，解成了什么 */
#tags { position: absolute; z-index: 5; left: 22px; bottom: calc(3.4vh + 78px); display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100vw - var(--panel-w) - 60px);
  pointer-events: none; }
#tags span { font-family: var(--song); font-size: 12px; letter-spacing: .08em; padding: 3px 8px; border: 1px solid rgba(60,50,40,.35); border-radius: 2px; color: var(--ink2);
  background: rgba(239,230,208,.6); animation: tag .5s both; }
#tags span.hot { color: var(--red); border-color: rgba(184,58,38,.55); }
@keyframes tag { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 底栏 ---------- */
#bar { position: absolute; z-index: 8; left: 50%; bottom: calc(3.4vh + 14px); transform: translateX(-50%); display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; background: rgba(34,42,56,.90); border: 1px solid rgba(184,148,76,.55); border-radius: 4px; box-shadow: 0 8px 26px rgba(20,20,30,.3);
  opacity: 0; transition: opacity 1s .8s; }
body.on #bar { opacity: 1; }
#bar button { background: transparent; border: 0; color: #eadfc6; font-size: 17px; letter-spacing: .14em; padding: 7px 12px; border-radius: 3px; white-space: nowrap; transition: background .2s, color .2s; }
#bar button:hover, #bar button.on { background: rgba(184,148,76,.22); color: #fff3d6; }
#bar button[data-act=prev], #bar button[data-act=next] { font-size: 22px; padding: 2px 10px 6px; letter-spacing: 0; }
#bar button.off { opacity: .45; }
#bar i { width: 1px; height: 20px; background: rgba(184,148,76,.4); margin: 0 3px; }

/* ---------- 面板 ---------- */
.panel { position: absolute; z-index: 30; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(960px, 92vw); max-height: 88vh; display: flex; flex-direction: column;
  background: #f1e8d3; border: 1px solid #8f7b55; outline: 4px solid rgba(241,232,211,.9); box-shadow: 0 0 0 5px #8f7b55, 0 24px 70px rgba(20,16,10,.45); border-radius: 2px;
  padding: 20px 24px 22px; animation: panel .35s cubic-bezier(.2,.8,.2,1) both; -webkit-user-select: text; user-select: text; }
@keyframes panel { from { opacity: 0; transform: translate(-50%, -48%); } to { opacity: 1; transform: translate(-50%, -50%); } }
.panel header { position: relative; padding-right: 40px; margin-bottom: 14px; flex: none; }
.panel h2 { margin: 0 0 6px; font-weight: 400; font-size: 28px; letter-spacing: .3em; }
.panel header p { margin: 0; font-family: var(--song); font-size: 13px; line-height: 1.7; color: var(--ink2); }
.panel .x { position: absolute; right: -6px; top: -8px; width: 38px; height: 38px; font-size: 26px; line-height: 1; background: none; border: 0; color: var(--ink2); }
.panel .x:hover { color: var(--red); }
.go { background: var(--red); color: #f6ecd8; border: 0; border-radius: 3px; font-size: 20px; padding: 8px 26px; letter-spacing: .2em; text-indent: .2em; }
.go:hover { filter: brightness(1.08); }

#codex-grid { overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; padding: 2px 4px 4px 2px; }
#codex-grid h3 { grid-column: 1 / -1; margin: 10px 0 0; font-weight: 400; font-size: 16px; letter-spacing: .4em; color: var(--red); border-bottom: 1px solid rgba(143,123,85,.5); padding-bottom: 4px; }
#codex-grid h3:first-child { margin-top: 0; }
.card { background: #f6eedb; border: 1px solid rgba(143,123,85,.55); border-radius: 2px; padding: 0 0 7px; text-align: center; cursor: pointer; transition: transform .18s, box-shadow .18s, border-color .18s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(60,40,10,.2); border-color: var(--red); }
.card canvas { width: 100%; aspect-ratio: 4 / 3; display: block; }
.card b { display: block; font-weight: 400; font-size: 18px; letter-spacing: .12em; margin-top: 2px; }
.card small { display: block; font-family: var(--song); font-size: 11px; color: var(--ink2); letter-spacing: .05em; }
.card.cur { border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }

#forge-text { width: 100%; font-family: var(--kai); font-size: 21px; line-height: 1.7; letter-spacing: .06em; padding: 10px 12px; background: #f8f1df; color: var(--ink);
  border: 1px solid #8f7b55; border-radius: 2px; resize: vertical; outline: none; }
#forge-text:focus, #ask-name:focus { border-color: var(--red); box-shadow: 0 0 0 2px rgba(184,58,38,.15); }
#forge-read { min-height: 26px; margin: 8px 0 4px; display: flex; flex-wrap: wrap; gap: 5px; font-family: var(--song); font-size: 12px; }
#forge-read span { padding: 2px 7px; border: 1px solid rgba(60,50,40,.3); border-radius: 2px; color: var(--ink2); }
#forge-read span.bad { color: #9a8f7f; border-style: dashed; }
#forge-chips { overflow-y: auto; margin-top: 6px; flex: 1 1 auto; min-height: 0; }
#forge-text { flex: none; }
#forge-read { flex: none; }
#forge-chips .row { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-bottom: 6px; }
#forge-chips .row em { font-style: normal; font-size: 14px; color: var(--red); letter-spacing: .2em; width: 2.6em; flex: none; }
#forge-chips button { background: #f8f1df; border: 1px solid rgba(143,123,85,.6); border-radius: 2px; font-size: 15px; padding: 2px 8px; letter-spacing: .04em; }
#forge-chips button:hover { border-color: var(--red); color: var(--red); }
#forge footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; flex: none; }
#forge footer button:not(.go) { background: none; border: 1px solid rgba(143,123,85,.7); border-radius: 3px; font-size: 16px; padding: 6px 14px; letter-spacing: .1em; }
#forge footer button:not(.go):hover { border-color: var(--red); color: var(--red); }

#ask { width: min(520px, 92vw); }
.ask-row { display: flex; gap: 10px; }
#ask-name { flex: 1; min-width: 0; font-family: var(--kai); font-size: 26px; letter-spacing: .2em; padding: 8px 14px; background: #f8f1df; color: var(--ink); border: 1px solid #8f7b55; border-radius: 2px; outline: none; }
.ask-hint { margin: 12px 0 0; font-family: var(--song); font-size: 12px; color: var(--ink2); }

#toast { position: absolute; z-index: 40; left: 50%; top: calc(3.4vh + 20px); transform: translate(-50%, -8px); background: rgba(34,42,56,.92); color: #eadfc6; font-size: 15px; letter-spacing: .12em;
  padding: 8px 16px; border-radius: 3px; border: 1px solid rgba(184,148,76,.5); opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; max-width: 86vw; text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
.ripple { position: absolute; z-index: 4; width: 10px; height: 10px; margin: -5px 0 0 -5px; border: 1.5px solid rgba(40,35,30,.55); border-radius: 50%; pointer-events: none; animation: rip .7s ease-out forwards; }
@keyframes rip { to { transform: scale(5); opacity: 0; } }

body.shot * { transition: none !important; animation: none !important; }
body.shot #title { display: none; }

#nogl { display: none; position: absolute; inset: 0; z-index: 50; background: var(--paper); align-items: center; justify-content: center; padding: 30px; font-size: 18px; line-height: 1.8; text-align: center; }
body.nogl #nogl { display: flex; }
body.nogl #title { display: none; }

/* ---------- 竖屏手机 ---------- */
@media (max-width: 760px), (max-aspect-ratio: 4/5) {
  #mark { left: 12px; top: calc(2.2vh + 8px); }
  .mk-txt { display: none; }
  #scroll { left: 46px; right: 12px; top: calc(2.2vh + 10px); bottom: auto; height: 27vh; width: auto; gap: 10px; }
  #text { font-size: 19px; line-height: 1.7; overflow-x: auto; }
  #src { font-size: 12px; }
  #seal { font-size: 17px; padding: 5px 4px; }
  #note { display: none; }
  #tags { left: 10px; right: 10px; max-width: none; bottom: calc(2.2vh + 70px); justify-content: center; }
  #tags span { font-size: 11px; padding: 2px 6px; }
  #bar { bottom: calc(2.2vh + 8px); flex-wrap: wrap; justify-content: center; width: calc(100vw - 16px); gap: 2px; padding: 5px 6px; }
  #bar { flex-wrap: nowrap; }
  #bar button { font-size: 15px; padding: 8px 6px; letter-spacing: .02em; flex: 1 1 auto; }
  #bar button[data-act=prev], #bar button[data-act=next] { padding: 3px 6px 7px; flex: 0 0 auto; }
  #bar i { display: none; }
  .panel { padding: 16px 14px 16px; max-height: 88vh; }
  .panel h2 { font-size: 24px; }
  #codex-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 7px; }
  .card b { font-size: 16px; }
  #forge-text { font-size: 18px; }
  #forge-chips button { font-size: 15px; padding: 3px 7px; }
}
@media (max-height: 520px) and (min-aspect-ratio: 4/5) {
  #text { font-size: 18px; line-height: 1.7; }
  #bar { padding: 4px 8px; }
  #bar button { font-size: 15px; padding: 4px 9px; }
  #tags { display: none; }
}
