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

body {
  font-family: 'Yu Gothic UI', Meiryo, 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #eee;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  user-select: none;
}

/* ===== TOOLBAR ===== */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 46px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  flex-shrink: 0;
}
/* ---------- レスポンシブ：3段階（PC / タブレット / スマホ） ---------- */
@media (max-width:1023px) and (min-width:600px){
  #main { grid-template-columns: 16px 1fr 190px; }
  #side-panel { width: 190px; min-width: 190px; }
  #toolbar { height:auto; flex-wrap:wrap; padding:6px 10px; gap:6px; }
  .toolbar-back-link { font-size:10px; padding:4px 8px; }
}
@media (max-width:599px){
  #main { grid-template-columns: 14px 1fr 150px; }
  #side-panel { width: 150px; min-width: 150px; font-size:12px; }
  #toolbar {
    height:auto;
    flex-wrap:wrap;
    padding:6px 8px;
    gap:5px;
  }
  #toolbar button, #toolbar select { font-size:11px; padding:5px 7px; }
  .toolbar-brand-group { order:-1; width:100%; margin-bottom:2px; }
  .toolbar-back-link { font-size:10px; padding:4px 7px; }
}
.toolbar-brand { font-weight: 800; font-size: 15px; color: #a78bfa; letter-spacing: 1px; white-space: nowrap; }
.toolbar-tools { display: flex; gap: 4px; }
.toolbar-edge  { display: flex; align-items: center; gap: 4px; margin-left: 6px; }
.toolbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.toolbar-label { font-size: 11px; color: #aaa; white-space: nowrap; }
.toolbar-mark{
  width:7px;height:7px;border-radius:50%;
  background:#a78bfa;
  box-shadow:0 0 6px 1px rgba(167,139,250,.8), 0 0 14px 3px rgba(167,139,250,.35);
}
.toolbar-brand-group{display:flex;align-items:center;gap:8px;}
.toolbar-brand-sub{
  font-size:11px;
  color:#888;
  border-left:1px solid #0f3460;
  padding-left:8px;
  white-space:nowrap;
}
#app-footer{
  flex-shrink:0;
  text-align:center;
  padding:6px;
  background:#16213e;
  border-top:1px solid #0f3460;
}
.footer-copyright{
  font-size:10px;
  color:#666;
}
.toolbar-back-link {
  font-size: 11px;
  color: #a78bfa;
  text-decoration: none;
  border: 1px solid #0f3460;
  border-radius: 20px;
  padding: 5px 10px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.toolbar-back-link:hover { background: #0f3460; color: #fff; }

.tool-btn {
  padding: 4px 10px; border-radius: 8px; border: 1px solid #0f3460;
  background: #1a1a2e; color: #ccc; cursor: pointer; font-size: 12px; transition: all .15s;
}
.tool-btn:hover  { background: #0f3460; color: #fff; }
.tool-btn.active { background: #667eea; color: #fff; border-color: #667eea; }

#toolbar select {
  background: #1a1a2e; color: #eee; border: 1px solid #0f3460;
  border-radius: 6px; padding: 3px 6px; font-size: 11px; cursor: pointer; max-width: 155px;
}
#toolbar input[type=color] { width: 26px; height: 26px; border: none; border-radius: 6px; cursor: pointer; padding: 0; }
#toolbar button {
  padding: 4px 10px; border-radius: 8px; border: 1px solid #0f3460;
  background: #1a1a2e; color: #ccc; cursor: pointer; font-size: 12px; white-space: nowrap; transition: all .15s;
}
#toolbar button:hover { background: #0f3460; color: #fff; }

/* ===== MAIN ===== */
#main {
  display: grid;
  grid-template-columns: 20px 1fr 234px;
  grid-template-rows: 20px 1fr;
  flex: 1;
  overflow: hidden;
}
#ruler-corner {
  grid-column: 1; grid-row: 1;
  background: #0f3460;
  border-right: 1px solid #1a2a4a;
  border-bottom: 1px solid #1a2a4a;
}
#ruler-h {
  grid-column: 2; grid-row: 1;
  height: 20px; width: 100%;
  background: #0f3460;
  border-bottom: 1px solid #1a2a4a;
  display: block;
}
#ruler-v {
  grid-column: 1; grid-row: 2;
  width: 20px; height: 100%;
  background: #0f3460;
  border-right: 1px solid #1a2a4a;
  display: block;
}
#side-panel {
  grid-column: 3; grid-row: 1 / 3;
}

