/* =============================================================================
 * bunko-engine / core.css — 縦書きの骨格 ＋ 内蔵クローム/設定シートの構造。
 *
 * これ1枚で「読めて・めくれて・設定シートが出る」状態になる（skin なしでも動く）。
 * 色は --bnk-* トークンで受け、既定値もここが持つ。トーンを変えるだけなら
 * skin 側でトークンを上書きする（skin-default.css / 各ホストの skin）。
 *
 * ここの構造（position / transform / スナップ / .bnk-col の寸法）を書き換えると
 * 組版とめくりが壊れる。装飾・配色は触ってよい範囲の外。
 * すべて .bnk-root 配下・bnk- 接頭辞（ホストのページに埋め込んでも衝突しない）。
 * ============================================================================= */

/* ホストが .bnk-root に position（relative/absolute/fixed）と実寸を与えること。
   エンジンの子要素は position:absolute でこの要素を基準に貼る。 */
.bnk-root {
  /* 既定トークン（明るいトーン）。skin で上書きされる。 */
  --bnk-ground: #e6ddc8;
  --bnk-page-bg: #f6f1e4;
  --bnk-ink: #2a251f;
  --bnk-ink-soft: #6f6555;
  --bnk-chrome-bg: rgba(28, 24, 19, 0.85);
  --bnk-chrome-ink: #f4efe4;
  --bnk-accent: #9a3b2e;
  --bnk-kei-color: #3f6b7a;

  overflow: hidden;
  background: var(--bnk-ground);
  color: var(--bnk-ink);
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
.bnk-root *,
.bnk-root *::before,
.bnk-root *::after {
  box-sizing: border-box;
}

/* ===== deck / pages ===== */
.bnk-deck {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: row; /* pages を逆順 append → page 0 が右端（漫画開き） */
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior: contain;
  touch-action: pan-x;
  scrollbar-width: none;
  background: var(--bnk-ground);
}
.bnk-deck::-webkit-scrollbar {
  display: none;
}

.bnk-page {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bnk-page-frame {
  position: relative;
  width: var(--bnk-page-w, 100%);
  max-width: 100%;
  height: 100%;
  background: var(--bnk-page-bg);
}

/* 本文枠：中に .bnk-bands（＝段の集合）。.bnk-bands の中に .bnk-col（段）を1〜2本、
   上→下に積む（縦書きの2段組）。CSS multicol は vertical-rl で壊れるので使わない。 */
.bnk-page-inner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: var(--bnk-text-w, 88%);
  height: var(--bnk-text-h, 80%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.bnk-bands {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: var(--bnk-col-gap, 0px);
  height: 100%;
  width: 100%;
  max-width: 100%;
}
.bnk-col {
  flex: 1 1 100%;
  writing-mode: vertical-rl;
  -webkit-writing-mode: vertical-rl;
  text-orientation: mixed;
  -webkit-text-orientation: mixed;
  line-break: strict;
  word-break: normal;
  overflow-wrap: normal;
  hanging-punctuation: allow-end;
  overflow: hidden;
  font-family: var(--bnk-font-family), "Shippori Mincho", serif;
  font-size: var(--bnk-fs, 16px);
  line-height: var(--bnk-lh, 1.78);
  color: var(--bnk-ink);
  text-align: justify;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}
.bnk-two-col .bnk-col {
  flex: 0 0 calc((var(--bnk-text-h, 80vh) - var(--bnk-col-gap, 0px)) / 2);
}
.bnk-col p {
  margin: 0;
  text-indent: 0;
  white-space: pre-wrap;
}
/* 挿絵のページ：本文枠いっぱいに、絵の縦横比のまま収める（拡大したときは枠の外＝画面いっぱいまで見せる） */
.bnk-page-inner.bnk-page-illust {
  overflow: visible;
}
.bnk-page-illust .bnk-illust {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bnk-page-illust .bnk-illust img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  transform-origin: center center;
}
/* 挿絵を指で拡大している間：デッキのスクロール（めくり）を止め、指の動きを絵のずらしに使う */
.bnk-zoomed .bnk-deck {
  overflow-x: hidden;
  touch-action: none;
}
.bnk-zoomed .bnk-page-illust {
  touch-action: none;
}
.bnk-col p.bnk-blank {
  color: transparent;
  user-select: none;
  font-size: 0.4em; /* paginate の BLANK_COST と対応 */
}
.bnk-col p.bnk-heading {
  font-weight: 700;
}
/* akibako 記法：段落寄せ（縦書きなので inline 軸＝天地方向） */
.bnk-col p.bnk-ac {
  text-align: center;
}
.bnk-col p.bnk-ar {
  text-align: end;
}
.bnk-col strong {
  font-weight: 700;
}
.bnk-col .bnk-nobr {
  white-space: nowrap;
}
.bnk-tcy {
  text-combine-upright: all;
  -webkit-text-combine-upright: all;
  text-orientation: mixed;
}
.bnk-col ruby {
  ruby-position: over;
}
.bnk-col rt {
  font-size: 0.5em;
  user-select: none;
  color: var(--bnk-ink-soft);
}
.bnk-bou {
  -webkit-text-emphasis: dot;
  text-emphasis: dot;
  -webkit-text-emphasis-position: over right;
  text-emphasis-position: over right;
}

/* ===== 飾り罫スロット（中身はホストが onFrame で描く） ===== */
.bnk-kei {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, var(--bnk-page-w, 100%));
  z-index: 5;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.bnk-kei-top {
  top: 0;
  height: var(--bnk-kei-top, 30px);
  padding-top: env(safe-area-inset-top);
}
.bnk-kei-bottom {
  bottom: 0;
  height: var(--bnk-kei-bottom, 30px);
  padding-bottom: env(safe-area-inset-bottom);
}
.bnk-kei > canvas,
.bnk-kei > svg {
  display: block;
  width: 100%;
  height: 100%;
}
/* ブリードするページ（表紙・遊び紙）では飾り罫を伏せる */
.bnk-on-bleed .bnk-kei {
  opacity: 0;
}

/* ===== パネル（表紙 / 終端 / 遊び紙） ===== */
.bnk-panel {
  position: absolute;
  inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
/* 縦スクロールが要るパネル（終端の感想欄など）はホスト側で
   `.bnk-panel { touch-action: pan-y }` 相当を当てる。表紙のように
   スワイプで抜けたいだけのパネルは何も指定しない（デッキの pan-x が通る）。 */
.bnk-bleed .bnk-page-frame {
  width: 100%;
}

/* ===== 組版中オーバーレイ ===== */
.bnk-relayout {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  z-index: 45;
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--bnk-ink-soft);
  background: var(--bnk-ground);
}
.bnk-relayout[hidden] {
  display: none;
}

/* ===== 内蔵クローム（chrome:true のとき） ===== */
.bnk-chrome {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--bnk-chrome-bg);
  color: var(--bnk-chrome-ink);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.28s ease;
  z-index: 20;
  font-size: 13px;
}
.bnk-chrome-top {
  top: 0;
  padding-top: max(12px, env(safe-area-inset-top));
  transform: translateY(-100%);
}
.bnk-chrome-bottom {
  bottom: 0;
  justify-content: center;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateY(100%);
}
.bnk-chrome-on .bnk-chrome-top,
.bnk-chrome-on .bnk-chrome-bottom {
  transform: translateY(0);
}
.bnk-title-mini {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.bnk-chip {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  border-radius: 999px;
  padding: 6px 13px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.bnk-chip:active {
  transform: scale(0.96);
}
.bnk-progress {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  font-size: 12px;
}
.bnk-scrubber {
  width: min(58%, 300px);
  accent-color: var(--bnk-accent);
  direction: rtl; /* 右端＝表紙、左へ動かすほど後ろのページ */
}

/* ===== 内蔵の設定シート ===== */
.bnk-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
  z-index: 30;
}
.bnk-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bnk-page-bg);
  color: var(--bnk-ink);
  border-radius: 18px 18px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(105%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 31;
  box-shadow: 0 -18px 50px -20px rgba(0, 0, 0, 0.5);
  max-width: 520px;
  margin: 0 auto;
  max-height: 82%;
  overflow-y: auto;
}
.bnk-sheet-on .bnk-scrim {
  opacity: 1;
  pointer-events: auto;
}
.bnk-sheet-on .bnk-sheet {
  transform: translateY(0);
}
.bnk-grip {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--bnk-ink-soft);
  opacity: 0.4;
  margin: 4px auto 16px;
}
.bnk-row {
  margin: 18px 0;
}
.bnk-row > label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--bnk-ink-soft);
  margin-bottom: 9px;
  font-weight: 700;
}
.bnk-seg {
  display: flex;
  gap: 6px;
}
.bnk-seg button {
  flex: 1 1 0;
  appearance: none;
  border: 1px solid var(--bnk-ink-soft);
  background: transparent;
  color: var(--bnk-ink);
  border-radius: 10px;
  padding: 10px 6px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.bnk-seg button[aria-pressed="true"] {
  background: var(--bnk-ink);
  color: var(--bnk-page-bg);
  border-color: var(--bnk-ink);
}
.bnk-seg button:focus-visible {
  outline: 2px solid var(--bnk-accent);
  outline-offset: 2px;
}
.bnk-sheet-foot {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid rgba(128, 128, 128, 0.2);
  display: flex;
  gap: 16px;
  font-size: 12px;
}
.bnk-sheet-foot a {
  color: var(--bnk-ink-soft);
  text-decoration: none;
}

/* ===== toast ===== */
.bnk-toast {
  position: absolute;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%) translateY(8px);
  background: var(--bnk-chrome-bg);
  color: var(--bnk-chrome-ink);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 40;
}
.bnk-toast.bnk-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.bnk-toast[hidden] {
  display: none;
}

/* ===== ノンブル（folio:true のとき・本文ページのみ常時） =====
   既定は下辺の外角（左下）。中央に置きたいホストは skin で
   `.bnk-folio{ left:0; right:0; text-align:center }` に上書きする。 */
.bnk-folio {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(4px, env(safe-area-inset-bottom));
  font-size: 11px;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  color: var(--bnk-ink-soft);
  pointer-events: none;
  z-index: 6;
}
.bnk-folio[hidden] {
  display: none;
}
