:root {
  /* shared palette (library luxe) */
  --ink: #0b0b10;
  --ink2: #10111a;

  --paper: #f4f1e7;
  --paper2: #efe9d8;

  --gold: #c9a24e;
  --teal: #6aa6a8;

  --text: rgba(244, 241, 231, 0.96);
  --muted: rgba(244, 241, 231, 0.72);
  --muted2: rgba(244, 241, 231, 0.55);

  --line: rgba(244, 241, 231, 0.14);
  --line2: rgba(244, 241, 231, 0.08);

  --card: rgba(16, 17, 26, 0.62);
  --card2: rgba(16, 17, 26, 0.78);

  --shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  --shadow2: 0 12px 36px rgba(0, 0, 0, 0.35);

  --r: 18px;
  --pad: clamp(14px, 3.4vw, 22px);
  --max: 860px;

  /* reader typography */
  --fontScale: 1;
  --base: calc(16px * var(--fontScale));
  --lead: calc(18px * var(--fontScale));
  --h1: calc(36px * var(--fontScale));
  --h2: calc(26px * var(--fontScale));
  --h3: calc(20px * var(--fontScale));
  --lh: 1.85;

  --focus: 0 0 0 3px rgba(201, 162, 78, 0.28);

  /* story font family (toggle) */
  --storyFontGothic: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP",
    "Hiragino Kaku Gothic ProN", Meiryo, Arial, sans-serif;
  --storyFontMincho: ui-serif, "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", "YuMincho",
    "MS PMincho", "MS Mincho", Georgia, "Times New Roman", Times, serif;
  --storyFont: var(--storyFontGothic);
}

/* Light theme override */
html[data-theme="light"] {
  --text: rgba(11, 11, 16, 0.94);
  --muted: rgba(11, 11, 16, 0.70);
  --muted2: rgba(11, 11, 16, 0.54);

  --line: rgba(11, 11, 16, 0.12);
  --line2: rgba(11, 11, 16, 0.08);

  --card: rgba(244, 241, 231, 0.88);
  --card2: rgba(244, 241, 231, 0.94);

  --shadow: 0 18px 60px rgba(0, 0, 0, 0.18);
  --shadow2: 0 12px 36px rgba(0, 0, 0, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(900px 700px at 18% 12%, rgba(106, 166, 168, 0.18), transparent 60%),
    radial-gradient(1000px 800px at 90% 10%, rgba(201, 162, 78, 0.16), transparent 62%),
    linear-gradient(180deg, var(--ink), var(--ink2));
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP",
    "Hiragino Kaku Gothic ProN", Meiryo, Arial, sans-serif;
  letter-spacing: 0.02em;
  overflow-x: hidden;
}

html[data-theme="light"] body {
  background:
    radial-gradient(900px 700px at 18% 12%, rgba(106, 166, 168, 0.16), transparent 60%),
    radial-gradient(1000px 800px at 90% 10%, rgba(201, 162, 78, 0.12), transparent 62%),
    linear-gradient(180deg, var(--paper), var(--paper2));
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

::selection {
  background: rgba(201, 162, 78, 0.20);
}

.rHeader {
  position: fixed; /* sticky → fixed */
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;

  background: linear-gradient(180deg, rgba(11, 11, 16, 0.82), rgba(11, 11, 16, 0.36));
  border-bottom: 1px solid var(--line2);
  backdrop-filter: blur(14px);

  transition: transform 0.22s ease, opacity 0.22s ease;
  will-change: transform;
}

html[data-theme="light"] .rHeader {
  background: linear-gradient(180deg, rgba(244, 241, 231, 0.92), rgba(244, 241, 231, 0.55));
}

.rHeaderInner {
  width: min(var(--max), calc(100% - var(--pad) * 2));
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
}

.rBrand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 210px;
}

.rMark {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  border: 1px solid rgba(201, 162, 78, 0.30);
  background:
    radial-gradient(14px 14px at 35% 35%, rgba(201, 162, 78, 0.85), transparent 70%),
    radial-gradient(16px 16px at 70% 70%, rgba(106, 166, 168, 0.70), transparent 75%),
    linear-gradient(180deg, rgba(244, 241, 231, 0.12), rgba(244, 241, 231, 0.02));
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
}

html[data-theme="light"] .rMark {
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.10);
}

