:root {
  font-family: "Meiryo", "メイリオ", "Yu Gothic UI", "Yu Gothic", system-ui, sans-serif;
  color: #ffffff;
  background: #000000;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --border-neutral: #767676;
  --border-accent: #8aa7ff;
  --border-neon: #00d4ff;
  --line: var(--border-neutral);
  --muted: #a6adba;
  --blue: #7698f4;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
.toolbar {
  min-height: 62px;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: #0b0c10;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 2;
}
.brand { display: flex; gap: 9px; align-items: center; min-width: 190px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: #252c3d; color: #a9bdff; display: grid; place-items: center; font-size: 22px; }
.brand strong { display: block; font-size: 13px; }
.brand small { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; height: 35px; max-width: 320px; flex: 1; color: #99a2b2; background: #111319; }
.search:focus-within { outline: 2px solid var(--border-neon); outline-offset: 2px; }
.search input { border: 0; outline: 0; width: 100%; font: inherit; background: transparent; font-size: 12px; }
.toolbar-actions { display: flex; align-items: center; gap: 7px; margin-left: auto; }
.button { border: 1px solid var(--line); background: #222630; color: #e7eaf0; border-radius: 7px; height: 34px; padding: 0 11px; font: inherit; font-size: 11px; cursor: pointer; white-space: nowrap; }
.button:hover, .canvas-controls button:hover, .icon-button:hover { background: #303644; }
.button.primary { background: var(--blue); color: white; border-color: var(--border-accent); }
.button.danger { color: #ff929b; border-color: #d87982; background: #282027; }
.button:focus-visible, .node-tools button:focus-visible, .child-add:focus-visible, .fold:focus-visible, .canvas-controls button:focus-visible, .icon-button:focus-visible { outline: 2px solid var(--border-neon); outline-offset: 2px; }
.hidden { display: none !important; }
main { position: relative; min-height: calc(100vh - 62px); }
.canvas-wrap { position: relative; min-height: calc(100vh - 62px); overflow: auto; touch-action: pan-y; cursor: default; background: #000000; }
.canvas-wrap.panning { cursor: grabbing; }
.canvas { position: relative; left: 0; top: 0; transform-origin: 0 0; width: 100%; min-height: calc(100vh - 62px); padding: 24px 18px 70px; }
.tree { position: relative; display: block; width: max-content; min-width: 0; margin: 0; z-index: 1; }
.tree-node { position: relative; display: block; width: max-content; min-width: 0; }
.children { display: flex; flex-direction: column; align-items: flex-start; gap: 0; position: relative; margin: 0 0 0 24px; padding: 0; border: 0; }
.children > .tree-node { padding: 0; }
.children > .tree-node::before { content: none; }
.node-card { position: relative; display: flex; align-items: center; justify-content: flex-start; gap: 3px; width: max-content; max-width: none; min-height: 27px; padding: 1px 2px; border: 0; border-radius: 2px; background: transparent; box-shadow: none; cursor: default; user-select: none; touch-action: pan-y; }
.node-card::before { content: ""; flex: 0 0 3px; align-self: stretch; max-height: 17px; border-radius: 0; background: var(--node-color, #9ab0e8); }
.node-card:not(.root-card)::before { display: none; }
.node-card.selected { background: #17191f; outline: 1px solid var(--border-accent); outline-offset: 1px; }
.node-card.drop-target { background: #161b27; outline: 1px dashed var(--border-accent); }
.node-title { flex: 0 0 auto; min-width: 0; max-width: none; font-size: 13px; line-height: 1.35; white-space: nowrap; overflow: visible; text-overflow: clip; cursor: text; }
.branch-card { min-height: 29px; padding: 3px 10px; border-radius: 10px; background: var(--node-color, #7898f5); color: #fff; }
.branch-card .node-title { color: #fff; font-size: 13px; }
.branch-card.selected { background: var(--node-color, #7898f5); }
.node-memo { font-size: 10px; color: var(--muted); margin-left: 3px; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-tools { position: absolute; z-index: 12; left: 100%; top: 50%; transform: translateY(-50%); display: inline-flex; gap: 0; opacity: 0; pointer-events: none; transition: opacity .12s; margin-left: 2px; }
.node-card:hover, .node-card:focus-within, .node-card.selected { z-index: 5; }
.node-card:hover .node-tools, .node-card:focus-within .node-tools, .node-card.selected .node-tools { opacity: 1; pointer-events: auto; }
.node-tools button, .fold, .child-add { width: 18px; height: 18px; border-radius: 3px; border: 0; background: transparent; color: #d1d7e2; cursor: pointer; font: inherit; font-size: 11px; line-height: 1; padding: 0; }
.node-tools button:hover, .fold:hover, .child-add:hover { background: #303644; }
.below-tools { display: flex; align-items: center; gap: 2px; height: 0; overflow: hidden; margin-left: 22px; opacity: 0; pointer-events: none; transition: height .12s, opacity .12s; }
.node-card:hover + .below-tools, .below-tools:hover, .node-card:focus-within + .below-tools, .tree-node:has(> .node-card.selected) > .below-tools { height: 15px; opacity: 1; pointer-events: auto; }
.below-tools { position: relative; z-index: 6; }
.child-add, .fold { width: 17px; height: 15px; color: #c7ceda; font-size: 11px; }
.root-card { min-height: 34px; font-weight: 600; }
.root-card::before { display: none; }
.root-card .node-title { font-size: 14px; }
.root-card .node-memo { display: none; }
.inline-name { flex: 0 1 auto; min-width: 5ch; max-width: none; height: 26px; border: 0; border-bottom: 1px solid #9bb5ff; border-radius: 0; padding: 2px 2px; background: transparent; color: inherit; font: inherit; font-size: 13px; outline: 0; }
.edge { fill: none; stroke: var(--branch-color, var(--line)); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.edge-dot { fill: #000000; stroke-width: 1.7; vector-effect: non-scaling-stroke; }
.canvas-controls { position: fixed; bottom: 14px; right: 14px; display: flex; gap: 3px; padding: 4px; background: #0b0c10; border: 1px solid var(--line); border-radius: 7px; z-index: 1; }
.canvas-controls button { width: 32px; height: 30px; border: 0; border-radius: 5px; background: #0b0c10; color: #ffffff; cursor: pointer; font: inherit; }
.hint { position: fixed; left: 13px; bottom: 19px; color: #929aa9; font-size: 10px; pointer-events: none; }
.editor { position: fixed; z-index: 3; right: 0; top: 62px; height: calc(100dvh - 62px); width: min(350px, 100vw); padding: 18px; background: #0b0c10; border-left: 1px solid var(--line); box-shadow: -8px 0 28px #0008; overflow: auto; }
.editor-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.editor h2 { font-size: 15px; margin: 4px 0; max-width: 270px; overflow-wrap: anywhere; }
.editor small { color: var(--muted); }
.icon-button { border: 0; background: #292e39; color: #f1f3f7; border-radius: 6px; width: 31px; height: 31px; font-size: 18px; cursor: pointer; }
.editor label { display: block; margin: 13px 0; color: #b5bdcb; font-size: 11px; }
.editor input:not([type=color]), .editor textarea, .editor select { display: block; width: 100%; margin-top: 5px; border: 1px solid var(--line); border-radius: 6px; padding: 9px; font: inherit; font-size: 13px; color: #ffffff; background: #111319; outline: none; }
.editor input:not([type=color]):focus, .editor textarea:focus, .editor select:focus { outline: 2px solid var(--border-neon); outline-offset: 2px; }
.editor input[type=color] { display: block; width: 58px; height: 32px; margin-top: 5px; border: 1px solid var(--line); border-radius: 6px; background: #111319; }
.editor-actions { display: flex; gap: 8px; margin-top: 18px; }
.toast { position: fixed; z-index: 5; left: 50%; bottom: 18px; transform: translateX(-50%); max-width: min(94vw, 500px); padding: 10px 13px; background: #191c24; color: #fff; border: 1px solid var(--line); border-radius: 7px; font-size: 12px; }
.toast button { margin-left: 12px; border: 0; background: transparent; color: #a9c5ff; font: inherit; font-weight: 600; cursor: pointer; }
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 21px; max-width: 420px; width: calc(100vw - 28px); color: #ffffff; background: #0b0c10; box-shadow: 0 20px 70px #0009; }
dialog::backdrop { background: #080a0fc9; }
dialog h2 { font-size: 16px; }
dialog p { font-size: 12px; line-height: 1.7; color: #b0b8c6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
@media (max-width: 700px) {
  .toolbar { min-height: 112px; padding: 8px 11px; display: grid; grid-template-columns: 1fr; gap: 6px; }
  .brand { min-width: 0; }
  .toolbar-actions { grid-row: 2; width: 100%; gap: 5px; margin: 0; overflow-x: auto; padding-bottom: 2px; }
  .toolbar-actions .button { height: 31px; padding: 0 9px; font-size: 10px; }
  .toolbar-actions #add-root span { display: none; }
  .toolbar-actions #export, .toolbar-actions #import { display: inline-block; }
  .search { grid-row: 3; width: 100%; max-width: none; height: 31px; }
  main, .canvas-wrap, .canvas { min-height: calc(100dvh - 112px); }
  .canvas { padding: 13px 10px 70px; }
  .tree { width: max-content; margin: 0; }
  .children { margin-left: 20px; }
  .node-card { min-height: 25px; padding: 0 1px; }
  .node-title { font-size: 13px; }
  .node-tools { opacity: 0; }
  .node-card.selected .node-tools, .node-card:focus-within .node-tools { opacity: 1; pointer-events: auto; }
  .node-tools button { width: 24px; height: 24px; font-size: 11px; }
  .node-memo { max-width: 100px; }
  .below-tools { margin-left: 18px; height: 0; }
  .node-card:hover + .below-tools, .below-tools:hover, .node-card:focus-within + .below-tools, .tree-node:has(> .node-card.selected) > .below-tools { height: 24px; opacity: 1; pointer-events: auto; }
  .child-add, .fold { width: 24px; height: 24px; }
  .hint { left: 10px; bottom: 17px; font-size: 9px; }
  .canvas-controls { right: 9px; bottom: 9px; }
  .editor { top: 0; width: min(330px, 88vw); height: 100dvh; padding: 17px; }
}

/* Hierarchy visibility: shared neutral selection trail, no level-based color or weight changes. */
.children { margin-left: 34px; gap: 4px; }
.node-card { min-height: 31px; }
.edge { stroke-width: 2.2; }
.edge.selected-path { stroke: #d8e2dc !important; stroke-width: 3; }
.node-card.in-selection-path { outline: 1px solid #95a39a; outline-offset: 2px; }
.node-card.selected { outline: 2px solid #d8e2dc; outline-offset: 2px; }
.selection-path { position: absolute; z-index: 8; top: 12px; left: 14px; display: flex; align-items: center; gap: 7px; max-width: calc(100% - 28px); left: auto; right: 14px; padding: 6px 9px; overflow-x: auto; white-space: nowrap; border: 1px solid #414852; border-radius: 5px; background: #0b0c10; color: #e5e9ed; font-size: 11px; line-height: 1.5; scrollbar-width: thin; }
.selection-path[hidden] { display: none !important; }
.selection-path-label, .selection-separator { color: #aab3bc; }
.selection-crumb, .selection-clear { flex: 0 0 auto; border: 0; padding: 1px 2px; background: transparent; color: #e5e9ed; font: inherit; cursor: pointer; }
.selection-crumb:hover, .selection-clear:hover { text-decoration: underline; }
.selection-clear { margin-left: 3px; font-size: 15px; }
.selection-crumb:focus-visible, .selection-clear:focus-visible { outline: 1px solid #d8e2dc; outline-offset: 2px; border-radius: 2px; }
.canvas-wrap:has(.selection-path:not([hidden])) .hint { opacity: .45; }
@media (max-width: 700px) {
  .children { margin-left: 26px; gap: 3px; }
  .selection-path { top: 8px; left: auto; right: 9px; max-width: calc(100% - 18px); gap: 5px; padding: 6px 7px; font-size: 10px; }
  .node-card { min-height: 30px; }
}