
  :root {
    --gold: #c9a96e;
    --gold-light: #e2c98a;
    --gold-dim: #8a6d3b;
  }
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  html, body {
    width: 100%; height: 100%;
    min-height: 100dvh;
    background: #0d0a06;
    overflow: hidden;
    font-family: 'Noto Serif JP', serif;
    user-select: none; -webkit-user-select: none;
  }
  html {
  background-color: #0d0a06;
  min-height: -webkit-fill-available;
}
  body { display: flex; align-items: center; justify-content: center; }
  .candle-warmth {
    position: fixed; inset: 0; z-index: 0;
    background: radial-gradient(ellipse at 50% 100%, rgba(180,100,20,0.18) 0%, transparent 70%);
    pointer-events: none;
  }
  .candle-vignette {
    position: fixed; inset: 0; z-index: 1;
    background: radial-gradient(ellipse at 50% 50%, transparent 30%, rgba(0,0,0,0.75) 100%);
    pointer-events: none;
  }
  .dust-particle {
    position: fixed; border-radius: 50%;
    background: var(--gold-light);
    animation: dustFloat linear infinite;
    pointer-events: none; z-index: 2;
  }
  @keyframes dustFloat {
    0%   { transform: translateY(110vh) rotate(0deg); opacity: 0; }
    10%  { opacity: 1; }
    90%  { opacity: 0.6; }
    100% { transform: translateY(-10vh) rotate(360deg); opacity: 0; }
  }
  .scene {
    position: relative; z-index: 10;
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100vh;
    /* overflow:hidden を外す → ズーム時に右端・下端が黒く切れるのを防ぐ */
    overflow: visible;
  }
  .book-shell {
    /* 横画面：従来通り */
    width: min(92vw, calc(92vh * 3508 / 1240));
    height: min(92vh, calc(92vw * 1240 / 3508));
    max-width: none;
    filter: drop-shadow(0 30px 60px rgba(0,0,0,0.85))
            drop-shadow(0 0 40px rgba(180,120,30,0.12));
    transition: opacity 0.4s ease;
  }
  /* 縦画面：幅92vwを固定してaspect-ratioで高さを自動計算 */
  @media (orientation: portrait) {
    .book-shell {
      width: 92vw;
      height: auto;
      aspect-ratio: 3508 / 1240;
    }
  }
  #book {
    width: 100%; height: 100%;
    background: none;
    background-image: url("../images/world_reverie/introduction.webp");
    touch-action: none;
    cursor: grab;
    user-select: none; -webkit-user-select: none;
    background-size: cover;
    background-position: center;
    transition: opacity 1.4s ease;
  }
  #book:active { cursor: grabbing; }
  .page-img {
    width: 100%; height: 100%;
    object-fit: cover; display: block;
    pointer-events: none; -webkit-user-drag: none;
    /* iOS Safari: ズーム時の画質改善（ピクセル補間をシャープ寄りに） */
    image-rendering: -webkit-optimize-contrast;
  }
  .nav-btn {
    position: fixed; top: 50%; z-index: 100;
    transform: translateY(-50%);
    background: transparent; border: none; cursor: pointer;
    color: var(--gold-dim);
    font-family: 'Cormorant Garamond', serif;
    font-size: 2.5rem; line-height: 1;
    transition: color 0.3s, text-shadow 0.3s;
    padding: 1rem 1.5rem; user-select: none;
  }
  .nav-btn:hover { color: var(--gold-light); text-shadow: 0 0 20px rgba(200,160,80,0.5); }
  .nav-btn:disabled { opacity: 0.2; cursor: default; }
  #btnPrev { left: 1rem; }
  #btnNext { right: 1rem; }
  /* ページナビ */
  .page-indicator {
    position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%);
    z-index: 100;
    display: flex; align-items: center; gap: 0.5rem;
    user-select: none;
  }
  .nav-char-wrap {
    display: flex; align-items: center; gap: 0.15rem;
  }
  .nav-char {
    font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, 'Times New Roman', serif;
    font-size: 1rem; letter-spacing: 0.08em;
    color: var(--gold-dim);
    transition: color 0.4s, text-shadow 0.4s, transform 0.4s;
    cursor: default;
    line-height: 1;
  }
  .nav-char.active {
    color: var(--gold-light);
    text-shadow: 0 0 8px rgba(201,169,110,0.8), 0 0 18px rgba(201,169,110,0.4);
    transform: scale(1.25);
  }
  .nav-char-btn {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1rem; color: var(--gold-dim);
    background: none; border: none; cursor: pointer;
    padding: 0 0.3rem;
    transition: color 0.3s, text-shadow 0.3s;
    line-height: 1;
  }
  .nav-char-btn:hover {
    color: var(--gold-light);
    text-shadow: 0 0 8px rgba(201,169,110,0.6);
  }
  .nav-char-btn:disabled { opacity: 0.25; cursor: default; }
  /* ===== Σ シークレット ===== */
  .nav-char.sigma-secret {
    cursor: pointer;
    transition: color 0.4s, text-shadow 0.4s, transform 0.4s;
  }
  .nav-char.sigma-secret:hover {
    color: #f2a7b8 !important;
    text-shadow: 0 0 10px rgba(242,167,184,0.9), 0 0 22px rgba(242,167,184,0.5);
    transform: scale(1.35);
  }
  /* モーダル */
  #smileModal {
    display: none;
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,0.85);
    align-items: center; justify-content: center;
    backdrop-filter: blur(6px);
    opacity: 0; transition: opacity 2.0s ease;
  }
  #smileModal.open {
    display: flex;
    opacity: 0;
  }
  #smileModal.visible {
    opacity: 1;
  }
  #smileModal img {
  max-width: 88vw; max-height: 88vh;
  object-fit: contain;
  border: 1px solid rgba(242,167,184,0.3);
  box-shadow: 0 0 40px rgba(242,167,184,0.2), 0 0 80px rgba(0,0,0,0.8);
  cursor: zoom-in;
  transition: transform 0.25s ease;
  touch-action: none; /* ←ピンチ操作をJSで制御するために必要 */
  user-select: none; -webkit-user-select: none;
}
#smileModal img.zoomed {
  cursor: zoom-out;
}