.rBrandText {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.rBrandName {
  font-weight: 760;
  letter-spacing: 0.06em;
  font-size: 15px;
}

.rBrandSub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted2);
}

.rTools {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.rBtn {
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--line2);
  background: rgba(244, 241, 231, 0.06);
  color: var(--text);
  font-weight: 650;
}

html[data-theme="light"] .rBtn {
  background: rgba(11, 11, 16, 0.05);
}

.rBtn:focus,
.rPill:focus,
.rBtnLink:focus {
  outline: none;
  box-shadow: var(--focus);
}

/* Selected state (for font toggle etc.) */
.rBtn[aria-pressed="true"] {
  border-color: rgba(201, 162, 78, 0.35);
  background: rgba(201, 162, 78, 0.12);
}

html[data-theme="light"] .rBtn[aria-pressed="true"] {
  background: rgba(201, 162, 78, 0.14);
}

/* 置換ブロック：.rPill〜.rPillVal（ここから） */
.rPill {
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(201, 162, 78, 0.35);
  background: rgba(201, 162, 78, 0.12);
  color: var(--text);
  font-weight: 650;
  white-space: nowrap;
}

.rPillKey {
  color: rgba(201, 162, 78, 0.98);
}

.rPillSep {
  color: var(--muted2);
  padding: 0 6px;
}

.rPillVal {
  color: var(--muted);
}

/* ★上下限で無効化：薄く＆押せない（直感で「もう動かない」を表現） */
#fontDown:disabled,
#fontUp:disabled,
#fontDown[aria-disabled="true"],
#fontUp[aria-disabled="true"],
.rBtn[aria-disabled="true"],
.rPill[aria-disabled="true"] {
  opacity: 0.42;
  filter: saturate(0.45);
  cursor: not-allowed;
  pointer-events: none;
}
/* 置換ブロック：.rPill〜.rPillVal（ここまで） */


.rProgress {
  height: 3px;
  background: rgba(244, 241, 231, 0.06);
}

html[data-theme="light"] .rProgress {
  background: rgba(11, 11, 16, 0.05);
}

.rProgressBar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(201, 162, 78, 0.90), rgba(106, 166, 168, 0.80));
  box-shadow: 0 8px 20px rgba(201, 162, 78, 0.18);
}

.rMain {
  width: min(var(--max), calc(100% - var(--pad) * 2));
  margin: 0 auto;

  /* 追加：fixedヘッダーぶん下げる（環境で微調整可） */
  padding-top: 82px;

  padding-bottom: 34px;
}

/* states */
.rState {
  border-radius: var(--r);
  border: 1px solid var(--line2);
  background: rgba(16, 17, 26, 0.62);
  box-shadow: var(--shadow2);
  padding: 18px;
}

html[data-theme="light"] .rState {
  background: rgba(244, 241, 231, 0.88);
}

.rStateTitle {
  font-size: calc(18px * var(--fontScale));
  font-weight: 820;
}

.rStateSub {
  margin-top: 8px;
  color: var(--muted);
  font-size: calc(14px * var(--fontScale));
  line-height: 1.6;
}

.rStateActions {
  margin-top: 14px;
}

.rSpinner {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 2px solid rgba(244, 241, 231, 0.20);
  border-top-color: rgba(201, 162, 78, 0.80);
  animation: spin 0.9s linear infinite;
  margin-bottom: 12px;
}

