/* ---------------------------------------------------------
   普賢岳アーカイブの研究ページ（research-fugen.html）だけで使う図と表。
   白黒と罫線で組み、赤（--brand）は「守る・止める・外に出さない」ものだけに使う。
   動きは画面に入ったとき（.is-on）だけ。止めたい人には最後の形を見せる。
   表（.fg-table）・数字の帯（.fg-nums）・切り替え（.fg-seg）はクルーズのページでも使う。
   スマホでは、横長の図を縦向きの図（.fg-sp）に差し替え、表は 1 行ずつ縦に積む。
   --------------------------------------------------------- */

/* PC 用の図とスマホ用の図 */
.fg-sp { display: none !important; }

/* 図の中の段落・表どうしの間 */
.rs-story__item > .fg-table,
.rs-story__item > .fg-nums,
.rs-story__item > .fg-trust,
.rs-story__item > .fg-log { margin-top: 12px; }
.rs-story__item > .rs-points { margin-top: 12px; }
.rs-story__item > .body-text + .body-text { margin-top: 8px; }

/* 構成図は四つ並べる */
.rs-stack__top.fg-stack4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1280px) and (min-width: 768px) {
  .rs-stack__top.fg-stack4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- 数字で見る ---------- */
.fg-nums {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 2px solid var(--ink);
}
.fg-num {
  display: flex; flex-direction: column; gap: 6px;
  padding: 22px 22px 24px 0; border-bottom: 1px solid var(--line);
}
.fg-num:not(:nth-child(3n + 1)) { padding-left: 22px; border-left: 1px solid var(--line); }
.fg-num__v {
  display: flex; align-items: baseline; gap: 4px;
  font-size: clamp(40px, 4.4vw, 60px); font-weight: 800; line-height: 1; letter-spacing: -.04em;
  font-variant-numeric: tabular-nums; color: var(--ink);
}
.fg-num__v small { font-size: 15px; font-weight: 700; letter-spacing: 0; color: var(--ink); }
.fg-num__k { margin-top: 6px; font-size: 14px; font-weight: 800; }
.fg-num__t { font-size: 13px; line-height: 1.7; color: var(--sub); }

/* ---------- 表（誌面の罫線） ---------- */
.fg-table {
  width: 100%; border-collapse: collapse;
  border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink);
  font-size: 14px; line-height: 1.75;
}
.fg-table th, .fg-table td { padding: 12px 14px 12px 0; text-align: left; vertical-align: top; }
.fg-table td + td, .fg-table th + td, .fg-table th + th { padding-left: 14px; }
.fg-table thead th { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--ink); }
.fg-table tbody tr + tr > * { border-top: 1px solid var(--line); }
.fg-table tbody th { width: 26%; font-weight: 800; color: var(--ink); }
.fg-table td { color: var(--sub); }
.fg-table tbody th span { display: block; margin-top: 2px; font-weight: 600; color: var(--sub); }
.fg-table s { color: var(--brand); text-decoration-thickness: 1px; }

/* ---------- 図の共通 ---------- */
.fg-fig svg { display: block; width: 100%; height: auto; overflow: visible; }
.fg-fig text { font-family: var(--font-jp); text-anchor: middle; dominant-baseline: middle; }

