/* ============================================================
   アルゴリズム & デザインパターン図鑑 — スタイル
   深いチャコール地に金の細線、明朝体のみで組む「図鑑」の意匠
   ============================================================ */
:root {
  --bg: #0e1311;
  --bg-side: #0b0f0d;
  --panel: #141a17;
  --panel2: #1b221e;
  --line: rgba(212, 180, 106, .16);
  --line-strong: rgba(212, 180, 106, .5);
  --gold: #d4b46a;
  --gold-deep: #a98a45;
  --gold-pale: #ecdcaa;
  --ivory: #f1ead9;
  --text: #e2dbc8;
  --muted: #a39d8b;
  --muted2: #6e6a5d;

  /* 可視化の意味色 (パレットに合わせて彩度を落とす) */
  --ok: #7fbf95;
  --warn: #d4b46a;
  --danger: #d9796a;
  --acc: #8aa8d4;
  --acc-dim: #34404c;
  --pur: #b39bcf;
  --cyan: #78c2c4;

  --radius: 4px;
  --sidebar-w: 288px;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --serif: "Shippori Mincho", "Noto Serif JP", "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "MS PMincho", serif;
  --mono: "Cascadia Code", Consolas, "Source Han Code JP", "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--gold); text-decoration: none; }
button { font-family: inherit; color: inherit; }
:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; }

.ic { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.3em; }
.hidden { display: none !important; }

#layout { display: flex; height: 100vh; height: 100dvh; }

/* ============================================================
   サイドバー
   ============================================================ */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 26px 24px 18px;
}
.side-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 48px;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 180, 106, .2) transparent;
}
.brand {
  display: flex; align-items: center; gap: 14px;
  color: var(--ivory); font-weight: 600; font-size: 15px; line-height: 1.4;
  letter-spacing: .02em;
}
.brand-icon { color: var(--gold); display: inline-flex; }
.brand-icon .ic { width: 34px; height: 34px; stroke-width: 1.3; }
.brand:hover .brand-text { color: var(--gold-pale); }

#nav-toggle {
  display: none;
  background: none; border: 1px solid var(--line); border-radius: var(--radius);
  width: 40px; height: 40px; cursor: pointer; color: var(--gold);
  align-items: center; justify-content: center;
}
#nav-toggle .ic { width: 22px; height: 22px; }
#nav-toggle .ic-close { display: none; }
#sidebar.open #nav-toggle .ic-menu { display: none; }
#sidebar.open #nav-toggle .ic-close { display: block; }

.searchbox {
  position: relative;
  display: block;
  margin: 4px 24px 22px;
}
.search-ic {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); display: inline-flex; pointer-events: none;
}
.search-ic .ic { width: 18px; height: 18px; }
#search {
  width: 100%;
  height: 46px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ivory);
  padding: 0 14px 0 42px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .3s var(--ease), background .3s var(--ease);
}
#search::placeholder { color: var(--muted); }
#search:hover { border-color: rgba(212, 180, 106, .3); }
#search:focus { border-color: var(--line-strong); background: rgba(212, 180, 106, .03); }
#search::-webkit-search-cancel-button { filter: grayscale(1) brightness(1.6); }

.nav-home {
  display: flex; align-items: center; gap: 14px;
  height: 54px;
  margin: 0 0 8px;
  padding: 0 24px;
  color: var(--text);
  font-size: 14.5px;
  border-left: 2px solid transparent;
  transition: background .3s var(--ease), color .3s var(--ease), border-color .3s var(--ease);
}
.nav-home .nav-ic { color: var(--gold); display: inline-flex; }
.nav-home:hover { color: var(--ivory); background: rgba(212, 180, 106, .04); }
.nav-home.active {
  color: var(--ivory);
  border-left-color: var(--gold);
  background: linear-gradient(90deg, rgba(212, 180, 106, .16), rgba(212, 180, 106, .02) 70%, transparent);
}
.nav-ic { width: 22px; height: 22px; flex: none; }

