/* データマネジメント史クロノマップ(試作) */
:root {
  --bg: #f5f7fa; --surface: #fff; --ink: #1c2733; --muted: #5b6b7a; --line: #d5dde6;
  --blue: #24466e; --blue-soft: #e4ecf6; --amber: #b8741c; --amber-soft: #f7ecdc;
  --edge: #1c2733;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #10161d; --surface: #171f28; --ink: #e6ecf2; --muted: #9aa8b5; --line: #2a3642;
    --blue: #8fb4e3; --blue-soft: #1d2b3c; --amber: #e0a34a; --amber-soft: #3a2c16; --edge: #e6ecf2; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
/* body は画面に固定(iOS Safari は body の overflow: hidden を無視して指でスクロールできてしまい、ヘッダが画面外に出る) */
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Hiragino Sans", "Yu Gothic", Meiryo, system-ui, sans-serif; font-size: 14.5px; line-height: 1.7; display: flex; flex-direction: column; overflow: hidden; position: fixed; inset: 0; width: 100%; }
button { font: inherit; color: inherit; background: none; border: 1px solid var(--line); border-radius: 6px; padding: .2em .7em; cursor: pointer; }
button:hover { border-color: var(--blue); }
button:disabled { opacity: .4; cursor: default; }
button.on { background: var(--blue); color: var(--surface); border-color: var(--blue); }
a { color: var(--blue); }
.mono { font-family: Consolas, "Courier New", monospace; }
.small { font-size: .8em; color: var(--muted); }
.hint { color: var(--muted); }

/* ヘッダー */
.top { flex: none; display: flex; align-items: center; gap: .8rem; padding: .45rem .9rem; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }   /* 万一スクロールしても常に上に */
.brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.brand .tag { font-size: .7rem; font-weight: 600; color: var(--amber); border: 1px solid var(--amber); border-radius: 999px; padding: 0 .5em; }
.brand .sub { font-size: .78rem; color: var(--muted); font-weight: 400; }
.top nav { display: flex; gap: .4rem; align-items: center; flex: 1; }
.top nav button, .zoom { white-space: nowrap; }
.top input { font: inherit; padding: .2em .6em; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); width: min(16rem, 40vw); }
.zoom { display: flex; align-items: center; gap: .3rem; font-size: .8rem; color: var(--muted); }
.zoom button { padding: 0 .55em; }
.tools { display: flex; align-items: center; gap: .3rem; font-size: .78rem; flex-wrap: wrap; }
.tools button, .tools .lvc { white-space: nowrap; flex: none; }
.tools button { padding: .05em .55em; font-size: .78rem; }
.tools .hintd { color: var(--muted); }
.tools .lvc { display: inline-flex; align-items: center; gap: 0; margin-right: .3rem; }
.tools .lvc button { border-radius: 0; margin-left: -1px; }
.tools .lvc button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.tools .lvc button:nth-child(3) { border-radius: 0 6px 6px 0; }
.tools .lvc .hintd { margin-left: .35rem; font-family: Consolas, monospace; }

/* 本体: 左に系統図、右にパネル */
main { flex: 1; min-height: 0; display: flex; }
#chartWrap { flex: 1; min-width: 0; position: relative; overflow: auto; background: var(--surface); }
#chart { display: block; }
#lanes { position: sticky; left: 0; width: 0; height: 0; z-index: 2; pointer-events: none; }   /* 横だけ固定。縦は図と一緒に動く */
#lanes .lane { position: absolute; left: 0; width: 11rem; display: flex; align-items: flex-start; padding-top: .3rem; font-size: .78rem; font-weight: 700; background: linear-gradient(90deg, var(--surface) 55%, transparent); pointer-events: none; user-select: none; }   /* 帯は素通し(下の箱を触れるように)。ボタンとつまみだけ受ける */
#lanes .lane .tg { border: none; border-radius: 0; padding: .1em .4em .1em .6rem; font: inherit; color: inherit; display: flex; align-items: center; gap: .3rem; text-align: left; cursor: pointer; pointer-events: auto; }
#lanes .lane .tg:hover .nm { text-decoration: underline; }
#lanes .lane .car { font-size: .7rem; opacity: .7; }
#lanes .lane .cnt { font-weight: 400; font-size: .7rem; opacity: .7; }
#lanes .lane.off .tg { font-weight: 600; opacity: .8; }
#lanes .lane .rs { position: absolute; left: 0; width: 5rem; bottom: -4px; height: 9px; cursor: row-resize; touch-action: none; z-index: 3; pointer-events: auto; }   /* 次のレーン名より上に */
#lanes .lane .rs::after { content: ""; position: absolute; left: .6rem; width: 2.2rem; top: 3px; height: 3px; border-radius: 2px; background: currentColor; opacity: .25; }
#lanes .lane .rs:hover::after, #lanes .lane.sized .rs::after { opacity: .7; }
#chartWrap { touch-action: none; }
#chart .node { touch-action: none; }
#panel { flex: none; width: 400px; overflow: auto; border-left: 1px solid var(--line); padding: .8rem 1rem 2rem; background: var(--bg); }
@media (max-width: 820px) {
  .top { padding: .35rem .6rem; gap: .4rem .6rem; }
  .brand { font-size: .95rem; }
  .brand .sub { display: none; }
  .top input { width: 9rem; }
  main { flex-direction: column; }
  #chartWrap { flex: 0 1 46vh; min-height: 8rem; }   /* 画面が低ければ縮む(本文がはみ出さない) */
  #panel { width: auto; flex: 1; min-height: 6rem; border-left: none; border-top: 1px solid var(--line); }
  #lanes .lane { width: 8rem; font-size: .7rem; }
  #lanes .lane .rs { height: 14px; bottom: -7px; }
}