/* ズーム中にモーダル背景クリックで閉じないようオーバーフロー対応 */
#smileModal {
  overflow: hidden; /* 既存のdisplay:noneより後で書くと上書きされるので注意 */
}
  #smileModalClose {
    position: absolute; top: 1.2rem; right: 1.5rem;
    background: none; border: none;
    color: #f2a7b8; font-size: 1.5rem;
    cursor: pointer; opacity: 0.7;
    transition: opacity 1.2s ease;
    font-family: 'Cormorant Garamond', serif;
  }
  #smileModalClose:hover { opacity: 1; }

  .page-counter {
    position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
    z-index: 100;
    font-family: 'Cormorant Garamond', serif; font-style: italic;
    font-size: 0.72rem; letter-spacing: 0.25em; color: var(--gold-dim);
    pointer-events: none;
  }
  .title-overlay {
    position: fixed; top: 1.5rem; left: 50%; transform: translateX(-50%);
    z-index: 100; text-align: center; pointer-events: none;
  }
  .title-overlay p {
    font-family: 'Cormorant Garamond', serif; font-style: italic;
    font-size: 0.75rem; letter-spacing: 0.35em; color: var(--gold-dim);
  }
  /* スマホ：目次ボタンと重ならないよう右寄せ＆左余白を確保 */
  @media (max-width: 768px) {
    .title-overlay {
      left: auto; transform: none;
      right: 1.2rem; text-align: right;
    }
  }
  .hint {
    position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%);
    z-index: 100;
    font-family: 'Cormorant Garamond', serif; font-style: italic;
    font-size: 0.8rem; letter-spacing: 0.2em; color: var(--gold-dim);
    animation: hintPulse 3s ease-in-out infinite;
    pointer-events: none; transition: opacity 0.8s;
  }
  @keyframes hintPulse { 0%,100% { opacity: 0.4; } 50% { opacity: 0.9; } }
  .hint.hidden { opacity: 0; }
  /* PC/スマホでヒントテキストを切り替え */
  .hint-mobile { display: none; }
  .hint-pc     { display: inline; }
  @media (max-width: 768px) {
    .hint-pc     { display: none; }
    .hint-mobile { 
      display: block; 
      text-align: center;
      width: 100%;
      margin: 15px auto;
      line-height: 1.6;       /* 行間を広げて読みやすく */
      letter-spacing: 0.05em; /* 文字の広がりを上品に */
    } /* ← hint-mobile の終わり */
  } /* ← メディアクエリ(@media)全体の終わり */
  .toc-btn {
    position: fixed; top: 1.4rem; left: 1.8rem; z-index: 200;
    background: transparent; border: 1px solid var(--gold-dim); color: var(--gold-dim);
    font-family: 'Cormorant Garamond', serif; font-size: 0.7rem; letter-spacing: 0.25em;
    padding: 0.45rem 0.9rem; cursor: pointer;
    transition: color 0.3s, border-color 0.3s, background 0.3s, box-shadow 0.3s;
    user-select: none;
  }
  .toc-btn:hover, .toc-btn.open {
    color: var(--gold-light); border-color: var(--gold-light);
    background: rgba(201,169,110,0.07); box-shadow: 0 0 14px rgba(200,160,80,0.2);
  }
  .toc-overlay {
    position: fixed; inset: 0; z-index: 190;
    background: rgba(5,3,1,0.55); opacity: 0; pointer-events: none;
    transition: opacity 0.5s; backdrop-filter: blur(2px);
  }
  .toc-overlay.open { opacity: 1; pointer-events: all; }
  .toc-panel {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 195;
    width: min(400px, 87vw);
    background: linear-gradient(160deg, #1b1407 0%, #120e05 60%, #0d0a06 100%);
    border-right: 1px solid var(--gold-dim);
    box-shadow: 6px 0 40px rgba(0,0,0,0.7), inset -1px 0 0 rgba(201,169,110,0.05);
    transform: translateX(-100%);
    transition: transform 0.55s cubic-bezier(0.77,0,0.175,1);
    overflow-y: auto; display: flex; flex-direction: column;
  
  }
  .toc-panel.open { transform: translateX(0); }
  .toc-panel::-webkit-scrollbar { width: 4px; }
  .toc-panel::-webkit-scrollbar-track { background: transparent; }
  .toc-panel::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 2px; }
  .toc-deco-top {
    flex-shrink: 0; padding: 2.5rem 2rem 1.2rem;
    border-bottom: 1px solid rgba(138,109,59,0.35); position: relative;
  }
  .toc-deco-top::after {
    content: ''; position: absolute; bottom: -1px; left: 2rem; right: 2rem;
    height: 1px; background: linear-gradient(to right, transparent, var(--gold-dim), transparent);
  }
  .toc-label {
    font-family: 'IM Fell English', serif; font-size: 0.55rem; letter-spacing: 0.45em;
    color: var(--gold-dim); text-transform: uppercase; margin-bottom: 0.4rem;text-align: right;  
  }
  .toc-title {
    font-family: 'Cormorant Garamond', serif; font-size: 1.35rem; font-style: italic;
    color: var(--gold-light); letter-spacing: 0.05em; line-height: 1.3;
  }
  .toc-title small {
    display: block; font-size: 0.72rem; letter-spacing: 0.2em;
    color: var(--gold-dim); font-style: normal; margin-top: 0.2rem;
  }
  .toc-list { flex: 1; padding: 1.5rem 0; list-style: none; }
  .toc-item {
    display: flex; align-items: baseline; padding: 0 2rem;
    cursor: pointer; transition: background 0.25s; position: relative;
  }
  .toc-item:hover { background: rgba(201,169,110,0.06); }
  .toc-item.active-toc { background: rgba(201,169,110,0.1); }
  .toc-item.active-toc .toc-item-title { color: var(--gold-light); }
  .toc-item.active-toc::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0;
    width: 2px; background: var(--gold);
  }
  .toc-item-inner {
    display: flex; align-items: baseline; width: 100%;
    padding: 0.7rem 0; border-bottom: 1px solid rgba(138,109,59,0.12);
  }
  .toc-item-num {
    font-family: 'Cormorant Garamond', serif; font-size: 0.62em; letter-spacing: 0.15em;
    color: var(--gold-dim); min-width: 2rem; flex-shrink: 0;
  }
  .toc-item-title {
    font-family: 'Noto Serif JP', serif; font-size: 0.8em; color: #c8b080;
    letter-spacing: 0.08em; line-height: 1.5; flex: 1; transition: color 0.25s;
  }
  .toc-item-title em {
    display: block; font-family: 'Cormorant Garamond', serif; font-style: italic;
    font-size: 0.68em; color: var(--gold-dim); letter-spacing: 0.12em; margin-top: 0.1rem;
  }
  .toc-dots {
    border-bottom: 1px dotted rgba(138,109,59,0.3); flex: 1;
    margin: 0 0.6rem 0.1rem; min-width: 1rem;
    max-width: 3rem
  }
  .toc-item-page {
    font-family: 'Cormorant Garamond', serif; font-size: 0.65em;
    letter-spacing: 0.12em; color: var(--gold-dim); flex-shrink: 0;
  }
  /* ===== サブ目次（～編）===== */
  /* has-childrenのliは縦方向に並べる */
  .toc-item.has-children {
    flex-direction: column;
    align-items: stretch;
  }
  /* ::after 擬似要素によるアローは廃止 → .toc-toggle-btn に移行 */

  /* ── アコーディオン用トグルボタン ── */
  .toc-toggle-btn {
    flex-shrink: 0;
    background: none;
    border: 1px solid rgba(138,109,59,0.4);
    border-radius: 3px;
    color: var(--gold-dim);
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    min-width: 2.4rem;
    min-height: 2.4rem;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
    margin-left: 0.5rem;
    /* transformだけアニメーション。colorはJSで切り替え */
    transition: transform 0.35s cubic-bezier(0.4,0,0.2,1), color 0.3s, border-color 0.3s, background 0.3s;
    user-select: none; -webkit-user-select: none;
    /* タッチ操作で誤作動しないよう */
    touch-action: manipulation;
  }
  .toc-toggle-btn:hover {
    color: var(--gold-light);
    border-color: var(--gold-light);
    background: rgba(201,169,110,0.08);
  }
  .toc-item.sub-open .toc-toggle-btn {
    transform: rotate(90deg);
    color: var(--gold-light);
    border-color: var(--gold-light);
    background: rgba(201,169,110,0.06);
  }
  @media (max-width: 768px) {
    .toc-toggle-btn {
      min-width: 2.8rem;
      min-height: 2.8rem;
      font-size: 1.25rem;
    }
  }
  .toc-sub-list {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.45s cubic-bezier(0.4,0,0.2,1), opacity 0.35s ease;
    opacity: 0;
    background: rgba(0,0,0,0.18);
    border-left: 2px solid rgba(138,109,59,0.25);
    margin-left: 0;
    width: 100%;
    box-sizing: border-box;
  }
  .toc-item.sub-open > .toc-sub-list {
    max-height: 600px;
    opacity: 1;
  }
  .toc-sub-item {
    display: flex; align-items: baseline;
    padding: 0 1.2rem 0 2.2rem;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
  }
  .toc-sub-item:hover { background: rgba(201,169,110,0.07); }
  .toc-sub-item.active-toc { background: rgba(201,169,110,0.1); }
  .toc-sub-item.active-toc::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0;
    width: 2px; background: var(--gold);
  }
  .toc-sub-item-inner {
    display: flex; align-items: baseline; width: 100%;
    padding: 0.55rem 0; border-bottom: 1px solid rgba(138,109,59,0.1);
  }
  .toc-sub-item-num {
    font-family: 'Cormorant Garamond', serif; font-size: 0.55rem;
    letter-spacing: 0.1em; color: rgba(138,109,59,0.55); min-width: 1.6rem; flex-shrink: 0;
  }
  .toc-sub-item-title {
    font-family: 'Noto Serif JP', serif; font-size: 0.72rem; color: #b09060;
    letter-spacing: 0.07em; line-height: 1.4; flex: 1; transition: color 0.25s;
  }
  .toc-sub-item-title em {
    display: block; font-family: 'Cormorant Garamond', serif; font-style: italic;
    font-size: 0.62rem; color: rgba(138,109,59,0.6); letter-spacing: 0.1em; margin-top: 0.1rem;
  }
  .toc-sub-item:hover .toc-sub-item-title { color: var(--gold-light); }
  .toc-sub-item.active-toc .toc-sub-item-title { color: var(--gold-light); }
  .toc-sub-dots {
    border-bottom: 1px dotted rgba(138,109,59,0.2); flex: 1;
    margin: 0 0.5rem 0.1rem; min-width: 0.5rem;
    max-width: 2rem; 
  }
  .toc-sub-item-page {
    font-family: 'Cormorant Garamond', serif; font-size: 0.6rem;
    letter-spacing: 0.1em; color: rgba(138,109,59,0.55); flex-shrink: 0;
  }

  .toc-footer {
    flex-shrink: 0; padding: 1.2rem 2rem 2rem;
    border-top: 1px solid rgba(138,109,59,0.2);
    font-family: 'Cormorant Garamond', serif; font-style: italic;
    font-size: 0.68rem; letter-spacing: 0.2em; color: rgba(138,109,59,0.5); text-align: center;
  }

  /* ===== ZOOM CONTROLS ===== */
  .zoom-controls {
    position: fixed; bottom: 2rem; right: 1.8rem; z-index: 200;
    display: flex; flex-direction: column; align-items: center; gap: 0.35rem;
  }
  .zoom-btn {
    width: 2.2rem; height: 2.2rem;
    background: rgba(13,10,6,0.75);
    border: 1px solid var(--gold-dim);
    color: var(--gold-dim);
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.25rem; line-height: 1;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: color 0.25s, border-color 0.25s, background 0.25s, box-shadow 0.25s;
    user-select: none; -webkit-user-select: none;
    backdrop-filter: blur(4px);
  }
  .zoom-btn:hover:not(:disabled) {
    color: var(--gold-light); border-color: var(--gold-light);
    background: rgba(201,169,110,0.1); box-shadow: 0 0 12px rgba(200,160,80,0.25);
  }
  .zoom-btn:disabled { opacity: 0.25; cursor: default; }
  .zoom-label {
    font-family: 'Cormorant Garamond', serif; font-size: 0.65rem;
    letter-spacing: 0.2em; color: var(--gold-dim);
    background: rgba(13,10,6,0.7); padding: 0.15rem 0.4rem;
    border: 1px solid rgba(138,109,59,0.3);
    backdrop-filter: blur(4px);
    min-width: 3.2rem; text-align: center;
  }
  .zoom-reset-btn {
    font-size: 0.6rem; letter-spacing: 0.1em; height: 1.6rem;
    width: auto; padding: 0 0.5rem;
  }

  /* スマホではズームボタンを非表示 */
  @media (max-width: 768px), (max-width: 1024px) and (orientation: landscape) and (hover: none) {
    .zoom-controls { display: none; }
  }

  /* ===== SOUND BUTTON ===== */
  #soundBtn, #soundBtnMobile {
    width: 2.2rem; height: 2.2rem;
    background: rgba(13,10,6,0.75);
    border: 1px solid var(--gold-dim);
    color: var(--gold-dim);
    font-size: 1rem; line-height: 1;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: color 0.25s, border-color 0.25s, background 0.25s, box-shadow 0.25s;
    user-select: none; -webkit-user-select: none;
    backdrop-filter: blur(4px);
    position: relative;
  }
  #soundBtn:hover, #soundBtnMobile:hover {
    color: var(--gold-light); border-color: var(--gold-light);
    background: rgba(201,169,110,0.1); box-shadow: 0 0 12px rgba(200,160,80,0.25);
  }
  #soundBtn.sound-off::after, #soundBtnMobile.sound-off::after {
    content: '';
    position: absolute;
    width: 1.5px; height: 70%;
    background: var(--gold-dim);
    transform: rotate(45deg);
    pointer-events: none;
  }
  /* スマホ用サウンドボタン（zoom-controlsとは独立・固定配置） */
  #soundBtnMobile {
    position: fixed; bottom: 3.8rem; right: 1.2rem; z-index: 200;
    display: none;
  }
  @media (max-width: 768px), (max-width: 1024px) and (orientation: landscape) and (hover: none) {
    #soundBtnMobile { display: flex; }
  }

  /* ===== FULLSCREEN BUTTON ===== */
  #fsBtn, #fsBtnMobile {
    width: 2.2rem; height: 2.2rem;
    background: rgba(13,10,6,0.75);
    border: 1px solid var(--gold-dim);
    color: var(--gold-dim);
    font-size: 0.75rem; line-height: 1; letter-spacing: 0.02em;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: color 0.25s, border-color 0.25s, background 0.25s, box-shadow 0.25s;
    user-select: none; -webkit-user-select: none;
    backdrop-filter: blur(4px);
    position: relative;
  }
  #fsBtn:hover, #fsBtnMobile:hover {
    color: var(--gold-light); border-color: var(--gold-light);
    background: rgba(201,169,110,0.1); box-shadow: 0 0 12px rgba(200,160,80,0.25);
  }
  /* スマホ用フルスクリーンボタン（soundBtnMobileの下） */
  #fsBtnMobile {
    position: fixed; bottom: 1.2rem; right: 1.2rem; z-index: 200;
    display: none;
  }
  @media (max-width: 768px), (max-width: 1024px) and (orientation: landscape) and (hover: none) {
    #fsBtnMobile { display: flex; }
  }

  /* ===== ZOOM WRAPPER (book-shell を包む) ===== */
  .zoom-wrapper {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    /* transform:scale()廃止 → book-shellのwidth/height直接変更方式 */
  }
  /* ズーム中：book-shellが画面外にはみ出せるよう scene を overflow visible に */
  .scene {
    overflow: visible !important;
  }

  /* StPageFlipが生成する親要素は拡大時に画面外まで広がりボタンを塞ぐ。
     親レイヤーのタップ判定を無効化し、本のキャンバス部分だけ有効に戻す */
  .stf__parent { pointer-events: none; }
  .stf__parent canvas,
  .stf__block  { pointer-events: auto; }