.nav-group {
  margin: 26px 24px 8px;
  padding-bottom: 8px;
  font-size: 12px; letter-spacing: .18em; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.nav-sec { border-left: 2px solid transparent; }
.nav-cat {
  width: 100%;
  display: flex; align-items: center; gap: 14px;
  height: 44px;
  padding: 0 20px 0 24px;
  background: none; border: none; cursor: pointer;
  color: var(--text);
  font-size: 14.5px;
  text-align: left;
  transition: color .3s var(--ease), background .3s var(--ease);
}
.nav-cat .nav-ic { color: var(--gold); opacity: .85; }
.nav-cat-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-cat .cnt { font-size: 12px; color: var(--muted2); font-variant-numeric: tabular-nums; }
.nav-chev { width: 14px; height: 14px; color: var(--muted2); transition: transform .4s var(--ease); }
.nav-cat:hover { color: var(--ivory); background: rgba(212, 180, 106, .04); }
.nav-sec.open .nav-cat { color: var(--ivory); }
.nav-sec.open .nav-chev { transform: rotate(90deg); color: var(--gold); }

.nav-items {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .45s var(--ease);
}
.nav-list { min-height: 0; overflow: hidden; }
.nav-sec.open .nav-items { grid-template-rows: 1fr; }
.nav-item {
  display: block;
  padding: 7px 20px 7px 60px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
  border-left: 1px solid transparent;
  transition: color .25s var(--ease), background .25s var(--ease);
}
.nav-list .nav-item:first-child { padding-top: 4px; }
.nav-list .nav-item:last-child { padding-bottom: 14px; }
.nav-item:hover { color: var(--ivory); }
.nav-item.active { color: var(--gold-pale); position: relative; }
.nav-item.active::before {
  content: ""; position: absolute; left: 46px; top: 50%; width: 6px; height: 1px;
  background: var(--gold); transform: translateY(-50%);
}

/* ============================================================
   メイン
   ============================================================ */
#main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 28px 40px 120px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 180, 106, .2) transparent;
}
.page { max-width: 1240px; margin: 0 auto; }
.page-topic, .page-all { max-width: 980px; }

/* 上部バー: パンくず + 罫線 + 銘 */
.topbar {
  display: flex; align-items: center; gap: 18px;
  font-size: 12px; letter-spacing: .06em; color: var(--muted);
}
.topbar-crumb { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.topbar-crumb a { color: var(--muted); }
.topbar-crumb a:hover { color: var(--gold-pale); }
.topbar-sep { color: var(--muted2); }
.topbar-line { flex: 1; height: 1px; background: var(--line); }
.topbar-tag { letter-spacing: .34em; text-transform: uppercase; font-size: 11px; color: var(--muted2); white-space: nowrap; }

.overline {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 12px; letter-spacing: .32em; text-transform: uppercase;
  color: var(--gold);
}
.overline .ic { width: 18px; height: 18px; }

.arrow-link {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--gold);
  transition: color .3s var(--ease);
}
.arrow-link .ic { width: 18px; height: 18px; transition: transform .4s var(--ease); }
.arrow-link:hover { color: var(--gold-pale); }
.arrow-link:hover .ic { transform: translateX(4px); }

.btn-primary {
  display: inline-flex; align-items: center; gap: 14px;
  height: 50px; padding: 0 30px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #e6ca82 0%, #d1b062 55%, #c19f4f 100%);
  color: #1b1607;
  font-size: 16px; font-weight: 600; letter-spacing: .06em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 10px 24px -12px rgba(212, 180, 106, .5);
  transition: transform .35s var(--ease), box-shadow .35s var(--ease), filter .35s var(--ease);
}
.btn-primary .ic { width: 20px; height: 20px; stroke-width: 1.7; transition: transform .4s var(--ease); }
.btn-primary:hover { filter: brightness(1.05); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .4), 0 14px 30px -12px rgba(212, 180, 106, .6); transform: translateY(-1px); }
.btn-primary:hover .ic { transform: translateX(4px); }
.btn-primary:active { transform: translateY(0) scale(.98); }