html[data-theme="light"] .rSpinner {
  border-color: rgba(11, 11, 16, 0.14);
  border-top-color: rgba(201, 162, 78, 0.85);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Article container */
.rArticle {
  border-radius: var(--r);
  border: 1px solid var(--line2);
  background: rgba(16, 17, 26, 0.62);
  box-shadow: var(--shadow);
  overflow: hidden;
}

html[data-theme="light"] .rArticle {
  background: rgba(244, 241, 231, 0.90);
}

/* Meta block */
.rMeta {
  padding: clamp(16px, 3vw, 22px);
  border-bottom: 1px solid var(--line2);
  background:
    radial-gradient(900px 600px at 18% 20%, rgba(201, 162, 78, 0.12), transparent 55%),
    radial-gradient(900px 600px at 84% 0%, rgba(106, 166, 168, 0.10), transparent 60%),
    rgba(16, 17, 26, 0.30);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

html[data-theme="light"] .rMeta {
  background:
    radial-gradient(900px 600px at 18% 20%, rgba(201, 162, 78, 0.10), transparent 55%),
    radial-gradient(900px 600px at 84% 0%, rgba(106, 166, 168, 0.08), transparent 60%),
    rgba(244, 241, 231, 0.60);
}

.rBadges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.rBadge {
  font-size: calc(12px * var(--fontScale));
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line2);
  background: rgba(244, 241, 231, 0.06);
  color: var(--muted);
}

html[data-theme="light"] .rBadge {
  background: rgba(11, 11, 16, 0.04);
  color: rgba(11, 11, 16, 0.72);
}

.rBadge.time {
  border-color: rgba(201, 162, 78, 0.34);
  color: rgba(201, 162, 78, 0.95);
}

.rBadge.genre {
  border-color: rgba(106, 166, 168, 0.30);
  color: rgba(106, 166, 168, 0.95);
}

.rBadge.tag {
  border-color: rgba(244, 241, 231, 0.14);
}

.rTitle {
  margin: 0;
  font-size: var(--h1);
  line-height: 1.08;
  letter-spacing: 0.02em;
}

.rByline {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: baseline;
  color: var(--muted2);
  font-size: calc(13px * var(--fontScale));
}

/* =========================
   Cover image in Meta
   ========================= */
.rMetaTop {
  /* 将来、meta上部だけスタイルを足したくなった時のためのラッパー */
}

.rCover {
  flex: 1;
  min-height: 240px;
  border-radius: 16px;
  border: 1px solid var(--line2);
  overflow: hidden;
  background: rgba(11, 11, 16, 0.12);
  box-shadow: var(--shadow2);
}

html[data-theme="light"] .rCover {
  background: rgba(11, 11, 16, 0.04);
}

.rCoverImg {
  width: 100%;
  height: 100%;
  display: block;

  /* ここがポイント：全体を表示（欠けない） */
  object-fit: contain;
  object-position: center;

  /* 余白部分の見た目（任意） */
  background: rgba(11, 11, 16, 0.06);
}

html[data-theme="light"] .rCoverImg {
  background: rgba(11, 11, 16, 0.03);
}

/* mobile: 少しだけ低く */
@media (max-width: 720px) {
  .rCover {
    min-height: 180px;
  }
}

.rBy {
  color: var(--muted2);
}

.rAuthor {
  color: var(--muted);
  font-weight: 700;
}

.rDate {
  color: var(--muted2);
}

.rDot {
  opacity: 0.6;
}

/* Body typography */
.rBody {
  padding: clamp(18px, 3.2vw, 26px);
  font-size: var(--base);
  line-height: var(--lh);

  /* “書籍”っぽい読み心地 */
  max-width: 68ch;
  margin: 0 auto;

  /* Optional: better Japanese typesetting */
  hanging-punctuation: first allow-end;
  line-break: strict;           /* 禁則・句読点処理を厳密寄りに */
  word-break: normal;
  overflow-wrap: break-word;    /* anywhere だと不自然に割れやすい */
  hyphens: auto;                /* EN向け（lang=en 時に有効） */
  font-kerning: normal;
}

.rBody p {
  margin: 0 0 1.05em;
  color: var(--text);
  text-wrap: pretty;
}

/* Default: justify (horizontal/vertical共通) */
.rBody p,
.rBody li {
  text-align: justify;
  text-justify: inter-character;
  text-align-last: start;
}

/* =========================
   Chapter spacing around headings（章の余韻）
   - margin-block は writing-mode に追従：
     横書き＝上下の余白 / 縦書き＝右→左の“列間”余白
   ========================= */
:root {
  /* 横書き時（上下） */
  --ssbHeadGapBefore: 6.6em; /* 見出しの“前” */
  --ssbHeadGapAfter:  1.2em; /* 見出しの“後” */

  /* 縦書き時（右→左の列間） */
  --ssbHeadGapBeforeV: 4.6em;
  --ssbHeadGapAfterV:  1.35em;
}

/* 本文（Markdown）直下の見出しだけに余白を適用する
   ※メタ内のタイトル(h1.rTitle)は .rMeta 内なので巻き込まれない */
#body.rBody > h1,
#body.rBody > h2,
#body.rBody > h3 {
  letter-spacing: 0.01em;

  margin: 0;
  margin-block-start: var(--ssbHeadGapBefore);
  margin-block-end: var(--ssbHeadGapAfter);
  margin-inline: 0;
}

