/* 夜巡长卷 · handscroll base styles. Palette = Overprint paper & ink tokens. */
@font-face { font-family: "Kai"; src: url("fonts/kai.woff2") format("woff2"); font-display: block; }
@font-face { font-family: "SerifSC"; src: url("fonts/serif.woff2") format("woff2"); font-display: swap; }

:root {
  --paper: #EEE3CC; --paper-dark: #E3D5B8; --paper-deep: #D8C8A6;
  --ink: #1E1A1A; --ink-soft: #4A3F36; --muted: #7A6E60;
  --verm: #DA442C; --verm-deep: #B3301C; --glow: #FFB020;
  --night: #1A1714; --night-2: #24201C; --night-ink: #EEE3CC;
  --desk: #121010;
  --roller: 64px;
  --page: calc(100vw - 2 * var(--roller));   /* the visible paper between the rollers */
  --u: min(1vh, 1.25vw);   /* size unit: tracks height, but never lets tall windows blow text up */
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--desk); overflow: hidden; color: var(--ink);
  font-family: "SerifSC", "Noto Serif SC", "Songti SC", serif; -webkit-user-select: none; user-select: none; }
#desk { position: fixed; inset: 0; background:
  radial-gradient(ellipse at 50% 120%, #2a211b 0%, #121010 60%); }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none; }
#viewport { position: absolute; top: 7vh; bottom: 9vh; left: var(--roller); right: var(--roller); overflow: hidden;
  perspective: 1400px; perspective-origin: 50% 50%; z-index: 2; }
#track { position: absolute; top: 0; bottom: 0; left: 0; display: flex; will-change: transform; transform-style: preserve-3d; }

/* Paper: every panel is a sheet of the same scroll; the JS curls sheets near the rollers. */
.panel { position: relative; flex: 0 0 var(--w, var(--page)); height: 100%; overflow: hidden;
  background: var(--paper) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.35  0 0 0 0 0.28  0 0 0 0 0.2  0 0 0 0.09 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  border-top: 3px double rgba(30,26,26,.45); border-bottom: 3px double rgba(30,26,26,.45);
  transform-origin: 50% 50%; backface-visibility: hidden; transition: background-color .6s; }
.panel::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: var(--shade, transparent); }
.panel.night { background-color: var(--night); color: var(--night-ink); }
.vert { writing-mode: vertical-rl; text-orientation: upright; }
:lang(en) .vert { text-orientation: mixed; }
:lang(en) .panel-head b { font-size: max(13px, calc(6 * var(--u))); letter-spacing: .04em; }
:lang(en) .panel-head i { font-size: max(13px, calc(1.5 * var(--u))); max-height: calc(48 * var(--u)); }
:lang(en) .front-title { font-size: min(calc(20 * var(--u)), 15vw); }

/* 引首 */
#p-front { display: flex; align-items: center; justify-content: center; }
/* The title soaks into the paper: each character arrives blurred and swollen, then dries sharp. */
.front-title { position: absolute; left: 22%; top: 50%; transform: translateY(-50%); font-family: "Kai", serif; font-size: min(calc(24 * var(--u)), 18vw); line-height: 1.02;
  writing-mode: vertical-rl; text-orientation: upright; color: var(--ink); white-space: nowrap; }
.front-title span { display: inline-block; opacity: 0; filter: blur(18px); transform: scale(1.18); transition: opacity 1.6s ease, filter 2.4s cubic-bezier(.2,.7,.2,1), transform 2.4s cubic-bezier(.2,.7,.2,1); }
.front-title.on span { opacity: 1; filter: blur(0); transform: none; }
.front-title::after { content: ""; position: absolute; inset: -10% -30%; background: radial-gradient(ellipse at 50% 50%, rgba(30,26,26,.10), rgba(30,26,26,0) 60%); z-index: -1; }
.front-title.on span:nth-child(2) { transition-delay: .35s; } .front-title.on span:nth-child(3) { transition-delay: .7s; }
.front-sub { position: absolute; left: 42%; top: calc(14 * var(--u)); font-family: "Kai", serif; font-size: max(13px, calc(2.4 * var(--u))); color: var(--ink-soft); letter-spacing: .3em; }
.keeper { position: absolute; right: 10vw; bottom: -calc(2 * var(--u)); height: calc(78 * var(--u)); filter: drop-shadow(8px 6px 0 rgba(218,68,44,.35)); }
.front-seal { position: absolute; left: calc(22% - calc(11 * var(--u))); bottom: calc(14 * var(--u)); width: calc(9 * var(--u)); transform: rotate(-8deg); opacity: .92; }
.hint { position: absolute; bottom: calc(4 * var(--u)); left: 50%; transform: translateX(-50%); font-size: max(13px, calc(1.8 * var(--u))); color: var(--muted); letter-spacing: .1em;
  animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .35; } }

/* Panel heads: tall vertical titles at the start of each sheet */
.panel-head { position: absolute; left: 3vw; top: calc(6 * var(--u)); display: flex; gap: calc(1.2 * var(--u)); z-index: 4; }
.panel-head b { font-family: "Kai", serif; font-weight: normal; font-size: max(13px, calc(9 * var(--u))); line-height: 1; }
.panel-head i { font-style: normal; font-size: max(13px, calc(1.7 * var(--u))); color: var(--muted); letter-spacing: .15em; max-height: calc(60 * var(--u)); }
.night .panel-head i { color: #A99D8A; }

/* 工坊 gates */
#p-work { --w: calc(14vw + var(--gates) * 30vw); background-color: var(--paper);
  background-image: var(--wall); background-size: cover; background-position: center; }
#p-work::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(238,227,204,.88) 0%, rgba(238,227,204,.55) 40%, rgba(238,227,204,.9) 100%); }
/* Gates share one six-row grid (subgrid) so moon, name, recipes, select, quote and stamp line up across columns,
   however many lines a column's quote or name needs. */
.gates { --gate-w: min(26vw, calc(46 * var(--u))); position: absolute; left: 14vw; top: 0; bottom: 0; display: grid; grid-auto-flow: column; grid-auto-columns: var(--gate-w);
  grid-template-rows: repeat(6, auto); align-content: safe center; column-gap: 4vw; row-gap: calc(1.6 * var(--u)); }
.gate { position: relative; grid-row: 1 / span 6; display: grid; grid-template-rows: subgrid; justify-items: center; align-items: center; min-width: 0; }
.moon { position: relative; width: 100%; aspect-ratio: 1; border-radius: 50%; overflow: hidden; background: #2a221c;
  box-shadow: 0 0 0 6px var(--ink), 0 0 0 9px var(--paper), 0 0 0 11px var(--verm-deep), 10px 12px 0 11px rgba(218,68,44,.35);
  transition: transform .5s cubic-bezier(.2,.8,.2,1); }
.moon img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.12); transition: transform 1.2s ease, filter .6s; filter: saturate(.85) brightness(.92); }
.gate:hover .moon img, .gate.running .moon img { transform: scale(1.02); filter: none; }
.moon .glow { position: absolute; width: 30%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, rgba(255,176,32,.75), rgba(255,176,32,0) 70%);
  mix-blend-mode: screen; opacity: 0; transition: opacity .6s; pointer-events: none; }
.gate.running .glow { opacity: 1; animation: flicker 1.7s infinite; }
@keyframes flicker { 30% { opacity: .75; } 60% { opacity: 1; } 80% { opacity: .85; } }
.moon .batch { position: absolute; left: 10%; right: 10%; bottom: 9%; height: 6px; background: rgba(0,0,0,.4); border-radius: 3px; opacity: 0; transition: opacity .3s; }
.gate.running .batch { opacity: 1; }
.moon .batch div { height: 100%; width: 0; background: var(--glow); border-radius: 3px; }
.gate-name { font-family: "Kai", serif; font-size: max(13px, calc(3.4 * var(--u))); display: flex; gap: 1vw; align-items: baseline; }
.gate-name small { font-family: "SerifSC", serif; font-size: max(13px, calc(1.5 * var(--u))); color: var(--muted); }
.recipes { display: flex; gap: .6vw; }
.recipe { width: calc(5.4 * var(--u)); height: calc(5.4 * var(--u)); border: 1px solid rgba(30,26,26,.35); background: rgba(238,227,204,.85); display: grid; place-items: center; cursor: pointer; position: relative; }
.recipe img { width: 80%; }
.recipe.on { outline: 2px solid var(--verm); outline-offset: 2px; }
.stamp { position: relative; width: calc(11 * var(--u)); height: calc(11 * var(--u)); cursor: pointer; display: grid; place-items: center; }
.stamp .face { position: absolute; inset: 0; background: var(--verm-deep); color: #F3EBD8; font-family: "Kai", serif; font-size: max(13px, calc(4 * var(--u)));
  display: grid; place-items: center; border: 3px solid #F3EBD8; outline: 2px solid var(--verm-deep); transform: rotate(-4deg);
  box-shadow: 4px 5px 0 rgba(30,26,26,.35); transition: transform .12s; }
.stamp:active .face { transform: rotate(-4deg) scale(.94); }
.stamp svg { position: absolute; inset: -10px; width: calc(100% + 20px); height: calc(100% + 20px); transform: rotate(-90deg); pointer-events: none; }
.stamp svg circle { fill: none; stroke: var(--verm); stroke-width: 4; stroke-dasharray: 300; stroke-dashoffset: 300; }
.gate.running .stamp .face { background: var(--ink); }
.imprint { position: absolute; width: calc(9 * var(--u)); height: calc(9 * var(--u)); pointer-events: none; opacity: 0; mix-blend-mode: multiply;
  background: center/contain no-repeat; animation: imprint 1.6s ease-out forwards; }
@keyframes imprint { 0% { opacity: 0; transform: scale(1.5) rotate(var(--r)); } 12% { opacity: .95; transform: scale(1) rotate(var(--r)); } 100% { opacity: .55; transform: scale(1) rotate(var(--r)); } }