/* ============================================================
   ホーム
   ============================================================ */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr);
  gap: 24px 32px;
  align-items: center;
  padding: 40px 0 28px;
  position: relative;
}
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 55% 70% at 74% 42%, rgba(212, 180, 106, .07), transparent 70%);
}
.hero-copy { position: relative; }
.hero h1 {
  font-size: clamp(34px, 4.2vw, 66px);
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
  color: var(--ivory);
  margin: 22px 0 26px;
}
.hero .lead {
  font-size: 17.5px; line-height: 1.95;
  color: var(--text);
  max-width: 30em;
  margin: 0 0 32px;
}

.hero-art { position: relative; min-height: 300px; }
.tree { display: block; width: 100%; height: auto; max-height: 470px; overflow: visible; }
.tree .geo circle, .tree .geo line { fill: none; stroke: var(--gold); stroke-opacity: .13; stroke-width: 1; }
.tree .geo .dash { stroke-dasharray: 3 6; stroke-opacity: .18; }
.tree .edge { stroke: var(--gold); stroke-opacity: .85; stroke-width: 1.4; }
.tree .node { filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .55)); }
.tree .halo { transform-origin: 300px 44px; transform-box: view-box; }

/* 統計: 罫線で区切るだけの帯 */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
  margin: 8px 0 40px;
}
.stat {
  text-align: center;
  padding: 6px 0;
  border-left: 1px solid var(--line);
}
.stat:first-child { border-left: none; }
.stats.stats-3 { grid-template-columns: repeat(3, 1fr); }
.stat b {
  display: block;
  font-size: 44px; font-weight: 500; line-height: 1.1;
  color: var(--ivory);
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.stat span { display: block; margin-top: 6px; font-size: 14px; color: var(--muted); letter-spacing: .04em; }

.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.sec-head h2 { font-size: 24px; font-weight: 600; color: var(--ivory); letter-spacing: .04em; margin: 0; padding: 0; border: none; }

.group-label {
  font-size: 12px; letter-spacing: .18em; color: var(--muted);
  margin: 26px 0 12px;
}
.group-label:first-of-type { margin-top: 0; }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}
.cat {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  column-gap: 18px;
  padding: 22px 24px 20px;
  min-height: 140px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  position: relative;
  transition: border-color .35s var(--ease), transform .35s var(--ease), background .35s var(--ease), box-shadow .35s var(--ease);
}
.cat .c-ic { grid-row: 1 / span 2; color: var(--gold); display: inline-flex; padding-top: 4px; }
.cat .c-ic .ic { width: 30px; height: 30px; stroke-width: 1.4; }
.cat .c-num { grid-column: 2; font-size: 11px; letter-spacing: .24em; color: var(--gold); line-height: 1.4; }
.cat .c-body { grid-column: 2; min-width: 0; }
.cat h3 { font-size: 19px; font-weight: 600; color: var(--ivory); margin: 2px 0 4px; line-height: 1.4; letter-spacing: .02em; }
.cat p { font-size: 13px; color: var(--muted); line-height: 1.7; }
.cat .c-foot {
  grid-column: 2;
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 16px;
  font-size: 13px; color: var(--text);
}
.cat .c-arrow { width: 20px; height: 20px; color: var(--gold); transition: transform .4s var(--ease); }
.cat:hover {
  border-color: var(--line-strong);
  background: #161d19;
  transform: translateY(-2px);
  box-shadow: 0 22px 40px -24px rgba(0, 0, 0, .7), inset 0 0 0 1px rgba(212, 180, 106, .08);
}
.cat:hover .c-arrow { transform: translateX(5px); }
.cat:active { transform: translateY(0) scale(.985); }

/* ============================================================
   トピックページ
   ============================================================ */
.topic-head { padding: 40px 0 8px; }
.topic-head .overline { margin-bottom: 18px; }
h1 { font-size: 40px; font-weight: 600; line-height: 1.3; letter-spacing: .03em; color: var(--ivory); margin-bottom: 14px; }
.lead { color: var(--text); font-size: 16.5px; line-height: 1.95; max-width: 40em; margin-bottom: 20px; }

