* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: #f4f6f8;
  color: #222;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toolbar {
  background: #ffffff;
  padding: 16px 20px 0;
  flex-shrink: 0;
  border-bottom: 1px solid #2563eb;
}

.toolbar-title {
  display: flex;
  align-items: center;
}

.toolbar h1 {
  margin: 0;
  font-size: 20px;
}

.toolbar-hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.btn {
  border: 1px solid #d0d5db;
  background: #fafafa;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: #eef1f5;
}

.btn.active {
  background: #dbeafe;
  border-color: #60a5fa;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.hint {
  margin: 0;
  font-size: 13px;
  color: #667085;
}

.tab-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #d0d5db;
  background: #f5f6f8;
  border-radius: 8px 8px 0 0;
  padding: 10px 12px;
  font-size: 13px;
  cursor: pointer;
}

.tab.active {
  background: #f4f6f8;
  border-color: #2563eb;
  border-bottom-color: #f4f6f8;
  margin-bottom: -1px;
  font-weight: bold;
  position: relative;
  z-index: 1;
}

.tab input {
  font-size: 13px;
  font-weight: bold;
  border: 1px solid #d0d5db;
  border-radius: 4px;
  width: 90px;
}

.tab-add {
  border: 1px dashed #b0b8c4;
  background: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  color: #475569;
  margin-bottom: 10px;
}

.tab-add:hover {
  background: #eef1f5;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: #ffffff;
  border-radius: 14px;
  padding: 20px 24px;
  width: 420px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.help-list {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
  line-height: 1.7;
}

.share-link-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.share-link-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #d0d5db;
  border-radius: 6px;
  font-size: 13px;
}

.share-link-row button {
  border: 1px solid #2563eb;
  background: #2563eb;
  color: #fff;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.share-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.share-primary-btn {
  width: 100%;
  margin-top: 14px;
  border: 1px solid #2563eb;
  background: #2563eb;
  color: #fff;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
}

.share-note {
  margin-top: 10px;
  font-size: 12px;
  color: #667085;
}

#canvasWrap {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  background-image: radial-gradient(#e2e5e9 1px, transparent 1px);
  background-size: 24px 24px;
  cursor: grab;
}

#canvasWrap.panning {
  cursor: grabbing;
}

#canvasContent {
  position: absolute;
  top: 0;
  left: 0;
  width: 6000px;
  height: 4000px;
  transform-origin: 0 0;
}

.toolbar-divider {
  width: 1px;
  flex-shrink: 0;
  align-self: stretch;
  background: #e0e0e0;
  margin: 0 2px;
}

.canvas-toolbar {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 32px);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.icon-btn-toolbar {
  font-size: 16px;
  line-height: 1;
  padding: 7px 9px;
  flex-shrink: 0;
}

#lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 6000px;
  height: 4000px;
  pointer-events: none;
}

#nodes {
  position: absolute;
  top: 0;
  left: 0;
  width: 6000px;
  height: 4000px;
}