/* 系統図の中身 */
#chart .tick { stroke: var(--edge); stroke-opacity: .08; }
#chart .tick.major { stroke-opacity: .18; }
#chart .yr { font-size: 11px; fill: var(--muted); font-family: Consolas, monospace; }
#chart .edge { fill: none; stroke: var(--edge); stroke-opacity: .28; stroke-width: 1.1; transition: stroke-opacity .15s; }
#chart .edge.re { stroke: var(--amber); stroke-opacity: .8; stroke-width: 1.5; stroke-dasharray: 5 4; }
#chart .ahp { fill: var(--edge); fill-opacity: .5; }
#chart .ahr { fill: var(--amber); }
#chartWrap.grab { cursor: grab; }
#chartWrap.grabbing { cursor: grabbing; }
#chart .node { cursor: pointer; }
#chart .node.moved rect { stroke-dasharray: 3 2; }
#chart .node.dragging rect { stroke-width: 3; }
#chart.edges-sel .edge:not(.on):not(.re) { display: none; }
#chart.edges-sel .edge.re:not(.on) { stroke-opacity: .3; }
#chart .node rect { fill: var(--surface); stroke-width: 1.3; }
#chart .node.imp3 rect { stroke-width: 2.2; }
#chart .node text { font-size: 11.5px; fill: var(--ink); pointer-events: none; }
#chart .node.imp1 text { fill: var(--muted); }
#chart .node:hover rect, #chart .node:focus rect { stroke-width: 2.6; }
#chart .node:focus { outline: none; }
#chart.has-sel .node { opacity: .38; }
#chart.has-sel .node.sel, #chart.has-sel .node.rel { opacity: 1; }
#chart.has-sel .node.sel rect { fill: var(--blue-soft); stroke-width: 3; }
#chart.has-sel .node.sel text { font-weight: 700; }
#chart.has-sel .edge { stroke-opacity: .08; }
#chart.has-sel .edge.re { stroke-opacity: .2; }
#chart.has-sel .edge.on { stroke-opacity: .9; stroke-width: 1.8; }
#chart.has-sel .edge.re.on { stroke-opacity: 1; stroke-width: 2; }