/* 縦書き時の章間 */
html[data-writing="vertical"] #body.rBody > h1,
html[data-writing="vertical"] #body.rBody > h2,
html[data-writing="vertical"] #body.rBody > h3 {
  margin-block-start: var(--ssbHeadGapBeforeV);
  margin-block-end: var(--ssbHeadGapAfterV);
}



#body.rBody > h1 { font-size: var(--h2); }
#body.rBody > h2 { font-size: var(--h2); }
#body.rBody > h3 { font-size: var(--h3); }

/* =========================
   Story font toggle (Gothic / Mincho)
   ========================= */
html[data-font="mincho"] {
  --storyFont: var(--storyFontMincho);
}

html[data-font="gothic"] {
  --storyFont: var(--storyFontGothic);
}

/* Apply to "reading" parts (UI stays system sans) */
.rStateTitle,
.rTitle,
.rBody,
.rBody h1,
.rBody h2,
.rBody h3 {
  font-family: var(--storyFont);
}

/* Mincho tends to look better with slightly tighter tracking */
html[data-font="mincho"] .rBody {
  letter-spacing: 0.01em;
}

.rBody a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  color: rgba(106, 166, 168, 0.98);
}

.rBody a:hover {
  opacity: 0.9;
}

.rBody strong {
  font-weight: 820;
}

.rBody em {
  font-style: italic;
  color: var(--muted);
}

.rBody code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Noto Sans Mono", monospace;
  font-size: calc(14px * var(--fontScale));
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px solid var(--line2);
  background: rgba(244, 241, 231, 0.06);
  color: rgba(244, 241, 231, 0.90);
}

html[data-theme="light"] .rBody code {
  background: rgba(11, 11, 16, 0.05);
  color: rgba(11, 11, 16, 0.90);
}

.rBody pre {
  margin: 1.1em 0 1.2em;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line2);
  background: rgba(11, 11, 16, 0.55);
  overflow: auto;
  box-shadow: var(--shadow2);
}

html[data-theme="light"] .rBody pre {
  background: rgba(11, 11, 16, 0.06);
}

.rBody pre code {
  display: block;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font-size: calc(13px * var(--fontScale));
  line-height: 1.55;
}

.rBody ul,
.rBody ol {
  margin: 0.2em 0 1.1em 1.2em;
  padding: 0;
  color: var(--text);
}

.rBody li {
  margin: 0.25em 0;
}

