:root {
  --paper: #f3f0e8;
  --ink: #17140f;
  --faint: #9c8f78;
  --red: #a8332a;
  --hair: rgba(26, 23, 20, 0.14);
  --grain: rgba(26, 23, 20, 0.035);
  --tombop: 0.12;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #12100e;
    --ink: #ece6da;
    --faint: #5b5145;
    --red: #c2564a;
    --hair: rgba(236, 230, 218, 0.16);
    --grain: rgba(236, 230, 218, 0.03);
    --tombop: 0.07;
  }
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
#grain {
  position: fixed; inset: 0; pointer-events: none;
  background-image: radial-gradient(var(--grain) 1px, transparent 1px);
  background-size: 3px 3px;
}

/* 選ばれなかった続きの堆積 */
#tomb {
  position: fixed;
  inset: 7vh 4vw calc(11vh + env(safe-area-inset-bottom)) 4vw;
  writing-mode: vertical-rl; text-orientation: upright;
  font-size: clamp(9px, 2.4vw, 12px); line-height: 1.6;
  color: var(--faint); opacity: var(--tombop);
  overflow: hidden; pointer-events: none;
}

#page {
  position: fixed;
  inset: 7vh 4vw calc(11vh + env(safe-area-inset-bottom)) 4vw;
  writing-mode: vertical-rl; text-orientation: upright;
  font-size: clamp(15px, 4.2vw, 21px);
  line-height: 1.85; letter-spacing: 0.06em;
  overflow: hidden;
}
/* 筆跡で人を分ける（A2） */
#page span { opacity: 0; animation: ink 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) forwards; }
#page span.orig { color: var(--ink); }
/* 本文は全部が小説家の新作なので、薄くする理由がない。
   --faint は原文と写しを見分けるための名残で、ダークだと紙との差が無く読めなかった。 */
#page span.scribe { color: var(--ink); }
#page span.fixed { color: var(--ink); }
#page span.censored { color: var(--ink); opacity: 1; animation: none; }
#page span.red { color: var(--red); text-decoration: line-through; text-decoration-color: var(--red); }
/* 筋の赤は文の単位で入る。語の赤と同じ太さで打ち消すと、60字が丸ごと潰れて読めない。
   罫は残したまま、帯で囲って「ここからここまでの話」だと分かるようにする。 */
#page span.red.plot { text-decoration-thickness: 1px; background: color-mix(in srgb, var(--red) 13%, transparent); }
#page span.out { animation: unink 0.22s ease-in forwards; }
@keyframes ink { from { opacity: 0; filter: blur(2.5px); } to { opacity: 1; filter: blur(0); } }
@keyframes unink { from { opacity: 1; } to { opacity: 0; filter: blur(3px); } }

/* 欄外の書き込み */
.aside {
  position: fixed;
  writing-mode: vertical-rl; text-orientation: upright;
  font-size: clamp(10px, 2.8vw, 13px); line-height: 1.4;
  pointer-events: none; max-height: 58vh;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  padding: 2px 1px; border-radius: 2px;
  opacity: 0; animation: appear 0.5s ease-out forwards;
}
.aside.red-hand { color: var(--red); }
/* 筋の赤（原作から話が外れた所）。語の赤より一段強く引く。 */
.aside.red-hand.plot { font-weight: 700; border-inline-start: 2px solid var(--red); padding-inline-start: 3px; }
/* 原作ではどうだったか。直しの文と並べるので、赤より薄い手で書く。 */
.aside.why-hand { color: color-mix(in srgb, var(--red) 58%, var(--ink)); font-style: italic; }
.aside.scribe-hand { color: var(--ink); font-style: italic; }
.aside.refused { text-decoration: line-through; text-decoration-thickness: 2px; opacity: 0.5; }
.aside.gone { opacity: 0; transition: opacity 0.9s ease; }
@keyframes appear { from { opacity: 0; transform: translateX(6px); } to { opacity: 0.95; transform: none; } }

/* 奥付（A1）：常設の担当者欄 */
#colophon {
  position: fixed; left: 0; right: 0;
  bottom: 0; height: calc(10vh + env(safe-area-inset-bottom));
  padding: 0 4vw env(safe-area-inset-bottom);
  display: flex; align-items: center; gap: 10px;
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 10px; letter-spacing: 0.06em; color: var(--faint);
  border-top: 1px solid var(--hair);
  background: var(--paper);
}
#colophon .who { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
#colophon .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--hair); }
#colophon .who.busy .dot { background: var(--ink); animation: breathe 1.1s ease-in-out infinite; }
#colophon .who.proof .dot { background: var(--red); }
@keyframes breathe { 0%,100% { opacity: 0.25; } 50% { opacity: 1; } }
#colophon .grow { flex: 1; }
#colophon .state { font-style: italic; opacity: 0.85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 分岐（C5） */
#choice {
  position: fixed; inset: 0; display: none;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(2px);
  padding: 7vh 4vw calc(12vh + env(safe-area-inset-bottom)) 4vw;
  gap: 4vw;
}
#choice.on { display: flex; flex-direction: row-reverse; } /* 縦書きは右から読む */
#choice .opt {
  flex: 1; min-width: 0;
  writing-mode: vertical-rl; text-orientation: upright;
  font-size: clamp(13px, 3.6vw, 18px); line-height: 1.8; letter-spacing: 0.05em;
  border: 1px solid var(--hair); border-radius: 3px;
  padding: 12px 8px; overflow: hidden;
  color: var(--ink);
  background: color-mix(in srgb, var(--paper) 96%, transparent);
  transition: transform 0.15s ease, border-color 0.15s ease;
  cursor: pointer;
}
#choice .opt:active { transform: scale(0.985); border-color: var(--ink); }
#choice .opt.away { color: var(--faint); }

