:root {
  --ink: #2b2118;
  --red: #a3221c;
  --f-name: "Yuji Syuku", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --f-text: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --f-hand: "Zen Kurenaido", "Hiragino Maru Gothic ProN", sans-serif;
  --sw: min(350px, calc(100vw - 28px));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0f0906;
  overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#board { position: fixed; left: 50%; top: 0; transform: translateX(-50%); display: block; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.vh button { font-size: 1px; }

#dim { position: fixed; inset: 0; background: #000; opacity: 0; transition: opacity 320ms cubic-bezier(.2,.8,.2,1); }
#dim.on { opacity: .55; }
#dim.book { background: #0b0705; }
#dim.book.on { opacity: .9; }
#dim.closing { transition-duration: 240ms; }
#dim[hidden] { display: none; }

/* ---------- 詳細シート ---------- */
#sheetWrap { position: fixed; inset: 0; display: grid; place-items: center; }
#sheetWrap[hidden] { display: none; }
#sheet {
  position: relative; width: var(--sw);
  height: min(calc(100dvh - 44px), calc(var(--sw) * 1.86));
  color: var(--ink); font-family: var(--f-text);
  transition: transform 320ms cubic-bezier(.2,.8,.2,1), opacity 200ms linear;
  will-change: transform; filter: drop-shadow(0 14px 22px rgba(0,0,0,.6));
}
#sheet.closing { transition: transform 240ms cubic-bezier(.4,0,.8,.4), opacity 240ms linear; }
#sheet.rm, #sheet.rm.closing { transition: opacity 120ms linear; }
.sheet-bg, .sheet-dmg { position: absolute; inset: 0; pointer-events: none; }
.sheet-bg {
  border-style: solid;
  border-width: calc(var(--sw) * 285 / 1050) calc(var(--sw) * 100 / 1050) calc(var(--sw) * 340 / 1050);
  border-image: url(../img/sheet.webp) 285 100 340 100 fill / 1 / 0 stretch;
}
.sheet-dmg { background: center / 100% 100% no-repeat; opacity: .9; inset: 1.5%; }
.sheet-body {
  position: absolute; left: calc(var(--sw) * .115); right: calc(var(--sw) * .115);
  top: calc(var(--sw) * .262); bottom: calc(var(--sw) * .095);
  overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  scrollbar-width: none; padding-bottom: calc(var(--sw) * .26);
  -webkit-mask-image: linear-gradient(#000 calc(100% - 22px), transparent);
          mask-image: linear-gradient(#000 calc(100% - 22px), transparent);
}
.sheet-body::-webkit-scrollbar { display: none; }
.sheet-seal { /* 蝋の封印は文字より手前に重ね直す（文字が封印の下をくぐる） */
  position: absolute; pointer-events: none;
  right: calc(var(--sw) * 62 / 1050); bottom: calc(var(--sw) * 105 / 1050);
  width: calc(var(--sw) * 200 / 1050); height: calc(var(--sw) * 215 / 1050);
  background: url(../img/sheet.webp) no-repeat; background-size: var(--sw) auto;
  background-position: calc(var(--sw) * -788 / 1050) calc(var(--sw) * -1127 / 1050);
  clip-path: ellipse(44% 43% at 50% 46%);
}
.d-title { font-family: var(--f-name); font-size: 25px; line-height: 1.3; text-align: center; margin: 2px 0 4px; letter-spacing: .04em; }
.d-rule { height: 9px; margin: 0 18% 10px; background:
  linear-gradient(var(--ink), var(--ink)) center / 100% 1px no-repeat,
  radial-gradient(circle, var(--ink) 2.4px, transparent 3px) center / 9px 9px no-repeat; opacity: .6; }
.d-head { display: flex; border: 1px solid rgba(43,33,24,.55); outline: 1px solid rgba(43,33,24,.25); outline-offset: 2px; margin: 4px 2px 14px; }
.d-head > div { flex: 1; padding: 6px 9px 8px; min-width: 0; }
.d-head > div + div { border-left: 1px solid rgba(43,33,24,.4); }
.d-label { font-size: 11px; letter-spacing: .12em; opacity: .72; margin-bottom: 2px; }
.d-big { font-size: 17px; font-weight: 600; line-height: 1.35; }
.d-sub { font-size: 12px; opacity: .8; }
.d-red { color: var(--red); opacity: 1; }
.d-status { margin: 0 2px 12px; border-top: 1px solid rgba(43,33,24,.5); }
.d-status > div { display: grid; grid-template-columns: 5.6em 1fr; border-bottom: 1px solid rgba(43,33,24,.3); }
.d-status .d-label { padding: 7px 4px 6px 2px; margin: 0; border-right: 1px solid rgba(43,33,24,.3); align-self: stretch; }
.d-status .d-val { padding: 5px 4px 6px 9px; }
.d-val { font-size: 14px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.d-body { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 0 4px 14px; }
.d-body > .full { grid-column: 1 / -1; }
.d-stamp { display: inline-block; border: 1.5px solid currentColor; border-radius: 3px; padding: 0 7px; font-weight: 600; transform: rotate(-2deg); letter-spacing: .1em; }
.d-note { display: block; font-size: 12.5px; opacity: .85; margin-top: 2px; }
.d-dots i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid var(--ink); margin-right: 4px; vertical-align: -1px; }
.d-dots i.on { background: var(--ink); }
.d-ticks { display: flex; gap: 3px; margin-top: 4px; }
.d-ticks i { flex: 1; height: 5px; border: 1px solid var(--ink); opacity: .7; }
.d-ticks i.on { background: var(--ink); }
.d-list { margin: 0; padding-left: 1.1em; font-size: 13.5px; line-height: 1.55; }
.d-sec { display: flex; align-items: center; gap: 8px; font-size: 12px; letter-spacing: .2em; margin: 4px 2px 8px; opacity: .8; }
.d-sec::before, .d-sec::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .6; }
.d-chain { margin: 0 6px 14px; }
.d-chainrow { margin-bottom: 10px; }
.d-node { position: relative; padding: 1px 0 9px 20px; font-size: 13.5px; line-height: 1.5; }
.d-node::before { content: ""; position: absolute; left: 5px; top: 0; bottom: 0; width: 1.5px; background: #9e2b25; }
.d-node::after { content: ""; position: absolute; left: 2px; top: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--ink); }
.d-node.stuck::after { background: #9e2b25; width: 11px; height: 11px; left: 0; top: 5px; box-shadow: 0 0 0 2px rgba(158,43,37,.25); }
.d-node.stuck { color: var(--red); font-weight: 600; }
.d-node.me { font-weight: 600; }
.d-node:last-child::before { bottom: auto; height: 10px; }
.d-memo { font-family: var(--f-hand); font-size: 15.5px; line-height: 1.75; white-space: pre-wrap; margin: 0 6px 10px; padding: 9px 12px 11px;
  background: rgba(255,250,232,.5); box-shadow: 0 1px 3px rgba(60,40,20,.35); transform: rotate(-.6deg); }
.d-why { font-size: 13.5px; line-height: 1.6; margin: 0 6px 10px; padding-left: 9px; border-left: 3px double var(--red); }

/* ---------- 本 ---------- */
#bookWrap { position: fixed; inset: 0; perspective: 1400px; overflow: hidden; }
#bookWrap[hidden] { display: none; }
#bookCover {
  position: absolute; left: 50%; top: 50%; width: min(84vw, 62dvh, 380px); height: auto;
  margin: 0; transform-origin: 0 50%; backface-visibility: hidden;
  transition: transform 320ms cubic-bezier(.2,.8,.2,1), opacity 160ms linear 260ms;
  filter: drop-shadow(0 18px 26px rgba(0,0,0,.7)); pointer-events: none; z-index: 2;
}
#bookWrap.open #bookCover { transition: transform 420ms cubic-bezier(.4,0,.2,1), opacity 160ms linear 300ms; opacity: 0; }
#bookPage {
  --pw: min(100vw, 430px, calc((100dvh - 40px) * .62));
  position: absolute; left: 50%; top: 50%; width: var(--pw); height: calc(var(--pw) * 1.6);
  transform: translate(-50%, -50%); opacity: 0; transition: opacity 260ms linear 160ms;
  color: var(--ink);
}
#bookWrap.open #bookPage { opacity: 1; }
#bookWrap.rm #bookCover, #bookWrap.rm #bookPage { transition: opacity 120ms linear !important; }
.page-bg { position: absolute; inset: 0; pointer-events: none; overflow: hidden;
  background: url(../img/open.webp) no-repeat; background-size: calc(var(--pw) * 2.42) auto; background-position: 96.5% 50%; }
