  :root {
    --bg-main: #f7f7f7;
    --text-main: #111111;
    --text-muted: #888888;
    --border-color: #dddddd;
    --bg-panel: #ffffff; 
    --bg-quote: #eeeeee;
  }

  [data-theme="dark"] {
    --bg-main: #262626;      
    --text-main: #d4d4d4;    
    --text-muted: #999999;
    --border-color: #444444; 
    --bg-panel: #2e2e2e;     
    --bg-quote: #2e2e2e;
  }

  html { scroll-behavior: smooth; scrollbar-gutter: stable; }

  body {
    margin: 0; padding: 0;
    background-color: var(--bg-main); 
    color: var(--text-main);
    font-family: "Noto Serif JP", serif;
    line-height: 2.2; 
    letter-spacing: 0.1em;
    transition: background-color 0.4s ease, color 0.4s ease; 
  }

  a { color: inherit; text-decoration: none; }
  html.no-scroll, body.no-scroll { overflow: hidden !important; touch-action: none; }

  .tools-container {
    display: flex; flex-direction: column; gap: 10px; margin-bottom: 40px;
    padding-bottom: 20px; border-bottom: 1px solid var(--border-color);
  }
  .tool-btn {
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid var(--border-color);
    color: var(--text-main); font-family: "Noto Serif JP", serif;
    font-size: 0.85rem; font-weight: 700; padding: 10px; cursor: pointer;
    transition: all 0.3s ease; letter-spacing: 0.1em;
  }
  .tool-btn:hover { background: var(--text-main); color: var(--bg-main); }
  .tool-btn.highlight { border-color: var(--text-main); border-width: 2px; }

  .viewer-header {
    position: fixed; top: 0; left: 0; width: 100%;
    background: var(--bg-main); opacity: 0.95;
    padding: 15px 20px; box-sizing: border-box;
    display: flex; justify-content: flex-end; 
    align-items: center;
    z-index: 2000; transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.4s;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  }
  .viewer-header.is-hidden { transform: translateY(-100%); }
  
  @media (min-width: 1001px) { .viewer-header { display: none !important; } }

  .sp-toc-overlay { display: none; }

  .layout-container {
    display: flex; max-width: 1300px; 
    margin: 100px auto 0; padding: 0 40px; gap: 60px;
  }

  .sidebar { width: 400px; flex-shrink: 0; }
  
  .toc-wrapper {
    position: sticky; top: 80px; 
    max-height: calc(100vh - 100px); overflow-y: auto;
    padding-right: 15px; 
  }
  .toc-wrapper::-webkit-scrollbar { width: 4px; }
  .toc-wrapper::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
  
  .pc-back-link {
    display: inline-block; font-size: 0.85rem; font-weight: 700; color: var(--text-muted);
    margin-bottom: 20px; transition: color 0.3s ease;
  }
  .pc-back-link:hover { color: var(--text-main); }

  .toc-article-title {
    font-size: 1.2rem; font-weight: 700; color: var(--text-main);
    line-height: 1.6; margin-bottom: 20px; letter-spacing: 0.2em;
    padding-bottom: 10px; border-bottom: 1px solid var(--border-color);
  }

  .toc-list { list-style: none; padding: 0; margin: 0; }
  
  .toc-item.toc-part { margin: 30px 0 15px 0; }
  .toc-item.toc-part > .toc-link {
    display: block; font-size: 1.1rem; font-weight: 700; color: var(--text-main);
    padding: 0 0 4px 8px; 
    border-bottom: 1px solid var(--text-main); 
    border-left: 4px solid transparent; 
    transition: all 0.3s ease; letter-spacing: 0.05em;
  }
  .toc-item.toc-part > .toc-link:hover { opacity: 0.6; }
  .toc-item.toc-part > .toc-link.is-active { border-left-color: var(--text-main); opacity: 1; }

  .toc-sublist { list-style: none; padding-left: 10px; margin: 5px 0 15px 0; }
  .toc-subitem { margin-bottom: 4px; }
  .toc-subitem > .toc-link {
    display: block; font-size: 0.85rem; font-weight: 400; color: var(--text-muted);
    padding: 2px 0 2px 8px; border-left: 2px solid transparent; transition: all 0.3s ease;
  }
  .toc-subitem > .toc-link:hover { color: var(--text-main); }
  .toc-subitem > .toc-link.is-active {
    color: var(--text-main); font-weight: 700; border-left-color: var(--text-main);
  }

  .toc-toggle {
    display: none; background: transparent; border: none; cursor: pointer;
    width: 30px; height: 20px; position: relative; z-index: 2001; flex-shrink: 0;
  }
  .toc-toggle span {
    display: block; width: 100%; height: 2px; background: var(--text-main);
    position: absolute; transition: all 0.3s ease;
  }
  .toc-toggle span:nth-child(1) { top: 0; }
  .toc-toggle span:nth-child(2) { top: 9px; }
  .toc-toggle span:nth-child(3) { bottom: 0; }
  .toc-toggle.is-active span:nth-child(1) { transform: translateY(9px) rotate(45deg); }
  .toc-toggle.is-active span:nth-child(2) { opacity: 0; }
  .toc-toggle.is-active span:nth-child(3) { transform: translateY(-9px) rotate(-45deg); }

  @media (max-width: 1000px) {
    .layout-container { padding: 0 20px; margin-top: 80px; }
    .sidebar { display: none; } 
    .toc-toggle { display: block; } 
    
    .sp-toc-overlay {
      display: block; position: fixed; top: 0; left: 0; width: 100%; height: 100dvh;
      background: var(--bg-main); opacity: 0; pointer-events: none; 
      padding: 100px 40px 40px; box-sizing: border-box; z-index: 1500; 
      transition: opacity 0.4s ease, background-color 0.4s; overflow-y: auto;
    }
    .sp-toc-overlay.is-active { opacity: 0.98; pointer-events: auto; }
    
    .sp-back-link {
      display: block; font-size: 1.1rem; font-weight: 700; color: var(--text-main);
      margin-bottom: 20px;
    }
  }

  .main-content { flex: 1; max-width: 720px; margin: 0 auto; }

  .article-meta {
    text-align: right; font-size: 0.85rem; color: var(--text-muted);
    letter-spacing: 0.1em; margin-bottom: 25px; font-weight: 700;
  }

  .article-title {
    font-size: 2.2rem; font-weight: 700; line-height: 1.5; 
    margin: 0 0 30px 0; padding-bottom: 20px;
  }

  .section-edition {
    font-size: 1.1rem; font-weight: 700; color: var(--text-muted);
    letter-spacing: 0.15em; margin-bottom: 60px; padding-bottom: 20px;
    border-bottom: 2px solid var(--text-main);
  }

  h2[id], h3[id] { scroll-margin-top: 100px; }

  .main-content h2.part-title {
    font-size: 1.5rem; font-weight: 700; text-align: center;
    margin: 140px 0 80px; padding: 25px 0; 
    background-color: transparent; color: var(--text-main);
    border-top: 1px solid var(--text-main);
    border-bottom: 1px solid var(--text-main);
    letter-spacing: 0.2em; text-indent: 0.2em;
  }

  .main-content h3.chapter-title {
    font-size: 1.35rem; font-weight: 700; 
    margin: 100px 0 40px; padding: 5px 0 5px 15px; 
    background-color: transparent; 
    border-left: 3px solid var(--text-main);
    box-shadow: none;
  }

  .main-content h4.section-title {
    font-size: 1.15rem; font-weight: 700; 
    margin: 60px 0 25px; color: var(--text-main);
  }
  
  .main-content p { font-size: 1.05rem; margin-bottom: 2.2em; text-align: justify; }
  .main-content strong { font-weight: 700; }
  .main-content ruby { font-family: "Noto Serif JP", serif; }
  .main-content rt { font-size: 0.6em; color: var(--text-muted); transform: translateY(-2px); }

  /* 引用部分（文字色反転対応済み：本文黒、名前グレー） */
  .main-content blockquote {
    margin: 40px 0; padding: 25px 30px;
    background-color: var(--bg-quote); border-left: 4px solid var(--text-muted);
    font-size: 0.95rem; color: var(--text-main); transition: background-color 0.4s;
  }
  .main-content blockquote p { margin-bottom: 0; line-height: 1.8; color: inherit; }
  .main-content blockquote p:not(:last-child) { margin-bottom: 1em; } 
  .main-content blockquote strong { color: var(--text-muted); } 

  .main-content figure { margin: 60px 0; text-align: center; }
  .main-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 40px auto;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  cursor: zoom-in;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
  .main-content img:hover {
    transform: translateY(-2px); box-shadow: 0 8px 25px rgba(0,0,0,0.1);
  }
  .main-content figcaption { font-size: 0.85rem; color: var(--text-muted); margin-top: 15px; line-height: 1.6; }

  .page-nav-container {
    display: flex; justify-content: space-between; align-items: center;
    margin: 100px 0 40px; padding-top: 40px; border-top: 1px solid var(--border-color);
  }
  .page-nav-btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 15px 30px; font-weight: 700; color: var(--text-main);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease; text-decoration: none; letter-spacing: 0.1em;
  }
  .page-nav-btn:hover { background: var(--text-main); color: var(--bg-main); }
  .page-nav-btn.next { margin-left: auto; }
  .page-nav-btn.prev { margin-right: auto; }

  .viewer-footer {
    padding: 80px 20px; text-align: center; border-top: 1px solid var(--border-color); margin-top: 80px;
  }
  .footer-back-btn {
    display: inline-block; color: var(--text-main); font-size: 0.85rem; font-weight: 700;
    border: 1px solid var(--text-main); padding: 12px 30px; 
    transition: all 0.3s ease; letter-spacing: 0.1em;
  }
  .footer-back-btn:hover { background-color: var(--text-main); color: var(--bg-main); }

  #article-img-modal {
    display: none; position: fixed; z-index: 3000; left: 0; top: 0;
    width: 100%; height: 100dvh; background-color: rgba(247, 247, 247, 0.95);
    opacity: 0; transition: opacity 0.3s ease;
    align-items: center; justify-content: center; cursor: zoom-out;
  }
  [data-theme="dark"] #article-img-modal { background-color: rgba(38, 38, 38, 0.95); }
  #article-img-modal.is-show { opacity: 1; }
  .article-modal-content {
    max-width: 90%; max-height: 90vh; object-fit: contain;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  }
  .article-modal-close {
    position: absolute; top: 20px; right: 40px; color: var(--text-main);
    font-size: 50px; font-weight: 300; cursor: pointer; transition: opacity 0.3s;
  }
  .article-modal-close:hover { opacity: 0.4; }

  /* スマホ専用のテキスト・余白縮小調整 */
  @media (max-width: 768px) {
    body {
      line-height: 1.9; 
      letter-spacing: 0.05em; 
    }
    
    .main-content p {
      font-size: 0.95rem; 
      margin-bottom: 1.8em; 
    }

    .article-title {
      font-size: 1.6rem; 
      margin-bottom: 40px;
    }
    
    .section-edition {
      font-size: 1rem;
      margin-bottom: 40px;
    }

    .main-content h2.part-title {
      font-size: 1.25rem;
      margin: 100px 0 60px;
      padding: 15px 0;
    }

    .main-content h3.chapter-title {
      font-size: 1.15rem;
      margin: 80px 0 30px;
    }

    .main-content h4.section-title {
      font-size: 1.05rem;
      margin: 50px 0 20px;
    }

    .main-content blockquote {
      font-size: 0.85rem; 
      padding: 15px 20px;
      margin: 30px 0;
    }
  }