/* ===== CANVAS ===== */
#canvas-container {
  grid-column: 2; grid-row: 2;
  position: relative; overflow: hidden; cursor: default;
  background-color: #f0f4ff;
  background-image: radial-gradient(circle, rgba(102,126,234,0.45) 1px, transparent 1px);
  background-size: 28px 28px;
}
#canvas-container.tool-node  { cursor: crosshair; }
#canvas-container.tool-text  { cursor: text; }
#canvas-container.tool-group { cursor: crosshair; }
#canvas-container.mode-edge  { cursor: cell; }
#canvas-container.tool-line   { cursor: crosshair; }

#graph { position: absolute; top:0; left:0; width:100%; height:100%; overflow:visible; }

/* レイヤー順: groups(底) → edges → nodes(最前面) */
#layer-groups { pointer-events: all; }
#layer-edges  { pointer-events: all; }
#layer-nodes  { pointer-events: all; }

/* ===== NODE ===== */
.node { cursor: move; }
.node.edge-source .node-frame { stroke: #ff4757 !important; }

/* ===== EDGE ===== */
.edge-line    { pointer-events: none; }
.edge-hitbox  { stroke: transparent; stroke-width: 16; fill: none; cursor: pointer; }
.edge.selected .edge-line { filter: drop-shadow(0 0 4px rgba(102,126,234,0.7)); }
.edge-label-g { cursor: move; }

/* ===== CONNECT BTN ===== */
#connect-btn {
  display: none; position: absolute; width: 28px; height: 28px; border-radius: 50%;
  background: #667eea; color: #fff; border: 2px solid #fff; cursor: pointer;
  font-size: 14px; line-height: 1; z-index: 20;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35); transition: transform .1s;
}
#connect-btn:hover { transform: scale(1.18); background: #5a6fd6; }

/* ===== EDGE HINT ===== */
#edge-hint {
  display: none; position: absolute; bottom: 32px; left: 50%; transform: translateX(-50%);
  background: rgba(20,20,50,0.88); color: #fff; padding: 6px 16px;
  border-radius: 20px; font-size: 12px; pointer-events: none; z-index: 30;
}

/* ===== DROP OVERLAY ===== */
#drop-overlay {
  display: none; position: absolute; inset: 0;
  background: rgba(102,126,234,0.13); border: 3px dashed #667eea;
  align-items: center; justify-content: center;
  font-size: 18px; color: #667eea; z-index: 25; pointer-events: none;
}
#drop-overlay.active { display: flex; }

/* ===== GROUP PREVIEW ===== */
#group-preview {
  display: none; position: absolute; border: 2px dashed #667eea;
  background: rgba(102,126,234,0.07); border-radius: 12px; pointer-events: none;
}

/* ===== SIDE PANEL ===== */
#side-panel {
  width: 234px; min-width: 234px; background: #16213e;
  border-left: 1px solid #0f3460; overflow-y: auto; overflow-x: hidden; flex-shrink: 0;
}
#side-panel::-webkit-scrollbar { width: 4px; }
#side-panel::-webkit-scrollbar-thumb { background: #0f3460; border-radius: 2px; }