/* “見開き感”の余白をスマホで崩さない */
@media (max-width: 720px) {
  :root {
    --max: 980px; /* header width remains comfortable */
    --h1: calc(30px * var(--fontScale));
    --h2: calc(22px * var(--fontScale));
    --h3: calc(18px * var(--fontScale));
    --lh: 1.9;
  }

  .rHeaderInner {
    padding: 8px 0;
  }

  /* ★スマホ/小型タブレットで“折り返し地獄”を防ぐ */
  .rBrand {
    min-width: 0;          /* 210px固定を解除 */
    flex: 0 0 auto;
  }

  .rBrandSub {
    display: none;
  }

  .rTools {
    flex: 1 1 auto;
    min-width: 0;

    /* ★折り返さず1段運用（足りない分は横スクロール） */
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;

    gap: 8px;
    justify-content: flex-start;
    padding-bottom: 2px; /* 指がかかりやすい余裕 */
  }

  /* ボタンが縮まず“横に並ぶ”ようにする */
  .rTools > * {
    flex: 0 0 auto;
  }

  /* iOS/Chromeでスクロールバーを目立たせない（挙動は維持） */
  .rTools::-webkit-scrollbar {
    height: 0;
  }

  .rBtn,
  .rPill {
    padding: 8px 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .rBody {
    max-width: 100%;
    padding: 16px;
  }
}

/* ★スマホ（特に狭い幅）ではブランド名を畳んで本文領域を最大化 */
@media (max-width: 560px) {
  .rBrandText {
    display: none;
  }
}

/* ★スマホ最狭幅：ヘッダー内ボタンを“1文字運用”にして欠けを防ぐ */
@media (max-width: 420px) {
  .rTools { gap: 6px; }

  /* Theme → T（先頭1文字だけ表示） */
  #themeToggle span {
    display: inline-block;
    width: 1.15em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: clip;
  }

  /* 縦書き/横書き → 縦/横（先頭1文字だけ表示） */
  #writingToggleText {
    display: inline-block;
    width: 1.15em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: clip;
  }

  /* 全画面 → 全（zenToggleText が生成される前提） */
  #zenToggleText {
    display: inline-block;
    width: 1.15em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: clip;
  }

  /* フォントサイズ：A−/A+ を − / + だけに（aria-label は残るので意味は伝わる） */
  /* フォントサイズ：− / + を “真円” に（ゴ/明と同じバランス） */
  #fontDown,
  #fontUp {
    font-size: 0;          /* "A" を非表示 */
    width: 40px;           /* ← 幅＝高さ */
    height: 40px;
    min-width: 40px;
    padding: 0;            /* ← 楕円化の原因を除去 */
    display: inline-flex;  /* ← 中央寄せ */
    align-items: center;
    justify-content: center;
    border-radius: 999px;  /* 念のため */
  }

  #fontDown::before,
  #fontUp::before {
    font-size: 16px;
    font-weight: 900;
    line-height: 1;
    display: block;
  }

  #fontDown::before { content: "−"; }
  #fontUp::before   { content: "+"; }

}

/* ★全画面(Zen)の≡ボタン：スマホでは文字を省略して被りを最小化 */
@media (max-width: 520px) {
  .ssbZenFabTxt {
    display: none;
  }
  .ssbZenFab {
    padding: 10px;
  }
}


/* Footer nav */
.rFootNav {
  border-top: 1px solid var(--line2);
  padding: 14px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: center;
  background: rgba(11, 11, 16, 0.18);
}

html[data-theme="light"] .rFootNav {
  background: rgba(11, 11, 16, 0.04);
}

.rBtnLink {
  display: inline-block;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(201, 162, 78, 0.26);
  background: rgba(201, 162, 78, 0.10);
  color: var(--text);
  font-weight: 700;
}

html[data-theme="light"] .rBtnLink {
  color: rgba(11, 11, 16, 0.92);
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  .rSpinner {
    animation: none;
  }
}

/* Optional: prevent iOS tap highlight */
* {
  -webkit-tap-highlight-color: transparent;
}

/* =========================
   Writing mode (vertical / horizontal)
   ========================= */
/* =============================
   Zen + 縦書き：右上メニューが本文に被るのを回避
   - 先頭（上側）に“逃げ”を作る
   ============================= */
