/* 目次 - 無印良品スタイル */

/* 記事レイアウト */
.article-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--spacing-xl);
  align-items: start;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
  position: relative;
}

.article-main {
  max-width: 800px;
  width: 100%;
  min-height: 100vh;
}

/* PC版：サイドバー目次 */
.article-toc-sidebar {
  position: -webkit-sticky;
  position: sticky;
  top: 120px;
  align-self: flex-start;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  overflow-x: hidden;
  will-change: transform;
  z-index: 10;
  -webkit-overflow-scrolling: touch; /* スムーズスクロール（iOS） */
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: var(--color-natural-brown) transparent;
}

/* Webkit用スクロールバースタイル */
.article-toc-sidebar::-webkit-scrollbar {
  width: 6px;
}

.article-toc-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.article-toc-sidebar::-webkit-scrollbar-thumb {
  background-color: rgba(99, 88, 76, 0.3);
  border-radius: 3px;
}

.article-toc-sidebar::-webkit-scrollbar-thumb:hover {
  background-color: rgba(99, 88, 76, 0.5);
}

.toc-container {
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  padding: var(--spacing-lg);
}

.toc-title {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: var(--spacing-md);
  padding-bottom: var(--spacing-sm);
  border-bottom: 1px solid var(--color-border);
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-charcoal);
}

.toc-title i {
  color: var(--color-natural-brown);
}

.toc-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toc-link {
  display: block;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text);
  letter-spacing: 0.05em;
  transition: all var(--transition-base);
  border-left: 2px solid transparent;
}

.toc-link:hover {
  background-color: var(--color-bg-gray);
  color: var(--color-natural-brown);
  border-left-color: var(--color-natural-brown);
}

.toc-link--active {
  background-color: var(--color-beige);
  color: var(--color-natural-brown);
  border-left-color: var(--color-natural-brown);
  font-weight: 500;
}

.toc-link--h2 {
  padding-left: 12px;
}

.toc-link--h3 {
  padding-left: 24px;
  font-size: 13px;
  color: var(--color-text-light);
}

/* SP版：目次ボタン */
.toc-button {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 60px;
  height: 60px;
  background-color: var(--color-natural-brown);
  color: white;
  border: none;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: all var(--transition-base);
  z-index: 900;
  opacity: 1;
  transform: translateY(0);
}

.toc-button--visible {
  opacity: 1;
  transform: translateY(0);
}

.toc-button:hover {
  background-color: var(--color-charcoal);
  transform: translateY(0) scale(1.05);
}

.toc-button:active {
  transform: translateY(0) scale(0.95);
}

.toc-button i {
  font-size: 18px;
}

.toc-button span {
  font-size: 10px;
  letter-spacing: 0.05em;
}

/* SP版：目次モーダル */
.toc-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.toc-modal--open {
  display: flex;
  opacity: 1;
}

.toc-modal__overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

.toc-modal__content {
  position: relative;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  margin: auto;
  background-color: white;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  animation: modalSlideUp 0.3s ease;
}

@keyframes modalSlideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.toc-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
}

.toc-modal__title {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-charcoal);
  margin: 0;
  padding: 0;
}

.toc-modal__title i {
  color: var(--color-natural-brown);
}

.toc-modal__close {
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  color: var(--color-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: all var(--transition-base);
  border-radius: 50%;
}

.toc-modal__close:hover {
  background-color: var(--color-bg-gray);
  color: var(--color-natural-brown);
}

.toc-modal__nav {
  padding: var(--spacing-md);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toc-modal__link {
  display: block;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text);
  letter-spacing: 0.05em;
  transition: all var(--transition-base);
  border-left: 3px solid transparent;
  border-radius: 4px;
}

.toc-modal__link:hover {
  background-color: var(--color-bg-gray);
  color: var(--color-natural-brown);
  border-left-color: var(--color-natural-brown);
}

.toc-modal__link.toc-link--active {
  background-color: var(--color-beige);
  color: var(--color-natural-brown);
  border-left-color: var(--color-natural-brown);
  font-weight: 500;
}

.toc-modal__link.toc-link--h3 {
  padding-left: 32px;
  font-size: 13px;
  color: var(--color-text-light);
}

/* レスポンシブ */
@media (max-width: 768px) {
  .article-layout {
    grid-template-columns: 1fr;
    padding: 0 16px;
  }

  .article-toc-sidebar {
    display: none;
  }

  .toc-button {
    display: flex;
  }

  .article-main {
    max-width: 100%;
    width: 100%;
  }
}

@media (min-width: 769px) {
  .toc-button,
  .toc-modal {
    display: none !important;
  }
}

/* スクロールバーのスタイル（目次用） */
.toc-container::-webkit-scrollbar,
.toc-modal__nav::-webkit-scrollbar {
  width: 6px;
}

.toc-container::-webkit-scrollbar-track,
.toc-modal__nav::-webkit-scrollbar-track {
  background: var(--color-bg-gray);
}

.toc-container::-webkit-scrollbar-thumb,
.toc-modal__nav::-webkit-scrollbar-thumb {
  background: var(--color-natural-brown);
  border-radius: 3px;
}

.toc-container::-webkit-scrollbar-thumb:hover,
.toc-modal__nav::-webkit-scrollbar-thumb:hover {
  background: var(--color-charcoal);
}