.node {
  position: absolute;
  width: 108px;
  text-align: center;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  background: #ffffff;
  border: 1px solid #c7cdd6;
  border-radius: 8px;
  padding: 7px 7px 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.node .avatar {
  width: 100%;
  height: 72px;
  margin: 0 0 6px;
  border-radius: 5px;
  background-color: #dfe4ea;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='9' r='4' fill='%23b0b8c4'/><path d='M4 20c0-4.4 3.6-7 8-7s8 2.6 8 7' fill='%23b0b8c4'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 42%;
  border: 2px solid transparent;
  box-sizing: border-box;
}

.node .name {
  font-size: 10px;
  font-weight: 700;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node .rel-label {
  font-size: 8px;
  color: #94a1b2;
  margin-top: 1px;
}

.node.active {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.25);
}

.node.editMode {
  border-color: #8b5cf6;
  box-shadow: 0 0 0 3px rgba(139,92,246,0.3);
}

.node .first-badge {
  display: none;
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #dc2626;
  color: #fff;
  font-size: 11px;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  z-index: 6;
}

.node.firstSelected .first-badge {
  display: flex;
}

.dir-btn {
  position: absolute;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid #8b5cf6;
  color: #6d28d9;
  cursor: pointer;
  white-space: nowrap;
  z-index: 5;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.dir-btn:hover {
  background: #f5f3ff;
}

.dir-top {
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
}

.dir-bottom {
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
}

.dir-left {
  top: 43px;
  left: -8px;
  transform: translate(-100%, -50%);
}

.dir-right {
  top: 43px;
  right: -8px;
  transform: translate(100%, -50%);
}

.edge-line {
  stroke: #94a3b8;
  stroke-width: 2;
}

.spouse-line {
  stroke: #475569;
  stroke-width: 2;
}

.sibling-line {
  stroke: #94a3b8;
  stroke-width: 2;
  stroke-dasharray: 5 4;
}

.active-line {
  stroke: #2563eb;
  stroke-width: 3;
}

.info-panel {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  border: 1px solid #d0d5db;
  border-radius: 12px;
  padding: 14px 18px;
  min-width: 260px;
  max-width: 90vw;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 30;
}

.info-panel.hidden {
  display: none;
}

.info-panel.editing {
  width: 340px;
  max-height: 70vh;
  overflow-y: auto;
}

.info-panel.pair {
  width: 380px;
}

.info-panel .detail-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.info-panel .detail-avatar {
  width: 76px;
  height: 76px;
  flex-shrink: 0;
  border-radius: 6px;
  background-color: #dfe4ea;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='9' r='4' fill='%23b0b8c4'/><path d='M4 20c0-4.4 3.6-7 8-7s8 2.6 8 7' fill='%23b0b8c4'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 42%;
}

.info-panel .detail-text {
  flex: 1;
  min-width: 0;
}

.info-panel .info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.gender-icon {
  margin-left: 5px;
  font-weight: bold;
}

.gender-icon.male {
  color: #2563eb;
}

.gender-icon.female {
  color: #e11d48;
}

.info-panel .info-name {
  font-size: 16px;
  font-weight: bold;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-panel .info-name-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.info-panel .info-summary {
  margin-top: 4px;
  font-size: 13px;
  color: #94a1b2;
}

.info-panel .info-memo {
  margin-top: 4px;
  font-size: 13px;
  color: #94a1b2;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-panel .pair-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.info-panel .pair-person {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 90px;
}

.info-panel .pair-avatar {
  width: 76px;
  height: 76px;
  border-radius: 6px;
  background-color: #dfe4ea;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='9' r='4' fill='%23b0b8c4'/><path d='M4 20c0-4.4 3.6-7 8-7s8 2.6 8 7' fill='%23b0b8c4'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 42%;
}

.info-panel .pair-name {
  font-size: 14px;
  font-weight: bold;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-panel .pair-middle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.info-panel .arrow-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: bold;
  white-space: nowrap;
}

.info-panel .arrow-row .arrow {
  font-size: 16px;
}

.info-panel .arrow-row.pending {
  color: #94a1b2;
  font-weight: normal;
}

.info-panel .pair-degree {
  font-size: 13px;
  color: #94a1b2;
  margin: 2px 0;
}

.info-panel .icon-btn {
  border: none;
  background: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
}

.info-panel .detail-form h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.info-panel .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  text-align: left;
}

.info-panel .field label {
  font-size: 12px;
  color: #667085;
}

.info-panel .field.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.info-panel .field.checkbox-field label {
  font-size: 13px;
  color: #1a1a1a;
}

.info-panel .field input,
.info-panel .field select,
.info-panel .field textarea {
  padding: 6px 8px;
  border: 1px solid #d0d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

.info-panel .field textarea {
  resize: vertical;
  min-height: 50px;
}

.info-panel .photo-preview {
  width: 96px;
  height: 96px;
  border-radius: 8px;
  background-color: #dfe4ea;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='9' r='4' fill='%23b0b8c4'/><path d='M4 20c0-4.4 3.6-7 8-7s8 2.6 8 7' fill='%23b0b8c4'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 42%;
  border: 2px dashed #c7cdd6;
  cursor: pointer;
}

.info-panel .photo-preview.drag-over {
  border-color: #2563eb;
  background-color: #eef2ff;
}

.info-panel .photo-btn-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.info-panel .photo-btn-row button {
  border: 1px solid #d0d5db;
  background: #fafafa;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}

.info-panel .photo-btn-row button:hover {
  background: #eef1f5;
}

.info-panel .form-sticky-footer {
  position: sticky;
  bottom: -14px;
  margin: 12px -18px -14px;
  padding: 10px 18px 14px;
  background: #ffffff;
  border-top: 1px solid #eef0f2;
}

.info-panel .form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

.info-panel .form-actions button {
  border: 1px solid #d0d5db;
  background: #fafafa;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}

.info-panel .form-actions .primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