html[data-writing="vertical"] .rBody {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  hanging-punctuation: none;

  /* 両端揃え（縦書き：行の上下端を揃える） */
  text-align: justify;
  text-justify: inter-character;
  text-align-last: start;

  /* ★詰まり・当たり対策：縦書きは少し字送りを増やす */
  letter-spacing: 0.06em;

  /* ★縦書き向けカーニング（vkrn優先） */
  font-kerning: normal;

  /* デフォルトは“詰まりやすい機能”を抑える（端末差対策） */
  font-feature-settings: "kern" 1, "vkrn" 1;
  font-variant-east-asian: normal;

  max-width: none;
  margin: 0 auto;

  /* スクロールは横のみ */
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;

  padding: clamp(18px, 3.2vw, 26px);
  touch-action: pan-x;
}

/* ★非Zen時：縦書き本文の先頭（天）が欠けないように“上側=inline-start”に逃げを作る
   emなのでフォント拡大縮小に追従します */
html[data-writing="vertical"]:not([data-zen="1"]) #body.rBody {
  padding-inline-start: calc(clamp(18px, 3.2vw, 26px) + 1.25em);
  scroll-padding-inline-start: calc(clamp(18px, 3.2vw, 26px) + 1.25em);
}

/* さらに狭い端末では少し多め */
@media (max-width: 480px) {
  html[data-writing="vertical"]:not([data-zen="1"]) #body.rBody {
    padding-inline-start: calc(clamp(18px, 3.2vw, 26px) + 1.55em);
    scroll-padding-inline-start: calc(clamp(18px, 3.2vw, 26px) + 1.55em);
  }
}

/* =========================
   Tate-chu-yoko (縦中横)
   - short ASCII numerals like 08:13 / 3号車 を読みやすく
   ========================= */
/* 段落の間隔（縦書き：段落の送り＝block方向＝右→左） */
html[data-writing="vertical"] .rBody p {
  margin: 0;
  margin-block-end: 1.05em; /* ← 空白行（段落間）を作る */

  /* 両端揃え（縦書き＝行の上下端を揃える） */
  text-align: justify;
  text-justify: inter-character;
  text-align-last: start; /* 最終行は伸ばさない */
}


/* 縦書き時はリストのインデントを少し控えめに */
html[data-writing="vertical"] .rBody ul,
html[data-writing="vertical"] .rBody li {
  text-align: justify;
  text-justify: inter-character;
  text-align-last: start;
}

html[data-writing="vertical"] .rBody ol {
  margin-inline-start: 0.8em;
}

/* sentinel は測定に使うが、レイアウトを押し広げない */
.ssbVSentinel {
  display: block;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* 縦書き時：rMeta を #body の「最初のページ」として配置 */
html[data-writing="vertical"] .rMeta.ssbMetaInBody {
  /* rMeta は横書きのまま（タイトル/タグを通常向きで見せる） */
  writing-mode: horizontal-tb;
  text-orientation: mixed;

  /* 1ページぶんの幅（好みで調整可） */
  width: min(420px, 78vw);
  height: 100%;

  /* 区切り線（メタ→本文の境界） */
  border-bottom: none;
  border-left: 1px solid var(--line2);

  /* 見た目は従来の rMeta 風 */
  padding: clamp(16px, 3vw, 22px);

  /* 縦書き：タイトル/表紙ページ上でも横ジェスチャが安定するよう補強 */
  touch-action: pan-x;
}

html[data-writing="vertical"] .rMeta.ssbMetaInBody img {
  -webkit-user-drag: none;
  user-select: none;
}

html[data-theme="light"][data-writing="vertical"] .rMeta.ssbMetaInBody {
  border-left-color: var(--line2);
}

/* =============================
   Zen / Fullscreen (ヘッダー非表示)
   - スマホ/タブレットで本文領域を広く
   ============================= */
html[data-zen="1"] .rHeader {
  transform: translateY(-110%);
  opacity: 0;
  pointer-events: none;
}

/* JSが効かない場合の保険（JSでは inline でも調整） */
html[data-zen="1"] .rMain {
  padding-top: calc(env(safe-area-inset-top, 0px) + 10px);
}

.ssbZenFab {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  z-index: 70;

  display: inline-flex;
  align-items: center;
  gap: 8px;

  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--line2);
  background: rgba(16, 17, 26, 0.62);
  color: var(--text);
  box-shadow: var(--shadow2);
}

