/* 相関図メーカー：エンタメパンダ ツールズと同じ白・墨・パンダ朱 */
:root {
  --ink: #1F1D1B;
  --sub: #66615C;
  --line: #E8E3DD;
  --surface: #F6F3EF;
  --blush: #FDF0EB;
  --shu: #E5452B;
  --shu-deep: #C93A22;
  --shu-text: #C93A22;
  --font: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  --shadow: 0 12px 32px rgba(31, 29, 27, .12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  background: #FFFFFF; color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.6; letter-spacing: .02em;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
/* 朱の細い線（エンタメパンダ本体のヘッダーと同じ） */
body::before { content: ""; display: block; flex-shrink: 0; height: 4px; background: var(--shu); }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
h1, h2 { margin: 0; }
button, input, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 8px; }
[hidden] { display: none !important; }
svg { flex-shrink: 0; }

/* サイト共通ヘッダー */
.hd { flex-shrink: 0; display: flex; align-items: center; gap: 8px 32px; height: 60px; padding: 0 40px; border-bottom: 1px solid var(--line); }
.logo { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-right: auto; min-width: 0; }
.logo img { width: 34px; height: 34px; object-fit: contain; }
.logo b { display: block; font-size: 19px; font-weight: 900; line-height: 1.1; letter-spacing: .04em; white-space: nowrap; }
.logo b span { color: var(--shu-text); }
.logo small { display: block; margin-top: 1px; font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--sub); line-height: 1.4; }
.nav { display: flex; align-items: center; gap: 28px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.nav a { display: flex; align-items: center; gap: 6px; min-height: 44px; transition: color .2s; }
.nav a:hover { color: var(--shu-text); }
.nav svg { width: 13px; height: 13px; }

/* ボタン */
.tbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #FFFFFF; font-size: 13px; font-weight: 700; white-space: nowrap; }
.tbtn svg { width: 16px; height: 16px; }
.tbtn:hover { border-color: var(--ink); }
.tbtn.primary { border-color: var(--ink); background: var(--ink); color: #FFFFFF; }
.tbtn[aria-pressed="true"], .tbtn[aria-expanded="true"] { border-color: var(--shu-deep); background: var(--blush); color: var(--shu-text); }
#savePng.primary { border-color: var(--shu-deep); background: var(--shu-deep); }
#savePng.primary:hover { border-color: var(--ink); background: var(--ink); }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: #FFFFFF; }
.icon-btn:hover { border-color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }
.text-btn { min-height: 44px; padding: 0; border: 0; background: none; font-size: 13px; font-weight: 700; color: var(--sub); text-decoration: underline; }

/* ツールの操作列 */
.rm-bar { position: relative; z-index: 20; flex-shrink: 0; display: flex; align-items: center; gap: 16px; min-height: 56px; padding: 6px 40px; border-bottom: 1px solid var(--line); background: #FFFFFF; }
.rm-name { font-size: 15px; font-weight: 900; white-space: nowrap; }
.top-actions { position: relative; display: flex; align-items: center; gap: 8px; margin-left: auto; }
.top-actions .icon-btn { width: 40px; height: 40px; border-color: transparent; }
.top-actions .icon-btn:hover { border-color: var(--line); }
.more-menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; padding: 6px; border: 1px solid var(--line); border-radius: 14px; background: #FFFFFF; box-shadow: var(--shadow); }
.more-menu button { display: block; width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: #FFFFFF; font-size: 14px; font-weight: 700; text-align: left; }
.more-menu button:hover { background: var(--surface); }

/* 作業面 */
.workspace { flex: 1; min-height: 0; padding: 12px 16px; background: #FFFFFF; }
.board-shell { position: relative; height: 100%; max-width: 1400px; margin: 0 auto; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background-color: var(--surface); background-image: radial-gradient(#DDD5CB 1.2px, transparent 1.2px); background-size: 22px 22px; }
.board-scroller { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; }
.board-stage { position: absolute; width: 1000px; height: 650px; transform-origin: 0 0; }
.board-stage > svg { display: block; width: 1000px; height: 650px; touch-action: none; user-select: none; }
/* 画面では作業面の点線を通しで見せる。PNGには図側の背景が入る。 */
#graph > .graph-bg, #graph > rect[fill="url(#dots)"] { display: none; }

/* 図の操作表示（色・書体は renderer.js の GRAPH_STYLE と共通） */
.edge { cursor: pointer; outline: none; }
.edge.selected .edge-line { stroke-width: 5; }
.edge:focus-visible .edge-label rect, .edge.selected .edge-label rect { stroke: var(--ink); stroke-width: 2; }
.edge-label text { pointer-events: none; }
.node { cursor: grab; outline: none; }
.node:active { cursor: grabbing; }
.avatar-placeholder { pointer-events: none; }
.node-name, .node-description { cursor: text; }
.node-remove { opacity: 0; transition: opacity .15s; }
.node:hover .node-remove, .node:focus .node-remove, .node.selected .node-remove { opacity: 1; }
.node-remove circle { fill: #FFFFFF; stroke: var(--ink); stroke-width: 1.5; cursor: pointer; }
.node-remove text { font-size: 20px; fill: var(--ink); pointer-events: none; }
.node.selected .avatar-ring, .node:focus-visible .avatar-ring { stroke: var(--ink); stroke-width: 5; }
.node.connect-selected .avatar-ring { stroke: var(--shu-deep); stroke-width: 6; stroke-dasharray: 9 5; }
.inline-editor { position: absolute; z-index: 12; transform: translate(-50%, -50%); }
.inline-editor input { width: 200px; padding: 8px 10px; border: 2px solid var(--ink); border-radius: 10px; background: #FFFFFF; box-shadow: var(--shadow); font-weight: 700; text-align: center; outline: none; }

/* テンプレート */
.templates { position: absolute; z-index: 10; top: 12px; left: 12px; width: 280px; max-height: calc(100% - 24px); overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: #FFFFFF; box-shadow: var(--shadow); }
.panel-heading, .inspector-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-heading { padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--line); }
.panel-heading h2, .inspector-head h2 { font-size: 15px; font-weight: 900; }
.panel-heading .icon-btn, .inspector-head .icon-btn { border-color: transparent; }
.panel-heading .icon-btn:hover, .inspector-head .icon-btn:hover { border-color: var(--line); }
.template-list { display: flex; flex-direction: column; gap: 4px; padding: 8px; }
.template-card { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 68px; padding: 8px 10px; border: 1px solid transparent; border-radius: 12px; background: #FFFFFF; text-align: left; }
.template-card:hover { background: var(--surface); }
.template-card.active { border-color: var(--shu-deep); background: var(--blush); }
.template-card > span:last-child { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.template-card strong { font-size: 14px; font-weight: 700; }
.template-card.active strong { color: var(--shu-text); }
.template-card small { font-size: 12px; color: var(--sub); }
.template-icon { position: relative; display: block; flex: 0 0 76px; height: 48px; }
.template-icon i { position: absolute; display: block; width: 18px; height: 18px; border: 2px solid var(--ink); border-radius: 50%; background: #FFFFFF; }
.triangle::before { content: ""; position: absolute; inset: 10px 17px 6px; border: 1.5px solid var(--sub); border-top: 0; transform: perspective(20px) rotateX(-12deg); }
.triangle i:nth-child(1) { top: 0; left: 29px; border-color: var(--shu); background: var(--blush); }
.triangle i:nth-child(2) { bottom: 0; left: 4px; }
.triangle i:nth-child(3) { bottom: 0; right: 4px; }
.four::before, .family::before { content: ""; position: absolute; inset: 9px 15px; border: 1.5px solid var(--sub); }
.four i:nth-child(1) { top: 0; left: 6px; border-color: var(--shu); background: var(--blush); }
.four i:nth-child(2) { top: 0; right: 6px; }
.four i:nth-child(3) { bottom: 0; left: 6px; }
.four i:nth-child(4) { bottom: 0; right: 6px; }
.org i { border-radius: 6px; }
.org i:nth-child(-n+3) { top: 2px; border-color: var(--shu); background: var(--blush); }
.org i:nth-child(n+4) { bottom: 2px; }
.org i:nth-child(1), .org i:nth-child(4) { left: 2px; }
.org i:nth-child(2), .org i:nth-child(5) { left: 29px; }
.org i:nth-child(3), .org i:nth-child(6) { right: 2px; }
.family::before { top: 19px; border-bottom: 0; }
.family i:nth-child(1) { top: 0; left: 29px; border-color: var(--shu); background: var(--blush); }
.family i:nth-child(2) { bottom: 0; left: 2px; }
.family i:nth-child(3) { bottom: 0; left: 29px; }
.family i:nth-child(4) { bottom: 0; right: 2px; }
.blank { display: grid; place-items: center; border: 1.5px dashed var(--sub); border-radius: 10px; font-size: 24px; color: var(--sub); }

/* 関係の設定 */
.edge-inspector { position: absolute; z-index: 13; top: 12px; right: 12px; width: 260px; max-height: calc(100% - 24px); overflow: auto; padding: 6px 16px 12px; border: 1px solid var(--line); border-radius: 16px; background: #FFFFFF; box-shadow: var(--shadow); }
.inspector-head { margin: 0 -10px 4px 0; }
.edge-inspector label, .edge-inspector legend { display: block; font-size: 12px; font-weight: 700; color: var(--sub); }
.edge-inspector label { margin: 10px 0; }
.edge-inspector input, .edge-inspector select { display: block; width: 100%; min-height: 44px; margin-top: 4px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #FFFFFF; font-size: 15px; color: var(--ink); }
.edge-inspector input:focus-visible, .edge-inspector select:focus-visible { outline: 3px solid var(--ink); outline-offset: 1px; }
.edge-inspector fieldset { margin: 10px 0; padding: 0; border: 0; }
.color-options { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.color-chip { position: relative; width: 30px; height: 30px; padding: 0; border: 3px solid #FFFFFF; border-radius: 50%; box-shadow: 0 0 0 1px var(--line); }
.color-chip.active { box-shadow: 0 0 0 2px var(--ink); }
.danger { color: var(--shu-text); }

/* 関係をつなぐ案内 */
.connect-hint { position: absolute; z-index: 14; top: 12px; left: 50%; display: flex; align-items: center; gap: 12px; max-width: calc(100% - 24px); padding: 4px 4px 4px 18px; border-radius: 999px; background: var(--ink); color: #FFFFFF; font-size: 13px; transform: translateX(-50%); white-space: nowrap; }
.connect-hint .tbtn { min-height: 36px; border-color: #FFFFFF; color: var(--ink); }

/* 下部バー */
.bottom-bar { flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 6px 40px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #FFFFFF; }
.title-area { display: flex; align-items: center; gap: 12px; min-width: 0; margin-right: auto; }
.title-area button { display: inline-flex; align-items: center; gap: 6px; min-width: 0; min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; }
.title-area button:hover { background: var(--surface); }
.title-area strong { overflow: hidden; font-size: 15px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.title-area svg { width: 16px; height: 16px; color: var(--sub); }
.save-state { font-size: 12px; color: var(--sub); white-space: nowrap; }
.save-state.error { color: var(--shu-text); font-weight: 700; }
.history-actions { display: flex; gap: 4px; }
.history-actions .icon-btn { border-color: transparent; }
.history-actions .icon-btn:hover { border-color: var(--line); }
.history-actions .icon-btn:disabled { opacity: .35; cursor: default; border-color: transparent; }
.zoom-actions { display: flex; align-items: center; margin-left: 8px; padding: 0 2px; border: 1px solid var(--line); border-radius: 999px; }
.zoom-actions button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: transparent; }
.zoom-actions button:hover { background: var(--surface); }
.zoom-actions svg { width: 18px; height: 18px; }
.zoom-actions output { width: 52px; font-size: 13px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.zoom-actions #fitView { border-left: 1px solid var(--line); border-radius: 0 999px 999px 0; }

/* トースト・ダイアログ */
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(72px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); padding: 6px 14px; border-radius: 999px; background: var(--ink); color: #FFFFFF; font-size: 13px; font-weight: 700; transform: translateX(-50%); pointer-events: none; }
.app-dialog { width: min(400px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: #FFFFFF; color: var(--ink); box-shadow: 0 20px 48px rgba(31, 29, 27, .16); }
.app-dialog::backdrop { background: rgba(31, 29, 27, .2); }
.app-dialog form { padding: 20px; }
.app-dialog p { margin: 0 0 16px; font-size: 15px; font-weight: 700; line-height: 1.7; white-space: pre-line; }
.app-dialog input { display: block; width: 100%; min-height: 44px; margin: -4px 0 16px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 16px; }
.app-dialog input:focus-visible { border-color: var(--ink); outline: 3px solid var(--ink); outline-offset: 1px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions .tbtn { min-height: 44px; padding: 0 18px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

@media (max-width: 1020px) {
  .hd, .rm-bar, .bottom-bar { padding-left: 28px; padding-right: 28px; }
}

@media (max-width: 760px) {
  .rm-bar { gap: 8px; min-height: 56px; padding: 6px 12px; }
  .rm-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .top-actions { flex: 1; justify-content: space-between; gap: 4px; margin: 0; }
  .top-actions .tbtn { width: 44px; min-height: 44px; padding: 0; }
  .top-actions .tbtn svg { width: 20px; height: 20px; }
  .top-actions .lbl { display: none; }
  .top-actions .icon-btn { width: 44px; height: 44px; }
  .workspace { padding: 8px; }
  .board-shell { border-radius: 12px; }
  #graph .graph-title { display: none; }
  .templates { top: 8px; left: 8px; width: min(280px, calc(100% - 16px)); }
  .edge-inspector { top: auto; right: 8px; bottom: 8px; left: 8px; width: auto; max-height: 70%; }
  .edge-inspector { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
  .edge-inspector[hidden] { display: none !important; }
  .inspector-head, .edge-inspector label:first-of-type, .edge-inspector fieldset, .edge-inspector .danger { grid-column: 1 / -1; }
  .edge-inspector label, .edge-inspector fieldset { margin: 6px 0; }
  .bottom-bar { gap: 2px; padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); }
  .title-area { gap: 0; }
  .title-area button { padding: 0 8px; }
  .title-area strong { font-size: 14px; }
  .save-state { display: none; }
  .history-actions { gap: 0; }
  .zoom-actions { margin-left: 2px; padding: 0; }
  .zoom-actions button { width: 44px; height: 44px; }
  .zoom-actions output { display: none; }
  .toast { bottom: calc(64px + env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .hd { padding: 0 16px; gap: 16px; }
  .logo b { font-size: 16px; }
  .logo img { width: 30px; height: 30px; }
  .logo small { display: none; }
  .nav { gap: 16px; font-size: 13px; }
  .nav .hide-sp, .nav .ext { display: none; }
}