/* パネル共通 */
.ph h2 { font-size: 1.15rem; margin: .1rem 0 .3rem; line-height: 1.4; }
.meta { display: flex; flex-wrap: wrap; gap: .3rem .6rem; align-items: center; font-size: .78rem; color: var(--muted); }
.meta .yr { font-family: Consolas, monospace; color: var(--blue); font-weight: 700; }
.meta .lanetag { border: 1px solid; border-radius: 999px; padding: 0 .5em; font-weight: 600; }
.meta .imp { color: var(--amber); letter-spacing: -.05em; }
.meta .lens { border: 1px solid var(--amber); color: var(--amber); border-radius: 999px; padding: 0 .5em; font-weight: 600; }
.who { font-size: .85rem; color: var(--muted); }
p.d { margin: .5rem 0; }
/* モデル図のイメージ(ピンの詳細の右上) */
.figbox { float: right; width: 52%; margin: 0 0 .5rem .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: .35rem .35rem .2rem; }
.figbox .cap { font-size: .72rem; color: var(--muted); text-align: center; margin-top: .15rem; }
.fig { width: 100%; height: auto; display: block; font-family: "Hiragino Sans", "Yu Gothic", Meiryo, system-ui, sans-serif; }
.fig text { font-size: 9px; fill: var(--ink); }
.fig text.m { font-size: 8px; fill: var(--muted); }
.fig text.code { font-family: Consolas, "Courier New", monospace; font-size: 8.5px; }
.fig text.code2 { font-family: Consolas, "Courier New", monospace; font-size: 8px; fill: var(--muted); }
.fig .b { fill: var(--surface); stroke: var(--blue); stroke-width: 1.1; }
.fig .b2 { fill: var(--blue-soft); }
.fig .b3 { fill: var(--bg); stroke: var(--line); }
.fig .ctx { fill: none; stroke: var(--amber); stroke-dasharray: 3 2; }
.fig .ctx2 { fill: var(--amber-soft); stroke: var(--amber); }
.fig .l { stroke: var(--ink); stroke-opacity: .55; stroke-width: 1; fill: none; }
.fig .l.hl { stroke: var(--amber); stroke-opacity: 1; stroke-width: 1.3; }
.fig .ah { fill: var(--ink); fill-opacity: .55; }
.fig .ah.hl { fill: var(--amber); fill-opacity: 1; }
.fig .dot { fill: var(--blue); }
.fig .q { fill: var(--amber); }
.fig .ring { fill: none; stroke: var(--amber); stroke-dasharray: 3 2; }
.fig .tri { fill: var(--blue-soft); stroke: var(--blue); }
.ph::after, .pin-detail::after { content: ""; display: block; clear: both; }
.clearfix { clear: both; }
dl.qa { margin: .6rem 0; display: grid; grid-template-columns: 7.5em 1fr; gap: .25rem .6rem; font-size: .9rem; border-left: 3px solid var(--amber); padding-left: .7rem; }
dl.qa dt { color: var(--amber); font-weight: 700; }
dl.qa dd { margin: 0; }
h3 { font-size: .82rem; color: var(--muted); margin: .9rem 0 .3rem; letter-spacing: .04em; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip { display: inline-flex; align-items: center; gap: .35em; font-size: .82rem; padding: .1em .6em; background: var(--surface); }
.chip .cy { font-family: Consolas, monospace; font-size: .8em; color: var(--blue); }
.chip.re { border-color: var(--amber); }
.chip.river { border-color: var(--blue); }
ul.re, ul.src { list-style: none; padding: 0; margin: 0; }
ul.re li { margin: .25rem 0; display: flex; flex-wrap: wrap; gap: .2rem .5rem; align-items: baseline; }
ul.re .note { font-size: .82rem; color: var(--muted); }
ul.src li { font-size: .84rem; margin: .2rem 0; }
.foot { display: flex; justify-content: space-between; align-items: center; margin-top: 1.2rem; padding-top: .6rem; border-top: 1px solid var(--line); gap: .5rem; }
.lnk { font-size: .85rem; }

/* 大河 */
.meta .rt { color: var(--blue); font-weight: 700; }
.q { margin: .5rem 0 .6rem; padding: .5rem .7rem; background: var(--blue-soft); border-radius: 6px; font-size: .95rem; }
.q b, .a b { color: var(--blue); margin-right: .4em; }
.lv { display: flex; align-items: center; gap: .3rem; font-size: .78rem; color: var(--muted); margin: .3rem 0 .6rem; flex-wrap: wrap; }
.lvb { font-size: .78rem; padding: .05em .6em; }
.nd { padding: .55rem 0; border-top: 1px dashed var(--line); cursor: pointer; border-radius: 4px; }
.nd:hover { background: var(--surface); }
.nd.cur { background: var(--surface); box-shadow: inset 3px 0 0 var(--blue); padding-left: .5rem; }
.nd .nh { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; font-size: .92rem; }
.nd .nh .yr { font-family: Consolas, monospace; color: var(--blue); font-weight: 700; font-size: .82rem; }
.lvtag { font-size: .68rem; border: 1px solid var(--blue); color: var(--blue); border-radius: 6px; padding: 0 .4em; }
.lvtag.lv3 { background: var(--blue); color: var(--surface); }
.lvtag.lv1 { border-color: var(--line); color: var(--muted); }
.nd p { margin: .25rem 0 .35rem; font-size: .92rem; }
.a { margin-top: .8rem; padding-top: .7rem; border-top: 2px solid var(--blue); font-size: .95rem; }

/* 一覧 */
.lanes-f { display: flex; flex-wrap: wrap; gap: .3rem; margin: .3rem 0 .6rem; }
.lf { font-size: .74rem; padding: .05em .55em; border-color: var(--c); color: var(--c); opacity: .55; }
.lf.on { opacity: 1; background: var(--c); color: #fff; }
.list .dec { font-size: .74rem; color: var(--muted); margin: .7rem 0 .2rem; letter-spacing: .05em; }
.row { display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left; border: none; border-bottom: 1px solid var(--line); border-radius: 0; padding: .35em .3em; }
.row:hover, .row.active { background: var(--surface); }
.row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.row .cy { font-family: Consolas, monospace; color: var(--blue); font-size: .82em; width: 3em; flex: none; }
.row .tt { flex: 1; }
.row .kd { font-size: .74em; color: var(--muted); flex: none; }
