:root {
  --desk: #17120d;
  --paper: #ece4cf;
  --ink: #1f1c19;
  --silk: #d6d0bf;
  --silk2: #c8c0a9;
  --brocade: #8c7a55;
  --seal: #b0392b;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "BiauKai", "Songti SC", serif;
  --xing: "Xingkai SC", "STXingkai", "Kaiti SC", "STKaiti", "KaiTi", serif;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--desk); color: var(--ink); font-family: var(--kai); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; background: #e9e2cf; touch-action: none; }

/* ———— 手卷 ———— */
#desk {
  position: fixed; inset: 0; display: grid; place-items: center; align-content: center; gap: 4vh;
  cursor: grab; user-select: none; touch-action: none;
  transition: transform 2s cubic-bezier(.55, 0, .35, 1), opacity 1.2s ease .7s;
}
#desk:active { cursor: grabbing; }
#desk.painting { cursor: crosshair; }
#desk.opened { cursor: zoom-in; }
#desk.entering { transform: scale(3.4); opacity: 0; pointer-events: none; }
#scroll {
  --open: 0;
  --w: min(86vw, 1500px);
  --h: min(calc(var(--w) / 2.5), 56vh);
  --m: calc(var(--h) * .1);
  position: relative; width: var(--w); height: var(--h);
}
#hole {
  position: absolute; top: 0; bottom: 0;
  left: calc(50% - var(--open) * var(--w) / 2);
  right: calc(50% - var(--open) * var(--w) / 2);
  box-shadow:
    0 0 0 2px var(--brocade),
    0 0 0 var(--m) var(--silk),
    0 0 0 calc(var(--m) + 2px) var(--brocade),
    0 0 0 calc(var(--m) * 1.7) var(--silk2),
    0 24px 70px calc(var(--m) * 1.7) rgba(0, 0, 0, .55),
    0 0 0 300vmax var(--desk);
}
.roller {
  position: absolute; top: calc(var(--m) * -1.7 - 10px); bottom: calc(var(--m) * -1.7 - 10px); width: 22px;
  background: linear-gradient(90deg, #2e1b0f, #7b4f2c 35%, #a06a3c 50%, #5a3820 75%, #2a180c);
  border-radius: 4px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.roller.left { left: calc(50% - var(--open) * var(--w) / 2 - var(--m) * 1.7 - 22px); }
.roller.right { right: calc(50% - var(--open) * var(--w) / 2 - var(--m) * 1.7 - 22px); }
.roller i {
  position: absolute; left: -3px; right: -3px; height: 16px; border-radius: 4px;
  background: linear-gradient(90deg, #a9a48f, #f1ede0 45%, #cfc9b4 60%, #8f8a76);
}
.roller i:first-child { top: -14px; }
.roller i:last-child { bottom: -14px; }
#label {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  writing-mode: vertical-rl; white-space: nowrap; padding: 18px 10px; background: #efe8d6; border: 1px solid var(--brocade);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35); display: flex; align-items: center; gap: 12px;
  transition: opacity .4s; pointer-events: none;
}
#label b { font-family: var(--xing); font-size: clamp(28px, 4vh, 44px); font-weight: 400; letter-spacing: .2em; }
#label small { font-size: 13px; color: #6b5f4a; letter-spacing: .15em; }
#label { opacity: calc(1 - var(--open) * 4); }
.seal {
  display: inline-grid; place-items: center; background: var(--seal); color: #f4e9da;
  font-family: var(--kai); line-height: 1.05; border-radius: 3px;
  filter: url(#rough);
}
#seal {
  position: absolute; width: calc(var(--h) * .13); height: calc(var(--h) * .13); font-size: calc(var(--h) * .048);
  right: calc(50% - var(--open) * var(--w) / 2 + var(--h) * .05); bottom: calc(var(--h) * .06);
  opacity: 0; transform: scale(1.8) rotate(-4deg); transition: opacity .25s, transform .35s cubic-bezier(.3, 1.6, .5, 1);
  mix-blend-mode: multiply;
}
#desk.opened #seal { opacity: .92; transform: scale(1) rotate(-4deg); }
#hint { margin: 0; color: #cfc4a8; letter-spacing: .4em; font-size: 15px; opacity: .85; animation: breathe 3s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .4; } }

/* ———— 画中 HUD ———— */
#hud { position: fixed; inset: 0; pointer-events: none; animation: fadein 1.5s ease; }
@keyframes fadein { from { opacity: 0; } }
#title { position: absolute; left: 22px; top: 22px; writing-mode: vertical-rl; white-space: nowrap; display: flex; gap: 10px; align-items: center; }
#title b { font-family: var(--xing); font-weight: 400; font-size: 34px; letter-spacing: .15em; color: #2a2520; }
#title span { font-size: 15px; letter-spacing: .3em; color: #5d5242; border-right: 1px solid rgba(40, 32, 24, .35); padding-right: 6px; }
#chips { position: absolute; right: 18px; top: 18px; display: flex; flex-direction: column; gap: 8px; pointer-events: auto; }
#chips button {
  width: 38px; height: 38px; border-radius: 3px; cursor: pointer; font-size: 18px;
  background: rgba(239, 232, 214, .78); border: 1px solid rgba(40, 32, 24, .35);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); transition: background .2s, color .2s;
}
#chips button:hover, #chips button.on { background: var(--seal); color: #f4e9da; border-color: var(--seal); }
#tech {
  position: absolute; right: 66px; top: 18px; width: 330px; padding: 12px 14px; pointer-events: auto;
  background: rgba(239, 232, 214, .9); border: 1px solid rgba(40, 32, 24, .3); font-size: 13px; line-height: 1.5;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#tech p { margin: 0 0 5px; display: grid; grid-template-columns: 38px 1fr; gap: 8px; }