/* 振り分け */
.fg-route__wires path { fill: none; stroke: var(--line); stroke-width: 2; }
.fg-route rect { fill: #fff; stroke: var(--ink); stroke-width: 1.5; }
.fg-route rect.is-key { stroke: var(--brand); }
.fg-route text { font-size: 17px; font-weight: 800; fill: var(--ink); }
.fg-route text.is-sub { font-size: 13px; font-weight: 600; fill: var(--muted); }
.fg-route__judge rect { fill: var(--ink); stroke: var(--ink); }
.fg-route__judge text, .fg-route__judge text.is-sub { fill: #fff; }
.fg-route__judge text.is-sub { opacity: .75; }
.fg-route__stop circle { fill: #fff; stroke: var(--brand); stroke-width: 2; }
.fg-route__stop path { stroke: var(--brand); stroke-width: 2.4; stroke-linecap: round; }
.fg-route__dots circle { fill: var(--ink); }
.fg-route__dots circle.is-key { fill: var(--brand); }

/* 関門 */
.fg-gate__rail { stroke: var(--line); stroke-width: 2; }
.fg-gate__bars line { stroke: var(--ink); stroke-width: 2; }
.fg-gate__label text { font-size: 15px; font-weight: 800; fill: var(--ink); }
.fg-gate__label text.is-sub { font-size: 12px; font-weight: 600; fill: var(--muted); }
.fg-gate__label.is-left text { text-anchor: start; }
.fg-gate__end rect { fill: var(--ink); }
.fg-gate__end text { font-size: 14px; font-weight: 800; fill: #fff; }
.fg-gate__end text.is-sub { font-size: 12px; font-weight: 600; opacity: .75; }
.fg-gate__dots circle { fill: var(--ink); opacity: 0; }
.fg-gate__dots circle.is-out { fill: var(--brand); }
.is-on .fg-gate__dots circle { animation: fg-pass 5.6s var(--ease) var(--d) infinite; }
.is-on .fg-gate__dots circle.is-out { animation-name: fg-drop; }
.is-on .fg-gate__dots.is-y circle { animation-name: fg-pass-y; }
.is-on .fg-gate__dots.is-y circle.is-out { animation-name: fg-drop-y; }
@keyframes fg-pass-y {
  0%   { opacity: 0; transform: translateY(0); }
  6%   { opacity: 1; }
  70%  { opacity: 1; transform: translateY(var(--to)); }
  85%, 100% { opacity: 0; transform: translateY(var(--to)); }
}
@keyframes fg-drop-y {
  0%   { opacity: 0; transform: translate(0, 0); }
  6%   { opacity: 1; }
  55%  { opacity: 1; transform: translate(0, var(--to)); }
  75%, 100% { opacity: 0; transform: translate(-24px, var(--to)); }
}
@keyframes fg-pass {
  0%   { opacity: 0; transform: translateX(0); }
  6%   { opacity: 1; }
  70%  { opacity: 1; transform: translateX(var(--to)); }
  85%, 100% { opacity: 0; transform: translateX(var(--to)); }
}
@keyframes fg-drop {
  0%   { opacity: 0; transform: translate(0, 0); }
  6%   { opacity: 1; }
  55%  { opacity: 1; transform: translate(var(--to), 0); }
  75%, 100% { opacity: 0; transform: translate(var(--to), 22px); }
}

/* 確かさの順位。上ほど太い線、下ほど細く薄い線 */
.fg-trust { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--ink); }
.fg-trust li {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px;
  padding: 14px 0 14px 28px; border-bottom: 1px solid var(--line);
  font-size: 14px; line-height: 1.75;
}
.fg-trust li::before {
  content: ''; position: absolute; left: 0; top: 14px; bottom: 14px;
  width: var(--bar, 6px); background: var(--ink); opacity: var(--op, 1);
  transform: scaleY(0); transform-origin: top;
  transition: transform .7s var(--reveal-ease, ease) calc(var(--i) * 120ms);
}
.fg-trust.is-on li::before { transform: none; }
.fg-trust li:nth-child(1) { --i: 0; --bar: 8px; }
.fg-trust li:nth-child(2) { --i: 1; --bar: 7px; --op: .85; }
.fg-trust li:nth-child(3) { --i: 2; --bar: 6px; --op: .7; }
.fg-trust li:nth-child(4) { --i: 3; --bar: 5px; --op: .55; }
.fg-trust li:nth-child(5) { --i: 4; --bar: 3px; --op: .4; }
.fg-trust li:nth-child(6) { --i: 5; --bar: 2px; --op: .25; }
.fg-trust__what { font-weight: 800; color: var(--ink); }
.fg-trust__how { color: var(--sub); }

/* ---------- 新聞の読み取り ---------- */
.fg-ocr__body { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 28px; align-items: stretch; }
.fg-ocr__paper svg { border: 1px solid var(--line); background: #f6f3ec; }
.fg-ocr__paper .ink { fill: #3a3a3a; }
.fg-ocr__paper .ink-line { stroke: #6f6f6f; stroke-width: 2.4; stroke-dasharray: 3 2; }
.fg-ocr__paper .head-text { font-size: 20px; font-weight: 800; fill: #222; }
.fg-ocr__paper .mast-text { font-size: 17px; font-weight: 800; fill: #fff; }
.fg-ocr__paper .ad rect { fill: none; stroke: #6f6f6f; stroke-width: 1.5; }
.fg-ocr__paper .ad text { font-size: 15px; font-weight: 700; fill: #6f6f6f; }
.fg-ocr__paper .box { fill: transparent; stroke: transparent; stroke-width: 1; transition: fill .5s, stroke .3s; transition-delay: calc(var(--k) * 18ms); }
.fg-ocr__paper .rule { stroke: #8a8a8a; stroke-width: 1; stroke-dasharray: 400; stroke-dashoffset: 0; transition: stroke .3s, stroke-width .3s; }
.fg-ocr__paper .scan { fill: var(--brand); opacity: 0; }
.fg-ocr__paper .tag { opacity: 0; transition: opacity .4s; }
.fg-ocr__paper .tag rect { fill: var(--ink); }
.fg-ocr__paper .tag text { font-size: 13px; font-weight: 800; fill: #fff; }
.fg-ocr__paper .tag.is-out rect { fill: var(--brand); }
.fg-ocr__paper .ad-x { stroke: var(--brand); stroke-width: 1.5; opacity: 0; transition: opacity .4s; }

.fg-ocr[data-stage="0"] .scan { animation: fg-scan 2.2s linear; }
@keyframes fg-scan { 0% { opacity: .5; transform: translateX(470px); } 100% { opacity: .5; transform: translateX(0); } }
.fg-ocr[data-stage="1"] .box,
.fg-ocr[data-stage="2"] .box { stroke: var(--ink); }
.fg-ocr[data-stage="2"] .rule,
.fg-ocr[data-stage="3"] .rule,
.fg-ocr[data-stage="4"] .rule { stroke: var(--brand); stroke-width: 2.2; animation: fg-draw 1s var(--ease); }
@keyframes fg-draw { from { stroke-dashoffset: 400; } to { stroke-dashoffset: 0; } }
.fg-ocr[data-stage="3"] .box.a, .fg-ocr[data-stage="4"] .box.a { fill: rgba(0, 0, 0, .16); stroke: var(--ink); }
.fg-ocr[data-stage="3"] .box.b, .fg-ocr[data-stage="4"] .box.b { fill: rgba(0, 0, 0, .05); stroke: #9a9a9a; }
.fg-ocr[data-stage="3"] .tag, .fg-ocr[data-stage="4"] .tag,
.fg-ocr[data-stage="3"] .ad-x, .fg-ocr[data-stage="4"] .ad-x { opacity: 1; }

.fg-ocr__out {
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px; border: 1px solid var(--line);
}
.fg-ocr__field { display: flex; flex-direction: column; gap: 6px; }
.fg-ocr__field p { font-size: 12px; font-weight: 800; color: var(--ink); }
.fg-ocr__field small { margin-left: 8px; font-size: 11px; font-weight: 600; color: var(--muted); }
.fg-ocr__bar {
  display: block; height: 7px; width: var(--w); background: var(--ink);
  transform: scaleX(0); transform-origin: left; opacity: .8;
  transition: transform .8s var(--ease);
}
.fg-ocr__field:nth-child(1) .fg-ocr__bar { height: 11px; }
.fg-ocr__field:nth-child(4) .fg-ocr__bar { background: var(--muted); }
.fg-ocr[data-stage="4"] .fg-ocr__bar { transform: none; }
.fg-ocr[data-stage="4"] .fg-ocr__field:nth-child(2) .fg-ocr__bar { transition-delay: .15s; }
.fg-ocr[data-stage="4"] .fg-ocr__field:nth-child(3) .fg-ocr__bar { transition-delay: .3s; }
.fg-ocr[data-stage="4"] .fg-ocr__field:nth-child(3) .fg-ocr__bar + .fg-ocr__bar { transition-delay: .45s; }
.fg-ocr[data-stage="4"] .fg-ocr__field:nth-child(4) .fg-ocr__bar { transition-delay: 1s; }
.fg-ocr__flag {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 12px; font-weight: 700; line-height: 1.5; color: var(--sub);
}
.fg-ocr__flag b { flex: none; color: var(--muted); transition: color .3s; }
.fg-ocr[data-stage="4"] .fg-ocr__flag b { color: var(--brand); transition-delay: 1.4s; }

/* 段階の名前。いまの段階に下線 */
.fg-steps {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px;
  list-style: none; margin: 0; padding: 0;
}
.fg-steps li {
  padding-top: 10px; border-top: 2px solid var(--line);
  font-size: 12px; font-weight: 700; line-height: 1.5; color: var(--dim);
  transition: color .3s, border-color .3s;
}
.fg-steps li.is-now { color: var(--ink); border-top-color: var(--ink); }

/* ---------- モザイクの見本 ---------- */
.fg-mosaic__body { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 28px; align-items: start; }
.fg-mosaic__canvas { display: block; width: 100%; height: auto; border: 1px solid var(--line); image-rendering: pixelated; }
.fg-mosaic__ctrl { display: flex; flex-direction: column; gap: 14px; }
.fg-mosaic__label { font-size: 12px; font-weight: 800; letter-spacing: .06em; color: var(--muted); }
.fg-seg { display: flex; flex-wrap: wrap; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.fg-seg button {
  flex: 1 1 auto; padding: 10px 8px; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 700; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.fg-seg button[aria-checked="true"] { color: var(--ink); border-bottom-color: var(--brand); }
.fg-seg button:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.fg-check { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; cursor: pointer; }
.fg-check input { accent-color: var(--ink); width: 16px; height: 16px; }
.fg-mosaic__calc { min-height: 34px; font-size: 14px; font-weight: 700; color: var(--sub); }
.fg-mosaic__calc b { font-size: 28px; font-weight: 800; letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; }
.fg-mosaic__note { font-size: 12px; line-height: 1.8; color: var(--muted); }

/* ---------- 統合リサーチの流れ ---------- */
.fg-flow {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0;
  list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--ink);
}
.fg-flow li {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  padding: 16px 14px 18px; border-bottom: 1px solid var(--line);
  transition: background-color .4s;
}
.fg-flow li + li { border-left: 1px solid var(--line); }
.fg-flow li + li::before {
  content: ''; position: absolute; left: -5px; top: 24px;
  width: 9px; height: 9px; background: #fff; border-top: 1.5px solid var(--ink); border-right: 1.5px solid var(--ink);
  transform: rotate(45deg);
}
.fg-flow .material-symbols-outlined { font-size: 22px; color: var(--ink); }
.fg-flow b { font-size: 14px; font-weight: 800; }
.fg-flow span:not(.material-symbols-outlined) { font-size: 12px; line-height: 1.7; color: var(--sub); }
.fg-flow li.is-now { background: var(--bg-soft); }
.fg-flow li.is-now .material-symbols-outlined { color: var(--brand); }

.fg-answer { padding: 18px 20px; border-left: 3px solid var(--ink); background: var(--bg-soft); }
.fg-answer__head { font-size: 12px; font-weight: 800; letter-spacing: .06em; color: var(--muted); }
.fg-answer__text { margin-top: 6px; font-size: 14px; line-height: 1.9; color: var(--ink); }
.fg-answer sup { font-size: 11px; font-weight: 800; color: var(--brand); vertical-align: super; }

/* ---------- 開発の記録 ---------- */
.fg-log { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--ink); max-width: 760px; }
.fg-log li { align-items: baseline; display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 20px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.fg-log time { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.fg-log p { font-size: 14px; line-height: 1.8; color: var(--sub); }

/* ---------- 狭い画面 ---------- */
@media (max-width: 767px) {
  /* 表や図の幅で列が広がらないよう、列の最小幅を 0 にする */
  #fugen .rs-theme__grid { grid-template-columns: minmax(0, 1fr); }
  #fugen .rs-story, #fugen .rs-story__item, #fugen .rs-fig { min-width: 0; }
  .fg-table { overflow-wrap: anywhere; }
  .rs-stack__top.fg-stack4 { grid-template-columns: 1fr; }
  .fg-pc { display: none !important; }
  .fg-sp { display: block !important; }

  /* 表は見出しの行を隠し、1 行を「行の見出し＋列名つきの値」の塊にして縦に積む（列名は fugen.js が data-label に入れる） */
  .fg-table, .fg-table tbody, .fg-table tr, .fg-table th, .fg-table td { display: block; width: auto; }
  .fg-table thead { display: none; }
  .fg-table tbody tr { padding: 14px 0; }
  .fg-table tbody tr + tr { border-top: 1px solid var(--line); }
  .fg-table tbody tr + tr > * { border-top: 0; }
  .fg-table tbody th { width: auto; padding: 0 0 6px; font-size: 14px; }
  .fg-table td, .fg-table td + td, .fg-table th + td { display: grid; grid-template-columns: 6.5em minmax(0, 1fr); gap: 12px; padding: 3px 0; }
  .fg-table td::before { content: attr(data-label); font-size: 11px; font-weight: 700; line-height: 2; color: var(--muted); }
  .fg-table td:not([data-label])::before, .fg-table td[data-label=""]::before { content: none; }
  .fg-table td[data-label=""], .fg-table td:not([data-label]) { display: block; }

  /* 縦向きの図は字を大きめに */
  .fg-route.fg-sp .fg-route__node text { font-size: 14px; }
  .fg-route.fg-sp .fg-route__ai text { font-size: 15px; }
  .fg-route.fg-sp text.is-sub { font-size: 12px; }
  .fg-route.fg-sp .fg-route__judge text { font-size: 17px; }
  .fg-route.fg-sp .fg-route__judge text.is-sub { font-size: 13px; }
  .fg-gate.fg-sp .fg-gate__label text { font-size: 17px; }
  .fg-gate.fg-sp .fg-gate__label text.is-sub { font-size: 13px; }
  .fg-gate.fg-sp .fg-gate__end text { font-size: 15px; }

  .fg-ocr__out { padding: 14px; gap: 10px; }
  .fg-ocr__flag { margin-top: 4px; }
  .fg-nums { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fg-num, .fg-num:not(:nth-child(3n + 1)) { padding: 18px 14px 18px 0; border-left: 0; }
  .fg-num:nth-child(2n) { padding-left: 14px; border-left: 1px solid var(--line); }
  .fg-num__v small { font-size: 13px; }
  .fg-table { font-size: 13px; }
  .fg-table th, .fg-table td { padding: 10px 8px 10px 0; }
  .fg-table td + td, .fg-table th + td, .fg-table th + th { padding-left: 8px; }
  .fg-trust li { grid-template-columns: 1fr; gap: 2px; padding-left: 22px; font-size: 13px; }
  .fg-ocr__body, .fg-mosaic__body { grid-template-columns: 1fr; gap: 16px; }
  .fg-steps { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fg-flow { grid-template-columns: 1fr; }
  .fg-flow li { flex-direction: row; flex-wrap: wrap; align-items: center; column-gap: 10px; padding: 12px 0; }
  .fg-flow li + li { border-left: 0; }
  .fg-flow li + li::before { display: none; }
  .fg-flow span:not(.material-symbols-outlined) { flex-basis: 100%; padding-left: 32px; }
  .fg-log li { grid-template-columns: 52px minmax(0, 1fr); gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .is-on .fg-gate__dots circle { animation: none; }
  .fg-route__dots { display: none; }
  .fg-gate__dots circle { opacity: 0; }
  .fg-trust li::before { transform: none; transition: none; }
  .fg-ocr__bar, .fg-ocr__paper .box, .fg-ocr__paper .tag, .fg-ocr__flag b { transition: none; }
  .fg-ocr .rule { animation: none !important; }
}