.meta { display: flex; flex-wrap: wrap; gap: 8px 0; margin: 6px 0 26px; font-size: 13.5px; }
.meta-item { display: inline-flex; align-items: baseline; gap: 10px; color: var(--muted); padding: 0 20px; }
.meta-item:first-child { padding-left: 0; }
.meta-item + .meta-item { border-left: 1px solid var(--line); }
.meta-item b { font-family: var(--mono); font-weight: 500; color: var(--gold-pale); font-size: 14px; }

h2 {
  font-size: 22px; font-weight: 600; letter-spacing: .04em; color: var(--ivory);
  margin: 48px 0 16px; padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
h3 { font-size: 16.5px; font-weight: 600; margin: 26px 0 8px; color: var(--gold-pale); }

.desc { max-width: 72ch; }
.desc p { margin: 12px 0; line-height: 1.95; }
.desc ul, .desc ol { margin: 12px 0 12px 26px; }
.desc li { margin: 5px 0; }
.desc strong { color: var(--gold-pale); font-weight: 600; }
.desc code {
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 3px; padding: 1px 6px; font-size: 13px;
  font-family: var(--mono); color: var(--ivory);
}
.desc table { border-collapse: collapse; margin: 16px 0; width: 100%; font-size: 14px; }
.desc th, .desc td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
.desc th { background: var(--panel); color: var(--ivory); font-weight: 600; }

.hero-mechanisms { display: flex; width: fit-content; margin-top: 22px; }
.topic-related { margin: 36px 0; }
.topic-related .arrow-link { display: flex; width: fit-content; max-width: 100%; margin: 12px 0; }
.topic-related .arrow-link span { overflow-wrap: anywhere; }
.topic-references a { color: var(--gold-pale); text-underline-offset: 4px; }
.topic-references a:hover { text-decoration: underline; }
.mechanism-viz .viz-stage { padding: 14px 8px; }
.mechanism-viz .sd-stage svg { max-height: none; min-width: 760px; }
#nav-mechanisms { color: var(--gold); font-size: 13px; padding-top: 4px; padding-bottom: 18px; }

/* ---------- 可視化パネル ---------- */
.viz-panel {
  --step-duration: 0ms;
  --step-ease: cubic-bezier(.22, 1, .36, 1);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  margin: 26px 0;
}
.viz-stage {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-height: 120px;
  overflow-x: auto;
}
.viz-stage svg { display: block; width: 100%; height: auto; }
.viz-error { color: var(--danger); }

.viz-controls {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 14px;
}
.vc-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent; color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  height: 38px; padding: 0 14px; font-size: 13.5px; cursor: pointer;
  transition: border-color .3s var(--ease), color .3s var(--ease), background .3s var(--ease), transform .2s var(--ease);
}
.vc-btn .ic { width: 16px; height: 16px; }
.vc-btn:hover:not(:disabled) { border-color: var(--line-strong); color: var(--ivory); }
.vc-btn:disabled { opacity: .35; cursor: default; }
.vc-btn:disabled:active { transform: none; }
.vc-btn:active { transform: scale(.97); }
.vc-btn.vc-icon { width: 38px; padding: 0; justify-content: center; }
.vc-btn.vc-play {
  background: linear-gradient(180deg, #e6ca82, #c9a755);
  border-color: transparent; color: #1b1607; font-weight: 600; min-width: 112px;
  justify-content: center;
}
.vc-btn.vc-play:hover { filter: brightness(1.05); color: #1b1607; }
.vc-btn.vc-play.on { background: var(--panel2); border-color: var(--gold); color: var(--gold-pale); }
.vc-speedwrap { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; margin-left: 8px; }
.vc-speed { accent-color: var(--gold); width: 110px; }
.vc-counter { flex: none; color: var(--muted); font-size: 12px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.vc-speedvalue { min-width: 3.5ch; color: var(--gold-pale); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.vc-timeline { display: flex; align-items: center; gap: 18px; margin-top: 14px; }
.vc-seek {
  --progress: 0%;
  appearance: none; -webkit-appearance: none;
  flex: 1; min-width: 40px; height: 24px; cursor: pointer;
  background: linear-gradient(to right, var(--gold) var(--progress), var(--panel2) var(--progress)) center / 100% 3px no-repeat;
}
.vc-seek::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 12px; height: 12px; border-radius: 50%; background: var(--gold-pale); border: 2px solid var(--gold);
}
.vc-seek::-moz-range-thumb { width: 9px; height: 9px; border-radius: 50%; background: var(--gold-pale); border: 2px solid var(--gold); }
.vc-seek:disabled { opacity: .4; cursor: default; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; font-size: 11.5px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; --mark-color: var(--muted); }
.legend-item i { width: 7px; height: 7px; border-radius: 50%; background: var(--mark-color); }
.mark-cmp, .mark-visit { --mark-color: var(--warn); }
.mark-swap, .mark-path { --mark-color: var(--danger); }
.mark-pivot, .mark-cur { --mark-color: var(--pur); }
.mark-sel, .mark-frontier, .mark-acc { --mark-color: var(--acc); }
.mark-set { --mark-color: var(--cyan); }
.mark-found, .mark-done { --mark-color: var(--ok); }

.viz-note {
  margin-top: 12px;
  min-height: 46px;
  background: var(--bg);
  border: 1px dashed rgba(212, 180, 106, .3);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--gold-pale);
  font-size: 13.5px;
  display: grid; align-items: start;
}
.viz-note-text, .viz-note-measure { grid-area: 1 / 1; overflow-wrap: anywhere; }
.viz-note-measure { visibility: hidden; pointer-events: none; user-select: none; }

/* ---------- ソート可視化 (棒グラフ) ---------- */
.sortviz { display: flex; align-items: flex-end; gap: 6px; height: 280px; padding-top: 38px; }
.sortviz .bar {
  flex: 1; min-width: 26px;
  background: var(--acc-dim);
  border-radius: 3px 3px 0 0;
  position: relative;
  transition: height var(--step-duration) var(--step-ease), background-color var(--step-duration) ease, box-shadow var(--step-duration) ease;
}
.sortviz .bar span {
  position: absolute; top: -24px; left: 0; right: 0;
  text-align: center; font-size: 13px; color: var(--muted);
  font-family: var(--mono);
}
.sortviz .bar.cmp   { background: var(--warn); }
.sortviz .bar.swap  { background: var(--danger); }
.sortviz .bar.done  { background: var(--ok); }
.sortviz .bar.pivot { background: var(--pur); }
.sortviz .bar.sel   { background: var(--acc); }
.sortviz .bar.set   { background: var(--cyan); }
.sortviz .bar.found { background: var(--ok); box-shadow: 0 0 14px rgba(127, 191, 149, .6); }
.sortviz .bar.cmp span, .sortviz .bar.swap span, .sortviz .bar.sel span,
.sortviz .bar.pivot span, .sortviz .bar.set span, .sortviz .bar.found span { color: var(--ivory); font-weight: 700; }

/* ---------- 配列可視化 (セル) ---------- */
.arrviz { display: flex; align-items: center; min-height: 150px; }
.arr-row { display: flex; gap: 6px; margin: auto; flex: none; }
.arr-cellwrap { display: flex; flex-direction: column; align-items: center; width: 54px; flex: none; }
.arr-idx { font-size: 11px; color: var(--muted); font-family: var(--mono); margin-bottom: 4px; }
.arr-cell {
  width: 100%; height: 50px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel2);
  border: 1.5px solid rgba(212, 180, 106, .28);
  border-radius: var(--radius);
  font-size: 17px; font-weight: 600;
  font-family: var(--mono);
  color: var(--ivory);
  transition: background-color var(--step-duration) ease, border-color var(--step-duration) ease, opacity var(--step-duration) ease, box-shadow var(--step-duration) ease;
}
.arr-cell.cmp   { border-color: var(--warn);   background: rgba(212, 180, 106, .16); }
.arr-cell.sel   { border-color: var(--acc);    background: rgba(138, 168, 212, .16); }
.arr-cell.found { border-color: var(--ok);     background: rgba(127, 191, 149, .22); box-shadow: 0 0 12px rgba(127, 191, 149, .45); }
.arr-cell.out   { opacity: .25; }
.arr-cell.swap  { border-color: var(--danger); background: rgba(217, 121, 106, .16); }
.arr-cell.set   { border-color: var(--cyan);   background: rgba(120, 194, 196, .16); }
.arr-cell.done  { border-color: var(--ok);     background: rgba(127, 191, 149, .14); }
.arr-lab { font-size: 11.5px; color: var(--gold); height: 20px; margin-top: 5px; font-weight: 700; }

/* ---------- SVG 図 (StepDiagram / GraphViz) ---------- */
.sd-stage svg { max-height: 460px; margin: 0 auto; }
.viz-scene :is(rect, circle, ellipse, line, path, polygon, text) {
  transition: fill var(--step-duration) ease, stroke var(--step-duration) ease, stroke-width var(--step-duration) ease, opacity var(--step-duration) ease;
}
.sd-box    { fill: #1b221e; stroke: #4a5348; stroke-width: 1.5; }
.sd-acc    { fill: rgba(138, 168, 212, .18); stroke: var(--acc);    stroke-width: 2; }
.sd-ok     { fill: rgba(127, 191, 149, .16); stroke: var(--ok);     stroke-width: 2; }
.sd-warn   { fill: rgba(212, 180, 106, .16); stroke: var(--warn);   stroke-width: 2; }
.sd-danger { fill: rgba(217, 121, 106, .16); stroke: var(--danger); stroke-width: 2; }
.sd-pur    { fill: rgba(179, 155, 207, .16); stroke: var(--pur);    stroke-width: 2; }
.sd-ghost  { fill: none; stroke: #4a5348; stroke-width: 1.5; stroke-dasharray: 5 4; }
.sd-text   { fill: var(--text);  font-size: 14px; font-family: inherit; }
.sd-sub    { fill: var(--muted); font-size: 11.5px; font-family: inherit; }
.sd-big    { fill: var(--ivory); font-size: 18px; font-weight: 700; font-family: inherit; }
.sd-mono   { fill: var(--text);  font-size: 14px; font-family: var(--mono); }
.sd-line   { stroke: #8f8977; stroke-width: 1.8; fill: none; }
.sd-line-acc    { stroke: var(--acc);    stroke-width: 2.2; fill: none; }
.sd-line-ok     { stroke: var(--ok);     stroke-width: 2.2; fill: none; }
.sd-line-warn   { stroke: var(--warn);   stroke-width: 2.2; fill: none; }
.sd-line-danger { stroke: var(--danger); stroke-width: 2.2; fill: none; }
.sd-line-pur    { stroke: var(--pur);    stroke-width: 2.2; fill: none; }

/* グラフノード */
.gv-node   { fill: #1b221e; stroke: #6d6a5c; stroke-width: 2; }
.gv-node.visit    { fill: rgba(212, 180, 106, .28); stroke: var(--warn); }
.gv-node.frontier { fill: rgba(138, 168, 212, .28); stroke: var(--acc); }
.gv-node.done     { fill: rgba(127, 191, 149, .28); stroke: var(--ok); }
.gv-node.path     { fill: rgba(217, 121, 106, .30); stroke: var(--danger); stroke-width: 3; }
.gv-node.cur      { fill: rgba(179, 155, 207, .30); stroke: var(--pur); stroke-width: 3; }
.gv-label  { fill: var(--ivory); font-size: 15px; font-weight: 700; font-family: inherit; }
.gv-edge   { stroke: #5a5f52; stroke-width: 2; }
.gv-edge.visit { stroke: var(--warn);   stroke-width: 3; }
.gv-edge.done  { stroke: var(--ok);     stroke-width: 3; }
.gv-edge.path  { stroke: var(--danger); stroke-width: 3.5; }
.gv-edge.acc   { stroke: var(--acc);    stroke-width: 3; }
.gv-w      { fill: var(--muted); font-size: 12.5px; font-family: var(--mono); }
.gv-d      { fill: var(--cyan); font-size: 12.5px; font-weight: 700; font-family: var(--mono); }

/* ---------- コードブロック ---------- */
.codeblock {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 16px 0;
}
.code-tabs {
  display: flex; align-items: center;
  background: var(--bg-side);
  border-bottom: 1px solid var(--line);
  padding: 0 10px 0 4px;
}
.tab {
  background: none; border: none; color: var(--muted);
  padding: 12px 18px; font-size: 13px; cursor: pointer;
  border-bottom: 1px solid transparent; margin-bottom: -1px;
  letter-spacing: .04em;
  transition: color .3s var(--ease), border-color .3s var(--ease);
}
.tab.on { color: var(--gold-pale); border-bottom-color: var(--gold); }
.tab:hover { color: var(--ivory); }
.copy {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 7px;
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: var(--radius); height: 30px; padding: 0 12px; font-size: 12px; cursor: pointer;
  transition: color .3s var(--ease), border-color .3s var(--ease);
}
.copy .ic { width: 14px; height: 14px; }
.copy .ic-check { display: none; }
.copy.done { color: var(--ok); border-color: rgba(127, 191, 149, .5); }
.copy.done .ic-copy { display: none; }
.copy.done .ic-check { display: block; }
.copy:hover { color: var(--ivory); border-color: var(--line-strong); }
pre.code {
  padding: 18px 20px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.65;
  font-family: var(--mono);
  tab-size: 4;
  color: var(--text);
}
.tok-kw  { color: #d4b46a; }
.tok-str { color: #a9c69b; }
.tok-num { color: #e3a67c; }
.tok-com { color: #6e6a5d; font-style: italic; }
.tok-fn  { color: #9fb6d9; }

/* 前後ナビ */
.pn { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--line); }
.pn a {
  display: flex; flex-direction: column; gap: 6px;
  padding: 16px 20px;
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ivory);
  transition: border-color .35s var(--ease), background .35s var(--ease), transform .35s var(--ease);
}
.pn a:hover { border-color: var(--line-strong); background: var(--panel); transform: translateY(-2px); }
.pn a:active { transform: translateY(0) scale(.985); }
.pn-k { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; letter-spacing: .12em; color: var(--muted); }
.pn-k .ic { width: 14px; height: 14px; color: var(--gold); }
.pn-t { font-size: 15.5px; }
.pn-next { text-align: right; align-items: flex-end; }

/* ============================================================
   全項目一覧
   ============================================================ */
.all-cat { margin: 22px 0 34px; }
.all-cat-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.all-cat-head .nav-ic { color: var(--gold); }
.all-cat-head h3 { margin: 0; font-size: 17px; color: var(--ivory); }
.all-cat-head .cnt { font-size: 12.5px; color: var(--muted); }
.all-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.all-item {
  display: grid; grid-template-columns: 34px 1fr; column-gap: 8px;
  padding: 12px 8px 12px 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  transition: background .3s var(--ease), color .3s var(--ease);
}
.all-item:hover { color: var(--ivory); background: rgba(212, 180, 106, .035); }
.all-num { font-size: 11px; letter-spacing: .18em; color: var(--gold); padding-top: 5px; }
.all-title { font-size: 15px; color: var(--ivory); }
.all-sum { grid-column: 2; font-size: 12.5px; color: var(--muted); line-height: 1.6; }

/* ============================================================
   モーション
   ============================================================ */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes node-in {
  from { opacity: 0; transform: scale(.4); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes draw {
  from { stroke-dashoffset: 1; }
  to   { stroke-dashoffset: 0; }
}
@keyframes lvl-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}
@keyframes breathe {
  0%, 100% { transform: scale(1);    opacity: .8; }
  50%      { transform: scale(1.18); opacity: 1; }
}
.tree .edge { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .9s var(--ease) forwards; }
.tree .node { transform-box: fill-box; transform-origin: center; animation: node-in .9s var(--ease) both; }
.tree .tree-connected { animation: lvl-float 8s ease-in-out infinite; }
.tree .halo { animation: breathe 4.5s ease-in-out infinite; }
.hero-copy > * { animation: rise .9s var(--ease) both; }
.hero-copy > :nth-child(2) { animation-delay: 80ms; }
.hero-copy > :nth-child(3) { animation-delay: 160ms; }
.hero-copy > :nth-child(4) { animation-delay: 240ms; }
.stats { animation: rise .9s var(--ease) both; animation-delay: 320ms; }
.topic-head, .page-topic .viz-panel { animation: rise .45s var(--ease) backwards; }
.page-topic .viz-panel { animation-delay: 60ms; }
.reveal-pending { opacity: 0; }
.motion-paused *, .page-hidden * { animation-play-state: paused !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .tree .edge { stroke-dashoffset: 0; }
  .reveal-pending { opacity: 1; }
  html, #main { scroll-behavior: auto; }
}

/* ============================================================
   レスポンシブ
   ============================================================ */
@media (max-width: 1180px) {
  .cat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr); }
  .hero h1 { font-size: clamp(34px, 4vw, 56px); }
}

@media (max-width: 900px) {
  #layout { flex-direction: column; height: auto; }
  #sidebar {
    width: 100%; min-width: 0;
    border-right: none; border-bottom: 1px solid var(--line);
    display: grid; grid-template-rows: auto 0fr;
    overflow: hidden;
    transition: grid-template-rows .32s var(--ease);
  }
  .side-head { padding: 16px 16px 12px; }
  #nav-toggle { display: inline-flex; }
  .side-body {
    display: block; min-height: 0; max-height: 70vh; padding-bottom: 0;
    overflow-y: auto; visibility: hidden;
    transition: visibility 0s .32s;
  }
  #sidebar.open { grid-template-rows: auto 1fr; }
  #sidebar.open .side-body { visibility: visible; transition-delay: 0s; }
  .searchbox { margin: 4px 16px 16px; }
  .nav-home, .nav-cat { padding-left: 16px; }
  .nav-group { margin-left: 16px; margin-right: 16px; }
  .nav-item { padding-left: 52px; }
  .nav-item.active::before { left: 38px; }

  #main { padding: 20px 16px 80px; overflow: visible; }
  .hero { grid-template-columns: 1fr; padding: 24px 0 16px; gap: 8px; }
  .hero::before { display: none; }
  .hero h1 { font-size: clamp(30px, 8.6vw, 48px); margin: 16px 0 18px; }
  .hero .lead { font-size: 16px; margin-bottom: 24px; }
  .hero .lead br { display: none; }
  .hero-art { min-height: 0; max-width: 480px; margin: 8px auto 0; }
  .topbar-tag { display: none; }
  .stats { padding: 14px 0; margin-bottom: 30px; }
  .stat b { font-size: 32px; }
  .stat span { font-size: 12.5px; }
  .sec-head h2 { font-size: 20px; }
  .cat-grid { grid-template-columns: 1fr; gap: 12px; }
  .cat { min-height: 0; padding: 18px 18px 16px; }

  h1 { font-size: 30px; }
  .topic-head { padding-top: 24px; }
  .pn { grid-template-columns: 1fr; }
  .pn-next { text-align: left; align-items: flex-start; }
  .all-list { grid-template-columns: 1fr; }
  .viz-panel { padding: 14px 12px; }
  .sd-stage svg { min-width: 600px; }
  .sd-stage::after {
    content: '図は左右にスクロールできます'; display: block;
    position: sticky; left: 0; width: max-content; max-width: 100%;
    margin-top: 10px; color: var(--muted); font-size: 11px;
  }
  .vc-speedwrap { margin-left: 0; }
  .viz-controls { gap: 8px 6px; }
}

@media (max-width: 480px) {
  .stats, .stats.stats-3 { grid-template-columns: 1fr; gap: 12px; }
  .stat { border-left: none; padding: 4px 0; }
  .meta { flex-direction: column; gap: 8px; }
  .meta-item { padding: 0; }
  .meta-item + .meta-item { border-left: none; }
  .vc-speedwrap { width: 100%; margin-top: 4px; }
  .vc-speed { flex: 1; }
  .vc-timeline { gap: 10px; }
  .vc-counter { font-size: 10.5px; }
  .viz-controls { display: grid; grid-template-columns: 38px 38px minmax(112px, 1fr) 38px; }
  .vc-reset { width: 38px; padding: 0; justify-content: center; }
  .vc-reset-label { display: none; }
  .vc-speedwrap { grid-column: 1 / -1; }
  .sortviz .bar { min-width: 18px; }
  .sortviz .bar span { font-size: 12px; }
}