/* 异录 */
#p-anom { background-color: var(--night); }
.ghost-faint, .ghost-lit { position: absolute; inset: 0; }
.ghost { position: absolute; height: calc(52 * var(--u)); transform-origin: 50% 100%; animation: sway 6s ease-in-out infinite; cursor: none; }
.ghost img { height: 100%; display: block; }
.ghost-faint .ghost { opacity: .05; filter: blur(2px) grayscale(1); }
.ghost-lit { -webkit-mask-image: radial-gradient(circle at var(--mx, -999px) var(--my, -999px), #000 0, #000 var(--r1, 110px), transparent var(--r2, 190px));
  mask-image: radial-gradient(circle at var(--mx, -999px) var(--my, -999px), #000 0, #000 var(--r1, 110px), transparent var(--r2, 190px));
  background: radial-gradient(circle at var(--mx, -999px) var(--my, -999px), rgba(255,176,32,.18), rgba(26,23,20,0) var(--r2, 190px)); }
.ghost-lit .ghost img { filter: drop-shadow(0 0 12px rgba(255,176,32,.4)); }
.ghost.found::after { content: "考"; position: absolute; top: 4%; right: -6%; width: calc(7 * var(--u)); height: calc(7 * var(--u)); display: grid; place-items: center;
  font-family: "Kai", serif; font-size: max(13px, calc(4.5 * var(--u))); color: #F3EBD8; background: var(--verm-deep); transform: rotate(-9deg); border: 2px solid #F3EBD8; }
.ghost-faint .ghost.found { opacity: .5; filter: grayscale(.4); }
.ghost .tag { position: absolute; left: 50%; bottom: -calc(5 * var(--u)); transform: translateX(-50%); white-space: nowrap; font-family: "Kai", serif; font-size: max(13px, calc(2.2 * var(--u))); color: var(--night-ink); }
@keyframes sway { 50% { transform: rotate(var(--sw, 1.5deg)) translateY(-calc(1 * var(--u))); } }
.whisper { position: absolute; right: 6vw; top: calc(10 * var(--u)); font-family: "Kai", serif; font-size: max(13px, calc(2.6 * var(--u))); letter-spacing: .5em; color: rgba(238,227,204,.07); }
.anom-lit .whisper { color: rgba(238,227,204,.5); transition: color 2s; }
body.lamp-on, body.lamp-on * { cursor: none !important; }
#lamp { position: fixed; width: 54px; height: 70px; margin: -35px 0 0 -27px; pointer-events: none; z-index: 30; opacity: 0; transition: opacity .3s;
  background: radial-gradient(ellipse at 50% 58%, #FFD27A 0 22%, #FFB020 23% 46%, rgba(218,68,44,.9) 47% 60%, rgba(0,0,0,0) 61%); filter: drop-shadow(0 0 18px rgba(255,176,32,.8)); }
#lamp::before { content: ""; position: absolute; left: 50%; top: -26px; width: 1px; height: 30px; background: #CFC4AE; }
body.lamp-on #lamp { opacity: 1; }

/* 灵宠 */
.beam { position: absolute; left: 10vw; right: 4vw; top: calc(8 * var(--u)); height: calc(3.2 * var(--u)); background: linear-gradient(#6E3B2A, #4a271b); border-radius: 4px; box-shadow: 0 6px 0 rgba(30,26,26,.25); }
.pets { position: absolute; left: 10vw; right: 4vw; top: calc(11 * var(--u)); bottom: 0; }
.pet { position: absolute; top: 0; width: calc(15 * var(--u)); transform-origin: 50% 0; cursor: pointer; }
.pet .string { width: 2px; margin: 0 auto; background: var(--verm-deep); height: var(--len, calc(18 * var(--u))); }
.pet .disc { width: calc(15 * var(--u)); height: calc(15 * var(--u)); border-radius: 50%; overflow: hidden; box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--paper), 6px 8px 0 6px rgba(30,26,26,.18); transition: filter .8s; background: #ccc; }
.pet .disc img { width: 100%; height: 100%; object-fit: cover; }
.pet:not(.met) .disc { filter: grayscale(1) brightness(.9) contrast(.9); }
.pet .label { text-align: center; font-family: "Kai", serif; font-size: max(13px, calc(2 * var(--u))); margin-top: calc(1 * var(--u)); opacity: 0; transition: opacity .6s; white-space: nowrap; }
.pet.met .label { opacity: 1; }
.pet.bonded .disc { box-shadow: 0 0 0 3px var(--verm), 0 0 0 6px var(--paper), 0 0 30px 6px rgba(255,176,32,.55); }
.pet .knot { width: calc(1.6 * var(--u)); height: calc(1.6 * var(--u)); margin: -.4vh auto 0; background: var(--verm); transform: rotate(45deg); }
.bonds { position: absolute; right: 6vw; bottom: calc(7 * var(--u)); display: flex; gap: 2vw; }
.bond { width: calc(17 * var(--u)); padding: calc(1.4 * var(--u)); border: 2px solid var(--ink); background: rgba(238,227,204,.9); text-align: center; font-size: max(13px, calc(1.6 * var(--u))); color: var(--muted); }
.bond b { display: block; font-family: "Kai", serif; font-weight: normal; font-size: max(13px, calc(2.6 * var(--u))); color: var(--ink); margin-top: .6vh; min-height: calc(3 * var(--u)); }
.bond.full { border-color: var(--verm-deep); }

/* 库房 */
.cabinet { position: absolute; left: 13%; top: calc(7 * var(--u)); bottom: calc(6 * var(--u)); width: 58%; display: grid; grid-template-columns: repeat(5, 1fr); grid-auto-rows: 1fr; gap: .8vh;
  padding: calc(1.6 * var(--u)); background: linear-gradient(#5b3021, #3e1f15); border-radius: 6px; box-shadow: 12px 14px 0 rgba(30,26,26,.25); }
.drawer { position: relative; background: linear-gradient(#8a4a33, #6E3B2A); border: 1px solid #2c140d; border-radius: 3px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .3vh; padding: .8vh .4vh .4vh; color: #F3EBD8; cursor: grab; transition: transform .25s, box-shadow .25s; overflow: hidden; }
.drawer:hover { transform: translateZ(0) translateY(-2px); box-shadow: 0 6px 10px rgba(0,0,0,.35); }
.drawer img { height: 48%; max-height: calc(7 * var(--u)); filter: drop-shadow(0 2px 0 rgba(0,0,0,.4)); }
.drawer .txt { display: flex; flex-direction: column; align-items: center; font-size: max(13px, calc(1.4 * var(--u))); line-height: 1.2; max-width: 100%; }
.drawer .txt b { font-family: "Kai", serif; font-weight: normal; font-size: max(13px, calc(1.7 * var(--u))); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.drawer .ring { position: absolute; top: 6px; left: 50%; width: 14px; height: 14px; margin-left: -7px; border: 2px solid #C9A25A; border-radius: 50%; border-top-color: transparent; }
.drawer.locked::after { content: ""; position: absolute; inset: 0; background: linear-gradient(135deg, transparent 46%, var(--verm) 46% 54%, transparent 54%); pointer-events: none; }
.drawer.empty { opacity: .35; cursor: default; }
.drawer.dragging { opacity: .4; }
.drag-ghost { position: fixed; width: calc(9 * var(--u)); height: calc(9 * var(--u)); pointer-events: none; z-index: 40; filter: drop-shadow(0 8px 6px rgba(0,0,0,.45)); }
.burner { position: absolute; right: 5%; bottom: calc(6 * var(--u)); width: 24%; max-width: calc(30 * var(--u)); height: calc(52 * var(--u)); }
.burner-body { position: absolute; left: 0; right: 0; bottom: calc(4 * var(--u)); height: calc(18 * var(--u)); border-radius: 0 0 50% 50% / 0 0 70% 70%;
  background: radial-gradient(ellipse at 50% 0%, #2b2420 0 34%, transparent 35%), linear-gradient(#9a5a2c, #5a2e16); box-shadow: inset 0 -8px 0 rgba(0,0,0,.3), 8px 10px 0 rgba(30,26,26,.2); }
.burner-body::before, .burner-body::after { content: ""; position: absolute; top: -calc(1.4 * var(--u)); width: calc(2.2 * var(--u)); height: calc(3 * var(--u)); border: 4px solid #7a3e1c; border-bottom: 0; border-radius: 50% 50% 0 0; }
.burner-body::before { left: calc(2 * var(--u)); } .burner-body::after { right: calc(2 * var(--u)); }
.burner.hot .burner-body { box-shadow: 0 0 60px 10px rgba(255,176,32,.45), inset 0 -8px 0 rgba(0,0,0,.3); }
.burner-body > i { display: none; }
.burner::before, .burner::after { content: ""; position: absolute; bottom: calc(1.6 * var(--u)); width: calc(1.6 * var(--u)); height: calc(4 * var(--u)); background: #5a2e16; border-radius: 0 0 40% 40%; }
.burner::before { left: 22%; } .burner::after { right: 22%; }
.burner-label { position: absolute; bottom: 0; width: 100%; text-align: center; font-family: "Kai", serif; font-size: max(13px, calc(2.2 * var(--u))); }
#smoke { position: absolute; left: -calc(10 * var(--u)); right: -calc(10 * var(--u)); top: -calc(10 * var(--u)); bottom: calc(18 * var(--u)); width: calc(100% + calc(20 * var(--u))); height: calc(100% - calc(8 * var(--u))); pointer-events: none; }

/* 拖尾 */
#p-end { background-color: var(--paper-dark); }
.colophon { position: absolute; right: 8%; top: calc(8 * var(--u)); height: calc(72 * var(--u)); max-width: 36%; text-orientation: mixed; font-family: "Kai", serif; font-size: max(13px, calc(2.6 * var(--u))); line-height: 2; letter-spacing: .2em; color: var(--ink-soft); }
.seals { position: absolute; left: 12%; top: calc(12 * var(--u)); width: 44%; display: flex; flex-wrap: wrap; gap: calc(2 * var(--u)); align-content: flex-start; }
.seal { width: calc(9 * var(--u)); height: calc(9 * var(--u)); background: var(--verm-deep); color: #F3EBD8; font-family: "Kai", serif; font-size: max(13px, calc(2.4 * var(--u))); display: grid; place-items: center; text-align: center;
  line-height: 1.1; padding: .6vh; border: 3px double #F3EBD8; transform: rotate(var(--r)); opacity: .9; mix-blend-mode: multiply; filter: url(#rough); }
.seal.blank { background: transparent; color: var(--muted); border: 2px dashed rgba(122,110,96,.6); mix-blend-mode: normal; filter: none; }
.credits { position: absolute; left: 4vw; bottom: calc(6 * var(--u)); height: calc(60 * var(--u)); font-size: max(13px, calc(1.4 * var(--u))); color: var(--muted); letter-spacing: .1em; }

/* HUD */
#ledger { position: fixed; top: 0; right: calc(var(--roller) + 3vw); z-index: 20; display: flex; flex-direction: column; align-items: center; transform-origin: 50% 0; }
#ledger .plaque { margin-top: calc(1 * var(--u)); padding: calc(1.2 * var(--u)) calc(1.6 * var(--u)); background: linear-gradient(#2a1a12, #1d120c); border: 2px solid #C9A25A; color: #EEE3CC; min-width: calc(21 * var(--u));
  box-shadow: 0 8px 18px rgba(0,0,0,.5); }
#ledger .row { display: flex; justify-content: space-between; gap: calc(2 * var(--u)); font-size: max(13px, calc(1.6 * var(--u))); line-height: 1.8; }
#ledger .row b { font-family: "SerifSC", serif; color: var(--glow); font-weight: 600; font-variant-numeric: tabular-nums; }
#ledger .cord { width: 2px; height: calc(2 * var(--u)); background: var(--verm); }
#ledger .tassel { width: calc(3.4 * var(--u)); margin-top: -.4vh; }
#ledger.bump { animation: bump .45s ease; }
@keyframes bump { 30% { transform: rotate(2deg) scale(1.04); } 70% { transform: rotate(-1.5deg); } }
#logo { position: fixed; top: calc(1.6 * var(--u)); left: calc(var(--roller) + 2vw); z-index: 20; display: flex; align-items: center; gap: calc(1 * var(--u)); color: #CFC4AE; font-family: "Kai", serif; font-size: max(13px, calc(2 * var(--u))); letter-spacing: .2em; }
#logo img { width: calc(4 * var(--u)); }
#tools { position: fixed; bottom: calc(1.4 * var(--u)); right: calc(var(--roller) + 2vw); z-index: 20; display: flex; gap: calc(1 * var(--u)); }
#tools button { min-height: 44px; min-width: 44px; padding: 0 calc(1.4 * var(--u)); background: transparent; color: #CFC4AE; border: 1px solid #6b5f52; font-family: inherit; font-size: max(13px, calc(1.5 * var(--u))); cursor: pointer; }
#tools button:hover, #tools button:focus-visible { border-color: var(--glow); color: var(--glow); outline: none; }
#ribbon { position: fixed; left: calc(var(--roller) + 2vw); right: calc(var(--roller) + calc(26 * var(--u))); bottom: calc(3.4 * var(--u)); height: 4px; background: #3a2f27; z-index: 20; }
#ribbonFill { height: 100%; width: 0; background: linear-gradient(90deg, var(--verm-deep), var(--verm)); }
#ribbonMarks { position: absolute; inset: 0; }
#ribbonMarks button { white-space: nowrap; position: absolute; top: 50%; transform: translate(-50%, -50%); min-width: 44px; min-height: 44px; background: none; border: 0; color: #A99D8A; font-family: "Kai", serif; font-size: max(13px, calc(1.8 * var(--u))); cursor: pointer; padding: 0; }
#ribbonMarks button::before { content: ""; display: block; width: 10px; height: 10px; margin: 0 auto 2px; background: #6b5f52; transform: rotate(45deg); }
#ribbonMarks button { color: transparent; }
#ribbonMarks button.here, #ribbonMarks button:hover, #ribbonMarks button:focus-visible { color: var(--glow); }
#ribbonMarks button.here::before { background: var(--verm); }
#ribbonMarks button:focus-visible { outline: 1px solid var(--glow); }
#ink { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 25; }
#toast { position: fixed; left: 50%; top: calc(8 * var(--u)); transform: translateX(-50%) translateY(-20px); padding: calc(1 * var(--u)) calc(2 * var(--u)); background: rgba(26,23,20,.92); color: var(--paper);
  border-left: 3px solid var(--verm); font-size: max(13px, calc(1.7 * var(--u))); opacity: 0; transition: .35s; z-index: 35; pointer-events: none; }
#toast.on { opacity: 1; transform: translateX(-50%); }

@media (max-width: 760px) {
  :root { --roller: 26px; }
  .gates { --gate-w: 70vw; }
  #p-work { --w: calc(14vw + var(--gates) * 76vw); }
  .cabinet { grid-template-columns: repeat(4, 1fr); width: 120vw; }
  #p-store { --w: 220vw !important; }
  .burner { right: 4vw; }
  #ribbon { right: calc(var(--roller) + 2vw); bottom: calc(7 * var(--u)); }
}
@media (prefers-reduced-motion: reduce) {
  html:not([data-ui-scale]) .ghost, html:not([data-ui-scale]) .hint, html:not([data-ui-scale]) .gate.running .glow { animation: none !important; }
}

/* =====================================================================================
   夜巡长卷 · Handscroll design system
   - content sits on the scroll paper itself; groups part with whitespace or the sheet's
     own double ink rule, not boxed web cards;
   - titles are Kai brush script; sheets open with the tall vertical head;
   - choices are ink-lined chips with the vermilion offset print (like the recipe chips);
     the one decisive action is a seal (like 开工), never a flat coloured button;
   - status marks are seals (考 / 熟 / 准 …), pictures sit in moon frames or round discs;
   - furniture is dark wood (cabinet, beam, burner); the anomaly sheet is night paper;
   - procedural 3D (rollers, ash) and the ink canvas carry the motion.
   ===================================================================================== */
:root { --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.35  0 0 0 0 0.28  0 0 0 0 0.2  0 0 0 0.09 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>"); --rule: 3px double rgba(30,26,26,.45); --print: 3px 3px 0 rgba(218,68,44,.35);
  --frame: 0 0 0 3px var(--ink), 0 0 0 6px var(--paper), 6px 8px 0 6px rgba(218,68,44,.35);
  --body: 18px; --data: 16px; --small: 14px; }

/* ---------- flat rollers: only when WebGL is unavailable ---------- */
.roller { display: none; }
body.no-gl .roller { display: block; position: fixed; top: 3vh; bottom: 5vh; width: 38px; z-index: 6; pointer-events: none;
  border: 4px solid #4a1f14; background: #c8aa7a; box-shadow: inset 8px 0 #dbc49a, inset -5px 0 #a88758; }
body.no-gl .roller.left { left: calc(var(--roller) - 38px); } body.no-gl .roller.right { right: calc(var(--roller) - 38px); }

/* ---------- chrome: scroll desk & utility controls ---------- */
#viewport { top: max(7vh, 62px); bottom: max(9vh, 78px); }
#ribbon { right: calc(var(--roller) + 2vw + 330px); }
#tutorialBtn, #workshopJump { position: fixed; z-index: 23; top: calc(1.6 * var(--u)); min-height: 40px; padding: 0 12px; font-family: "Kai", serif;
  font-size: max(15px, calc(1.8 * var(--u))); color: #CFC4AE; background: transparent; border: 1px solid #6b5f52; cursor: pointer; }
#tutorialBtn { left: calc(var(--roller) + 2vw + 240px); }
#workshopJump { left: calc(var(--roller) + 2vw + 400px); max-width: 170px; }
#workshopJump option { color: var(--ink); background: var(--paper); }
:lang(en) #tutorialBtn { left: calc(var(--roller) + 2vw + 330px); } :lang(en) #workshopJump { left: calc(var(--roller) + 2vw + 530px); } :lang(en) #saveStatus { left: calc(var(--roller) + 2vw + 720px); }
#tutorialBtn:hover, #tutorialBtn:focus-visible, #workshopJump:hover, #workshopJump:focus-visible, #tutorialBtn[aria-expanded="true"] { border-color: var(--glow); color: var(--glow); outline: none; }
#saveStatus { position: fixed; z-index: 22; top: calc(1.6 * var(--u)); left: calc(var(--roller) + 2vw + 590px); right: calc(var(--roller) + 3vw + calc(24 * var(--u)));
  min-height: 40px; display: flex; align-items: center; font-size: var(--small); color: #8f8373; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#saveStatus.error { color: #F3EBD8; background: var(--verm-deep); padding: 0 10px; white-space: normal; }
#tools button { font-family: "Kai", serif; }
select:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid var(--verm); outline-offset: 2px; }
#track *, .yard-inner, dialog { scrollbar-width: thin; scrollbar-color: rgba(179,48,28,.55) transparent; }
#track *::-webkit-scrollbar { width: 6px; height: 6px; } #track *::-webkit-scrollbar-thumb { background: rgba(179,48,28,.55); border-radius: 3px; }
@media (max-width: 1100px) { #logo span { display: none; } #tutorialBtn { left: calc(var(--roller) + 2vw + 60px); } #workshopJump { left: calc(var(--roller) + 2vw + 200px); }
  #saveStatus { left: calc(var(--roller) + 2vw + 380px); } }
@media (max-width: 800px) { #saveStatus { display: none; } #saveStatus.error { display: flex; top: auto; bottom: 64px; left: 30px; right: 30px; }
  #ribbon { right: calc(var(--roller) + 2vw); bottom: 70px; } #viewport { bottom: 110px; } }

/* ---------- shared ink vocabulary: chips, seals, ink fields ---------- */
.yard-button, .settings-button, #p-store .stock-toolbar button, .stock-tabs button, .render-slip button, .item-sheet .sheet-amounts button, .backup-dialog button, .boot-error button {
  min-height: 44px; min-width: 44px; padding: 0 14px; margin: 4px 10px 4px 0; font-family: "Kai", serif; font-size: max(16px, calc(2 * var(--u))); color: var(--ink);
  background: rgba(238,227,204,.6); border: 1px solid rgba(30,26,26,.55); box-shadow: var(--print); cursor: pointer; transition: transform .12s, box-shadow .12s; }
.yard-button:hover:not(:disabled), .settings-button:hover, .stock-tabs button:hover, .render-slip button:hover:not(:disabled), .item-sheet .sheet-amounts button:hover:not(:disabled) {
  transform: translate(-1px,-1px); box-shadow: 4px 4px 0 rgba(218,68,44,.5); }
.yard-button:disabled, .render-slip button:disabled, .item-sheet .sheet-amounts button:disabled { opacity: .38; box-shadow: none; cursor: default; }
/* the decisive action: a seal, as on the workshop gate */
#yardConfirm, #expeditionConfirm, #commitControl, #tutorialConfirm, #offlineContinue, #offlineRetry, #recoveryRetry, .item-sheet .sheet-confirm, .render-slip button.primary, #renderConfirm {
  min-height: 48px; padding: 0 20px; font-family: "Kai", serif; font-size: max(17px, calc(2.2 * var(--u))); letter-spacing: .12em; color: #F3EBD8; background: var(--verm-deep);
  border: 3px solid #F3EBD8; outline: 2px solid var(--verm-deep); outline-offset: 0; box-shadow: 4px 5px 0 rgba(30,26,26,.35); transform: rotate(-2deg); cursor: pointer; }
#yardConfirm:disabled, #expeditionConfirm:disabled, #tutorialConfirm:disabled, .render-slip button.primary:disabled {
  color: var(--muted); background: transparent; border: 1px dashed rgba(122,110,96,.7); outline: 0; box-shadow: none; transform: none; opacity: .8; }
.seal-mark, .yard-card.dossier-step::after, #yard-lineage .permit::before, .yard-card[data-state="ripe"] .plot-bed::after, .rc-seal, .combat-stage .cs-stamp {
  display: grid; place-items: center; font-family: "Kai", serif; color: #F3EBD8; background: var(--verm-deep); border: 2px solid #F3EBD8; outline: 1px solid var(--verm-deep);
  transform: rotate(-8deg); filter: url(#rough); }
.yard-field { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 6px 18px 6px 0; font-family: "Kai", serif; font-size: max(15px, calc(1.8 * var(--u))); color: var(--ink-soft); }
.yard-field select, .yard-field input, #p-store .stock-toolbar input, #p-store .stock-toolbar select, .recipe-select {
  min-height: 44px; max-width: 100%; padding: 4px 4px; font-family: "SerifSC", serif; font-size: var(--body); color: var(--ink); background: transparent;
  border: 0; border-bottom: 1px solid rgba(30,26,26,.55); border-radius: 0; }
.yard-field select option, .recipe-select option { background: var(--paper); }
.yard-field input[type=number] { width: 90px; text-align: center; }
.yard-field input[type=checkbox] { width: 24px; min-height: 24px; accent-color: var(--verm-deep); }

/* ---------- 工坊 gates: moon gates, recipe chips, work line and craft book ---------- */
/* Short windows scroll the whole row of gates together, so columns stay aligned. */
.gates { top: 0; bottom: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; row-gap: calc(1.2 * var(--u)); padding: calc(2 * var(--u)) 0; } .gates::-webkit-scrollbar { display: none; }
.gate { padding: 0 10px; }
.gate .work-quote { align-self: stretch; grid-template-rows: auto auto auto 1fr; }
.gate .wo-status { align-self: end; }
.gate .moon { width: min(100%, calc(24 * var(--u))); }
.scene-placeholder { display: grid; place-items: center; height: 100%; color: var(--paper); font-family: "Kai", serif; font-size: max(13px, calc(2.4 * var(--u))); }
.gate-name { flex-wrap: wrap; justify-content: center; }
.gate .recipes { width: 100%; justify-content: flex-start; overflow-x: auto; overflow-y: hidden; gap: 8px; padding: 6px 4px 10px; scroll-snap-type: x proximity; }
.gate .recipe { flex: 0 0 auto; width: max(44px, calc(5.4 * var(--u))); height: max(44px, calc(5.4 * var(--u))); padding: 2px; box-shadow: var(--print);
  font-family: inherit; color: var(--ink); scroll-snap-align: start; }
.gate .recipe img { width: 80%; height: 80%; object-fit: contain; }
.gate .recipe .glyph { font-family: "Kai", serif; font-size: max(13px, calc(2.6 * var(--u))); color: var(--ink-soft); }
.gate .recipe .tier { position: absolute; right: -4px; bottom: -4px; font-style: normal; font-family: "Kai", serif; font-size: 13px; line-height: 15px; min-width: 15px;
  color: #F3EBD8; background: var(--ink); text-align: center; }
.gate .recipe .lv { position: absolute; left: 0; right: 0; bottom: 2px; font-style: normal; font-size: 13px; color: var(--verm-deep); text-align: center; }
.gate .recipe .lv { display: none; }
.gate .recipe.locked { box-shadow: none; border-style: dashed; }
.gate .recipe.locked img { filter: grayscale(1) opacity(.4); }
.recipe-select { width: auto; max-width: 100%; text-align: center; font-family: "Kai", serif; font-size: max(15px, calc(1.8 * var(--u))); color: var(--ink-soft); cursor: pointer; }
/* the work line under the gate: ink on paper, no slip */
.gate .work-quote { width: 100%; display: grid; justify-items: center; gap: 4px; text-align: center; font-size: var(--small); line-height: 1.35; color: var(--ink-soft); white-space: normal; min-height: 0; }
.gate .wo-out { display: flex; align-items: center; gap: 6px; font-family: "Kai", serif; font-size: max(17px, calc(2.3 * var(--u))); color: var(--ink); }
.gate .wo-out img { width: calc(3.6 * var(--u)); height: calc(3.6 * var(--u)); min-width: 28px; min-height: 28px; object-fit: contain; }
.gate .wo-out em { font-style: normal; color: var(--verm-deep); }
.gate .wo-out .secs { font-family: "SerifSC", serif; font-size: var(--small); color: var(--muted); font-variant-numeric: tabular-nums; }
.gate .wo-in { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 12px; }
.gate .chip { display: inline-flex; align-items: center; gap: 3px; font-size: var(--small); }
.gate .chip img { width: 22px; height: 22px; object-fit: contain; }
.gate .chip b { font-weight: normal; max-width: 13em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gate .chip em { font-style: normal; font-variant-numeric: tabular-nums; }
.gate .chip.short em, .gate .chip.short b { color: var(--verm-deep); }
.gate .chip.none { color: var(--muted); }
.gate .wo-meta { font-size: 13px; color: var(--muted); }
.gate .wo-status { font-family: "Kai", serif; font-size: 13px; padding: 0 6px; color: var(--verm-deep); border: 1px solid currentColor; transform: rotate(-3deg); }
.gate .wo-status.run { color: #F3EBD8; background: var(--verm-deep); }
.gate .wo-status.ready { color: var(--ink-soft); }
.work-actions { display: flex; align-items: center; justify-content: center; gap: calc(2.4 * var(--u)); }
.stamp { padding: 0; border: 0; background: none; font: inherit; flex-shrink: 0; width: max(72px, calc(10 * var(--u))); height: max(72px, calc(10 * var(--u))); }
:lang(en) .stamp .face { font-size: max(13px, calc(2.6 * var(--u))); }
/* the craft book is a thin stitched booklet beside the seal */
.settings-button { writing-mode: vertical-rl; text-orientation: upright; min-height: max(72px, calc(10 * var(--u))); width: 44px; padding: 8px 0; margin: 0; letter-spacing: .2em;
  background: var(--paper-dark); border: 1px solid var(--ink); border-left: 5px solid var(--ink); }
:lang(en) .settings-button { text-orientation: mixed; letter-spacing: .05em; font-size: 15px; }

/* ---------- sheets with functional books: 院务 · 夜巡案卷 · 诡异志 · 灵宠 ---------- */
.yard-book { position: absolute; top: calc(5 * var(--u)); bottom: calc(3 * var(--u)); left: calc(3vw + calc(16 * var(--u))); right: 4vw; display: flex; flex-direction: column;
  gap: 8px; overflow: hidden; color: var(--ink); font: var(--body)/1.55 "SerifSC", serif; }
#yardBook .yard-title, #expeditionBook .yard-title { display: none; }
.yard-title { font-family: "Kai", serif; font-weight: normal; font-size: max(13px, calc(4 * var(--u))); margin: 0; }
/* section tabs read like the ribbon: a diamond and a brush word */
.yard-tabs { display: flex; flex-wrap: wrap; gap: 0 calc(2.4 * var(--u)); border-bottom: var(--rule); padding-bottom: 2px; }
.yard-tabs .yard-button { position: relative; margin: 0; padding: 0 4px 0 18px; background: none; border: 0; box-shadow: none; color: var(--muted); font-size: max(17px, calc(2.4 * var(--u))); }
.yard-tabs .yard-button::before { content: ""; position: absolute; left: 2px; top: 50%; width: 8px; height: 8px; margin-top: -4px; background: #A99D8A; transform: rotate(45deg); }
.yard-tabs .yard-button:hover { transform: none; box-shadow: none; color: var(--ink); }
.yard-tabs .yard-button[aria-pressed="true"] { color: var(--ink); }
.yard-tabs .yard-button[aria-pressed="true"]::before { background: var(--verm); box-shadow: 0 0 8px rgba(218,68,44,.6); }
.yard-panel { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 4px 14px 10px 4px; }
.yard-panel[hidden] { display: none; }
.yard-panel p { margin: 6px 0; }
#expeditionBook p { white-space: pre-line; overflow-wrap: anywhere; }
.yard-note, .yard-details { color: var(--ink-soft); font-size: var(--small); }
.yard-live { font-variant-numeric: tabular-nums; }
/* an entry is a stretch of the paper under a brush heading, parted by the sheet's double rule */
.yard-card { margin: 0; padding: 12px 0 14px; background: none; border: 0; border-top: var(--rule); }
.yard-card h3 { margin: 0 0 4px; font-family: "Kai", serif; font-weight: normal; font-size: max(20px, calc(2.8 * var(--u))); }
.yard-list { display: grid; gap: 0 calc(3 * var(--u)); }
.yard-slot { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px dotted rgba(30,26,26,.35); }
/* the quote under each book: the review line and its seal */
.yard-review { flex-shrink: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 18px; max-height: 26vh; overflow: auto; padding: 10px 2px 4px; border-top: var(--rule); background: none; }
.yard-quote, #expeditionQuote { flex: 1 1 300px; margin: 0; padding-left: 14px; position: relative; color: var(--ink-soft); font-size: var(--small); white-space: pre-line; }
.yard-quote::before, #expeditionQuote::before { content: ""; position: absolute; left: 0; top: .55em; width: 7px; height: 7px; background: var(--verm); transform: rotate(45deg); }
.combat-live { padding: 8px 0; border-top: 1px dotted rgba(30,26,26,.35); white-space: pre-line; }

/* 夜巡 · the patrol is a night painting hung on the sheet */
.combat-stage { position: relative; display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 12px; min-height: calc(28 * var(--u)); margin: 10px 8px 18px;
  padding: 14px 18px 10px; overflow: hidden; color: var(--night-ink); background: var(--night); box-shadow: 0 0 0 4px var(--ink), 0 0 0 7px var(--paper), 10px 12px 0 7px rgba(218,68,44,.35);
  isolation: isolate; }
.combat-stage .cs-wall { position: absolute; inset: 0; z-index: -2; background: var(--night) center/cover no-repeat; filter: saturate(.7) brightness(.5); }
.combat-stage::after { content: ""; position: absolute; inset: 0; z-index: -1; background: radial-gradient(ellipse at 50% 120%, rgba(255,176,32,.16), transparent 60%), linear-gradient(180deg, transparent 40%, rgba(12,10,9,.8)); }
.combat-stage .cs-side { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.combat-stage .cs-fig { height: calc(17 * var(--u)); max-width: 100%; object-fit: contain; filter: drop-shadow(0 0 12px rgba(255,176,32,.3)); }
.combat-stage .cs-keeper .cs-fig { transform: scaleX(-1); filter: drop-shadow(6px 4px 0 rgba(218,68,44,.35)); }
.combat-stage .cs-foe .cs-fig { transform-origin: 50% 100%; animation: sway 6s ease-in-out infinite; }
.combat-stage:not(.live) .cs-foe .cs-fig, .combat-stage.waiting .cs-foe .cs-fig { display: none; }
.combat-stage .cs-bar { width: min(220px, 100%); height: 6px; background: rgba(238,227,204,.14); }
.combat-stage .cs-bar i { display: block; height: 100%; width: 0; transition: width .35s ease; }
.combat-stage .cs-keeper .cs-bar i { background: var(--glow); }
.combat-stage .cs-foe .cs-bar i { background: var(--verm); }
.combat-stage .cs-name { font-family: "Kai", serif; font-weight: normal; font-size: max(15px, calc(2 * var(--u))); text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combat-stage .cs-rule { font-style: normal; font-size: 13px; color: #A99D8A; text-align: center; }
.combat-stage .cs-mid { display: flex; flex-direction: column; align-items: center; gap: 8px; align-self: center; min-width: 64px; }
.combat-stage .cs-vs { font-family: "Kai", serif; font-size: max(13px, calc(3.4 * var(--u))); color: rgba(238,227,204,.4); }
.combat-stage .cs-stamp { width: calc(7 * var(--u)); height: calc(7 * var(--u)); min-width: 44px; min-height: 44px; font-size: max(13px, calc(4 * var(--u))); opacity: 0; }
.combat-stage .cs-stamp:empty { display: none; }
.combat-stage .cs-stamp.hit { animation: imprint 1.6s ease-out forwards; --r: -8deg; }
.combat-stage .cs-drops { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 10px; font-size: 13px; color: var(--glow); }
.combat-stage .cs-drops span { display: inline-flex; align-items: center; gap: 2px; }
.combat-stage .cs-drops img { width: 22px; height: 22px; object-fit: contain; }
.combat-stage .cs-line { position: absolute; right: 18px; top: 12px; display: flex; gap: 6px; }
.combat-stage .cs-line img { height: calc(6 * var(--u)); min-height: 36px; object-fit: contain; opacity: .35; filter: grayscale(1) blur(.5px); }
.combat-stage.live .cs-line { display: none; }
/* 案卷 · the case premise is pasted in like a slip; each step carries a seal */
.dossier-premise { position: relative; margin: 8px 0 12px; padding: 12px 16px; white-space: pre-line; background: var(--paper-dark); box-shadow: var(--print); border-left: 5px solid var(--ink); }
.dossier-premise::before { content: attr(data-title); display: block; margin-bottom: 4px; font-family: "Kai", serif; font-size: max(19px, calc(2.6 * var(--u))); }
.yard-card.dossier-step { position: relative; padding-right: 80px; }
.yard-card.dossier-step::after { position: absolute; right: 10px; top: 16px; width: 50px; height: 50px; font-size: 24px; }
.yard-card.dossier-step[data-status="locked"], .yard-card.dossier-step[data-status="full_version"] { opacity: .5; }
.yard-card.dossier-step[data-status="locked"]::after { content: "封"; background: transparent; color: var(--muted); border: 2px dashed var(--muted); outline: 0; filter: none; }
.yard-card.dossier-step[data-status="available"]::after { content: "待"; background: transparent; color: var(--verm-deep); border-color: var(--verm-deep); }
.yard-card.dossier-step[data-status="observing"]::after { content: "查"; }
.yard-card.dossier-step[data-status="proved"]::after { content: "呈"; }
.yard-card.dossier-step[data-status="claimed"]::after { content: "結"; background: var(--ink); outline-color: var(--ink); }
.yard-card.dossier-step[data-status="failed"]::after { content: "敗"; background: #5a1a12; }
html[lang="en"] .yard-card.dossier-step[data-status]::after { font-size: 20px; }
/* 委托 · notices pinned to the sheet */
.yard-card.notice { max-width: 520px; margin: 14px 0; padding: 22px 16px 14px; border: 0; background: var(--paper-dark); box-shadow: var(--print); transform: rotate(-.5deg); }
.yard-card.notice:nth-child(even) { transform: rotate(.6deg); }
.yard-card.notice::before { content: ""; position: absolute; top: 7px; left: 50%; width: 12px; height: 12px; margin-left: -6px; background: var(--verm); transform: rotate(45deg); box-shadow: 0 0 0 2px var(--paper); }
.yard-card.notice { position: relative; }
.yard-card.notice.shelved { opacity: .55; }

/* 院务 · garden beds, town map, lineage, gear */
#yard-farm .yard-list { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
.plot-bed { --grow: 0; position: relative; height: calc(12 * var(--u)); min-height: 84px; margin: 4px 0 8px; overflow: hidden;
  background: repeating-linear-gradient(180deg, #5b3021 0 9px, #3e1f15 9px 12px, #6E3B2A 12px 20px); box-shadow: 8px 10px 0 rgba(30,26,26,.2); }
.yard-card[data-state="empty"] .plot-bed { filter: saturate(.6) brightness(.9); }
.plot-bed .pb-sprout { position: absolute; left: 50%; bottom: 14px; width: 64px; height: 64px; margin-left: -32px; display: grid; place-items: end center; }
.plot-bed .pb-sprout img { width: 64px; height: 64px; object-fit: contain; transform-origin: 50% 100%; transform: scale(calc(.5 + .5 * var(--grow))); opacity: calc(.7 + .3 * var(--grow));
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.4)); transition: transform .6s ease; }
.yard-card[data-state="ripe"] .plot-bed .pb-sprout img { filter: drop-shadow(0 0 10px rgba(255,176,32,.9)); }
.yard-card[data-state="ripe"] .plot-bed::after { content: "熟"; position: absolute; right: 10px; top: 10px; width: 34px; height: 34px; font-size: 20px; }
html[lang="en"] .yard-card[data-state="ripe"] .plot-bed::after { content: "Ripe"; width: auto; padding: 0 6px; font-size: 13px; }
.plot-bed .pb-grow, .plot-bed .pb-fert { position: absolute; left: 10px; right: 10px; height: 4px; background: rgba(0,0,0,.35); overflow: hidden; }
.plot-bed .pb-grow { bottom: 8px; } .plot-bed .pb-fert { bottom: 3px; height: 2px; }
.plot-bed .pb-grow i { display: block; height: 100%; width: 0; background: var(--glow); transition: width .4s linear; }
.plot-bed .pb-fert i { display: block; height: 100%; background: #C9A25A; }
.town-meters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 24px; margin: 8px 0 14px; }
.town-meters .tm { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; font-family: "Kai", serif; font-size: max(15px, calc(1.8 * var(--u))); }
.town-meters b { height: 4px; background: rgba(30,26,26,.18); overflow: hidden; }
.town-meters b i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .3s; }
.town-meters .tm.over b i { background: var(--verm); }
.town-meters em { font-style: normal; font-family: "SerifSC", serif; font-size: var(--small); font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.town-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px 26px; margin: 0 0 14px; }
.town-district h4 { margin: 0 0 6px; font-family: "Kai", serif; font-weight: normal; font-size: max(18px, calc(2.4 * var(--u))); border-bottom: var(--rule); }
.town-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.town-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; min-height: 76px; min-width: 0; padding: 14px 2px 4px; font: inherit; color: var(--ink);
  background: rgba(238,227,204,.6); border: 1px solid rgba(30,26,26,.5); cursor: pointer; }
.town-tile::before { content: ""; position: absolute; left: -4px; right: -4px; top: -2px; height: 9px; background: var(--ink); clip-path: polygon(0 100%, 10% 0, 90% 0, 100% 100%); }
.town-tile .tt-glyph { font-family: "Kai", serif; font-size: max(20px, calc(2.8 * var(--u))); line-height: 1; }
.town-tile .tt-name, .town-tile .tt-state { font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.town-tile[data-state="active"] { box-shadow: var(--print); }
.town-tile[data-state="active"]::before { background: var(--verm-deep); }
.town-tile[data-state="active"] .tt-state { color: var(--verm-deep); }
.town-tile[data-state="inactive"] .tt-state { color: var(--verm-deep); }
.town-tile[data-state="inactive"] { border-color: var(--verm-deep); }
.town-tile[data-state="building"] { background: repeating-linear-gradient(135deg, rgba(238,227,204,.6) 0 6px, rgba(30,26,26,.08) 6px 12px); }
.town-tile[data-state="open"] { border-style: dashed; }
.town-tile[data-state="locked"] { opacity: .35; border-style: dashed; }
.town-tile[aria-pressed="true"] { outline: 2px solid var(--verm); outline-offset: 2px; }
#yard-lineage .gen-node { position: relative; display: grid; grid-template-columns: 76px 1fr; column-gap: 16px; align-items: start; border-top: 0; padding: 6px 0 18px; }
#yard-lineage .gen-node > :not(.gen-mark) { grid-column: 2; }
#yard-lineage .gen-node > .yard-button { justify-self: start; }
#yard-lineage .gen-node .gen-mark { grid-row: 1 / span 3; width: 66px; height: 66px; border-radius: 50%; display: grid; place-items: center; align-content: center;
  background: var(--paper-dark); box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--paper); color: var(--ink-soft); }
#yard-lineage .gen-node .gen-mark b { font-family: "Kai", serif; font-weight: normal; font-size: 30px; line-height: 1; }
#yard-lineage .gen-node .gen-mark span { font-size: 13px; font-variant-numeric: tabular-nums; }
#yard-lineage .gen-node[data-owned="true"] .gen-mark { background: var(--verm-deep); color: #F3EBD8; box-shadow: 0 0 0 3px var(--verm), 0 0 0 6px var(--paper), 0 0 22px 4px rgba(255,176,32,.45); }
#yard-lineage .gen-node + .gen-node::before { content: ""; position: absolute; left: 37px; top: -14px; width: 2px; height: 18px; background: var(--verm-deep); }
#yard-lineage .gen-node[data-ready="true"] h3::after { content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 10px; vertical-align: middle; background: var(--glow); transform: rotate(45deg); }
#yard-lineage .permit { position: relative; padding-left: 46px; min-height: 36px; }
#yard-lineage .permit::before { content: "未"; position: absolute; left: 0; top: -2px; width: 32px; height: 32px; font-size: 17px; background: transparent; color: var(--muted); border: 2px dashed var(--muted); outline: 0; filter: none; }
#yard-lineage .permit[data-granted="true"]::before { content: "准"; background: var(--verm-deep); color: #F3EBD8; border: 2px solid #F3EBD8; outline: 1px solid var(--verm-deep); filter: url(#rough); }
.gear-figure { display: grid; grid-template-columns: minmax(0, 260px) minmax(160px, 220px) minmax(0, 260px); justify-content: center; gap: 14px; align-items: center; margin: 4px 0 14px; }
.gear-figure .gf-col { display: flex; flex-direction: column; gap: 12px; }
.gear-figure .gf-body { display: grid; place-items: center; }
.gear-figure .gf-keeper { height: calc(34 * var(--u)); max-width: 100%; object-fit: contain; filter: drop-shadow(8px 6px 0 rgba(218,68,44,.35)); }
.gear-slot { display: grid; grid-template-columns: 52px minmax(0, 1fr); column-gap: 10px; align-items: center; min-height: 60px; min-width: 0; padding: 4px; font: inherit; text-align: left;
  color: var(--ink); background: none; border: 0; cursor: pointer; }
.gear-slot img, .gear-slot[data-filled="false"]::before { grid-column: 1; grid-row: 1 / span 2; width: 48px; height: 48px; object-fit: contain; background: var(--paper-dark);
  box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--paper), 4px 5px 0 4px rgba(218,68,44,.3); }
.gear-slot[data-filled="false"]::before { content: ""; background: transparent; box-shadow: 0 0 0 1px rgba(30,26,26,.4); border: 1px dashed rgba(30,26,26,.35); }
.gear-slot .gs-name, .gear-slot .gs-item { grid-column: 2; }
.gear-slot .gs-name { font-family: "Kai", serif; font-size: 15px; color: var(--muted); }
.gear-slot .gs-item { font-size: var(--small); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.gear-slot:hover .gs-item { color: var(--verm-deep); }
.gf-right .gear-slot { grid-template-columns: minmax(0, 1fr) 52px; text-align: right; }
.gf-right .gear-slot img, .gf-right .gear-slot[data-filled="false"]::before { grid-column: 2; }
.gf-right .gear-slot .gs-name, .gf-right .gear-slot .gs-item { grid-column: 1; }
.yard-effects { font-size: var(--small); color: var(--ink-soft); }

/* 诡异志 · 灵宠: the record book lies open on the first page; lamp and lanterns follow */
#p-anom, #p-pets { --w: calc(var(--page) * 1.9) !important; }
#p-anom .ghost-faint, #p-anom .ghost-lit { left: calc(var(--page) * 1.02); width: calc(var(--page) * .85); }
#p-pets .pets, #p-pets .beam { left: calc(var(--page) * 1.02); width: calc(var(--page) * .85); }
#p-pets .bonds { left: calc(var(--page) * 1.05); width: calc(var(--page) * .7); }
#p-anom .whisper { right: auto; left: calc(var(--page) * 1.75); }
.collection-book { left: calc(3vw + calc(16 * var(--u))); right: auto; width: calc(var(--page) * .95 - 3vw - calc(16 * var(--u))); z-index: 5; }
.collection-book.yard-inner { overflow: hidden; display: block; padding: 0; background: none; border: 0; }
.night .collection-book { color: var(--night-ink); }
.candidate-note { position: absolute; left: calc(var(--page) * 1.05); bottom: calc(2 * var(--u)); width: calc(var(--page) * .75); font-size: var(--small); color: var(--muted); letter-spacing: .1em; }
.night .candidate-note { color: #6b5f52; }
.book-spread { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); height: 100%; gap: 0; }
.leaf { overflow-y: auto; overscroll-behavior: contain; padding: 4px 22px 10px 0; min-height: 0; }
.leaf-right { padding: 4px 4px 10px 22px; border-left: var(--rule); }
.night .leaf-right { border-left-color: rgba(238,227,204,.3); }
.leaf .yard-title { font-size: max(26px, calc(3.6 * var(--u))); margin: 0 0 4px; }
.leaf p { font-size: var(--small); line-height: 1.55; white-space: pre-line; overflow-wrap: anywhere; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 14px 10px; margin-top: 12px; }
.book-tile { position: relative; min-width: 0; height: 100px; padding: 6px 2px 0; display: flex; flex-direction: column; align-items: center; gap: 4px; font-family: inherit; color: inherit;
  background: rgba(238,227,204,.5); border: 1px solid rgba(30,26,26,.45); box-shadow: var(--print); cursor: pointer; overflow: hidden; }
.night .book-tile { background: rgba(26,23,20,.6); border-color: rgba(238,227,204,.35); box-shadow: 3px 3px 0 rgba(255,176,32,.2); }
.book-tile img { width: 56px; height: 56px; object-fit: contain; }
.night .book-tile img { filter: drop-shadow(0 0 8px rgba(255,176,32,.35)); }
.book-tile.figure img { height: 64px; width: 48px; }
.book-tile .glyph { height: 56px; display: grid; place-items: center; font-family: "Kai", serif; font-size: 30px; color: var(--muted); }
.book-tile .name { display: block; width: 100%; text-align: center; font-family: "Kai", serif; font-size: 14px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 3px; }
.book-tile.unseen { box-shadow: none; border-style: dashed; background: transparent; }
.book-tile.unseen img { opacity: .06; filter: blur(2px) grayscale(1); }
.book-tile.verified::after { content: "考"; position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; display: grid; place-items: center; font-family: "Kai", serif; font-size: 14px;
  color: #F3EBD8; background: var(--verm-deep); border: 1px solid #F3EBD8; transform: rotate(-9deg); }
.book-tile.on { outline: 2px solid var(--verm); outline-offset: 2px; }
.book-tile.companion { background: none; border: 0; box-shadow: none; height: 108px; }
.book-tile.companion .ring { position: absolute; top: 2px; left: 50%; width: 68px; height: 68px; margin-left: -34px; border-radius: 50%; background: conic-gradient(var(--verm) var(--p, 0deg), rgba(122,110,96,.3) 0); }
.book-tile.companion img, .book-tile.companion .glyph { position: relative; z-index: 1; width: 60px; height: 60px; margin-top: 2px; border-radius: 50%; object-fit: cover; background: #ccc;
  box-shadow: 0 0 0 2px var(--ink); }
.book-tile.companion.unmet img { filter: grayscale(1) brightness(.9) contrast(.9); }
.book-tile.companion.bonded .ring { box-shadow: 0 0 18px 5px rgba(255,176,32,.55); }
.book-tile.companion.on { outline: 0; } .book-tile.companion.on .ring { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--verm); }
.book-plate { position: relative; width: 160px; height: 160px; margin: 6px auto 14px; background: var(--paper-dark); box-shadow: var(--frame); display: grid; place-items: center; overflow: hidden; }
.night .book-plate { background: var(--night-2); box-shadow: 0 0 0 3px #CFC4AE, 0 0 0 6px var(--night), 6px 8px 0 6px rgba(255,176,32,.25); }
.book-plate img { max-width: 86%; max-height: 86%; object-fit: contain; }
.book-plate.figure { width: 160px; height: 240px; }
.book-plate.unseen { background: repeating-linear-gradient(135deg, var(--paper-deep) 0 6px, rgba(122,110,96,.18) 6px 7px); }
.night .book-plate.unseen { background: var(--night-2); }
.book-plate.unseen::after { content: "？"; font-family: "Kai", serif; font-size: 64px; color: rgba(122,110,96,.7); }
.book-plate.verified::before { content: "考"; position: absolute; right: 6px; top: 6px; z-index: 2; width: 36px; height: 36px; display: grid; place-items: center; font-family: "Kai", serif; font-size: 22px;
  color: #F3EBD8; background: var(--verm-deep); border: 2px solid #F3EBD8; transform: rotate(-9deg); }
.book-plate.round { border-radius: 50%; }
.book-plate.round img { width: 100%; height: 100%; max-width: 100%; max-height: 100%; object-fit: cover; }
.book-plate.round.unmet img { filter: grayscale(1) brightness(.92) contrast(.9); }
.book-plate.round.bonded { box-shadow: 0 0 0 3px var(--verm), 0 0 0 6px var(--paper), 0 0 30px 6px rgba(255,176,32,.55); }
.night .yard-button { color: var(--night-ink); background: rgba(26,23,20,.5); border-color: rgba(238,227,204,.45); box-shadow: 3px 3px 0 rgba(255,176,32,.25); }
.night .yard-field, .night .yard-note, .night .yard-details { color: #A99D8A; }
.night .yard-field select, .night .yard-field input { color: var(--night-ink); border-bottom-color: rgba(238,227,204,.5); }
.night .yard-field select option { color: var(--ink); }
.night .yard-review { border-top-color: rgba(238,227,204,.3); }
.night .yard-quote { color: #CFC4AE; }

/* ---------- 库房: apothecary cabinet; drawer controls surface on hover / focus ---------- */
#p-store .stock-toolbar { position: absolute; left: 13%; right: 27%; top: calc(2 * var(--u)); display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
#p-store .stock-toolbar input { flex: 1 1 200px; }
#p-store .stock-toolbar button { margin: 0; }
#p-store .stock-toolbar button.on { color: #F3EBD8; background: var(--verm-deep); border-color: var(--verm-deep); }
#p-store .stock-toolbar span { flex-basis: 100%; font-size: var(--small); color: var(--muted); }
.stock-tabs { position: absolute; left: 13%; right: 27%; top: calc(2 * var(--u) + 104px); display: flex; flex-wrap: wrap; gap: 0 calc(2 * var(--u)); }
.stock-tabs button { position: relative; margin: 0; padding: 0 4px 0 16px; background: none; border: 0; box-shadow: none; color: var(--muted); font-size: max(16px, calc(2 * var(--u))); }
.stock-tabs button::before { content: ""; position: absolute; left: 2px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; background: #A99D8A; transform: rotate(45deg); }
.stock-tabs button:hover { transform: none; box-shadow: none; color: var(--ink); }
.stock-tabs button.on { color: var(--ink); } .stock-tabs button.on::before { background: var(--verm); }
#p-store .cabinet { top: calc(2 * var(--u) + 152px); bottom: calc(6 * var(--u)); left: 13%; width: 58%; max-height: none; overflow: auto;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); grid-auto-rows: max-content; align-content: start; gap: .8vh; }
#p-store.render-mode .cabinet { bottom: calc(6 * var(--u) + 120px); }
#p-store .drawer { min-height: 0; height: auto; padding: 0; gap: 0; display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; }
#p-store .drawer .face { position: relative; width: 100%; height: 118px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 16px 4px 6px; }
#p-store .drawer .pull { position: absolute; top: 6px; left: 50%; width: 14px; height: 14px; margin-left: -7px; border: 2px solid #C9A25A; border-radius: 50%; border-top-color: transparent; }
#p-store .drawer .face img { position: static; width: 52px; height: 52px; object-fit: contain; filter: drop-shadow(0 2px 0 rgba(0,0,0,.4)); }
#p-store .drawer .glyph { font-family: "Kai", serif; font-size: 34px; color: #F3EBD8; }
#p-store .drawer .face img, #p-store .drawer .glyph { order: 1; } #p-store .drawer .slip { order: 2; }
#p-store .drawer .slip { display: flex; align-items: baseline; justify-content: center; gap: 4px; width: 100%; padding: 0 4px; color: #F3EBD8; }
#p-store .drawer .slip b { min-width: 0; font-family: "Kai", serif; font-weight: normal; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#p-store .drawer .slip i { font-style: normal; font-size: 13px; color: #C9A25A; }
#p-store .drawer .qty { position: absolute; right: 6px; top: 6px; font-size: 13px; color: var(--glow); font-variant-numeric: tabular-nums; }
#p-store .drawer .kept { position: absolute; left: 6px; top: 6px; padding: 0 4px; font-size: 13px; color: var(--ink); background: #C9A25A; }
#p-store .drawer .cord { display: none; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(135deg, transparent 46%, var(--verm) 46% 54%, transparent 54%); }
#p-store .drawer .cord::after { content: ""; position: absolute; left: 50%; top: 50%; width: 12px; height: 12px; margin: -6px; background: var(--verm); transform: rotate(45deg); box-shadow: 0 0 0 2px #7a1c10; }
#p-store .drawer.locked .cord { display: block; } #p-store .drawer.locked::after { display: none; }
#p-store .drawer .check { display: none; position: absolute; right: 6px; bottom: 30px; width: 22px; height: 22px; background: var(--verm); transform: rotate(45deg); box-shadow: 0 0 0 2px #F3EBD8; }
#p-store .drawer.picked { outline: 3px solid var(--glow); outline-offset: -2px; } #p-store .drawer.picked .check { display: block; }
#p-store .drawer.unpickable .face { opacity: .4; }
#p-store.render-mode .drawer .face { cursor: pointer; }
#p-store .drawer.empty { opacity: 1; } #p-store .drawer.empty .face { opacity: .4; }
/* controls fold into the drawer's lower rail; they show on hover, keyboard focus or touch */
#p-store .drawer .stock-controls { display: flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: #2c140d; opacity: 0; transition: opacity .2s; }
#p-store .drawer:hover .stock-controls, #p-store .drawer:focus-within .stock-controls, #p-store.render-mode .drawer .stock-controls { opacity: 1; }
@media (hover: none) { #p-store .drawer .stock-controls { opacity: 1; } }
#p-store .drawer .stock-controls button { min-width: 44px; min-height: 44px; margin: 0; padding: 0 4px; flex: 1 1 0; font-family: "Kai", serif; font-size: 14px;
  color: #F3EBD8; background: #4a271b; border: 1px solid #6b3a26; box-shadow: none; cursor: pointer; }
#p-store .drawer .stock-controls button:hover, #p-store .drawer .stock-controls button:focus-visible { border-color: var(--glow); outline: none; }
#p-store .drawer .stock-controls .lock-item[aria-pressed="true"] { background: var(--verm-deep); border-color: var(--verm); }
#p-store .drawer .stock-controls .lock-item { order: 1; } #p-store .drawer .stock-controls .render-item { order: 2; }
#p-store .drawer .stock-controls .keep { order: 3; flex: 1 1 60%; display: flex; align-items: center; gap: 2px; min-width: 0; color: #CFC4AE; font-family: "Kai", serif; font-size: 13px; }
#p-store .drawer .stock-controls .reserve-item { order: 4; flex: 0 0 auto; }
#p-store .drawer .stock-controls input { flex: 1 1 auto; width: 100%; min-width: 40px; min-height: 44px; padding: 0 3px; font-size: 14px; text-align: center; color: var(--ink); background: #EEE3CC; border: 0; }
.drag-ghost { width: auto; height: auto; padding: 0; background: none; border: 0; }
.drag-ghost img { width: 64px; height: 64px; object-fit: contain; display: block; }
.render-slip { position: absolute; left: 13%; width: 58%; bottom: calc(6 * var(--u)); z-index: 3; padding: 10px 2px 0; display: grid; gap: 6px; border-top: var(--rule); }
.render-slip[hidden] { display: none; }
.render-slip p { margin: 0; font-size: var(--small); }
.render-slip-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
/* the item page is a slip laid on the cabinet's right */
.item-sheet { position: absolute; right: 3%; top: 16%; bottom: 8%; width: 25%; min-width: 250px; z-index: 6; overflow-y: auto; padding: 18px 18px 14px; color: var(--ink);
  background: var(--paper) var(--grain); border-top: var(--rule); border-bottom: var(--rule); box-shadow: -10px 12px 0 rgba(30,26,26,.25); }
.item-sheet[hidden] { display: none; }
.item-sheet .sheet-close { position: absolute; right: 4px; top: 4px; width: 44px; height: 44px; font-size: 24px; background: none; border: 0; color: var(--ink-soft); cursor: pointer; }
.item-sheet .sheet-head { display: flex; gap: 12px; align-items: center; padding-right: 36px; }
.item-sheet .sheet-head img { width: 64px; height: 64px; object-fit: contain; background: var(--paper-dark); box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--paper), 4px 5px 0 4px rgba(218,68,44,.35); }
.item-sheet .sheet-head b { display: block; font-family: "Kai", serif; font-weight: normal; font-size: 24px; }
.item-sheet .sheet-head small { display: block; font-size: 13px; color: var(--muted); }
.item-sheet .sheet-head em { display: block; font-style: normal; font-size: 13px; color: var(--verm-deep); }
.item-sheet p { margin: 8px 0; font-size: var(--small); line-height: 1.45; }
.item-sheet .sheet-value, .item-sheet .sheet-more { color: var(--ink-soft); }
.item-sheet .sheet-why { color: var(--verm-deep); }
.item-sheet .sheet-amounts { display: flex; flex-wrap: wrap; gap: 2px; }
.item-sheet .sheet-amounts button { margin: 4px 8px 4px 0; padding: 0 10px; font-size: 15px; }
.item-sheet .sheet-quote { padding-left: 14px; position: relative; }
.item-sheet .sheet-quote::before { content: ""; position: absolute; left: 0; top: .55em; width: 7px; height: 7px; background: var(--verm); transform: rotate(45deg); }
.item-sheet h4 { margin: 16px 0 4px; font-family: "Kai", serif; font-weight: normal; font-size: 17px; border-bottom: var(--rule); }
.item-sheet .sheet-link { display: flex; align-items: center; gap: 6px; width: 100%; min-height: 44px; padding: 0 4px; text-align: left; font-family: inherit; font-size: var(--small);
  background: none; border: 0; border-bottom: 1px dotted rgba(30,26,26,.3); color: var(--ink); cursor: pointer; }
.item-sheet .sheet-link:hover, .item-sheet .sheet-link:focus-visible { color: var(--verm-deep); outline: none; }
.item-sheet .sheet-link i { margin-left: auto; font-style: normal; font-size: 13px; color: #F3EBD8; background: var(--ink); padding: 0 4px; }

/* ---------- sheets laid over the desk: craft book, receipt, steward, backup ---------- */
#productionDialog, #offlineDialog, .backup-dialog, #tutorialDialog.steward { color: var(--ink); background: var(--paper) var(--grain); border: 0; border-top: var(--rule); border-bottom: var(--rule);
  box-shadow: 14px 16px 0 rgba(30,26,26,.4), 0 30px 80px rgba(0,0,0,.6); font: var(--body)/1.5 "SerifSC", serif; }
#productionDialog::backdrop, #offlineDialog::backdrop, .backup-dialog::backdrop { background: radial-gradient(ellipse at 50% 120%, rgba(42,33,27,.85), rgba(11,10,9,.9) 70%); }
/* 工艺簿 */
#productionDialog { width: min(1180px, 96vw); height: min(660px, 92vh); max-height: none; padding: calc(2.4 * var(--u)) calc(3 * var(--u)) calc(1.6 * var(--u)); overflow: hidden; }
#productionDialog[open] { display: flex; flex-direction: column; }
#productionDialog header { display: flex; align-items: center; gap: 14px; padding-bottom: 10px; border-bottom: 2px solid var(--verm-deep); }
#productionDialog header h2 { flex: 1; margin: 0; font-family: "Kai", serif; font-weight: normal; font-size: max(24px, calc(3.6 * var(--u))); }
#controlsIcon { width: 52px; height: 52px; object-fit: contain; background: var(--paper-dark); box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--paper), 4px 5px 0 4px rgba(218,68,44,.35); }
#controlsIcon:not([src]), #controlsIcon[src=""] { visibility: hidden; }
#closeControls { width: 44px; height: 44px; font-size: 26px; background: none; border: 0; color: var(--ink-soft); cursor: pointer; }
#controlsNote { margin: 8px 0 4px; font-size: var(--small); color: var(--muted); }
#controlFields { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: min-content; gap: 6px 30px; padding: 4px 6px 4px 0; }
#productionDialog fieldset.cb-panel { margin: 0; padding: 0 0 12px; min-width: 0; border: 0; border-top: var(--rule); }
#productionDialog fieldset.cb-panel legend { padding: 6px 10px 0 0; font-family: "Kai", serif; font-size: max(20px, calc(2.8 * var(--u))); color: var(--ink); }
#productionDialog .cb-options { grid-column: 1 / span 2; } #productionDialog .cb-env { grid-column: 3; }
#productionDialog .cb-panel h4 { margin: 10px 0 2px; font-family: "Kai", serif; font-weight: normal; font-size: 17px; border-top: 1px dotted rgba(30,26,26,.35); padding-top: 8px; }
#productionDialog .cb-panel select { width: 100%; min-height: 44px; margin: 4px 0; font: inherit; color: var(--ink); background: transparent; border: 0; border-bottom: 1px solid rgba(30,26,26,.55); }
#productionDialog .cb-panel button:not(.cb-option) { min-height: 44px; margin: 6px 10px 4px 0; padding: 0 14px; font-family: "Kai", serif; font-size: 17px; color: var(--ink);
  background: rgba(238,227,204,.6); border: 1px solid rgba(30,26,26,.55); box-shadow: var(--print); cursor: pointer; }
#productionDialog .cb-slip { padding-left: 14px; position: relative; font-size: var(--small); color: var(--ink-soft); }
#productionDialog .cb-slip::before { content: ""; position: absolute; left: 0; top: .55em; width: 7px; height: 7px; background: #C9A25A; transform: rotate(45deg); }
#productionDialog .cb-slip:empty { display: none; }
#productionDialog .cb-level { font-family: "Kai", serif; font-size: 18px; margin: 4px 0 0; }
#productionDialog .cb-hint { font-size: 13px; color: var(--muted); }
.cb-scale { position: relative; height: 6px; margin: 26px 4px 10px; background: rgba(30,26,26,.15); }
.cb-scale i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--ink); transition: width .3s; }
.cb-scale b { position: absolute; top: -7px; bottom: -7px; width: 2px; margin-left: -1px; background: rgba(30,26,26,.3); }
.cb-scale b span { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font: 11px/1.6 "SerifSC", serif; color: var(--muted); white-space: nowrap; }
.cb-scale b.on { background: var(--verm-deep); } .cb-scale b.on span { color: var(--verm-deep); }
.cb-effects { list-style: none; margin: 6px 0; padding: 0; font-size: var(--small); }
.cb-effects li { display: flex; gap: 10px; padding: 1px 0; color: var(--muted); }
.cb-effects li em { font-style: normal; min-width: 38px; font-variant-numeric: tabular-nums; }
.cb-effects li.on { color: var(--ink); } .cb-effects li.on em { color: var(--verm-deep); }
.cb-item { display: grid; grid-template-columns: 60px 1fr; column-gap: 14px; align-items: center; padding: 8px 0; }
.cb-item img { grid-row: 1 / span 2; width: 56px; height: 56px; object-fit: contain; background: var(--paper-dark); box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--paper), 4px 5px 0 4px rgba(218,68,44,.35); }
.cb-item b { font-family: "Kai", serif; font-weight: normal; font-size: 20px; }
.cb-item span { font-size: 13px; color: var(--ink-soft); }
.cb-option-cards { display: flex; flex-wrap: wrap; gap: 12px; margin: 6px 0 8px; }
#productionDialog .cb-option { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 150px; margin: 0; padding: 8px 12px; text-align: left; color: var(--ink);
  background: rgba(238,227,204,.6); border: 1px solid rgba(30,26,26,.55); box-shadow: var(--print); cursor: pointer; }
#productionDialog .cb-option b { font-family: "Kai", serif; font-weight: normal; font-size: 16px; }
#productionDialog .cb-option span { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-size: 13px; }
#productionDialog .cb-option img { width: 24px; height: 24px; object-fit: contain; }
#productionDialog .cb-option.on { outline: 2px solid var(--verm); outline-offset: 2px; }
#productionDialog .cb-option.blocked { opacity: .55; }
#productionDialog .cb-foot { display: flex; align-items: center; gap: 18px; margin-top: 10px; padding-top: 10px; border-top: var(--rule); }
#controlQuote { flex: 1; min-height: 44px; display: flex; align-items: center; padding-left: 16px; position: relative; font-size: var(--small); white-space: pre-line; }
#controlQuote::after { content: ""; position: absolute; left: 0; top: 50%; width: 8px; height: 8px; margin-top: -4px; background: var(--verm); transform: rotate(45deg); }
#controlQuote:empty::before { content: attr(data-hint); color: var(--muted); }
#commitControl { min-width: 120px; }
#commitControl[hidden] { display: none; }
@media (max-width: 900px) { #controlFields { grid-template-columns: 1fr; } #productionDialog .cb-options, #productionDialog .cb-env { grid-column: auto; } }
/* 离线回执 */
#offlineDialog { width: min(640px, 92vw); max-height: 86vh; overflow: auto; padding: 0 0 16px; }
#offlineDialog > *:not(.rc-head):not(.offline-actions) { margin-left: 28px; margin-right: 28px; }
#offlineDialog .rc-head { display: flex; align-items: center; gap: 16px; padding: 20px 28px 12px; border-bottom: 2px solid var(--verm-deep); }
#offlineDialog .rc-head h2 { margin: 0; font-family: "Kai", serif; font-weight: normal; font-size: max(26px, calc(3.6 * var(--u))); }
#offlineDialog .rc-seal { flex: none; width: 50px; height: 50px; font-size: 26px; }
#offlineDialog .rc-seal::before { content: "執"; }
#offlineDialog[data-state="busy"] .rc-seal { background: var(--ink); outline-color: var(--ink); } #offlineDialog[data-state="busy"] .rc-seal::before { content: "算"; }
#offlineDialog[data-state="failed"] .rc-seal::before { content: "未"; }
#offlineSummary { font-family: "Kai", serif; font-size: max(19px, calc(2.6 * var(--u))); }
#offlineDialog progress { width: 100%; height: 6px; appearance: none; -webkit-appearance: none; border: 0; background: rgba(30,26,26,.15); }
#offlineDialog progress::-webkit-progress-bar { background: rgba(30,26,26,.15); }
#offlineDialog progress::-webkit-progress-value { background: var(--ink); } #offlineDialog progress::-moz-progress-bar { background: var(--ink); }
#offlineDialog p { overflow-wrap: anywhere; }
#offlineError:not(:empty) { padding-left: 16px; position: relative; color: var(--verm-deep); }
#offlineError:not(:empty)::before { content: ""; position: absolute; left: 0; top: .5em; width: 8px; height: 8px; background: var(--verm); transform: rotate(45deg); }
.rc-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 8px 0 12px; border-top: var(--rule); border-bottom: var(--rule); padding: 8px 0; }
.rc-stat { display: flex; flex-direction: column; align-items: center; }
.rc-stat b { font-family: "Kai", serif; font-weight: normal; font-size: max(26px, calc(3.6 * var(--u))); color: var(--verm-deep); font-variant-numeric: tabular-nums; }
.rc-stat span { font-size: 13px; color: var(--muted); }
.rc-xp { list-style: none; margin: 0 0 8px; padding: 0; columns: 2; column-gap: 24px; font-size: var(--small); }
.rc-xp li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; border-bottom: 1px dotted rgba(30,26,26,.3); break-inside: avoid; }
.rc-xp li span { font-family: "Kai", serif; }
.rc-items summary { cursor: pointer; font-family: "Kai", serif; font-size: 18px; }
.rc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px 12px; margin-top: 6px; }
.rc-grid p { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 6px; margin: 0 !important; font-size: var(--small); }
.rc-grid img { width: 28px; height: 28px; object-fit: contain; }
.rc-grid span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-grid b { font-weight: normal; font-variant-numeric: tabular-nums; color: var(--ink); }
.rc-grid p.neg b { color: var(--verm-deep); }
.rc-stopped { padding-left: 16px; position: relative; color: var(--verm-deep); font-size: var(--small); }
.offline-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: flex-end; position: sticky; bottom: 0; padding: 12px 28px 0; background: var(--paper); }
/* 执事笺: a slip hung under its toggle; the page stays live behind it */
#tutorialDialog.steward { position: fixed; inset: auto; top: max(7vh, 62px); left: calc(var(--roller) + 2vw); z-index: 24; margin: 0; width: min(440px, calc(100vw - 2 * var(--roller) - 4vw));
  max-height: calc(100vh - 220px); overflow: auto; padding: 0 18px 14px; font-size: var(--small); box-shadow: 10px 12px 0 rgba(30,26,26,.4), 0 20px 50px rgba(0,0,0,.5); }
#tutorialDialog.steward header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 -18px 6px; padding: 12px 18px 8px;
  background: var(--paper); border-bottom: 2px solid var(--verm-deep); }
#tutorialDialog.steward h2 { margin: 0; font-family: "Kai", serif; font-weight: normal; font-size: max(22px, calc(3 * var(--u))); }
#tutorialDialog.steward h2::before { content: "箋"; display: inline-grid; place-items: center; width: 32px; height: 32px; margin-right: 10px; font-size: 18px; vertical-align: 3px;
  color: #F3EBD8; background: var(--verm-deep); border: 2px solid #F3EBD8; outline: 1px solid var(--verm-deep); transform: rotate(-8deg); }
#tutorialDialog .yard-button { font-size: 16px; }
#tutorialDots { display: flex; gap: 8px; list-style: none; margin: 8px 0 4px; padding: 0; }
#tutorialDots li { flex: 1; height: 4px; background: rgba(30,26,26,.15); }
#tutorialDots li.done { background: var(--ink); } #tutorialDots li.current { background: var(--verm); box-shadow: 0 0 6px rgba(218,68,44,.6); }
#tutorialProgress { font-family: "Kai", serif; font-size: 18px; margin: 4px 0; }
#tutorialBody { margin: 4px 0; color: var(--ink-soft); }
#tutorialHint { margin: 8px 0; padding-left: 14px; position: relative; color: var(--ink); }
#tutorialHint::before { content: ""; position: absolute; left: 0; top: .55em; width: 7px; height: 7px; background: #C9A25A; transform: rotate(45deg); }
#tutorialHint:empty, #tutorialSupplies:empty, #tutorialChecklist:empty, #tutorialReview:empty { display: none; }
#tutorialSupplies { font-size: 13px; color: var(--muted); }
#tutorialChecklist { white-space: pre-line; }
#tutorialReview { margin: 8px 0; padding-left: 14px; position: relative; }
#tutorialReview::before { content: ""; position: absolute; left: 0; top: .55em; width: 7px; height: 7px; background: var(--verm); transform: rotate(45deg); }
#tutorialActions { display: flex; flex-wrap: wrap; align-items: center; }
#tutorialEnabled { font-size: 14px !important; opacity: .8; }
@media (max-width: 760px) { #tutorialDialog.steward { left: 8px; right: 8px; width: auto; } }
/* 备份 */
.backup-dialog { width: min(800px, 92vw); max-height: 86vh; overflow: auto; padding: 22px 26px; }
.backup-dialog h2 { margin: 0 0 6px; font-family: "Kai", serif; font-weight: normal; font-size: 26px; }
.backup-dialog textarea { box-sizing: border-box; width: 100%; height: 35vh; resize: vertical; font: 13px monospace; color: var(--ink); background: rgba(238,227,204,.6); border: 1px solid rgba(30,26,26,.4); }
/* 恢复页 (boot failure: nothing is written) */
.boot-error { position: relative; max-width: 720px; margin: 12vh auto; padding: 30px 34px 26px; color: var(--ink); background: var(--paper) var(--grain);
  border-top: var(--rule); border-bottom: var(--rule); box-shadow: 14px 16px 0 rgba(30,26,26,.45), 0 30px 80px rgba(0,0,0,.6); font: 17px/1.6 "SerifSC", serif; }
.boot-error::before { content: "護"; position: absolute; right: 26px; top: 24px; width: 56px; height: 56px; display: grid; place-items: center; font: 30px/1 "Kai", serif;
  color: #F3EBD8; background: var(--verm-deep); border: 2px solid #F3EBD8; outline: 1px solid var(--verm-deep); transform: rotate(-8deg); }
.boot-error h1 { margin: 0 80px 12px 0; font-family: "Kai", serif; font-weight: normal; font-size: 30px; line-height: 1.3; }
#recoveryReason { padding-left: 16px; position: relative; color: var(--verm-deep); }
#recoveryReason::before { content: ""; position: absolute; left: 0; top: .55em; width: 8px; height: 8px; background: var(--verm); transform: rotate(45deg); }

@media (max-height: 740px) { .gate .moon { width: min(100%, calc(26 * var(--u))); } }
@media (max-width: 1000px) { #yard-farm .yard-list { grid-template-columns: 1fr; } .yard-book { left: calc(3vw + calc(13 * var(--u))); right: 3vw; } }
@media (max-width: 900px) { .book-spread { grid-template-columns: 1fr; overflow-y: auto; } .leaf { overflow: visible; } .leaf-right { border-left: 0; border-top: var(--rule); padding-left: 0; }
  .item-sheet { width: 44%; } #p-store .cabinet, .render-slip { width: 74%; } #p-store .stock-toolbar, .stock-tabs { right: 8%; } }
@media (max-width: 760px) { .town-meters { grid-template-columns: 1fr; } .gear-figure { grid-template-columns: 1fr 1fr; } .gear-figure .gf-body { display: none; }
  .combat-stage { grid-template-columns: 1fr; } .combat-stage .cs-line { position: static; justify-content: center; } }
@media (prefers-reduced-motion: reduce) { html:not([data-ui-scale]) *, html:not([data-ui-scale]) *::before, html:not([data-ui-scale]) *::after { animation: none !important; transition: none !important; } }

/* Lamp reveal states: unseen = a shadow only, seen = the figure, verified = sealed */
.ghost-faint .ghost.unseen { opacity: .02; }
.ghost-lit .ghost.unseen img { filter: brightness(0) blur(1px); opacity: .55; }
.ghost-lit .ghost.unseen .tag { color: #6b5f52; }
.ghost-faint .ghost.seen { opacity: .08; }
.ghost { cursor: pointer; }
body.lamp-on .ghost { cursor: none; }
.pet:not(.met) .disc img { opacity: .55; }
.pet:not(.met) .knot { background: #6b5f52; }
:lang(en) .seal { font-family: "SerifSC", serif; font-size: max(13px, calc(1.3 * var(--u))); line-height: 1.15; }
.seal { overflow: hidden; word-break: break-all; }
.pet.small { width: calc(12 * var(--u)); } .pet.small .disc { width: calc(12 * var(--u)); height: calc(12 * var(--u)); }
.ghost-faint .ghost, .ghost-lit .ghost { transform-origin: 50% 100%; }

/* Reserve desk space for the top ledger bar; native focus scrolling folds into handscroll offset. */
#viewport { top: max(102px, 11vh); }
.panel { overflow: clip; }
#ledger { top: 56px; right: calc(var(--roller) + 2vw); pointer-events: none; }
#ledger .plaque { display: flex; align-items: center; gap: 18px; min-width: 0; margin: 0; padding: 2px 10px; }
#ledger .row { gap: 6px; font-size: 13px; line-height: 26px; white-space: nowrap; }
#ledger .cord { position: absolute; left: 100%; top: 10px; width: 10px; height: 2px; }
#ledger .tassel { position: absolute; left: calc(100% + 7px); top: 8px; width: 18px; height: 30px; object-fit: contain; margin: 0; }
#saveStatus, :lang(en) #saveStatus { top: 55px; left: calc(var(--roller) + 2vw); right: auto; max-width: 35vw; min-height: 34px; font-size: 13px; }
#saveStatus.error { z-index: 26; max-width: none; right: calc(var(--roller) + 2vw); }
#tutorialBtn, #workshopJump { min-height: 44px; }
.gate .wo-meta, .gate .chip, .gate .wo-out .secs { font-size: var(--data); }
.gate .chip { flex-wrap: wrap; justify-content: center; }
.gate .chip.short b { max-width: none; white-space: normal; }
.gate .wo-status { max-width: 100%; overflow-wrap: anywhere; }
@media (max-height: 799px) { .gate .moon { width: min(100%, calc(22 * var(--u))); } }
@media (max-width: 1100px) {
  :lang(en) #tutorialBtn { left: calc(var(--roller) + 2vw + 60px); }
  :lang(en) #workshopJump { left: calc(var(--roller) + 2vw + 240px); }
  #ledger .plaque { gap: 10px; }
  #saveStatus, :lang(en) #saveStatus { max-width: 22vw; }
}