.panel-section { padding: 11px 12px; border-bottom: 1px solid #0f3460; }
.panel-title { font-size: 13px; font-weight: 700; color: #a78bfa; margin-bottom: 9px; }
.panel-divider {
  font-size: 10px; color: #555; text-align: center;
  margin: 8px 0 6px; letter-spacing: 1px;
}

.hint-title { font-size: 12px; font-weight: 700; color: #a78bfa; margin-bottom: 6px; }
.hint-body  { font-size: 11px; color: #aaa; line-height: 1.75; }

.prop-group { margin-bottom: 7px; }
.prop-label { font-size: 10px; color: #777; margin-bottom: 3px; }

#side-panel input[type=text],
#side-panel input[type=number],
#side-panel select,
#side-panel textarea {
  width: 100%; background: #1a1a2e; border: 1px solid #0f3460; border-radius: 6px;
  color: #eee; padding: 5px 8px; font-size: 12px; font-family: inherit; outline: none; transition: border-color .15s;
}
#side-panel input:focus,
#side-panel select:focus,
#side-panel textarea:focus { border-color: #667eea; }
#side-panel textarea { resize: vertical; min-height: 52px; }
#side-panel input[type=color] { width: 34px; height: 26px; border: none; border-radius: 6px; cursor: pointer; padding: 0; background: none; }
#side-panel input[type=checkbox] { width: auto; accent-color: #667eea; cursor: pointer; }
#side-panel input[type=range]    { accent-color: #667eea; cursor: pointer; }

.slider-row  { display: flex; align-items: center; gap: 8px; }
.slider-val  { font-size: 11px; color: #aaa; min-width: 36px; text-align: right; }

/* スウォッチ */
.swatches { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.color-swatch {
  width: 18px; height: 18px; border-radius: 4px; cursor: pointer;
  border: 2px solid transparent; transition: transform .1s, border-color .1s;
}
.color-swatch:hover  { transform: scale(1.22); }
.color-swatch.active { border-color: #fff; }

/* アイコンスウォッチ */
.icon-swatches { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.icon-swatch {
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer; font-size: 16px;
  background: #1a1a2e; border: 1px solid #0f3460; display: flex;
  align-items: center; justify-content: center; transition: all .12s;
}
.icon-swatch:hover  { background: #0f3460; transform: scale(1.15); }
.icon-swatch.active { border-color: #667eea; background: #1e2a4a; }

.btn-row { display: flex; gap: 6px; }
.btn-row button {
  flex: 1; padding: 5px; background: #1a1a2e; border: 1px solid #0f3460;
  border-radius: 6px; color: #ccc; cursor: pointer; font-size: 11px; transition: all .15s;
}
.btn-row button:hover { background: #0f3460; color: #fff; }

#side-panel button:not(.btn-danger):not(.btn-row button) {
  padding: 5px 10px; background: #1a1a2e; border: 1px solid #0f3460;
  border-radius: 6px; color: #ccc; cursor: pointer; font-size: 11px; transition: all .15s;
}
#side-panel button:not(.btn-danger):not(.btn-row button):hover { background: #0f3460; color: #fff; }

.btn-danger {
  width: 100%; padding: 6px; background: rgba(255,71,87,0.1); border: 1px solid #ff4757;
  border-radius: 6px; color: #ff6b7a; cursor: pointer; font-size: 11px;
  margin-top: 6px; transition: all .15s;
}
.btn-danger:hover { background: #ff4757; color: #fff; }

/* ===== STATUS BAR ===== */
#statusbar {
  height: 24px; background: #0f3460; display: flex; align-items: center;
  gap: 16px; padding: 0 12px; font-size: 11px; color: #777; flex-shrink: 0;
}
#st-msg { color: #a78bfa; margin-left: auto; }

/* ===== CTX MENU ===== */
.ctx-menu {
  display: none; position: fixed; background: #1e2a4a; border: 1px solid #0f3460;
  border-radius: 10px; padding: 4px 0; z-index: 100; min-width: 160px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}
.ctx-item { padding: 7px 14px; cursor: pointer; font-size: 12px; color: #ccc; transition: background .1s; }
.ctx-item:hover { background: #0f3460; color: #fff; }
.ctx-danger { color: #ff6b7a !important; }
.ctx-danger:hover { background: rgba(255,71,87,0.18) !important; }

/* ===== TRIM DIALOG ===== */
#trim-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.72);
  z-index: 200; align-items: center; justify-content: center;
}
#trim-overlay.active { display: flex; }
#trim-dialog {
  background: #16213e; border: 1px solid #0f3460; border-radius: 16px;
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
  max-width: 760px; width: 95vw; box-shadow: 0 16px 48px rgba(0,0,0,0.55);
}
#trim-header   { font-size: 14px; font-weight: 700; color: #a78bfa; }
#trim-body     { display: flex; gap: 16px; align-items: flex-start; }
#trim-canvas   { border-radius: 8px; cursor: crosshair; max-width: 560px; display: block; }
#trim-right    { display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 108px; }
#trim-preview-label { font-size: 11px; color: #888; }
#trim-preview  { border-radius: 6px; border: 2px solid #667eea; display: block; }
#trim-hint     { font-size: 10px; color: #555; text-align: center; line-height: 1.6; }
#trim-footer   { display: flex; justify-content: flex-end; gap: 10px; }
#trim-footer button { padding: 7px 20px; border-radius: 8px; border: 1px solid #0f3460; cursor: pointer; font-size: 13px; }
#trim-cancel   { background: #1a1a2e; color: #aaa; }
#trim-cancel:hover { background: #0f3460; color: #fff; }
#trim-ok       { background: #667eea; color: #fff; border-color: #667eea; }
#trim-ok:hover { background: #5a6fd6; }

/* リサイズハンドル */
.node circle[r="5"] { pointer-events: all; }

/* バージョン表示 */
.toolbar-ver {
  font-size: 9px; color: #666; margin-left: 5px; font-weight: 400; letter-spacing: 0;
}

/* Buy Me a Coffee */
.bmc-link {
  color: #fdcb6e; text-decoration: none; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 10px; border: 1px solid #fdcb6e44;
  transition: all .15s; white-space: nowrap;
}
.bmc-link:hover { background: #fdcb6e22; color: #ffd97d; }

/* スペースパン */
#canvas-container.tool-pan { cursor: grab !important; }
#canvas-container.tool-pan:active { cursor: grabbing !important; }

/* パネルミニヒント */
.panel-hint-mini {
  font-size: 10px;
  color: #556;
  background: #0f1a2e;
  border-radius: 6px;
  padding: 5px 8px;
  margin-bottom: 8px;
  line-height: 1.7;
  border-left: 2px solid #667eea44;
}

/* ヒントセクション見出し */
.hint-section {
  color: #a78bfa;
  font-size: 11px;
  margin-top: 2px;
  margin-bottom: 1px;
}

/* パネル内ヒントボックス */
.panel-hint-box {
  font-size: 10px;
  color: #667eea;
  background: rgba(102,126,234,0.08);
  border: 1px solid rgba(102,126,234,0.2);
  border-radius: 6px;
  padding: 5px 8px;
  margin-bottom: 8px;
  line-height: 1.7;
}


/* ツールバーセパレーター */
.toolbar-sep {
  width: 1px; height: 20px;
  background: #0f3460; margin: 0 2px;
}

/* ===== PANEL TABS ===== */
#panel-tabs {
  display: flex;
  border-bottom: 1px solid #0f3460;
  background: #16213e;
  flex-shrink: 0;
}
.panel-tab {
  flex: 1; padding: 8px 4px; font-size: 12px; font-weight: 600;
  background: none; border: none; color: #666; cursor: pointer;
  border-bottom: 2px solid transparent; transition: all .15s;
}
.panel-tab:hover { color: #aaa; }
.panel-tab.active { color: #a78bfa; border-bottom-color: #a78bfa; }
.tab-content { display: block; overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0; }
.tab-content::-webkit-scrollbar { width: 4px; }
.tab-content::-webkit-scrollbar-thumb { background: #0f3460; border-radius: 2px; }

/* panel-content はスクロール可能な領域 */
#panel-content { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
#panel-content::-webkit-scrollbar { width: 4px; }
#panel-content::-webkit-scrollbar-thumb { background: #0f3460; border-radius: 2px; }

/* tab-pane */
.tab-pane { padding: 4px 0; }

/* 言語セレクト */
#panel-lang { padding: 8px 12px; border-bottom: 1px solid #0f3460; }
#lang-select { width: 100%; padding: 4px 6px; background: #0f3460; border: 1px solid #1a3a6e;
  border-radius: 6px; color: #c4b5fd; font-size: 12px; }

/* side-panelをflexに */
#side-panel {
  display: flex !important;
  flex-direction: column;
}

/* ===== FORK OVERLAY ===== */
#fork-overlay {
  display: none;
  position: absolute;
  bottom: 60px; left: 50%;
  transform: translateX(-50%);
  background: rgba(20,20,50,0.92);
  border: 1px solid #667eea;
  border-radius: 14px;
  padding: 8px 16px;
  gap: 12px;
  align-items: center;
  z-index: 30;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
#fork-count {
  font-size: 12px; color: #a78bfa;
}
#btn-fork-confirm {
  padding: 4px 14px; background: #667eea; color: #fff;
  border: none; border-radius: 8px; cursor: pointer; font-size: 12px;
}
#btn-fork-confirm:hover { background: #5a6fd6; }
#btn-fork-cancel {
  padding: 4px 10px; background: transparent; color: #ff6b7a;
  border: 1px solid #ff4757; border-radius: 8px; cursor: pointer; font-size: 12px;
}
#btn-fork-cancel:hover { background: #ff4757; color: #fff; }

/* フォーク選択中の子ノードハイライト */
.fork-dst .node-frame,
.fork-dst rect:first-child,
.fork-dst ellipse:first-child,
.fork-dst path:first-child,
.fork-dst circle:first-child {
  stroke: #ffa502 !important;
  stroke-width: 3 !important;
}

/* ヘルプタブ内SupportMeリンク */
.bmc-link-panel {
  display: inline-block;
  color: #fdcb6e; text-decoration: none; font-size: 12px; font-weight: 600;
  padding: 8px 16px; border-radius: 20px;
  border: 1px solid #fdcb6e66; background: rgba(253,203,110,0.08);
  transition: all .15s;
}
.bmc-link-panel:hover { background: rgba(253,203,110,0.18); color: #ffd97d; }

/* フルスクリーン解除ボタン */
#btn-fullscreen-exit {
  display: none;
  position: absolute;
  top: 8px; right: 8px;
  z-index: 40;
  padding: 4px 10px;
  background: rgba(20,20,50,0.75);
  border: 1px solid #667eea;
  border-radius: 8px;
  color: #a78bfa;
  cursor: pointer;
  font-size: 12px;
}
:fullscreen #btn-fullscreen-exit,
:-webkit-full-screen #btn-fullscreen-exit { display: block; }
