/* 読み物の版: 本文の段が主役。OFF / ON は文中の言葉として押し、図はその言葉どおりに変わる。
   three.js の部品と入れ方の勘所は、本文を止めずに読めるよう余白の注に置く。操作できる言葉だけに色を使う。
   本文は端末の書体、見出しだけ使う字を抜き出した Noto Sans JP Black（OFL）を同梱する */
@font-face { font-family: 'Head'; src: url('../fonts/NotoSansJP-Black-head.woff2') format('woff2'); font-weight: 900; font-display: swap; }
:root {
  --paper: #fbfaf7; --ink: #23221f; --mute: #6f6a62; --rule: #e3ded4; --act: #b5461d; --actbg: #f6e2d6; --dark: #16181b;
  --body: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Noto Sans CJK JP', 'Yu Gothic UI', 'Yu Gothic', Meiryo, sans-serif;
  --head: 'Head', var(--body);
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
/* 見出しと押せる言葉は文節で折り、行の長さを揃える（「表／現」のような語の途中の折り返しを避ける） */
h1, h2, h3, .short, .seg, .badge { word-break: auto-phrase; text-wrap: balance; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 16px; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--body); font-size: 16.5px; line-height: 1.95; font-feature-settings: 'palt' 1; }
a { color: var(--act); }
body.dev { background: #000; }
body.dev > *:not(canvas) { display: none !important; }
body.dev canvas.gl { display: block; position: fixed; left: 0; top: 0; }

/* 段組み: 左に目次、中央に本文、右に余白の注。図は本文と余白の幅いっぱい */
.page { display: grid; grid-template-columns: 210px minmax(0, 640px) 260px; column-gap: 48px; justify-content: center; padding: 0 40px; }
.toc { grid-column: 1; grid-row: 1 / 3; }
nav.toc > ol { position: sticky; top: 0; max-height: 100vh; overflow-y: auto; margin: 0; padding: 40px 0 16px; list-style: none; font-size: 12px; line-height: 1.5; scrollbar-width: thin; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li.g { margin-bottom: 9px; }
.toc li li a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toc li.g > a { display: block; color: var(--ink); font-weight: 700; font-size: 12px; letter-spacing: .04em; text-decoration: none; margin-bottom: 2px; }
.toc li li a { display: block; color: var(--mute); text-decoration: none; padding: 1px 0 1px 14px; position: relative; }
.toc li li a span { font-variant-numeric: tabular-nums; margin-right: 6px; }
.toc li li a:hover { color: var(--ink); }
.toc li li a[aria-current] { color: var(--ink); font-weight: 700; }
.toc li li a[aria-current]::before { content: ''; position: absolute; left: 2px; top: .75em; width: 6px; height: 6px; border-radius: 50%; background: var(--act); }
main { grid-column: 2 / 4; min-width: 0; }
.foot { grid-column: 2 / 4; }
.hero, .tech { display: grid; grid-template-columns: minmax(0, 640px) 260px; column-gap: 48px; }

/* 冒頭 */
.kick { grid-column: 1 / 3; margin: 44px 0 0; font-size: 13px; color: var(--mute); letter-spacing: .04em; }
h1 { grid-column: 1 / 3; font-family: var(--head); font-weight: 900; font-size: 50px; line-height: 1.3; margin: 6px 0 20px; letter-spacing: .005em; }
h1 br.b:nth-of-type(2) { display: none; }
.hero .demo { grid-column: 1 / 3; grid-row: 4; margin-top: 4px; }
.hero .prose { grid-column: 1; grid-row: 3; }
.hero .side { grid-column: 2; grid-row: 3; }
.toc-sp { display: none; }

/* 章 */
.chap { border-top: 1px solid var(--ink); margin-top: 56px; padding-top: 10px; }
.chap-no { margin: 0; font-size: 13px; color: var(--mute); letter-spacing: .1em; }
.chap h2 { font-family: var(--head); font-weight: 900; font-size: 36px; line-height: 1.35; margin: 2px 0 6px; }
.chap-lead { margin: 0 0 8px; max-width: 640px; color: var(--mute); }

/* 技法 */
.tech { margin-top: 40px; }
.th { grid-column: 1 / 3; }
.tech h3 { font-family: var(--head); font-weight: 900; font-size: 30px; line-height: 1.4; margin: 0; }
.tech h3 .n { font-family: var(--body); font-weight: 400; color: var(--mute); font-size: 18px; margin-right: 12px; font-variant-numeric: tabular-nums; }
.short { font-weight: 700; margin: 2px 0 10px; }
.tech .prose { grid-column: 1; grid-row: 2; }
.tech .side { grid-column: 2; grid-row: 2; padding-top: 4px; }
.tech .demo { grid-column: 1 / 3; grid-row: 3; }
.prose p { margin: 0 0 1em; }

/* 押せる言葉 */
.t { font: inherit; font-weight: 700; color: var(--act); background: transparent; border: 0; border-bottom: 1.5px dotted var(--act); border-radius: 2px; padding: 0 3px; margin: 0 1px; cursor: pointer; line-height: inherit; white-space: nowrap; }
.t i { font-style: normal; font-size: .7em; letter-spacing: .08em; margin-right: 4px; opacity: .85; }
.t[aria-pressed='true'] { background: var(--actbg); border-bottom-style: solid; }
.t:hover { background: var(--actbg); }
.t:focus-visible, .seg:focus-visible, .cmp:focus-visible, .rvb:focus-visible, .surface:focus-visible { outline: 2px solid var(--act); outline-offset: 2px; }

/* 余白の注 */
.side { font-size: 13px; line-height: 1.8; color: var(--mute); }
.note { border-left: 2px solid var(--rule); padding-left: 12px; margin: 0 0 16px; }
.note b { display: block; color: var(--ink); font-size: 12px; letter-spacing: .06em; }
.note code { font-family: var(--mono); font-size: 12px; color: var(--ink); word-break: break-all; }

/* 図 */
.demo { margin: 4px 0 8px; }
.surface { position: relative; aspect-ratio: 16 / 9; background: var(--dark); overflow: hidden; border-radius: 4px; cursor: pointer; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.surface .poster, .surface canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.surface canvas { opacity: 0; transition: opacity .25s; }
.surface canvas.live { opacity: 1; }
.badge { position: absolute; left: 12px; top: 12px; padding: 4px 11px; font-size: 13px; font-weight: 700; color: #fff; background: rgba(20, 20, 22, .62); border-radius: 3px; pointer-events: none; letter-spacing: .02em; }
.badge i { font-style: normal; font-size: 11px; letter-spacing: .1em; margin-right: 6px; opacity: .85; }
.demo[data-s='on'] .badge { background: rgba(255, 178, 122, .94); color: #2a1608; }
.demo[data-s='split'] .badge { display: none; }
.handle { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 38px; height: 38px; border-radius: 50%; background: #fff; color: var(--ink); display: grid; place-items: center; box-shadow: 0 2px 10px rgba(0, 0, 0, .35); pointer-events: none; opacity: 0; transition: opacity .2s; }
.demo[data-s='split'] .handle { opacity: 1; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 8px; font-size: 13px; }
.sw { display: inline-flex; }
.seg { font: inherit; font-weight: 700; font-size: 13px; padding: 5px 12px; border: 1px solid var(--rule); background: transparent; color: var(--mute); cursor: pointer; }
.seg i { font-style: normal; font-size: 10.5px; letter-spacing: .1em; margin-right: 6px; }
.seg:first-child { border-radius: 4px 0 0 4px; } .seg:last-child { border-radius: 0 4px 4px 0; border-left: 0; }
.seg[aria-pressed='true'] { background: var(--actbg); border-color: var(--act); color: var(--act); }
.seg:last-child[aria-pressed='true'] { border-left: 1px solid var(--act); margin-left: -1px; }
.cmp, .rvb { font: inherit; font-size: 12.5px; padding: 5px 10px; border: 1px solid var(--rule); border-radius: 4px; background: transparent; color: var(--mute); cursor: pointer; }
.cmp[aria-pressed='true'], .rvb[aria-pressed='true'] { border-color: var(--ink); color: var(--ink); }
.stats { margin-left: auto; color: var(--mute); font-size: 12px; font-variant-numeric: tabular-nums; }

.foot { margin-top: 64px; padding: 24px 0 64px; border-top: 1px solid var(--rule); color: var(--mute); font-size: 13px; }

/* 狭い画面: 目次は冒頭の後に畳んで置く。技法は 題名 → 図 → 本文 → 注 の順にし、題名のすぐ下で図が見えるようにする */
@media (max-width: 1080px) {
  .page { grid-template-columns: minmax(0, 1fr); padding: 0 20px; column-gap: 0; }
  .toc { display: none; }
  main, .foot { grid-column: 1; }
  .hero, .tech { grid-template-columns: minmax(0, 1fr); column-gap: 0; }
  .kick, h1, .hero .demo, .hero .prose, .hero .side, .th, .tech .prose, .tech .side, .tech .demo { grid-column: 1; grid-row: auto; }
  .kick { margin-top: 22px; font-size: 12px; }
  h1 { font-size: 31px; margin-bottom: 14px; }
  h1 br.b:nth-of-type(2) { display: inline; }
  body { font-size: 15.5px; line-height: 1.9; }
  .demo { margin: 4px -20px 18px; }
  .surface { border-radius: 0; }
  .bar { padding: 0 20px; }
  .sw { display: flex; width: 100%; }
  .seg { flex: 1; font-size: 13px; padding: 9px 8px; line-height: 1.45; }
  .seg i { display: block; margin: 0; }
  .stats { margin-left: 0; width: 100%; }
  .toc-sp { display: block; margin: 8px 0 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); font-size: 14px; }
  .toc-sp summary { padding: 10px 0; font-weight: 700; cursor: pointer; }
  .toc-sp ol { list-style: none; margin: 0 0 12px; padding: 0; line-height: 1.9; }
  .toc-sp li.g > a { font-weight: 700; color: var(--ink); text-decoration: none; }
  .toc-sp li li a { color: var(--mute); text-decoration: none; padding-left: 14px; display: block; }
  .toc-sp li li a span { margin-right: 6px; font-variant-numeric: tabular-nums; }
  .chap { margin-top: 40px; }
  .chap h2 { font-size: 27px; }
  .tech { margin-top: 32px; }
  .tech h3 { font-size: 24px; }
  .tech h3 .n { font-size: 15px; margin-right: 8px; }
}
