:root{
  --ink:#1f2937;
  --muted:#6b7280;
  --brand:#2563eb;
  --bg:#f8fafc;
  --card:#ffffff;
}

html{
  scroll-behavior:smooth;
}

body{
  margin:0;
  font-family:system-ui,-apple-system,BlinkMacSystemFont,sans-serif;
  background:var(--bg);
  color:var(--ink);
  line-height:1.8;
  overflow-x:hidden; /* ← スマホ横はみ出し保険 */
}

/* ✅ wrap：PCは最大1024px、スマホは100% */
.wrap{
  background: gold;
  width:100%;
  max-width:1024px;     /* ← PCの基準幅 */
  margin:0 auto;
  position:relative;
}

/* メイン */
main{
  max-width:960px;
  margin:auto;
  padding:24px;
  background: red;
}

h1,h2,h3{
  line-height:1.4;
}

h1{
  font-size:1.8rem;
  margin-bottom:16px;
}

h2{
  margin-top:0;
  font-size:1.4rem;
  border-left:6px solid var(--brand);
  padding-left:12px;
}

h3{
  margin-top:24px;
  font-size:1.15rem;
}

section{
  background:var(--card);
  border-radius:12px;
  padding:20px;
  margin-bottom:24px;
  box-shadow:0 6px 20px rgba(0,0,0,.05);
}

code,pre{
  background:#0f172a;
  color:#e5e7eb;
  border-radius:8px;
}

code{
  padding:2px 6px;
}

pre{
  padding:16px;
  overflow:auto;
}

ul{
  padding-left:20px;
}

.note{
  background:#eef2ff;
  border-left:4px solid var(--brand);
  padding:12px;
  margin:16px 0;
}

small{
  color:var(--muted);
}

/* ===============================
📑 目次（TOC）基本デザイン
=============================== */
.toc{
  background:#f1f5f9;
  border:1px solid #e5e7eb;
  border-radius:12px;
  padding:16px;
  margin:20px 0 28px;
}

.toc-header{
  font-weight:700;
  margin-bottom:10px;
}

.toc ul{
  list-style:none;
  padding-left:0;
  margin:0;
}

.toc li{
  margin:6px 0;
}

.toc a{
  color:var(--brand);
  text-decoration:none;
}

.toc a:hover{
  text-decoration:underline;
}

/* 現在地ハイライト */
.toc a.active{
  font-weight:700;
  color:#1d4ed8;
  background:#e0e7ff;
  padding:2px 6px;
  border-radius:6px;
}

/* スクロールの微調整 */
main h2{
  scroll-margin-top: 8px;
}

/* ===============================
✅ PC：TOC を wrap内に置きつつ固定表示
（PCだけに限定）
=============================== */
@media (min-width: 1024px){

  body{
    display:block;
  }

  /* main は TOC 幅分だけ右にずらす */
  main{
    margin-left:260px;
  }

  /* ✅ fixed でも「wrapの左端位置」に固定 */
  .toc{
    position:fixed;
    top:20px;

    /* wrapは最大1024pxなので半分=512px */
    left:50%;
    transform:translateX(-512px);

    width:220px;
    max-height:90vh;
    overflow:auto;
    z-index:100;
  }
}

/* ===============================
📱 スマホ最適化（元の挙動を維持）
=============================== */
@media (max-width: 768px){

  body{
    font-size:16px;
    line-height:1.9;
  }

  /* ✅ スマホは wrap を自然に100%（max-widthがあるのでOK） */
  .wrap{
    width:100%;
    max-width:100%;
  }

  main{
    padding:16px 14px;
  }

  h1{
    font-size:1.6rem;
    margin-bottom:20px;
  }

  h2{
    font-size:1.35rem;
    margin-top:32px;
  }

  h3{
    font-size:1.15rem;
    margin-top:24px;
  }

  p, li{
    font-size:1rem;
  }

  ul{
    padding-left:22px;
  }

  section{
    padding:18px 16px;
  }

  code{
    font-size:0.95rem;
    padding:4px 6px;
  }

  pre{
    font-size:0.9rem;
    padding:14px;
    line-height:1.6;
    overflow-x:auto;
  }

  .note{
    font-size:0.95rem;
    padding:14px;
  }
}

/* ===============================
📱 目次（スマホ開閉アニメーション）
=============================== */
@media (max-width: 768px){

  .toc{
    padding:14px;
  }

  .toc-header{
    cursor:pointer;
  }

  .toc ul{
    list-style:none;
    padding-left:0;
    margin:0;

    max-height:0;
    overflow:hidden;
    opacity:0;
    transition:
      max-height 0.35s ease,
      opacity 0.25s ease;
  }

  .toc.open ul{
    max-height:600px;
    opacity:1;
  }
}
