:root {
  --bg: #0d0f14;
  --grid-dot: rgba(255, 255, 255, 0.11);
  --chrome: rgba(20, 23, 31, 0.88);
  --chrome-border: rgba(255, 255, 255, 0.1);
  --node-bg: #161a24;
  --node-border: rgba(255, 255, 255, 0.11);
  --ink: #f3f4f6;
  --ink-2: #cbd5e1;
  --muted: #8b95a7;
  --edge: #64748b;
  --edge-hi: #38bdf8;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-float: 0 10px 30px rgba(0, 0, 0, 0.55);
  --sel: #38bdf8;
  --sticky-bg: #fef08a;
  --sticky-ink: #422006;
}
[data-theme="light"] {
  --bg: #f4f5f7;
  --grid-dot: rgba(15, 23, 42, 0.14);
  --chrome: rgba(255, 255, 255, 0.9);
  --chrome-border: rgba(15, 23, 42, 0.1);
  --node-bg: #ffffff;
  --node-border: rgba(15, 23, 42, 0.12);
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --edge: #94a3b8;
  --edge-hi: #0284c7;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-float: 0 10px 30px rgba(15, 23, 42, 0.12);
  --sel: #0284c7;
  --sticky-bg: #fef08a;
  --sticky-ink: #422006;
}

* { box-sizing: border-box; user-select: none; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

#viewport {
  position: fixed; inset: 0; overflow: hidden; cursor: grab;
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid-dot) 1.25px, transparent 1.25px);
  background-size: 24px 24px;
}
#viewport.panning { cursor: grabbing; }
#viewport.connecting { cursor: crosshair; }

#world { position: absolute; top: 0; left: 0; width: 0; height: 0; transform-origin: 0 0; }

#edgesLayer {
  position: absolute; top: -4000px; left: -4000px; width: 12000px; height: 12000px;
  pointer-events: none; overflow: visible;
}
.edge-path { fill: none; stroke: var(--edge); stroke-width: 2.2; transition: stroke 0.15s; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 16; cursor: pointer; pointer-events: stroke; }
.edge-group:hover .edge-path, .edge-group.selected .edge-path { stroke: var(--edge-hi); stroke-width: 3; }
.edge-label-bg { fill: var(--node-bg); stroke: var(--node-border); stroke-width: 1; rx: 6; ry: 6; cursor: pointer; pointer-events: all; }
.edge-label-txt { fill: var(--muted); font-size: 10.5px; font-weight: 600; text-anchor: middle; pointer-events: none; }
.edge-group:hover .edge-label-txt, .edge-group.selected .edge-label-txt { fill: var(--edge-hi); }

.node {
  position: absolute; width: 252px;
  background: var(--node-bg); border: 1.5px solid var(--node-border); border-radius: 14px;
  box-shadow: var(--shadow); cursor: grab; transition: box-shadow 0.15s, border-color 0.15s;
}
.node:hover { border-color: rgba(148, 163, 184, 0.45); }
.node.selected { border-color: var(--sel); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.25), var(--shadow); z-index: 20; }
.node.dragging { cursor: grabbing; z-index: 30; opacity: 0.96; }