#ribbon { position: absolute; left: 17%; top: 0; width: 26px; height: calc(var(--pw) * .21); border: 0; padding: 0; cursor: pointer;
  background: linear-gradient(90deg, #6f1814, #a3221c 45%, #7d1b17); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 88%, 0 100%);
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
#ribbon::after { content: ""; position: absolute; inset: -6px -12px; }
.page-body { position: absolute; left: 18.5%; right: 21%; top: 14.5%; bottom: 13.5%;
  overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(transparent, #000 14px, #000 calc(100% - 18px), transparent);
          mask-image: linear-gradient(transparent, #000 14px, #000 calc(100% - 18px), transparent);
  padding: 14px 4px 20px; }
.page-body::-webkit-scrollbar { display: none; }
.b-door { height: 100%; display: grid; place-items: center; font-family: var(--f-name); font-size: 30px; letter-spacing: .14em; opacity: .85; }
.b-toc-title { font-family: var(--f-name); font-size: 20px; text-align: center; letter-spacing: .2em; margin: 2px 0 14px 34px; }
.b-toc { list-style: none; margin: 0; padding: 0; }
.b-toc button { display: flex; width: 100%; gap: 10px; align-items: baseline; background: none; border: 0; border-bottom: 1px dotted rgba(43,33,24,.5);
  padding: 11px 2px 8px; color: inherit; font: 17px/1.4 var(--f-name); text-align: left; cursor: pointer; }
.b-toc button span:first-child { flex: 1; }
.b-toc button span:last-child { font: 12px var(--f-text); opacity: .75; white-space: nowrap; }
.b-title { font-family: var(--f-name); font-size: 22px; line-height: 1.4; margin: 0 0 2px 36px; }
.b-date { font: 12.5px var(--f-text); opacity: .75; margin: 0 0 14px 36px; }
.b-text { font: 17px/1.9 var(--f-hand); background: repeating-linear-gradient(transparent 0, transparent calc(1.9em - 1px), rgba(90,60,30,.22) calc(1.9em - 1px), rgba(90,60,30,.22) 1.9em); }
.b-text p { margin: 0 0 1.9em; white-space: pre-wrap; }