html[data-theme="light"] .ssbZenFab {
  background: rgba(244, 241, 231, 0.85);
}

.ssbZenFab[hidden] {
  display: none !important;
}

.ssbZenFabIco {
  font-weight: 900;
  line-height: 1;
}

.ssbZenFabTxt {
  font-weight: 750;
  font-size: 13px;
}

/* 明朝（mincho）はプロポーショナルが映えるので“縦書き時のみ”再ON */
html[data-font="mincho"][data-writing="vertical"] .rBody {
  letter-spacing: 0.04em; /* 明朝は少し控えめでOK */

  /*
    NOTE:
    palt/pkna + proportional-width は、環境によって三点リーダ（…）まで
    句読点扱いで“隅”に寄せてしまうことがあるため、縦書きではOFFにします。
  */
  font-feature-settings: "kern" 1, "vkrn" 1;
  font-variant-east-asian: normal;
}


/* Zen + 縦書き：右上メニュー（ssbZenFab）と本文が重ならないよう上余白を確保 */
html[data-zen="1"][data-writing="vertical"] .rBody {
  padding-top: calc(clamp(18px, 3.2vw, 26px) + var(--ssbZenFabGutter, 56px));
}

html[data-zen="1"][data-writing="vertical"] .rMeta.ssbMetaInBody {
  padding-top: calc(clamp(16px, 3vw, 22px) + var(--ssbZenFabGutter, 56px));
}

/* A案：平均/件数（人気度） */
.ssbRatingAgg {
  font-size: calc(12px * var(--fontScale, 1));
  color: var(--muted2, rgba(255, 255, 255, 0.72));
}

/* =========================
   Mobile/Tablet stability: lock reader layout in vertical mode
   - Prevents rArticle from "resizing" while dragging
   - Uses stable viewport height (svh) + flex so #body gets the remaining space.
   ========================= */
html[data-writing="vertical"] body {
  overflow: hidden;           /* page itself doesn't scroll in vertical mode */
  overscroll-behavior: none;  /* stop elastic overscroll */
}

html[data-writing="vertical"] .rMain {
  /* stable viewport height: 100svh (fallback: 100vh) */
  height: 100vh;
  height: 100svh;
  box-sizing: border-box;
  overflow: hidden;
  padding-bottom: 0;
}

html[data-writing="vertical"] #article.rArticle {
  height: 100%;
  display: flex;
  flex-direction: column;
}

html[data-writing="vertical"] #body.rBody {
  flex: 1 1 auto;
  min-height: 0;
  height: auto; /* override legacy fixed height */
}

html[data-writing="vertical"] .rFootNav {
  flex: 0 0 auto;
}


/* Toolbar scroll hints (fade) */

@media (max-width: 720px) {
  /* rTools は横スクロール前提：フェードで“続き”を示す */
  .rTools {
    position: relative;
  }

  .rTools[data-right="1"]::after,
  .rTools[data-left="1"]::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 22px;
    pointer-events: none;
    z-index: 2;
  }

  .rTools[data-right="1"]::after {
    right: 0;
    background: linear-gradient(90deg, rgba(11, 11, 16, 0), rgba(11, 11, 16, 0.78));
  }

  .rTools[data-left="1"]::before {
    left: 0;
    background: linear-gradient(270deg, rgba(11, 11, 16, 0), rgba(11, 11, 16, 0.78));
  }

  html[data-theme="light"] .rTools[data-right="1"]::after {
    background: linear-gradient(90deg, rgba(244, 241, 231, 0), rgba(244, 241, 231, 0.92));
  }

  html[data-theme="light"] .rTools[data-left="1"]::before {
    background: linear-gradient(270deg, rgba(244, 241, 231, 0), rgba(244, 241, 231, 0.92));
  }
}

/* Header auto-hide (phone only via JS) */
.rHeader.isAutoHidden {
  transform: translateY(-110%);
  opacity: 0;
  pointer-events: none;
}