.node-stripe { height: 5px; width: 100%; border-radius: 12px 12px 0 0; }
.node-head { padding: 10px 13px 6px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.node-badge { font-size: 0.64rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em; padding: 2px 7px; border-radius: 999px; }
.node-title { padding: 0 13px 6px; font-size: 0.92rem; font-weight: 700; letter-spacing: -0.015em; line-height: 1.3; }
.node-body { padding: 0 13px 12px; font-size: 0.77rem; color: var(--muted); line-height: 1.48; white-space: pre-line; }

.node.type-sticky {
  width: 220px; background: var(--sticky-bg); color: var(--sticky-ink);
  border-color: rgba(180, 83, 9, 0.25); border-radius: 10px; transform: rotate(-0.6deg);
}
.node.type-sticky .node-stripe { display: none; }
.node.type-sticky .node-badge { background: rgba(120, 53, 15, 0.12); color: #78350f; }
.node.type-sticky .node-title { color: #451a03; font-size: 0.88rem; }
.node.type-sticky .node-body { color: #713f12; font-size: 0.78rem; }

.node.type-core {
  width: 272px; border-color: rgba(20, 184, 166, 0.6);
  box-shadow: 0 0 0 1px rgba(20, 184, 166, 0.25), var(--shadow);
}

.port {
  position: absolute; top: 50%; width: 13px; height: 13px; border-radius: 50%;
  background: var(--node-bg); border: 2.5px solid var(--edge);
  transform: translateY(-50%); cursor: crosshair; z-index: 5;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.port.in { left: -7px; }
.port.out { right: -7px; }
.node:hover .port, .port:hover { border-color: var(--edge-hi); }
.port:hover { transform: translateY(-50%) scale(1.35); background: var(--edge-hi); }

.c-proc { background: #3b82f6; } .b-proc { background: rgba(59, 130, 246, 0.16); color: #60a5fa; }
.c-store { background: #14b8a6; } .b-store { background: rgba(20, 184, 166, 0.16); color: #2dd4bf; }
.c-core { background: linear-gradient(90deg, #10b981, #06b6d4); } .b-core { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.c-gate { background: #f59e0b; } .b-gate { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.c-fin { background: #a855f7; } .b-fin { background: rgba(168, 85, 247, 0.18); color: #c084fc; }
.c-actor { background: #ec4899; } .b-actor { background: rgba(236, 72, 153, 0.16); color: #f472b6; }
.c-class { background: #6366f1; } .b-class { background: rgba(99, 102, 241, 0.18); color: #818cf8; }
.c-kpi { background: #22c55e; } .b-kpi { background: rgba(34, 197, 94, 0.16); color: #4ade80; }
.c-state { background: #06b6d4; } .b-state { background: rgba(6, 182, 212, 0.16); color: #22d3ee; }

[data-theme="light"] .b-proc { color: #1d4ed8; }
[data-theme="light"] .b-store { color: #0f766e; }
[data-theme="light"] .b-core { color: #047857; }
[data-theme="light"] .b-gate { color: #b45309; }
[data-theme="light"] .b-fin { color: #7e22ce; }
[data-theme="light"] .b-actor { color: #be185d; }
[data-theme="light"] .b-class { color: #4338ca; }
[data-theme="light"] .b-kpi { color: #15803d; }
[data-theme="light"] .b-state { color: #0e7490; }

.float-bar {
  position: fixed; z-index: 40;
  background: var(--chrome); backdrop-filter: blur(14px);
  border: 1px solid var(--chrome-border); border-radius: 14px;
  box-shadow: var(--shadow-float);
  display: flex; align-items: center; gap: 6px; padding: 6px;
}
.top-left { top: 16px; left: 16px; gap: 8px; padding: 6px 10px; }
.top-right { top: 16px; right: 16px; }
.bottom-dock { bottom: 18px; left: 50%; transform: translateX(-50%); padding: 6px 8px; gap: 5px; }
.bottom-left { bottom: 18px; left: 16px; padding: 5px 8px; }

.logo-dot {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #14b8a6, #3b82f6);
  color: #fff; font-weight: 900; font-size: 0.85rem; display: grid; place-items: center;
}
.divider { width: 1px; height: 22px; background: var(--chrome-border); margin: 0 2px; }

.fbtn {
  font-family: inherit; font-size: 0.78rem; font-weight: 600; text-decoration: none;
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
  padding: 7px 11px; border-radius: 9px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: all 0.12s;
}
.fbtn:hover { background: rgba(148, 163, 184, 0.14); color: var(--ink); }
.fbtn.active { background: rgba(56, 189, 248, 0.18); color: #38bdf8; border-color: rgba(56, 189, 248, 0.35); }
[data-theme="light"] .fbtn.active { color: #0369a1; }
.fbtn.primary { background: linear-gradient(135deg, #0ea5e9, #6366f1); color: #fff; }
.fbtn.primary:hover { filter: brightness(1.08); }
.fbtn.sticky-btn { background: rgba(254, 240, 138, 0.18); color: #fde047; }
[data-theme="light"] .fbtn.sticky-btn { background: #fef08a; color: #713f12; }
.dot-swatch { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

#inspector {
  position: fixed; top: 74px; right: 16px; width: 315px; max-height: calc(100vh - 150px);
  z-index: 45; background: var(--chrome); backdrop-filter: blur(16px);
  border: 1px solid var(--chrome-border); border-radius: 16px; box-shadow: var(--shadow-float);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(350px); opacity: 0; pointer-events: none;
  transition: transform 0.2s cubic-bezier(.16,1,.3,1), opacity 0.2s;
}
#inspector.open { transform: translateX(0); opacity: 1; pointer-events: auto; }
.insp-head { padding: 13px 15px; border-bottom: 1px solid var(--chrome-border); display: flex; align-items: center; justify-content: space-between; }
.insp-head strong { font-size: 0.85rem; }
.insp-body { padding: 14px 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.insp-body * { user-select: text; }
.insp-field label { display: block; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 5px; }
.insp-field input, .insp-field textarea, .insp-field select {
  width: 100%; background: rgba(15, 23, 42, 0.45); border: 1px solid var(--chrome-border);
  border-radius: 9px; color: var(--ink); font-family: inherit; font-size: 0.82rem; padding: 8px 10px; outline: none;
}
[data-theme="light"] .insp-field input,
[data-theme="light"] .insp-field textarea,
[data-theme="light"] .insp-field select { background: #f8fafc; }
.insp-field input:focus, .insp-field textarea:focus { border-color: var(--sel); }
.insp-field textarea { min-height: 110px; resize: vertical; line-height: 1.45; }

#minimap {
  position: fixed; bottom: 18px; right: 16px; width: 170px; height: 110px; z-index: 40;
  background: var(--chrome); backdrop-filter: blur(12px);
  border: 1px solid var(--chrome-border); border-radius: 12px; box-shadow: var(--shadow-float);
  overflow: hidden; pointer-events: none;
}
#minimap svg { width: 100%; height: 100%; display: block; }

.hint {
  position: fixed; top: 72px; left: 16px; z-index: 35;
  font-size: 0.72rem; color: var(--muted);
  background: var(--chrome); border: 1px solid var(--chrome-border);
  padding: 5px 10px; border-radius: 999px; pointer-events: none;
}

.modal-bg {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.65); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 90;
}
.modal-bg.open { display: flex; }
.modal {
  width: 100%; max-width: 720px; max-height: 82vh; background: var(--node-bg);
  border: 1px solid var(--chrome-border); border-radius: 16px; box-shadow: var(--shadow-float);
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
}
.modal * { user-select: text; }
.modal pre {
  margin: 0; overflow: auto; flex: 1; background: var(--bg); border: 1px solid var(--chrome-border);
  border-radius: 10px; padding: 12px; font-size: 0.78rem; color: var(--ink-2); white-space: pre-wrap;
}

.toast {
  position: fixed; bottom: 74px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: #0ea5e9; color: #fff; padding: 7px 14px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 700; opacity: 0; pointer-events: none; transition: all 0.2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .hint, #minimap { display: none; }
  .bottom-dock { max-width: 94vw; overflow-x: auto; }
}

/* Split / Full OOSAD Specification Panel */
body.mode-split #viewport { right: 48%; }
body.mode-doc #viewport, body.mode-doc .bottom-dock, body.mode-doc .bottom-left, body.mode-doc #minimap, body.mode-doc .hint { display: none !important; }
body.mode-split .bottom-dock { left: 26%; }
body.mode-split #minimap { right: calc(48% + 16px); }
body.mode-split #inspector { right: calc(48% + 16px); }

#specPanel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 48%;
  background: var(--bg);
  border-left: 1px solid var(--chrome-border);
  z-index: 38;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  padding: 82px 28px 60px;
}
body.mode-split #specPanel { display: flex; }
body.mode-doc #specPanel { display: flex; width: 100%; border-left: none; align-items: center; }
body.mode-doc .spec-inner { max-width: 900px; width: 100%; }

.spec-inner { display: flex; flex-direction: column; gap: 22px; }
.spec-inner * { user-select: text; }

.spec-sec {
  background: var(--node-bg);
  border: 1px solid var(--node-border);
  border-radius: 14px;
  padding: 18px 20px;
}
.spec-sec-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--chrome-border);
}
.spec-sec-head h2 { margin: 0; font-size: 0.96rem; font-weight: 800; letter-spacing: -0.015em; display: flex; align-items: center; gap: 8px; }
.spec-tag { font-size: 0.68rem; font-weight: 800; padding: 2px 7px; border-radius: 6px; background: rgba(56, 189, 248, 0.16); color: #38bdf8; }

.spec-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (max-width: 900px) {
  body.mode-split #viewport { right: 0; bottom: 52%; }
  body.mode-split #specPanel { top: 48%; width: 100%; border-left: none; border-top: 1px solid var(--chrome-border); padding-top: 20px; }
  .spec-grid-2 { grid-template-columns: 1fr; }
}

.spec-kv { display: flex; flex-direction: column; gap: 3px; }
.spec-kv label { font-size: 0.67rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.ed {
  outline: none; border-radius: 6px; padding: 3px 6px; margin: -3px -6px;
  font-size: 0.83rem; color: var(--ink-2); line-height: 1.5; cursor: text;
  transition: background 0.12s, box-shadow 0.12s;
}
.ed:hover { background: rgba(148, 163, 184, 0.1); }
.ed:focus { background: rgba(15, 23, 42, 0.5); box-shadow: 0 0 0 1.5px var(--sel); color: var(--ink); }
[data-theme="light"] .ed:focus { background: #ffffff; }
.ed.b { font-weight: 700; color: var(--ink); }

.spec-row {
  padding: 11px 12px; border-radius: 10px;
  background: rgba(148, 163, 184, 0.05);
  border: 1px solid var(--chrome-border);
  display: flex; flex-direction: column; gap: 6px;
}
.spec-row-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pill-sm {
  font-size: 0.66rem; font-weight: 800; padding: 2px 8px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.04em; border: none; cursor: pointer; font-family: inherit;
}
.pill-in { background: rgba(34, 197, 94, 0.18); color: #4ade80; }
.pill-later { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.pill-out { background: rgba(239, 68, 68, 0.18); color: #f87171; }
[data-theme="light"] .pill-in { color: #15803d; }
[data-theme="light"] .pill-later { color: #b45309; }
[data-theme="light"] .pill-out { color: #b91c1c; }

.feas-score-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: 11px;
  background: rgba(20, 184, 166, 0.12); border: 1px solid rgba(20, 184, 166, 0.3);
  margin-bottom: 12px;
}
.feas-score-banner strong { font-size: 1.15rem; color: #2dd4bf; }
[data-theme="light"] .feas-score-banner strong { color: #0f766e; }