/* 味方を選ぶ「そのままでいい／直させる」は、いまは下の一本の中にある（core.css）。
   ここに画面いっぱいの position:fixed が残っていて、帯を突き抜けて広がっていた。
   広い画面では左380pxの帯を無視して本文の上に重なる（実測 1251px 幅で 0→1251px）。 */

#top {
  position: fixed; left: 0; right: 0; top: env(safe-area-inset-top);
  height: 7vh; display: flex; align-items: center; gap: 10px; padding: 0 4vw;
  font-family: ui-monospace, monospace; font-size: 10px;
  letter-spacing: 0.08em; color: var(--faint);
}
#top .grow { flex: 1; }
#top button {
  font-family: inherit; font-size: 10px; letter-spacing: 0.08em;
  background: none; border: 1px solid var(--hair); color: var(--faint);
  padding: 5px 9px; border-radius: 3px; cursor: pointer;
}
#meter { width: 22vw; max-width: 130px; height: 1px; background: var(--hair); position: relative; }
#meter i { position: absolute; inset: 0 auto 0 0; width: 0%; background: var(--ink); transition: width 0.6s ease; }
#meter b { position: absolute; top: -3px; width: 1px; height: 7px; background: var(--red); left: 0; opacity: 0; transition: left 1s ease; }

/* ---------------------------------------------- 印章＝人物のアイコン */
.seal {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; flex: 0 0 22px;
  border: 1px solid currentColor; border-radius: 2px;
  font-size: 11px; line-height: 1; font-family: "Hiragino Mincho ProN", serif;
  transform: rotate(-3deg); opacity: 0.35; transition: opacity 0.4s ease;
}
.seal.big { width: 40px; height: 40px; flex: 0 0 40px; font-size: 19px; border-width: 1.5px; }
/* 判子の字の色。**役ごとの色はここに全部置く。**他のファイルに書くと、
   下の .face（字を消す指定）と同じ強さでぶつかり、あとに読まれたほうが勝つ。 */
.seal.scribe   { color: var(--ink); }
.seal.novelist { color: var(--ink); }
.seal.proof    { color: var(--red); }
.seal.censor   { color: var(--ink); }
.seal.sponsor  { color: #8a6a1f; }
.seal.editor   { color: var(--ink); border-style: dashed; }

/* 顔。判子の枠はそのままに、中身を似顔絵に差し替える。
   奥付の検印は判子のままにしたいので、.face を付けたものだけ顔になる。 */
.seal.face {
  opacity: 1; transform: none;
  background-repeat: no-repeat; background-position: center top; background-size: cover;
  border-radius: 50%; border-color: rgba(28, 26, 23, 0.22);
}
.seal.face.novelist { background-image: url(/face/novelist.jpg); }
.seal.face.proof    { background-image: url(/face/proof.jpg); border-color: rgba(176, 58, 46, 0.4); }
.seal.face.censor   { background-image: url(/face/censor.jpg); }
.seal.face.sponsor  { background-image: url(/face/sponsor.jpg); border-color: rgba(138, 106, 31, 0.5); }
.seal.face.editor   { background-image: url(/face/editor.jpg); border-style: solid; }
/* **顔を貼ったら、判子の字は出さない。**
   .seal.face { color: transparent } だと役ごとの色（.seal.novelist 等）と
   同じ強さなので、あとに読まれたほうが勝ち、似顔絵の上に「作」「金」が乗る
   （実際に本番でそうなった）。:is() で一段強くして、書く順に左右されないようにする。 */
.seal.face:is(.scribe, .novelist, .proof, .censor, .sponsor, .editor) { color: transparent; }
.who.busy .seal, .seal.lit { opacity: 1; }
.who.busy .seal { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 0.5; } 50% { opacity: 1; } }

#colophon .who { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
#colophon .who .nm { font-size: 10px; }
#colophon .who.you .nm { color: var(--ink); }

