/* ============================================================
   となりの英語 — Table of Contents (TOC)
   2 modes:
     .te-toc--inline    冒頭・全展開（記事先頭）
     .te-toc--sidebar   sticky 追従コンパクト（デスクトップ右側）
   Mobile collapse:
     .te-toc--collapsed (default on mobile via JS or class)
   Heading depth: H2 + H3 (1. / 1.1)
   Active item: dot + bold
   ============================================================ */

.te-toc {
  position: relative;
  font-family: var(--te-font-body);
  color: var(--te-ink);
  background: var(--te-cream-warm);
  border: 1px solid var(--te-hairline-soft);
  border-radius: var(--te-radius-md);
  padding: 22px 26px 24px;
  margin: 1.75rem 0 2.5rem;
  font-size: 14px;
  line-height: 1.8;
}

/* ---------- header ---------- */
.te-toc__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px dashed var(--te-hairline);
}
.te-toc__eyebrow {
  font-size: 9.5px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--te-salmon);
  margin-bottom: 2px;
}
.te-toc__title {
  font-family: var(--te-font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--te-deep-green);
  letter-spacing: 0.05em;
  margin: 0;
}
.te-toc__count {
  font-size: 11px;
  color: var(--te-ink-soft);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ---------- list ---------- */
.te-toc__list {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: te-toc-h2;
}
.te-toc__list--sub {
  counter-reset: te-toc-h3;
  margin: 4px 0 8px 0;
  padding-left: 0;
}

/* ---------- items (H2) ---------- */
.te-toc__item {
  position: relative;
  padding: 4px 0;
}
.te-toc__item > a {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: baseline;
  gap: 6px;
  text-decoration: none;
  color: var(--te-ink);
  padding: 4px 0;
  transition: color .15s ease;
  position: relative;
}
.te-toc__item > a::before {
  content: counter(te-toc-h2, decimal) ".";
  counter-increment: te-toc-h2;
  font-family: var(--te-font-display);
  color: var(--te-primary-teal);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
}
.te-toc__item > a:hover { color: var(--te-deep-green); }
.te-toc__item > a:hover .te-toc__text { color: var(--te-deep-green); }

.te-toc__text {
  display: inline-block;
  border-bottom: 1px solid transparent;
  transition: border-color .15s ease;
  font-weight: 500;
  color: var(--te-ink);
}
.te-toc__item > a:hover .te-toc__text { border-bottom-color: var(--te-hairline); }

/* ---------- items (H3 sub) ---------- */
.te-toc__sub {
  position: relative;
  padding: 2px 0 2px 38px;
}
.te-toc__sub > a {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 6px;
  text-decoration: none;
  color: var(--te-ink-soft);
  font-size: 13px;
  padding: 3px 0;
}
.te-toc__sub > a::before {
  content: counter(te-toc-h2, decimal) "." counter(te-toc-h3, decimal);
  counter-increment: te-toc-h3;
  color: var(--te-primary-teal);
  opacity: .65;
  font-size: 12px;
  letter-spacing: 0.02em;
}
.te-toc__sub > a:hover { color: var(--te-deep-green); }

/* ---------- active state (dot + bold) ---------- */
.te-toc__item.is-active > a .te-toc__text,
.te-toc__sub.is-active > a {
  color: var(--te-deep-green);
  font-weight: 700;
}
.te-toc__item.is-active > a::after,
.te-toc__sub.is-active > a::after {
  content: "";
  position: absolute;
  left: -16px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--te-salmon);
  transform: translateY(-50%);
  box-shadow: 0 0 0 3px rgba(232,165,152,.18);
}
.te-toc__sub.is-active > a::after { left: -10px; width: 5px; height: 5px; }

/* ============================================================
   Mode A: Inline (記事冒頭・全展開)
   ============================================================ */
.te-toc--inline {
  /* default styles already cover this */
  background: var(--te-cream-warm);
}
.te-toc--inline .te-toc__list { max-height: none; }

/* ============================================================
   Mode B: Sidebar sticky (desktop only)
   ============================================================ */
.te-toc--sidebar {
  background: transparent;
  border: none;
  padding: 0 0 0 18px;
  border-left: 1px solid var(--te-hairline-soft);
  font-size: 12.5px;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--te-hairline) transparent;
}
.te-toc--sidebar .te-toc__header {
  border-bottom: none;
  padding-bottom: 6px;
  margin-bottom: 8px;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.te-toc--sidebar .te-toc__title {
  font-size: 12px;
  font-family: var(--te-font-body);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--te-ink-soft);
  font-weight: 600;
}
.te-toc--sidebar .te-toc__eyebrow,
.te-toc--sidebar .te-toc__count { display: none; }
.te-toc--sidebar .te-toc__item > a {
  grid-template-columns: 28px 1fr;
  font-size: 12.5px;
  padding: 3px 0;
}
.te-toc--sidebar .te-toc__item > a::before { font-size: 12px; }
.te-toc--sidebar .te-toc__sub { padding-left: 28px; }
.te-toc--sidebar .te-toc__sub > a { font-size: 11.5px; grid-template-columns: 32px 1fr; }
.te-toc--sidebar .te-toc__item.is-active > a::after,
.te-toc--sidebar .te-toc__sub.is-active > a::after { left: -19px; }

/* ============================================================
   Mobile collapse
   ============================================================ */
.te-toc__toggle {
  display: none;
  width: 100%;
  background: transparent;
  border: 1px solid var(--te-hairline);
  border-radius: var(--te-radius-sm);
  padding: 12px 16px;
  font-family: var(--te-font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--te-deep-green);
  cursor: pointer;
  text-align: left;
  position: relative;
  letter-spacing: 0.04em;
  transition: background .15s ease;
}
.te-toc__toggle:hover { background: rgba(255,255,255,.5); }
.te-toc__toggle::after {
  content: "▾";
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--te-primary-teal);
  transition: transform .25s ease;
}
.te-toc--collapsed .te-toc__toggle::after { transform: translateY(-50%) rotate(-90deg); }
.te-toc--collapsed .te-toc__header,
.te-toc--collapsed .te-toc__list { display: none; }
.te-toc--collapsed { padding: 0; background: transparent; border: none; }
.te-toc--collapsed .te-toc__toggle { display: block; }

/* Mobile: toggle visible on inline mode */
@media (max-width: 720px) {
  .te-toc--inline .te-toc__toggle { display: block; margin-bottom: 0; }
  .te-toc--inline.te-toc--collapsed .te-toc__toggle { margin-bottom: 0; }
  .te-toc--inline:not(.te-toc--collapsed) .te-toc__toggle { margin-bottom: 14px; }
  .te-toc--sidebar { display: none; }   /* sidebar hidden on mobile */
}
@media (min-width: 721px) {
  .te-toc__toggle { display: none !important; }
}