#tech b { color: var(--seal); font-weight: 400; }
#tech span { font-variant-numeric: tabular-nums; }
#help {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); margin: 0; white-space: nowrap;
  font-size: 14px; letter-spacing: .2em; color: #4c4336; transition: opacity 2s;
}
#help.fade { opacity: 0; }
#prompt {
  position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%); pointer-events: auto; cursor: pointer;
  padding: 8px 18px; background: rgba(239, 232, 214, .88); border: 1px solid rgba(40, 32, 24, .4); font-size: 16px; letter-spacing: .15em;
}
kbd { font-family: inherit; border: 1px solid var(--ink); padding: 0 6px; margin-right: 6px; border-radius: 2px; }

/* ———— 对话 ———— */
#talk {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(720px, 94vw);
  background: linear-gradient(#f1ead8, #e9e0c9); border: 1px solid rgba(40, 32, 24, .4);
  box-shadow: 0 18px 60px rgba(30, 20, 10, .35); padding: 14px 18px 12px; animation: rise .35s ease;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 12px); } }
#talk header { display: flex; align-items: center; gap: 10px; }
#talk header b { font-family: var(--xing); font-weight: 400; font-size: 22px; }
#talk header em { font-style: normal; font-size: 12px; color: #7a6c55; border: 1px solid rgba(122, 108, 85, .5); padding: 0 6px; }
#talk-close { margin-left: auto; background: none; border: none; font-size: 22px; cursor: pointer; color: #6b5f4a; }
.seal.mini { width: 26px; height: 26px; font-size: 15px; }
#talk-log { max-height: 30vh; overflow-y: auto; padding: 8px 2px; font-size: 18px; line-height: 1.7; }
#talk-log p { margin: 6px 0; }
#talk-log p.me { text-align: right; color: #3d5160; }
#talk-log p.me::before { content: "我："; color: #8a9aa6; font-size: 14px; }
#talk-log p.thinking::after { content: "……"; animation: breathe 1.2s infinite; }
#talk-form { display: flex; gap: 8px; border-top: 1px solid rgba(40, 32, 24, .2); padding-top: 10px; }
#talk-input { flex: 1; font: inherit; font-size: 17px; padding: 6px 10px; background: rgba(255, 255, 255, .45); border: 1px solid rgba(40, 32, 24, .3); outline: none; }
#talk-input:focus { border-color: var(--seal); }
#talk-form button { width: 40px; border: 1px solid rgba(40, 32, 24, .35); background: rgba(255, 255, 255, .35); cursor: pointer; font-size: 17px; }
#talk-send { background: var(--seal) !important; color: #f4e9da; border-color: var(--seal) !important; }
#talk-mic.on { background: var(--seal); color: #f4e9da; }

/* ———— 留影 ———— */
.modal { position: fixed; inset: 0; display: grid; place-items: center; align-content: center; gap: 16px; background: rgba(20, 15, 10, .72); }
.modal img { max-width: 90vw; max-height: 76vh; box-shadow: 0 20px 70px rgba(0, 0, 0, .6); }
.modal video { max-height: 76vh; max-width: 90vw; aspect-ratio: 9 / 16; background: #000; box-shadow: 0 20px 70px rgba(0, 0, 0, .6); }
.modal .bar { display: flex; gap: 12px; }
.modal .bar > * {
  padding: 8px 18px; background: #efe8d6; border: 1px solid var(--brocade); color: var(--ink);
  text-decoration: none; cursor: pointer; font-size: 16px; letter-spacing: .15em;
}

@media (max-width: 640px) {
  #help { font-size: 12px; letter-spacing: .05em; }
  #title b { font-size: 26px; }
  #tech { width: calc(100vw - 90px); }
}

/* Keep the original scroll and controls legible in narrow embedded viewports. */
#hint { position: relative; z-index: 1; max-width: 94vw; text-align: center; }
#talk-input { min-width: 0; }
.modal .bar { max-width: 94vw; flex-wrap: wrap; justify-content: center; }
@media (max-width: 640px) {
  #desk { gap: 110px; }
  #scroll { --w: 76vw; }
  #hint { font-size: 12px; letter-spacing: .12em; }
  #talk header { gap: 6px; }
  #talk header em { font-size: 10px; }
}

/* Leave room below the brocade mat for the instruction line. */
#desk { gap: 12vh; }
@media (max-width: 640px) { #desk { gap: 110px; } }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