/* ---------------------------------------------- 幕開け */
#curtain {
  position: fixed; inset: 0; z-index: 20;
  background: var(--paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 0 10vw; text-align: center;
  transition: opacity 0.9s ease;
}
#curtain.gone { opacity: 0; pointer-events: none; }
#curtain .title { font-size: 17px; letter-spacing: 0.14em; }
#curtain .sub { font-family: ui-monospace, monospace; font-size: 11px; color: var(--faint); letter-spacing: 0.08em; line-height: 2; }
#curtain button {
  margin-top: 8px; font-family: inherit; font-size: 13px; letter-spacing: 0.1em;
  padding: 12px 22px; border: 1px solid var(--ink); border-radius: 3px;
  background: var(--paper); color: var(--ink); cursor: pointer;
}
#cast { display: flex; flex-direction: column; gap: 12px; min-height: 190px; justify-content: center; }
#cast .row {
  display: flex; align-items: center; gap: 12px; text-align: left;
  opacity: 0; transform: translateY(6px);
}
#cast .row.in { animation: stampIn 0.55s cubic-bezier(0.2,0.8,0.3,1) forwards; }
@keyframes stampIn {
  0% { opacity: 0; transform: translateY(6px) scale(1.5) rotate(-14deg); }
  60% { opacity: 1; transform: translateY(0) scale(0.94) rotate(-3deg); }
  100% { opacity: 1; transform: none; }
}
#cast .nm { font-size: 13px; letter-spacing: 0.06em; }
#cast .li { font-size: 11px; color: var(--faint); font-family: ui-monospace, monospace; }
#cast .row.you .nm { text-decoration: underline; text-underline-offset: 4px; }

/* ---------------------------------------------- 相談としての分岐 */
#ask {
  position: fixed; left: 0; right: 0; top: calc(7vh + env(safe-area-inset-top));
  display: none; align-items: center; gap: 8px; padding: 6px 4vw 10px;
  z-index: 6;
}
#ask.on { display: flex; }
#ask .bubble {
  font-size: 12.5px; line-height: 1.6; color: var(--ink);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  border: 1px solid var(--hair); border-radius: 3px; padding: 7px 10px;
}
/* 見出しは横書きで上に、本文は縦書きで下に。縦書きの中に絶対配置すると消える。 */
#choice { padding: 9vh 4vw calc(11vh + env(safe-area-inset-bottom) + 66px) 4vw; }
#choice .pane { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
#choice .lab {
  display: flex; align-items: baseline; gap: 8px;
  font-family: ui-monospace, monospace; font-size: 10.5px;
  letter-spacing: 0.1em; color: var(--faint); padding-left: 2px;
}
#choice .mine { display: none; font-size: 9.5px; color: var(--ink); }
#choice .pane.pref .mine { display: inline; }
#choice .pane.pref .opt { border-color: color-mix(in srgb, var(--ink) 45%, transparent); }
#choice .opt { flex: 1; }

/* ---------------------------------------------- 心の声（吹き出し） */
#voices {
  position: fixed; left: 4vw; right: 4vw;
  bottom: calc(11vh + env(safe-area-inset-bottom) + 6px);
  display: flex; flex-direction: column; gap: 6px;
  align-items: flex-start; pointer-events: none; z-index: 7;
}
.voice {
  display: flex; align-items: flex-start; gap: 7px;
  max-width: 88%;
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.2,0.8,0.3,1);
}
.voice.in { opacity: 1; transform: none; }
.voice .say {
  position: relative;
  font-size: 12.5px; line-height: 1.65; color: var(--ink);
  background: color-mix(in srgb, var(--paper) 95%, transparent);
  border: 1px solid var(--hair); border-radius: 3px;
  padding: 7px 10px;
}
/* 吹き出しの尻尾（印の方を向く） */
.voice .say::before {
  content: ""; position: absolute; left: -5px; top: 9px;
  width: 8px; height: 8px; transform: rotate(45deg);
  background: inherit; border-left: 1px solid var(--hair); border-bottom: 1px solid var(--hair);
}
.voice.proof .say { color: var(--red); border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.voice.censor .say { color: var(--ink); background: var(--ink); border-color: var(--ink); }
.voice.censor .say { color: var(--paper); letter-spacing: 0.2em; }
/* 押された印は濃い。幕開けの4つは押した直後なので既定の薄さを上書きする */
#cast .row.in .seal { opacity: 1; }
/* 返事のボタンが浮いていたころは、吹き出しをその上へ逃がす必要があった。
   いまは帯の中に入っていて、吹き出しは帯の高さ（--barh）を見て避ける。
   ここに 11vh の決め打ちを残すと、body.asking のほうが詳しくて勝ってしまう。 */

/* 書いている先の棒。打っている間だけ点滅する。 */
#page span.caret {
  display: inline-block; width: 0.62em; height: 2px; vertical-align: middle;
  background: var(--ink); opacity: 0; margin: 1px 0;
}
#page.typing span.caret { animation: caret 0.9s step-end infinite; }
@keyframes caret { 0%, 55% { opacity: 0.85; } 56%, 100% { opacity: 0; } }
